This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] ptype: show members of an unnamed struct inside an union


Carlos,

> The attached patched fixes an issue described on this post:
> 
> http://sourceware.org/ml/gdb-patches/2002-04/msg01114.html
> 
> Any comments?

It actually seems to me that the current behavior is expected.
It's not actually a question of named vs unnamed structure,
but rather a question of nesting. Consider the following example:

    struct inner
    {
      int mapping;
    };
    
    struct outer
    {
      int a;
      struct inner b;
      struct
      {
        int c;
        struct { int d; } e;
      } f;
    };

Doing a "ptype" on type "outer" yields:

    type = struct outer {
        int a;
        struct inner b;
        struct {
            int c;
            struct {...} e;
        } f;
    }

Basically, the idea here is to avoid going too deep into the type
structure by only printing complete information for the immediate
fields of our structure (that's nesting level 1). For nesting level 2,
we print the type name only (eg: "struct inner b"), or, when the field
has an unnamed type, a concise description of that type: That's why
we printed "struct { int c; ... }". For nesting level 3, we try to
be even more concise, which means the type name if we have one, or
"struct {...}" if we don't.

See also the description of the function you tried to modify:

   SHOW positive means print details about the type (e.g. enum values),
   and print structure elements passing SHOW - 1 for show.
   SHOW negative means just print the type name or struct tag if there is one.
   If there is no name, print something sensible but concise like
   "struct {...}".
   SHOW zero means just print the type name or struct tag if there is one.
   If there is no name, print something sensible but not as concise like
   "struct {int x; int y;}".

So, in order to get the type description for our nested structure,
we just need to get one level deeper by doing the following:

    (gdb) ptype my_outer.f
    type = struct {
        int c;
        struct {
            int d;
        } e;
    }

Similarly in your example:

    (gdb) ptype mypage.u
    type = union {
        struct {
            int mapping;
        };
    }

I looked at the current GDB documentation for "ptype" and couldn't
find anything that confirmed my analysis. I think a contribution
to the documentation would be very much appreciated.

In the meantime, I will submit a testcase in our testsuite that would have
failed if you patch had been applied.

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]