From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cdIrBXrPsmmmEiYAWB0awg (envelope-from ) for ; Thu, 12 Mar 2026 10:36:42 -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=Bc7u/59Y; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 118F31E08D; Thu, 12 Mar 2026 10:36:42 -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_MSPIKE_H2,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 3EAC71E08D for ; Thu, 12 Mar 2026 10:36:41 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id B11794BBCD9B for ; Thu, 12 Mar 2026 14:36:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B11794BBCD9B 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=Bc7u/59Y 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 B85C94B9DB55 for ; Thu, 12 Mar 2026 14:36:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B85C94B9DB55 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 B85C94B9DB55 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=1773326173; cv=none; b=LEX/XbjFyCToybce5a7Oy6k2x79K7HirVUYjQqoGe/RJiku8OunviQWLYZBAP/Dv/Q0xYo8kvkazPib9or9DDoEGW4eTT9Tuj+TXX5eS8vkdx3TY/XZa6NgUxDnyzeunf4efBmkM+BwLgQ5dggRylfxjJQEY5w6M9zofw4JDyCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773326173; c=relaxed/simple; bh=1BvFM2KJDws774sqYapRoWlNAKbgL+3dPFkAfOx63vk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=L9fPRBz2Le1Yb9UIs3VxnNFC5YFo4Ok4Wmn/YN4NDb++6L0IxQS5WCG/n3czVfGArTqN1f6IJ78agtiM3PPuoChYBArzKgu3vXx1rsk1q1lyLBE/Eo3Fv2fqWb46Np0tGHRuMHjLfXjjZbtoSmUCOidByd0OFVO+mXloLf5/u9A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B85C94B9DB55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=labware.com; s=mimecast20220511; t=1773326173; 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=fxHFpn5uw5OcRv8+m5AhTvx9gVeIGFqM6YR5HS4qgI8=; b=Bc7u/59Yao0CdM9q0vQHEioOxAzqHj5FPf0oUWZII/utO7QaLXP7oBNTcISqxHOI7Kn8QK c+rF2wOAx0XiquXzOCo1Pf+8vWgjZTO+apfq9ac2AhqXlHZvWMf4OTSYEqfxQpIm7+CU7P 6tqStT81AqNmAQSir3So9JlulQmjV20= Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11022100.outbound.protection.outlook.com [52.101.43.100]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-EnswGmJoMCa6ETJdh9nPKg-1; Thu, 12 Mar 2026 10:36:12 -0400 X-MC-Unique: EnswGmJoMCa6ETJdh9nPKg-1 X-Mimecast-MFC-AGG-ID: EnswGmJoMCa6ETJdh9nPKg_1773326171 Received: from SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) by CH0PR17MB6915.namprd17.prod.outlook.com (2603:10b6:610:18a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9700.13; Thu, 12 Mar 2026 14:36:07 +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.013; Thu, 12 Mar 2026 14:36:06 +0000 From: Jan Vrany To: gdb-patches@sourceware.org, tom@tromey.com CC: Jan Vrany , Eli Zaretskii Subject: [PATCH v2] gdb/python: add property ranges to gdb.Block object Date: Thu, 12 Mar 2026 14:33:46 +0000 Message-ID: <20260312143344.4147036-3-jan.vrany@labware.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <87bjgttecc.fsf@tromey.com> References: <87bjgttecc.fsf@tromey.com> X-ClientProxiedBy: AM0PR02CA0125.eurprd02.prod.outlook.com (2603:10a6:20b:28c::22) To SA1PR17MB5365.namprd17.prod.outlook.com (2603:10b6:806:1d8::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR17MB5365:EE_|CH0PR17MB6915:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ad295dd-b767-4634-8dd2-08de8044b0be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|376014|56012099003|18002099003|22082099003 X-Microsoft-Antispam-Message-Info: zjE49YlkNidohqkbJ7qDPi+W8fPUiBt8d4Uqls9cj/ocYiVQQSH9dlOzqvFhQxzjPlHyg/WL2WHSds6TK/MS47yNpMWPZOY4TnLXt1fv9s3GwTjJ9/gm/nz+lel+8XLI55LP8DbGorhBIW+Hyt5S2ThA4n36Rm0iFn/XGa6IKcXwgLOVq8gcfjnpN+Itvu41y/NuCruxJp5IyYnyTQs+3xGAD7n8OGRQFs7FJvTqpuBRy/X3yvEV1pzfuZMY1dUGufVmRJekgpvHGcDVOI5stfAbBJVOCIzno+wMysIjOxOiNK0F0facYas3iYe893yyl0G0fL3FLa/AIPCuyVdF+BTgCLT5SOIKOFWwFlfSgp7hf08kxbWFS9FLMAzO5BwRXcIPAZ06wFfyWB4qoSpnosyQNS4YJ6R7B1qeVAeBpvETx2weQz13bMS7cgaWDEccxsxAoasQKlwN3Svlzv0RKkDwUMRi7jUypn+asMBLvEDSLK4Vavt+IB8qGu0moZcjCJHRgy2+sQzasR7FJXzGXYz7K43xTpid2RvFg/iPj+JlY6Mx4VA5ii5nkNlNMpWtEWjEbHQPPheJ1BK2anrqX9DZP+rHu8T8RXyXYGdzs3Ke9vqyR6lmPfRoozvuUbGTH2Ff4bkJnhR+LVb8O9UENXsdizZ4D50kBcggE7kZOfL01FMNn2/tQ/DBkhY+OCTtERLL3dzoOO/0d4LlYXwbzch3z01hjgbYhrmYpp5DWyQ= 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)(56012099003)(18002099003)(22082099003); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?D0qrB68q+oXYL2dOyf+cX1qdxJh1eacAAiBwOe8TPz4CcIdE0NaRxH3SREbx?= =?us-ascii?Q?GhCuxB1adTB5EmfIwjvJ1DUqcM/vViIiqnbeDkYoy9VwtXwW3kq/olMb9CJN?= =?us-ascii?Q?bQBhmzNdpqc/m6qBTNZr/3yQDYeJvVozZmyv1S4Es2Z0tXLReTAT32lCGUQA?= =?us-ascii?Q?AjzNHEgNlLub+sqkiKF00eC0TRiRpurwldxsynzv12tqKsshIuxp2uD2c4Ua?= =?us-ascii?Q?SQ9oHJ/byB83beMeva5rVF2FKjKhSEKxTZ+NUKU61CTVjB2o7/dHIEu1V4TL?= =?us-ascii?Q?0gV3RunEAetD0XVUY/N5xabUqQMEry+uQKh4gOD85d+OR/xXgleL8cObiZlm?= =?us-ascii?Q?L/g0pyLwwOV3AWxetHLkojMsFsquhdmSXkPktlqgAuEXRs+42cRIEJb0qW5J?= =?us-ascii?Q?6qmJL77BmdSfkJ6RJ2sb4bTI56sUbdA2ufLCTkpoouOvhctifCrxz8lLk7s+?= =?us-ascii?Q?c6bVX1yCgpIy2tlDLOEyiEOAw5UZ0TSgkDbxqwRj5k2YDOLh809Y3XLSjnXo?= =?us-ascii?Q?cT6ka6WIE/ENIVGeSF4uIlb/XyxUJ9wrSdlYXW6Bj9sT3Ngw5HRSkmBHj3EE?= =?us-ascii?Q?eVuQpMsBHLX5quBbFDmGRweXC4CmMRfHjpTTceu+H4EvHIwk9w8R6OT3/j4O?= =?us-ascii?Q?Pdc/CuJWl8/rD+jXstAT75QRsDVvw60Fyb79oOSjn+ecvNyZnNLtH5jexHL7?= =?us-ascii?Q?pTSjo5CLz3yxJZVJ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?us-ascii?Q?ueIZLkma2Vr6ddKm7SljTOjG0WdTZsNTS1M0Jk+cVr5JM8h4V2EYExlsBHZa?= =?us-ascii?Q?bPXRbrsuBAcucwuror2cnhe8dtuwrdErx16Emei8pa2DkhPUxWVfGr9qyx8d?= =?us-ascii?Q?XQXXwc5ODA=3D=3D?= X-Exchange-RoutingPolicyChecked: oqJByjikrW4ficn9frc16wG7369m2wBXHvPHWDELTEpN005hjurRKR+zC6MY7RQTXM2DfDGbkgq2VlHm4Wk9Fa502UTl/sjXvGVAOS7IBqAO+d8csbhW8xoPO1RUiRFMor9WwHC0Mwf6CGylzNQgZDeJnGrn2lIRpudpbLqhvv+BJeRVNvrCKnkt9Fl+qxVa2bOSLz117jqwZMrayQlNQbrn+v73AFiqy00BvxehhnDoFxUD636OGafkR349x0pHst6d5CIqibrWOPYyBYZCmW+z/IubFNMeXQQ6lPUh769UMGN+6jsYqFXn6ziSMBV0cjfLXBfnj1MnzBFkCiX7hQ== X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ad295dd-b767-4634-8dd2-08de8044b0be X-MS-Exchange-CrossTenant-AuthSource: SA1PR17MB5365.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2026 14:36:06.5231 (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: r5FMEX6kgxeunygybF0V01TnCknciHE5Hgq5f8KAL0jD1eCksV5j3vM4Y6oCZOEgrhKJ2agtKb1avt7HeJ0eJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR17MB6915 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: nWOtNxD95K7JRqoJwrrMnfkgMASl5yGuioIhVgbim30_1773326171 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 06:35 -0600, Tom Tromey wrote: > Jan> +=09 gdbpy_ref<> range_obj (Py_BuildValue ("(KK)", ranges[i].start = (), > Jan> +=09=09=09=09=09=09ranges[i].end ())); > > Another error check. > > Someday maybe we'll land the "safety" approach and this stuff will be eas= ier. Thanks, fixed below. 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 | 35 +++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-block.exp | 3 +++ 4 files changed, 50 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..6d3cb1d0bd5 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -117,6 +117,39 @@ 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 ("((KK))", block->start (), 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 (Py_BuildValue ("(KK)", ranges[i].start (), +=09=09=09=09=09=09ranges[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 +597,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