From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id A4FAC3857835; Thu, 27 Apr 2023 22:01:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4FAC3857835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682632866; bh=oVPH+G19VY3PjaIoBkfAhZU2uAeVGxHZ6N/WgR7VJQs=; h=From:To:Subject:Date:From; b=mYVlmn65z8SwBM25TAaVzUoPYJP9l5u5JCEbEpxM0z9z9cN29oOpOaUzsLtq4lXxE MHTxu86ytrBXELtAg/i1PW4DqrBMBGOqnXMVZ9Gozvbf0LSeJm9wWkVWCr5Hftq15J Ivx9TjQ7BSsrUZDy/Mi6wZU/HiHUKjRsyTOoW3Ok= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10657] libstdc++: Fix GDB Xmethod for std::shared_ptr::use_count() [PR109064] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 6930165acd05c8eef88a99b9546742b108e0c84e X-Git-Newrev: 3ca17b2b6be8e9bab2ee06636826d92604104475 Message-Id: <20230427220106.A4FAC3857835@sourceware.org> Date: Thu, 27 Apr 2023 22:01:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3ca17b2b6be8e9bab2ee06636826d92604104475 commit r11-10657-g3ca17b2b6be8e9bab2ee06636826d92604104475 Author: Jonathan Wakely Date: Fri Mar 10 11:06:25 2023 +0000 libstdc++: Fix GDB Xmethod for std::shared_ptr::use_count() [PR109064] 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(). Diff: --- libstdc++-v3/python/libstdcxx/v6/xmethods.py | 5 ++++- libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 991d945321a..d6cbcf139c5 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -730,7 +730,7 @@ class SharedPtrUseCountWorker(gdb.xmethod.XMethodWorker): "Implements std::shared_ptr::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 diff --git a/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc b/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc index e7cdfa4bd53..7b9e3e5534d 100644 --- a/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc +++ b/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc @@ -36,6 +36,8 @@ main () std::shared_ptr 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 }