This is the mail archive of the
mailing list for the libstdc++ project.
Re: Smart pointer pretty printers
On Fri, Feb 24, 2017 at 4:11 PM, Jonathan Wakely <email@example.com> 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.
@@ -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,
"Print a unique_ptr"