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] gdb/python: add missing handling for anonymous members of struct and union


On Sep 29, 2011, at 10:51 AM, Li Yu wrote:

> 
> 
> 2011/9/29 Paul Koning <paulkoning@comcast.net>
> I'm confused by what this patch does.
> 
> It seems that it handles an empty field name by producing None instead of a gdb.Field.  Why do that?  The existing code detects the case where TYPE_FIELD_NAME is null -- if it is, then Field.name is set to None, otherwise it is set to a Python string whose content is the field name.  If it's possible for TYPE_FIELD_NAME to be non-null but a zero length string, would it not be more consistent for that case also to produce a gdb.Field object with name == None?
> 
> 
> Sorry for too short description, please allow me use one example to explain why I write this patch, we assume there is a C source like below:
> struct A
> {
> ããint a;
> ããunion {
> ããããint b0;
> ããããint b1;
> ãã};
> ããint c;
> ããunion {
> ããããint d0;
> ããããint d1;
> ãã};
> };
> 
> int main()
> {
>    struct A a;
> }
> 
> After great gdb break at main() function, we execute below python script:
> 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, we will see its output may be:
> 
> [a] 0
> [] {d0 = 0, d1 = 0}
> [c] 0
> [] {d0 = 0, d1 = 0}
> 
> 
> With this patch, we will see its output may be:
> 
> [a] 0
> [b0] 0
> [b1] 0
> [c] 0
> [d0] 0
> [d1] 0
> 
> 
> Now, the question is clearly, gdb.Type.fields() miss right handling for anonymous members of union/struct.

Makes sense.  Since that changes the behavior of the class, I think this needs a change in the documentation, and some new or changed tests in the testsuite.

	paul


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