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


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


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