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

On Fri, Feb 24, 2017 at 4:11 PM, Jonathan Wakely <> wrote:
> This looks promising, thanks. I'll look into making that change, and
> something similar to the shared_ptr printer too.

Great, thanks! Well, you can have the diff for the shared_ptr printer
too, it's almost the same thing :). I also added printing of the
pointed type analogously to the unique pointer version.

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

     def to_string (self):
         state = 'empty'
@@ -116,8 +120,8 @@ 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"

Regards, Juraj

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