+2021-04-17  Tom Tromey  <tom@tromey.com>
+
+       * psymtab.c (psymbol_functions::expand_matching_symbols): Rename
+       from map_matching_symbols.  Change parameters.
+       * psympriv.h (struct psymbol_functions) <expand_matching_symbols>:
+       Rename from map_matching_symbols.  Change parameters.
+       * dwarf2/read.c (struct dwarf2_gdb_index)
+       <expand_matching_symbols>: Rename from map_matching_symbols.
+       Change parameters.
+       (struct dwarf2_debug_names_index) <expand_matching_symbols>:
+       Rename from map_matching_symbols.  Change parameters.
+       (dwarf2_gdb_index::expand_matching_symbols): Rename from
+       dw2_map_matching_symbols.  Change parameters.
+       (dwarf2_gdb_index::expand_matching_symbols): Remove old
+       implementation.
+       (dwarf2_debug_names_index::expand_matching_symbols): Rename from
+       map_matching_symbols.  Change parameters.
+       * objfiles.h (struct objfile) <expand_matching_symbols>: Rename
+       from map_matching_symbols.  Change parameters.
+       * symfile-debug.c (objfile::expand_matching_symbols): Rename from
+       map_matching_symbols.  Change parameters.
+       * ada-lang.c (map_matching_symbols): New function.
+       (add_nonlocal_symbols): Update.
+
 2021-04-17  Tom Tromey  <tom@tromey.com>
 
        * quick-symbol.h (struct quick_symbol_functions)
 
   return lookup_name.ada ().lookup_name ().c_str ();
 }
 
+/* A helper for add_nonlocal_symbols.  Call expand_matching_symbols
+   for OBJFILE, then walk the objfile's symtabs and update the
+   results.  */
+
+static void
+map_matching_symbols (struct objfile *objfile,
+                     const lookup_name_info &lookup_name,
+                     bool is_wild_match,
+                     domain_enum domain,
+                     int global,
+                     match_data &data)
+{
+  data.objfile = objfile;
+  objfile->expand_matching_symbols (lookup_name, domain, global,
+                                   is_wild_match ? nullptr : compare_names);
+
+  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+  for (compunit_symtab *symtab : objfile->compunits ())
+    {
+      const struct block *block
+       = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind);
+      if (!iterate_over_symbols_terminated (block, lookup_name,
+                                           domain, data))
+       break;
+    }
+}
+
 /* Add to RESULT all non-local symbols whose name and domain match
    LOOKUP_NAME and DOMAIN respectively.  The search is performed on
    GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK
 
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      data.objfile = objfile;
-
-      objfile->map_matching_symbols (lookup_name, domain, global, data,
-                                    is_wild_match ? NULL : compare_names);
+      map_matching_symbols (objfile, lookup_name, is_wild_match, domain,
+                           global, data);
 
       for (compunit_symtab *cu : objfile->compunits ())
        {
       lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL);
 
       for (objfile *objfile : current_program_space->objfiles ())
-       {
-         data.objfile = objfile;
-         objfile->map_matching_symbols (name1, domain, global, data,
-                                        compare_names);
-       }
-    }          
+       map_matching_symbols (objfile, name1, false, domain, global, data);
+    }
 }
 
 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if
 
 {
   void dump (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
 {
   void dump (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
    gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify);
 
 void
-dwarf2_gdb_index::map_matching_symbols
+dwarf2_gdb_index::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   /* Used for Ada.  */
       /* We have -readnow: no .gdb_index, but no partial symtabs either.  So,
         proceed assuming all symtabs have been read in.  */
     }
-
-  for (compunit_symtab *cust : objfile->compunits ())
-    {
-      const struct block *block;
-
-      if (cust == NULL)
-       continue;
-      block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-      if (!iterate_over_symbols_terminated (block, name,
-                                           domain, callback))
-       return;
-    }
 }
 
 /* Starting from a search name, return the string that finds the upper
 }
 
 void
-dwarf2_debug_names_index::map_matching_symbols
+dwarf2_debug_names_index::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
     return;
 
   mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
-  const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
   const block_search_flags block_flags
     = global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK;
 
                                         nullptr);
       return true;
     }, per_objfile);
-
-  /* It's a shame we couldn't do this inside the
-     dw2_expand_symtabs_matching_symbol callback, but that skips CUs
-     that have already been expanded.  Instead, this loop matches what
-     the psymtab code does.  */
-  for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
-    {
-      compunit_symtab *symtab = per_objfile->get_symtab (per_cu);
-      if (symtab != nullptr)
-       {
-         const struct block *block
-           = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind);
-         if (!iterate_over_symbols_terminated (block, name,
-                                               domain, callback))
-           break;
-       }
-    }
 }
 
 bool
 
   void expand_symtabs_with_fullname (const char *fullname);
 
   /* See quick_symbol_functions.  */
-  void map_matching_symbols
+  void expand_matching_symbols
     (const lookup_name_info &name, domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare);
 
   /* See quick_symbol_functions.  */
 
 
   void expand_all_symtabs (struct objfile *objfile) override;
 
-  void map_matching_symbols
+  void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
   bool expand_symtabs_matching
 
   return ps->fullname;
 }
 
-/* Psymtab version of map_matching_symbols.  See its definition in
+/* Psymtab version of expand_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 void
-psymbol_functions::map_matching_symbols
+psymbol_functions::expand_matching_symbols
   (struct objfile *objfile,
    const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
-  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
-
   for (partial_symtab *ps : require_partial_symbols (objfile))
     {
       QUIT;
-      if (ps->readin_p (objfile)
-         || match_partial_symbol (objfile, ps, global, name, domain,
+      if (!ps->readin_p (objfile)
+         && match_partial_symbol (objfile, ps, global, name, domain,
                                   ordered_compare))
-       {
-         struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps);
-         const struct block *block;
-
-         if (cust == NULL)
-           continue;
-         block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-         if (!iterate_over_symbols_terminated (block, name,
-                                               domain, callback))
-           return;
-       }
+       psymtab_to_symtab (objfile, ps);
     }
 }
 
 
   virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
   /* Find global or static symbols in all tables that are in DOMAIN
-     and for which MATCH (symbol name, NAME) == 0, passing each to 
-     CALLBACK, reading in partial symbol tables as needed.  Look
-     through global symbols if GLOBAL and otherwise static symbols.
-     Passes NAME and NAMESPACE to CALLBACK with each symbol
-     found.  After each block is processed, passes NULL to CALLBACK.
+     and for which MATCH (symbol name, NAME) == 0, reading in partial
+     symbol tables as needed.  Look through global symbols if GLOBAL
+     and otherwise static symbols.
+
      MATCH must be weaker than strcmp_iw_ordered in the sense that
      strcmp_iw_ordered(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE,
      if non-null, must be an ordering relation compatible with
      and 
            strcmp_iw_ordered(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
      (allowing strcmp_iw_ordered(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
-     CALLBACK returns true to indicate that the scan should continue, or
-     false to indicate that the scan should be terminated.  */
+  */
 
-  virtual void map_matching_symbols
+  virtual void expand_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
      domain_enum domain,
      int global,
-     gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) = 0;
 
   /* Expand all symbol tables in OBJFILE matching some criteria.
 
 }
 
 void
-objfile::map_matching_symbols
+objfile::expand_matching_symbols
   (const lookup_name_info &name, domain_enum domain,
    int global,
-   gdb::function_view<symbol_found_callback_ftype> callback,
    symbol_compare_ftype *ordered_compare)
 {
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog,
-                     "qf->map_matching_symbols (%s, %s, %d, %s)\n",
+                     "qf->expand_matching_symbols (%s, %s, %d, %s)\n",
                      objfile_debug_name (this),
                      domain_name (domain), global,
                      host_address_to_string (ordered_compare));
 
   for (const auto &iter : qf)
-    iter->map_matching_symbols (this, name, domain, global,
-                               callback, ordered_compare);
+    iter->expand_matching_symbols (this, name, domain, global,
+                                  ordered_compare);
 }
 
 bool