Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [RFC] python: gdb.Type: strip typedefs past pointers too
@ 2010-09-18 14:12 Paul Bolle
  2010-09-19 16:35 ` Joel Brobecker
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Paul Bolle @ 2010-09-18 14:12 UTC (permalink / raw)
  To: gdb-patches

0) gdb.Type.strip_typedefs() stops stripping types if it encounters a
type that is a pointer to a typedef:

(gdb) ptype wchar_t
type = long int
(gdb) ptype wchar_t *
type = long int *
(gdb) python print gdb.lookup_type("wchar_t").strip_typedefs()
long int
(gdb) python print gdb.lookup_type("wchar_t").pointer().strip_typedefs()
wchar_t *

1) I drafted a patch (pasted below this message) that works around this
limitation:

(gdb) ptype wchar_t
type = long int
(gdb) ptype wchar_t *
type = long int *
(gdb) python print gdb.lookup_type("wchar_t").strip_typedefs()
long int
(gdb) python print gdb.lookup_type("wchar_t").pointer().strip_typedefs()
long int *

2) I'm not comfortable with the code I'm using here (ie, gdb's type
handling code) so I'd appreciate comments on this draft patch.


Paul Bolle
---
Currently gdb.Type.strip_typedefs() doesn't strip typedefs if it
encounters a type that is a pointer to a typedef. In those cases it
doesn't really behave as advertised (well, as I understand the
advertisement).

So learn strip_typedefs() to handle pointers to typedefs too.
---
 gdb/python/py-type.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 8232436..08602a1 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -267,8 +267,29 @@ static PyObject *
 typy_strip_typedefs (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
+  struct type *real_type;
+  int level = 0;
 
-  return type_to_type_object (check_typedef (type));
+  real_type = check_typedef (type);
+
+  while (TYPE_CODE (real_type) == TYPE_CODE_PTR ||
+	 TYPE_CODE (real_type) == TYPE_CODE_TYPEDEF)
+    {
+      if (TYPE_CODE (real_type) == TYPE_CODE_TYPEDEF)
+	{
+	  CHECK_TYPEDEF (real_type);
+	}
+      else
+       {
+	  real_type = TYPE_TARGET_TYPE (real_type);
+	  level++;
+	}
+    }
+
+  while (level--)
+    real_type = lookup_pointer_type (real_type);
+
+  return type_to_type_object (real_type);
 }
 
 /* Return an array type.  */
-- 
1.7.2.3


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-09-20 12:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-18 14:12 [PATCH] [RFC] python: gdb.Type: strip typedefs past pointers too Paul Bolle
2010-09-19 16:35 ` Joel Brobecker
2010-09-19 17:56   ` Paul Bolle
2010-09-20  9:32     ` Daniel Jacobowitz
2010-09-20  9:48       ` Paul Bolle
2010-09-20 10:04         ` Daniel Jacobowitz
2010-09-20 10:15 ` Phil Muldoon
2010-09-20 10:53   ` Paul Bolle
2010-09-20 12:02 ` Jan Kratochvil
2010-09-20 16:25   ` Paul Bolle
2010-09-20 13:59     ` Paul Bolle
2010-09-20 16:08     ` Paul Bolle
2010-09-21 12:39     ` Jan Kratochvil
2010-09-20 13:14 ` André Pönitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox