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]

Re: [python] [patch] Fix prettyprinter of std::map<const char *, ...>


>>>>> "Paul" == Paul Pluzhnikov <ppluzhnikov@google.com> writes:

Paul> Attached patch fixes this by brute force :(
Paul> Not sure if there is a better fix.

Paul> -        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))

This line was always pretty bogus.  Thanks for digging this out.

I'm committing the appended, which fixes this properly.

Tom

2008-12-17  Tom Tromey  <tromey@redhat.com>

	* python/lib/gdb/libstdcxx/v6/printers.py
	(StdMapPrinter.children): Use type's const method.
	* python/python-type.c (typy_const): New function.
	(typy_volatile): Likewise.
	(typy_unqualified): Likewise.
	(type_object_methods): Add const, volatile, unqualified.

2008-12-17  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (Types From Inferior): Document const, volatile,
	and unqualified methods.

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6257660..13137ab 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18377,9 +18377,25 @@ The type of the field.
 @end table
 @end defmethod
 
-@defmethod Type pointer
-Return a new @code{gdb.Type} object which represents a pointer to this
-type.
+@defmethod Type const
+Return a new @code{gdb.Type} object which represents a @code{const}
+qualified variant of this type.
+@end defmethod
+
+@defmethod Type const
+Return a new @code{gdb.Type} object which represents a
+@code{const}-qualified variant of this type.
+@end defmethod
+
+@defmethod Type volatile
+Return a new @code{gdb.Type} object which represents a
+@code{volatile}-qualified variant of this type.
+@end defmethod
+
+@defmethod Type unqualified
+Return a new @code{gdb.Type} object which represents an unqualified
+variant of this type.  That is, the result is neither @code{const} nor
+@code{volatile}.
 @end defmethod
 
 @defmethod Type reference
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index c03c682..4390553 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -232,9 +232,9 @@ class StdMapPrinter:
         return '%s with %d elements' % (self.typename, len (self.iter))
 
     def children (self):
-        keytype = self.val.type().template_argument(0)
+        keytype = self.val.type().template_argument(0).const()
         valuetype = self.val.type().template_argument(1)
-        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))
+        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< %s, %s > >' % (keytype, valuetype))
         nodetype = nodetype.pointer()
         return self._iter (self.iter, nodetype)
 
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index b2d3654..5aa82f6 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -280,6 +280,54 @@ typy_target (PyObject *self, PyObject *args)
   return type_to_type_object (TYPE_TARGET_TYPE (type));
 }
 
+/* Return a const-qualified type variant.  */
+static PyObject *
+typy_const (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (1, 0, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
+/* Return a volatile-qualified type variant.  */
+static PyObject *
+typy_volatile (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (0, 1, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
+/* Return an unqualified type variant.  */
+static PyObject *
+typy_unqualified (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      type = make_cv_type (0, 0, type, NULL);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return type_to_type_object (type);
+}
+
 /* Return the size of the type represented by SELF, in bytes.  */
 static PyObject *
 typy_sizeof (PyObject *self, PyObject *args)
@@ -652,6 +700,7 @@ gdbpy_initialize_types (void)
 static PyMethodDef type_object_methods[] =
 {
   { "code", typy_code, METH_NOARGS, "Return the code for this type" },
+  { "const", typy_const, METH_NOARGS, "Return a const variant of this type" },
   { "fields", typy_fields, METH_NOARGS,
     "Return a sequence holding all the fields of this type.\n\
 Each field is a dictionary." },
@@ -665,6 +714,10 @@ Each field is a dictionary." },
     "Return the target type of this type" },
   { "template_argument", typy_template_argument, METH_VARARGS,
     "Return a single template argument type" },
+  { "unqualified", typy_unqualified, METH_NOARGS,
+    "Return a variant of this type without const or volatile attributes" },
+  { "volatile", typy_volatile, METH_NOARGS,
+    "Return a volatile variant of this type" },
   { NULL }
 };
 


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