[PATCH v4] gdb/python: add missing handling for anonymous members of struct and union

Li Yu raise.sail@gmail.com
Sat Oct 8 05:35:00 GMT 2011


gdb.Type.fields() missed handling for anonymous members.

This patch fix it, below are details:

Assume that we have a c source as below:

/////////////////////////////
struct A
{
       int a;
       union {
               int b0;
               int b1;
               union {
                       int bb0;
                       int bb1;
                       union {
                               int bbb0;
                               int bbb1;
                       };
               };
       };
       int c;
       union {
               union {
                       int dd0;
                       int dd1;
               };
               int d2;
               int d3;
       };
};

int main()
{
  struct A a;
}
////////////////////////////

And have a python gdb script as below:

##########################
v = gdb.parse_and_eval("a")
t = v.type
fields = t.fields()
for f in fields:
   print "[%s]" % f.name, v[f.name]
##########################

Without this patch, above script will print:

[a] -7616
[] {{dd0 = 0, dd1 = 0}, d2 = 0, d3 = 0}
[c] 0
[] {{dd0 = 0, dd1 = 0}, d2 = 0, d3 = 0}

With this patch, above script will print rightly:

[a] -7616
[b0] 32767
[b1] 32767
[bb0] 32767
[bb1] 32767
[bbb0] 32767
[bbb1] 32767
[c] 0
[dd0] 0
[dd1] 0
[d2] 0
[d3] 0

Thanks for Paul and Tom's feedback of this patch.

This version uses recursion implementation, as we discussed, this
patch is passed by "make check" without regression :)

Signed-off-by: Li Yu <raise.sail@gmail.com>

gdb/python/:
2011-10-8  Li Yu  <raise.sail@gmail.com>

       * py-type.c: Add process for anonymous members of struct and union

 py-type.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb.python.patch
Type: text/x-patch
Size: 2119 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20111008/14c2d6dc/attachment.bin>


More information about the Gdb-patches mailing list