Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/7] Remove addrmap from blockvector
@ 2026-03-04 16:59 Jan Vrany
  2026-03-04 16:59 ` [PATCH v2 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab Jan Vrany
                   ` (15 more replies)
  0 siblings, 16 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This is a v2 of a series removing the addrmap from blockvector, a step towards
expandable blockvectors which are needed for lazy CU expansion and for
Python JIT API.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829

* v1 submission is here:

  https://inbox.sourceware.org/gdb-patches/20260219185638.360694-1-jan.vrany@labware.com/

* changes since v2:

  * fix formatting and missing comments

  * swapped commits "gdb: remove address map from struct blockvector"
    and "gdb: update blockvector::lookup to handle non-contiguous blocks"
    to make code bisectable

  * rework readnow_functions::find_pc_sect_compunit_symtab to work with
    interleaved CUs.

Jan Vrany (7):
  gdb: implement readnow_functions::find_pc_sect_compunit_symtab
  gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
  gdb: simplify find_compunit_symtab_for_pc_sect
  gdb: update blockvector::lookup to handle non-contiguous blocks
  gdb: do not set blockvector address map
  gdb: remove address map from struct blockvector
  gdb: add unit test for blockvector::lookup of non-contiguous blocks

 gdb/block-selftests.c | 156 +++++++++++++++++++++++++-----------------
 gdb/block.c           |  34 ++++++---
 gdb/block.h           |  17 ++---
 gdb/buildsym.c        |  55 +--------------
 gdb/dwarf2/read.c     |  73 +++++++++++++++++---
 gdb/expanded-symbol.c |  18 +++++
 gdb/expanded-symbol.h |   8 +--
 gdb/symtab.c          |  91 ------------------------
 8 files changed, 206 insertions(+), 246 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
@ 2026-03-04 16:59 ` Jan Vrany
  2026-03-04 16:59 ` [PATCH v2 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab Jan Vrany
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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) readnow_functions::find_pc_sect_compunit_symtab is called from
    find_compunit_symtab_for_pc_sect *after* all CUs expanded so far
    are searched and,
 2) it happens that required CUs were expanded by other "quick function"
    called prior find_pc_sect_compunit_symtab.

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 a6244319f71..f7f39d75c16 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1525,6 +1525,10 @@ struct readnow_functions : public dwarf2_base_index_functions
     return true;
   }
 
+  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
   {
@@ -2166,6 +2170,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->symtab_set_p (data))
+	{
+	  compunit_symtab *this_cu = per_objfile->get_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.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
  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 ` 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
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany, Tom Tromey

This commit updates expanded_symbols_functions::find_pc_sect_compunit_symtab
to search all compunits rather than just returning null.

The original implementation (just return null) was based on reasoning
that its would suffice since find_compunit_symtab_for_pc_sect walks
all CUs anyway [1]. This commit is a preparation to simplify
find_compunit_symtab_for_pc_sect by removing that code.

Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829

[1] https://inbox.sourceware.org/gdb-patches/874iqoogoa.fsf@tromey.com/
---
 gdb/expanded-symbol.c | 18 ++++++++++++++++++
 gdb/expanded-symbol.h |  8 +-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/gdb/expanded-symbol.c b/gdb/expanded-symbol.c
index 050608795f9..3c7f9019beb 100644
--- a/gdb/expanded-symbol.c
+++ b/gdb/expanded-symbol.c
@@ -18,6 +18,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "block.h"
 #include "objfiles.h"
 #include "symtab.h"
 #include "source.h"
@@ -113,3 +114,20 @@ expanded_symbols_functions::find_symbol_by_address (objfile *objfile,
 
   return nullptr;
 }
+
+/* See expanded-symbol.h.  */
+
+compunit_symtab *
+expanded_symbols_functions::find_pc_sect_compunit_symtab
+    (objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
+     obj_section *section, int warn_if_readin)
+{
+  for (compunit_symtab &symtab : objfile->compunits ())
+    {
+      const blockvector *bv = symtab.blockvector ();
+      if (bv != nullptr && bv->contains (pc))
+	return &symtab;
+    }
+
+  return nullptr;
+}
diff --git a/gdb/expanded-symbol.h b/gdb/expanded-symbol.h
index c088d74f7e5..dc2e9814b3c 100644
--- a/gdb/expanded-symbol.h
+++ b/gdb/expanded-symbol.h
@@ -71,13 +71,7 @@ struct expanded_symbols_functions : public quick_symbol_functions
 
   compunit_symtab *find_pc_sect_compunit_symtab
     (objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
-     obj_section *section, int warn_if_readin) override
-  {
-    /* Simply returning NULL here is okay since the (only) caller
-       find_compunit_symtab_for_pc_sect iterates over existing CUs
-       anyway.  */
-    return nullptr;
-  }
+     obj_section *section, int warn_if_readin) override;
 
   symbol *find_symbol_by_address (objfile *objfile, CORE_ADDR address)
     override;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 3/7] gdb: simplify find_compunit_symtab_for_pc_sect
  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 16:59 ` Jan Vrany
  2026-03-04 16:59 ` [PATCH v2 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks Jan Vrany
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit simplifies find_compunit_symtab_for_pc_sect by removing the
code that walks over all (currently expanded) CUs and delegating to
quick_symbol_functions::find_pc_sect_compunit_symtab instead.

With this commit on Linux x86_64 I see no regression. With -readnow
there are some regressions, mainly caused by slightly different order
of expanding CUs. Since there's a proposal to remove -readnow support,
I have not fixed nor investigated failing tests in depth.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/dwarf2/read.c |  8 -----
 gdb/symtab.c      | 91 -----------------------------------------------
 2 files changed, 99 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index f7f39d75c16..7c6f54449ba 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2156,17 +2156,9 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
   if (data == nullptr)
     return nullptr;
 
-  if (warn_if_readin && per_objfile->symtab_set_p (data))
-    warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
-	     paddress (objfile->arch (), pc));
-
   compunit_symtab *result = find_pc_sect_compunit_symtab_includes
     (dw2_instantiate_symtab (data, per_objfile, false), pc);
 
-  if (warn_if_readin && result == nullptr)
-    warning (_("(Error: pc %s in address map, but not in symtab.)"),
-	     paddress (objfile->arch (), pc));
-
   return result;
 }
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cd3bf876551..4eea86319f8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2742,9 +2742,6 @@ iterate_over_symbols (const struct block *block,
 struct compunit_symtab *
 find_compunit_symtab_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
 {
-  struct compunit_symtab *best_cust = NULL;
-  CORE_ADDR best_cust_range = 0;
-
   /* If we know that this is not a text address, return failure.  This is
      necessary because we loop based on the block's high and low code
      addresses, which do not include the data ranges, and because
@@ -2755,94 +2752,6 @@ find_compunit_symtab_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
   if (msymbol.minsym && msymbol.minsym->data_p ())
     return NULL;
 
-  /* Search all symtabs for the one whose file contains our address, and which
-     is the smallest of all the ones containing the address.  This is designed
-     to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
-     and symtab b is at 0x2000-0x3000.  So the GLOBAL_BLOCK for a is from
-     0x1000-0x4000, but for address 0x2345 we want to return symtab b.
-
-     This happens for native ecoff format, where code from included files
-     gets its own symtab.  The symtab for the included file should have
-     been read in already via the dependency mechanism.
-     It might be swifter to create several symtabs with the same name
-     like xcoff does (I'm not sure).
-
-     It also happens for objfiles that have their functions reordered.
-     For these, the symtab we are looking for is not necessarily read in.  */
-
-  for (objfile &obj_file : current_program_space->objfiles ())
-    {
-      for (compunit_symtab &cust : obj_file.compunits ())
-	{
-	  const struct blockvector *bv = cust.blockvector ();
-	  const struct block *global_block = bv->global_block ();
-	  CORE_ADDR start = global_block->start ();
-	  CORE_ADDR end = global_block->end ();
-	  bool in_range_p = start <= pc && pc < end;
-	  if (!in_range_p)
-	    continue;
-
-	  if (bv->map () != nullptr)
-	    {
-	      if (bv->map ()->find (pc) == nullptr)
-		continue;
-
-	      return &cust;
-	    }
-
-	  CORE_ADDR range = end - start;
-	  if (best_cust != nullptr
-	      && range >= best_cust_range)
-	    /* Cust doesn't have a smaller range than best_cust, skip it.  */
-	    continue;
-
-	  /* For an objfile that has its functions reordered,
-	     find_pc_psymtab will find the proper partial symbol table
-	     and we simply return its corresponding symtab.  */
-	  /* In order to better support objfiles that contain both
-	     stabs and coff debugging info, we continue on if a psymtab
-	     can't be found.  */
-	  struct compunit_symtab *result
-	    = obj_file.find_pc_sect_compunit_symtab (msymbol, pc,
-						     section, 0);
-	  if (result != nullptr)
-	    return result;
-
-	  if (section != 0)
-	    {
-	      struct symbol *found_sym = nullptr;
-
-	      for (int b_index = GLOBAL_BLOCK;
-		   b_index <= STATIC_BLOCK && found_sym == nullptr;
-		   ++b_index)
-		{
-		  const struct block *b = bv->block (b_index);
-		  for (struct symbol *sym : block_iterator_range (b))
-		    {
-		      if (matching_obj_sections (sym->obj_section (&obj_file),
-						 section))
-			{
-			  found_sym = sym;
-			  break;
-			}
-		    }
-		}
-	      if (found_sym == nullptr)
-		continue;		/* No symbol in this symtab matches
-					   section.  */
-	    }
-
-	  /* Cust is best found so far, save it.  */
-	  best_cust = &cust;
-	  best_cust_range = range;
-	}
-    }
-
-  if (best_cust != NULL)
-    return best_cust;
-
-  /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs).  */
-
   for (objfile &objf : current_program_space->objfiles ())
     {
       struct compunit_symtab *result
-- 
2.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (2 preceding siblings ...)
  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
  2026-03-04 16:59 ` [PATCH v2 5/7] gdb: do not set blockvector address map Jan Vrany
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 5/7] gdb: do not set blockvector address map
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (3 preceding siblings ...)
  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 ` Jan Vrany
  2026-03-04 16:59 ` [PATCH v2 6/7] gdb: remove address map from struct blockvector Jan Vrany
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit removes the code that sets blockvector's addrmap in case one
or more blocks are non-contiguous. Following commit will fix GDB to
handle such blocks without use of the addrmap.

Testing on Debian x86_64 using with and without -readnow, I see no new
regressions except following:

    FAIL: gdb.dwarf2/debug-names.exp: print _start

This is caused by discrepancy between the debug info and the debug names
and will be eventually fixed in a separate patch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/buildsym.c | 55 ++------------------------------------------------
 1 file changed, 2 insertions(+), 53 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index aa95889424b..5f47d0d5835 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -316,18 +316,10 @@ buildsym_compunit::make_blockvector ()
   std::unique_ptr<struct blockvector> blockvector;
   int i;
 
-  /* Count the length of the list of blocks.  Also, if any blocks are
-     non-contiguous then we need to make use of the addrmap for mapping
-     addresses to blocks (PENDING_ADDRMAP_INTERESTING is set to true).  If
-     all the blocks are contiguous then we can avoid creating the addrmap,
-     and perform block look up using the blockvector.  */
+  /* Count the length of the list of blocks.  */
 
-  bool pending_addrmap_interesting = false;
   for (next = m_pending_blocks, i = 0; next; next = next->next, i++)
-    {
-      if (!next->block->is_contiguous ())
-	pending_addrmap_interesting = true;
-    }
+    ;
 
   blockvector = std::make_unique<struct blockvector> (i);
 
@@ -345,49 +337,6 @@ buildsym_compunit::make_blockvector ()
   m_pending_block_obstack.clear ();
   m_pending_blocks = nullptr;
 
-  /* If we needed an address map for this symtab, record it in the
-     blockvector.  */
-  if (pending_addrmap_interesting)
-    {
-      struct addrmap_mutable pending_addrmap;
-      int num_blocks = blockvector->num_blocks ();
-
-      /* If PENDING_ADDRMAP_INTERESTING is true then we must have seen
-	 an interesting block.  If we see one block, then we should at a
-	 minimum have a global block, and a static block.  */
-      gdb_assert (num_blocks > 1);
-
-      /* Assert our understanding of how the blocks are laid out.  */
-      gdb_assert (blockvector->block (0)->is_global_block ());
-      gdb_assert (blockvector->block (1)->is_static_block ());
-
-      /* The 'J > 1' here is so that we don't place the global block into
-	 the map.  For CU with gaps, the static block will reflect the
-	 gaps, while the global block will just reflect the full extent of
-	 the range.  */
-      for (int j = num_blocks; j > 1; )
-	{
-	  --j;
-	  struct block *b = blockvector->block (j);
-
-	  gdb_assert (!b->is_global_block ());
-
-	  if (b->is_contiguous ())
-	    pending_addrmap.set_empty (b->start (), (b->end () - 1), b);
-	  else
-	    {
-	      for (const auto &br : b->ranges ())
-		pending_addrmap.set_empty (br.start (), (br.end () - 1), b);
-	    }
-	}
-
-      blockvector->set_map
-	(new (&m_objfile->objfile_obstack) addrmap_fixed
-	 (&m_objfile->objfile_obstack, &pending_addrmap));
-    }
-  else
-    blockvector->set_map (nullptr);
-
   /* Some compilers output blocks in the wrong order, but we depend on
      their being in the right order so we can binary search.  Check the
      order and moan about it.
-- 
2.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 6/7] gdb: remove address map from struct blockvector
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (4 preceding siblings ...)
  2026-03-04 16:59 ` [PATCH v2 5/7] gdb: do not set blockvector address map Jan Vrany
@ 2026-03-04 16:59 ` Jan Vrany
  2026-03-04 16:59 ` [PATCH v2 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit removes m_map member and its accessors from struct blockvector
since it is no longer used. It also updates unit test accordingly.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/block-selftests.c | 90 ++++++++++++-------------------------------
 gdb/block.c           | 10 -----
 gdb/block.h           | 13 -------
 3 files changed, 24 insertions(+), 89 deletions(-)

diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c
index d23783d6bdc..77b8d67ded8 100644
--- a/gdb/block-selftests.c
+++ b/gdb/block-selftests.c
@@ -40,35 +40,19 @@ make_block (struct blockvector &bv, struct obstack &ob, CORE_ADDR start,
   return b;
 }
 
-/* A helper to create and set address map given a blockvector.  */
 static void
-make_map (struct blockvector &bv, struct obstack &ob)
+test_blockvector_lookup_contains ()
 {
-  struct addrmap_mutable map;
-
-  for (int i = bv.num_blocks () - 1; i > STATIC_BLOCK; i--)
-    {
-      auto b = bv.block (i);
-      map.set_empty (b->start (), b->end () - 1, b);
-    }
-
-  bv.set_map (new (&ob) addrmap_fixed (&ob, &map));
-}
-
-/* Create and return blockvector with following blocks:
+  /* Create blockvector with following blocks:
 
 	B0    0x1000 - 0x4000   (global block)
 	B1    0x1000 - 0x4000   (static block)
-	 B2   0x1000 - 0x2000
+	  B2  0x1000 - 0x2000
 				(hole)
-	 B3   0x3000 - 0x4000
-
-  If USE_MAP is true, then also set blockvector's address map.
-*/
-static blockvector_up
-make_blockvector (struct obstack &ob, bool use_map)
-{
-  auto bv = std::make_unique<struct blockvector> (0);
+	  B3  0x3000 - 0x4000
+  */
+  auto_obstack ob;
+  blockvector_up bv = std::make_unique<struct blockvector> (0);
 
   auto global_block = make_block (*bv.get (), ob, 0x1000, 0x4000);
   auto static_block = make_block (*bv.get (), ob, 0x1000, 0x4000,
@@ -76,51 +60,25 @@ make_blockvector (struct obstack &ob, bool use_map)
   make_block (*bv.get (), ob, 0x1000, 0x2000, static_block);
   make_block (*bv.get (), ob, 0x3000, 0x4000, static_block);
 
-  if (use_map)
-    make_map (*bv.get (), ob);
+  /* Test address outside global block's range.  */
+  SELF_CHECK (bv->lookup (0x0500) == nullptr);
+  SELF_CHECK (bv->contains (0x0500) == false);
 
-  return bv;
-}
+  /* Test address falling into a block.  */
+  SELF_CHECK (bv->lookup (0x1500) == bv->block (2));
+  SELF_CHECK (bv->contains (0x1500) == true);
 
-static void
-test_blockvector_lookup_contains ()
-{
-  for (bool with_map : { false, true })
-    {
-      /* Test blockvector without an address map.  */
-      auto_obstack ob;
-      blockvector_up bv = make_blockvector (ob, with_map);
-
-      /* Test address outside global block's range.  */
-      SELF_CHECK (bv->lookup (0x0500) == nullptr);
-      SELF_CHECK (bv->contains (0x0500) == false);
-
-      /* Test address falling into a block.  */
-      SELF_CHECK (bv->lookup (0x1500) == bv->block (2));
-      SELF_CHECK (bv->contains (0x1500) == true);
-
-      /* Test address falling into a "hole".  If BV has an address map,
-	 lookup () returns nullptr and contains (). returns false.  If not,
-	 lookup () return static block and contains() returns true.  */
-      if (with_map)
-	{
-	  SELF_CHECK (bv->lookup (0x2500) == nullptr);
-	  SELF_CHECK (bv->contains (0x2500) == false);
-	}
-      else
-	{
-	  SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK));
-	  SELF_CHECK (bv->contains (0x2500) == true);
-	}
-
-      /* Test address falling into a block above the "hole".  */
-      SELF_CHECK (bv->lookup (0x3500) == bv->block (3));
-      SELF_CHECK (bv->contains (0x3500) == true);
-
-      /* Test address outside global block's range.  */
-      SELF_CHECK (bv->lookup (0x4000) == nullptr);
-      SELF_CHECK (bv->contains (0x4000) == false);
-    }
+  /* Test address falling into a "hole".  */
+  SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK));
+  SELF_CHECK (bv->contains (0x2500) == true);
+
+  /* Test address falling into a block above the "hole".  */
+  SELF_CHECK (bv->lookup (0x3500) == bv->block (3));
+  SELF_CHECK (bv->contains (0x3500) == true);
+
+  /* Test address outside global block's range.  */
+  SELF_CHECK (bv->lookup (0x4000) == nullptr);
+  SELF_CHECK (bv->contains (0x4000) == false);
 }
 
 } /* namespace selftests */
diff --git a/gdb/block.c b/gdb/block.c
index b964674865b..cd0f60ef3cb 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -842,11 +842,6 @@ blockvector::lookup (CORE_ADDR addr) const
   if (addr < start || end <= addr)
     return nullptr;
 
-  /* If we have an addrmap mapping code addresses to blocks, then use
-     that.  */
-  if (map () != nullptr)
-    return (const struct block *) map ()->find (addr);
-
   /* Otherwise, use binary search to find the last block that starts
      before PC.
      Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
@@ -925,11 +920,6 @@ void
 blockvector::relocate (struct objfile *objfile,
 		       gdb::array_view<const CORE_ADDR> offsets)
 {
-  int block_line_section = SECT_OFF_TEXT (objfile);
-
-  if (m_map != nullptr)
-    m_map->relocate (offsets[block_line_section]);
-
   for (struct block *b : m_blocks)
     b->relocate (objfile, offsets);
 }
diff --git a/gdb/block.h b/gdb/block.h
index 59cabbd620d..9a7e8a591d3 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -492,14 +492,6 @@ struct blockvector
   const struct block *static_block () const
   { return this->block (STATIC_BLOCK); }
 
-  /* Const version of the above.  */
-  const addrmap_fixed *map () const
-  { return m_map; }
-
-  /* Set this blockvector's address -> block map.  */
-  void set_map (addrmap_fixed *map)
-  { m_map = map; }
-
   /* Block comparison function.  Returns true if B1 must be ordered before
      B2 in a blockvector, false otherwise.  */
   static bool block_less_than (const struct block *b1, const struct block *b2);
@@ -526,11 +518,6 @@ struct blockvector
 		 gdb::array_view<const CORE_ADDR> offsets);
 
 private:
-  /* An address map mapping addresses to blocks in this blockvector.
-     This pointer is zero if the blocks' start and end addresses are
-     enough.  */
-  addrmap_fixed *m_map = nullptr;
-
   /* The blocks themselves.  */
   std::vector<struct block *> m_blocks;
 };
-- 
2.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (5 preceding siblings ...)
  2026-03-04 16:59 ` [PATCH v2 6/7] gdb: remove address map from struct blockvector Jan Vrany
@ 2026-03-04 16:59 ` Jan Vrany
  2026-03-10 18:14 ` [PING] Re: [PATCH v2 0/7] Remove addrmap from blockvector Jan Vraný
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-03-04 16:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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.51.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
  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
  0 siblings, 0 replies; 20+ messages in thread
From: Tom Tromey @ 2026-03-04 21:19 UTC (permalink / raw)
  To: Jan Vrany; +Cc: gdb-patches, Tom Tromey, Simon Marchi

>>>>> "Jan" == Jan Vrany <jan.vrany@labware.com> writes:

Jan> This commit updates expanded_symbols_functions::find_pc_sect_compunit_symtab
Jan> to search all compunits rather than just returning null.

Jan> The original implementation (just return null) was based on reasoning
Jan> that its would suffice since find_compunit_symtab_for_pc_sect walks
Jan> all CUs anyway [1]. This commit is a preparation to simplify
Jan> find_compunit_symtab_for_pc_sect by removing that code.

Jan> Approved-By: Tom Tromey <tom@tromey.com>
Jan> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829

Jan> +  for (compunit_symtab &symtab : objfile->compunits ())

This "conflicts" with Simon's change to
expanded_symbols_functions -- whichever patch lands second will have to
be updated to account for the patch that lands first.

I just wanted to make sure you both are aware.

I think the change should be just looping over the local compunits, and
as far as I'm concerned that qualifies as obvious.

thanks,
Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PING] Re: [PATCH v2 0/7] Remove addrmap from blockvector
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (6 preceding siblings ...)
  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 ` Jan Vraný
  2026-04-22 10:29 ` [PATCH v3 " Jan Vrany
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vraný @ 2026-03-10 18:14 UTC (permalink / raw)
  To: gdb-patches

Polite ping.

Thanks! Jan

On Wed, 2026-03-04 at 16:59 +0000, Jan Vrany wrote:
> This is a v2 of a series removing the addrmap from blockvector, a step towards
> expandable blockvectors which are needed for lazy CU expansion and for
> Python JIT API.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
> 
> * v1 submission is here:
> 
>   https://inbox.sourceware.org/gdb-patches/20260219185638.360694-1-jan.vrany@labware.com/
> 
> * changes since v2:
> 
>   * fix formatting and missing comments
> 
>   * swapped commits "gdb: remove address map from struct blockvector"
>     and "gdb: update blockvector::lookup to handle non-contiguous blocks"
>     to make code bisectable
> 
>   * rework readnow_functions::find_pc_sect_compunit_symtab to work with
>     interleaved CUs.
> 
> Jan Vrany (7):
>   gdb: implement readnow_functions::find_pc_sect_compunit_symtab
>   gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
>   gdb: simplify find_compunit_symtab_for_pc_sect
>   gdb: update blockvector::lookup to handle non-contiguous blocks
>   gdb: do not set blockvector address map
>   gdb: remove address map from struct blockvector
>   gdb: add unit test for blockvector::lookup of non-contiguous blocks
> 
>  gdb/block-selftests.c | 156 +++++++++++++++++++++++++-----------------
>  gdb/block.c           |  34 ++++++---
>  gdb/block.h           |  17 ++---
>  gdb/buildsym.c        |  55 +--------------
>  gdb/dwarf2/read.c     |  73 +++++++++++++++++---
>  gdb/expanded-symbol.c |  18 +++++
>  gdb/expanded-symbol.h |   8 +--
>  gdb/symtab.c          |  91 ------------------------
>  8 files changed, 206 insertions(+), 246 deletions(-)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 0/7] Remove addrmap from blockvector
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (7 preceding siblings ...)
  2026-03-10 18:14 ` [PING] Re: [PATCH v2 0/7] Remove addrmap from blockvector Jan Vraný
@ 2026-04-22 10:29 ` 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
                   ` (6 subsequent siblings)
  15 siblings, 2 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This is a v3 of an earlier series removing the addrmap from blockvector, a
step towards expandable blockvectors which are needed for lazy CU expansion
and forPython JIT API.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829

* v1 submission is here:

  https://inbox.sourceware.org/gdb-patches/20260219185638.360694-1-jan.vrany@labware.com/

* v2 submission is here:

  https://inbox.sourceware.org/gdb-patches/20260304165914.3209106-1-jan.vrany@labware.com/

* changes since v3:

  * rebased on current master to accomodate changes in expanded_symbols_functions

  * re-tested on Linux x86_64 both with and without -readnow. I have spotted
    no regressions, but I need to say that on my machine and with my test
    setup a lot of tests fail with -readnow.

Thanks!

Jan

---

Jan Vrany (7):
  gdb: implement readnow_functions::find_pc_sect_compunit_symtab
  gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
  gdb: simplify find_compunit_symtab_for_pc_sect
  gdb: update blockvector::lookup to handle non-contiguous blocks
  gdb: do not set blockvector address map
  gdb: remove address map from struct blockvector
  gdb: add unit test for blockvector::lookup of non-contiguous blocks

 gdb/block-selftests.c | 156 +++++++++++++++++++++++++-----------------
 gdb/block.c           |  34 ++++++---
 gdb/block.h           |  17 ++---
 gdb/buildsym.c        |  55 +--------------
 gdb/dwarf2/read.c     |  73 +++++++++++++++++---
 gdb/expanded-symbol.c |  18 +++++
 gdb/expanded-symbol.h |   8 +--
 gdb/symtab.c          |  91 ------------------------
 8 files changed, 206 insertions(+), 246 deletions(-)

-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 1/7] gdb: implement readnow_functions::find_pc_sect_compunit_symtab
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (8 preceding siblings ...)
  2026-04-22 10:29 ` [PATCH v3 " Jan Vrany
@ 2026-04-22 10:29 ` Jan Vrany
  2026-04-22 10:29 ` [PATCH v3 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab Jan Vrany
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 2/7] gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (9 preceding siblings ...)
  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 ` Jan Vrany
  2026-04-22 10:29 ` [PATCH v3 3/7] gdb: simplify find_compunit_symtab_for_pc_sect Jan Vrany
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany, Tom Tromey

This commit updates expanded_symbols_functions::find_pc_sect_compunit_symtab
to search all compunits rather than just returning null.

The original implementation (just return null) was based on reasoning
that its would suffice since find_compunit_symtab_for_pc_sect walks
all CUs anyway [1]. This commit is a preparation to simplify
find_compunit_symtab_for_pc_sect by removing that code.

Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829

[1] https://inbox.sourceware.org/gdb-patches/874iqoogoa.fsf@tromey.com/
---
 gdb/expanded-symbol.c | 18 ++++++++++++++++++
 gdb/expanded-symbol.h |  8 +-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/gdb/expanded-symbol.c b/gdb/expanded-symbol.c
index 6dcb4047e3f..81f592bb71d 100644
--- a/gdb/expanded-symbol.c
+++ b/gdb/expanded-symbol.c
@@ -18,6 +18,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "block.h"
 #include "objfiles.h"
 #include "symtab.h"
 #include "source.h"
@@ -115,3 +116,20 @@ expanded_symbols_functions::find_symbol_by_address (objfile *objfile,
 
   return nullptr;
 }
+
+/* See expanded-symbol.h.  */
+
+compunit_symtab *
+expanded_symbols_functions::find_pc_sect_compunit_symtab
+    (objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
+     obj_section *section, int warn_if_readin)
+{
+  for (compunit_symtab *symtab : m_compunit_symtabs)
+    {
+      const blockvector *bv = symtab->blockvector ();
+      if (bv != nullptr && bv->contains (pc))
+	return symtab;
+    }
+
+  return nullptr;
+}
diff --git a/gdb/expanded-symbol.h b/gdb/expanded-symbol.h
index 68f5532e6b8..d57ca4ef4ce 100644
--- a/gdb/expanded-symbol.h
+++ b/gdb/expanded-symbol.h
@@ -77,13 +77,7 @@ struct expanded_symbols_functions : public quick_symbol_functions
 
   compunit_symtab *find_pc_sect_compunit_symtab
     (objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
-     obj_section *section, int warn_if_readin) override
-  {
-    /* Simply returning NULL here is okay since the (only) caller
-       find_compunit_symtab_for_pc_sect iterates over existing CUs
-       anyway.  */
-    return nullptr;
-  }
+     obj_section *section, int warn_if_readin) override;
 
   symbol *find_symbol_by_address (objfile *objfile, CORE_ADDR address)
     override;
-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 3/7] gdb: simplify find_compunit_symtab_for_pc_sect
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (10 preceding siblings ...)
  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 ` Jan Vrany
  2026-04-22 10:30 ` [PATCH v3 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks Jan Vrany
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit simplifies find_compunit_symtab_for_pc_sect by removing the
code that walks over all (currently expanded) CUs and delegating to
quick_symbol_functions::find_pc_sect_compunit_symtab instead.

With this commit on Linux x86_64 I see no regression both with and
without -readnow.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/dwarf2/read.c |  8 -----
 gdb/symtab.c      | 91 -----------------------------------------------
 2 files changed, 99 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e9ea276b927..7352bc605ed 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2097,17 +2097,9 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
   if (data == nullptr)
     return nullptr;
 
-  if (warn_if_readin && per_objfile->compunit_symtab_set_p (data))
-    warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
-	     paddress (objfile->arch (), pc));
-
   compunit_symtab *result = find_pc_sect_compunit_symtab_includes
     (dw2_instantiate_symtab (data, per_objfile, false), pc);
 
-  if (warn_if_readin && result == nullptr)
-    warning (_("(Error: pc %s in address map, but not in symtab.)"),
-	     paddress (objfile->arch (), pc));
-
   return result;
 }
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 357b8e63b19..d909d41bf6e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2717,9 +2717,6 @@ for_each_symbol (const struct block *block, const lookup_name_info &name,
 struct compunit_symtab *
 find_compunit_symtab_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
 {
-  struct compunit_symtab *best_cust = NULL;
-  CORE_ADDR best_cust_range = 0;
-
   /* If we know that this is not a text address, return failure.  This is
      necessary because we loop based on the block's high and low code
      addresses, which do not include the data ranges, and because
@@ -2730,94 +2727,6 @@ find_compunit_symtab_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
   if (msymbol.minsym && msymbol.minsym->data_p ())
     return NULL;
 
-  /* Search all symtabs for the one whose file contains our address, and which
-     is the smallest of all the ones containing the address.  This is designed
-     to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
-     and symtab b is at 0x2000-0x3000.  So the GLOBAL_BLOCK for a is from
-     0x1000-0x4000, but for address 0x2345 we want to return symtab b.
-
-     This happens for native ecoff format, where code from included files
-     gets its own symtab.  The symtab for the included file should have
-     been read in already via the dependency mechanism.
-     It might be swifter to create several symtabs with the same name
-     like xcoff does (I'm not sure).
-
-     It also happens for objfiles that have their functions reordered.
-     For these, the symtab we are looking for is not necessarily read in.  */
-
-  for (objfile &obj_file : current_program_space->objfiles ())
-    {
-      for (compunit_symtab &cust : obj_file.compunits ())
-	{
-	  const struct blockvector *bv = cust.blockvector ();
-	  const struct block *global_block = bv->global_block ();
-	  CORE_ADDR start = global_block->start ();
-	  CORE_ADDR end = global_block->end ();
-	  bool in_range_p = start <= pc && pc < end;
-	  if (!in_range_p)
-	    continue;
-
-	  if (bv->map () != nullptr)
-	    {
-	      if (bv->map ()->find (pc) == nullptr)
-		continue;
-
-	      return &cust;
-	    }
-
-	  CORE_ADDR range = end - start;
-	  if (best_cust != nullptr
-	      && range >= best_cust_range)
-	    /* Cust doesn't have a smaller range than best_cust, skip it.  */
-	    continue;
-
-	  /* For an objfile that has its functions reordered,
-	     find_pc_psymtab will find the proper partial symbol table
-	     and we simply return its corresponding symtab.  */
-	  /* In order to better support objfiles that contain both
-	     stabs and coff debugging info, we continue on if a psymtab
-	     can't be found.  */
-	  struct compunit_symtab *result
-	    = obj_file.find_pc_sect_compunit_symtab (msymbol, pc,
-						     section, 0);
-	  if (result != nullptr)
-	    return result;
-
-	  if (section != 0)
-	    {
-	      struct symbol *found_sym = nullptr;
-
-	      for (int b_index = GLOBAL_BLOCK;
-		   b_index <= STATIC_BLOCK && found_sym == nullptr;
-		   ++b_index)
-		{
-		  const struct block *b = bv->block (b_index);
-		  for (struct symbol *sym : block_iterator_range (b))
-		    {
-		      if (matching_obj_sections (sym->obj_section (&obj_file),
-						 section))
-			{
-			  found_sym = sym;
-			  break;
-			}
-		    }
-		}
-	      if (found_sym == nullptr)
-		continue;		/* No symbol in this symtab matches
-					   section.  */
-	    }
-
-	  /* Cust is best found so far, save it.  */
-	  best_cust = &cust;
-	  best_cust_range = range;
-	}
-    }
-
-  if (best_cust != NULL)
-    return best_cust;
-
-  /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs).  */
-
   for (objfile &objf : current_program_space->objfiles ())
     {
       struct compunit_symtab *result
-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 4/7] gdb: update blockvector::lookup to handle non-contiguous blocks
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (11 preceding siblings ...)
  2026-04-22 10:29 ` [PATCH v3 3/7] gdb: simplify find_compunit_symtab_for_pc_sect Jan Vrany
@ 2026-04-22 10:30 ` Jan Vrany
  2026-04-22 10:30 ` [PATCH v3 5/7] gdb: do not set blockvector address map Jan Vrany
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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 dc00327048f..b266ec38ea4 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 091120ae2b8..34bafb962d7 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 7352bc605ed..5cee71bb8e3 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9289,6 +9289,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> rangevec;
 	  dwarf2_ranges_process (ranges_offset, cu, die->tag,
 				 [&] (unrelocated_addr start,
@@ -9296,10 +9299,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);
 	    rangevec.emplace_back (abs_start, abs_end);
 	  });
 
+	  gdb_assert (rangevec.size () == 0 || block->start () == lo);
+	  gdb_assert (rangevec.size () == 0 || block->end () == hi);
+
 	  block->set_ranges (make_blockranges (objfile, rangevec));
 	}
     }
-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 5/7] gdb: do not set blockvector address map
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (12 preceding siblings ...)
  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 ` 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
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit removes the code that sets blockvector's addrmap in case one
or more blocks are non-contiguous. Following commit will fix GDB to
handle such blocks without use of the addrmap.

Testing on Debian x86_64 using with and without -readnow, I see no new
regressions except following:

    FAIL: gdb.dwarf2/debug-names.exp: print _start

This is caused by discrepancy between the debug info and the debug names
and will be eventually fixed in a separate patch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/buildsym.c | 55 ++------------------------------------------------
 1 file changed, 2 insertions(+), 53 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 9799af17f32..c343e1d10f7 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -316,18 +316,10 @@ buildsym_compunit::make_blockvector ()
   std::unique_ptr<struct blockvector> blockvector;
   int i;
 
-  /* Count the length of the list of blocks.  Also, if any blocks are
-     non-contiguous then we need to make use of the addrmap for mapping
-     addresses to blocks (PENDING_ADDRMAP_INTERESTING is set to true).  If
-     all the blocks are contiguous then we can avoid creating the addrmap,
-     and perform block look up using the blockvector.  */
+  /* Count the length of the list of blocks.  */
 
-  bool pending_addrmap_interesting = false;
   for (next = m_pending_blocks, i = 0; next; next = next->next, i++)
-    {
-      if (!next->block->is_contiguous ())
-	pending_addrmap_interesting = true;
-    }
+    ;
 
   blockvector = std::make_unique<struct blockvector> (i);
 
@@ -345,49 +337,6 @@ buildsym_compunit::make_blockvector ()
   m_pending_block_obstack.clear ();
   m_pending_blocks = nullptr;
 
-  /* If we needed an address map for this symtab, record it in the
-     blockvector.  */
-  if (pending_addrmap_interesting)
-    {
-      struct addrmap_mutable pending_addrmap;
-      int num_blocks = blockvector->num_blocks ();
-
-      /* If PENDING_ADDRMAP_INTERESTING is true then we must have seen
-	 an interesting block.  If we see one block, then we should at a
-	 minimum have a global block, and a static block.  */
-      gdb_assert (num_blocks > 1);
-
-      /* Assert our understanding of how the blocks are laid out.  */
-      gdb_assert (blockvector->block (0)->is_global_block ());
-      gdb_assert (blockvector->block (1)->is_static_block ());
-
-      /* The 'J > 1' here is so that we don't place the global block into
-	 the map.  For CU with gaps, the static block will reflect the
-	 gaps, while the global block will just reflect the full extent of
-	 the range.  */
-      for (int j = num_blocks; j > 1; )
-	{
-	  --j;
-	  struct block *b = blockvector->block (j);
-
-	  gdb_assert (!b->is_global_block ());
-
-	  if (b->is_contiguous ())
-	    pending_addrmap.set_empty (b->start (), (b->end () - 1), b);
-	  else
-	    {
-	      for (const auto &br : b->ranges ())
-		pending_addrmap.set_empty (br.start (), (br.end () - 1), b);
-	    }
-	}
-
-      blockvector->set_map
-	(new (&m_objfile->objfile_obstack) addrmap_fixed
-	 (&m_objfile->objfile_obstack, &pending_addrmap));
-    }
-  else
-    blockvector->set_map (nullptr);
-
   /* Some compilers output blocks in the wrong order, but we depend on
      their being in the right order so we can binary search.  Check the
      order and moan about it.
-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 6/7] gdb: remove address map from struct blockvector
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (13 preceding siblings ...)
  2026-04-22 10:30 ` [PATCH v3 5/7] gdb: do not set blockvector address map Jan Vrany
@ 2026-04-22 10:30 ` Jan Vrany
  2026-04-22 10:30 ` [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

This commit removes m_map member and its accessors from struct blockvector
since it is no longer used. It also updates unit test accordingly.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
---
 gdb/block-selftests.c | 90 ++++++++++++-------------------------------
 gdb/block.c           | 10 -----
 gdb/block.h           | 13 -------
 3 files changed, 24 insertions(+), 89 deletions(-)

diff --git a/gdb/block-selftests.c b/gdb/block-selftests.c
index d23783d6bdc..77b8d67ded8 100644
--- a/gdb/block-selftests.c
+++ b/gdb/block-selftests.c
@@ -40,35 +40,19 @@ make_block (struct blockvector &bv, struct obstack &ob, CORE_ADDR start,
   return b;
 }
 
-/* A helper to create and set address map given a blockvector.  */
 static void
-make_map (struct blockvector &bv, struct obstack &ob)
+test_blockvector_lookup_contains ()
 {
-  struct addrmap_mutable map;
-
-  for (int i = bv.num_blocks () - 1; i > STATIC_BLOCK; i--)
-    {
-      auto b = bv.block (i);
-      map.set_empty (b->start (), b->end () - 1, b);
-    }
-
-  bv.set_map (new (&ob) addrmap_fixed (&ob, &map));
-}
-
-/* Create and return blockvector with following blocks:
+  /* Create blockvector with following blocks:
 
 	B0    0x1000 - 0x4000   (global block)
 	B1    0x1000 - 0x4000   (static block)
-	 B2   0x1000 - 0x2000
+	  B2  0x1000 - 0x2000
 				(hole)
-	 B3   0x3000 - 0x4000
-
-  If USE_MAP is true, then also set blockvector's address map.
-*/
-static blockvector_up
-make_blockvector (struct obstack &ob, bool use_map)
-{
-  auto bv = std::make_unique<struct blockvector> (0);
+	  B3  0x3000 - 0x4000
+  */
+  auto_obstack ob;
+  blockvector_up bv = std::make_unique<struct blockvector> (0);
 
   auto global_block = make_block (*bv.get (), ob, 0x1000, 0x4000);
   auto static_block = make_block (*bv.get (), ob, 0x1000, 0x4000,
@@ -76,51 +60,25 @@ make_blockvector (struct obstack &ob, bool use_map)
   make_block (*bv.get (), ob, 0x1000, 0x2000, static_block);
   make_block (*bv.get (), ob, 0x3000, 0x4000, static_block);
 
-  if (use_map)
-    make_map (*bv.get (), ob);
+  /* Test address outside global block's range.  */
+  SELF_CHECK (bv->lookup (0x0500) == nullptr);
+  SELF_CHECK (bv->contains (0x0500) == false);
 
-  return bv;
-}
+  /* Test address falling into a block.  */
+  SELF_CHECK (bv->lookup (0x1500) == bv->block (2));
+  SELF_CHECK (bv->contains (0x1500) == true);
 
-static void
-test_blockvector_lookup_contains ()
-{
-  for (bool with_map : { false, true })
-    {
-      /* Test blockvector without an address map.  */
-      auto_obstack ob;
-      blockvector_up bv = make_blockvector (ob, with_map);
-
-      /* Test address outside global block's range.  */
-      SELF_CHECK (bv->lookup (0x0500) == nullptr);
-      SELF_CHECK (bv->contains (0x0500) == false);
-
-      /* Test address falling into a block.  */
-      SELF_CHECK (bv->lookup (0x1500) == bv->block (2));
-      SELF_CHECK (bv->contains (0x1500) == true);
-
-      /* Test address falling into a "hole".  If BV has an address map,
-	 lookup () returns nullptr and contains (). returns false.  If not,
-	 lookup () return static block and contains() returns true.  */
-      if (with_map)
-	{
-	  SELF_CHECK (bv->lookup (0x2500) == nullptr);
-	  SELF_CHECK (bv->contains (0x2500) == false);
-	}
-      else
-	{
-	  SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK));
-	  SELF_CHECK (bv->contains (0x2500) == true);
-	}
-
-      /* Test address falling into a block above the "hole".  */
-      SELF_CHECK (bv->lookup (0x3500) == bv->block (3));
-      SELF_CHECK (bv->contains (0x3500) == true);
-
-      /* Test address outside global block's range.  */
-      SELF_CHECK (bv->lookup (0x4000) == nullptr);
-      SELF_CHECK (bv->contains (0x4000) == false);
-    }
+  /* Test address falling into a "hole".  */
+  SELF_CHECK (bv->lookup (0x2500) == bv->block (STATIC_BLOCK));
+  SELF_CHECK (bv->contains (0x2500) == true);
+
+  /* Test address falling into a block above the "hole".  */
+  SELF_CHECK (bv->lookup (0x3500) == bv->block (3));
+  SELF_CHECK (bv->contains (0x3500) == true);
+
+  /* Test address outside global block's range.  */
+  SELF_CHECK (bv->lookup (0x4000) == nullptr);
+  SELF_CHECK (bv->contains (0x4000) == false);
 }
 
 } /* namespace selftests */
diff --git a/gdb/block.c b/gdb/block.c
index b266ec38ea4..98c99145b15 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -842,11 +842,6 @@ blockvector::lookup (CORE_ADDR addr) const
   if (addr < start || end <= addr)
     return nullptr;
 
-  /* If we have an addrmap mapping code addresses to blocks, then use
-     that.  */
-  if (map () != nullptr)
-    return (const struct block *) map ()->find (addr);
-
   /* Otherwise, use binary search to find the last block that starts
      before PC.
      Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
@@ -925,11 +920,6 @@ void
 blockvector::relocate (struct objfile *objfile,
 		       gdb::array_view<const CORE_ADDR> offsets)
 {
-  int block_line_section = SECT_OFF_TEXT (objfile);
-
-  if (m_map != nullptr)
-    m_map->relocate (offsets[block_line_section]);
-
   for (struct block *b : m_blocks)
     b->relocate (objfile, offsets);
 }
diff --git a/gdb/block.h b/gdb/block.h
index 34bafb962d7..72bc4a5dca3 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -492,14 +492,6 @@ struct blockvector
   const struct block *static_block () const
   { return this->block (STATIC_BLOCK); }
 
-  /* Const version of the above.  */
-  const addrmap_fixed *map () const
-  { return m_map; }
-
-  /* Set this blockvector's address -> block map.  */
-  void set_map (addrmap_fixed *map)
-  { m_map = map; }
-
   /* Block comparison function.  Returns true if B1 must be ordered before
      B2 in a blockvector, false otherwise.  */
   static bool block_less_than (const struct block *b1, const struct block *b2);
@@ -526,11 +518,6 @@ struct blockvector
 		 gdb::array_view<const CORE_ADDR> offsets);
 
 private:
-  /* An address map mapping addresses to blocks in this blockvector.
-     This pointer is zero if the blocks' start and end addresses are
-     enough.  */
-  addrmap_fixed *m_map = nullptr;
-
   /* The blocks themselves.  */
   std::vector<struct block *> m_blocks;
 };
-- 
2.53.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks
  2026-03-04 16:59 [PATCH v2 0/7] Remove addrmap from blockvector Jan Vrany
                   ` (14 preceding siblings ...)
  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
  15 siblings, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-22 10:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Vrany

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



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PING] Re: [PATCH v3 0/7] Remove addrmap from blockvector
  2026-04-22 10:29 ` [PATCH v3 " Jan Vrany
@ 2026-04-28 18:55   ` Jan Vrany
  2026-05-08  9:14   ` Jan Vrany
  1 sibling, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-04-28 18:55 UTC (permalink / raw)
  To: gdb-patches

Polite ping. 

Thanks!

Jan

On Wed, 2026-04-22 at 10:29 +0000, Jan Vrany wrote:
> This is a v3 of an earlier series removing the addrmap from blockvector, a
> step towards expandable blockvectors which are needed for lazy CU expansion
> and forPython JIT API.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
> 
> * v1 submission is here:
> 
>   https://inbox.sourceware.org/gdb-patches/20260219185638.360694-1-jan.vrany@labware.com/
> 
> * v2 submission is here:
> 
>   https://inbox.sourceware.org/gdb-patches/20260304165914.3209106-1-jan.vrany@labware.com/
> 
> * changes since v3:
> 
>   * rebased on current master to accomodate changes in expanded_symbols_functions
> 
>   * re-tested on Linux x86_64 both with and without -readnow. I have spotted
>     no regressions, but I need to say that on my machine and with my test
>     setup a lot of tests fail with -readnow.
> 
> Thanks!
> 
> Jan
> 
> ---
> 
> Jan Vrany (7):
>   gdb: implement readnow_functions::find_pc_sect_compunit_symtab
>   gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
>   gdb: simplify find_compunit_symtab_for_pc_sect
>   gdb: update blockvector::lookup to handle non-contiguous blocks
>   gdb: do not set blockvector address map
>   gdb: remove address map from struct blockvector
>   gdb: add unit test for blockvector::lookup of non-contiguous blocks
> 
>  gdb/block-selftests.c | 156 +++++++++++++++++++++++++-----------------
>  gdb/block.c           |  34 ++++++---
>  gdb/block.h           |  17 ++---
>  gdb/buildsym.c        |  55 +--------------
>  gdb/dwarf2/read.c     |  73 +++++++++++++++++---
>  gdb/expanded-symbol.c |  18 +++++
>  gdb/expanded-symbol.h |   8 +--
>  gdb/symtab.c          |  91 ------------------------
>  8 files changed, 206 insertions(+), 246 deletions(-)
> 
> --
> 2.53.0
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PING] Re: [PATCH v3 0/7] Remove addrmap from blockvector
  2026-04-22 10:29 ` [PATCH v3 " Jan Vrany
  2026-04-28 18:55   ` [PING] " Jan Vrany
@ 2026-05-08  9:14   ` Jan Vrany
  1 sibling, 0 replies; 20+ messages in thread
From: Jan Vrany @ 2026-05-08  9:14 UTC (permalink / raw)
  To: gdb-patches

Polite ping. 

Thanks!

Jan

On Tue, 2026-04-28 at 19:55 +0100, Jan Vrany wrote:
> Polite ping. 
> 
> Thanks!
> 
> Jan
> 
> On Wed, 2026-04-22 at 10:29 +0000, Jan Vrany wrote:
> > This is a v3 of an earlier series removing the addrmap from blockvector, a
> > step towards expandable blockvectors which are needed for lazy CU expansion
> > and forPython JIT API.
> > 
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33829
> > 
> > * v1 submission is here:
> > 
> >   https://inbox.sourceware.org/gdb-patches/20260219185638.360694-1-jan.vrany@labware.com/
> > 
> > * v2 submission is here:
> > 
> >   https://inbox.sourceware.org/gdb-patches/20260304165914.3209106-1-jan.vrany@labware.com/
> > 
> > * changes since v3:
> > 
> >   * rebased on current master to accomodate changes in expanded_symbols_functions
> > 
> >   * re-tested on Linux x86_64 both with and without -readnow. I have spotted
> >     no regressions, but I need to say that on my machine and with my test
> >     setup a lot of tests fail with -readnow.
> > 
> > Thanks!
> > 
> > Jan
> > 
> > ---
> > 
> > Jan Vrany (7):
> >   gdb: implement readnow_functions::find_pc_sect_compunit_symtab
> >   gdb: update expanded_symbols_functions::find_pc_sect_compunit_symtab
> >   gdb: simplify find_compunit_symtab_for_pc_sect
> >   gdb: update blockvector::lookup to handle non-contiguous blocks
> >   gdb: do not set blockvector address map
> >   gdb: remove address map from struct blockvector
> >   gdb: add unit test for blockvector::lookup of non-contiguous blocks
> > 
> >  gdb/block-selftests.c | 156 +++++++++++++++++++++++++-----------------
> >  gdb/block.c           |  34 ++++++---
> >  gdb/block.h           |  17 ++---
> >  gdb/buildsym.c        |  55 +--------------
> >  gdb/dwarf2/read.c     |  73 +++++++++++++++++---
> >  gdb/expanded-symbol.c |  18 +++++
> >  gdb/expanded-symbol.h |   8 +--
> >  gdb/symtab.c          |  91 ------------------------
> >  8 files changed, 206 insertions(+), 246 deletions(-)
> > 
> > --
> > 2.53.0
> > 


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-05-08  9:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v3 7/7] gdb: add unit test for blockvector::lookup of non-contiguous blocks Jan Vrany

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox