diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-20 17:23:40 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-20 17:23:42 -0600 |
commit | 39298a5d973d5822ed7d09230f67cc83f72a06c2 (patch) | |
tree | 468409018aab2f1b1856aec397eee5bd38d19f51 /gdb/dwarf2 | |
parent | 5c3f1e5bfc0cf45d8bc734aabaf0225b72a31096 (diff) | |
download | binutils-39298a5d973d5822ed7d09230f67cc83f72a06c2.zip binutils-39298a5d973d5822ed7d09230f67cc83f72a06c2.tar.gz binutils-39298a5d973d5822ed7d09230f67cc83f72a06c2.tar.bz2 |
Convert quick_symbol_functions to use methods
This changes quick_symbol_functions to be a base class with pure
virtual methods, rather than a struct holding function pointers.
Then, objfile is changed to hold a unique_ptr to an instance of this
class.
struct psymbol_functions is put into psympriv.h, and not psymtab.c,
because that is convenient later in the series.
gdb/ChangeLog
2021-03-20 Tom Tromey <tom@tromey.com>
* psympriv.h (struct psymbol_functions): New.
* symfile.c (syms_from_objfile_1, reread_symbols): Update.
* symfile-debug.c (objfile::find_compunit_symtab_by_address)
(objfile::lookup_global_symbol_language): Update.
* quick-symbol.h (struct quick_symbol_functions): Convert function
pointers to methods. Add virtual destructor.
(quick_symbol_functions_up): New typedef.
* psymtab.h (psym_functions, dwarf2_gdb_index_functions)
(dwarf2_debug_names_functions): Don't declare.
(make_psymbol_functions): Declare.
* psymtab.c (psymbol_functions::map_symtabs_matching_filename)
(psymbol_functions::find_pc_sect_compunit_symtab)
(psymbol_functions::lookup_symbol)
(psymbol_functions::lookup_global_symbol_language)
(psymbol_functions::find_last_source_symtab)
(psymbol_functions::forget_cached_source_info)
(psymbol_functions::print_stats, psymbol_functions::dump)
(psymbol_functions::expand_symtabs_for_function)
(psymbol_functions::expand_all_symtabs)
(psymbol_functions::expand_symtabs_with_fullname)
(psymbol_functions::map_symbol_filenames)
(psymbol_functions::map_matching_symbols)
(psymbol_functions::expand_symtabs_matching)
(psymbol_functions::has_symbols)
(psymbol_functions::find_compunit_symtab_by_address): Rename.
(psym_functions): Remove.
(make_psymbol_functions): New function.
* objfiles.h (struct objfile) <qf>: Change type.
* elfread.c (elf_symfile_read): Update.
* dwarf2/read.c (struct dwarf2_base_index_functions)
(struct dwarf2_gdb_index, struct dwarf2_debug_names_index): New.
(make_dwarf_gdb_index, make_dwarf_debug_names): New functions.
(dwarf2_base_index_functions::find_last_source_symtab)
(dwarf2_base_index_functions::forget_cached_source_info)
(dwarf2_base_index_functions::map_symtabs_matching_filename)
(dwarf2_gdb_index::lookup_symbol)
(dwarf2_base_index_functions::print_stats)
(dwarf2_gdb_index::dump)
(dwarf2_gdb_index::expand_symtabs_for_function)
(dwarf2_base_index_functions::expand_all_symtabs)
(dwarf2_base_index_functions::expand_symtabs_with_fullname):
Rename.
(dwarf2_gdb_index::map_matching_symbols): New method.
(dwarf2_gdb_index::expand_symtabs_matching): New method.
(dwarf2_base_index_functions::find_pc_sect_compunit_symtab)
(dwarf2_base_index_functions::map_symbol_filenames)
(dwarf2_base_index_functions::has_symbols): Rename.
(dwarf2_gdb_index_functions): Remove.
(dwarf2_debug_names_index::lookup_symbol)
(dwarf2_debug_names_index::dump)
(dwarf2_debug_names_index::expand_symtabs_for_function)
(dwarf2_debug_names_index::map_matching_symbols)
(dwarf2_debug_names_index::expand_symtabs_matching): Rename.
(dwarf2_debug_names_functions): Remove.
* dwarf2/public.h (make_dwarf_gdb_index, make_dwarf_debug_names):
Declare.
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/public.h | 3 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 274 |
2 files changed, 192 insertions, 85 deletions
diff --git a/gdb/dwarf2/public.h b/gdb/dwarf2/public.h index d0182d4..6b0fe08 100644 --- a/gdb/dwarf2/public.h +++ b/gdb/dwarf2/public.h @@ -43,4 +43,7 @@ extern bool dwarf2_initialize_objfile (struct objfile *objfile, extern void dwarf2_build_psymtabs (struct objfile *); extern void dwarf2_build_frame_info (struct objfile *); +extern quick_symbol_functions_up make_dwarf_gdb_index (); +extern quick_symbol_functions_up make_dwarf_debug_names (); + #endif /* DWARF2_PUBLIC_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 744b6bc..19e5cdb 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2150,7 +2150,7 @@ dwarf2_get_section_info (struct objfile *objfile, } -/* DWARF quick_symbols_functions support. */ +/* DWARF quick_symbol_functions support. */ /* TUs can share .debug_line entries, and there can be a lot more TUs than unique line tables, so we maintain a separate table of all .debug_line @@ -2193,6 +2193,119 @@ struct dwarf2_per_cu_quick_data unsigned int no_file_data : 1; }; +struct dwarf2_base_index_functions : public quick_symbol_functions +{ + bool has_symbols (struct objfile *objfile) override; + + struct symtab *find_last_source_symtab (struct objfile *objfile) override; + + void forget_cached_source_info (struct objfile *objfile) override; + + bool map_symtabs_matching_filename + (struct objfile *objfile, const char *name, const char *real_path, + gdb::function_view<bool (symtab *)> callback) override; + + enum language lookup_global_symbol_language (struct objfile *objfile, + const char *name, + domain_enum domain, + bool *symbol_found_p) override + { + *symbol_found_p = false; + return language_unknown; + } + + void print_stats (struct objfile *objfile) override; + + void expand_all_symtabs (struct objfile *objfile) override; + + void expand_symtabs_with_fullname (struct objfile *objfile, + const char *fullname) override; + + struct compunit_symtab *find_pc_sect_compunit_symtab + (struct objfile *objfile, struct bound_minimal_symbol msymbol, + CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override; + + struct compunit_symtab *find_compunit_symtab_by_address + (struct objfile *objfile, CORE_ADDR address) override + { + return nullptr; + } + + void map_symbol_filenames (struct objfile *objfile, + symbol_filename_ftype *fun, void *data, + int need_fullname) override; +}; + +struct dwarf2_gdb_index : public dwarf2_base_index_functions +{ + struct compunit_symtab *lookup_symbol (struct objfile *objfile, + block_enum block_index, + const char *name, + domain_enum domain) override; + + void dump (struct objfile *objfile) override; + + void expand_symtabs_for_function (struct objfile *objfile, + const char *func_name) override; + + void map_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; + + void expand_symtabs_matching + (struct objfile *objfile, + 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, + gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, + enum search_domain kind) override; +}; + +struct dwarf2_debug_names_index : public dwarf2_base_index_functions +{ + struct compunit_symtab *lookup_symbol (struct objfile *objfile, + block_enum block_index, + const char *name, + domain_enum domain) override; + + void dump (struct objfile *objfile) override; + + void expand_symtabs_for_function (struct objfile *objfile, + const char *func_name) override; + + void map_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; + + void expand_symtabs_matching + (struct objfile *objfile, + 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, + gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, + enum search_domain kind) override; +}; + +quick_symbol_functions_up +make_dwarf_gdb_index () +{ + return quick_symbol_functions_up (new dwarf2_gdb_index); +} + +quick_symbol_functions_up +make_dwarf_debug_names () +{ + return quick_symbol_functions_up (new dwarf2_debug_names_index); +} + /* Utility hash function for a stmt_list_hash. */ static hashval_t @@ -3206,8 +3319,8 @@ dw2_get_real_path (dwarf2_per_objfile *per_objfile, return qfn->real_names[index]; } -static struct symtab * -dw2_find_last_source_symtab (struct objfile *objfile) +struct symtab * +dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_cu_data *dwarf_cu = per_objfile->per_bfd->all_comp_units.back (); @@ -3240,8 +3353,9 @@ dw2_free_cached_file_names (void **slot, void *info) return 1; } -static void -dw2_forget_cached_source_info (struct objfile *objfile) +void +dwarf2_base_index_functions::forget_cached_source_info + (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -3275,8 +3389,8 @@ dw2_map_expand_apply (struct objfile *objfile, /* Implementation of the map_symtabs_matching_filename method. */ -static bool -dw2_map_symtabs_matching_filename +bool +dwarf2_base_index_functions::map_symtabs_matching_filename (struct objfile *objfile, const char *name, const char *real_path, gdb::function_view<bool (symtab *)> callback) { @@ -3525,9 +3639,10 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) return NULL; } -static struct compunit_symtab * -dw2_lookup_symbol (struct objfile *objfile, block_enum block_index, - const char *name, domain_enum domain) +struct compunit_symtab * +dwarf2_gdb_index::lookup_symbol (struct objfile *objfile, + block_enum block_index, + const char *name, domain_enum domain) { struct compunit_symtab *stab_best = NULL; dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -3568,8 +3683,8 @@ dw2_lookup_symbol (struct objfile *objfile, block_enum block_index, return stab_best; } -static void -dw2_print_stats (struct objfile *objfile) +void +dwarf2_base_index_functions::print_stats (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); int total = (per_objfile->per_bfd->all_comp_units.size () @@ -3592,8 +3707,8 @@ dw2_print_stats (struct objfile *objfile) One use is to verify .gdb_index has been loaded by the gdb.dwarf2/gdb-index.exp testcase. */ -static void -dw2_dump (struct objfile *objfile) +void +dwarf2_gdb_index::dump (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -3609,9 +3724,9 @@ dw2_dump (struct objfile *objfile) printf_filtered ("\n"); } -static void -dw2_expand_symtabs_for_function (struct objfile *objfile, - const char *func_name) +void +dwarf2_gdb_index::expand_symtabs_for_function (struct objfile *objfile, + const char *func_name) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -3625,8 +3740,8 @@ dw2_expand_symtabs_for_function (struct objfile *objfile, } -static void -dw2_expand_all_symtabs (struct objfile *objfile) +void +dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); int total_units = (per_objfile->per_bfd->all_comp_units.size () @@ -3645,9 +3760,9 @@ dw2_expand_all_symtabs (struct objfile *objfile) } } -static void -dw2_expand_symtabs_with_fullname (struct objfile *objfile, - const char *fullname) +void +dwarf2_base_index_functions::expand_symtabs_with_fullname + (struct objfile *objfile, const char *fullname) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -3753,6 +3868,18 @@ dw2_map_matching_symbols } } +void +dwarf2_gdb_index::map_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) +{ + dw2_map_matching_symbols (objfile, name, domain, global, callback, + ordered_compare); +} + /* Starting from a search name, return the string that finds the upper bound of all strings that start with SEARCH_NAME in a sorted name list. Returns the empty string to indicate that the upper bound is @@ -4746,6 +4873,19 @@ dw2_expand_symtabs_matching }, per_objfile); } +void +dwarf2_gdb_index::expand_symtabs_matching + (struct objfile *objfile, + 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, + gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, + enum search_domain kind) +{ + dw2_expand_symtabs_matching (objfile, file_matcher, lookup_name, + symbol_matcher, expansion_notify, kind); +} + /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific symtab. */ @@ -4774,12 +4914,13 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, return NULL; } -static struct compunit_symtab * -dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, - struct bound_minimal_symbol msymbol, - CORE_ADDR pc, - struct obj_section *section, - int warn_if_readin) +struct compunit_symtab * +dwarf2_base_index_functions::find_pc_sect_compunit_symtab + (struct objfile *objfile, + struct bound_minimal_symbol msymbol, + CORE_ADDR pc, + struct obj_section *section, + int warn_if_readin) { struct dwarf2_per_cu_data *data; struct compunit_symtab *result; @@ -4805,9 +4946,11 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, return result; } -static void -dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, - void *data, int need_fullname) +void +dwarf2_base_index_functions::map_symbol_filenames (struct objfile *objfile, + symbol_filename_ftype *fun, + void *data, + int need_fullname) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -4872,32 +5015,12 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, }); } -static bool -dw2_has_symbols (struct objfile *objfile) +bool +dwarf2_base_index_functions::has_symbols (struct objfile *objfile) { return true; } -const struct quick_symbol_functions dwarf2_gdb_index_functions = -{ - dw2_has_symbols, - dw2_find_last_source_symtab, - dw2_forget_cached_source_info, - dw2_map_symtabs_matching_filename, - dw2_lookup_symbol, - NULL, - dw2_print_stats, - dw2_dump, - dw2_expand_symtabs_for_function, - dw2_expand_all_symtabs, - dw2_expand_symtabs_with_fullname, - dw2_map_matching_symbols, - dw2_expand_symtabs_matching, - dw2_find_pc_sect_compunit_symtab, - NULL, - dw2_map_symbol_filenames -}; - /* DWARF-5 debug_names reader. */ /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */ @@ -5632,9 +5755,10 @@ dw2_debug_names_iterator::next () return per_cu; } -static struct compunit_symtab * -dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index, - const char *name, domain_enum domain) +struct compunit_symtab * +dwarf2_debug_names_index::lookup_symbol + (struct objfile *objfile, block_enum block_index, + const char *name, domain_enum domain) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -5683,8 +5807,8 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index, via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase uses this to verify that .debug_names has been loaded. */ -static void -dw2_debug_names_dump (struct objfile *objfile) +void +dwarf2_debug_names_index::dump (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -5697,9 +5821,9 @@ dw2_debug_names_dump (struct objfile *objfile) printf_filtered ("\n"); } -static void -dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile, - const char *func_name) +void +dwarf2_debug_names_index::expand_symtabs_for_function + (struct objfile *objfile, const char *func_name) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -5717,8 +5841,8 @@ dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile, } } -static void -dw2_debug_names_map_matching_symbols +void +dwarf2_debug_names_index::map_matching_symbols (struct objfile *objfile, const lookup_name_info &name, domain_enum domain, int global, @@ -5775,8 +5899,8 @@ dw2_debug_names_map_matching_symbols } } -static void -dw2_debug_names_expand_symtabs_matching +void +dwarf2_debug_names_index::expand_symtabs_matching (struct objfile *objfile, gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, const lookup_name_info *lookup_name, @@ -5822,26 +5946,6 @@ dw2_debug_names_expand_symtabs_matching }, per_objfile); } -const struct quick_symbol_functions dwarf2_debug_names_functions = -{ - dw2_has_symbols, - dw2_find_last_source_symtab, - dw2_forget_cached_source_info, - dw2_map_symtabs_matching_filename, - dw2_debug_names_lookup_symbol, - NULL, - dw2_print_stats, - dw2_debug_names_dump, - dw2_debug_names_expand_symtabs_for_function, - dw2_expand_all_symtabs, - dw2_expand_symtabs_with_fullname, - dw2_debug_names_map_matching_symbols, - dw2_debug_names_expand_symtabs_matching, - dw2_find_pc_sect_compunit_symtab, - NULL, - dw2_map_symbol_filenames -}; - /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point to either a dwarf2_per_bfd or dwz_file object. */ |