From d3214198119c1a2f9a6a2b8fcc56d8c324e1a245 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 2 Apr 2020 08:47:49 +0200 Subject: [gdb] Use partial symbol table to find language for main When language is set to auto, part of loading an executable is to update the language accordingly. This is implemented by set_initial_language. The implementation of set_initial_language works as follows: - check if any objfile in the progspace has name_of_main/language_of_main set, and if so, use the first one found. [ This is what you get f.i. when using dwarf with DW_AT_main_subprogram. ] - otherwise, check for known names in the minimal symbols, and either: - use the associated language if any (f.i. for ada), or - lookup the symbol in the symtab for the name and use the symbol language (f.i. for c/c++). The symbol lookup can be slow though. In the case of the cc1 binary from PR23710 comment 1, getting to the initial prompt takes ~8s: ... $ time.sh gdb cc1 -batch -ex "show language" The current source language is "auto; currently c++". maxmem: 1272260 real: 8.05 user: 7.73 system: 0.38 ... but if we skip guessing the initial language by setting it instead, it takes only ~4s: ... $ time.sh gdb -iex "set language c++" cc1 -batch -ex "show language" The current source language is "c++". maxmem: 498272 real: 3.99 user: 3.90 system: 0.15 ... In both cases, we load the partial symbols for the executable, but in the first case only we also do a lookup of main, which causes the corresponding partial symtab to be expanded into a full symtab. Ideally, we'd like to get the language of the symbol without triggering expansion into a full symtab, and get the speedup without having to set the language manually. There's a related fixme in the header comment of set_initial_language: ... /* Set the initial language. FIXME: A better solution would be to record the language in the psymtab when reading partial symbols, and then use it (if known) to set the language. This would be a win for formats that encode the language in an easily discoverable place, such as DWARF. For stabs, we can jump through hoops looking for specially named symbols or try to intuit the language from the specific type of stabs we find, but we can't do that until later when we read in full symbols. */ void set_initial_language (void) ... Since we're already tracking the language of partial symbols, use this to set the language for the main symbol. Note that this search in partial symbol tables is not guaranteed to yield the same result as the lookup_symbol_in_language call currently done in set_initial_language. Build and reg-tested on x86_64-linux. gdb/ChangeLog: 2020-04-02 Tom de Vries * dwarf2/read.c (dwarf2_gdb_index_functions, dwarf2_debug_names_functions): Init lookup_global_symbol_language with NULL. * psymtab.c (psym_lookup_global_symbol_language): New function. (psym_functions): Init psym_lookup_global_symbol_language with psym_lookup_global_symbol_language. * symfile-debug.c (debug_sym_quick_functions): Init lookup_global_symbol_language with NULL. * symfile.c (set_initial_language): Remove fixme comment. * symfile.h (struct quick_symbol_functions): Add lookup_global_symbol_language. * symtab.c (find_quick_global_symbol_language): New function. (find_main_name): Use find_quick_global_symbol_language. gdb/testsuite/ChangeLog: 2020-04-02 Tom de Vries * gdb.base/main-psymtab.exp: New file. --- gdb/dwarf2/read.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gdb/dwarf2') diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2db527e..198fac0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4708,6 +4708,7 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions = dw2_forget_cached_source_info, dw2_map_symtabs_matching_filename, dw2_lookup_symbol, + NULL, dw2_print_stats, dw2_dump, dw2_expand_symtabs_for_function, @@ -5590,6 +5591,7 @@ const struct quick_symbol_functions dwarf2_debug_names_functions = 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, -- cgit v1.1