From: Tom Tromey Date: Sat, 17 Apr 2021 15:35:04 +0000 (-0600) Subject: Let expand_symtabs_matching short-circuit X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=df35e6262da99acc80bb88d669975f0b52e33876;p=binutils-gdb.git Let expand_symtabs_matching short-circuit 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 * 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) : Return bool. * psymtab.c (psymbol_functions::expand_symtabs_matching): Return bool. * psympriv.h (struct psymbol_functions) : Return bool. * objfiles.h (struct objfile) : Return bool. * dwarf2/read.c (struct dwarf2_gdb_index) : Return bool. (struct dwarf2_debug_names_index) : 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 84ce6c16f4b..f1d21931751 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,31 @@ +2021-04-17 Tom Tromey + + * 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) : Return + bool. + * psymtab.c (psymbol_functions::expand_symtabs_matching): Return + bool. + * psympriv.h (struct psymbol_functions) + : Return bool. + * objfiles.h (struct objfile) : Return + bool. + * dwarf2/read.c (struct dwarf2_gdb_index) + : Return bool. + (struct dwarf2_debug_names_index) : + 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 * quick-symbol.h (enum block_search_flag_values): New. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 32c0ed73cbd..b1604a13fc2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2283,7 +2283,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions gdb::function_view callback, symbol_compare_ftype *ordered_compare) override; - void expand_symtabs_matching + bool expand_symtabs_matching (struct objfile *objfile, gdb::function_view 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 callback, symbol_compare_ftype *ordered_compare) override; - void expand_symtabs_matching + bool expand_symtabs_matching (struct objfile *objfile, gdb::function_view 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 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 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 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 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 diff --git a/gdb/objfiles.h b/gdb/objfiles.h index bf6e6a1d01a..fd3323fef07 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -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 file_matcher, const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, diff --git a/gdb/psympriv.h b/gdb/psympriv.h index e4bf038108f..51b02f586bb 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -541,7 +541,7 @@ struct psymbol_functions : public quick_symbol_functions gdb::function_view callback, symbol_compare_ftype *ordered_compare) override; - void expand_symtabs_matching + bool expand_symtabs_matching (struct objfile *objfile, gdb::function_view file_matcher, const lookup_name_info *lookup_name, diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 6f3d8562151..6e7bf240a39 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -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 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 diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 7e22108d7dd..37601d8afbd 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -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 file_matcher, const lookup_name_info *lookup_name, diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index d811809514b..eff2e3aa337 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -265,7 +265,7 @@ objfile::map_matching_symbols callback, ordered_compare); } -void +bool objfile::expand_symtabs_matching (gdb::function_view 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 * diff --git a/gdb/symfile.c b/gdb/symfile.c index 67345114852..3e8859916af 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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 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". diff --git a/gdb/symfile.h b/gdb/symfile.h index bda1c578773..56fc37910fb 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -321,7 +321,7 @@ symfile_segment_data_up get_symfile_segment_data (bfd *abfd); extern scoped_restore_tmpl increment_reading_symtab (void); -void expand_symtabs_matching +bool expand_symtabs_matching (gdb::function_view file_matcher, const lookup_name_info &lookup_name, gdb::function_view symbol_matcher, diff --git a/gdb/symtab.c b/gdb/symtab.c index 9615216d6df..907ebd03984 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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);