From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cWSKFByNz2oLJgkAWB0awg (envelope-from ) for ; Wed, 14 Oct 2026 10:09:32 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=fkVwrmMG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4EE081E050; Wed, 14 Oct 2026 10:09:32 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BD4611E04E for ; Wed, 14 Oct 2026 10:09:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D61D04BA23F8 for ; Wed, 14 Oct 2026 14:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D61D04BA23F8 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=fkVwrmMG Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 349C14BA2E3D for ; Wed, 14 Oct 2026 14:08:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 349C14BA2E3D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 349C14BA2E3D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791986933; cv=none; b=keYPPAX7kwn1JBPcQid8cvl0RKsvp5fqK4jCB1DhQHr2gF8kylypHCN6Vm2YWrSmKkHJpb/gMqpVv+crAHVoq4UkLlormLPqdUYDmEHKj/zK1bHn81RXU4lMSCNopPczqG6TQyUGfQLRiodsaASt2jUbMgos5VFqGEnXpwpv5+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791986933; c=relaxed/simple; bh=d+e2d1SO1OfRiQXQF4Fd/Sztt6i/uv2se5iWO1p6s3g=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=hpSS3IO6+CLKWDpc5k0cZprOuXNTygkpaL49j+0lKoRtygztsX3ZBgIihtPoHA+3u0hCQY1YTE7HmDDlPQtT2PKWEjVdnPrK2CyM5z3j4XMnhO3geKZ5064WDihGaHbQxx4UBIvUXHQ/otQgt3Ew4VBwJoaUXfTH6bfoae5AvZs= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=fkVwrmMG reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 349C14BA2E3D Received: from eig-obgw-6006b.ext.cloudfilter.net ([10.0.30.211]) by cmsmtp with ESMTPS id GzWWxvcMyusRSGzf2xJIE7; Wed, 14 Oct 2026 14:08:52 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Gzf1xknjLbhSyGzf1xbGoQ; Wed, 14 Oct 2026 14:08:51 +0000 X-Authority-Analysis: v=2.4 cv=IJECChvG c=1 sm=1 tr=0 ts=6acf8cf4 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=ItBw4LHWJt0A:10 a=Rj1hLgJg9nnNnd-qjVEA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Lo7SB4vRmRn7bUTZOLktfQgrfsvXTQpmhgHMFYmw/gY=; b=fkVwrmMGNkcWlrLj2hMrXVOib0 PUEN+ImuW0L0AfzrzPBcPMu/RVP7wYjVKyr6+5iVXCxsvtZSm8iNgeeYBjpXwzLXO7YuNxMo64Dg1 SsfIwX/9a2Zh2CVNTyMzgQsqB; Received: from 97-122-110-129.hlrn.qwest.net ([97.122.110.129]:45562 helo=[192.168.0.17]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xGzf1-000000002J7-17Yx; Wed, 14 Oct 2026 08:08:51 -0600 From: Tom Tromey Date: Wed, 14 Oct 2026 08:08:49 -0600 Subject: [PATCH 1/5] Rewrite gdb.BreakpointLocation repr method MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261014-python-safety-breakpoint-v1-1-c8e72d58f3cd@tromey.com> References: <20261014-python-safety-breakpoint-v1-0-c8e72d58f3cd@tromey.com> In-Reply-To: <20261014-python-safety-breakpoint-v1-0-c8e72d58f3cd@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.110.129 X-Source-L: No X-Exim-ID: 1xGzf1-000000002J7-17Yx X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-129.hlrn.qwest.net ([192.168.0.17]) [97.122.110.129]:45562 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfG4E2BIikvfdSvxjFz5afe2bg3iOMdttKk7Yq05uIt6S9DiR3AI8oPyC7mlU2dLMdh9HY8PKvfjwJlf4h7Oe3vb9i+wLbDP35sz2FVNP8/Ej7CVyPcPg buWnf1SCMEM6ZLNw3ssZULmSByglidDDUvSVJymv/l7r5ADRSVr2HJcYX1f7uBJF8075Ou2Nl1YD2+fjyJ45RRnFcPkTkRdqjjc= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This rewrites the gdb.BreakpointLocation repr method to use the Python safety API. --- gdb/python/py-breakpoint.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index b1615db1be3..cb18fec11f9 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -44,6 +44,9 @@ struct gdbpy_breakpoint_location_object : public PyObject /* An owning reference to the location's breakpoint owner. */ gdbpy_breakpoint_object *owner; + + /* Implementation of 'repr'. */ + gdbpy_ref<> repr (); }; static_assert (gdb::is_python_allocatable_v); @@ -1716,40 +1719,41 @@ bplocpy_dealloc (PyObject *py_self) /* __repr__ implementation for gdb.BreakpointLocation. */ -static PyObject * -bplocpy_repr (PyObject *py_self) +gdbpy_ref<> +gdbpy_breakpoint_location_object::repr () { - const auto self = (gdbpy_breakpoint_location_object *) py_self; - if (self->owner == nullptr || self->owner->bp == nullptr - || self->owner->bp != self->bp_loc->owner) - return gdb_py_invalid_object_repr (py_self); + if (owner == nullptr || owner->bp == nullptr || owner->bp != bp_loc->owner) + /* FIXME: Python safety. gdb_py_invalid_object_repr ought to + throw on error, and return gdbpy_ref<>, but currently does + not. */ + return gdbpy_ref<> (gdb_py_invalid_object_repr (this)); - const auto enabled = self->bp_loc->enabled ? "enabled" : "disabled"; + const auto enabled = bp_loc->enabled ? "enabled" : "disabled"; std::string str (enabled); str += string_printf (" address=%s", - paddress (self->bp_loc->owner->gdbarch, - self->bp_loc->address)); + paddress (bp_loc->owner->gdbarch, + bp_loc->address)); - if (self->bp_loc->requested_address != self->bp_loc->address) + if (bp_loc->requested_address != bp_loc->address) str += string_printf (" requested_address=%s", - paddress (self->bp_loc->owner->gdbarch, - self->bp_loc->requested_address)); - if (self->bp_loc->symtab != nullptr) - str += string_printf (" source=%s:%d", self->bp_loc->symtab->filename (), - self->bp_loc->line_number); + paddress (bp_loc->owner->gdbarch, + bp_loc->requested_address)); + if (bp_loc->symtab != nullptr) + str += string_printf (" source=%s:%d", bp_loc->symtab->filename (), + bp_loc->line_number); - const auto fn_name = self->bp_loc->function_name.get (); + const auto fn_name = bp_loc->function_name.get (); if (fn_name != nullptr) { str += " in "; str += fn_name; } - return PyUnicode_FromFormat ("<%s %s>", - gdbpy_py_obj_tp_name (py_self).c_str (), - str.c_str ()); + return gdbpy_unicode_from_format ("<%s %s>", + gdbpy_py_obj_tp_name (this).c_str (), + str.c_str ()); } /* Attribute get/set Python definitions. */ @@ -1783,7 +1787,8 @@ PyTypeObject breakpoint_location_object_type = 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ - bplocpy_repr, /*tp_repr*/ + wrap_tp_callback, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ -- 2.49.0