This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

[python][patch] Pretty printers for anonymous types.


Greetings,

Consider this C source:

typedef struct {
  int x;
} Foo;

typedef Foo Bar;

int main()
{
  Foo f;
  Bar b;
  return f.x + b.x;
}

AFAICT, currently there is no way to establish a pretty printer for
'Foo', because get_type() in python/python.c answers with
"struct { ... }" for either 'f' or 'b'.

Attached is a proposed fix.

Ok to commit?

--
Paul Pluzhnikov

2009-01-16  Paul Pluzhnikov  <ppluzhnikov@google.com>

	    * python/python.c (get_type): Return innermost typdef
	    name for anonymous types.

diff --git a/gdb/python/python.c b/gdb/python/python.c
index bdb5319..f75a443 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -822,11 +822,24 @@ get_type (struct type *type)
   struct ui_file *stb;
   char *thetype;
   long length;
+  struct type *const orig_type = type;
 
   stb = mem_fileopen ();
   old_chain = make_cleanup_ui_file_delete (stb);
 
   CHECK_TYPEDEF (type);
+  if (TYPE_NAME (type) == NULL
+      && TYPE_CODE (orig_type) == TYPE_CODE_TYPEDEF)
+    {
+      /* We landed on unnamed type, something like
+	   typedef struct { ... } Foo;
+         in C. Try using the innermost typedef name instead.  */
+      type = orig_type;
+      while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
+	     && TYPE_TARGET_TYPE (type)
+	     && TYPE_NAME (TYPE_TARGET_TYPE (type)))
+	type = TYPE_TARGET_TYPE (type);
+    }
 
   type_print (type, "", stb, -1);
 


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