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]

[PATCH] gdb/python: add missing handling for anonymous members of struct and union


gdb.Type.fields() missed handling for anonymous members.
This patch fix it,

Signed-off-by: Li Yu <raise.sail@gmail.com>

gdb/python/:
2011-09-29  Li Yu  <raise.sail@gmail.com>

	* py-type.c: Add process for anonymous members of struct and union

---
 gdb/python/py-type.c |   37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
--- gdb-7.3.1.orig/gdb/python/py-type.c	2011-01-27 04:53:45.000000000 +0800
+++ gdb-7.3.1/gdb/python/py-type.c	2011-09-29 15:15:31.000000000 +0800
@@ -143,6 +143,7 @@ convert_field (struct type *type, int fi
 {
   PyObject *result = field_new ();
   PyObject *arg;
+  char *name = TYPE_FIELD_NAME (type, field);
 
   if (!result)
     return NULL;
@@ -157,8 +158,13 @@ convert_field (struct type *type, int fi
 	goto failarg;
     }
 
-  if (TYPE_FIELD_NAME (type, field))
-    arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
+  if (name)
+    {
+      if (name[0])
+        arg = PyString_FromString (name);
+      else
+        return Py_None;
+    }
   else
     {
       arg = Py_None;
@@ -240,6 +246,33 @@ typy_fields (PyObject *self, PyObject *a
 	  Py_DECREF (result);
 	  return NULL;
 	}
+
+      if (dict == Py_None)
+        {
+          struct type *f_type = TYPE_FIELD_TYPE(type, i);
+          int j;
+
+          if ((TYPE_CODE(type) != TYPE_CODE_UNION) 
+            && (TYPE_CODE(type) != TYPE_CODE_STRUCT))
+            {
+	      Py_DECREF (result);
+	      return NULL;
+            }
+            
+          for (j = 0; j < TYPE_NFIELDS(f_type); ++j)
+            {
+              PyObject *dict = convert_field (f_type, j);
+
+              if (!dict || PyList_Append (result, dict))
+                {
+                  Py_XDECREF (dict);
+                  Py_DECREF (result);
+                  return NULL;
+                }
+            }
+          continue;
+        }
+
       if (PyList_Append (result, dict))
 	{
 	  Py_DECREF (dict);


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