From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [PATCH v2 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks
Date: Wed, 4 Mar 2026 16:59:11 +0000 [thread overview]
Message-ID: <20260304165914.3209106-5-jan.vrany@labware.com> (raw)
In-Reply-To: <20260304165914.3209106-1-jan.vrany@labware.com>
This commit updates blockvector::lookup to handle non-contiguous without
help of addrmap. It introduces a new method, block::contains(CORE_ADDR),
to check whether given block contains given address. This new method is
then used in blockvector::lookup instead of simply using block's
start and end addresses.
For this to work, it is essential that blocks' start address is the same
as start address of lowest range and similarly blocks' end address same
as end address of highest range. Therefore this commit also adds assert
to DWARF reader to ensure that.
A unit test for non-contiguous blocks will come later in this series.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
gdb/block.c | 24 +++++++++++++++++++++++-
gdb/block.h | 4 ++++
gdb/dwarf2/read.c | 10 ++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/gdb/block.c b/gdb/block.c
index 730e4580a5b..b964674865b 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -85,6 +85,25 @@ block::contains (const struct block *a, bool allow_nested) const
/* See block.h. */
+bool
+block::contains (const CORE_ADDR addr) const
+{
+ if (addr >= start () && addr < end ())
+ {
+ if (is_contiguous ())
+ return true;
+
+ for (auto range : ranges ())
+ {
+ if (range.start () <= addr && addr < range.end ())
+ return true;
+ }
+ }
+ return false;
+}
+
+/* See block.h. */
+
struct symbol *
block::linkage_function () const
{
@@ -857,7 +876,10 @@ blockvector::lookup (CORE_ADDR addr) const
if (b->start () > addr)
return nullptr;
if (b->end () > addr)
- return b;
+ {
+ if (b->contains (addr))
+ return b;
+ }
bot--;
}
diff --git a/gdb/block.h b/gdb/block.h
index b84ca12c35a..59cabbd620d 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -315,6 +315,10 @@ struct block : public allocate_on_obstack<block>
bool contains (const struct block *a, bool allow_nested = false) const;
+ /* Return true if block contains address ADDR. Return false otherwise. */
+
+ bool contains (const CORE_ADDR addr) const;
+
/* Relocate this block and all contained blocks. OBJFILE is the
objfile holding this block, and OFFSETS is the relocation offsets
to use. */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7c6f54449ba..c9b6bebdb86 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9410,6 +9410,9 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
if (die->tag != DW_TAG_compile_unit)
ranges_offset += cu->gnu_ranges_base;
+ CORE_ADDR lo = std::numeric_limits<CORE_ADDR>::max ();
+ CORE_ADDR hi = std::numeric_limits<CORE_ADDR>::min ();
+
std::vector<blockrange> blockvec;
dwarf2_ranges_process (ranges_offset, cu, die->tag,
[&] (unrelocated_addr start,
@@ -9417,10 +9420,17 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
{
CORE_ADDR abs_start = per_objfile->relocate (start);
CORE_ADDR abs_end = per_objfile->relocate (end);
+
+ lo = std::min (lo, abs_start);
+ hi = std::max (hi, abs_end);
+
dwarf2_maybe_record_inline_function (cu, block, end);
blockvec.emplace_back (abs_start, abs_end);
});
+ gdb_assert (blockvec.size () == 0 || block->start () == lo);
+ gdb_assert (blockvec.size () == 0 || block->end () == hi);
+
block->set_ranges (make_blockranges (objfile, blockvec));
}
}
--
2.51.0
next prev parent reply other threads:[~2026-03-04 17:03 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 ` Jan Vrany [this message]
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 ` [PATCH v3 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab Jan Vrany
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=20260304165914.3209106-5-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--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