public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 11/14] gdb: remove BLOCK_ENTRY_PC macro
@ 2022-04-21 15:03 Simon Marchi
  2022-04-21 15:03 ` [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 15:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Replace with equivalent method.

Change-Id: I0e033095e7358799930775e61028b48246971a7d
---
 gdb/ax-gdb.c                     |  2 +-
 gdb/block.h                      | 40 ++++++++++++++++++--------------
 gdb/blockframe.c                 |  8 +++----
 gdb/compile/compile-c-symbols.c  |  4 ++--
 gdb/compile/compile-object-run.c |  2 +-
 gdb/compile/compile.c            |  4 ++--
 gdb/dwarf2/loc.c                 |  4 ++--
 gdb/findvar.c                    |  4 ++--
 gdb/infcmd.c                     |  2 +-
 gdb/infrun.c                     |  4 ++--
 gdb/inline-frame.c               |  4 ++--
 gdb/linespec.c                   |  2 +-
 gdb/parse.c                      |  4 ++--
 gdb/printcmd.c                   |  4 ++--
 gdb/symtab.c                     | 12 +++++-----
 gdb/tracepoint.c                 |  4 ++--
 gdb/value.c                      |  2 +-
 17 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index e2e311f9d74a..f8ea8adc6266 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -571,7 +571,7 @@ gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
       break;
 
     case LOC_BLOCK:
-      ax_const_l (ax, BLOCK_ENTRY_PC (var->value_block ()));
+      ax_const_l (ax, var->value_block ()->entry_pc ());
       value->kind = axs_rvalue;
       break;
 
diff --git a/gdb/block.h b/gdb/block.h
index 96ceea23020e..e7bc725c4716 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -183,6 +183,28 @@ struct block
     return this->ranges ().size () == 0 || this->ranges ().size () == 1;
   }
 
+  /* Define the "entry pc" for a block BL to be the lowest (start) address
+     for the block when all addresses within the block are contiguous.  If
+     non-contiguous, then use the start address for the first range in the
+     block.
+
+     At the moment, this almost matches what DWARF specifies as the entry
+     pc.  (The missing bit is support for DW_AT_entry_pc which should be
+     preferred over range data and the low_pc.)
+
+     Once support for DW_AT_entry_pc is added, I expect that an entry_pc
+     field will be added to one of these data structures.  Once that's done,
+     the entry_pc field can be set from the dwarf reader (and other readers
+     too).  ENTRY_PC can then be redefined to be less DWARF-centric.  */
+
+  CORE_ADDR entry_pc () const
+  {
+    if (this->is_contiguous ())
+      return this->start ();
+    else
+      return this->ranges ()[0].start ();
+  }
+
   /* Addresses in the executable code that are in this block.  */
 
   CORE_ADDR m_start;
@@ -231,24 +253,6 @@ struct global_block
   struct compunit_symtab *compunit_symtab;
 };
 
-/* Define the "entry pc" for a block BL to be the lowest (start) address
-   for the block when all addresses within the block are contiguous.  If
-   non-contiguous, then use the start address for the first range in the
-   block.
-
-   At the moment, this almost matches what DWARF specifies as the entry
-   pc.  (The missing bit is support for DW_AT_entry_pc which should be
-   preferred over range data and the low_pc.)
-
-   Once support for DW_AT_entry_pc is added, I expect that an entry_pc
-   field will be added to one of these data structures.  Once that's done,
-   the entry_pc field can be set from the dwarf reader (and other readers
-   too).  BLOCK_ENTRY_PC can then be redefined to be less DWARF-centric.  */
-
-#define BLOCK_ENTRY_PC(bl)	(bl->is_contiguous () \
-				 ? bl->start () \
-				 : bl->ranges ()[0].start ())
-
 struct blockvector
 {
   /* Number of blocks in the list.  */
diff --git a/gdb/blockframe.c b/gdb/blockframe.c
index 1b7381b5617e..548c730fdc53 100644
--- a/gdb/blockframe.c
+++ b/gdb/blockframe.c
@@ -96,7 +96,7 @@ get_pc_function_start (CORE_ADDR pc)
       if (symbol)
 	{
 	  bl = symbol->value_block ();
-	  return BLOCK_ENTRY_PC (bl);
+	  return bl->entry_pc ();
 	}
     }
 
@@ -254,7 +254,7 @@ find_pc_partial_function_sym (CORE_ADDR pc,
       f = find_pc_sect_function (mapped_pc, section);
       if (f != NULL
 	  && (msymbol.minsym == NULL
-	      || (BLOCK_ENTRY_PC (f->value_block ())
+	      || (f->value_block ()->entry_pc ()
 		  >= msymbol.value_address ())))
 	{
 	  const struct block *b = f->value_block ();
@@ -392,7 +392,7 @@ find_function_entry_range_from_pc (CORE_ADDR pc, const char **name,
 
   if (status && block != nullptr && !block->is_contiguous ())
     {
-      CORE_ADDR entry_pc = BLOCK_ENTRY_PC (block);
+      CORE_ADDR entry_pc = block->entry_pc ();
 
       for (blockrange &range : block->ranges ())
 	{
@@ -424,7 +424,7 @@ find_function_type (CORE_ADDR pc)
 {
   struct symbol *sym = find_pc_function (pc);
 
-  if (sym != NULL && BLOCK_ENTRY_PC (sym->value_block ()) == pc)
+  if (sym != NULL && sym->value_block ()->entry_pc () == pc)
     return sym->type ();
 
   return NULL;
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 4c30ae98c1c2..e1f94ec2907c 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -93,7 +93,7 @@ convert_one_symbol (compile_c_instance *context,
 
 	case LOC_BLOCK:
 	  kind = GCC_C_SYMBOL_FUNCTION;
-	  addr = BLOCK_ENTRY_PC (sym.symbol->value_block ());
+	  addr = sym.symbol->value_block ()->entry_pc ();
 	  if (is_global && sym.symbol->type ()->is_gnu_ifunc ())
 	    addr = gnu_ifunc_resolve_addr (target_gdbarch (), addr);
 	  break;
@@ -404,7 +404,7 @@ gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 	    gdb_printf (gdb_stdlog,
 			"gcc_symbol_address \"%s\": full symbol\n",
 			identifier);
-	  result = BLOCK_ENTRY_PC (sym->value_block ());
+	  result = sym->value_block ()->entry_pc ();
 	  if (sym->type ()->is_gnu_ifunc ())
 	    result = gnu_ifunc_resolve_addr (target_gdbarch (), result);
 	  found = 1;
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index d5742a5880de..331ae35c5e92 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -145,7 +145,7 @@ compile_object_run (compile_module_up &&module)
 
       gdb_assert (func_type->code () == TYPE_CODE_FUNC);
       func_val = value_from_pointer (lookup_pointer_type (func_type),
-				   BLOCK_ENTRY_PC (func_sym->value_block ()));
+				   func_sym->value_block ()->entry_pc ());
 
       vargs = XALLOCAVEC (struct value *, func_type->num_fields ());
       if (func_type->num_fields () >= 1)
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 5cbb341b383b..1c3a618690be 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -487,10 +487,10 @@ get_expr_block_and_pc (CORE_ADDR *pc)
 	block = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
 				   STATIC_BLOCK);
       if (block != NULL)
-	*pc = BLOCK_ENTRY_PC (block);
+	*pc = block->entry_pc ();
     }
   else
-    *pc = BLOCK_ENTRY_PC (block);
+    *pc = block->entry_pc ();
 
   return block;
 }
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index ea45475810ec..f490b68adc3d 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -453,7 +453,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	  if (pc_block)
 	    pc_func = block_linkage_function (pc_block);
 
-	  if (pc_func && pc == BLOCK_ENTRY_PC (pc_func->value_block ()))
+	  if (pc_func && pc == pc_func->value_block ()->entry_pc ())
 	    {
 	      *locexpr_length = length;
 	      return loc_ptr;
@@ -753,7 +753,7 @@ func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
   struct symbol *sym = find_pc_function (addr);
   struct type *type;
 
-  if (sym == NULL || BLOCK_ENTRY_PC (sym->value_block ()) != addr)
+  if (sym == NULL || sym->value_block ()->entry_pc () != addr)
     throw_error (NO_ENTRY_VALUE_ERROR,
 		 _("DW_TAG_call_site resolving failed to find function "
 		   "name for address %s"),
diff --git a/gdb/findvar.c b/gdb/findvar.c
index bdc3d35c3458..1f0317567cd4 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -704,10 +704,10 @@ language_defn::read_var_value (struct symbol *var,
     case LOC_BLOCK:
       if (overlay_debugging)
 	addr = symbol_overlayed_address
-	  (BLOCK_ENTRY_PC (var->value_block ()),
+	  (var->value_block ()->entry_pc (),
 	   var->obj_section (var->objfile ()));
       else
-	addr = BLOCK_ENTRY_PC (var->value_block ());
+	addr = var->value_block ()->entry_pc ();
       break;
 
     case LOC_REGISTER:
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 5368fcd71570..53c9e3d0afea 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1345,7 +1345,7 @@ until_next_command (int from_tty)
     {
       sal = find_pc_line (pc, 0);
 
-      tp->control.step_range_start = BLOCK_ENTRY_PC (func->value_block ());
+      tp->control.step_range_start = func->value_block ()->entry_pc ();
       tp->control.step_range_end = sal.end;
 
       /* By setting the step_range_end based on the current pc, we are
diff --git a/gdb/infrun.c b/gdb/infrun.c
index c311240b78cd..f58e47b5e24c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4671,8 +4671,8 @@ fill_in_stop_func (struct gdbarch *gdbarch,
 	 stop_func_start is NOT advanced when in a range of a
 	 non-contiguous block that does not contain the entry pc.  */
       if (block != nullptr
-	  && ecs->stop_func_start <= BLOCK_ENTRY_PC (block)
-	  && BLOCK_ENTRY_PC (block) < ecs->stop_func_end)
+	  && ecs->stop_func_start <= block->entry_pc ()
+	  && block->entry_pc () < ecs->stop_func_end)
 	{
 	  ecs->stop_func_start
 	    += gdbarch_deprecated_function_start_offset (gdbarch);
diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c
index bd173a1d21b7..c502674b1d42 100644
--- a/gdb/inline-frame.c
+++ b/gdb/inline-frame.c
@@ -181,7 +181,7 @@ inline_frame_this_id (struct frame_info *this_frame,
      in the frame ID (and eventually, to set breakpoints).  */
   func = get_frame_function (this_frame);
   gdb_assert (func != NULL);
-  (*this_id).code_addr = BLOCK_ENTRY_PC (func->value_block ());
+  (*this_id).code_addr = func->value_block ()->entry_pc ();
   (*this_id).artificial_depth++;
 }
 
@@ -362,7 +362,7 @@ skip_inline_frames (thread_info *thread, bpstat *stop_chain)
 	    {
 	      /* See comments in inline_frame_this_id about this use
 		 of BLOCK_ENTRY_PC.  */
-	      if (BLOCK_ENTRY_PC (cur_block) == this_pc
+	      if (cur_block->entry_pc () == this_pc
 		  || block_starting_point_at (this_pc, cur_block))
 		{
 		  /* Do not skip the inlined frame if execution
diff --git a/gdb/linespec.c b/gdb/linespec.c
index fd3fba871c5c..c424b33b5228 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2224,7 +2224,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 		   && sym.symbol->aclass () == LOC_BLOCK)
 		{
 		  const CORE_ADDR addr
-		    = BLOCK_ENTRY_PC (sym.symbol->value_block ());
+		    = sym.symbol->value_block ()->entry_pc ();
 
 		  for (const auto &elem : ls->minimal_symbols)
 		    {
diff --git a/gdb/parse.c b/gdb/parse.c
index 73669923890e..52925db21895 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -454,7 +454,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
   if (!expression_context_block)
     expression_context_block = get_selected_block (&expression_context_pc);
   else if (pc == 0)
-    expression_context_pc = BLOCK_ENTRY_PC (expression_context_block);
+    expression_context_pc = expression_context_block->entry_pc ();
   else
     expression_context_pc = pc;
 
@@ -468,7 +468,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
 	  = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
 			       STATIC_BLOCK);
       if (expression_context_block)
-	expression_context_pc = BLOCK_ENTRY_PC (expression_context_block);
+	expression_context_pc = expression_context_block->entry_pc ();
     }
 
   if (language_mode == language_mode_auto && block != NULL)
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 102058a85793..806c5d1b004f 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -645,7 +645,7 @@ build_address_symbolic (struct gdbarch *gdbarch,
 	 pointer is <function+3>.  This matches the ISA behavior.  */
       addr = gdbarch_addr_bits_remove (gdbarch, addr);
 
-      name_location = BLOCK_ENTRY_PC (symbol->value_block ());
+      name_location = symbol->value_block ()->entry_pc ();
       if (do_demangle || asm_demangle)
 	name_temp = symbol->print_name ();
       else
@@ -1778,7 +1778,7 @@ info_address_command (const char *exp, int from_tty)
 
     case LOC_BLOCK:
       gdb_printf (_("a function at address "));
-      load_addr = BLOCK_ENTRY_PC (sym->value_block ());
+      load_addr = sym->value_block ()->entry_pc ();
       fputs_styled (paddress (gdbarch, load_addr), address_style.style (),
 		    gdb_stdout);
       if (section_is_overlay (section))
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 63fa9ba3196e..0367705576c8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1821,7 +1821,7 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
       addr = sym->value_address ();
       break;
     case LOC_BLOCK:
-      addr = BLOCK_ENTRY_PC (sym->value_block ());
+      addr = sym->value_block ()->entry_pc ();
       break;
 
     default:
@@ -3779,7 +3779,7 @@ find_function_start_sal (symbol *sym, bool funfirstline)
 {
   fixup_symbol_section (sym, NULL);
   symtab_and_line sal
-    = find_function_start_sal_1 (BLOCK_ENTRY_PC (sym->value_block ()),
+    = find_function_start_sal_1 (sym->value_block ()->entry_pc (),
 				 sym->obj_section (sym->objfile ()),
 				 funfirstline);
   sal.symbol = sym;
@@ -3908,7 +3908,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
       fixup_symbol_section (sym, NULL);
 
       objfile = sym->objfile ();
-      pc = BLOCK_ENTRY_PC (sym->value_block ());
+      pc = sym->value_block ()->entry_pc ();
       section = sym->obj_section (objfile);
       name = sym->linkage_name ();
     }
@@ -3984,7 +3984,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
       /* Check if gdbarch_skip_prologue left us in mid-line, and the next
 	 line is still part of the same function.  */
       if (skip && start_sal.pc != pc
-	  && (sym ? (BLOCK_ENTRY_PC (sym->value_block ()) <= start_sal.end
+	  && (sym ? (sym->value_block ()->entry_pc () <= start_sal.end
 		     && start_sal.end < sym->value_block()->end ())
 	      : (lookup_minimal_symbol_by_pc_section (start_sal.end, section).minsym
 		 == lookup_minimal_symbol_by_pc_section (pc, section).minsym)))
@@ -4182,7 +4182,7 @@ find_function_alias_target (bound_minimal_symbol msymbol)
   symbol *sym = find_pc_function (func_addr);
   if (sym != NULL
       && sym->aclass () == LOC_BLOCK
-      && BLOCK_ENTRY_PC (sym->value_block ()) == func_addr)
+      && sym->value_block ()->entry_pc () == func_addr)
     return sym;
 
   return NULL;
@@ -5791,7 +5791,7 @@ find_gnu_ifunc (const symbol *sym)
 				symbol_name_match_type::SEARCH_NAME);
   struct objfile *objfile = sym->objfile ();
 
-  CORE_ADDR address = BLOCK_ENTRY_PC (sym->value_block ());
+  CORE_ADDR address = sym->value_block ()->entry_pc ();
   minimal_symbol *ifunc = NULL;
 
   iterate_over_minimal_symbols (objfile, lookup_name,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 64419436fd74..44d16b55bca6 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2512,7 +2512,7 @@ info_scope_command (const char *args_in, int from_tty)
 
 	  if (SYMBOL_COMPUTED_OPS (sym) != NULL)
 	    SYMBOL_COMPUTED_OPS (sym)->describe_location (sym,
-							  BLOCK_ENTRY_PC (block),
+							  block->entry_pc (),
 							  gdb_stdout);
 	  else
 	    {
@@ -2587,7 +2587,7 @@ info_scope_command (const char *args_in, int from_tty)
 		  gdb_printf ("a function at address ");
 		  gdb_printf ("%s",
 			      paddress (gdbarch,
-					BLOCK_ENTRY_PC (sym->value_block ())));
+					sym->value_block ()->entry_pc ()));
 		  break;
 		case LOC_UNRESOLVED:
 		  msym = lookup_minimal_symbol (sym->linkage_name (),
diff --git a/gdb/value.c b/gdb/value.c
index 08cccf711b22..022fca91a42a 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3184,7 +3184,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
   VALUE_LVAL (v) = lval_memory;
   if (sym)
     {
-      set_value_address (v, BLOCK_ENTRY_PC (sym->value_block ()));
+      set_value_address (v, sym->value_block ()->entry_pc ());
     }
   else
     {
-- 
2.26.2


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

* [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros
  2022-04-21 15:03 [PATCH 11/14] gdb: remove BLOCK_ENTRY_PC macro Simon Marchi
@ 2022-04-21 15:03 ` Simon Marchi
  2022-04-21 20:14   ` Lancelot SIX
  2022-04-21 15:03 ` [PATCH 13/14] gdb: constify addrmap_find Simon Marchi
  2022-04-21 15:03 ` [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro Simon Marchi
  2 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 15:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Replace with calls to blockvector::blocks, and the appropriate method
call on the returned array_view.

Change-Id: I04d1f39603e4d4c21c96822421431d9a029d8ddd
---
 gdb/ada-exp.y                     |  3 +-
 gdb/ada-lang.c                    | 23 +++++----
 gdb/block.c                       | 14 +++---
 gdb/block.h                       | 63 +++++++++++++++++++++--
 gdb/buildsym.c                    | 28 +++++------
 gdb/c-exp.y                       |  4 +-
 gdb/coffread.c                    |  3 +-
 gdb/compile/compile-object-load.c | 11 ++--
 gdb/compile/compile.c             |  4 +-
 gdb/cp-support.c                  | 12 +++--
 gdb/guile/scm-symtab.c            |  6 +--
 gdb/jit.c                         |  9 ++--
 gdb/linespec.c                    |  7 ++-
 gdb/maint.c                       |  2 +-
 gdb/mdebugread.c                  | 84 ++++++++++++++-----------------
 gdb/objfiles.c                    |  6 +--
 gdb/p-exp.y                       |  5 +-
 gdb/parse.c                       |  5 +-
 gdb/psymtab.c                     |  4 +-
 gdb/python/py-symbol.c            |  3 +-
 gdb/python/py-symtab.c            |  8 +--
 gdb/symfile-debug.c               |  2 +-
 gdb/symmisc.c                     | 17 +++----
 gdb/symtab.c                      | 23 ++++-----
 gdb/symtab.h                      |  9 +++-
 25 files changed, 194 insertions(+), 161 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 60a7c1bf91f5..8660205809a2 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1369,8 +1369,7 @@ block_lookup (const struct block *context, const char *raw_name)
     symtab = NULL;
 
   if (symtab != NULL)
-    result = BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
-				STATIC_BLOCK);
+    result = symtab->compunit ()->blockvector ()->static_block ();
   else if (syms.empty () || syms[0].symbol->aclass () != LOC_BLOCK)
     {
       if (context == NULL)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c06dbc2f055e..42f285165e3a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4711,12 +4711,13 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
      for that symbol depends on the context.  To determine whether
      the symbol is local or not, we check the block where we found it
      against the global and static blocks of its associated symtab.  */
-  if (sym
-      && BLOCKVECTOR_BLOCK (sym->symtab ()->compunit ()->blockvector (),
-			    GLOBAL_BLOCK) != block
-      && BLOCKVECTOR_BLOCK (sym->symtab ()->compunit ()->blockvector (),
-			    STATIC_BLOCK) != block)
-    return;
+  if (sym != nullptr)
+    {
+      const blockvector &bv = *sym->symtab ()->compunit ()->blockvector ();
+
+      if (bv.global_block () != block && bv.static_block () != block)
+	return;
+    }
 
   h = msymbol_hash (name) % HASH_SIZE;
   e = XOBNEW (&sym_cache->cache_space, cache_entry);
@@ -5563,7 +5564,7 @@ map_matching_symbols (struct objfile *objfile,
   for (compunit_symtab *symtab : objfile->compunits ())
     {
       const struct block *block
-	= BLOCKVECTOR_BLOCK (symtab->blockvector (), block_kind);
+	= symtab->blockvector ()->block (block_kind);
       if (!iterate_over_symbols_terminated (block, lookup_name,
 					    domain, data))
 	break;
@@ -5592,7 +5593,7 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
       for (compunit_symtab *cu : objfile->compunits ())
 	{
 	  const struct block *global_block
-	    = BLOCKVECTOR_BLOCK (cu->blockvector (), GLOBAL_BLOCK);
+	    = cu->blockvector ()->global_block ();
 
 	  if (ada_add_block_renamings (result, global_block, lookup_name,
 				       domain))
@@ -13099,7 +13100,7 @@ ada_add_global_exceptions (compiled_regex *preg,
 
 	  for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
 	    {
-	      const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+	      const struct block *b = bv->block (i);
 	      struct block_iterator iter;
 	      struct symbol *sym;
 
@@ -13687,7 +13688,7 @@ class ada_language : public language_defn
 	for (compunit_symtab *s : objfile->compunits ())
 	  {
 	    QUIT;
-	    b = BLOCKVECTOR_BLOCK (s->blockvector (), GLOBAL_BLOCK);
+	    b = s->blockvector ()->global_block ();
 	    ALL_BLOCK_SYMBOLS (b, iter, sym)
 	      {
 		if (completion_skip_symbol (mode, sym))
@@ -13706,7 +13707,7 @@ class ada_language : public language_defn
 	for (compunit_symtab *s : objfile->compunits ())
 	  {
 	    QUIT;
-	    b = BLOCKVECTOR_BLOCK (s->blockvector (), STATIC_BLOCK);
+	    b = s->blockvector ()->static_block ();
 	    /* Don't do this block twice.  */
 	    if (b == surrounding_static_block)
 	      continue;
diff --git a/gdb/block.c b/gdb/block.c
index 2d28f9de7926..1c3a0030fd48 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -147,14 +147,14 @@ find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
      They both have the same START,END values.
      Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
      fact that this choice was made was subtle, now we make it explicit.  */
-  gdb_assert (BLOCKVECTOR_NBLOCKS (bl) >= 2);
+  gdb_assert (bl->blocks ().size () >= 2);
   bot = STATIC_BLOCK;
-  top = BLOCKVECTOR_NBLOCKS (bl);
+  top = bl->blocks ().size ();
 
   while (top - bot > 1)
     {
       half = (top - bot + 1) >> 1;
-      b = BLOCKVECTOR_BLOCK (bl, bot + half);
+      b = bl->block (bot + half);
       if (b->start () <= pc)
 	bot += half;
       else
@@ -165,7 +165,7 @@ find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
 
   while (bot >= STATIC_BLOCK)
     {
-      b = BLOCKVECTOR_BLOCK (bl, bot);
+      b = bl->block (bot);
       if (!(b->start () <= pc))
 	return NULL;
       if (b->end () > pc)
@@ -543,8 +543,7 @@ block_iterator_step (struct block_iterator *iterator, int first)
 	  if (cust == NULL)
 	    return  NULL;
 
-	  block = BLOCKVECTOR_BLOCK (cust->blockvector (),
-				     iterator->which);
+	  block = cust->blockvector ()->block (iterator->which);
 	  sym = mdict_iterator_first (block->multidict (),
 				      &iterator->mdict_iter);
 	}
@@ -612,8 +611,7 @@ block_iter_match_step (struct block_iterator *iterator,
 	  if (cust == NULL)
 	    return  NULL;
 
-	  block = BLOCKVECTOR_BLOCK (cust->blockvector (),
-				     iterator->which);
+	  block = cust->blockvector ()->block (iterator->which);
 	  sym = mdict_iter_match_first (block->multidict (), name,
 					&iterator->mdict_iter);
 	}
diff --git a/gdb/block.h b/gdb/block.h
index e7bc725c4716..14f82b81c73f 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -255,18 +255,71 @@ struct global_block
 
 struct blockvector
 {
-  /* Number of blocks in the list.  */
-  int nblocks;
+  /* Return a view on the blocks of this blockvector.  */
+  gdb::array_view<struct block *> blocks()
+  {
+    return gdb::array_view<struct block *> (m_blocks, m_num_blocks);
+  }
+
+  /* Const version of the above.  */
+  gdb::array_view<const struct block *const> blocks() const
+  {
+    const struct block **blocks = (const struct block **) m_blocks;
+    return gdb::array_view<const struct block *const> (blocks, m_num_blocks);
+  }
+
+  /* Return the block at index I.  */
+  struct block *block (size_t i)
+  { return this->blocks ()[i]; }
+
+  /* Const version of the above.  */
+  const struct block *block (size_t i) const
+  { return this->blocks ()[i]; }
+
+  /* Set the block at index I.  */
+  void set_block (int i, struct block *block)
+  { m_blocks[i] = block; }
+
+  /* Set the number of blocks of this blockvector.
+
+     The storage of blocks is done using a flexible array member, so the number
+     of blocks set here must agree with what was effectively allocated.  */
+  void set_num_blocks (int num_blocks)
+  { m_num_blocks = num_blocks; }
+
+  /* Return the number of blocks in this blockvector.  */
+  int num_blocks () const
+  { return m_num_blocks; }
+
+  /* Return the global block of this blockvector.  */
+  struct block *global_block ()
+  { return this->block (GLOBAL_BLOCK); }
+
+  /* Const version of the above.  */
+  const struct block *global_block () const
+  { return this->block (GLOBAL_BLOCK); }
+
+  /* Return the static block of this blockvector.  */
+  struct block *static_block ()
+  { return this->block (STATIC_BLOCK); }
+
+  /* Const version of the above.  */
+  const struct block *static_block () const
+  { return this->block (STATIC_BLOCK); }
+
   /* An address map mapping addresses to blocks in this blockvector.
      This pointer is zero if the blocks' start and end addresses are
      enough.  */
   struct addrmap *map;
+
+private:
+  /* Number of blocks in the list.  */
+  int m_num_blocks;
+
   /* The blocks themselves.  */
-  struct block *block[1];
+  struct block *m_blocks[1];
 };
 
-#define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
-#define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
 #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)
 
 /* Return the objfile of BLOCK, which must be non-NULL.  */
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index f4e5eb39f527..e12fafcf40cb 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -447,11 +447,9 @@ buildsym_compunit::make_blockvector ()
      each block into the list after its subblocks in order to make
      sure this is true.  */
 
-  BLOCKVECTOR_NBLOCKS (blockvector) = i;
+  blockvector->set_num_blocks (i);
   for (next = m_pending_blocks; next; next = next->next)
-    {
-      BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
-    }
+    blockvector->set_block (--i, next->block);
 
   free_pending_blocks ();
 
@@ -469,15 +467,15 @@ buildsym_compunit::make_blockvector ()
      Note: Remember that the first two blocks are the global and static
      blocks.  We could special case that fact and begin checking at block 2.
      To avoid making that assumption we do not.  */
-  if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
+  if (blockvector->num_blocks () > 1)
     {
-      for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
+      for (i = 1; i < blockvector->num_blocks (); i++)
 	{
-	  if (BLOCKVECTOR_BLOCK(blockvector, i - 1)->start ()
-	      > BLOCKVECTOR_BLOCK(blockvector, i)->start ())
+	  if (blockvector->block (i - 1)->start ()
+	      > blockvector->block (i)->start ())
 	    {
 	      CORE_ADDR start
-		= BLOCKVECTOR_BLOCK(blockvector, i)->start ();
+		= blockvector->block (i)->start ();
 
 	      complaint (_("block at %s out of order"),
 			 hex_string ((LONGEST) start));
@@ -982,7 +980,7 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
 
   cu->set_blockvector (blockvector);
   {
-    struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
+    struct block *b = blockvector->global_block ();
 
     set_block_compunit_symtab (b, cu);
   }
@@ -998,9 +996,9 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
     /* The main source file's symtab.  */
     struct symtab *symtab = cu->primary_filetab ();
 
-    for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
+    for (block_i = 0; block_i < blockvector->num_blocks (); block_i++)
       {
-	struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
+	struct block *block = blockvector->block (block_i);
 	struct symbol *sym;
 	struct mdict_iterator miter;
 
@@ -1129,7 +1127,7 @@ void
 buildsym_compunit::augment_type_symtab ()
 {
   struct compunit_symtab *cust = m_compunit_symtab;
-  const struct blockvector *blockvector = cust->blockvector ();
+  struct blockvector *blockvector = cust->blockvector ();
 
   if (!m_context_stack.empty ())
     complaint (_("Context stack not empty in augment_type_symtab"));
@@ -1142,7 +1140,7 @@ buildsym_compunit::augment_type_symtab ()
 
   if (m_file_symbols != NULL)
     {
-      struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
+      struct block *block = blockvector->static_block ();
 
       /* First mark any symbols without a specified symtab as belonging
 	 to the primary symtab.  */
@@ -1153,7 +1151,7 @@ buildsym_compunit::augment_type_symtab ()
 
   if (m_global_symbols != NULL)
     {
-      struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
+      struct block *block = blockvector->global_block ();
 
       /* First mark any symbols without a specified symtab as belonging
 	 to the primary symtab.  */
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index d852b1e8a360..517ab42b2297 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -3110,8 +3110,8 @@ classify_name (struct parser_state *par_state, const struct block *block,
 	  if (symtab)
 	    {
 	      yylval.bval
-		= BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
-				     STATIC_BLOCK);
+		= symtab->compunit ()->blockvector ()->static_block ();
+
 	      return FILENAME;
 	    }
 	}
diff --git a/gdb/coffread.c b/gdb/coffread.c
index f5ef12854405..fa2c5e22e1a2 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1478,12 +1478,11 @@ patch_type (struct type *type, struct type *real_type)
 static void
 patch_opaque_types (struct symtab *s)
 {
-  const struct block *b;
   struct block_iterator iter;
   struct symbol *real_sym;
 
   /* Go through the per-file symbols only.  */
-  b = BLOCKVECTOR_BLOCK (s->compunit ()->blockvector (), STATIC_BLOCK);
+  const struct block *b = s->compunit ()->blockvector ()->static_block ();
   ALL_BLOCK_SYMBOLS (b, iter, real_sym)
     {
       /* Find completed typedefs to use to fix opaque ones.
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 2835f2d73d1f..d393091966ce 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -422,7 +422,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
 				 symbol_name_match_type::SEARCH_NAME);
 
   bv = func_sym->symtab ()->compunit ()->blockvector ();
-  nblocks = BLOCKVECTOR_NBLOCKS (bv);
+  nblocks = bv->num_blocks ();
 
   gdb_ptr_type_sym = NULL;
   for (block_loop = 0; block_loop < nblocks; block_loop++)
@@ -430,7 +430,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
       struct symbol *function = NULL;
       const struct block *function_block;
 
-      block = BLOCKVECTOR_BLOCK (bv, block_loop);
+      block = bv->block (block_loop);
       if (block->function () != NULL)
 	continue;
       gdb_val_sym = block_lookup_symbol (block,
@@ -441,8 +441,8 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
 	continue;
 
       function_block = block;
-      while (function_block != BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)
-	     && function_block != BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
+      while (function_block != bv->static_block ()
+	     && function_block != bv->global_block ())
 	{
 	  function_block = function_block->superblock ();
 	  function = function_block->function ();
@@ -450,8 +450,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
 	    break;
 	}
       if (function != NULL
-	  && (function_block->superblock ()
-	      == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
+	  && function_block->superblock () == bv->static_block ()
 	  && symbol_matches_search_name (function, func_matcher))
 	break;
     }
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 1c3a618690be..2843f05fdd7d 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -484,8 +484,8 @@ get_expr_block_and_pc (CORE_ADDR *pc)
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
       if (cursal.symtab)
-	block = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
-				   STATIC_BLOCK);
+	block = cursal.symtab->compunit ()->blockvector ()->static_block ();
+
       if (block != NULL)
 	*pc = block->entry_pc ();
     }
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 14fad2d453fe..f52055893d2b 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1440,7 +1440,7 @@ static void
 add_symbol_overload_list_qualified (const char *func_name,
 				    std::vector<symbol *> *overload_list)
 {
-  const struct block *b, *surrounding_static_block = 0;
+  const struct block *surrounding_static_block = 0;
 
   /* Look through the partial symtabs for all symbols which begin by
      matching FUNC_NAME.  Make sure we read that symbol table in.  */
@@ -1451,7 +1451,9 @@ add_symbol_overload_list_qualified (const char *func_name,
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
 
-  for (b = get_selected_block (0); b != NULL; b = b->superblock ())
+  for (const block *b = get_selected_block (0);
+       b != nullptr;
+       b = b->superblock ())
     add_symbol_overload_list_block (func_name, b, overload_list);
 
   surrounding_static_block = block_static_block (get_selected_block (0));
@@ -1464,7 +1466,7 @@ add_symbol_overload_list_qualified (const char *func_name,
       for (compunit_symtab *cust : objfile->compunits ())
 	{
 	  QUIT;
-	  b = BLOCKVECTOR_BLOCK (cust->blockvector (), GLOBAL_BLOCK);
+	  const block *b = cust->blockvector ()->global_block ();
 	  add_symbol_overload_list_block (func_name, b, overload_list);
 	}
     }
@@ -1474,10 +1476,12 @@ add_symbol_overload_list_qualified (const char *func_name,
       for (compunit_symtab *cust : objfile->compunits ())
 	{
 	  QUIT;
-	  b = BLOCKVECTOR_BLOCK (cust->blockvector (), STATIC_BLOCK);
+	  const block *b = cust->blockvector ()->static_block ();
+
 	  /* Don't do this block twice.  */
 	  if (b == surrounding_static_block)
 	    continue;
+
 	  add_symbol_overload_list_block (func_name, b, overload_list);
 	}
     }
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index 1ba5cb587b1f..518ceeaa15dc 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -361,10 +361,9 @@ gdbscm_symtab_global_block (SCM self)
     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   const struct symtab *symtab = st_smob->symtab;
   const struct blockvector *blockvector;
-  const struct block *block;
 
   blockvector = symtab->compunit ()->blockvector ();
-  block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
+  const struct block *block = blockvector->global_block ();
 
   return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
 }
@@ -379,10 +378,9 @@ gdbscm_symtab_static_block (SCM self)
     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   const struct symtab *symtab = st_smob->symtab;
   const struct blockvector *blockvector;
-  const struct block *block;
 
   blockvector = symtab->compunit ()->blockvector ();
-  block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
+  const struct block *block = blockvector->static_block ();
 
   return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
 }
diff --git a/gdb/jit.c b/gdb/jit.c
index 4ff180d48733..9f2df719a8db 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -565,7 +565,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   BLOCKVECTOR_MAP (bv) = NULL;
   begin = stab->blocks.front ().begin;
   end = stab->blocks.front ().end;
-  BLOCKVECTOR_NBLOCKS (bv) = actual_nblocks;
+  bv->set_num_blocks (actual_nblocks);
 
   /* First run over all the gdb_block objects, creating a real block
      object for each.  Simultaneously, keep setting the real_block
@@ -598,7 +598,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
 
       new_block->set_function (block_name);
 
-      BLOCKVECTOR_BLOCK (bv, block_idx) = new_block;
+      bv->set_block (block_idx, new_block);
       if (begin > new_block->start ())
 	begin = new_block->start ();
       if (end < new_block->end ())
@@ -626,7 +626,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       new_block->set_start (begin);
       new_block->set_end (end);
 
-      BLOCKVECTOR_BLOCK (bv, i) = new_block;
+      bv->set_block (i, new_block);
 
       if (i == GLOBAL_BLOCK)
 	set_block_compunit_symtab (new_block, cust);
@@ -647,8 +647,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       else
 	{
 	  /* And if not, we set a default parent block.  */
-	  gdb_block_iter.real_block->set_superblock
-	    (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK));
+	  gdb_block_iter.real_block->set_superblock (bv->static_block ());
 	}
     }
 }
diff --git a/gdb/linespec.c b/gdb/linespec.c
index c424b33b5228..3cbb8f821f13 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1190,9 +1190,9 @@ iterate_over_all_matching_symtabs
 		  int i;
 		  const blockvector *bv = symtab->compunit ()->blockvector ();
 
-		  for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS (bv); i++)
+		  for (i = FIRST_LOCAL_BLOCK; i < bv->num_blocks (); i++)
 		    {
-		      block = BLOCKVECTOR_BLOCK (bv, i);
+		      block = bv->block (i);
 		      state->language->iterate_over_symbols
 			(block, lookup_name, name_domain,
 			 [&] (block_symbol *bsym)
@@ -1231,8 +1231,7 @@ iterate_over_file_blocks
 {
   const struct block *block;
 
-  for (block = BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
-				  STATIC_BLOCK);
+  for (block = symtab->compunit ()->blockvector ()->static_block ();
        block != NULL;
        block = block->superblock ())
     current_language->iterate_over_symbols (block, name, domain, callback);
diff --git a/gdb/maint.c b/gdb/maint.c
index 7b726c2bc9f6..31b8fd8322e2 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -943,7 +943,7 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
 	  for (compunit_symtab *cu : o->compunits ())
 	    {
 	      ++nr_compunit_symtabs;
-	      nr_blocks += BLOCKVECTOR_NBLOCKS (cu->blockvector ());
+	      nr_blocks += cu->blockvector ()->num_blocks ();
 	      nr_symtabs += std::distance (cu->filetabs ().begin (),
 					   cu->filetabs ().end ());
 	    }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index cd242967ab7d..ca7c15ee63fd 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -628,8 +628,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       break;
 
     case stGlobal:		/* External symbol, goes into global block.  */
-      b = BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
-			     GLOBAL_BLOCK);
+      b = top_stack->cur_st->compunit ()->blockvector ()->global_block ();
       s = new_symbol (name);
       s->set_value_address (sh->value);
       add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
@@ -770,19 +769,19 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       b = top_stack->cur_block;
       if (sh->st == stProc)
 	{
-	  const struct blockvector *bv
+	  struct blockvector *bv
 	    = top_stack->cur_st->compunit ()->blockvector ();
 
 	  /* The next test should normally be true, but provides a
 	     hook for nested functions (which we don't want to make
 	     global).  */
-	  if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
-	    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	  if (b == bv->static_block ())
+	    b = bv->global_block ();
 	  /* Irix 5 sometimes has duplicate names for the same
 	     function.  We want to add such names up at the global
 	     level, not as a nested function.  */
 	  else if (sh->value == top_stack->procadr)
-	    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	    b = bv->global_block ();
 	}
       add_symbol (s, top_stack->cur_st, b);
 
@@ -1144,12 +1143,11 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		top_stack->blocktype == stStaticProc))
 	{
 	  /* Finished with procedure */
-	  const struct blockvector *bv
+	  struct blockvector *bv
 	    = top_stack->cur_st->compunit ()->blockvector ();
 	  struct mdebug_extra_func_info *e;
 	  struct block *cblock = top_stack->cur_block;
 	  struct type *ftype = top_stack->cur_type;
-	  int i;
 
 	  top_stack->cur_block->set_end
 	    (top_stack->cur_block->end () + sh->value); /* size */
@@ -1168,10 +1166,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
 	  /* f77 emits proc-level with address bounds==[0,0],
 	     So look for such child blocks, and patch them.  */
-	  for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
+	  for (block *b_bad : bv->blocks ())
 	    {
-	      struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
-
 	      if (b_bad->superblock () == cblock
 		  && b_bad->start () == top_stack->procadr
 		  && b_bad->end () == top_stack->procadr)
@@ -1967,8 +1963,7 @@ parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
 #else
       s = mylookup_symbol
 	(sh_name,
-	 BLOCKVECTOR_BLOCK (search_symtab->blockvector (),
-			    STATIC_BLOCK),
+	 search_symtab->blockvector ()->static_block (),
 	 VAR_DOMAIN,
 	 LOC_BLOCK);
 #endif
@@ -4099,8 +4094,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 
       push_parse_stack ();
       top_stack->cur_st = cust->primary_filetab ();
-      top_stack->cur_block
-	= BLOCKVECTOR_BLOCK (cust->blockvector (), STATIC_BLOCK);
+      top_stack->cur_block = cust->blockvector ()->static_block ();
       top_stack->cur_block->set_start (pst->text_low (objfile));
       top_stack->cur_block->set_end (0);
       top_stack->blocktype = stFile;
@@ -4189,8 +4183,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 	 FIXME, Maybe quit once we have found the right number of ext's?  */
       top_stack->cur_st = cust->primary_filetab ();
       top_stack->cur_block
-	= BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
-			     GLOBAL_BLOCK);
+	= top_stack->cur_st->compunit ()->blockvector ()->global_block ();
       top_stack->blocktype = stFile;
 
       ext_ptr = PST_PRIVATE (pst)->extern_tab;
@@ -4504,12 +4497,13 @@ add_block (struct block *b, struct symtab *s)
 
   bv = (struct blockvector *) xrealloc ((void *) bv,
 					(sizeof (struct blockvector)
-					 + BLOCKVECTOR_NBLOCKS (bv)
-					 * sizeof (bv->block)));
+					 + bv->num_blocks ()
+					 * sizeof (struct block)));
   if (bv != s->compunit ()->blockvector ())
     s->compunit ()->set_blockvector (bv);
 
-  BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
+  bv->set_block (bv->num_blocks (), b);
+  bv->set_num_blocks (bv->num_blocks () + 1);
 }
 
 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
@@ -4573,13 +4567,13 @@ sort_blocks (struct symtab *s)
   struct blockvector *bv
     = (struct blockvector *) s->compunit ()->blockvector ();
 
-  if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
+  if (bv->num_blocks () <= FIRST_LOCAL_BLOCK)
     {
       /* Cosmetic */
-      if (BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->end () == 0)
-	BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->set_start (0);
-      if (BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)->end () == 0)
-	BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)->set_start (0);
+      if (bv->global_block ()->end () == 0)
+	bv->global_block ()->set_start (0);
+      if (bv->static_block ()->end () == 0)
+	bv->static_block ()->set_start (0);
       return;
     }
   /*
@@ -4588,29 +4582,27 @@ sort_blocks (struct symtab *s)
    * are very different.  It would be nice to find a reliable test
    * to detect -O3 images in advance.
    */
-  if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
-    std::sort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
-	       &BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)),
-	       block_is_less_than);
+  if (bv->num_blocks () > FIRST_LOCAL_BLOCK + 1)
+    {
+      gdb::array_view<block *> blocks_view = bv->blocks ();
+
+      std::sort (blocks_view.begin () + FIRST_LOCAL_BLOCK,
+		 blocks_view.end (), block_is_less_than);
+    }
 
   {
     CORE_ADDR high = 0;
-    int i, j = BLOCKVECTOR_NBLOCKS (bv);
+    int i, j = bv->num_blocks ();
 
     for (i = FIRST_LOCAL_BLOCK; i < j; i++)
-      if (high < BLOCKVECTOR_BLOCK(bv, i)->end ())
-	high = BLOCKVECTOR_BLOCK(bv, i)->end ();
-    BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->set_end (high);
+      if (high < bv->block (i)->end ())
+	high = bv->block (i)->end ();
+    bv->global_block ()->set_end (high);
   }
 
-  BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->set_start
-    (BLOCKVECTOR_BLOCK(bv, FIRST_LOCAL_BLOCK)->start ());
-
-  BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)->set_start
-    (BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->start ());
-
-  BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)->set_end
-    (BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK)->end ());
+  bv->global_block ()->set_start (bv->block (FIRST_LOCAL_BLOCK)->start ());
+  bv->static_block ()->set_start (bv->global_block ()->start ());
+  bv->static_block ()->set_end (bv->global_block ()->end ());
 }
 \f
 
@@ -4635,10 +4627,9 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile)
 
   /* All symtabs must have at least two blocks.  */
   bv = new_bvect (2);
-  BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
-  BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
-  BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)->set_superblock
-    (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
+  bv->set_block (GLOBAL_BLOCK, new_block (NON_FUNCTION_BLOCK, lang));
+  bv->set_block (STATIC_BLOCK, new_block (NON_FUNCTION_BLOCK, lang));
+  bv->static_block ()->set_superblock (bv->global_block ());
   cust->set_blockvector (bv);
 
   cust->set_debugformat ("ECOFF");
@@ -4713,8 +4704,7 @@ new_bvect (int nblocks)
 
   size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
   bv = (struct blockvector *) xzalloc (size);
-
-  BLOCKVECTOR_NBLOCKS (bv) = nblocks;
+  bv->set_num_blocks (nblocks);
 
   return bv;
 }
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index c4b054a70d57..0fec5231106a 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -664,19 +664,17 @@ objfile_relocate1 (struct objfile *objfile,
 
     for (compunit_symtab *cust : objfile->compunits ())
       {
-	const struct blockvector *bv = cust->blockvector ();
+	struct blockvector *bv = cust->blockvector ();
 	int block_line_section = cust->block_line_section ();
 
 	if (BLOCKVECTOR_MAP (bv))
 	  addrmap_relocate (BLOCKVECTOR_MAP (bv), delta[block_line_section]);
 
-	for (int i = 0; i < BLOCKVECTOR_NBLOCKS (bv); ++i)
+	for (block *b : bv->blocks ())
 	  {
-	    struct block *b;
 	    struct symbol *sym;
 	    struct mdict_iterator miter;
 
-	    b = BLOCKVECTOR_BLOCK (bv, i);
 	    b->set_start (b->start () + delta[block_line_section]);
 	    b->set_end (b->end () + delta[block_line_section]);
 
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index ffa82f6e42c3..7c88df65e69a 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -619,9 +619,8 @@ block	:	BLOCKNAME
 			      struct symtab *tem =
 				  lookup_symtab (copy.c_str ());
 			      if (tem)
-				$$ = BLOCKVECTOR_BLOCK
-				  (tem->compunit ()->blockvector (),
-				   STATIC_BLOCK);
+				$$ = (tem->compunit ()->blockvector ()
+				      ->static_block ());
 			      else
 				error (_("No file or function \"%s\"."),
 				       copy.c_str ());
diff --git a/gdb/parse.c b/gdb/parse.c
index 52925db21895..fb308be0d7c9 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -463,10 +463,11 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
   if (!expression_context_block)
     {
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+
       if (cursal.symtab)
 	expression_context_block
-	  = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
-			       STATIC_BLOCK);
+	  = cursal.symtab->compunit ()->blockvector ()->static_block ();
+
       if (expression_context_block)
 	expression_context_pc = expression_context_block->entry_pc ();
     }
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index ce29e1922a15..402d6085fe61 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1798,7 +1798,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 	      if (cust == NULL)
 		continue;
 	      bv = cust->blockvector ();
-	      b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+	      b = bv->static_block ();
 	      for (partial_symbol *psym : ps->static_psymbols)
 		{
 		  /* Skip symbols for inlined functions without address.  These may
@@ -1819,7 +1819,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 		      gdb_printf (" psymtab\n");
 		    }
 		}
-	      b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	      b = bv->global_block ();
 	      for (partial_symbol *psym : ps->global_psymbols)
 		{
 		  sym = block_lookup_symbol (b, psym->ginfo.search_name (),
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 414a310da64a..02c35acd1e93 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -569,10 +569,9 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 	  for (compunit_symtab *cust : objfile->compunits ())
 	    {
 	      const struct blockvector *bv;
-	      const struct block *block;
 
 	      bv = cust->blockvector ();
-	      block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+	      const struct block *block = bv->static_block ();
 
 	      if (block != nullptr)
 		{
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 0a6ee014ea73..7ed62716b678 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -176,13 +176,13 @@ static PyObject *
 stpy_global_block (PyObject *self, PyObject *args)
 {
   struct symtab *symtab = NULL;
-  const struct block *block = NULL;
   const struct blockvector *blockvector;
 
   STPY_REQUIRE_VALID (self, symtab);
 
   blockvector = symtab->compunit ()->blockvector ();
-  block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
+  const struct block *block = blockvector->global_block ();
+
   return block_to_block_object (block, symtab->compunit ()->objfile ());
 }
 
@@ -192,13 +192,13 @@ static PyObject *
 stpy_static_block (PyObject *self, PyObject *args)
 {
   struct symtab *symtab = NULL;
-  const struct block *block = NULL;
   const struct blockvector *blockvector;
 
   STPY_REQUIRE_VALID (self, symtab);
 
   blockvector = symtab->compunit ()->blockvector ();
-  block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
+  const struct block *block = blockvector->static_block ();
+
   return block_to_block_object (block, symtab->compunit ()->objfile ());
 }
 
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index efceef3564ec..bbbcbcabfdee 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -246,7 +246,7 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
   {
     struct symbol *sym, *with_opaque = NULL;
     const struct blockvector *bv = stab->blockvector ();
-    const struct block *block = BLOCKVECTOR_BLOCK (bv, kind);
+    const struct block *block = bv->block (kind);
 
     sym = block_find_symbol (block, name, domain,
 			     block_find_non_opaque_type_preferred,
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 3699e82d0c42..68b76bf3b8eb 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -236,13 +236,9 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 {
   struct objfile *objfile = symtab->compunit ()->objfile ();
   struct gdbarch *gdbarch = objfile->arch ();
-  int i;
   struct mdict_iterator miter;
-  int len;
   struct linetable *l;
-  const struct blockvector *bv;
   struct symbol *sym;
-  const struct block *b;
   int depth;
 
   gdb_printf (outfile, "\nSymtab for file %s at %s\n",
@@ -263,8 +259,8 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   if (l)
     {
       gdb_printf (outfile, "\nLine table:\n\n");
-      len = l->nitems;
-      for (i = 0; i < len; i++)
+      int len = l->nitems;
+      for (int i = 0; i < len; i++)
 	{
 	  gdb_printf (outfile, " line %d at ", l->item[i].line);
 	  gdb_puts (paddress (gdbarch, l->item[i].pc), outfile);
@@ -278,11 +274,10 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   if (is_main_symtab_of_compunit_symtab (symtab))
     {
       gdb_printf (outfile, "\nBlockvector:\n\n");
-      bv = symtab->compunit ()->blockvector ();
-      len = BLOCKVECTOR_NBLOCKS (bv);
-      for (i = 0; i < len; i++)
+      const blockvector *bv = symtab->compunit ()->blockvector ();
+      for (int i = 0; i < bv->num_blocks (); i++)
 	{
-	  b = BLOCKVECTOR_BLOCK (bv, i);
+	  const block *b = bv->block (i);
 	  depth = block_depth (b) * 2;
 	  gdb_printf (outfile, "%*sblock #%03d, object at %s",
 		      depth, "", i,
@@ -351,7 +346,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	  gdb_printf (outfile, "Compunit user: %s\n", addr);
 	}
       if (cust->includes != nullptr)
-	for (i = 0; ; ++i)
+	for (int i = 0; ; ++i)
 	  {
 	    struct compunit_symtab *include = cust->includes[i];
 	    if (include == nullptr)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0367705576c8..31e7160a186e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2327,7 +2327,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
       struct block_symbol result;
 
       bv = cust->blockvector ();
-      block = BLOCKVECTOR_BLOCK (bv, block_index);
+      block = bv->block (block_index);
       result.symbol = block_lookup_symbol_primary (block, name, domain);
       result.block = block;
       if (result.symbol == NULL)
@@ -2460,7 +2460,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
     }
 
   bv = cust->blockvector ();
-  block = BLOCKVECTOR_BLOCK (bv, block_index);
+  block = bv->block (block_index);
   result.symbol = block_lookup_symbol (block, name,
 				       symbol_name_match_type::FULL, domain);
   if (result.symbol == NULL)
@@ -2810,7 +2810,7 @@ basic_lookup_transparent_type_quick (struct objfile *objfile,
     return NULL;
 
   bv = cust->blockvector ();
-  block = BLOCKVECTOR_BLOCK (bv, block_index);
+  block = bv->block (block_index);
   sym = block_find_symbol (block, name, STRUCT_DOMAIN,
 			   block_find_non_opaque_type, NULL);
   if (sym == NULL)
@@ -2835,7 +2835,7 @@ basic_lookup_transparent_type_1 (struct objfile *objfile,
   for (compunit_symtab *cust : objfile->compunits ())
     {
       bv = cust->blockvector ();
-      block = BLOCKVECTOR_BLOCK (bv, block_index);
+      block = bv->block (block_index);
       sym = block_find_symbol (block, name, STRUCT_DOMAIN,
 			       block_find_non_opaque_type, NULL);
       if (sym != NULL)
@@ -2980,8 +2980,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
       for (compunit_symtab *cust : obj_file->compunits ())
 	{
 	  const struct blockvector *bv = cust->blockvector ();
-	  const struct block *global_block
-	    = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	  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;
@@ -3030,7 +3029,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 		   b_index <= STATIC_BLOCK && sym == NULL;
 		   ++b_index)
 		{
-		  const struct block *b = BLOCKVECTOR_BLOCK (bv, b_index);
+		  const struct block *b = bv->block (b_index);
 		  ALL_BLOCK_SYMBOLS (b, iter, sym)
 		    {
 		      fixup_symbol_section (sym, obj_file);
@@ -3089,7 +3088,7 @@ find_symbol_at_address (CORE_ADDR address)
 
       for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
 	{
-	  const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+	  const struct block *b = bv->block (i);
 	  struct block_iterator iter;
 	  struct symbol *sym;
 
@@ -3406,7 +3405,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
       else if (alt)
 	val.end = alt->pc;
       else
-	val.end = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)->end ();
+	val.end = bv->global_block ()->end ();
     }
   val.section = section;
   return val;
@@ -4869,7 +4868,7 @@ global_symbol_searcher::add_matching_symbols
 	{
 	  struct block_iterator iter;
 	  struct symbol *sym;
-	  const struct block *b = BLOCKVECTOR_BLOCK (bv, block);
+	  const struct block *b = bv->block (block);
 
 	  ALL_BLOCK_SYMBOLS (b, iter, sym)
 	    {
@@ -5832,7 +5831,6 @@ add_symtab_completions (struct compunit_symtab *cust,
 			enum type_code code)
 {
   struct symbol *sym;
-  const struct block *b;
   struct block_iterator iter;
   int i;
 
@@ -5842,7 +5840,8 @@ add_symtab_completions (struct compunit_symtab *cust,
   for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
     {
       QUIT;
-      b = BLOCKVECTOR_BLOCK (cust->blockvector (), i);
+
+      const struct block *b = cust->blockvector ()->block (i);
       ALL_BLOCK_SYMBOLS (b, iter, sym)
 	{
 	  if (completion_skip_symbol (mode, sym))
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 40283350cbe8..8c2837cfa8b0 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1757,12 +1757,17 @@ struct compunit_symtab
     m_dirname = dirname;
   }
 
+  struct blockvector *blockvector ()
+  {
+    return m_blockvector;
+  }
+
   const struct blockvector *blockvector () const
   {
     return m_blockvector;
   }
 
-  void set_blockvector (const struct blockvector *blockvector)
+  void set_blockvector (struct blockvector *blockvector)
   {
     m_blockvector = blockvector;
   }
@@ -1860,7 +1865,7 @@ struct compunit_symtab
 
   /* List of all symbol scope blocks for this symtab.  It is shared among
      all symtabs in a given compilation unit.  */
-  const struct blockvector *m_blockvector;
+  struct blockvector *m_blockvector;
 
   /* Section in objfile->section_offsets for the blockvector and
      the linetable.  Probably always SECT_OFF_TEXT.  */
-- 
2.26.2


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

* [PATCH 13/14] gdb: constify addrmap_find
  2022-04-21 15:03 [PATCH 11/14] gdb: remove BLOCK_ENTRY_PC macro Simon Marchi
  2022-04-21 15:03 ` [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros Simon Marchi
@ 2022-04-21 15:03 ` Simon Marchi
  2022-04-21 15:03 ` [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro Simon Marchi
  2 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 15:03 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

addrmap_find shouldn't need to modify the addrmap, so constify the
addrmap parameter.  This helps for the following patch, where getting
the map of a const blockvector will return a const addrmap.

Change-Id: If670e425ed013724a3a77aab7961db50366dccb2
---
 gdb/addrmap.c | 16 ++++++++--------
 gdb/addrmap.h |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index f88880614eca..8141337e4844 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -38,7 +38,7 @@ struct addrmap_funcs
   void (*set_empty) (struct addrmap *self,
 		     CORE_ADDR start, CORE_ADDR end_inclusive,
 		     void *obj);
-  void *(*find) (struct addrmap *self, CORE_ADDR addr);
+  void *(*find) (const addrmap *self, CORE_ADDR addr);
   struct addrmap *(*create_fixed) (struct addrmap *self,
 				   struct obstack *obstack);
   void (*relocate) (struct addrmap *self, CORE_ADDR offset);
@@ -62,7 +62,7 @@ addrmap_set_empty (struct addrmap *map,
 
 
 void *
-addrmap_find (struct addrmap *map, CORE_ADDR addr)
+addrmap_find (const addrmap *map, CORE_ADDR addr)
 {
   return map->funcs->find (map, addr);
 }
@@ -130,11 +130,11 @@ addrmap_fixed_set_empty (struct addrmap *self,
 
 
 static void *
-addrmap_fixed_find (struct addrmap *self, CORE_ADDR addr)
+addrmap_fixed_find (const addrmap *self, CORE_ADDR addr)
 {
-  struct addrmap_fixed *map = (struct addrmap_fixed *) self;
-  struct addrmap_transition *bottom = &map->transitions[0];
-  struct addrmap_transition *top = &map->transitions[map->num_transitions - 1];
+  const addrmap_fixed *map = (const addrmap_fixed *) self;
+  const addrmap_transition *bottom = &map->transitions[0];
+  const addrmap_transition *top = &map->transitions[map->num_transitions - 1];
 
   while (bottom < top)
     {
@@ -142,7 +142,7 @@ addrmap_fixed_find (struct addrmap *self, CORE_ADDR addr)
 	 1 (i.e., two entries are under consideration), then mid ==
 	 bottom, and then we may not narrow the range when (mid->addr
 	 < addr).  */
-      struct addrmap_transition *mid = top - (top - bottom) / 2;
+      const addrmap_transition *mid = top - (top - bottom) / 2;
 
       if (mid->addr == addr)
 	{
@@ -389,7 +389,7 @@ addrmap_mutable_set_empty (struct addrmap *self,
 
 
 static void *
-addrmap_mutable_find (struct addrmap *self, CORE_ADDR addr)
+addrmap_mutable_find (const addrmap *self, CORE_ADDR addr)
 {
   struct addrmap_mutable *map = (struct addrmap_mutable *) self;
   splay_tree_node n = addrmap_splay_tree_lookup (map, addr);
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index 54567fa0d9d6..412e42888973 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -82,7 +82,7 @@ void addrmap_set_empty (struct addrmap *map,
 			void *obj);
 
 /* Return the object associated with ADDR in MAP.  */
-void *addrmap_find (struct addrmap *map, CORE_ADDR addr);
+void *addrmap_find (const addrmap *map, CORE_ADDR addr);
 
 /* Create a fixed address map which is a copy of the mutable address
    map ORIGINAL.  Allocate entries in OBSTACK.  */
-- 
2.26.2


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

* [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro
  2022-04-21 15:03 [PATCH 11/14] gdb: remove BLOCK_ENTRY_PC macro Simon Marchi
  2022-04-21 15:03 ` [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros Simon Marchi
  2022-04-21 15:03 ` [PATCH 13/14] gdb: constify addrmap_find Simon Marchi
@ 2022-04-21 15:03 ` Simon Marchi
  2022-04-21 20:19   ` Lancelot SIX
  2 siblings, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 15:03 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

Change-Id: I4e56c76dfc363c1447686fb29c4212ea18b4dba0
---
 gdb/block.c        |  4 ++--
 gdb/block.h        | 18 ++++++++++++++----
 gdb/buildsym.c     |  6 +++---
 gdb/inline-frame.c |  5 ++---
 gdb/jit.c          |  2 +-
 gdb/objfiles.c     |  4 ++--
 gdb/symtab.c       |  4 ++--
 7 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 1c3a0030fd48..507f08b07795 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -138,8 +138,8 @@ find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
 
   /* If we have an addrmap mapping code addresses to blocks, then use
      that.  */
-  if (BLOCKVECTOR_MAP (bl))
-    return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), pc);
+  if (bl->map ())
+    return (const struct block *) addrmap_find (bl->map (), pc);
 
   /* Otherwise, use binary search to find the last block that starts
      before PC.
diff --git a/gdb/block.h b/gdb/block.h
index 14f82b81c73f..fa7f9ba6dc85 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -307,12 +307,24 @@ struct blockvector
   const struct block *static_block () const
   { return this->block (STATIC_BLOCK); }
 
+  /* Return the address -> block map of this blockvector.  */
+  addrmap *map ()
+  { return m_map; }
+
+  /* Const version of the above.  */
+  const addrmap *map () const
+  { return m_map; }
+
+  /* Set this blockvector's address -> block map.  */
+  void set_map (addrmap *map)
+  { m_map = map; }
+
+private:
   /* An address map mapping addresses to blocks in this blockvector.
      This pointer is zero if the blocks' start and end addresses are
      enough.  */
-  struct addrmap *map;
+  struct addrmap *m_map;
 
-private:
   /* Number of blocks in the list.  */
   int m_num_blocks;
 
@@ -320,8 +332,6 @@ struct blockvector
   struct block *m_blocks[1];
 };
 
-#define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)
-
 /* Return the objfile of BLOCK, which must be non-NULL.  */
 
 extern struct objfile *block_objfile (const struct block *block);
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index e12fafcf40cb..a98a25d97adc 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -456,10 +456,10 @@ buildsym_compunit::make_blockvector ()
   /* If we needed an address map for this symtab, record it in the
      blockvector.  */
   if (m_pending_addrmap != nullptr && m_pending_addrmap_interesting)
-    BLOCKVECTOR_MAP (blockvector)
-      = addrmap_create_fixed (m_pending_addrmap, &m_objfile->objfile_obstack);
+    blockvector->set_map
+      (addrmap_create_fixed (m_pending_addrmap, &m_objfile->objfile_obstack));
   else
-    BLOCKVECTOR_MAP (blockvector) = 0;
+    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
diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c
index c502674b1d42..57b58f38c220 100644
--- a/gdb/inline-frame.c
+++ b/gdb/inline-frame.c
@@ -286,11 +286,10 @@ block_starting_point_at (CORE_ADDR pc, const struct block *block)
   const struct block *new_block;
 
   bv = blockvector_for_pc (pc, NULL);
-  if (BLOCKVECTOR_MAP (bv) == NULL)
+  if (bv->map () == nullptr)
     return 0;
 
-  new_block = (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bv),
-						   pc - 1);
+  new_block = (const struct block *) addrmap_find (bv->map (), pc - 1);
   if (new_block == NULL)
     return 1;
 
diff --git a/gdb/jit.c b/gdb/jit.c
index 9f2df719a8db..b4a070bb8796 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -562,7 +562,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
 
   /* At the end of this function, (begin, end) will contain the PC range this
      entire blockvector spans.  */
-  BLOCKVECTOR_MAP (bv) = NULL;
+  bv->set_map (nullptr);
   begin = stab->blocks.front ().begin;
   end = stab->blocks.front ().end;
   bv->set_num_blocks (actual_nblocks);
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 0fec5231106a..956df9c3d550 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -667,8 +667,8 @@ objfile_relocate1 (struct objfile *objfile,
 	struct blockvector *bv = cust->blockvector ();
 	int block_line_section = cust->block_line_section ();
 
-	if (BLOCKVECTOR_MAP (bv))
-	  addrmap_relocate (BLOCKVECTOR_MAP (bv), delta[block_line_section]);
+	if (bv->map ())
+	  addrmap_relocate (bv->map (), delta[block_line_section]);
 
 	for (block *b : bv->blocks ())
 	  {
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 31e7160a186e..4b33d6c91af8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2987,9 +2987,9 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 	  if (!in_range_p)
 	    continue;
 
-	  if (BLOCKVECTOR_MAP (bv))
+	  if (bv->map () != nullptr)
 	    {
-	      if (addrmap_find (BLOCKVECTOR_MAP (bv), pc) == nullptr)
+	      if (addrmap_find (bv->map (), pc) == nullptr)
 		continue;
 
 	      return cust;
-- 
2.26.2


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

* Re: [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros
  2022-04-21 15:03 ` [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros Simon Marchi
@ 2022-04-21 20:14   ` Lancelot SIX
  2022-04-21 20:25     ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Lancelot SIX @ 2022-04-21 20:14 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Hi,

I just skimmed through and some minor style points below:

> diff --git a/gdb/block.h b/gdb/block.h
> index e7bc725c4716..14f82b81c73f 100644
> --- a/gdb/block.h
> +++ b/gdb/block.h
> @@ -255,18 +255,71 @@ struct global_block
>  
>  struct blockvector
>  {
> -  /* Number of blocks in the list.  */
> -  int nblocks;
> +  /* Return a view on the blocks of this blockvector.  */
> +  gdb::array_view<struct block *> blocks()

Missing a space before the parens here.

> +  {
> +    return gdb::array_view<struct block *> (m_blocks, m_num_blocks);
> +  }
> +
> +  /* Const version of the above.  */
> +  gdb::array_view<const struct block *const> blocks() const

And here too.

> +  {
> +    const struct block **blocks = (const struct block **) m_blocks;
> +    return gdb::array_view<const struct block *const> (blocks, m_num_blocks);
> +  }

Best,
Lancelot.

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

* Re: [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro
  2022-04-21 15:03 ` [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro Simon Marchi
@ 2022-04-21 20:19   ` Lancelot SIX
  2022-04-21 20:25     ` Simon Marchi
  0 siblings, 1 reply; 8+ messages in thread
From: Lancelot SIX @ 2022-04-21 20:19 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Hi,

> diff --git a/gdb/block.c b/gdb/block.c
> index 1c3a0030fd48..507f08b07795 100644
> --- a/gdb/block.c
> +++ b/gdb/block.c
> @@ -138,8 +138,8 @@ find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
>  
>    /* If we have an addrmap mapping code addresses to blocks, then use
>       that.  */
> -  if (BLOCKVECTOR_MAP (bl))
> -    return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), pc);
> +  if (bl->map ())

Should be

  if (bl->map () != nullptr)

> +    return (const struct block *) addrmap_find (bl->map (), pc);
>  
>    /* Otherwise, use binary search to find the last block that starts
>       before PC.
> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
> index 0fec5231106a..956df9c3d550 100644
> --- a/gdb/objfiles.c
> +++ b/gdb/objfiles.c
> @@ -667,8 +667,8 @@ objfile_relocate1 (struct objfile *objfile,
>  	struct blockvector *bv = cust->blockvector ();
>  	int block_line_section = cust->block_line_section ();
>  
> -	if (BLOCKVECTOR_MAP (bv))
> -	  addrmap_relocate (BLOCKVECTOR_MAP (bv), delta[block_line_section]);
> +	if (bv->map ())

Here also.

> +	  addrmap_relocate (bv->map (), delta[block_line_section]);
>  
>  	for (block *b : bv->blocks ())
>  	  {

Best,
Lancelot

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

* Re: [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros
  2022-04-21 20:14   ` Lancelot SIX
@ 2022-04-21 20:25     ` Simon Marchi
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 20:25 UTC (permalink / raw)
  To: Lancelot SIX, Simon Marchi; +Cc: gdb-patches

On 2022-04-21 16:14, Lancelot SIX via Gdb-patches wrote:
> Hi,
> 
> I just skimmed through and some minor style points below:
> 
>> diff --git a/gdb/block.h b/gdb/block.h
>> index e7bc725c4716..14f82b81c73f 100644
>> --- a/gdb/block.h
>> +++ b/gdb/block.h
>> @@ -255,18 +255,71 @@ struct global_block
>>  
>>  struct blockvector
>>  {
>> -  /* Number of blocks in the list.  */
>> -  int nblocks;
>> +  /* Return a view on the blocks of this blockvector.  */
>> +  gdb::array_view<struct block *> blocks()
> 
> Missing a space before the parens here.
> 
>> +  {
>> +    return gdb::array_view<struct block *> (m_blocks, m_num_blocks);
>> +  }
>> +
>> +  /* Const version of the above.  */
>> +  gdb::array_view<const struct block *const> blocks() const
> 
> And here too.

Fixed both, thanks.

Simon

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

* Re: [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro
  2022-04-21 20:19   ` Lancelot SIX
@ 2022-04-21 20:25     ` Simon Marchi
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2022-04-21 20:25 UTC (permalink / raw)
  To: Lancelot SIX, Simon Marchi; +Cc: gdb-patches

On 2022-04-21 16:19, Lancelot SIX via Gdb-patches wrote:
> Hi,
> 
>> diff --git a/gdb/block.c b/gdb/block.c
>> index 1c3a0030fd48..507f08b07795 100644
>> --- a/gdb/block.c
>> +++ b/gdb/block.c
>> @@ -138,8 +138,8 @@ find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
>>  
>>    /* If we have an addrmap mapping code addresses to blocks, then use
>>       that.  */
>> -  if (BLOCKVECTOR_MAP (bl))
>> -    return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), pc);
>> +  if (bl->map ())
> 
> Should be
> 
>   if (bl->map () != nullptr)
> 
>> +    return (const struct block *) addrmap_find (bl->map (), pc);
>>  
>>    /* Otherwise, use binary search to find the last block that starts
>>       before PC.
>> diff --git a/gdb/objfiles.c b/gdb/objfiles.c
>> index 0fec5231106a..956df9c3d550 100644
>> --- a/gdb/objfiles.c
>> +++ b/gdb/objfiles.c
>> @@ -667,8 +667,8 @@ objfile_relocate1 (struct objfile *objfile,
>>  	struct blockvector *bv = cust->blockvector ();
>>  	int block_line_section = cust->block_line_section ();
>>  
>> -	if (BLOCKVECTOR_MAP (bv))
>> -	  addrmap_relocate (BLOCKVECTOR_MAP (bv), delta[block_line_section]);
>> +	if (bv->map ())
> 
> Here also.
> 
>> +	  addrmap_relocate (bv->map (), delta[block_line_section]);
>>  
>>  	for (block *b : bv->blocks ())
>>  	  {
> 
> Best,
> Lancelot

Fixed both, thanks.

Simon

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

end of thread, other threads:[~2022-04-21 20:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21 15:03 [PATCH 11/14] gdb: remove BLOCK_ENTRY_PC macro Simon Marchi
2022-04-21 15:03 ` [PATCH 12/14] gdb: remove BLOCKVECTOR_BLOCK and BLOCKVECTOR_NBLOCKS macros Simon Marchi
2022-04-21 20:14   ` Lancelot SIX
2022-04-21 20:25     ` Simon Marchi
2022-04-21 15:03 ` [PATCH 13/14] gdb: constify addrmap_find Simon Marchi
2022-04-21 15:03 ` [PATCH 14/14] gdb: remove BLOCKVECTOR_MAP macro Simon Marchi
2022-04-21 20:19   ` Lancelot SIX
2022-04-21 20:25     ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).