From: Jan Vrany <jan@vrany.io>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan@vrany.io>
Subject: [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks
Date: Wed, 22 Apr 2026 10:30:28 +0000 [thread overview]
Message-ID: <20260422102923.1185738-8-jan@vrany.io> (raw)
In-Reply-To: <20260304165914.3209106-1-jan.vrany@labware.com>
This commit add a new unit test that tests block lookup when blocks are
non-contiguous.
---
gdb/block-selftests.c | 72 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c
index 77b8d67ded8..c41a9ac7e82 100644
--- a/gdb/block-selftests.c
+++ b/gdb/block-selftests.c
@@ -81,6 +81,75 @@ test_blockvector_lookup_contains ()
SELF_CHECK (bv->contains (0x4000) == false);
}
+/* Create and return struct blockranges* from 2 ranges. */
+static struct blockranges *
+make_blockranges_2 (struct obstack &ob, CORE_ADDR start0, CORE_ADDR end0,
+ CORE_ADDR start1, CORE_ADDR end1)
+{
+ struct blockranges *ranges = (struct blockranges *) obstack_alloc
+ (&ob, sizeof (struct blockranges) + (2 - 1) * sizeof (struct blockrange));
+
+ ranges->nranges = 2;
+ ranges->range[0].set_start (start0);
+ ranges->range[0].set_end (end0);
+ ranges->range[1].set_start (start1);
+ ranges->range[1].set_end (end1);
+
+ return ranges;
+}
+
+static void
+test_blockvector_lookup_non_continuguous ()
+{
+ /* Create blockvector with following blocks:
+
+ B0 0x1000 - 0x8000 (global block)
+ B1 0x1000 - 0x8000 (static block)
+ B2 0x1000 - 0x2000 (B2's range 1)
+ B3 0x2000 - 0x3000 (B3's range 1)
+ (hole 1)
+ B4 0x5000 - 0x5500
+ (hole 2)
+ (B2) 0x6000 - 0x7000 (B2's range 2)
+ (B3) 0x7000 - 0x8000 (B3's range 2)
+
+ Blocks B2 and B3 are non-continguous (consist of two
+ disjoint ranges) and interleaved.
+ */
+ auto_obstack ob;
+ blockvector_up bv = std::make_unique<struct blockvector> (0);
+
+ auto global_block = make_block (*bv.get (), ob, 0x1000, 0x8000);
+ auto static_block = make_block (*bv.get (), ob, 0x1000, 0x8000,
+ global_block);
+ auto b2 = make_block (*bv.get (), ob, 0x1000, 0x7000, static_block);
+ b2->set_ranges (make_blockranges_2 (ob, 0x1000, 0x2000, 0x6000, 0x7000));
+ auto b3 = make_block (*bv.get (), ob, 0x2000, 0x8000, static_block);
+ b3->set_ranges (make_blockranges_2 (ob, 0x2000, 0x3000, 0x7000, 0x8000));
+ auto b4 = make_block (*bv.get (), ob, 0x5000, 0x5500, static_block);
+
+ /* Test address falling into range 1 of B2. */
+ SELF_CHECK (bv->lookup (0x1500) == b2);
+
+ /* Test address falling into range 2 of B2. */
+ SELF_CHECK (bv->lookup (0x6000) == b2);
+
+ /* Test address falling into range 1 of B3. */
+ SELF_CHECK (bv->lookup (0x2500) == b3);
+
+ /* Test address falling into range 2 of B3. */
+ SELF_CHECK (bv->lookup (0x7999) == b3);
+
+ /* Test address falling into B4. */
+ SELF_CHECK (bv->lookup (0x5250) == b4);
+
+ /* Test address falling into hole 1. */
+ SELF_CHECK (bv->lookup (0x4000) == static_block);
+
+ /* Test address falling into hole 2. */
+ SELF_CHECK (bv->lookup (0x5750) == static_block);
+}
+
} /* namespace selftests */
@@ -88,4 +157,7 @@ INIT_GDB_FILE (block_selftest)
{
selftests::register_test ("blockvector-lookup-contains",
selftests::test_blockvector_lookup_contains);
+ selftests::register_test
+ ("blockvector-lookup-non-contiguous",
+ selftests::test_blockvector_lookup_non_continuguous);
}
--
2.53.0
prev parent reply other threads:[~2026-04-22 10:47 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 ` [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 ` Jan Vrany [this message]
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-8-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