From c92d4de16a0650ae973cfecf9c563893757a01f1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 2 Mar 2023 15:05:17 -0700 Subject: Replace search_domain with domain_search_flags This patch changes gdb to replace search_domain with domain_search_flags everywhere. search_domain is removed. --- gdb/ada-lang.c | 6 +- gdb/compile/compile-cplus-symbols.c | 2 +- gdb/dwarf2/cooked-index.c | 36 ++++++++++ gdb/dwarf2/cooked-index.h | 26 +------- gdb/dwarf2/read-gdb-index.c | 33 +++++---- gdb/dwarf2/read.c | 4 +- gdb/linespec.c | 33 ++++----- gdb/mi/mi-symbol-cmds.c | 33 ++++----- gdb/objfiles.h | 2 +- gdb/psymtab.c | 14 ++-- gdb/psymtab.h | 2 +- gdb/python/py-symbol.c | 2 +- gdb/python/python.c | 2 +- gdb/quick-symbol.h | 2 +- gdb/symfile-debug.c | 12 ++-- gdb/symfile.c | 2 +- gdb/symfile.h | 2 +- gdb/symmisc.c | 2 +- gdb/symtab.c | 130 +++++++++++++++++++----------------- gdb/symtab.h | 36 ++-------- 20 files changed, 187 insertions(+), 194 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c04c48e..4eea4e6 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5514,7 +5514,7 @@ map_matching_symbols (struct objfile *objfile, global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK, - domain, ALL_DOMAIN); + domain, SEARCH_ALL); const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; for (compunit_symtab *symtab : objfile->compunits ()) @@ -12997,7 +12997,7 @@ ada_add_global_exceptions (compiled_regex *preg, }, NULL, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - VARIABLES_DOMAIN); + SEARCH_VAR_DOMAIN); /* Iterate over all objfiles irrespective of scope or linker namespaces so we get all exceptions anywhere in the progspace. */ @@ -13542,7 +13542,7 @@ public: NULL, NULL, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - ALL_DOMAIN); + SEARCH_ALL); /* At this point scan through the misc symbol vectors and add each symbol you find to the list. Eventually we want to ignore diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c index e4bbaa9..dbdabe9 100644 --- a/gdb/compile/compile-cplus-symbols.c +++ b/gdb/compile/compile-cplus-symbols.c @@ -368,7 +368,7 @@ gcc_cplus_convert_symbol (void *datum, symbol_searcher searcher; searcher.find_all_symbols (identifier, current_language, - ALL_DOMAIN, nullptr, nullptr); + SEARCH_ALL, nullptr, nullptr); /* Convert any found symbols. */ for (const auto &it : searcher.matching_symbols ()) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index d5a21ee..4831acc 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -198,6 +198,42 @@ test_compare () /* See cooked-index.h. */ +bool +cooked_index_entry::matches (domain_search_flags kind) const +{ + /* Just reject type declarations. */ + if ((flags & IS_TYPE_DECLARATION) != 0) + return false; + + if ((kind & SEARCH_VAR_DOMAIN) != 0 + && (tag == DW_TAG_variable + || tag == DW_TAG_constant + || tag == DW_TAG_enumerator)) + return true; + + if ((kind & SEARCH_STRUCT_DOMAIN) != 0 + && (tag == DW_TAG_structure_type + || tag == DW_TAG_class_type + || tag == DW_TAG_union_type + || tag == DW_TAG_enumeration_type)) + return true; + + if ((kind & SEARCH_MODULE_DOMAIN) != 0 && tag == DW_TAG_module) + return true; + + if ((kind & SEARCH_TYPE_DOMAIN) != 0 && tag_is_type (tag)) + return true; + + if ((kind & SEARCH_FUNCTION_DOMAIN) != 0 + && (tag == DW_TAG_subprogram + || tag == DW_TAG_entry_point)) + return true; + + return false; +} + +/* See cooked-index.h. */ + const char * cooked_index_entry::full_name (struct obstack *storage, bool for_main) const { diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 86fbb8f..b49e0b1 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -160,29 +160,7 @@ struct cooked_index_entry : public allocate_on_obstack } /* Return true if this entry matches KIND. */ - bool matches (enum search_domain kind) const - { - /* Just reject type declarations. */ - if ((flags & IS_TYPE_DECLARATION) != 0) - return false; - - switch (kind) - { - case VARIABLES_DOMAIN: - return (tag == DW_TAG_variable - || tag == DW_TAG_constant - || tag == DW_TAG_enumerator); - case FUNCTIONS_DOMAIN: - return (tag == DW_TAG_subprogram - || tag == DW_TAG_entry_point); - case TYPES_DOMAIN: - return tag_is_type (tag); - case MODULES_DOMAIN: - return tag == DW_TAG_module; - } - - return true; - } + bool matches (domain_search_flags kind) const; /* Construct the fully-qualified name of this entry and return a pointer to it. If allocation is needed, it will be done on @@ -798,7 +776,7 @@ struct cooked_index_functions : public dwarf2_base_index_functions gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) override; + domain_search_flags kind) override; struct compunit_symtab *find_pc_sect_compunit_symtab (struct objfile *objfile, struct bound_minimal_symbol msymbol, diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c index 3f10aa7..091aa62 100644 --- a/gdb/dwarf2/read-gdb-index.c +++ b/gdb/dwarf2/read-gdb-index.c @@ -147,7 +147,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) override; + domain_search_flags kind) override; }; /* This dumps minimal information about the index. @@ -176,7 +176,7 @@ dw2_expand_marked_cus gdb::function_view file_matcher, gdb::function_view expansion_notify, block_search_flags search_flags, - search_domain kind) + domain_search_flags kind) { offset_type vec_len, vec_idx; bool global_seen = false; @@ -227,27 +227,24 @@ dw2_expand_marked_cus continue; } - switch (kind) + domain_search_flags mask = 0; + switch (symbol_kind) { - case VARIABLES_DOMAIN: - if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) - continue; - break; - case FUNCTIONS_DOMAIN: - if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION) - continue; + case GDB_INDEX_SYMBOL_KIND_VARIABLE: + mask = SEARCH_VAR_DOMAIN; break; - case TYPES_DOMAIN: - if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) - continue; + case GDB_INDEX_SYMBOL_KIND_FUNCTION: + mask = SEARCH_FUNCTION_DOMAIN; break; - case MODULES_DOMAIN: - if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) - continue; + case GDB_INDEX_SYMBOL_KIND_TYPE: + mask = SEARCH_TYPE_DOMAIN; break; - default: + case GDB_INDEX_SYMBOL_KIND_OTHER: + mask = SEARCH_MODULE_DOMAIN; break; } + if ((kind & mask) == 0) + continue; } /* Don't crash on bad data. */ @@ -276,7 +273,7 @@ dwarf2_gdb_index::expand_symtabs_matching gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) + domain_search_flags kind) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 82f969a..bc56c10 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1638,7 +1638,7 @@ struct readnow_functions : public dwarf2_base_index_functions gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) override + domain_search_flags kind) override { return true; } @@ -16625,7 +16625,7 @@ cooked_index_functions::expand_symtabs_matching gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) + domain_search_flags kind) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); diff --git a/gdb/linespec.c b/gdb/linespec.c index 2c54ed5..1d8cbc5 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -387,13 +387,13 @@ static int symbol_to_sal (struct symtab_and_line *result, static void add_matching_symbols_to_info (const char *name, symbol_name_match_type name_match_type, - enum search_domain search_domain, + domain_search_flags domain_search_flags, struct collect_info *info, struct program_space *pspace); static void add_all_symbol_names_from_pspace (struct collect_info *info, struct program_space *pspace, - const std::vector &names, enum search_domain search_domain); + const std::vector &names, domain_search_flags domain_search_flags); static std::vector collect_symtabs_from_filename (const char *file, @@ -1155,7 +1155,7 @@ iterate_over_all_matching_symtabs (struct linespec_state *state, const lookup_name_info &lookup_name, const domain_enum name_domain, - enum search_domain search_domain, + domain_search_flags domain_search_flags, struct program_space *search_pspace, bool include_inline, gdb::function_view callback) { @@ -1174,7 +1174,7 @@ iterate_over_all_matching_symtabs (SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK), UNDEF_DOMAIN, - search_domain); + domain_search_flags); for (compunit_symtab *cu : objfile->compunits ()) { @@ -3331,7 +3331,7 @@ decode_objc (struct linespec_state *self, linespec *ls, const char *arg) return {}; add_all_symbol_names_from_pspace (&info, NULL, symbol_names, - FUNCTIONS_DOMAIN); + SEARCH_FUNCTION_DOMAIN); std::vector values; if (!symbols.empty () || !minimal_symbols.empty ()) @@ -3450,10 +3450,10 @@ lookup_prefix_sym (struct linespec_state *state, if (elt == nullptr) { iterate_over_all_matching_symtabs (state, lookup_name, - STRUCT_DOMAIN, ALL_DOMAIN, + STRUCT_DOMAIN, SEARCH_ALL, NULL, false, collector); iterate_over_all_matching_symtabs (state, lookup_name, - VAR_DOMAIN, ALL_DOMAIN, + VAR_DOMAIN, SEARCH_ALL, NULL, false, collector); } else @@ -3531,12 +3531,12 @@ static void add_all_symbol_names_from_pspace (struct collect_info *info, struct program_space *pspace, const std::vector &names, - enum search_domain search_domain) + domain_search_flags domain_search_flags) { for (const char *iter : names) add_matching_symbols_to_info (iter, symbol_name_match_type::FULL, - search_domain, info, pspace); + domain_search_flags, info, pspace); } static void @@ -3630,7 +3630,7 @@ find_method (struct linespec_state *self, iterate over the symbol tables looking for all matches in this pspace. */ add_all_symbol_names_from_pspace (&info, pspace, result_names, - FUNCTIONS_DOMAIN); + SEARCH_FUNCTION_DOMAIN); superclass_vec.clear (); last_result_len = result_names.size (); @@ -3753,7 +3753,7 @@ symtabs_from_filename (const char *filename, void symbol_searcher::find_all_symbols (const std::string &name, const struct language_defn *language, - enum search_domain search_domain, + domain_search_flags domain_search_flags, std::vector *search_symtabs, struct program_space *search_pspace) { @@ -3775,7 +3775,7 @@ symbol_searcher::find_all_symbols (const std::string &name, info.file_symtabs = search_symtabs; add_matching_symbols_to_info (name.c_str (), symbol_name_match_type::WILD, - search_domain, &info, search_pspace); + domain_search_flags, &info, search_pspace); } /* Look up a function symbol named NAME in symtabs FILE_SYMTABS. Matching @@ -3801,9 +3801,10 @@ find_function_symbols (struct linespec_state *state, find_imps (name, &symbol_names); if (!symbol_names.empty ()) add_all_symbol_names_from_pspace (&info, state->search_pspace, - symbol_names, FUNCTIONS_DOMAIN); + symbol_names, SEARCH_FUNCTION_DOMAIN); else - add_matching_symbols_to_info (name, name_match_type, FUNCTIONS_DOMAIN, + add_matching_symbols_to_info (name, name_match_type, + SEARCH_FUNCTION_DOMAIN, &info, state->search_pspace); } @@ -4322,7 +4323,7 @@ search_minsyms_for_name (struct collect_info *info, static void add_matching_symbols_to_info (const char *name, symbol_name_match_type name_match_type, - enum search_domain search_domain, + domain_search_flags domain_search_flags, struct collect_info *info, struct program_space *pspace) { @@ -4333,7 +4334,7 @@ add_matching_symbols_to_info (const char *name, if (elt == nullptr) { iterate_over_all_matching_symtabs (info->state, lookup_name, - VAR_DOMAIN, search_domain, + VAR_DOMAIN, domain_search_flags, pspace, true, [&] (block_symbol *bsym) { return info->add_symbol (bsym); }); diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c index 758f597..37cf2fb 100644 --- a/gdb/mi/mi-symbol-cmds.c +++ b/gdb/mi/mi-symbol-cmds.c @@ -72,7 +72,7 @@ mi_cmd_symbol_list_lines (const char *command, const char *const *argv, results. */ static void -output_debug_symbol (ui_out *uiout, enum search_domain kind, +output_debug_symbol (ui_out *uiout, domain_search_flags kind, struct symbol *sym, int block) { ui_out_emit_tuple tuple_emitter (uiout, NULL); @@ -81,7 +81,7 @@ output_debug_symbol (ui_out *uiout, enum search_domain kind, uiout->field_unsigned ("line", sym->line ()); uiout->field_string ("name", sym->print_name ()); - if (kind == FUNCTIONS_DOMAIN || kind == VARIABLES_DOMAIN) + if ((kind & (SEARCH_FUNCTION_DOMAIN | SEARCH_VAR_DOMAIN)) != 0) { string_file tmp_stream; type_print (sym->type (), "", &tmp_stream, -1); @@ -113,7 +113,7 @@ output_nondebug_symbol (ui_out *uiout, and then prints the matching [m]symbols in an MI structured format. */ static void -mi_symbol_info (enum search_domain kind, const char *name_regexp, +mi_symbol_info (domain_search_flags kind, const char *name_regexp, const char *type_regexp, bool exclude_minsyms, size_t max_results) { @@ -190,7 +190,7 @@ parse_max_results_option (const char *arg) Processes command line options from ARGV and ARGC. */ static void -mi_info_functions_or_variables (enum search_domain kind, +mi_info_functions_or_variables (domain_search_flags kind, const char *const *argv, int argc) { size_t max_results = SIZE_MAX; @@ -217,7 +217,7 @@ mi_info_functions_or_variables (enum search_domain kind, while (1) { const char *cmd_string - = ((kind == FUNCTIONS_DOMAIN) + = ((kind == SEARCH_FUNCTION_DOMAIN) ? "-symbol-info-functions" : "-symbol-info-variables"); int opt = mi_getopt (cmd_string, argc, argv, opts, &oind, &oarg); if (opt < 0) @@ -253,7 +253,7 @@ typedef std::vector::const_iterator static module_symbol_search_iterator output_module_symbols_in_single_module_and_file (struct ui_out *uiout, module_symbol_search_iterator iter, - const module_symbol_search_iterator end, enum search_domain kind) + const module_symbol_search_iterator end, domain_search_flags kind) { /* The symbol for the module in which the first result resides. */ const symbol *first_module_symbol = iter->first.symbol; @@ -288,7 +288,7 @@ output_module_symbols_in_single_module_and_file static module_symbol_search_iterator output_module_symbols_in_single_module (struct ui_out *uiout, module_symbol_search_iterator iter, - const module_symbol_search_iterator end, enum search_domain kind) + const module_symbol_search_iterator end, domain_search_flags kind) { gdb_assert (iter->first.symbol != nullptr); gdb_assert (iter->second.symbol != nullptr); @@ -316,8 +316,8 @@ output_module_symbols_in_single_module command line options passed to the MI command. */ static void -mi_info_module_functions_or_variables (enum search_domain kind, - const char *const *argv, int argc) +mi_info_module_functions_or_variables (domain_search_flags kind, + const char *const *argv, int argc) { const char *module_regexp = nullptr; const char *regexp = nullptr; @@ -343,7 +343,7 @@ mi_info_module_functions_or_variables (enum search_domain kind, while (1) { const char *cmd_string - = ((kind == FUNCTIONS_DOMAIN) + = ((kind == SEARCH_FUNCTION_DOMAIN) ? "-symbol-info-module-functions" : "-symbol-info-module-variables"); int opt = mi_getopt (cmd_string, argc, argv, opts, &oind, &oarg); @@ -385,7 +385,7 @@ void mi_cmd_symbol_info_functions (const char *command, const char *const *argv, int argc) { - mi_info_functions_or_variables (FUNCTIONS_DOMAIN, argv, argc); + mi_info_functions_or_variables (SEARCH_FUNCTION_DOMAIN, argv, argc); } /* Implement -symbol-info-module-functions command. */ @@ -394,7 +394,7 @@ void mi_cmd_symbol_info_module_functions (const char *command, const char *const *argv, int argc) { - mi_info_module_functions_or_variables (FUNCTIONS_DOMAIN, argv, argc); + mi_info_module_functions_or_variables (SEARCH_FUNCTION_DOMAIN, argv, argc); } /* Implement -symbol-info-module-variables command. */ @@ -403,7 +403,7 @@ void mi_cmd_symbol_info_module_variables (const char *command, const char *const *argv, int argc) { - mi_info_module_functions_or_variables (VARIABLES_DOMAIN, argv, argc); + mi_info_module_functions_or_variables (SEARCH_VAR_DOMAIN, argv, argc); } /* Implement -symbol-inf-modules command. */ @@ -446,7 +446,7 @@ mi_cmd_symbol_info_modules (const char *command, const char *const *argv, } } - mi_symbol_info (MODULES_DOMAIN, regexp, nullptr, true, max_results); + mi_symbol_info (SEARCH_MODULE_DOMAIN, regexp, nullptr, true, max_results); } /* Implement -symbol-info-types command. */ @@ -489,7 +489,8 @@ mi_cmd_symbol_info_types (const char *command, const char *const *argv, } } - mi_symbol_info (TYPES_DOMAIN, regexp, nullptr, true, max_results); + mi_symbol_info (SEARCH_TYPE_DOMAIN | SEARCH_STRUCT_DOMAIN, regexp, nullptr, + true, max_results); } /* Implement -symbol-info-variables command. */ @@ -498,5 +499,5 @@ void mi_cmd_symbol_info_variables (const char *command, const char *const *argv, int argc) { - mi_info_functions_or_variables (VARIABLES_DOMAIN, argv, argc); + mi_info_functions_or_variables (SEARCH_VAR_DOMAIN, argv, argc); } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 65115ce..e576c4b 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -592,7 +592,7 @@ public: gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind); + domain_search_flags kind); /* See quick_symbol_functions. */ struct compunit_symtab *find_pc_sect_compunit_symtab diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 4a3a872..61d7c3b 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -803,7 +803,7 @@ recursively_search_psymtabs struct objfile *objfile, block_search_flags search_flags, domain_enum domain, - enum search_domain search, + domain_search_flags search, const lookup_name_info &lookup_name, gdb::function_view sym_matcher) { @@ -876,15 +876,15 @@ recursively_search_psymtabs if ((domain == UNDEF_DOMAIN || symbol_matches_domain ((*psym)->ginfo.language (), (*psym)->domain, domain)) - && (search == ALL_DOMAIN - || (search == MODULES_DOMAIN + && (search == SEARCH_ALL + || (search == SEARCH_MODULE_DOMAIN && (*psym)->domain == MODULE_DOMAIN) - || (search == VARIABLES_DOMAIN + || (search == SEARCH_VAR_DOMAIN && (*psym)->aclass != LOC_TYPEDEF && (*psym)->aclass != LOC_BLOCK) - || (search == FUNCTIONS_DOMAIN + || (search == SEARCH_FUNCTION_DOMAIN && (*psym)->aclass == LOC_BLOCK) - || (search == TYPES_DOMAIN + || (search == SEARCH_TYPE_DOMAIN && (*psym)->aclass == LOC_TYPEDEF)) && psymbol_name_matches (*psym, lookup_name) && (sym_matcher == NULL @@ -914,7 +914,7 @@ psymbol_functions::expand_symtabs_matching gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain search) + domain_search_flags search) { /* Clear the search flags. */ for (partial_symtab *ps : partial_symbols (objfile)) diff --git a/gdb/psymtab.h b/gdb/psymtab.h index 2bf4234..c4a0d91 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -634,7 +634,7 @@ struct psymbol_functions : public quick_symbol_functions gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) override; + domain_search_flags kind) override; struct compunit_symtab *find_pc_sect_compunit_symtab (struct objfile *objfile, struct bound_minimal_symbol msymbol, diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 52a25b6..a7d010f 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -596,7 +596,7 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) lookup_name_info lookup_name (name, symbol_name_match_type::FULL); expand_symtabs_matching (NULL, lookup_name, NULL, NULL, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - ALL_DOMAIN); + SEARCH_ALL); for (objfile *objfile : current_program_space->objfiles ()) { diff --git a/gdb/python/python.c b/gdb/python/python.c index 1d40639..de3a94d 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -736,7 +736,7 @@ gdbpy_rbreak (PyObject *self, PyObject *args, PyObject *kw) minsyms_p = cmp; } - global_symbol_searcher spec (FUNCTIONS_DOMAIN, regex); + global_symbol_searcher spec (SEARCH_FUNCTION_DOMAIN, regex); SCOPE_EXIT { for (const char *elem : spec.filenames) xfree ((void *) elem); diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 63b2908..8646ac1 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -156,7 +156,7 @@ struct quick_symbol_functions gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) = 0; + domain_search_flags kind) = 0; /* Return the comp unit from OBJFILE that contains PC and SECTION. Return NULL if there is no such compunit. This diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index b0d2e19..38db777 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -223,7 +223,7 @@ objfile::map_symtabs_matching_filename (SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK), UNDEF_DOMAIN, - ALL_DOMAIN)) + SEARCH_ALL)) { retval = false; break; @@ -289,7 +289,7 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain) ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK, domain, - ALL_DOMAIN)) + SEARCH_ALL)) break; } @@ -344,7 +344,7 @@ objfile::expand_symtabs_for_function (const char *func_name) (SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK), VAR_DOMAIN, - ALL_DOMAIN); + SEARCH_ALL); } void @@ -381,7 +381,7 @@ objfile::expand_symtabs_with_fullname (const char *fullname) (SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK), UNDEF_DOMAIN, - ALL_DOMAIN); + SEARCH_ALL); } bool @@ -392,7 +392,7 @@ objfile::expand_symtabs_matching gdb::function_view expansion_notify, block_search_flags search_flags, domain_enum domain, - enum search_domain kind) + domain_search_flags kind) { /* This invariant is documented in quick-functions.h. */ gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); @@ -404,7 +404,7 @@ objfile::expand_symtabs_matching host_address_to_string (&file_matcher), host_address_to_string (&symbol_matcher), host_address_to_string (&expansion_notify), - search_domain_name (kind)); + domain_name (kind).c_str ()); for (const auto &iter : qf) if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name, diff --git a/gdb/symfile.c b/gdb/symfile.c index 6b9f805..065eaf0 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3769,7 +3769,7 @@ expand_symtabs_matching gdb::function_view symbol_matcher, gdb::function_view expansion_notify, block_search_flags search_flags, - enum search_domain kind) + domain_search_flags kind) { for (objfile *objfile : current_program_space->objfiles ()) if (!objfile->expand_symtabs_matching (file_matcher, diff --git a/gdb/symfile.h b/gdb/symfile.h index 4cb3c38..6f8b441 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -352,7 +352,7 @@ bool expand_symtabs_matching gdb::function_view symbol_matcher, gdb::function_view expansion_notify, block_search_flags search_flags, - enum search_domain kind); + domain_search_flags kind); void map_symbol_filenames (gdb::function_view fun, bool need_fullname); diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 5dfb9fc..519df25 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -920,7 +920,7 @@ maintenance_expand_symtabs (const char *args, int from_tty) NULL, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, UNDEF_DOMAIN, - ALL_DOMAIN); + SEARCH_ALL); } diff --git a/gdb/symtab.c b/gdb/symtab.c index 779e1ff..7c56dba 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -313,22 +313,6 @@ domain_name (domain_enum e) } } -/* Return the name of a search_domain . */ - -const char * -search_domain_name (enum search_domain e) -{ - switch (e) - { - case VARIABLES_DOMAIN: return "VARIABLES_DOMAIN"; - case FUNCTIONS_DOMAIN: return "FUNCTIONS_DOMAIN"; - case TYPES_DOMAIN: return "TYPES_DOMAIN"; - case MODULES_DOMAIN: return "MODULES_DOMAIN"; - case ALL_DOMAIN: return "ALL_DOMAIN"; - default: gdb_assert_not_reached ("bad search_domain"); - } -} - /* See symtab.h. */ std::string @@ -4774,7 +4758,7 @@ treg_matches_sym_type_name (const compiled_regex &treg, bool global_symbol_searcher::is_suitable_msymbol - (const enum search_domain kind, const minimal_symbol *msymbol) + (const domain_search_flags kind, const minimal_symbol *msymbol) { switch (msymbol->type ()) { @@ -4782,12 +4766,12 @@ global_symbol_searcher::is_suitable_msymbol case mst_bss: case mst_file_data: case mst_file_bss: - return kind == VARIABLES_DOMAIN; + return (kind & SEARCH_VAR_DOMAIN) != 0; case mst_text: case mst_file_text: case mst_solib_trampoline: case mst_text_gnu_ifunc: - return kind == FUNCTIONS_DOMAIN; + return (kind & SEARCH_FUNCTION_DOMAIN) != 0; default: return false; } @@ -4799,7 +4783,7 @@ bool global_symbol_searcher::expand_symtabs (objfile *objfile, const std::optional &preg) const { - enum search_domain kind = m_kind; + domain_search_flags kind = m_kind; bool found_msymbol = false; auto do_file_match = [&] (const char *filename, bool basenames) @@ -4838,7 +4822,7 @@ global_symbol_searcher::expand_symtabs all objfiles. In large programs (1000s of shared libs) searching all objfiles is not worth the pain. */ if (filenames.empty () - && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN)) + && (kind & (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN)) != 0) { for (minimal_symbol *msymbol : objfile->msymbols ()) { @@ -4858,7 +4842,7 @@ global_symbol_searcher::expand_symtabs in the process we will add matching symbols or msymbols to the results list, and that requires that the symbols tables are expanded. */ - if (kind == FUNCTIONS_DOMAIN + if ((kind & SEARCH_FUNCTION_DOMAIN) != 0 ? (find_pc_compunit_symtab (msymbol->value_address (objfile)) == NULL) : (lookup_symbol_in_objfile_from_linkage_name @@ -4883,7 +4867,7 @@ global_symbol_searcher::add_matching_symbols const std::optional &treg, std::set *result_set) const { - enum search_domain kind = m_kind; + domain_search_flags kind = m_kind; /* Add matching symbols (if not already present). */ for (compunit_symtab *cust : objfile->compunits ()) @@ -4916,7 +4900,7 @@ global_symbol_searcher::add_matching_symbols continue; bool matches = false; - if (!matches && kind == VARIABLES_DOMAIN) + if (!matches && (kind & SEARCH_VAR_DOMAIN) != 0) { if (sym->aclass () != LOC_TYPEDEF && sym->aclass () != LOC_UNRESOLVED @@ -4932,7 +4916,7 @@ global_symbol_searcher::add_matching_symbols || treg_matches_sym_type_name (*treg, sym))) matches = true; } - if (!matches && kind == FUNCTIONS_DOMAIN) + if (!matches && (kind & SEARCH_FUNCTION_DOMAIN) != 0) { if (sym->aclass () == LOC_BLOCK && (!treg.has_value () @@ -4940,13 +4924,13 @@ global_symbol_searcher::add_matching_symbols sym))) matches = true; } - if (!matches && kind == TYPES_DOMAIN) + if (!matches && (kind & SEARCH_TYPE_DOMAIN) != 0) { if (sym->aclass () == LOC_TYPEDEF && sym->domain () != MODULE_DOMAIN) matches = true; } - if (!matches && kind == MODULES_DOMAIN) + if (!matches && (kind & SEARCH_MODULE_DOMAIN) != 0) { if (sym->domain () == MODULE_DOMAIN && sym->line () != 0) @@ -4978,7 +4962,7 @@ global_symbol_searcher::add_matching_msymbols (objfile *objfile, const std::optional &preg, std::vector *results) const { - enum search_domain kind = m_kind; + domain_search_flags kind = m_kind; for (minimal_symbol *msymbol : objfile->msymbols ()) { @@ -4995,7 +4979,7 @@ global_symbol_searcher::add_matching_msymbols { /* For functions we can do a quick check of whether the symbol might be found via find_pc_symtab. */ - if (kind != FUNCTIONS_DOMAIN + if ((kind & SEARCH_FUNCTION_DOMAIN) == 0 || (find_pc_compunit_symtab (msymbol->value_address (objfile)) == NULL)) { @@ -5025,8 +5009,6 @@ global_symbol_searcher::search () const std::optional preg; std::optional treg; - gdb_assert (m_kind != ALL_DOMAIN); - if (m_symbol_name_regexp != NULL) { const char *symbol_name_regexp = m_symbol_name_regexp; @@ -5103,11 +5085,13 @@ global_symbol_searcher::search () const user wants to see symbols matching a type regexp, then never give a minimal symbol, as we assume that a minimal symbol does not have a type. */ - if ((found_msymbol || (filenames.empty () && m_kind == VARIABLES_DOMAIN)) + if ((found_msymbol + || (filenames.empty () && (m_kind & SEARCH_VAR_DOMAIN) != 0)) && !m_exclude_minsyms && !treg.has_value ()) { - gdb_assert (m_kind == VARIABLES_DOMAIN || m_kind == FUNCTIONS_DOMAIN); + gdb_assert ((m_kind & (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN)) + != 0); for (objfile *objfile : current_program_space->objfiles ()) if (!add_matching_msymbols (objfile, preg, &result)) break; @@ -5238,36 +5222,55 @@ print_msymbol_info (struct bound_minimal_symbol msymbol) static void symtab_symbol_info (bool quiet, bool exclude_minsyms, - const char *regexp, enum search_domain kind, + const char *regexp, domain_enum kind, const char *t_regexp, int from_tty) { - static const char * const classnames[] = - {"variable", "function", "type", "module"}; const char *last_filename = ""; int first = 1; - gdb_assert (kind != ALL_DOMAIN); - if (regexp != nullptr && *regexp == '\0') regexp = nullptr; - global_symbol_searcher spec (kind, regexp); + domain_search_flags flags = to_search_flags (kind); + if (kind == TYPE_DOMAIN) + flags |= SEARCH_STRUCT_DOMAIN; + + global_symbol_searcher spec (flags, regexp); spec.set_symbol_type_regexp (t_regexp); spec.set_exclude_minsyms (exclude_minsyms); std::vector symbols = spec.search (); if (!quiet) { + const char *classname; + switch (kind) + { + case VAR_DOMAIN: + classname = "variable"; + break; + case FUNCTION_DOMAIN: + classname = "function"; + break; + case TYPE_DOMAIN: + classname = "type"; + break; + case MODULE_DOMAIN: + classname = "module"; + break; + default: + gdb_assert_not_reached ("invalid domain enum"); + } + if (regexp != NULL) { if (t_regexp != NULL) gdb_printf (_("All %ss matching regular expression \"%s\"" " with type matching regular expression \"%s\":\n"), - classnames[kind], regexp, t_regexp); + classname, regexp, t_regexp); else gdb_printf (_("All %ss matching regular expression \"%s\":\n"), - classnames[kind], regexp); + classname, regexp); } else { @@ -5275,9 +5278,9 @@ symtab_symbol_info (bool quiet, bool exclude_minsyms, gdb_printf (_("All defined %ss" " with type matching regular expression \"%s\" :\n"), - classnames[kind], t_regexp); + classname, t_regexp); else - gdb_printf (_("All defined %ss:\n"), classnames[kind]); + gdb_printf (_("All defined %ss:\n"), classname); } } @@ -5380,7 +5383,7 @@ info_variables_command (const char *args, int from_tty) args = nullptr; symtab_symbol_info - (opts.quiet, opts.exclude_minsyms, args, VARIABLES_DOMAIN, + (opts.quiet, opts.exclude_minsyms, args, VAR_DOMAIN, opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (), from_tty); } @@ -5399,7 +5402,7 @@ info_functions_command (const char *args, int from_tty) args = nullptr; symtab_symbol_info - (opts.quiet, opts.exclude_minsyms, args, FUNCTIONS_DOMAIN, + (opts.quiet, opts.exclude_minsyms, args, FUNCTION_DOMAIN, opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (), from_tty); } @@ -5442,7 +5445,8 @@ info_types_command (const char *args, int from_tty) (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); if (args != nullptr && *args == '\0') args = nullptr; - symtab_symbol_info (opts.quiet, false, args, TYPES_DOMAIN, NULL, from_tty); + symtab_symbol_info (opts.quiet, false, args, TYPE_DOMAIN, nullptr, + from_tty); } /* Command completer for 'info types' command. */ @@ -5474,7 +5478,7 @@ info_modules_command (const char *args, int from_tty) (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); if (args != nullptr && *args == '\0') args = nullptr; - symtab_symbol_info (opts.quiet, true, args, MODULES_DOMAIN, NULL, + symtab_symbol_info (opts.quiet, true, args, MODULE_DOMAIN, nullptr, from_tty); } @@ -5517,7 +5521,7 @@ rbreak_command (const char *regexp, int from_tty) } } - global_symbol_searcher spec (FUNCTIONS_DOMAIN, regexp); + global_symbol_searcher spec (SEARCH_FUNCTION_DOMAIN, regexp); if (file_name != nullptr) spec.filenames.push_back (file_name); std::vector symbols = spec.search (); @@ -6015,7 +6019,7 @@ default_collect_symbol_completion_matches_break_on return true; }, SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - ALL_DOMAIN); + SEARCH_ALL); /* Search upwards from currently selected frame (so that we can complete on local vars). Also catch fields of types defined in @@ -6714,12 +6718,12 @@ static struct cmd_list_element *info_module_cmdlist = NULL; std::vector search_module_symbols (const char *module_regexp, const char *regexp, - const char *type_regexp, search_domain kind) + const char *type_regexp, domain_search_flags kind) { std::vector results; /* Search for all modules matching MODULE_REGEXP. */ - global_symbol_searcher spec1 (MODULES_DOMAIN, module_regexp); + global_symbol_searcher spec1 (SEARCH_MODULE_DOMAIN, module_regexp); spec1.set_exclude_minsyms (true); std::vector modules = spec1.search (); @@ -6765,8 +6769,10 @@ search_module_symbols (const char *module_regexp, const char *regexp, static void info_module_subcommand (bool quiet, const char *module_regexp, const char *regexp, const char *type_regexp, - search_domain kind) + domain_search_flags kind) { + gdb_assert (kind == SEARCH_FUNCTION_DOMAIN || kind == SEARCH_VAR_DOMAIN); + /* Print a header line. Don't build the header line bit by bit as this prevents internationalisation. */ if (!quiet) @@ -6776,12 +6782,12 @@ info_module_subcommand (bool quiet, const char *module_regexp, if (type_regexp == nullptr) { if (regexp == nullptr) - gdb_printf ((kind == VARIABLES_DOMAIN + gdb_printf ((kind == SEARCH_VAR_DOMAIN ? _("All variables in all modules:") : _("All functions in all modules:"))); else gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables matching regular expression" " \"%s\" in all modules:") : _("All functions matching regular expression" @@ -6792,7 +6798,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, { if (regexp == nullptr) gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables with type matching regular " "expression \"%s\" in all modules:") : _("All functions with type matching regular " @@ -6800,7 +6806,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, type_regexp); else gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables matching regular expression " "\"%s\",\n\twith type matching regular " "expression \"%s\" in all modules:") @@ -6816,7 +6822,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, { if (regexp == nullptr) gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables in all modules matching regular " "expression \"%s\":") : _("All functions in all modules matching regular " @@ -6824,7 +6830,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, module_regexp); else gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables matching regular expression " "\"%s\",\n\tin all modules matching regular " "expression \"%s\":") @@ -6837,7 +6843,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, { if (regexp == nullptr) gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables with type matching regular " "expression \"%s\"\n\tin all modules matching " "regular expression \"%s\":") @@ -6847,7 +6853,7 @@ info_module_subcommand (bool quiet, const char *module_regexp, type_regexp, module_regexp); else gdb_printf - ((kind == VARIABLES_DOMAIN + ((kind == SEARCH_VAR_DOMAIN ? _("All variables matching regular expression " "\"%s\",\n\twith type matching regular expression " "\"%s\",\n\tin all modules matching regular " @@ -6962,7 +6968,7 @@ info_module_functions_command (const char *args, int from_tty) (opts.quiet, opts.module_regexp.empty () ? nullptr : opts.module_regexp.c_str (), args, opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (), - FUNCTIONS_DOMAIN); + SEARCH_FUNCTION_DOMAIN); } /* Implements the 'info module variables' command. */ @@ -6981,7 +6987,7 @@ info_module_variables_command (const char *args, int from_tty) (opts.quiet, opts.module_regexp.empty () ? nullptr : opts.module_regexp.c_str (), args, opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (), - VARIABLES_DOMAIN); + SEARCH_VAR_DOMAIN); } /* Command completer for 'info module ...' sub-commands. */ diff --git a/gdb/symtab.h b/gdb/symtab.h index 953b6c1..b3646e4 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -947,30 +947,6 @@ search_flags_matches (domain_search_flags flags, domain_enum domain) return (flags & to_search_flags (domain)) != 0; } -/* Searching domains, used when searching for symbols. Element numbers are - hardcoded in GDB, check all enum uses before changing it. */ - -enum search_domain -{ - /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and - TYPES_DOMAIN. */ - VARIABLES_DOMAIN = 0, - - /* All functions -- for some reason not methods, though. */ - FUNCTIONS_DOMAIN = 1, - - /* All defined types */ - TYPES_DOMAIN = 2, - - /* All modules. */ - MODULES_DOMAIN = 3, - - /* Any type. */ - ALL_DOMAIN = 4 -}; - -extern const char *search_domain_name (enum search_domain); - /* An address-class says where to find the value of a symbol. */ enum address_class @@ -2584,13 +2560,11 @@ class global_symbol_searcher public: /* Constructor. */ - global_symbol_searcher (enum search_domain kind, + global_symbol_searcher (domain_search_flags kind, const char *symbol_name_regexp) : m_kind (kind), m_symbol_name_regexp (symbol_name_regexp) { - /* The symbol searching is designed to only find one kind of thing. */ - gdb_assert (m_kind != ALL_DOMAIN); } /* Set the optional regexp that matches against the symbol type. */ @@ -2632,7 +2606,7 @@ private: TYPES_DOMAIN - Search all type names. MODULES_DOMAIN - Search all Fortran modules. ALL_DOMAIN - Not valid for this function. */ - enum search_domain m_kind; + domain_search_flags m_kind; /* Regular expression to match against the symbol name. */ const char *m_symbol_name_regexp = nullptr; @@ -2676,7 +2650,7 @@ private: std::vector *results) const; /* Return true if MSYMBOL is of type KIND. */ - static bool is_suitable_msymbol (const enum search_domain kind, + static bool is_suitable_msymbol (const domain_search_flags kind, const minimal_symbol *msymbol); }; @@ -2693,7 +2667,7 @@ typedef std::pair module_symbol_search; within the module. */ extern std::vector search_module_symbols (const char *module_regexp, const char *regexp, - const char *type_regexp, search_domain kind); + const char *type_regexp, domain_search_flags kind); /* Convert a global or static symbol SYM (based on BLOCK, which should be either GLOBAL_BLOCK or STATIC_BLOCK) into a string for use in 'info' @@ -2895,7 +2869,7 @@ public: to search all symtabs and program spaces. */ void find_all_symbols (const std::string &name, const struct language_defn *language, - enum search_domain search_domain, + domain_search_flags domain_search_flags, std::vector *search_symtabs, struct program_space *search_pspace); -- cgit v1.1