Simplify quick_symbol_functions::map_matching_symbols
authorTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:04 +0000 (09:35 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:06 +0000 (09:35 -0600)
quick_symbol_functions::map_matching_symbols is only used by the Ada
code.  Currently, it both expands certain psymtabs and then walks over
the full symtabs -- including any already-expanded ones -- calling a
callback.

It appears to work lazily as well, in that if the callback returns
false, iteration stops.  However, only the psymtab implementation does
this; the DWARF index implementations are not lazy.  It turns out,
though, that the only callback that is ever passed here never returns
false.

This patch simplifies this method by removing the callback.  The
method is also renamed.  In the new scheme, the caller is responsible
for walking the full symtabs, which removes some redundancy as well.

gdb/ChangeLog
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.

gdb/ChangeLog
gdb/ada-lang.c
gdb/dwarf2/read.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/quick-symbol.h
gdb/symfile-debug.c

index 6de85cb7983612409678e066441cc5cdcdd308a1..33a0997afcc85be3216b48d4bd9421684b0ec05b 100644 (file)
@@ -1,3 +1,27 @@
+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)
index 589fbf1a0c49f3dac17b5956c69177d0374d66dd..d170a1e662a7ecfd79fc5bf65a1602d23f254373 100644 (file)
@@ -5175,6 +5175,33 @@ ada_lookup_name (const lookup_name_info &lookup_name)
   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
@@ -5191,10 +5218,8 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
 
   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 ())
        {
@@ -5214,12 +5239,8 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
       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
index 6befb77a2b6d8ee602333f90dea31b5d5010d6c1..22a5f333b785be2f11c7ae22918c8dddfe7fef01 100644 (file)
@@ -2260,12 +2260,11 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
   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
@@ -2283,12 +2282,11 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
   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
@@ -3538,11 +3536,10 @@ dw2_expand_symtabs_matching_one
    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.  */
@@ -3581,18 +3578,6 @@ dwarf2_gdb_index::map_matching_symbols
       /* 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
@@ -5509,11 +5494,10 @@ dwarf2_debug_names_index::dump (struct objfile *objfile)
 }
 
 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);
@@ -5523,7 +5507,6 @@ dwarf2_debug_names_index::map_matching_symbols
     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;
 
@@ -5549,23 +5532,6 @@ dwarf2_debug_names_index::map_matching_symbols
                                         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
index 90ea49e7c9079695b791402e9d2b09c146e9b1d8..5a8a782a64623dd9ecf37e485bd6af255e9bac73 100644 (file)
@@ -621,10 +621,9 @@ public:
   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.  */
index a5395718b7a1297d182d18ff46d7c92357b8f265..59dd66f57e5d58dc94f1bd5935a4fd74ac3a15d2 100644 (file)
@@ -518,12 +518,11 @@ struct psymbol_functions : public 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
index 7c73293ecf164a0a2e53c5138063a87f2e686aec..75a307c89aa31c93f950589b7f249e3718c4a2c1 100644 (file)
@@ -979,36 +979,23 @@ psymtab_to_fullname (struct partial_symtab *ps)
   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);
     }
 }
 
index d883d7b0c1b79745a4f9b0466464602e7c9f7f38..f06ceff41c238250dfef373adb11670334c70802 100644 (file)
@@ -120,11 +120,10 @@ struct quick_symbol_functions
   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
@@ -133,15 +132,13 @@ struct quick_symbol_functions
      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.
index dd5a70b4356bbd361dd6aedfaf91269f938875b4..b839194e2f74272444a450aacdd7eb22503021c4 100644 (file)
@@ -353,22 +353,21 @@ objfile::expand_symtabs_with_fullname (const char *fullname)
 }
 
 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
This page took 0.041215 seconds and 4 git commands to generate.