From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oca4OlaNz2oLJgkAWB0awg (envelope-from ) for ; Wed, 14 Oct 2026 10:10:30 -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=P5EJrjry; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E8D0F1E050; Wed, 14 Oct 2026 10:10:30 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 5D6791E04E for ; Wed, 14 Oct 2026 10:10:30 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E83814BA23D6 for ; Wed, 14 Oct 2026 14:10:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E83814BA23D6 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=P5EJrjry Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 08F8B4BA2E3D for ; Wed, 14 Oct 2026 14:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08F8B4BA2E3D 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 08F8B4BA2E3D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791986939; cv=none; b=sPMtwxCa7qAHvdbni3xOYsXLIFA2sDLplpYDmqlG5AolPIVK8JiwnE8WWh2IoiF2SwTDTAS2ZpnMlfPlck5YTKA4jjI8w++Ed1V3WfDJtXm+ctJsPBcopkPBD7/2b+E7GyqqDeQ03cc7uRssw9dIfDyLlExkFNP1UkfGAlu2nyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791986939; c=relaxed/simple; bh=kHoyIdaWZZBE0gciT4FkLZpCGDRVR4bUK+79S+qj1HE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=sI2gt+oGsyAmNf5V5U0JggjLAPnpYd1e7UwWBl0KBkaHUweMjUCcS9wgRUeM8paCJxkOsdeYZ7LRwaVWTbJFlVPlZ4wCOH9xE23x/mWjCiBwC7ARjrst24mBiVFhkrIKiZcQCOdvJmeBOq/oOXIyf6/O5KC60vl5gYozH/MzP2g= 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=P5EJrjry reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08F8B4BA2E3D Received: from eig-obgw-5007b.ext.cloudfilter.net ([10.0.29.167]) by cmsmtp with ESMTPS id GvmFxLlaQc3XsGzf8xy97R; Wed, 14 Oct 2026 14:08:58 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Gzf3x6kELgNihGzf3xJ2vW; Wed, 14 Oct 2026 14:08:53 +0000 X-Authority-Analysis: v=2.4 cv=G78cE8k5 c=1 sm=1 tr=0 ts=6acf8cfa a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=ItBw4LHWJt0A:10 a=ImRR9NKHZFSlpMGYZSUA: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=eWvbBI79Lfk1nv7ZCyfcKSEMS0sackdHyMGOAC/3jLo=; b=P5EJrjryYiCXBbocJVIfABmTVw P+PaF64IaFtsfld0Nps0jQWDVim78bw4rHOWJMCy0EZsnZ+rG8CceyDclDMzIHwwrLIS2up7Al4t6 bd8Wk1x8GO9/Qds4r+oaV/4jX; 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 1xGzf3-000000002J7-0KvT; Wed, 14 Oct 2026 08:08:53 -0600 From: Tom Tromey Date: Wed, 14 Oct 2026 08:08:53 -0600 Subject: [PATCH 5/5] Rewrite gdb.BreakpointLocation setter MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261014-python-safety-breakpoint-v1-5-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: 1xGzf3-000000002J7-0KvT 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: 7 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfAI9+MD1go3e0sMgBB4Rkkm9cUYork4Hfwne8koEsqMeeupMeXTJXBN9kwdBY1YAAp6FSr68eT+Yhtn8sQDOjRpHLmdxJAAsxcm14W6udEx5yACgL64r g115xqI69NClZGEhGTinUAKSVulb3P1DHfU7tU1xjUuE2VihK3YYQgJN++oTUB4+R7CI4GB6CTB88OfWuJ/8Ruy7VEsTwKaPKkc= 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 one gdb.BreakpointLocation setter function to use the Python safety API. --- gdb/python/py-breakpoint.c | 56 +++++++++++++--------------------------------- gdb/python/py-ref.h | 7 ++++++ gdb/python/py-wrappers.h | 10 +++++++++ 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index b39093ebd81..f6d3ffc01f5 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -75,6 +75,10 @@ struct gdbpy_breakpoint_location_object : public PyObject return bp_loc->enabled; } + /* Python function to set the enabled state of a breakpoint + location. */ + void set_enabled (gdbpy_opt_borrowed_ref<> newvalue); + /* Python function to get owner of breakpoint location, which is of type gdb.Breakpoint. */ gdbpy_ref<> get_owner () const @@ -128,18 +132,6 @@ struct gdbpy_breakpoint_location_object : public PyObject static_assert (gdb::is_python_allocatable_v); -/* Require that BREAKPOINT and LOCATION->OWNER are the same; throw a Python - exception if they are not. This macro is for use in setter functions. */ -#define BPLOCPY_SET_REQUIRE_VALID(Breakpoint, Location) \ - do { \ - if ((Breakpoint)->bp != (Location)->bp_loc->owner) \ - { \ - PyErr_Format (PyExc_RuntimeError, \ - _("Breakpoint location is invalid.")); \ - return -1; \ - } \ - } while (0) - /* Debugging of Python breakpoints. */ static bool pybp_debug; @@ -1606,39 +1598,20 @@ GDBPY_INITIALIZE_FILE (gdbpy_initialize_breakpoint_locations); /* Python function to set the enabled state of a breakpoint location. */ -static int -bplocpy_set_enabled (PyObject *py_self, PyObject *newvalue, void *closure) +void +gdbpy_breakpoint_location_object::set_enabled + (gdbpy_opt_borrowed_ref<> newvalue) { - auto *self = (gdbpy_breakpoint_location_object *) py_self; - BPPY_SET_REQUIRE_VALID (self->owner); - BPLOCPY_SET_REQUIRE_VALID (self->owner, self); + require_valid (); if (newvalue == nullptr) - { - PyErr_SetString (PyExc_TypeError, - _("Cannot delete 'enabled' attribute.")); - return -1; - } + gdbpy_err_set_string (PyExc_TypeError, + _("Cannot delete 'enabled' attribute.")); else if (!PyBool_Check (newvalue)) - { - PyErr_SetString (PyExc_TypeError, - _("The value of 'enabled' must be a boolean.")); - return -1; - } + gdbpy_err_set_string (PyExc_TypeError, + _("The value of 'enabled' must be a boolean.")); - int cmp = PyObject_IsTrue (newvalue); - if (cmp < 0) - return -1; - - try - { - enable_disable_bp_location (self->bp_loc, cmp == 1); - } - catch (const gdb_exception &except) - { - return gdbpy_handle_gdb_exception (-1, except); - } - return 0; + enable_disable_bp_location (bp_loc, gdbpy_object_is_true (newvalue)); } /* Attempt to get fully resolved file path for symtab. */ @@ -1769,7 +1742,8 @@ static gdb_PyGetSetDef bp_location_object_getset[] = { { "enabled", wrap_getter, - bplocpy_set_enabled, + wrap_setter, "Boolean telling whether the breakpoint is enabled.", NULL }, { "owner", wrap_getter gdb_assert (this->m_obj != nullptr); } + template + gdbpy_borrowed_ref (const gdbpy_opt_borrowed_ref &ref) + : gdbpy_opt_borrowed_ref (ref) + { + gdb_assert (this->m_obj != nullptr); + } + gdbpy_borrowed_ref (std::nullptr_t) = delete; /* Allow a (checked) conversion to any subclass of T. */ diff --git a/gdb/python/py-wrappers.h b/gdb/python/py-wrappers.h index 5b1353872cc..fdb11d2a1fa 100644 --- a/gdb/python/py-wrappers.h +++ b/gdb/python/py-wrappers.h @@ -358,4 +358,14 @@ gdbpy_sequence_concat (gdbpy_borrowed_ref<> first, gdbpy_borrowed_ref<> second) return result; } +/* Wrapper for PyObject_IsTrue. */ +static inline bool +gdbpy_object_is_true (gdbpy_borrowed_ref<> val) +{ + int cmp = PyObject_IsTrue (val); + if (cmp < 0) + throw gdb_python_exception (); + return cmp; +} + #endif /* GDB_PYTHON_PY_WRAPPERS_H */ -- 2.49.0