This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] gdb/python: add missing handling for anonymous members of struct and union
- From: Paul Koning <paulkoning at comcast dot net>
- To: Li Yu <raise dot sail at gmail dot com>, gdb-patches at sourceware dot org
- Date: Thu, 29 Sep 2011 21:09:41 -0400
- Subject: Re: [PATCH] gdb/python: add missing handling for anonymous members of struct and union
- References: <4E841E64.8090609@gmail.com> <09787EF419216C41A903FD14EE5506DD030A334B61@AUSX7MCPC103.AMER.DELL.COM> <AFD030CE-0F23-48D7-8A66-F17DDBFA89B0@comcast.net> <CA+WLrf8CitrMfanhy0S6DcM47b1odfm0ZkX8nJ3ezafpfAoS5g@mail.gmail.com>
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