From d1eef86d12f5aa2f8461add1180df9db4b59a39d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 20 Mar 2021 17:23:40 -0600 Subject: [PATCH] Introduce objfile::require_partial_symbols This adds a new method, objfile::require_partial_symbols. This reuses most of the code from the old function in psymtab.c. That function is now made static, and simplified. gdb/ChangeLog 2021-03-20 Tom Tromey * symfile.c (read_symbols): Use objfile method. * symfile-debug.c (objfile::require_partial_symbols): New method. * psymtab.h (require_partial_symbols): Don't declare. * psymtab.c (require_partial_symbols): Use objfile method. Now static. (psymbol_functions::map_symtabs_matching_filename, OBJFILE) (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::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::find_compunit_symtab_by_address) (maintenance_print_psymbols, maintenance_info_psymtabs) (maintenance_check_psymtabs): Update. * objfiles.h (struct objfile) : Declare new method. --- gdb/ChangeLog | 25 ++++++++++++++++++ gdb/objfiles.h | 3 +++ gdb/psymtab.c | 63 ++++++++++++++++++--------------------------- gdb/psymtab.h | 8 ------ gdb/symfile-debug.c | 21 +++++++++++++++ gdb/symfile.c | 4 +-- 6 files changed, 75 insertions(+), 49 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1640270a7c1..f647ac48739 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,28 @@ +2021-03-20 Tom Tromey + + * symfile.c (read_symbols): Use objfile method. + * symfile-debug.c (objfile::require_partial_symbols): New method. + * psymtab.h (require_partial_symbols): Don't declare. + * psymtab.c (require_partial_symbols): Use objfile method. Now + static. + (psymbol_functions::map_symtabs_matching_filename, OBJFILE) + (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::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::find_compunit_symtab_by_address) + (maintenance_print_psymbols, maintenance_info_psymtabs) + (maintenance_check_psymtabs): Update. + * objfiles.h (struct objfile) : Declare + new method. + 2021-03-20 Tom Tromey * xcoffread.c (xcoff_sym_fns): Update. diff --git a/gdb/objfiles.h b/gdb/objfiles.h index ff60e18bca4..c51217be6f0 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -615,6 +615,9 @@ public: domain_enum domain, bool *symbol_found_p); + /* See quick_symbol_functions. */ + void require_partial_symbols (bool verbose); + /* The object file's original name as specified by the user, made absolute, and tilde-expanded. However, it is not canonicalized diff --git a/gdb/psymtab.c b/gdb/psymtab.c index b5ddef90878..302ef9a192f 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -75,28 +75,15 @@ psymtab_storage::install_psymtab (partial_symtab *pst) -/* See psymtab.h. */ +/* Ensure that the partial symbols for OBJFILE have been loaded. This + will print a message when symbols are loaded. This function + returns a range adapter suitable for iterating over the psymtabs of + OBJFILE. */ -psymtab_storage::partial_symtab_range -require_partial_symbols (struct objfile *objfile, bool verbose) +static psymtab_storage::partial_symtab_range +require_partial_symbols (struct objfile *objfile) { - if ((objfile->flags & OBJF_PSYMTABS_READ) == 0) - { - objfile->flags |= OBJF_PSYMTABS_READ; - - if (objfile->qf->can_lazily_read_symbols ()) - { - if (verbose) - printf_filtered (_("Reading symbols from %s...\n"), - objfile_name (objfile)); - objfile->qf->read_partial_symbols (objfile); - - if (verbose && !objfile_has_symbols (objfile)) - printf_filtered (_("(No debugging symbols found in %s)\n"), - objfile_name (objfile)); - } - } - + objfile->require_partial_symbols (true); return objfile->psymtabs (); } @@ -140,7 +127,7 @@ psymbol_functions::map_symtabs_matching_filename { const char *name_basename = lbasename (name); - for (partial_symtab *pst : require_partial_symbols (objfile, true)) + for (partial_symtab *pst : require_partial_symbols (objfile)) { /* Anonymous psymtabs don't have a file name. */ if (pst->anonymous) @@ -342,7 +329,7 @@ find_pc_sect_psymtab (struct objfile *objfile, its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying debug info type in single OBJFILE. */ - for (partial_symtab *pst : require_partial_symbols (objfile, true)) + for (partial_symtab *pst : require_partial_symbols (objfile)) if (!pst->psymtabs_addrmap_supported && pc >= pst->text_low (objfile) && pc < pst->text_high (objfile)) { @@ -465,7 +452,7 @@ psymbol_functions::lookup_symbol (struct objfile *objfile, lookup_name_info psym_lookup_name = lookup_name.make_ignore_params (); - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { if (!ps->readin_p (objfile) && lookup_partial_symbol (objfile, ps, psym_lookup_name, @@ -516,7 +503,7 @@ psymbol_functions::lookup_global_symbol_language (struct objfile *objfile, lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { struct partial_symbol *psym; if (ps->readin_p (objfile)) @@ -765,7 +752,7 @@ psymbol_functions::find_last_source_symtab (struct objfile *ofp) { struct partial_symtab *cs_pst = NULL; - for (partial_symtab *ps : require_partial_symbols (ofp, true)) + for (partial_symtab *ps : require_partial_symbols (ofp)) { const char *name = ps->filename; int len = strlen (name); @@ -801,7 +788,7 @@ psymbol_functions::find_last_source_symtab (struct objfile *ofp) void psymbol_functions::forget_cached_source_info (struct objfile *objfile) { - for (partial_symtab *pst : require_partial_symbols (objfile, true)) + for (partial_symtab *pst : require_partial_symbols (objfile)) { if (pst->fullname != NULL) { @@ -1008,7 +995,7 @@ psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache) n_psyms); i = 0; - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { if (!ps->readin_p (objfile)) i++; @@ -1061,7 +1048,7 @@ psymbol_functions::expand_symtabs_for_function (struct objfile *objfile, lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL); lookup_name_info lookup_name = base_lookup.make_ignore_params (); - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { if (ps->readin_p (objfile)) continue; @@ -1080,7 +1067,7 @@ psymbol_functions::expand_symtabs_for_function (struct objfile *objfile, void psymbol_functions::expand_all_symtabs (struct objfile *objfile) { - for (partial_symtab *psymtab : require_partial_symbols (objfile, true)) + for (partial_symtab *psymtab : require_partial_symbols (objfile)) psymtab_to_symtab (objfile, psymtab); } @@ -1091,7 +1078,7 @@ void psymbol_functions::expand_symtabs_with_fullname (struct objfile *objfile, const char *fullname) { - for (partial_symtab *p : require_partial_symbols (objfile, true)) + for (partial_symtab *p : require_partial_symbols (objfile)) { /* Anonymous psymtabs don't have a name of a source file. */ if (p->anonymous) @@ -1115,7 +1102,7 @@ psymbol_functions::map_symbol_filenames (struct objfile *objfile, void *data, int need_fullname) { - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { const char *fullname; @@ -1196,7 +1183,7 @@ psymbol_functions::map_matching_symbols { const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { QUIT; if (ps->readin_p (objfile) @@ -1321,7 +1308,7 @@ psymbol_functions::expand_symtabs_matching enum search_domain domain) { /* Clear the search flags. */ - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) ps->searched_flag = PST_NOT_SEARCHED; for (partial_symtab *ps : m_partial_symtabs->range ()) @@ -1414,7 +1401,7 @@ psymbol_functions::find_compunit_symtab_by_address (struct objfile *objfile, { std::set seen_addrs; - for (partial_symtab *pst : require_partial_symbols (objfile, true)) + for (partial_symtab *pst : require_partial_symbols (objfile)) { fill_psymbol_map (objfile, pst, &seen_addrs, @@ -1861,7 +1848,7 @@ maintenance_print_psymbols (const char *args, int from_tty) } else { - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { int print_for_source = 0; @@ -1892,7 +1879,7 @@ maintenance_print_psymbols (const char *args, int from_tty) if (address_arg == NULL && source_arg == NULL - && objfile->partial_symtabs->psymtabs_addrmap != NULL) + && partial_symtabs->psymtabs_addrmap != NULL) { outfile->puts ("\n"); dump_psymtab_addrmap (objfile, partial_symtabs, NULL, outfile); @@ -1925,7 +1912,7 @@ maintenance_info_psymtabs (const char *regexp, int from_tty) actually find a symtab whose name matches. */ int printed_objfile_start = 0; - for (partial_symtab *psymtab : require_partial_symbols (objfile, true)) + for (partial_symtab *psymtab : require_partial_symbols (objfile)) { QUIT; @@ -2025,7 +2012,7 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) const struct block *b; for (objfile *objfile : current_program_space->objfiles ()) - for (partial_symtab *ps : require_partial_symbols (objfile, true)) + for (partial_symtab *ps : require_partial_symbols (objfile)) { struct gdbarch *gdbarch = objfile->arch (); diff --git a/gdb/psymtab.h b/gdb/psymtab.h index 18b47c55b3c..e19cac64aa4 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -146,14 +146,6 @@ private: }; -/* Ensure that the partial symbols for OBJFILE have been loaded. If - VERBOSE is true, then this will print a message when symbols - are loaded. This function returns a range adapter suitable for - iterating over the psymtabs of OBJFILE. */ - -extern psymtab_storage::partial_symtab_range require_partial_symbols - (struct objfile *objfile, bool verbose); - extern quick_symbol_functions_up make_psymbol_functions (const std::shared_ptr &); diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 94559c7370c..99974536bf4 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -357,6 +357,27 @@ objfile::lookup_global_symbol_language (const char *name, return result; } +void +objfile::require_partial_symbols (bool verbose) +{ + if ((flags & OBJF_PSYMTABS_READ) == 0) + { + flags |= OBJF_PSYMTABS_READ; + + if (qf->can_lazily_read_symbols ()) + { + if (verbose) + printf_filtered (_("Reading symbols from %s...\n"), + objfile_name (this)); + qf->read_partial_symbols (this); + + if (verbose && !objfile_has_symbols (this)) + printf_filtered (_("(No debugging symbols found in %s)\n"), + objfile_name (this)); + } + } +} + /* Debugging version of struct sym_probe_fns. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 01304523c0d..d2ea04ed149 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -69,8 +69,6 @@ #include #include -#include "psymtab.h" - int (*deprecated_ui_load_progress_hook) (const char *section, unsigned long num); void (*deprecated_show_load_progress) (const char *section, @@ -793,7 +791,7 @@ read_symbols (struct objfile *objfile, symfile_add_flags add_flags) } } if ((add_flags & SYMFILE_NO_READ) == 0) - require_partial_symbols (objfile, false); + objfile->require_partial_symbols (false); } /* Initialize entry point information for this objfile. */ -- 2.30.2