From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KDQFITAitGlSnCcAWB0awg (envelope-from ) for ; Fri, 13 Mar 2026 10:41:52 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=labware.com header.i=@labware.com header.a=rsa-sha256 header.s=mimecast20220511 header.b=czw9hSfn; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6E0701E0DD; Fri, 13 Mar 2026 10:41:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham 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 D672C1E08D for ; Fri, 13 Mar 2026 10:41:50 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 426B94BC895A for ; Fri, 13 Mar 2026 14:41:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 426B94BC895A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=labware.com header.i=@labware.com header.a=rsa-sha256 header.s=mimecast20220511 header.b=czw9hSfn Received: from us-smtp-delivery-114.mimecast.com (us-smtp-delivery-114.mimecast.com [170.10.129.114]) by sourceware.org (Postfix) with ESMTP id 88CEB4BC8975 for ; Fri, 13 Mar 2026 14:41:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88CEB4BC8975 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=labware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=labware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 88CEB4BC8975 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773412881; cv=none; b=EcdttULda5CsWawgoJ+8hQIS52G+Vdxrl3kLkaCgvqyfQwDk+4pK+nvw+uHJ7lBi+xZIqL+d2fBotLm6+tPbcZPYtI0H5UfzMTgTrIdwYBJj8Zt5RPK/hh7DnGrlu25khG4Hhsr1iTL3Id8QS7A5Ylu2Dg1yfzm03Fq7DuWBIbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773412881; c=relaxed/simple; bh=Q96H1w27jsqOfywGLBm8r89zxorv3J4BClJiZVvpWfE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=P5rXA1WaGSe23WvIklEb32odghVm/OMYyQoOOQppozHDyJ8JW35f62oyBAk8dU0lxAUF6oM3SjUMBKo9RE+8IkSgwQEuh8FFCO1vpB+tg7+L9xxBaEJPOoaqbwO05gKWRnnjHUt9MlxKFSsrK8fYRbpLa/Lz5IAH/1fnSa1HysE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88CEB4BC8975 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=labware.com; s=mimecast20220511; t=1773412881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+U3LT84mbCwWaNw6Xnw64xrO2+vzf/NCnXZ6bVDxWC0=; b=czw9hSfnS0F+plhrWUC2D9XEfziOyWLK5iJo9VWoRgPG7v6awvcaLQ2E4Sg0GctmAfmoPQ 86jYUTRo0RIcBrUX3ulmUCmSOp2vPKQK4BCDM19JxR2rOUgm/WFUfZ8EV12mQCwPZLEmQj xW39eQ1xRZfpAtgZuMlh/luiSu18wPE= Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11023120.outbound.protection.outlook.com [40.107.201.120]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-bHfUR0rAP2CQa-rr_ZglVg-1; Fri, 13 Mar 2026 10:41:20 -0400 X-MC-Unique: bHfUR0rAP2CQa-rr_ZglVg-1 X-Mimecast-MFC-AGG-ID: bHfUR0rAP2CQa-rr_ZglVg_1773412878 Received: from SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) by IA3PR17MB7861.namprd17.prod.outlook.com (2603:10b6:208:541::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.15; Fri, 13 Mar 2026 14:41:16 +0000 Received: from SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::9a:538a:fa42:730e]) by SA1PR17MB5365.namprd17.prod.outlook.com ([fe80::9a:538a:fa42:730e%3]) with mapi id 15.20.9700.015; Fri, 13 Mar 2026 14:41:16 +0000 From: Jan Vrany To: gdb-patches@sourceware.org CC: Jan Vrany , Eli Zaretskii Subject: [PATCH v3] gdb/python: add property ranges to gdb.Block object Date: Fri, 13 Mar 2026 14:40:19 +0000 Message-ID: <20260313144019.273153-1-jan.vrany@labware.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <87y0jxrsdu.fsf@tromey.com> References: <87y0jxrsdu.fsf@tromey.com> X-ClientProxiedBy: LO4P123CA0638.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:296::18) To SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR17MB5365:EE_|IA3PR17MB7861:EE_ X-MS-Office365-Filtering-Correlation-Id: 8581071e-d72e-459a-fbbb-08de810e94cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|376014|18002099003|56012099003|22082099003 X-Microsoft-Antispam-Message-Info: KmLVWDkCSzTvnQ20l5Yhoz/2Y2Zen6B/EDEMc/wMAq1WxdMhUu7qse79mY55wrN/3O5n5jwBlnyHiYZsBmzAbHwryHjiYQj55UviiPM7mGBIjeqO3YohbrizQUk5w9bw8m6fpN+DjiPJorz/b/HVZC4NGTPBpmQCRA1M6m6z2mfwUHpkQ5zghZLaOC8JtWX1v/dspBn0Q7vBfP0BYzEaZ6isme3bBI4RdiUmOQWEpRC+XiSz2GkTs8DtYTqJtxrBOShsS8/TAfIiccVrPM9eePYSlh8EglFuIIfI1ltW6dfY61Fd8/6Tlau+G2uPmBjhDwKi6/jGlb0CTk0IjkcgoLLFeSDckmX4KkQlzYuKqrQvjdGAOwBfK0iuhFUsWpfclQkmkcJ+T/a0BDAridsGeYYTIm32nCQxnqf5mc+ikrrM+9byjvdypM2349TqphvEJti5+5zU2+BNYy9ry00tEBcyK6mspwlX9QAPwwCb8bbfb9M8mpvccJ2MhQiOGGPU5EvgRWyr0ze58lAn9wkGU6i4UTe9v9SCdrueSzV0kG+elDB8qqLb59bNHG1T1e9SLJetJ9Wc8KoG1OC5IjggyaVCKZ4nneYb2ROEDVNOA/vm8En8hvzyHINuDdrvE7J2Jb5jRlL3Ls1067WhAq8JBYuTaw4RinRkKslmn+VWHMawJRo3BdnmEHUnFLPq//Jw0QV6lZNe5mUg6NaHCSLE6mRHrVTr4bB/0Ht9ma7CJNw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR17MB5365.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(18002099003)(56012099003)(22082099003); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?g8/O/piwiTiXya8yN+2J7lu5jOFT4SVMI511OdUSMUkouJM+WIvyay6ZnXfW?= =?us-ascii?Q?NEvirPv3YDi26qZxHB4KYCXYMsyWxf8uG+t+YrB4Z8Sn7uHHlq2iVbySG/Xy?= =?us-ascii?Q?kTFhNcqIMLFzKAsjTUDxWtZjzZy4wklscmKcQF4oTyjDAvbF6x8dIGVOrghu?= =?us-ascii?Q?dMoHWq1FbU8CDITWMLzvFUJuBOUZV+0a7Wz9I9OSF2JuROzWx2ak2eFoKVFu?= =?us-ascii?Q?My3eUxcHI7YdUZ6q+j6CCfRma9sAFBb7Dt/T/LEsiBUNdpxi1BkT2alcZ/HT?= =?us-ascii?Q?nFpYgusqAUyr4+RSaeKtHRQhm605jsGDtqB8Ahcn1IduX+/xi4zK56uecov/?= =?us-ascii?Q?DL9ZNJEgjhD1Hz62x1IWDW+xZvm67oH+Zkmfg+B95Jv6zwyjQ4msSHBWX8As?= =?us-ascii?Q?l0+Z6uBEOBYCqlSYlCPP2G4YPyUyT6nCRPpDU6WUiBRvKvGAqMuMO5KVqRWv?= =?us-ascii?Q?8BtD3o7zm/5Hr7UFmS5NIxf9FX0IMKcwbTVUNFXSkWzB2DYf4dt7AeCUCtZy?= =?us-ascii?Q?sGmtPO4KpDrXcV8hH0j0pj6/WgFhko4ohf397zei01s83ZYXMp2WC/WzVIY+?= =?us-ascii?Q?NzHn3tWSFlD9gdOLKGRYtI6gCYPo073U5BzPLdg7hka1829Ux7exyfyNe03K?= =?us-ascii?Q?vjZ0nXVr1RWkj2UpNfKRiqFQ8t0Dovi3Q++pgQURysgWfaMNTZm4rUJUJNc1?= =?us-ascii?Q?y6KvuAaIkJXQkcjeAd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us-ascii?Q?hpgqbQnSr8yv6klQ+xKD9GgqfXy1cUyQOXAFyonHD2K9Q7CkWaC5GRNIpnHX?= =?us-ascii?Q?dZCPHF6GLavLxHr83QOblI/P1BF2AsRzhY8frsfKFbZiZ3sePqnDO6hg/XoF?= =?us-ascii?Q?ZDNgi6ec2w=3D=3D?= X-Exchange-RoutingPolicyChecked: b956Qi76IpTz2bJJJdVvG4G4K4dk9nwjymO9Q2dP6ZWXaIxCBcbBpMyMzuISqaQAaKqsknzWHQVR9ZeYnJKbPmsIrUSVVs+oFQCVfXnUyw63fvTdclTi10BWQ73u5m1WFe0gk8rn2MPMHq7FHWuHmFMIl+Vo6bdP9HiJxXonQJGcaLejIUrp80QDrH787ln8108VEuQ8kxqnsGFgDQfXXXt7kNDwMg/sUGicRXsKRK0wTZu9ST+eCASSRFf4bKHPbAxd9RqUy1o26yRvHXITtQt7LU/I909L5aTimaWvmI5h7YgQV/NPkYNIV8yKOR+06H/7cZIv1anJUiKnwlpJ4w== X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8581071e-d72e-459a-fbbb-08de810e94cf X-MS-Exchange-CrossTenant-AuthSource: SA1PR17MB5365.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2026 14:41:16.6087 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WwoFPY7yUtYBmp2XLEMSyAu8sb/Vil1ldHfW72Ff2fpEwpjhKag/uirDtMhHRqEmenD5QAMUKnSUHGw0Ey0o/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA3PR17MB7861 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MmIuuGu3kqTHkX35oKBsQ3fHDgiqfBdePm6CF_cuoGQ_1773412878 X-Mimecast-Originator: labware.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252 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 > On Thu, 2026-03-12 at 09:15 -0600, Tom Tromey wrote: > > Also, we apparently still support versions of Python that don't > guarantee "long long" support. There's some text in python-internal.h > about this, look for "HAVE_LONG_LONG". > > So I think this code needs to use GDB_PY_LLU_ARG and have explicit casts > to gdb_py_ulongest. I see. The v3 below does that. > > Or maybe be written in some other way. > I tried to use "(OO)", gdb_py_object_from_ulongest(start), gdb_py_object_fr= om_ulongest(end) but that did not look significantly better to me. I do not like the need to test for block::ranges to be empty. I experimente= d with making block::ranges to always return at least one range, it turns out it simplifies the code on more places (except block::relocate). I plan to send this in a separate series soon(ish). Thanks, Jan -- 8< -- This commit adds a new property - ranges - to gdb.Block object. It holds a tuple of ranges for that block. Each range is a tuple of (start, end) address. For contiguous blocks it contains only one range. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 4 +++ gdb/doc/python.texi | 8 ++++++ gdb/python/py-block.c | 39 +++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-block.exp | 3 +++ 4 files changed, 54 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index e46a5108272..e48eecbeb7c 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -229,6 +229,10 @@ qExecAndArgs the appropriate user setting is enabled, and GDB knows how to style this source file. =20 + ** New gdb.Block.ranges attribute. This read only attribute contains + a tuple of pairs each representing a single range. Contiguous blocks + have only one range. + * Guile API =20 ** Procedures 'memory-port-read-buffer-size', diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 2df3b7c0423..05e00d8370f 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -6342,6 +6342,14 @@ One past the last address that appears in the block.= This attribute is not writable. @end defvar =20 +@defvar Block.ranges +A tuple representing address ranges of the block. Each range is represent= ed +as a pair (two-element tuple) where the first element is the start of the +range and the second element is one past the last address that appears in +the range. The order of ranges is unspecified. Contiguous blocks have onl= y +one range. This attribute is not writable. +@end defvar + @defvar Block.function The name of the block represented as a @code{gdb.Symbol}. If the block is not named, then this attribute holds @code{None}. This diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 4d77242ca0d..6e4b662cc51 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -117,6 +117,43 @@ blpy_get_end (PyObject *self, void *closure) return gdb_py_object_from_ulongest (block->end ()).release (); } =20 +/* Implementation of gdb.Block.ranges. */ + +static PyObject * +blpy_get_ranges (PyObject *self, void *closure) +{ + const struct block *block =3D nullptr; + + BLPY_REQUIRE_VALID (self, block); + + auto ranges =3D block->ranges (); + + if (ranges.size () =3D=3D 0) + return Py_BuildValue ("((" GDB_PY_LLU_ARG GDB_PY_LLU_ARG "))", +=09=09=09 (gdb_py_ulongest) block->start (), +=09=09=09 (gdb_py_ulongest) block->end ()); + else + { + gdbpy_ref<> ranges_obj (PyTuple_New (ranges.size ())); + if (ranges_obj =3D=3D nullptr) +=09return nullptr; + + for (int i =3D 0; i < ranges.size (); i++) +=09{ +=09 gdbpy_ref<> range_obj +=09 (Py_BuildValue ("(" GDB_PY_LLU_ARG GDB_PY_LLU_ARG ")", +=09=09=09 (gdb_py_ulongest) ranges[i].start (), +=09=09=09 (gdb_py_ulongest) ranges[i].end ())); +=09 if (range_obj =3D=3D nullptr) +=09 return nullptr; + +=09 PyTuple_SetItem (ranges_obj.get (), i, range_obj.release ()); +=09} + + return ranges_obj.release (); + } +} + static PyObject * blpy_get_function (PyObject *self, void *closure) { @@ -564,6 +601,8 @@ static gdb_PyGetSetDef block_object_getset[] =3D { "Whether this block is a global block.", NULL }, { "subblocks", blpy_get_subblocks, nullptr, "List of blocks contained in this block.", nullptr }, + { "ranges", blpy_get_ranges, nullptr, + "List of address ranges for this block.", nullptr }, { NULL } /* Sentinel */ }; =20 diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.pyth= on/py-block.exp index b483d4b8a92..e4e309da05f 100644 --- a/gdb/testsuite/gdb.python/py-block.exp +++ b/gdb/testsuite/gdb.python/py-block.exp @@ -43,6 +43,9 @@ gdb_test "python print (block)" " \= {i, f, b\}>" \ gdb_test "python print (block.function)" "None" "first anonymous block" gdb_test "python print (block.start)" "${decimal}" "check start not None" gdb_test "python print (block.end)" "${decimal}" "check end not None" +gdb_test "python print (block.ranges)" \ +=09 "\\(\\(${decimal}, ${decimal}\\)(,|(, (\\(${decimal}, ${decimal}\\))+)= )\\)" \ +=09 "check ranges contains tuple of tuples" gdb_test "python print (block\['f'\].name =3D=3D 'f')" "True" "check varia= ble access" gdb_test "python print (block\['nonexistent'\])" ".*KeyError.*: 'nonexiste= nt'.*" \ =09 "check nonexistent variable" --=20 2.51.0