From: Jan Vrany <jan@vrany.io>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan@vrany.io>
Subject: [PATCH v3 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab
Date: Wed, 22 Apr 2026 10:29:40 +0000 [thread overview]
Message-ID: <20260422102923.1185738-2-jan@vrany.io> (raw)
In-Reply-To: <20260304165914.3209106-1-jan.vrany@labware.com>
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=33829
---
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;
}
+ 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,
CORE_ADDR address) override
{
@@ -2107,6 +2111,57 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
return result;
}
+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 = get_dwarf2_per_objfile (objfile);
+ dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
+
+ /* This invariant is documented in read.h */
+ gdb_assert (per_bfd->index_table == 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 words,
+ smaller blocks are "closer". */
+
+ auto closer = [&] (const block *b1, const block *b2)
+ {
+ if (b1 == nullptr)
+ return false;
+ if (b2 == nullptr)
+ return true;
+ return (b1->end () - b1->start ()) < (b2->end () - b2->start ());
+ };
+
+ compunit_symtab *best_cu = nullptr;
+ const block *best_bl = nullptr;
+
+ for (int i = 0; i < per_bfd->all_units.size (); i++)
+ {
+ dwarf2_per_cu *data = per_bfd->all_units[i].get ();
+
+ if (per_objfile->compunit_symtab_set_p (data))
+ {
+ compunit_symtab *this_cu = per_objfile->get_compunit_symtab (data);
+ const block *this_bl = this_cu->blockvector ()->lookup (pc);
+
+ if (closer (this_bl, best_bl))
+ {
+ best_cu = this_cu;
+ best_bl = this_bl;
+ }
+ }
+ }
+ return best_cu;
+}
+
void
dwarf2_base_index_functions::map_symbol_filenames (objfile *objfile,
symbol_filename_listener fun,
--
2.53.0
next prev parent reply other threads:[~2026-04-22 10:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
2026-03-04 16:59 ` [PATCH v2 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab Jan Vrany
2026-03-04 16:59 ` [PATCH v2 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab Jan Vrany
2026-03-04 21:19 ` Tom Tromey
2026-03-04 16:59 ` [PATCH v2 3/7] gdb: simplify find_compunit_symtab_for_pc_sect Jan Vrany
2026-03-04 16:59 ` [PATCH v2 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks Jan Vrany
2026-03-04 16:59 ` [PATCH v2 5/7] gdb: do not set blockvector address map Jan Vrany
2026-03-04 16:59 ` [PATCH v2 6/7] gdb: remove address map from struct blockvector Jan Vrany
2026-03-04 16:59 ` [PATCH v2 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany
2026-03-10 18:14 ` [PING] Re: [PATCH v2 0/7] Remove addrmap from blockvector Jan Vraný
2026-04-22 10:29 ` [PATCH v3 " Jan Vrany
2026-04-28 18:55 ` [PING] " Jan Vrany
2026-05-08 9:14 ` Jan Vrany
2026-04-22 10:29 ` Jan Vrany [this message]
2026-04-22 10:29 ` [PATCH v3 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab Jan Vrany
2026-04-22 10:29 ` [PATCH v3 3/7] gdb: simplify find_compunit_symtab_for_pc_sect Jan Vrany
2026-04-22 10:30 ` [PATCH v3 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks Jan Vrany
2026-04-22 10:30 ` [PATCH v3 5/7] gdb: do not set blockvector address map Jan Vrany
2026-04-22 10:30 ` [PATCH v3 6/7] gdb: remove address map from struct blockvector Jan Vrany
2026-04-22 10:30 ` [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260422102923.1185738-2-jan@vrany.io \
--to=jan@vrany.io \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox