From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eUhFDGeo6GnekTMAWB0awg (envelope-from ) for ; Wed, 22 Apr 2026 06:52:23 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail3 header.b=HrOKcYuJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 242081E0C3; Wed, 22 Apr 2026 06:52:23 -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 5E4221E067 for ; Wed, 22 Apr 2026 06:52:22 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 971FF44AFFCD for ; Wed, 22 Apr 2026 10:52:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 971FF44AFFCD Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=vrany.io header.i=@vrany.io header.a=rsa-sha256 header.s=protonmail3 header.b=HrOKcYuJ Received: from mail-4399.protonmail.ch (mail-4399.protonmail.ch [185.70.43.99]) by sourceware.org (Postfix) with ESMTPS id A2DE24BCA439 for ; Wed, 22 Apr 2026 10:29:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2DE24BCA439 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=vrany.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrany.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A2DE24BCA439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.43.99 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853787; cv=none; b=C91SGYDUMx36njHRmyOmv1Zzl+8u8RhaL7VaB0qUXeTdcs1yoS1OX78WA4NY5/uqM/bJOvSjBj51Kgk5PzwUftJuNLB/T8S0fY+WxSONsVoUwJpTGY137A9MYDreYMBL34PnCSLzbcCgHFyT0iAQFF/z/0c+gt4qWz+q74d+zgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853787; c=relaxed/simple; bh=ch5awyWNo8kr+UFNnA4qe/1/k+Ggf/6qk62LzhlHuBc=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=q/4nkugw5yjTuGMBpTUeZc6+PtltCdSH/8qDBifBd28jvEOoi3h0rsrCIV4I+PjGt/je+QTzukMoJ+8dXMmCgknT7y8jEyUZw9aqRFemZ+e7qIpdlsR4vR/WluYbY+NOBT4BhJAb9we0biUm5apfZFNbiC6SvM/4CGX1bh23Fus= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2DE24BCA439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrany.io; s=protonmail3; t=1776853785; x=1777112985; bh=/Bd5/oJBltAyZ1EGHGtUKOWMtzlQ6dpZg5wq4wmpx4Y=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=HrOKcYuJg+8PE19nTasxOvWR1ZPAuGke66NBJ62oCMs9vIhBx/6cNPXjcvE6yG+5W RqCiTgCh428zXLTcz9lhGU/43HQdQcr8G2uAJ2cHxHxMSSw0fZwe2HXB6RruqSFE3r /rXJXF9LsTuOwOJdDrpkN/+cc5y/QmfX5Q2LRjIQydhQQQf4HEl5Kzam3rgQhTB0WA 3hp6ff58NZyf2vrrA5N4ElG2e/PnxNN6FYkKly692i9sdRrSsZDfCI8CugD7qIjFms 81ElKagF3uTpW0wJWrBEyFvvsv2PP4Lh5VSKJFtIGwcG38Y2ltojuMp7gNlLFMpw79 LKM4+8XBmh6BA== Date: Wed, 22 Apr 2026 10:29:40 +0000 To: gdb-patches@sourceware.org From: Jan Vrany Cc: Jan Vrany Subject: [PATCH v3 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab Message-ID: <20260422102923.1185738-2-jan@vrany.io> In-Reply-To: <20260304165914.3209106-1-jan.vrany@labware.com> References: <20260304165914.3209106-1-jan.vrany@labware.com> Feedback-ID: 40767693:user:proton X-Pm-Message-ID: b77b2df07b8b802b9a779063efd34768b7f7e145 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 commit implements readnow_functions::find_pc_sect_compunit_symtab. As comment in read.h states, index_table member dwarf2_per_bfd is null when -readnow is used and thus this method would always return null when using -readnow. This issue did not manifest until now because: 1) all symtabs are expanded prior calling quick_symbol_functions::find_pc_sect_compunit_symtab and 2) find_compunit_symtab_for_pc_sect iterates iterate over all (currently expanded) symtabs before delegating to quick symbols. This is a preparation for simplifying find_compunit_symtab_for_pc_sect by removing the code that walks all existing CUs. In order to handle interleaved CUs with "holes" this implementation walks over all CUs and looks for a CU that contains the "closest" (smallest) block that contain given PC. An example of such a case is test dw2-entry-points.exp. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D33829 --- gdb/dwarf2/read.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 375e8a75db4..e9ea276b927 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1490,6 +1490,10 @@ struct readnow_functions : public dwarf2_base_index_= functions return iteration_status::keep_going; } =20 + struct compunit_symtab *find_pc_sect_compunit_symtab ( + struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc, + struct obj_section *section, int warn_if_readin) override; + struct symbol *find_symbol_by_address (struct objfile *objfile, =09=09=09=09=09 CORE_ADDR address) override { @@ -2107,6 +2111,57 @@ dwarf2_base_index_functions::find_pc_sect_compunit_s= ymtab return result; } =20 +struct compunit_symtab * +readnow_functions::find_pc_sect_compunit_symtab + (struct objfile *objfile, + bound_minimal_symbol msymbol, + CORE_ADDR pc, + struct obj_section *section, + int warn_if_readin) +{ + dwarf2_per_objfile *per_objfile =3D get_dwarf2_per_objfile (objfile); + dwarf2_per_bfd *per_bfd =3D per_objfile->per_bfd; + + /* This invariant is documented in read.h */ + gdb_assert (per_bfd->index_table =3D=3D nullptr); + + /* Since we have no index, we have to walk all CUs and find one with the + "closest" block that contains PC. For the purpose of this method, + a block B1 is considerent closer matching than block B2 if B1 is not = null + and B2 is either null or has larger total span than B1. In other wor= ds, + smaller blocks are "closer". */ + + auto closer =3D [&] (const block *b1, const block *b2) + { + if (b1 =3D=3D nullptr) +=09return false; + if (b2 =3D=3D nullptr) +=09return true; + return (b1->end () - b1->start ()) < (b2->end () - b2->start ()); + }; + + compunit_symtab *best_cu =3D nullptr; + const block *best_bl =3D nullptr; + + for (int i =3D 0; i < per_bfd->all_units.size (); i++) + { + dwarf2_per_cu *data =3D per_bfd->all_units[i].get (); + + if (per_objfile->compunit_symtab_set_p (data)) +=09{ +=09 compunit_symtab *this_cu =3D per_objfile->get_compunit_symtab (data); +=09 const block *this_bl =3D this_cu->blockvector ()->lookup (pc); + +=09 if (closer (this_bl, best_bl)) +=09 { +=09 best_cu =3D this_cu; +=09 best_bl =3D this_bl; +=09 } +=09} + } + return best_cu; +} + void dwarf2_base_index_functions::map_symbol_filenames (objfile *objfile, =09=09=09=09=09=09 symbol_filename_listener fun, --=20 2.53.0