From: "Jan Vraný" <Jan.Vrany@labware.com>
To: "tom@tromey.com" <tom@tromey.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/7] gdb: simplify find_compunit_symtab_for_pc_sect
Date: Thu, 26 Feb 2026 15:00:41 +0000 [thread overview]
Message-ID: <853bd327acf343d776a5f8513a7d67c828dcb674.camel@labware.com> (raw)
In-Reply-To: <87ecmg4i39.fsf@tromey.com>
On Thu, 2026-02-19 at 13:02 -0700, Tom Tromey wrote:
> > > > > > "Jan" == Jan Vrany <jan.vrany@labware.com> writes:
>
> Jan> This commit simplifies find_compunit_symtab_for_pc_sect by removing the
> Jan> code that walks over all (currently expanded) CUs and delegating to
> Jan> quick_symbol_functions::find_pc_sect_compunit_symtab instead.
>
> Jan> With this commit on Linux x86_64 I see no regression. With -readnow
> Jan> there are some regressions, mainly caused by slightly different order
> Jan> of expanding CUs. Since there's a proposal to remove -readnow support,
> Jan> I have not fixed nor investigated failing tests in depth.
>
> I think that proposal was rejected so I'm afraid you'll have to revisit
> that.
So I did that. The only regression I spotted is dw2-entry-points.exp in
which the hand-written DWARF creates to CUs, first one with "hole".
And since blockvector::lookup() returns static block if no better block
is found and because the CU with hole happens to be tried first,
the test fails. If one changes the order of CUs in the test, it passed.
There's an easy "fix" for that - look for compunit that contains shortest
block containing the PC, somewhat along the lines of "big chunk": in current
find_compunit_symtab_for_pc_sect (see patch below).
But: I'm not sure we want to do that. This brings us back to the idea that
blockvector::lookup() should never return static block. Or accept that
regression.
Jan
-- >8 --
From a4b9d584634f4aff9fc0d2f4b3ce2a2a5019b3ad Mon Sep 17 00:00:00 2001
From: Jan Vrany <jan.vrany@labware.com>
Date: Wed, 25 Feb 2026 22:34:40 +0000
Subject: [PATCH] FIXUP: gdb: implement
readnow_functions::find_pc_sect_compunit_symtab
---
gdb/dwarf2/read.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2ed8b78d596..824f5081105 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2176,21 +2176,41 @@ readnow_functions::find_pc_sect_compunit_symtab
/* This invariant is documented in read.h */
gdb_assert (per_bfd->index_table == nullptr);
- /* Since we have no index, we simply walk all units until matching CU is
- found (of there are no more CUs). */
+ /* Since we have no index, we have to walk all CUs and find one with
+ best-matching block that contains PC. For the purpose of this method,
+ a block B1 is considerent better 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 "better". */
+
+ auto better = [&] (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->symtab_set_p (data))
{
- compunit_symtab *result = find_pc_sect_compunit_symtab_includes (
- per_objfile->get_symtab (data), pc);
- if (result != nullptr)
- return result;
+ compunit_symtab *this_cu = per_objfile->get_symtab (data);
+ const block *this_bl = this_cu->blockvector ()->lookup (pc);
+
+ if (better (this_bl, best_bl))
+ {
+ best_cu = this_cu;
+ best_bl = this_bl;
+ }
}
}
- return nullptr;
+ return best_cu;
}
void
--
2.51.0
next prev parent reply other threads:[~2026-02-26 15:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 18:56 [PATCH 0/7] Remove addrmap from blockvector Jan Vrany
2026-02-19 18:56 ` [PATCH 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab Jan Vrany
2026-02-19 20:01 ` Tom Tromey
2026-02-20 12:36 ` Jan Vraný
2026-02-20 14:25 ` Tom Tromey
2026-02-20 15:57 ` Jan Vraný
2026-02-19 18:56 ` [PATCH 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab Jan Vrany
2026-02-19 20:02 ` Tom Tromey
2026-02-19 18:56 ` [PATCH 3/7] gdb: simplify find_compunit_symtab_for_pc_sect Jan Vrany
2026-02-19 20:02 ` Tom Tromey
2026-02-20 12:40 ` Jan Vraný
2026-02-20 14:25 ` Tom Tromey
2026-02-26 15:00 ` Jan Vraný [this message]
2026-02-19 18:56 ` [PATCH 4/7] gdb: do not set blockvector address map Jan Vrany
2026-02-19 20:03 ` Tom Tromey
2026-02-20 12:42 ` Jan Vraný
2026-02-19 18:56 ` [PATCH 5/7] gdb: update blockvector::lookup to handle non-contiguous blocks Jan Vrany
2026-02-19 20:06 ` Tom Tromey
2026-02-19 20:20 ` Tom Tromey
2026-02-20 13:03 ` Jan Vraný
2026-02-20 16:38 ` Tom Tromey
2026-03-03 11:06 ` Jan Vraný
2026-03-09 15:52 ` Jan Vraný
2026-02-19 18:56 ` [PATCH 6/7] gdb: remove address map from struct blockvector Jan Vrany
2026-02-19 18:56 ` [PATCH 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany
2026-02-19 20:12 ` Tom Tromey
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=853bd327acf343d776a5f8513a7d67c828dcb674.camel@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/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