Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [PATCH 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks
Date: Thu, 19 Feb 2026 18:56:38 +0000	[thread overview]
Message-ID: <20260219185638.360694-8-jan.vrany@labware.com> (raw)
In-Reply-To: <20260219185638.360694-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 | 74 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c
index 77b8d67ded8..ca4289fbb6f 100644
--- a/gdb/block-selftests.c
+++ b/gdb/block-selftests.c
@@ -20,6 +20,7 @@
 #include "gdbsupport/selftest.h"
 #include "block.h"
 #include "addrmap.h"
+#include "obstack.h"
 
 
 namespace selftests {
@@ -81,6 +82,76 @@ 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 +159,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.51.0


  parent reply	other threads:[~2026-02-19 18:59 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ý
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 ` Jan Vrany [this message]
2026-02-19 20:12   ` [PATCH 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks 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=20260219185638.360694-8-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