sim: mips: merge mips64vr4300 with existing multi-run build
[binutils-gdb.git] / gdb / symtab.c
index 58a2033f1ff995d87b79de3cb0705c375b1cbdc5..a7a54159b6da4a950952b2ea4ee44535862242db 100644 (file)
@@ -121,7 +121,7 @@ struct main_info
 
 /* Program space key for finding name and language of "main".  */
 
-static const program_space_key<main_info> main_progspace_key;
+static const registry<program_space>::key<main_info> main_progspace_key;
 
 /* The default symbol cache size.
    There is no extra cpu cost for large N (except when flushing the cache,
@@ -251,7 +251,7 @@ struct symbol_cache
 
 /* Program space key for finding its symbol cache.  */
 
-static const program_space_key<symbol_cache> symbol_cache_key;
+static const registry<program_space>::key<symbol_cache> symbol_cache_key;
 
 /* When non-zero, print debugging messages related to symtab creation.  */
 unsigned int symtab_create_debug = 0;
@@ -405,12 +405,12 @@ compunit_symtab::primary_filetab () const
 /* See symtab.h.  */
 
 enum language
-compunit_language (const struct compunit_symtab *cust)
+compunit_symtab::language () const
 {
-  struct symtab *symtab = cust->primary_filetab ();
+  struct symtab *symtab = primary_filetab ();
 
-/* The language of the compunit symtab is the language of its primary
-   source file.  */
+  /* The language of the compunit symtab is the language of its
+     primary source file.  */
   return symtab->language ();
 }
 
@@ -1424,13 +1424,11 @@ symbol_cache_lookup (struct symbol_cache *cache,
 
   if (eq_symbol_entry (slot, objfile_context, name, domain))
     {
-      if (symbol_lookup_debug)
-       gdb_printf (gdb_stdlog,
-                   "%s block symbol cache hit%s for %s, %s\n",
-                   block == GLOBAL_BLOCK ? "Global" : "Static",
-                   slot->state == SYMBOL_SLOT_NOT_FOUND
-                   ? " (not found)" : "",
-                   name, domain_name (domain));
+      symbol_lookup_debug_printf ("%s block symbol cache hit%s for %s, %s",
+                                 block == GLOBAL_BLOCK ? "Global" : "Static",
+                                 slot->state == SYMBOL_SLOT_NOT_FOUND
+                                 ? " (not found)" : "", name,
+                                 domain_name (domain));
       ++bsc->hits;
       if (slot->state == SYMBOL_SLOT_NOT_FOUND)
        return SYMBOL_LOOKUP_FAILED;
@@ -1439,13 +1437,9 @@ symbol_cache_lookup (struct symbol_cache *cache,
 
   /* Symbol is not present in the cache.  */
 
-  if (symbol_lookup_debug)
-    {
-      gdb_printf (gdb_stdlog,
-                 "%s block symbol cache miss for %s, %s\n",
-                 block == GLOBAL_BLOCK ? "Global" : "Static",
-                 name, domain_name (domain));
-    }
+  symbol_lookup_debug_printf ("%s block symbol cache miss for %s, %s",
+                             block == GLOBAL_BLOCK ? "Global" : "Static",
+                             name, domain_name (domain));
   ++bsc->misses;
   return {};
 }
@@ -1821,7 +1815,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:
@@ -1956,6 +1950,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
                           const domain_enum domain, enum language lang,
                           struct field_of_this_result *is_a_field_of_this)
 {
+  SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT;
+
   demangle_result_storage storage;
   const char *modified_name = demangle_for_lookup (name, lang, storage);
 
@@ -1996,15 +1992,9 @@ lookup_language_this (const struct language_defn *lang,
   if (lang->name_of_this () == NULL || block == NULL)
     return {};
 
-  if (symbol_lookup_debug > 1)
-    {
-      struct objfile *objfile = block_objfile (block);
-
-      gdb_printf (gdb_stdlog,
-                 "lookup_language_this (%s, %s (objfile %s))",
-                 lang->name (), host_address_to_string (block),
-                 objfile_debug_name (objfile));
-    }
+  symbol_lookup_debug_printf_v ("lookup_language_this (%s, %s (objfile %s))",
+                               lang->name (), host_address_to_string (block),
+                               objfile_debug_name (block_objfile (block)));
 
   while (block)
     {
@@ -2015,22 +2005,18 @@ lookup_language_this (const struct language_defn *lang,
                                 VAR_DOMAIN);
       if (sym != NULL)
        {
-         if (symbol_lookup_debug > 1)
-           {
-             gdb_printf (gdb_stdlog, " = %s (%s, block %s)\n",
-                         sym->print_name (),
-                         host_address_to_string (sym),
-                         host_address_to_string (block));
-           }
+         symbol_lookup_debug_printf_v
+           ("lookup_language_this (...) = %s (%s, block %s)",
+            sym->print_name (), host_address_to_string (sym),
+            host_address_to_string (block));
          return (struct block_symbol) {sym, block};
        }
       if (block->function ())
        break;
-      block = BLOCK_SUPERBLOCK (block);
+      block = block->superblock ();
     }
 
-  if (symbol_lookup_debug > 1)
-    gdb_printf (gdb_stdlog, " = NULL\n");
+  symbol_lookup_debug_printf_v ("lookup_language_this (...) = NULL");
   return {};
 }
 
@@ -2088,6 +2074,8 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
                   const domain_enum domain, enum language language,
                   struct field_of_this_result *is_a_field_of_this)
 {
+  SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT;
+
   struct block_symbol result;
   const struct language_defn *langdef;
 
@@ -2096,12 +2084,13 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
       struct objfile *objfile = (block == nullptr
                                 ? nullptr : block_objfile (block));
 
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_aux (%s, %s (objfile %s), %s, %s)\n",
-                 name, host_address_to_string (block),
-                 objfile != NULL
-                 ? objfile_debug_name (objfile) : "NULL",
-                 domain_name (domain), language_str (language));
+      symbol_lookup_debug_printf
+       ("demangled symbol name = \"%s\", block @ %s (objfile %s)",
+        name, host_address_to_string (block),
+        objfile != NULL ? objfile_debug_name (objfile) : "NULL");
+      symbol_lookup_debug_printf
+       ("domain name = \"%s\", language = \"%s\")",
+        domain_name (domain), language_str (language));
     }
 
   /* Make sure we do something sensible with is_a_field_of_this, since
@@ -2117,11 +2106,9 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
   result = lookup_local_symbol (name, match_type, block, domain, language);
   if (result.symbol != NULL)
     {
-      if (symbol_lookup_debug)
-       {
-         gdb_printf (gdb_stdlog, "lookup_symbol_aux (...) = %s\n",
-                     host_address_to_string (result.symbol));
-       }
+      symbol_lookup_debug_printf
+       ("found symbol @ %s (using lookup_local_symbol)",
+        host_address_to_string (result.symbol));
       return result;
     }
 
@@ -2145,7 +2132,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
             be typedefed; just be safe.  */
          t = check_typedef (t);
          if (t->is_pointer_or_reference ())
-           t = TYPE_TARGET_TYPE (t);
+           t = t->target_type ();
 
          if (t->code () != TYPE_CODE_STRUCT
              && t->code () != TYPE_CODE_UNION)
@@ -2154,11 +2141,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
 
          if (check_field (t, name, is_a_field_of_this))
            {
-             if (symbol_lookup_debug)
-               {
-                 gdb_printf (gdb_stdlog,
-                             "lookup_symbol_aux (...) = NULL\n");
-               }
+             symbol_lookup_debug_printf ("no symbol found");
              return {};
            }
        }
@@ -2170,11 +2153,9 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
   result = langdef->lookup_symbol_nonlocal (name, block, domain);
   if (result.symbol != NULL)
     {
-      if (symbol_lookup_debug)
-       {
-         gdb_printf (gdb_stdlog, "lookup_symbol_aux (...) = %s\n",
-                     host_address_to_string (result.symbol));
-       }
+      symbol_lookup_debug_printf
+       ("found symbol @ %s (using language lookup_symbol_nonlocal)",
+        host_address_to_string (result.symbol));
       return result;
     }
 
@@ -2182,13 +2163,9 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
      but more useful than an error.  */
 
   result = lookup_static_symbol (name, domain);
-  if (symbol_lookup_debug)
-    {
-      gdb_printf (gdb_stdlog, "lookup_symbol_aux (...) = %s\n",
-                 result.symbol != NULL
-                 ? host_address_to_string (result.symbol)
-                 : "NULL");
-    }
+  symbol_lookup_debug_printf
+    ("found symbol @ %s (using lookup_static_symbol)",
+     result.symbol != NULL ? host_address_to_string (result.symbol) : "NULL");
   return result;
 }
 
@@ -2229,7 +2206,7 @@ lookup_local_symbol (const char *name,
 
       if (block->function () != NULL && block_inlined_p (block))
        break;
-      block = BLOCK_SUPERBLOCK (block);
+      block = block->superblock ();
     }
 
   /* We've reached the end of the function without finding a result.  */
@@ -2246,31 +2223,27 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
 {
   struct symbol *sym;
 
-  if (symbol_lookup_debug > 1)
+  if (symbol_lookup_debug)
     {
-      struct objfile *objfile = (block == nullptr
-                                ? nullptr : block_objfile (block));
+      struct objfile *objfile
+       = block == nullptr ? nullptr : block_objfile (block);
 
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_block (%s, %s (objfile %s), %s)",
-                 name, host_address_to_string (block),
-                 objfile_debug_name (objfile),
-                 domain_name (domain));
+      symbol_lookup_debug_printf_v
+       ("lookup_symbol_in_block (%s, %s (objfile %s), %s)",
+        name, host_address_to_string (block),
+        objfile != nullptr ? objfile_debug_name (objfile) : "NULL",
+        domain_name (domain));
     }
 
   sym = block_lookup_symbol (block, name, match_type, domain);
   if (sym)
     {
-      if (symbol_lookup_debug > 1)
-       {
-         gdb_printf (gdb_stdlog, " = %s\n",
-                     host_address_to_string (sym));
-       }
+      symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) = %s",
+                                   host_address_to_string (sym));
       return fixup_symbol_section (sym, NULL);
     }
 
-  if (symbol_lookup_debug > 1)
-    gdb_printf (gdb_stdlog, " = NULL\n");
+  symbol_lookup_debug_printf_v ("lookup_symbol_in_block (...) = NULL");
   return NULL;
 }
 
@@ -2308,15 +2281,11 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
 {
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
-  if (symbol_lookup_debug > 1)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_objfile_symtabs (%s, %s, %s, %s)",
-                 objfile_debug_name (objfile),
-                 block_index == GLOBAL_BLOCK
-                 ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-                 name, domain_name (domain));
-    }
+  symbol_lookup_debug_printf_v
+    ("lookup_symbol_in_objfile_symtabs (%s, %s, %s, %s)",
+     objfile_debug_name (objfile),
+     block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
+     name, domain_name (domain));
 
   struct block_symbol other;
   other.symbol = NULL;
@@ -2327,7 +2296,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)
@@ -2352,18 +2321,16 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
 
   if (other.symbol != NULL)
     {
-      if (symbol_lookup_debug > 1)
-       {
-         gdb_printf (gdb_stdlog, " = %s (block %s)\n",
-                     host_address_to_string (other.symbol),
-                     host_address_to_string (other.block));
-       }
+      symbol_lookup_debug_printf_v
+       ("lookup_symbol_in_objfile_symtabs (...) = %s (block %s)",
+        host_address_to_string (other.symbol),
+        host_address_to_string (other.block));
       other.symbol = fixup_symbol_section (other.symbol, objfile);
       return other;
     }
 
-  if (symbol_lookup_debug > 1)
-    gdb_printf (gdb_stdlog, " = NULL\n");
+  symbol_lookup_debug_printf_v
+    ("lookup_symbol_in_objfile_symtabs (...) = NULL");
   return {};
 }
 
@@ -2438,41 +2405,31 @@ lookup_symbol_via_quick_fns (struct objfile *objfile,
   const struct block *block;
   struct block_symbol result;
 
-  if (symbol_lookup_debug > 1)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_via_quick_fns (%s, %s, %s, %s)\n",
-                 objfile_debug_name (objfile),
-                 block_index == GLOBAL_BLOCK
-                 ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-                 name, domain_name (domain));
-    }
+  symbol_lookup_debug_printf_v
+    ("lookup_symbol_via_quick_fns (%s, %s, %s, %s)",
+     objfile_debug_name (objfile),
+     block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
+     name, domain_name (domain));
 
   cust = objfile->lookup_symbol (block_index, name, domain);
   if (cust == NULL)
     {
-      if (symbol_lookup_debug > 1)
-       {
-         gdb_printf (gdb_stdlog,
-                     "lookup_symbol_via_quick_fns (...) = NULL\n");
-       }
+      symbol_lookup_debug_printf_v
+       ("lookup_symbol_via_quick_fns (...) = NULL");
       return {};
     }
 
   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)
     error_in_psymtab_expansion (block_index, name, cust);
 
-  if (symbol_lookup_debug > 1)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_via_quick_fns (...) = %s (block %s)\n",
-                 host_address_to_string (result.symbol),
-                 host_address_to_string (block));
-    }
+  symbol_lookup_debug_printf_v
+    ("lookup_symbol_via_quick_fns (...) = %s (block %s)",
+     host_address_to_string (result.symbol),
+     host_address_to_string (block));
 
   result.symbol = fixup_symbol_section (result.symbol, objfile);
   result.block = block;
@@ -2538,24 +2495,19 @@ lookup_symbol_in_static_block (const char *name,
       struct objfile *objfile = (block == nullptr
                                 ? nullptr : block_objfile (block));
 
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_static_block (%s, %s (objfile %s),"
-                 " %s)\n",
-                 name,
-                 host_address_to_string (block),
-                 objfile_debug_name (objfile),
-                 domain_name (domain));
+      symbol_lookup_debug_printf
+       ("lookup_symbol_in_static_block (%s, %s (objfile %s), %s)",
+        name, host_address_to_string (block),
+        objfile != nullptr ? objfile_debug_name (objfile) : "NULL",
+        domain_name (domain));
     }
 
   sym = lookup_symbol_in_block (name,
                                symbol_name_match_type::FULL,
                                static_block, domain);
-  if (symbol_lookup_debug)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_static_block (...) = %s\n",
-                 sym != NULL ? host_address_to_string (sym) : "NULL");
-    }
+  symbol_lookup_debug_printf ("lookup_symbol_in_static_block (...) = %s",
+                             sym != NULL
+                             ? host_address_to_string (sym) : "NULL");
   return (struct block_symbol) {sym, static_block};
 }
 
@@ -2572,102 +2524,33 @@ lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
 
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
-  if (symbol_lookup_debug)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_objfile (%s, %s, %s, %s)\n",
-                 objfile_debug_name (objfile),
-                 block_index == GLOBAL_BLOCK
-                 ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-                 name, domain_name (domain));
-    }
+  symbol_lookup_debug_printf ("lookup_symbol_in_objfile (%s, %s, %s, %s)",
+                             objfile_debug_name (objfile),
+                             block_index == GLOBAL_BLOCK
+                             ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
+                             name, domain_name (domain));
 
   result = lookup_symbol_in_objfile_symtabs (objfile, block_index,
                                             name, domain);
   if (result.symbol != NULL)
     {
-      if (symbol_lookup_debug)
-       {
-         gdb_printf (gdb_stdlog,
-                     "lookup_symbol_in_objfile (...) = %s"
-                     " (in symtabs)\n",
-                     host_address_to_string (result.symbol));
-       }
+      symbol_lookup_debug_printf
+       ("lookup_symbol_in_objfile (...) = %s (in symtabs)",
+        host_address_to_string (result.symbol));
       return result;
     }
 
   result = lookup_symbol_via_quick_fns (objfile, block_index,
                                        name, domain);
-  if (symbol_lookup_debug)
-    {
-      gdb_printf (gdb_stdlog,
-                 "lookup_symbol_in_objfile (...) = %s%s\n",
-                 result.symbol != NULL
-                 ? host_address_to_string (result.symbol)
-                 : "NULL",
-                 result.symbol != NULL ? " (via quick fns)" : "");
-    }
+  symbol_lookup_debug_printf ("lookup_symbol_in_objfile (...) = %s%s",
+                             result.symbol != NULL
+                             ? host_address_to_string (result.symbol)
+                             : "NULL",
+                             result.symbol != NULL ? " (via quick fns)"
+                             : "");
   return result;
 }
 
-/* Find the language for partial symbol with NAME.  */
-
-static enum language
-find_quick_global_symbol_language (const char *name, const domain_enum domain)
-{
-  for (objfile *objfile : current_program_space->objfiles ())
-    {
-      bool symbol_found_p;
-      enum language lang
-       = objfile->lookup_global_symbol_language (name, domain, &symbol_found_p);
-      if (symbol_found_p)
-       return lang;
-    }
-
-  return language_unknown;
-}
-
-/* Private data to be used with lookup_symbol_global_iterator_cb.  */
-
-struct global_or_static_sym_lookup_data
-{
-  /* The name of the symbol we are searching for.  */
-  const char *name;
-
-  /* The domain to use for our search.  */
-  domain_enum domain;
-
-  /* The block index in which to search.  */
-  enum block_enum block_index;
-
-  /* The field where the callback should store the symbol if found.
-     It should be initialized to {NULL, NULL} before the search is started.  */
-  struct block_symbol result;
-};
-
-/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
-   It searches by name for a symbol in the block given by BLOCK_INDEX of the
-   given OBJFILE.  The arguments for the search are passed via CB_DATA, which
-   in reality is a pointer to struct global_or_static_sym_lookup_data.  */
-
-static int
-lookup_symbol_global_or_static_iterator_cb (struct objfile *objfile,
-                                           void *cb_data)
-{
-  struct global_or_static_sym_lookup_data *data =
-    (struct global_or_static_sym_lookup_data *) cb_data;
-
-  gdb_assert (data->result.symbol == NULL
-             && data->result.block == NULL);
-
-  data->result = lookup_symbol_in_objfile (objfile, data->block_index,
-                                          data->name, data->domain);
-
-  /* If we found a match, tell the iterator to stop.  Otherwise,
-     keep going.  */
-  return (data->result.symbol != NULL);
-}
-
 /* This function contains the common code of lookup_{global,static}_symbol.
    OBJFILE is only used if BLOCK_INDEX is GLOBAL_SCOPE, in which case it is
    the objfile to start the lookup in.  */
@@ -2680,7 +2563,6 @@ lookup_global_or_static_symbol (const char *name,
 {
   struct symbol_cache *cache = get_symbol_cache (current_program_space);
   struct block_symbol result;
-  struct global_or_static_sym_lookup_data lookup_data;
   struct block_symbol_cache *bsc;
   struct symbol_cache_slot *slot;
 
@@ -2700,16 +2582,15 @@ lookup_global_or_static_symbol (const char *name,
 
   /* Do a global search (of global blocks, heh).  */
   if (result.symbol == NULL)
-    {
-      memset (&lookup_data, 0, sizeof (lookup_data));
-      lookup_data.name = name;
-      lookup_data.block_index = block_index;
-      lookup_data.domain = domain;
-      gdbarch_iterate_over_objfiles_in_search_order
-       (objfile != NULL ? objfile->arch () : target_gdbarch (),
-        lookup_symbol_global_or_static_iterator_cb, &lookup_data, objfile);
-      result = lookup_data.result;
-    }
+    gdbarch_iterate_over_objfiles_in_search_order
+      (objfile != NULL ? objfile->arch () : target_gdbarch (),
+       [&result, block_index, name, domain] (struct objfile *objfile_iter)
+        {
+          result = lookup_symbol_in_objfile (objfile_iter, block_index,
+                                             name, domain);
+          return result.symbol != nullptr;
+        },
+       objfile);
 
   if (result.symbol != NULL)
     symbol_cache_mark_found (bsc, slot, objfile, result.symbol, result.block);
@@ -2810,7 +2691,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 +2716,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,17 +2861,16 @@ 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;
          if (!in_range_p)
            continue;
 
-         if (BLOCKVECTOR_MAP (bv))
+         if (bv->map () != nullptr)
            {
-             if (addrmap_find (BLOCKVECTOR_MAP (bv), pc) == nullptr)
+             if (bv->map ()->find (pc) == nullptr)
                continue;
 
              return cust;
@@ -3030,7 +2910,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 +2969,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;
 
@@ -3272,8 +3152,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
               should occur, we'd like to know about it, so error out,
               fatally.  */
            if (mfunsym.value_address () == pc)
-             internal_error (__FILE__, __LINE__,
-               _("Infinite recursion detected in find_pc_sect_line;"
+             internal_error (_("Infinite recursion detected in find_pc_sect_line;"
                  "please file a bug report"));
 
            return find_pc_line (mfunsym.value_address (), 0);
@@ -3406,7 +3285,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;
@@ -3779,7 +3658,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 +3787,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 +3863,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)))
@@ -4046,7 +3925,7 @@ skip_prologue_sal (struct symtab_and_line *sal)
        function_block = b;
       else if (b->function () != NULL)
        break;
-      b = BLOCK_SUPERBLOCK (b);
+      b = b->superblock ();
     }
   if (function_block != NULL
       && function_block->function ()->line () != 0)
@@ -4145,7 +4024,7 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
                  bl = NULL;
                  break;
                }
-             bl = BLOCK_SUPERBLOCK (bl);
+             bl = bl->superblock ();
            }
          if (bl != NULL)
            break;
@@ -4182,7 +4061,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;
@@ -4713,12 +4592,8 @@ treg_matches_sym_type_name (const compiled_regex &treg,
   struct type *sym_type;
   std::string printed_sym_type_name;
 
-  if (symbol_lookup_debug > 1)
-    {
-      gdb_printf (gdb_stdlog,
-                 "treg_matches_sym_type_name\n     sym %s\n",
-                 sym->natural_name ());
-    }
+  symbol_lookup_debug_printf_v ("treg_matches_sym_type_name, sym %s",
+                               sym->natural_name ());
 
   sym_type = sym->type ();
   if (sym_type == NULL)
@@ -4730,14 +4605,8 @@ treg_matches_sym_type_name (const compiled_regex &treg,
     printed_sym_type_name = type_to_string (sym_type);
   }
 
-
-  if (symbol_lookup_debug > 1)
-    {
-      gdb_printf (gdb_stdlog,
-                 "     sym_type_name %s\n",
-                 printed_sym_type_name.c_str ());
-    }
-
+  symbol_lookup_debug_printf_v ("sym_type_name %s",
+                               printed_sym_type_name.c_str ());
 
   if (printed_sym_type_name.empty ())
     return false;
@@ -4869,7 +4738,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)
            {
@@ -4990,6 +4859,7 @@ global_symbol_searcher::search () const
   if (m_symbol_name_regexp != NULL)
     {
       const char *symbol_name_regexp = m_symbol_name_regexp;
+      std::string symbol_name_regexp_holder;
 
       /* Make sure spacing is right for C++ operators.
         This is just a courtesy to make the matching less sensitive
@@ -5018,10 +4888,9 @@ global_symbol_searcher::search () const
          /* If wrong number of spaces, fix it.  */
          if (fix >= 0)
            {
-             char *tmp = (char *) alloca (8 + fix + strlen (opname) + 1);
-
-             sprintf (tmp, "operator%.*s%s", fix, " ", opname);
-             symbol_name_regexp = tmp;
+             symbol_name_regexp_holder
+               = string_printf ("operator%.*s%s", fix, " ", opname);
+             symbol_name_regexp = symbol_name_regexp_holder.c_str ();
            }
        }
 
@@ -5791,7 +5660,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,
@@ -5832,7 +5701,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 +5710,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))
@@ -6013,7 +5882,7 @@ default_collect_symbol_completion_matches_break_on
           are in scope for a nested function.  */
        if (b->function () != NULL && block_inlined_p (b))
          break;
-       b = BLOCK_SUPERBLOCK (b);
+       b = b->superblock ();
       }
 
   /* Add fields from the file's types; symbols will be added below.  */
@@ -6411,13 +6280,25 @@ find_main_name (void)
      Fallback to "main".  */
 
   /* Try to find language for main in psymtabs.  */
-  enum language lang
-    = find_quick_global_symbol_language ("main", VAR_DOMAIN);
-  if (lang != language_unknown)
-    {
-      set_main_name ("main", lang);
-      return;
-    }
+  bool symbol_found_p = false;
+  gdbarch_iterate_over_objfiles_in_search_order
+    (target_gdbarch (),
+     [&symbol_found_p] (objfile *obj)
+       {
+        language lang
+          = obj->lookup_global_symbol_language ("main", VAR_DOMAIN,
+                                                &symbol_found_p);
+        if (symbol_found_p)
+          {
+            set_main_name ("main", lang);
+            return 1;
+          }
+
+        return 0;
+       }, nullptr);
+
+  if (symbol_found_p)
+    return;
 
   set_main_name ("main", language_unknown);
 }