]> 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>
Fri, 10 Mar 2023 11:10:23 +0000 (11:10 +0000)
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 6af7a3dcfe3c2e722e448fac4d9933dc4fb124ec..18a165f425e420073e07fac54588770ccd9bf000 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 c89f1d05aa316223a1b68a72a96148ba25a00e79..c228d3ad26cb1f648fa03521a6c6a46835b4a934 100644 (file)
@@ -37,6 +37,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.* } }
 
@@ -67,6 +69,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
 }