From c1a66c0629d3b62075a73793f1a7e7393e23e7e2 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 14 Apr 2020 15:08:42 +0200 Subject: [gdb] Expand symbolless symtabs using maint expand-symtabs Consider this test-case, consisting of header file hello.h: ... inline static const char* foo (void) { return "foo"; } ... and source file hello.c: ... int main (void) { printf ("hello: %s\n", foo ()); return 0; } ... compiled with -g: ... $ gcc hello.c -g ... When trying to expand the partial symtab for hello.h: ... $ gdb -batch \ -iex "set language c" \ a.out \ -ex "maint expand-symtabs hello.h" \ -ex "maint info psymtabs" ... we in fact find that the partial symtab for hello.h (and corresponding includer partial symtab hello.c) have not been expanded: ... { psymtab hello.h ((struct partial_symtab *) 0x27cf070) readin no ... { psymtab hello.c ((struct partial_symtab *) 0x2cf09e0) readin no ... This is due to the recursively_search_psymtabs call in psym_expand_symtabs_matching: ... if (recursively_search_psymtabs (ps, objfile, domain, lookup_name, symbol_matcher)) ... which always returns false for symbolless partial symtabs. The same problem occurs with CUs where the dwarf is generated by gas --gdwarf-2 for a foo.S: if we read such a test-case with -readnow, we'll have a symbolless symtab for foo.S. But if we read the test-case with partial symtabs, and expand those using "maint expand-symtabs", the foo.S psymtab remains unexpanded. Fix this by passing a NULL symbol_matcher and lookup_name to expand_symtabs_matching in maintenance_expand_symtabs, and skipping the call to recursively_search_psymtabs if symbol_matcher == NULL and lookup_name == NULL. Build and tested on x86_64-linux, with native. In addition, tested test-case with target boards cc-with-gdb-index.exp, cc-with-debug-names.exp and readnow.exp. gdb/ChangeLog: 2020-04-14 Tom de Vries PR symtab/25720 * symmisc.c (maintenance_expand_symtabs): Call expand_symtabs_matching with NULL symbol_matcher and lookup_name. * psymtab.c (psym_expand_symtabs_matching): Handle NULL symbol_matcher and lookup_name. * dwarf2/read.c (dw2_expand_symtabs_matching) (dw2_debug_names_expand_symtabs_matching): Same. * symfile.h (struct quick_symbol_functions::expand_symtabs_matching): Make lookup_name a pointer. Update comment. * symtab.c (global_symbol_searcher::expand_symtabs): Handle lookup_name being a pointer. * symfile.c (expand_symtabs_matching): Same. * symfile-debug.c (debug_qf_expand_symtabs_matching): Same. * linespec.c (iterate_over_all_matching_symtabs): Same. gdb/testsuite/ChangeLog: 2020-04-14 Tom de Vries PR symtab/25720 * gdb.base/maint-expand-symbols-header-file.c: New test. * gdb.base/maint-expand-symbols-header-file.exp: New file. * gdb.base/maint-expand-symbols-header-file.h: New test. --- gdb/symfile.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'gdb/symfile.h') diff --git a/gdb/symfile.h b/gdb/symfile.h index 84fa283..5ada6c3 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -253,11 +253,14 @@ struct quick_symbol_functions names (the passed file name is already only the lbasename'd part). - Otherwise, if KIND does not match, this symbol is skipped. + If the file is not skipped, and SYMBOL_MATCHER and LOOKUP_NAME are NULL, + the symbol table is expanded. - If even KIND matches, SYMBOL_MATCHER is called for each symbol - defined in the file. The symbol "search" name is passed to - SYMBOL_MATCHER. + Otherwise, individual symbols are considered. + + If KIND does not match, the symbol is skipped. + + If the symbol name does not match LOOKUP_NAME, the symbol is skipped. If SYMBOL_MATCHER returns false, then the symbol is skipped. @@ -265,7 +268,7 @@ struct quick_symbol_functions void (*expand_symtabs_matching) (struct objfile *objfile, gdb::function_view file_matcher, - const lookup_name_info &lookup_name, + const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, enum search_domain kind); -- cgit v1.1