]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix GDB Xmethod for std::shared_ptr::use_count() [PR109064]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 10 Mar 2023 11:06:25 +0000 (11:06 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Apr 2023 20:32:05 +0000 (21:32 +0100)
libstdc++-v3/ChangeLog:

PR libstdc++/109064
* python/libstdcxx/v6/xmethods.py (SharedPtrUseCountWorker):
Remove self-recursion in __init__. Add missing _supports.
* testsuite/libstdc++-xmethods/shared_ptr.cc: Check use_count()
and unique().

libstdc++-v3/python/libstdcxx/v6/xmethods.py
libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc

index 2617c189e40474442425d7a385ebf06dd743565b..cd535fb5ed68844372b92d5a03f33398b2d2c989 100644 (file)
@@ -730,7 +730,7 @@ class SharedPtrUseCountWorker(gdb.xmethod.XMethodWorker):
     "Implements std::shared_ptr<T>::use_count()"
 
     def __init__(self, elem_type):
-        SharedPtrUseCountWorker.__init__(self, elem_type)
+        pass
 
     def get_arg_types(self):
         return None
@@ -738,6 +738,9 @@ class SharedPtrUseCountWorker(gdb.xmethod.XMethodWorker):
     def get_result_type(self, obj):
         return gdb.lookup_type('long')
 
+    def _supports(self, method_name):
+        return True
+
     def __call__(self, obj):
         refcounts = obj['_M_refcount']['_M_pi']
         return refcounts['_M_use_count'] if refcounts else 0
index 05fdd57ec3f522476ef278add09631bac95fe2dc..e7a79d67d598f58b791f8cd441bdee8d1471e9e9 100644 (file)
@@ -36,6 +36,8 @@ main ()
 
   std::shared_ptr<x_struct[3]> s(new x_struct[2]{ {92}, {115} });
 
+  auto qq = q;
+
 // { dg-final { note-test *p 10 } }
 // { dg-final { regexp-test p.get() 0x.* } }
 
@@ -66,6 +68,11 @@ main ()
 // { dg-final { whatis-test s.get() "x_struct \*" } }
 // { dg-final { whatis-test s\[1].y int } }
 
+// { dg-final { note-test p.use_count() 1 } }
+// { dg-final { note-test p.unique() true } }
+// { dg-final { note-test q.use_count() 2 } }
+// { dg-final { note-test q.unique() false } }
+
   return 0;  // Mark SPOT
 }