This is the mail archive of the mailing list for the libstdc++ 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: Smart pointer pretty printers

I now realized that I worked on an older version of the
file. I have produced a patch against a recent version, which had some
changes to the unique pointer printer regarding a newer implementation
of the unique pointer. The patch includes this for both the unique and
shared pointers. Also, I have added the same for the vector iterator
just for your consideration. Do you think the same could be applied
for other STL container iterators?

Also, let me know if you need a copyright assignment.

Regards, Juraj

--- libstdcxx/v6/
+++ libstdcxx/v6/
@@ -121,6 +121,10 @@ class SharedPointerPrinter:
     def __init__ (self, typename, val):
         self.typename = strip_versioned_namespace(typename)
         self.val = val
+        self.pointer = val['_M_ptr']
+    def children (self):
+        return [('get()', self.pointer)]

     def to_string (self):
         state = 'empty'
@@ -131,25 +135,27 @@ class SharedPointerPrinter:
             if usecount == 0:
                 state = 'expired, weak %d' % weakcount
-                state = 'count %d, weak %d' % (usecount, weakcount - 1)
-        return '%s (%s) %s' % (self.typename, state, self.val['_M_ptr'])
+                state = 'use count = %d, weak count = %d' %
(usecount, weakcount - 1)
+        return '%s<%s> (%s)' % (self.typename,
str(, state)

 class UniquePointerPrinter:
     "Print a unique_ptr"

     def __init__ (self, typename, val):
         self.val = val
-    def to_string (self):
         impl_type = self.val.type.fields()[0].type.tag
         if is_specialization_of(impl_type, '__uniq_ptr_impl'): # New
-            v = self.val['_M_t']['_M_t']['_M_head_impl']
+            self.pointer = self.val['_M_t']['_M_t']['_M_head_impl']
         elif is_specialization_of(impl_type, 'tuple'):
-            v = self.val['_M_t']['_M_head_impl']
+            self.pointer = self.val['_M_t']['_M_head_impl']
             raise ValueError("Unsupported implementation for
unique_ptr: %s" % self.val.type.fields()[0].type.tag)
-        return 'std::unique_ptr<%s> containing %s' % (str(,
-                                                      str(v))
+    def children (self):
+        return [('get()', self.pointer)]
+    def to_string (self):
+        return ('std::unique_ptr<%s>' % (str(

 def get_value_from_aligned_membuf(buf, valtype):
     """Returns the value held in a __gnu_cxx::__aligned_membuf."""
@@ -350,11 +356,17 @@ class StdVectorIteratorPrinter:

     def __init__(self, typename, val):
         self.val = val
+        self.pointer = self.val['_M_current']
+    def children(self):
+        if not self.pointer:
+            return []
+        return [('operator->()', self.pointer)]

     def to_string(self):
-        if not self.val['_M_current']:
+        if not self.pointer:
             return 'non-dereferenceable iterator for std::vector'
-        return str(self.val['_M_current'].dereference())
+        return ('std::vector<%s>::iterator' %

 class StdTuplePrinter:
     "Print a std::tuple"

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