From: Paul Koning <paulkoning@comcast.net>
To: Tom Tromey <tromey@redhat.com>
Cc: Li Yu <raise.sail@gmail.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2] gdb/python: add missing handling for anonymous members of struct and union
Date: Tue, 04 Oct 2011 20:41:00 -0000 [thread overview]
Message-ID: <F281C53B-182F-44BA-B0DB-C0E46E47069F@comcast.net> (raw)
In-Reply-To: <m3pqicld48.fsf@fleche.redhat.com>
On Oct 4, 2011, at 4:23 PM, Tom Tromey wrote:
>>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes:
>
> Tom> I don't understand why the iterator iterates into sub-objects. Why not
> Tom> just have a flat iterator? That is, return a field with no name whose
> Tom> type is some structure, and then let the caller iterate over that type
> Tom> if need be.
>
> Paul> That's the current behavior. Yu showed an example where he wanted
> Paul> to get all the field names so he could then use those to retrieve
> Paul> the fields in a gdb.Value object.
>
> Ok, I see. Thanks.
>
> Paul> (Value objects don't currently have iterators; I'll propose a
> Paul> patch for that shortly.)
>
> Thanks, after reading your other patch I was meaning to see if this was
> needed :)
>
> Paul> You can certainly do this in Python, for example:
>
> Why don't we do that, then, in some code in the gdb python library?
>
> Paul> (This could be done more elegantly if gdb.Type could be subclassed.)
>
> It seems reasonable to me.
>
> Tom
There is an inconsistency between type and value that relates to this discussion. Right now, Type objects can be asked for a field by name, but that only works for fields at that level (not inside anonymous elements). On the other hands, for Value objects, you *can* ask for a subfield of an anonymous field by name.
It works that way because value_struct_elt recurses into anonymous elements, while the Type lookup uses code lifted from lookup_struct_elt_type which does not do so.
This ties into how iterators work, because the expected behavior is that each key that can be used in an item lookup "obj[key]" is also returned by keys(), and similarly for the other list/iterator methods. Right now, that's true for gdb.Type (top level only is returned). In my test code for Value iterators it is currently not true (the Value iterators also process only the top level even though lookup by name digs into anonymous subelements).
So we have:
1. Type field lookup: flat
2. Type iteration: flat
3. Value field lookup: recursive
4. [Value iteration: flat] (not submitted yet)
And Yu's proposed change makes #2 recursive (but does not change #1).
I think minimally things need to be pairwise the same (1 and 2, 3 and 4). It seems most logical for all four to be the same. My preference would be all four recursive, but flat/flat, recursive/recursive is a reasonable fallback especially if we add sample code for recursive walk of gdb.Type to the gdb Python library.
paul
next prev parent reply other threads:[~2011-10-04 20:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-30 11:04 Li Yu
2011-09-30 16:15 ` Paul Koning
2011-10-01 14:01 ` Li Yu
2011-10-01 18:54 ` Paul Koning
2011-10-04 16:37 ` Tom Tromey
2011-10-04 18:05 ` Paul Koning
2011-10-04 20:24 ` Tom Tromey
2011-10-04 20:41 ` Paul Koning [this message]
2011-10-19 20:52 ` Tom Tromey
2011-10-19 20:59 ` Paul Koning
2011-10-20 18:49 ` Tom Tromey
2011-10-25 18:34 ` [RFA] Python: iterator for deep traversal of gdb.Type struct/union fields Paul Koning
2011-10-25 19:03 ` Paul Koning
2011-10-25 20:16 ` Eli Zaretskii
2011-10-26 17:14 ` Paul Koning
2011-10-27 13:01 ` Doug Evans
2011-10-27 14:52 ` Paul_Koning
2011-10-27 19:57 ` Tom Tromey
[not found] ` <09787EF419216C41A903FD14EE5506DD030CF168FB@AUSX7MCPC103.AMER.DELL.COM>
2011-10-27 21:56 ` Paul Koning
2011-10-27 22:14 ` Eli Zaretskii
2011-10-28 14:55 ` Paul Koning
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=F281C53B-182F-44BA-B0DB-C0E46E47069F@comcast.net \
--to=paulkoning@comcast.net \
--cc=gdb-patches@sourceware.org \
--cc=raise.sail@gmail.com \
--cc=tromey@redhat.com \
/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