Let expand_symtabs_matching short-circuit
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:05 +0000 (09:35 -0600)
This changes expand_symtabs_exp_notify_ftype to return bool, and
updates all the uses.  Now, if the notification function returns
false, the call is short-circuited and stops examining symtabs.  This
is a step toward replacing map_symtabs_matching_filename with
expand_symtabs_matching.

gdb/ChangeLog
2021-04-17  Tom Tromey  <tom@tromey.com>

* symtab.c (default_collect_symbol_completion_matches_break_on):
Update.
* symfile.h (expand_symtabs_matching): Return bool.
* symfile.c (expand_symtabs_matching): Return bool.
* symfile-debug.c (objfile::expand_symtabs_matching): Return
bool.
* quick-symbol.h (expand_symtabs_exp_notify_ftype): Return bool.
(struct quick_symbol_functions) <expand_symtabs_matching>: Return
bool.
* psymtab.c (psymbol_functions::expand_symtabs_matching): Return
bool.
* psympriv.h (struct psymbol_functions)
<expand_symtabs_matching>: Return bool.
* objfiles.h (struct objfile) <expand_symtabs_matching>: Return
bool.
* dwarf2/read.c (struct dwarf2_gdb_index)
<expand_symtabs_matching>: Return bool.
(struct dwarf2_debug_names_index) <expand_symtabs_matching>:
Return bool.
(dw2_expand_symtabs_matching_symbol): Return bool.
(dw2_expand_symtabs_matching_one, dw2_expand_marked_cus)
(dw2_expand_symtabs_matching)
(dwarf2_gdb_index::expand_symtabs_matching)
(dwarf2_debug_names_index::expand_symtabs_matching)
(dwarf2_debug_names_index::expand_symtabs_matching): Return bool.

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

index 84ce6c16f4b58bcb7b3856c5cf2fd53f84052121..f1d21931751833989b9de73565379fdbb6ef4a7d 100644 (file)
@@ -1,3 +1,31 @@
+2021-04-17  Tom Tromey  <tom@tromey.com>
+
+       * symtab.c (default_collect_symbol_completion_matches_break_on):
+       Update.
+       * symfile.h (expand_symtabs_matching): Return bool.
+       * symfile.c (expand_symtabs_matching): Return bool.
+       * symfile-debug.c (objfile::expand_symtabs_matching): Return
+       bool.
+       * quick-symbol.h (expand_symtabs_exp_notify_ftype): Return bool.
+       (struct quick_symbol_functions) <expand_symtabs_matching>: Return
+       bool.
+       * psymtab.c (psymbol_functions::expand_symtabs_matching): Return
+       bool.
+       * psympriv.h (struct psymbol_functions)
+       <expand_symtabs_matching>: Return bool.
+       * objfiles.h (struct objfile) <expand_symtabs_matching>: Return
+       bool.
+       * dwarf2/read.c (struct dwarf2_gdb_index)
+       <expand_symtabs_matching>: Return bool.
+       (struct dwarf2_debug_names_index) <expand_symtabs_matching>:
+       Return bool.
+       (dw2_expand_symtabs_matching_symbol): Return bool.
+       (dw2_expand_symtabs_matching_one, dw2_expand_marked_cus)
+       (dw2_expand_symtabs_matching)
+       (dwarf2_gdb_index::expand_symtabs_matching)
+       (dwarf2_debug_names_index::expand_symtabs_matching)
+       (dwarf2_debug_names_index::expand_symtabs_matching): Return bool.
+
 2021-04-17  Tom Tromey  <tom@tromey.com>
 
        * quick-symbol.h (enum block_search_flag_values): New.
index 32c0ed73cbdf65017d5b5c40aeee29fb4220b30b..b1604a13fc2d320922b8faf018be568cb0d32004 100644 (file)
@@ -2283,7 +2283,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
@@ -2312,7 +2312,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
@@ -3822,7 +3822,7 @@ dwarf2_base_index_functions::expand_symtabs_with_fullname
     }
 }
 
-static void
+static bool
 dw2_expand_symtabs_matching_symbol
   (mapped_index_base &index,
    const lookup_name_info &lookup_name_in,
@@ -3830,7 +3830,7 @@ dw2_expand_symtabs_matching_symbol
    gdb::function_view<bool (offset_type)> match_callback,
    dwarf2_per_objfile *per_objfile);
 
-static void
+static bool
 dw2_expand_symtabs_matching_one
   (dwarf2_per_cu_data *per_cu,
    dwarf2_per_objfile *per_objfile,
@@ -4125,7 +4125,7 @@ mapped_index_base::build_name_components (dwarf2_per_objfile *per_objfile)
    symbol name that matches, calls MATCH_CALLBACK, passing it the
    symbol's index in the mapped_index_base symbol table.  */
 
-static void
+static bool
 dw2_expand_symtabs_matching_symbol
   (mapped_index_base &index,
    const lookup_name_info &lookup_name_in,
@@ -4210,12 +4210,16 @@ dw2_expand_symtabs_matching_symbol
 
   /* Finally call the callback, once per match.  */
   ULONGEST prev = -1;
+  bool result = true;
   for (offset_type idx : matches)
     {
       if (prev != idx)
        {
          if (!match_callback (idx))
-           break;
+           {
+             result = false;
+             break;
+           }
          prev = idx;
        }
     }
@@ -4223,6 +4227,8 @@ dw2_expand_symtabs_matching_symbol
   /* Above we use a type wider than idx's for 'prev', since 0 and
      (offset_type)-1 are both possible values.  */
   static_assert (sizeof (prev) > sizeof (offset_type), "");
+
+  return result;
 }
 
 #if GDB_SELF_TEST
@@ -4663,7 +4669,7 @@ run_test ()
    dw_expand_symtabs_matching_file_matcher), expand the CU and call
    EXPANSION_NOTIFY on it.  */
 
-static void
+static bool
 dw2_expand_symtabs_matching_one
   (dwarf2_per_cu_data *per_cu,
    dwarf2_per_objfile *per_objfile,
@@ -4679,15 +4685,16 @@ dw2_expand_symtabs_matching_one
       gdb_assert (symtab != nullptr);
 
       if (expansion_notify != NULL && symtab_was_null)
-       expansion_notify (symtab);
+       return expansion_notify (symtab);
     }
+  return true;
 }
 
 /* Helper for dw2_expand_matching symtabs.  Called on each symbol
    matched, to expand corresponding CUs that were marked.  IDX is the
    index of the symbol name that matched.  */
 
-static void
+static bool
 dw2_expand_marked_cus
   (dwarf2_per_objfile *per_objfile, offset_type idx,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4764,9 +4771,12 @@ dw2_expand_marked_cus
        }
 
       dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cutu (cu_index);
-      dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-                                      expansion_notify);
+      if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
+                                           expansion_notify))
+       return false;
     }
+
+  return true;
 }
 
 /* If FILE_MATCHER is non-NULL, set all the
@@ -4846,7 +4856,7 @@ dw_expand_symtabs_matching_file_matcher
     }
 }
 
-void
+bool
 dwarf2_gdb_index::expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -4859,7 +4869,7 @@ dwarf2_gdb_index::expand_symtabs_matching
 
   /* index_table is NULL if OBJF_READNOW.  */
   if (!per_objfile->per_bfd->index_table)
-    return;
+    return true;
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
@@ -4869,22 +4879,28 @@ dwarf2_gdb_index::expand_symtabs_matching
        {
          QUIT;
 
-         dw2_expand_symtabs_matching_one (per_cu, per_objfile,
-                                          file_matcher, expansion_notify);
+         if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+                                               file_matcher,
+                                               expansion_notify))
+           return false;
        }
-      return;
+      return true;
     }
 
   mapped_index &index = *per_objfile->per_bfd->index_table;
 
-  dw2_expand_symtabs_matching_symbol (index, *lookup_name,
-                                     symbol_matcher,
-                                     [&] (offset_type idx)
+  bool result
+    = dw2_expand_symtabs_matching_symbol (index, *lookup_name,
+                                         symbol_matcher,
+                                         [&] (offset_type idx)
     {
-      dw2_expand_marked_cus (per_objfile, idx, file_matcher, expansion_notify,
-                            kind);
+      if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
+                                 expansion_notify, kind))
+       return false;
       return true;
     }, per_objfile);
+
+  return result;
 }
 
 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
@@ -5896,7 +5912,7 @@ dwarf2_debug_names_index::map_matching_symbols
     }
 }
 
-void
+bool
 dwarf2_debug_names_index::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -5909,7 +5925,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
 
   /* debug_names_table is NULL if OBJF_READNOW.  */
   if (!per_objfile->per_bfd->debug_names_table)
-    return;
+    return true;
 
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
@@ -5919,17 +5935,20 @@ dwarf2_debug_names_index::expand_symtabs_matching
        {
          QUIT;
 
-         dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-                                          expansion_notify);
+         if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+                                               file_matcher,
+                                               expansion_notify))
+           return false;
        }
-      return;
+      return true;
     }
 
   mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
 
-  dw2_expand_symtabs_matching_symbol (map, *lookup_name,
-                                     symbol_matcher,
-                                     [&] (offset_type namei)
+  bool result
+    = dw2_expand_symtabs_matching_symbol (map, *lookup_name,
+                                         symbol_matcher,
+                                         [&] (offset_type namei)
     {
       /* The name was matched, now expand corresponding CUs that were
         marked.  */
@@ -5937,10 +5956,14 @@ dwarf2_debug_names_index::expand_symtabs_matching
 
       struct dwarf2_per_cu_data *per_cu;
       while ((per_cu = iter.next ()) != NULL)
-       dw2_expand_symtabs_matching_one (per_cu, per_objfile, file_matcher,
-                                        expansion_notify);
+       if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+                                             file_matcher,
+                                             expansion_notify))
+         return false;
       return true;
     }, per_objfile);
+
+  return result;
 }
 
 /* Get the content of the .gdb_index section of OBJ.  SECTION_OWNER should point
index bf6e6a1d01a9cfa0b6a34757bf657cf715277917..fd3323fef07d47734f226e9990d304c03b6c223e 100644 (file)
@@ -603,7 +603,7 @@ public:
      symbol_compare_ftype *ordered_compare);
 
   /* See quick_symbol_functions.  */
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
      gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
index e4bf038108fca2b8e4b95e4eebfa2623ea7aed16..51b02f586bb3779b893883e09ce5b69052cf76a4 100644 (file)
@@ -541,7 +541,7 @@ struct psymbol_functions : public quick_symbol_functions
      gdb::function_view<symbol_found_callback_ftype> callback,
      symbol_compare_ftype *ordered_compare) override;
 
-  void expand_symtabs_matching
+  bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
index 6f3d856215158d2e00bd4497d5db4347570f943b..6e7bf240a39880afda10cfe1a40d97c2c5c298cd 100644 (file)
@@ -1293,7 +1293,7 @@ recursively_search_psymtabs
 /* Psymtab version of expand_symtabs_matching.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
-void
+bool
 psymbol_functions::expand_symtabs_matching
   (struct objfile *objfile,
    gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
@@ -1346,9 +1346,12 @@ psymbol_functions::expand_symtabs_matching
            psymtab_to_symtab (objfile, ps);
 
          if (expansion_notify != NULL)
-           expansion_notify (symtab);
+           if (!expansion_notify (symtab))
+             return false;
        }
     }
+
+  return true;
 }
 
 /* Psymtab version of has_symbols.  See its definition in
index 7e22108d7ddb0c0df06e2571224067955cd15389..37601d8afbd6f4f1a6619bcc85871b9573959d42 100644 (file)
@@ -52,9 +52,11 @@ typedef bool (expand_symtabs_file_matcher_ftype) (const char *filename,
 typedef bool (expand_symtabs_symbol_matcher_ftype) (const char *name);
 
 /* Callback for quick_symbol_functions->expand_symtabs_matching
-   to be called after a symtab has been expanded.  */
+   to be called after a symtab has been expanded.  If this returns
+   true, more symtabs are checked; if it returns false, iteration
+   stops.  */
 
-typedef void (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
+typedef bool (expand_symtabs_exp_notify_ftype) (compunit_symtab *symtab);
 
 /* The "quick" symbol functions exist so that symbol readers can
    avoiding an initial read of all the symbols.  For example, symbol
@@ -206,8 +208,12 @@ struct quick_symbol_functions
 
      If SYMBOL_MATCHER returns false, then the symbol is skipped.
 
-     Otherwise, the symbol's symbol table is expanded.  */
-  virtual void expand_symtabs_matching
+     Otherwise, the symbol's symbol table is expanded and the
+     notification function is called.  If the notification function
+     returns false, execution stops and this method returns false.
+     Otherwise, more files are considered.  This method will return
+     true if all calls to the notification function return true.  */
+  virtual bool expand_symtabs_matching
     (struct objfile *objfile,
      gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
      const lookup_name_info *lookup_name,
index d811809514b0e7cfd8f658b72066be8f691d6ea3..eff2e3aa3371ba6fb7697af747a637a0198eed8a 100644 (file)
@@ -265,7 +265,7 @@ objfile::map_matching_symbols
                                callback, ordered_compare);
 }
 
-void
+bool
 objfile::expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info *lookup_name,
@@ -283,8 +283,11 @@ objfile::expand_symtabs_matching
                      search_domain_name (kind));
 
   for (const auto &iter : qf)
-    iter->expand_symtabs_matching (this, file_matcher, lookup_name,
-                                  symbol_matcher, expansion_notify, kind);
+    if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name,
+                                       symbol_matcher, expansion_notify,
+                                       kind))
+      return false;
+  return true;
 }
 
 struct compunit_symtab *
index 673451148523420e7c2abd6c531c7e3531cf11b5..3e8859916afaa73c8dad590c34a533482cc55ce9 100644 (file)
@@ -3716,7 +3716,7 @@ symfile_free_objfile (struct objfile *objfile)
    Expand all symtabs that match the specified criteria.
    See quick_symbol_functions.expand_symtabs_matching for details.  */
 
-void
+bool
 expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info &lookup_name,
@@ -3725,10 +3725,12 @@ expand_symtabs_matching
    enum search_domain kind)
 {
   for (objfile *objfile : current_program_space->objfiles ())
-    objfile->expand_symtabs_matching (file_matcher,
-                                     &lookup_name,
-                                     symbol_matcher,
-                                     expansion_notify, kind);
+    if (!objfile->expand_symtabs_matching (file_matcher,
+                                          &lookup_name,
+                                          symbol_matcher,
+                                          expansion_notify, kind))
+      return false;
+  return true;
 }
 
 /* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
index bda1c578773b75df6aa52c84fddb13865a9d543c..56fc37910fb42a0a9a7afaf8fcea9901a38b3a04 100644 (file)
@@ -321,7 +321,7 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
 
 extern scoped_restore_tmpl<int> increment_reading_symtab (void);
 
-void expand_symtabs_matching
+bool expand_symtabs_matching
   (gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
index 9615216d6dfde31599f23113a9c43ecf3cd7bc21..907ebd0398457de9b62d3eb35666a70ec76eeedc 100644 (file)
@@ -5730,6 +5730,7 @@ default_collect_symbol_completion_matches_break_on
                               add_symtab_completions (symtab,
                                                       tracker, mode, lookup_name,
                                                       sym_text, word, code);
+                              return true;
                             },
                           ALL_DOMAIN);