From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 16E7C3858D1E for ; Fri, 10 Mar 2023 11:37:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16E7C3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678448240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dIUojf5PvyChkYEnA1Ml8BWV2j086KT/ToG1E2A0V4Q=; b=IxBxLOQcrqWtJQYXpNAWTivruzRHL9FvqCeILEMxF2cTmH5nXdrq2cJjyOGpwUthR8HoR+ OuhcqPQjGTYAXXTdvN9TjqNXTj6aG1VScThwrd/4Hf5XT4XCe7vlktpfxo+RSbA3GxWlIg MXdSU9kP5PmnC9xUL0VhGCmkeKH44Ho= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-374-1z57A9_GNCqscW5vWTQenw-1; Fri, 10 Mar 2023 06:37:19 -0500 X-MC-Unique: 1z57A9_GNCqscW5vWTQenw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 431D48027FD; Fri, 10 Mar 2023 11:37:19 +0000 (UTC) Received: from localhost (unknown [10.33.36.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FF0040BC781; Fri, 10 Mar 2023 11:37:18 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix GDB Xmethod for std::shared_ptr::use_count() [PR109064] Date: Fri, 10 Mar 2023 11:37:18 +0000 Message-Id: <20230310113718.2304961-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux (GDB 13.1). Pushed to trunk for now, will do backports too. -- >8 -- 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 | 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 6af7a3dcfe3..18a165f425e 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 c89f1d05aa3..c228d3ad26c 100644 --- a/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc +++ b/libstdc++-v3/testsuite/libstdc++-xmethods/shared_ptr.cc @@ -37,6 +37,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.* } } @@ -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 } -- 2.39.2