* python/lib/gdb/types.py (deepitems): New function.
authorPaul Koning <pkoning@equallogic.com>
Wed, 26 Oct 2011 15:09:40 +0000 (15:09 +0000)
committerPaul Koning <pkoning@equallogic.com>
Wed, 26 Oct 2011 15:09:40 +0000 (15:09 +0000)
gdb/ChangeLog
gdb/python/lib/gdb/types.py

index f8aa18794b247c24d369acacd7c6280135aa5551..3127093aa6edaccb9e43e0ea3e23504526d44989 100644 (file)
@@ -1,3 +1,7 @@
+2011-10-26  Paul Koning  <paul_koning@dell.com>
+
+       * python/lib/gdb/types.py (deepitems): New function.
+       
 2011-10-25  Paul Koning  <paul_koning@dell.com>
 
        PR python/13327
index 54fbe3c7bfb09a5e8cf0be5f2aa00a247643ee19..9a9b24557d6b2bc4cc1d9a86ad68ca5587018e81 100644 (file)
@@ -89,3 +89,23 @@ def make_enum_dict(enum_type):
         # The enum's value is stored in "bitpos".
         enum_dict[field.name] = field.bitpos
     return enum_dict
+
+
+def deepitems (type_):
+    """Return an iterator that recursively traverses anonymous fields.
+
+    Arguments:
+        type_: The type to traverse.  It should be one of
+        gdb.TYPE_CODE_STRUCT or gdb.TYPE_CODE_UNION.
+
+    Returns:
+        an iterator similar to gdb.Type.iteritems(), i.e., it returns
+        pairs of key, value, but for any anonymous struct or union
+        field that field is traversed recursively, depth-first.
+    """
+    for k, v in type_.iteritems ():
+        if k:
+            yield k, v
+        else:
+            for i in deepitems (v.type):
+                yield i