Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Carlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] ptype: show members of an unnamed struct inside an union
Date: Tue, 28 Aug 2007 17:14:00 -0000	[thread overview]
Message-ID: <20070828171422.GB3874@adacore.com> (raw)
In-Reply-To: <46C4D20E.1010703@linux.vnet.ibm.com>

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


  parent reply	other threads:[~2007-08-28 17:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-16 22:39 Carlos Eduardo Seo
2007-08-24 15:48 ` Joel Brobecker
2007-08-24 16:02   ` Carlos Eduardo Seo
2007-08-24 17:39     ` Joel Brobecker
2007-08-28 17:14 ` Joel Brobecker [this message]
2007-08-28 19:03   ` Luis Machado
2007-08-28 20:04     ` Joel Brobecker
2007-08-28 20:12       ` Carlos Eduardo Seo
2007-08-28 20:34         ` Joel Brobecker
2007-08-29  2:56           ` Daniel Jacobowitz
2007-08-29  4:36             ` Joel Brobecker
2007-08-29 16:30               ` Daniel Jacobowitz
2007-08-29 18:32                 ` Joel Brobecker
2007-08-29 18:36                   ` Daniel Jacobowitz
2007-08-29 18:48                     ` Joel Brobecker
2007-08-29 18:50                       ` Carlos Eduardo Seo
2007-08-29 20:14                       ` Carlos Eduardo Seo
2007-08-29 20:23                         ` Daniel Jacobowitz
2007-08-29 20:26                           ` Carlos Eduardo Seo
2007-08-29 20:41                             ` Joel Brobecker
2007-08-29 20:44                               ` Daniel Jacobowitz
2007-08-29 21:01                                 ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070828171422.GB3874@adacore.com \
    --to=brobecker@adacore.com \
    --cc=cseo@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox