PR libstdc++/59253 Improve pretty printers for smart pointers
PR libstdc++/59253 (partial) * python/libstdcxx/v6/printers.py (SmartPtrIterator): Common iterator type for pointer stored by shared_ptr, weak_ptr and unique_ptr. (SharedPointerPrinter, UniquePointerPrinter): Treat stored values as children. * testsuite/libstdc++-prettyprinters/cxx11.cc: Update expected output of unique_ptr printer. * testsuite/libstdc++-prettyprinters/shared_ptr.cc: Update expected output of shared_ptr printer. From-SVN: r256390
This commit is contained in:
parent
1eac10b39f
commit
d2dfcf823c
@ -1,3 +1,15 @@
|
||||
2018-01-09 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/59253 (partial)
|
||||
* python/libstdcxx/v6/printers.py (SmartPtrIterator): Common iterator
|
||||
type for pointer stored by shared_ptr, weak_ptr and unique_ptr.
|
||||
(SharedPointerPrinter, UniquePointerPrinter): Treat stored values as
|
||||
children.
|
||||
* testsuite/libstdc++-prettyprinters/cxx11.cc: Update expected output
|
||||
of unique_ptr printer.
|
||||
* testsuite/libstdc++-prettyprinters/shared_ptr.cc: Update expected
|
||||
output of shared_ptr printer.
|
||||
|
||||
2018-01-05 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/83626
|
||||
|
@ -114,12 +114,31 @@ def strip_versioned_namespace(typename):
|
||||
return typename.replace(_versioned_namespace, '')
|
||||
return typename
|
||||
|
||||
class SmartPtrIterator(Iterator):
|
||||
"An iterator for smart pointer types with a single 'child' value"
|
||||
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.val is None:
|
||||
raise StopIteration
|
||||
self.val, val = None, self.val
|
||||
return ('get()', val)
|
||||
|
||||
class SharedPointerPrinter:
|
||||
"Print a shared_ptr or weak_ptr"
|
||||
|
||||
def __init__ (self, typename, val):
|
||||
self.typename = strip_versioned_namespace(typename)
|
||||
self.val = val
|
||||
self.pointer = val['_M_ptr']
|
||||
|
||||
def children (self):
|
||||
return SmartPtrIterator(self.pointer)
|
||||
|
||||
def to_string (self):
|
||||
state = 'empty'
|
||||
@ -128,27 +147,29 @@ class SharedPointerPrinter:
|
||||
usecount = refcounts['_M_use_count']
|
||||
weakcount = refcounts['_M_weak_count']
|
||||
if usecount == 0:
|
||||
state = 'expired, weak %d' % weakcount
|
||||
state = 'expired, weak count %d' % weakcount
|
||||
else:
|
||||
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(self.pointer.type.target().strip_typedefs()), state)
|
||||
|
||||
class UniquePointerPrinter:
|
||||
"Print a unique_ptr"
|
||||
|
||||
def __init__ (self, typename, val):
|
||||
self.val = val
|
||||
impl_type = val.type.fields()[0].type.tag
|
||||
if is_specialization_of(impl_type, '__uniq_ptr_impl'): # New implementation
|
||||
self.pointer = val['_M_t']['_M_t']['_M_head_impl']
|
||||
elif is_specialization_of(impl_type, 'tuple'):
|
||||
self.pointer = val['_M_t']['_M_head_impl']
|
||||
else:
|
||||
raise ValueError("Unsupported implementation for unique_ptr: %s" % impl_type)
|
||||
|
||||
def children (self):
|
||||
return SmartPtrIterator(self.pointer)
|
||||
|
||||
def to_string (self):
|
||||
impl_type = self.val.type.fields()[0].type.tag
|
||||
if is_specialization_of(impl_type, '__uniq_ptr_impl'): # New implementation
|
||||
v = self.val['_M_t']['_M_t']['_M_head_impl']
|
||||
elif is_specialization_of(impl_type, 'tuple'):
|
||||
v = self.val['_M_t']['_M_head_impl']
|
||||
else:
|
||||
raise ValueError("Unsupported implementation for unique_ptr: %s" % self.val.type.fields()[0].type.tag)
|
||||
return 'std::unique_ptr<%s> containing %s' % (str(v.type.target()),
|
||||
str(v))
|
||||
return ('std::unique_ptr<%s>' % (str(self.pointer.type.target())))
|
||||
|
||||
def get_value_from_aligned_membuf(buf, valtype):
|
||||
"""Returns the value held in a __gnu_cxx::__aligned_membuf."""
|
||||
|
@ -127,14 +127,14 @@ main()
|
||||
std::unique_ptr<datum> uptr (new datum);
|
||||
uptr->s = "hi bob";
|
||||
uptr->i = 23;
|
||||
// { dg-final { regexp-test uptr {std::unique_ptr.datum. containing 0x.*} } }
|
||||
// { dg-final { regexp-test uptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
|
||||
std::unique_ptr<datum> &ruptr = uptr;
|
||||
// { dg-final { regexp-test ruptr {std::unique_ptr.datum. containing 0x.*} } }
|
||||
// { dg-final { regexp-test ruptr {std::unique_ptr.datum. = {get\(\) = 0x.*}} } }
|
||||
|
||||
ExTuple tpl(6,7);
|
||||
// { dg-final { note-test tpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
|
||||
// { dg-final { note-test tpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
|
||||
ExTuple &rtpl = tpl;
|
||||
// { dg-final { note-test rtpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
|
||||
// { dg-final { note-test rtpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
|
||||
placeholder(""); // Mark SPOT
|
||||
use(efl);
|
||||
use(fl);
|
||||
|
@ -49,25 +49,25 @@ main()
|
||||
typedef std::weak_ptr<int> weak;
|
||||
|
||||
shared esp;
|
||||
// { dg-final { note-test esp "std::shared_ptr (empty) 0x0" } }
|
||||
// { dg-final { note-test esp "std::shared_ptr<int> (empty) = {get() = 0x0}" } }
|
||||
weak ewp1;
|
||||
// { dg-final { note-test ewp1 "std::weak_ptr (empty) 0x0" } }
|
||||
// { dg-final { note-test ewp1 "std::weak_ptr<int> (empty) = {get() = 0x0}" } }
|
||||
weak ewp2 = esp;
|
||||
// { dg-final { note-test ewp2 "std::weak_ptr (empty) 0x0" } }
|
||||
// { dg-final { note-test ewp2 "std::weak_ptr<int> (empty) = {get() = 0x0}" } }
|
||||
|
||||
shared sp1 = make(0x12345678);
|
||||
shared sp2 = sp1;
|
||||
// { dg-final { note-test sp1 "std::shared_ptr (count 2, weak 0) 0x12345678" } }
|
||||
// { dg-final { note-test sp1 "std::shared_ptr<int> (use count 2, weak count 0) = {get() = 0x12345678}" } }
|
||||
|
||||
shared sp3 = make(0x12344321);
|
||||
weak sp4 = sp3;
|
||||
weak wp1 = sp3;
|
||||
// { dg-final { note-test wp1 "std::weak_ptr (count 1, weak 2) 0x12344321" } }
|
||||
// { dg-final { note-test wp1 "std::weak_ptr<int> (use count 1, weak count 2) = {get() = 0x12344321}" } }
|
||||
|
||||
shared sp5 = make(0x56788765);
|
||||
weak wp2 = sp5;
|
||||
sp5.reset();
|
||||
// { dg-final { note-test wp2 "std::weak_ptr (expired, weak 1) 0x56788765" } }
|
||||
// { dg-final { note-test wp2 "std::weak_ptr<int> (expired, weak count 1) = {get() = 0x56788765}" } }
|
||||
|
||||
placeholder(""); // Mark SPOT
|
||||
use(esp);
|
||||
|
Loading…
Reference in New Issue
Block a user