From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2QCIEpmy22p00xAAWB0awg (envelope-from ) for ; Fri, 23 Oct 2026 15:16:41 -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=MuF3aogC; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 471C7378002; Fri, 23 Oct 2026 15:16:41 -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 7E8781E007 for ; Fri, 23 Oct 2026 15:16:40 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9E494BA23C9 for ; Fri, 23 Oct 2026 19:16:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9E494BA23C9 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=MuF3aogC Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id E85674BA2E15 for ; Fri, 23 Oct 2026 19:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E85674BA2E15 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 E85674BA2E15 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=1792782953; cv=none; b=Znq2/YKo34rfd4FKlMnDqMfMaoiOPDZemYFFSS56nfk24yymausGOYfBc0Q/vkDGywnfmCMDO4xQt7RtsbfHm/nXDnmQC+WKi8cwx0jRvm5kaBphiIjJyt8g3NF/m9oc5ads1kHNirGfxfdydU/hvMltxTQkUaA5VkQNkhUr0kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792782953; c=relaxed/simple; bh=ZFZKiVauBAbUV9sC80g19j57xLqDfgiA4aD2LGZIpoI=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=hP/F0I34v/QIm3zVtictn39wOXmT41tbwJuYKJkEYSegck/61+MWGdIplfMUhChttNK1CmqJkw8BdykoDFraJNXBk+MyGrR5e/ys9K6nNOUyTY8Z1xOSC2SDFLYVMp0oXIc8MxO8dZ89/+X1yrg1UAotekNHN32GhvUp1iTf/ZQ= 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=MuF3aogC reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E85674BA2E15 Received: from eig-obgw-6003b.ext.cloudfilter.net ([10.0.30.175]) by cmsmtp with ESMTPS id K4GLxxg6Tc3XsKKk3xEU7y; Fri, 23 Oct 2026 19:15:51 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id KKk3x4GEjzvPGKKk3xPsek; Fri, 23 Oct 2026 19:15:51 +0000 X-Authority-Analysis: v=2.4 cv=Y5f4sgeN c=1 sm=1 tr=0 ts=6adbb267 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=ItBw4LHWJt0A:10 a=WLFQ1AhLbOWlxlwZWqcA:9 a=QEXdDO2ut3YA:10 a=O8hF6Hzn-FEA: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=khv0P9OIPzro+ueumjbu098L0gnfOrkxnGwo5Lqt8AY=; b=MuF3aogCik9bzv89zQWc2+CcES 4TCVcKJcjvxHRMraknwn2XABXHT6JTLF6IZsCvaLp3Tr0hBncA/yq1PVrIcsSpbLWA/IAyByVBowX Yq9gzSQVorfBqNOv8g2dIwoCg; Received: from 97-122-110-129.hlrn.qwest.net ([97.122.110.129]:59452 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 1xKKk3-00000000DHL-0WLu; Fri, 23 Oct 2026 13:15:51 -0600 From: Tom Tromey Date: Fri, 23 Oct 2026 13:15:51 -0600 Subject: [PATCH 6/6] Some frame-related Python safety fixes MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261023-python-safety-fixmes-v1-6-055b9e1d237b@tromey.com> References: <20261023-python-safety-fixmes-v1-0-055b9e1d237b@tromey.com> In-Reply-To: <20261023-python-safety-fixmes-v1-0-055b9e1d237b@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: 1xKKk3-00000000DHL-0WLu 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]:59452 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: MS4xfPY1VnenVWd8ImuNT4BKxXwWVbn5CpMBDRCn1IGXpUHXO/MOetrEgFEJVWZa/Ik1/u0unVfKrkX0CVRBbof6Fi61uuCwrPdGxmlQj65u8EuXlRp39+wV ftUV8vroHiCAk+QOr1HbG1YoO1LZuY95tlDMYJSt3BwStYsUcvQITXXKqTIWZ8IQGWYdTJ5SxF3PQjOj5mHeuKKwhyc3o7CVVG0= 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 makes some frame-related Python safety fixes, with a goal of simplifying some code and removing some FIXMEs. A method can now return a frame_info_ptr; this will be handled by a new to_python overload. A safe wrapper is now provided for frame_info_to_frame_object. --- gdb/python/py-frame.c | 49 ++++++++++++++++---------------------------- gdb/python/py-inferior.c | 2 +- gdb/python/py-safety.h | 11 ++++++++++ gdb/python/python-internal.h | 5 +++-- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index e34d4b5d2e9..f9e95f3aec3 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -108,12 +108,12 @@ struct frame_object : public PyObject /* Implementation of gdb.Frame.older (self) -> gdb.Frame. Returns the frame immediately older (outer) to this frame, or None if there isn't one. */ - gdbpy_ref<> older (); + frame_info_ptr older (); /* Implementation of gdb.Frame.newer (self) -> gdb.Frame. Returns the frame immediately newer (inner) to this frame, or None if there isn't one. */ - gdbpy_ref<> newer (); + frame_info_ptr newer (); /* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line. Returns the frame's symtab and line. */ @@ -282,8 +282,6 @@ frame_object::function () /* Convert a frame_info struct to a Python Frame object. Sets a Python exception and returns NULL on error. */ -/* FIXME: Python safety. This function should be converted, but the - callers aren't ready yet. */ gdbpy_ref<> frame_info_to_frame_object (const frame_info_ptr &frame) @@ -307,27 +305,26 @@ frame_info_to_frame_object (const frame_info_ptr &frame) } gdbpy_ref<> +safe_frame_info_to_frame_object (const frame_info_ptr &frame) +{ + gdbpy_ref<> result = frame_info_to_frame_object (frame); + if (result == nullptr) + throw gdb_python_exception (); + return result; +} + +frame_info_ptr frame_object::older () { frame_info_ptr frame = require_frame (); - frame_info_ptr prev = get_prev_frame (frame); - - if (prev) - return frame_info_to_frame_object (prev); - - return py_none (); + return get_prev_frame (frame); } -gdbpy_ref<> +frame_info_ptr frame_object::newer () { frame_info_ptr frame = require_frame (); - frame_info_ptr next = get_next_frame (frame); - - if (next) - return frame_info_to_frame_object (next); - - return py_none (); + return get_next_frame (frame); } gdbpy_ref<> @@ -431,29 +428,19 @@ frame_object::static_link () /* Implementation of gdb.newest_frame () -> gdb.Frame. Returns the newest frame object. */ -gdbpy_ref<> +frame_info_ptr gdbpy_newest_frame () { - /* FIXME: Python safety. Convert frame_info_to_frame_object. */ - gdbpy_ref<> result = frame_info_to_frame_object (get_current_frame ()); - if (result == nullptr) - throw gdb_python_exception (); - return result; + return get_current_frame (); } /* Implementation of gdb.selected_frame () -> gdb.Frame. Returns the selected frame object. */ -gdbpy_ref<> +frame_info_ptr gdbpy_selected_frame () { - frame_info_ptr frame - = get_selected_frame ("No frame is currently selected."); - /* FIXME: Python safety. Convert frame_info_to_frame_object. */ - gdbpy_ref<> result = frame_info_to_frame_object (frame); - if (result == nullptr) - throw gdb_python_exception (); - return result; + return get_selected_frame ("No frame is currently selected."); } /* Implementation of gdb.stop_reason_string (Integer) -> String. diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 5e77f9f37bd..84a4b1ae6ee 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -1023,7 +1023,7 @@ python_context_changed (user_selected_what selection) try { if (has_stack_frames ()) - frame_obj = gdbpy_selected_frame (); + frame_obj = safe_frame_info_to_frame_object (gdbpy_selected_frame ()); else frame_obj = py_none (); } diff --git a/gdb/python/py-safety.h b/gdb/python/py-safety.h index 0d5a45e72fd..b8e6434d168 100644 --- a/gdb/python/py-safety.h +++ b/gdb/python/py-safety.h @@ -120,6 +120,17 @@ to_python (gdbpy_ref<> &&value) return value.release (); } +static inline PyObject * +to_python (const frame_info_ptr &frame) +{ + if (frame.is_null ()) + return py_none ().release (); + + /* Note that currently this might return NULL on error; but that is + fine in this context. */ + return frame_info_to_frame_object (frame).release (); +} + static inline PyObject * to_python (symbol *sym) { diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index ee1a19131bd..8aaf96021f7 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -543,8 +543,8 @@ gdbpy_ref<> gdbpy_lookup_static_symbols (gdbpy_borrowed_ref<> args, PyObject *gdbpy_start_recording (PyObject *self, PyObject *args); PyObject *gdbpy_current_recording (PyObject *self, PyObject *args); PyObject *gdbpy_stop_recording (PyObject *self, PyObject *args); -gdbpy_ref<> gdbpy_newest_frame (); -gdbpy_ref<> gdbpy_selected_frame (); +frame_info_ptr gdbpy_newest_frame (); +frame_info_ptr gdbpy_selected_frame (); PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw); int gdbpy_is_field (PyObject *obj); PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length, @@ -578,6 +578,7 @@ gdbpy_ref<> block_to_block_object (const struct block *block, gdbpy_ref<> value_to_value_object (struct value *v); gdbpy_ref<> type_to_type_object (struct type *); gdbpy_ref<> frame_info_to_frame_object (const frame_info_ptr &frame); +gdbpy_ref<> safe_frame_info_to_frame_object (const frame_info_ptr &frame); gdbpy_ref<> symtab_to_linetable_object (PyObject *symtab); gdbpy_ref<> pspace_to_pspace_object (struct program_space *); PyObject *pspy_get_printers (PyObject *, void *); -- 2.49.0