This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2] gdb/python: add missing handling for anonymous members of struct and union
- From: Paul Koning <paulkoning at comcast dot net>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Li Yu <raise dot sail at gmail dot com>, gdb-patches at sourceware dot org
- Date: Tue, 4 Oct 2011 14:04:55 -0400
- Subject: Re: [PATCH v2] gdb/python: add missing handling for anonymous members of struct and union
- References: <4E8595F6.7080004@gmail.com> <m38vp0pvc9.fsf@fleche.redhat.com>
On Oct 4, 2011, at 12:36 PM, Tom Tromey wrote:
> ...
> I don't understand why the iterator iterates into sub-objects. Why not
> just have a flat iterator? That is, return a field with no name whose
> type is some structure, and then let the caller iterate over that type
> if need be.
>
> Tom
That's the current behavior. Yu showed an example where he wanted to get all the field names so he could then use those to retrieve the fields in a gdb.Value object. (Value objects don't currently have iterators; I'll propose a patch for that shortly.)
You can certainly do this in Python, for example:
import gdb
def deepkeys (t):
parent = t.iteritems ()
child = None
while True:
if not child:
try:
k, v = parent.next ()
except StopIteration:
parent = None
raise
if k:
yield k
continue
child = deepkeys (v.type)
try:
yield child.next ()
except StopIteration:
child = None
(This could be done more elegantly if gdb.Type could be subclassed.)
It's an interesting inconsistency that values can be indexed by field names of nested fields inside anonymous fields, but type cannot. And the keys() method on a Type right now returns only the top level names.
paul