| Message ID | 20241121124714.419946-2-jan.vrany@labware.com |
|---|---|
| State | New |
| Headers |
Return-Path: <gdb-patches-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16B07385701E for <patchwork@sourceware.org>; Thu, 21 Nov 2024 12:50:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16B07385701E X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-114.mimecast.com (us-smtp-delivery-114.mimecast.com [170.10.133.114]) by sourceware.org (Postfix) with ESMTP id 442C23857BA5 for <gdb-patches@sourceware.org>; Thu, 21 Nov 2024 12:47:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 442C23857BA5 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 442C23857BA5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732193253; cv=none; b=v4GpPVtCw/UUhLvb3jta/t2cohdY3RLMHktEI1gexLSfoO5RiK+gm6SUQMDgfYU+xUECqAqYnMWr5vGNiDMkJa6mlivK3VPT0sZYUT0kZlgD/namwop1DGkXi1ipJO42iCWUZRXWgjnuP3rskddnUHYXNdD5IVbKLF3xpk2zv9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732193253; c=relaxed/simple; bh=0hlCXuhWVYOBfGHvaUHND8pmXyMqz875lxYFX/ldtA8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CxOD/e3XYt1zYat6itMGgXhE2ZVzaYon79usklhn1zVdIfWgcOOv0lBFqCjvSpDN+zYMySUKxtVUxbVJEBLs+tUdWr4K8DYkeQlER6wbqvrqfqlSpHh5TvwtcHpf610Ddj8LHcooEIpShFcE1s10rpqyW27ODKBiVtBpLQ0T3M0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 442C23857BA5 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-kxc7kVIiMte-johAlJi4HQ-1; Thu, 21 Nov 2024 07:47:32 -0500 X-MC-Unique: kxc7kVIiMte-johAlJi4HQ-1 X-Mimecast-MFC-AGG-ID: kxc7kVIiMte-johAlJi4HQ Received: from SA0PR17MB4314.namprd17.prod.outlook.com (2603:10b6:806:e7::16) by SA1PR17MB6504.namprd17.prod.outlook.com (2603:10b6:806:337::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Thu, 21 Nov 2024 12:47:30 +0000 Received: from SA0PR17MB4314.namprd17.prod.outlook.com ([fe80::38a7:a6f2:3b95:bc26]) by SA0PR17MB4314.namprd17.prod.outlook.com ([fe80::38a7:a6f2:3b95:bc26%5]) with mapi id 15.20.8158.023; Thu, 21 Nov 2024 12:47:30 +0000 From: Jan Vrany <jan.vrany@labware.com> To: gdb-patches@sourceware.org CC: Jan Vrany <jan.vrany@labware.com> Subject: [RFC v2 01/21] gdb: update is_addr_in_objfile to support "dynamic" objfiles Date: Thu, 21 Nov 2024 12:46:54 +0000 Message-ID: <20241121124714.419946-2-jan.vrany@labware.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121124714.419946-1-jan.vrany@labware.com> References: <20241121124714.419946-1-jan.vrany@labware.com> X-ClientProxiedBy: LO4P123CA0289.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::6) To SA0PR17MB4314.namprd17.prod.outlook.com (2603:10b6:806:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA0PR17MB4314:EE_|SA1PR17MB6504:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e2d66b5-219f-45d4-a52a-08dd0a2aa967 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014 X-Microsoft-Antispam-Message-Info: JgNc/SdTbO0UOnCtOEzZow4qu6SdgYTtMmpKyyaVcao+VzXKOAypWiq8RHQXMNEtbt+zy0dYJn/eVIYRweUjIYRRGNjnI+4mkpOqTT5vwTzzVzE3XIvZBTZsH0ucu+abm9ucRhLsywUSkCNTDGwi30mXcfTNwtsdzKBmYwpa97/TZmkPK7vfPOr6QprB6vDjQslzv7o5J/XRW8G5N1fRmjVy36EsPEjS5RmZfVpZ+hU3W5UozdwM+4fg17vfkUpb7LtSS3RwORYNv7T/ETNYrTMII5/OoVbA8caS8poDJe9e4Xl9HugP2KoP1vKUX/iXcM+hWuZvJFtp4Dc1msaKpJm3T8cjIepxWIdC21iwWA8fR2amcIHfS7XNfXzOpyZOfzRrjh1uGc2gpwxv7ntIKud2seoPNMcEEwTiyGtdCQ4po02CxXS5r/KK43C7qL7VUc5wcEgOckEFcM60ugKK43ozlyAmp+94b5lB7mpBPGRLnU9+M0lRAsFOYvGZzd1fakgwI4RdD+HAUNJNE6NFbZSuCnrFbXF6vWqd6wsNCoOt4G3qzvh/WCydUUSMXVzGcbEemS1ArxgNKFLnBmd86s4S7NBsoCTalbbZJXs8mgPl3DuBkjDMkUREgN5wv7Z7NegN9rcRrxP2A9DB6n6hiVKHWtkhSUJyw7F+C4lDCtgUOzXnRMf6Ocxhmv6HwhDEu1+mA5gIbK9nCPS6VI9v6KpokPmAIdG0BQ7NXYVclFxpalIOo3Xe1v9f+01NxHaREXGD5exnN6+LfCJtdbzA/Wprc+3s0TWBSqtUVrN0iN/meTFd2usws0PNsXqT2z33XbU9p0meuTJEuQoXmHzPxJbeLRQBMGgqjpzxdhR8sYi7zI7lJO98KKeR/gTC2RwGteMOjm2y0oaDCEXxtmoFIUyoRZ701VAoANxN0ffuYd6+/nLOU+KC2o6bNXrs+OhbSQpoug8nEZnSwiZMU2xc/Ydyc5lWMuKWDdrU+Fn8K44ZgFQ5KJDtawSvmB9+Lv5tkAxrDnPk/KgsJ6MnSV95bL/cGMNthUDLY3JgCpVyDdlj6Gw+Q6tZee1069ob5A79NQ3zWo7dm0mSY0gmb0DSCo0aTESiuHnxDgA2vMHeV3WY4PfdNso9KU1lYpJxPJlrX5FYoMyAX42CDGgGekyTE7PkB5G7mxH7wJqK1KIHeVSKzDj1IQ0lPtKHw9hty7KO6Ltt+HHGWXA7Q1JbckUAnxAKlG0PQzxu5dezptZHGDuPH6i/ARzZJU6XZzzK8XPORLD/PH2SBD3/wZplukwCY0LSXPn1yl/T31xx1n6syDA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA0PR17MB4314.namprd17.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3tmDE3spsY75cTuitYX4p2h6dexQrCfj+WorWcCkmtmBSrl9fsyyY/1hRBdlp26DISqO1ogIS+Ew8pi9agT50eC0ArFlFtwZ8bZ8MaKdrTLW+cSg+75pLZttV0JMuctEKLj7zz9QlJhxdUPUreFCUQ4SyABOXGrOMLBrHKOm4FDG2Mi6KGiMqGMjxr3WgilLe2yEa18s1ddHx+imUmxlqowfo0qrXjQSVNRuJphgaBvpP79sXKoaMGUD49u9+9XgbkDIs97+js6Rgz7dURDMHC4KIWztr6m82vpk4qA78ovkzT5R+8m6fmTNysAWhFodEBfxt+owXvIvHZ2ewB8Try1L23q8NEQEXG84aBz7hOWypZwaYe37LQflhKT5RcaaUxjnQ0VHKG+4ytsBZvk2zIGWoeOZMdoH8Bo6H39gQVZWL9aVHyPl8zdPYR8bh3VktGluDkmGdqVFNOypgHV0KNnCUSryRcyQ7F5vUOmda5yqrTPVbd9G+RChnbgmcoqdhNz2JO4gJ7eG6ju9hh3FEkH/bp+ARCSVQ/+ceja7cToN7CwmM/FBDnEfQb/f6AVMs32zyMZA74Q2I9Ot9ggJ+NrJ4YrGGonxkC3Kblk6hBkSZBBoDoDUyBCYVoUSoFjtV6H1h5GiBdk3XnqaNYk+UtLWFdlfg97yagDsuktF0QOxjAugbpVB8nvyuAhEgdagjiWb1OkJTGOZlXAvAst7n1Cw4Enq0462petEQL5//8ZBLBlqJ1AqRitDWusMClxfw/VyW8qgpXk0c5z0WPkY0Lu0onvQ+l5SjQsXYvpvIu9aW+qYhfbKq69Hm5sRca0OQd0d3Q6mCPOsQ64dqVr7hjc74JjKrlSxqiNkJJQpZXT7o/guIpcBX1wm6rmCJy7BVD3PbiaZgb+xBIbY9epMoUkSsk7WLJeXm7CxtU0moNfIhwT5Ov5nedWVNd9hFGzIs2/UZtbYF66vKfH1fXU4tqd5XHxX9aEfjnhmqUhurwmTWtFgKIUcM2AE1JTONufchls3s4i2tUPVuHZ8WvH7N1v1DKDueiBS68YIdWL15HklyaFf+3KhehZJjNojjXy9sDiHZ5fttPIp/gBs7RO1I5bxVsAR/iuKtJNnUUH2M69KqmFQ0uILYdQmZFSBQwLXI/nt3RgQKDiJNT+pgn2vO5GsSOwUF2h0Sna63jSjIjevc7KZLiIEto0QzwyLmfto1zemGazEeauWpv71EaZXj393Vwlqwhr4j4oPG0y4yaP9aMbjP/OWf4o+tT/c3tFu7KLBHcVgg6Xu22o1ifeHdevEZboGBK0EWr65/2yz4N+YUpbaF+nkFbuZM+nNJvJ8OQi/kfDmS78vBgkEFZ9ZEM6hju701SK/Hk4CplC6GBxFLDw1HeiOy/BjAZgjH+N8WPbEYsQSaVa/Fdqep96hlMEy36NJM65IIfX3hlbv7y935WkCHhsJPjc6tkNpHxFkr2AYb66OKwe0Y9hYGWAE7Bj4hDFPZ0kF9uKBytXJDW2ZpVeroOcFBBqAbI3wwOxAO47TrtOnUpIX1/mS5Xh6vkKgH60A+f7qge7RcRDnTeK1i/pXUYtpPLdEfrxs8mw9 X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e2d66b5-219f-45d4-a52a-08dd0a2aa967 X-MS-Exchange-CrossTenant-AuthSource: SA0PR17MB4314.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 12:47:30.4447 (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: T9MxI6furBcFNQxfA351K26J9Vg2vOL5xqlO406Bo0RHor7cGRqVSTEUEKKoWOVVhAWEvwhLqmg/QyrJu4IVwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR17MB6504 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DoSf6bThghVRXu3Bz3X3LVETN3w1oDA8MNZ4F3nT98k_1732193251 X-Mimecast-Originator: labware.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
Add Python "JIT" API
|
|
Commit Message
Jan Vrany
Nov. 21, 2024, 12:46 p.m. UTC
While working with objfiles in Python I noticed that gdb.Progspace.objfile_for_address () does not return "dynamic" objfile create by (for example) GDB's JIT reader API. This is because is_addr_in_objfile() checks if given address falls into any (mappped) section of that objfile. However objfiles created by JIT reader API do not have sections. To solve this issue, this commit updates is_addr_in_objfile() to also check if address fall into any compunit if that objfile. It does so only if objfile has no sections. --- gdb/objfiles.c | 16 ++++++++++++++++ gdb/testsuite/gdb.base/jit-reader.exp | 9 +++++++++ 2 files changed, 25 insertions(+)
Comments
Jan, thanks for working on this fix. Jan Vrany <jan.vrany@labware.com> writes: > While working with objfiles in Python I noticed that > gdb.Progspace.objfile_for_address () does not return "dynamic" objfile s/objfile/objfiles/. > create by (for example) GDB's JIT reader API. > > This is because is_addr_in_objfile() checks if given address falls into "checks if a given address" > any (mappped) section of that objfile. However objfiles created by JIT > reader API do not have sections. > > To solve this issue, this commit updates is_addr_in_objfile() to also > check if address fall into any compunit if that objfile. It does so only "check if the address falls into any compunit in that objfile." > if objfile has no sections. "if the objfile has no sections". > --- > gdb/objfiles.c | 16 ++++++++++++++++ > gdb/testsuite/gdb.base/jit-reader.exp | 9 +++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/gdb/objfiles.c b/gdb/objfiles.c > index 555195dc61f..0bb578fa6a8 100644 > --- a/gdb/objfiles.c > +++ b/gdb/objfiles.c > @@ -1194,6 +1194,22 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile) > if (osect->contains (addr)) > return true; > } > + /* Objfiles created dynamically by JIT reader API (and possibly by > + other means too) do not have sections and therefore the above > + check never succeeds. > + > + For such "dynamic" objfiles walk over all compunits and check > + if given ADDR falls into compunit's global block. */ "into a compunit's global block." > + if (! objfile->sections_start) This should be: if (objfile->sections_start == nullptr) > + { > + for (compunit_symtab *cu > + : const_cast<struct objfile *>(objfile)->compunits ()) I think this can be 'const compunit_symtab *cu' here. All the methods called below have 'const' variants available. > + { > + global_block *gb = cu->blockvector ()->global_block (); > + if (gb->start () <= addr && addr <= gb->end ()) I believe that the block's end address is the first address outside the block. So I think this should be: if (gb->start () <= addr && addr < gb->end ()) There are two problems with this approach, one I'm not sure how to deal with is that the blocks start/end only reflects the text range of the compunit_symtab, so while is_addr_in_objfile will return an objfile based on a data address for "normal" objfiles, for dynamic objfiles this is not true, only a lookup with a text address will work. I'm not sure if there's a solution to this problem, I suspect you understand dynamic objfiles better than me. But if there's not good solution maybe the right solution is to just document this in the function comment, and leave it be for now. The second issue is that it is possible for there to be a gap in an objfile's range. This is described in a comment inside the function find_pc_sect_compunit_symtab (symtab.c), which is worth a read. But basically a CU might cover 0x1000..0x2000 then 0x3000..0x4000 which a different CU from a different objfile might cover 0x2000..0x3000. The global block for the first CU will have a start/end of 0x1000..0x4000, but shouldn't claim addresses in the range 0x2000..0x3000. You might need to factor out some of the logic from find_pc_sect_compunit_symtab and do an address to compunit_symtab lookup, then check if the objfile associated with the compunit_symtab is the one being checked for? Thanks, Andrew > + return true; > + } > + } > return false; > } > > diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp > index 62f6af29ac1..9a873c77909 100644 > --- a/gdb/testsuite/gdb.base/jit-reader.exp > +++ b/gdb/testsuite/gdb.base/jit-reader.exp > @@ -229,6 +229,15 @@ proc jit_reader_test {} { > gdb_test "python print( \[o for o in gdb.objfiles() if o.filename.startswith('<< JIT compiled code')\]\[0\].build_id )" \ > "None" \ > "python gdb.Objfile.build_id" > + > + # Check that Progspace.objfile_for_address () finds "jitted" > + # objfile > + gdb_test "frame 0" \ > + "#0 $hex in jit_function_stack_mangle ()$any" \ > + "select frame 0" > + gdb_test "python print( gdb.current_progspace().objfile_for_address(gdb.parse_and_eval('\$pc')) )" \ > + "<gdb.Objfile filename=<< JIT compiled code at $hex >>>" \ > + "python gdb.Progspace.objfile_for_address" > } > } > } > -- > 2.45.2
On Sat, 2024-12-07 at 11:45 +0000, Andrew Burgess wrote: > > Jan, thanks for working on this fix. > > Jan Vrany <jan.vrany@labware.com> writes: > > > While working with objfiles in Python I noticed that > > gdb.Progspace.objfile_for_address () does not return "dynamic" > > objfile > > s/objfile/objfiles/. > > > create by (for example) GDB's JIT reader API. > > > > This is because is_addr_in_objfile() checks if given address falls > > into > > "checks if a given address" > > > any (mappped) section of that objfile. However objfiles created by > > JIT > > reader API do not have sections. > > > > To solve this issue, this commit updates is_addr_in_objfile() to > > also > > check if address fall into any compunit if that objfile. It does so > > only > > "check if the address falls into any compunit in that objfile." > > > if objfile has no sections. > > "if the objfile has no sections". > > > --- > > gdb/objfiles.c | 16 ++++++++++++++++ > > gdb/testsuite/gdb.base/jit-reader.exp | 9 +++++++++ > > 2 files changed, 25 insertions(+) > > > > diff --git a/gdb/objfiles.c b/gdb/objfiles.c > > index 555195dc61f..0bb578fa6a8 100644 > > --- a/gdb/objfiles.c > > +++ b/gdb/objfiles.c > > @@ -1194,6 +1194,22 @@ is_addr_in_objfile (CORE_ADDR addr, const > > struct objfile *objfile) > > if (osect->contains (addr)) > > return true; > > } > > + /* Objfiles created dynamically by JIT reader API (and possibly > > by > > + other means too) do not have sections and therefore the above > > + check never succeeds. > > + > > + For such "dynamic" objfiles walk over all compunits and check > > + if given ADDR falls into compunit's global block. */ > > "into a compunit's global block." > > > + if (! objfile->sections_start) > > This should be: > > if (objfile->sections_start == nullptr) > > > + { > > + for (compunit_symtab *cu > > + : const_cast<struct objfile *>(objfile)->compunits > > ()) > > I think this can be 'const compunit_symtab *cu' here. All the > methods > called below have 'const' variants available. > > > + { > > + global_block *gb = cu->blockvector ()->global_block (); > > + if (gb->start () <= addr && addr <= gb->end ()) > > I believe that the block's end address is the first address outside > the > block. So I think this should be: > > if (gb->start () <= addr && addr < gb->end ()) Thanks, I'll fix this and all other things mentioned above. > > There are two problems with this approach, one I'm not sure how to > deal > with is that the blocks start/end only reflects the text range of the > compunit_symtab, so while is_addr_in_objfile will return an objfile > based on a data address for "normal" objfiles, for dynamic objfiles > this > is not true, only a lookup with a text address will work. Sorry, I do not understand what do you mean by this. For "normal" objfiles, I can give it both, a code (text) address or address of some static data: (top-gdb) bt #0 init_page_info () at utils.c:1130 #1 0x00005555574ed6ea in gdb_init () at top.c:2305 #2 0x00005555570817f2 in captured_main_1 (context=0x7fffffffdc80) at main.c:1040 #3 0x000055555708263d in captured_main (data=0x7fffffffdc80) at main.c:1330 #4 0x00005555570826dc in gdb_main (args=0x7fffffffdc80) at main.c:1359 #5 0x0000555556999908 in main (argc=1, argv=0x7fffffffddb8) at gdb.c:38 (top-gdb) python print(gdb.selected_inferior().progspace.objfile_for_address(int(gdb.par se_and_eval('&objfiles_pspace_data')))) <gdb.Objfile filename=/home/.../gdb/gdb> (top-gdb) python print(gdb.selected_inferior().progspace.objfile_for_address(int(gdb.par se_and_eval('&objfiles_pspace_data')))) <gdb.Objfile filename=/home/.../gdb/gdb> > > I'm not sure if there's a solution to this problem, I suspect you > understand dynamic objfiles better than me. > But if there's not good > solution maybe the right solution is to just document this in the > function comment, and leave it be for now. > > The second issue is that it is possible for there to be a gap in an > objfile's range. This is described in a comment inside the function > find_pc_sect_compunit_symtab (symtab.c), which is worth a read. But > basically a CU might cover 0x1000..0x2000 then 0x3000..0x4000 which a > different CU from a different objfile might cover 0x2000..0x3000. > The > global block for the first CU will have a start/end of > 0x1000..0x4000, > but shouldn't claim addresses in the range 0x2000..0x3000. Yes. My thinking was that it is not possible by using JIT APIs (current JIT-reader or the one introduced in this series) to create a cu with "holes" like the above. So for any objfile, it is either a normal one and the existing code would care for it, or it is a "dynamic" one (which has no sections) and then it cannot have CUs with holes and the simple check would do. > > You might need to factor out some of the logic from > find_pc_sect_compunit_symtab and do an address to compunit_symtab > lookup, then check if the objfile associated with the compunit_symtab > is > the one being checked for? Yes, this makes sense even if such dynamic objfile cannot be created right now. It may not stay so forever though. I'll have a look. Thanks a lot! Jan > > Thanks, > Andrew > > > + return true; > > + } > > + } > > return false; > > } > > > > diff --git a/gdb/testsuite/gdb.base/jit-reader.exp > > b/gdb/testsuite/gdb.base/jit-reader.exp > > index 62f6af29ac1..9a873c77909 100644 > > --- a/gdb/testsuite/gdb.base/jit-reader.exp > > +++ b/gdb/testsuite/gdb.base/jit-reader.exp > > @@ -229,6 +229,15 @@ proc jit_reader_test {} { > > gdb_test "python print( \[o for o in > > gdb.objfiles() if o.filename.startswith('<< JIT compiled > > code')\]\[0\].build_id )" \ > > "None" \ > > "python gdb.Objfile.build_id" > > + > > + # Check that Progspace.objfile_for_address () > > finds "jitted" > > + # objfile > > + gdb_test "frame 0" \ > > + "#0 $hex in jit_function_stack_mangle ()$any" > > \ > > + "select frame 0" > > + gdb_test "python print( > > gdb.current_progspace().objfile_for_address(gdb.parse_and_eval('\$p > > c')) )" \ > > + "<gdb.Objfile filename=<< JIT compiled code at > > $hex >>>" \ > > + "python gdb.Progspace.objfile_for_address" > > } > > } > > } > > -- > > 2.45.2 >
On Sat, 2024-12-07 at 11:45 +0000, Andrew Burgess wrote: > > The second issue is that it is possible for there to be a gap in an > objfile's range. This is described in a comment inside the function > find_pc_sect_compunit_symtab (symtab.c), which is worth a read. But > basically a CU might cover 0x1000..0x2000 then 0x3000..0x4000 which a > different CU from a different objfile might cover 0x2000..0x3000. > The > global block for the first CU will have a start/end of > 0x1000..0x4000, > but shouldn't claim addresses in the range 0x2000..0x3000. > > You might need to factor out some of the logic from > find_pc_sect_compunit_symtab and do an address to compunit_symtab > lookup, then check if the objfile associated with the compunit_symtab > is > the one being checked for? On a second thought, in what situations there can be 2 CUs, each from different objfile, interleaved like the comment says? The comment says: This happens for native ecoff format, where code from included files gets its own symtab. In this case, symtabs for included files would belong to the same objfile, no? In the other cases: It also happens for objfiles that have their functions reordered. Again, all functions (possibly from different CUs) would belong to the same objfile, no? Jan > > Thanks, > Andrew > > > + return true; > > + } > > + } > > return false; > > } > > > > diff --git a/gdb/testsuite/gdb.base/jit-reader.exp > > b/gdb/testsuite/gdb.base/jit-reader.exp > > index 62f6af29ac1..9a873c77909 100644 > > --- a/gdb/testsuite/gdb.base/jit-reader.exp > > +++ b/gdb/testsuite/gdb.base/jit-reader.exp > > @@ -229,6 +229,15 @@ proc jit_reader_test {} { > > gdb_test "python print( \[o for o in > > gdb.objfiles() if o.filename.startswith('<< JIT compiled > > code')\]\[0\].build_id )" \ > > "None" \ > > "python gdb.Objfile.build_id" > > + > > + # Check that Progspace.objfile_for_address () > > finds "jitted" > > + # objfile > > + gdb_test "frame 0" \ > > + "#0 $hex in jit_function_stack_mangle ()$any" > > \ > > + "select frame 0" > > + gdb_test "python print( > > gdb.current_progspace().objfile_for_address(gdb.parse_and_eval('\$p > > c')) )" \ > > + "<gdb.Objfile filename=<< JIT compiled code at > > $hex >>>" \ > > + "python gdb.Progspace.objfile_for_address" > > } > > } > > } > > -- > > 2.45.2 >
>> + global_block *gb = cu->blockvector ()->global_block (); >> + if (gb->start () <= addr && addr <= gb->end ()) Andrew> I believe that the block's end address is the first address outside the Andrew> block. So I think this should be: Andrew> if (gb->start () <= addr && addr < gb->end ()) If this will still be in the final patch, it may make sense to have a 'block' method for this. thanks, Tom
On Thu, 2024-12-19 at 12:43 -0700, Tom Tromey wrote: > > > + global_block *gb = cu->blockvector ()->global_block > > > (); > > > + if (gb->start () <= addr && addr <= gb->end ()) > > Andrew> I believe that the block's end address is the first address > outside the > Andrew> block. So I think this should be: > > Andrew> if (gb->start () <= addr && addr < gb->end ()) > > If this will still be in the final patch, it may make sense to have a > 'block' method for this. > Yes, in my work-in-progress v3 I did exactly this. Accounting for (at least some cases of) non-continguous compunits caused more changes not only in this patch but also in others. Thanks, Jan > thanks, > Tom >
diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 555195dc61f..0bb578fa6a8 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1194,6 +1194,22 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile) if (osect->contains (addr)) return true; } + /* Objfiles created dynamically by JIT reader API (and possibly by + other means too) do not have sections and therefore the above + check never succeeds. + + For such "dynamic" objfiles walk over all compunits and check + if given ADDR falls into compunit's global block. */ + if (! objfile->sections_start) + { + for (compunit_symtab *cu + : const_cast<struct objfile *>(objfile)->compunits ()) + { + global_block *gb = cu->blockvector ()->global_block (); + if (gb->start () <= addr && addr <= gb->end ()) + return true; + } + } return false; } diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp index 62f6af29ac1..9a873c77909 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -229,6 +229,15 @@ proc jit_reader_test {} { gdb_test "python print( \[o for o in gdb.objfiles() if o.filename.startswith('<< JIT compiled code')\]\[0\].build_id )" \ "None" \ "python gdb.Objfile.build_id" + + # Check that Progspace.objfile_for_address () finds "jitted" + # objfile + gdb_test "frame 0" \ + "#0 $hex in jit_function_stack_mangle ()$any" \ + "select frame 0" + gdb_test "python print( gdb.current_progspace().objfile_for_address(gdb.parse_and_eval('\$pc')) )" \ + "<gdb.Objfile filename=<< JIT compiled code at $hex >>>" \ + "python gdb.Progspace.objfile_for_address" } } }