diff options
author | Tom de Vries <tdevries@suse.de> | 2020-04-02 08:47:49 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2020-04-02 08:47:49 +0200 |
commit | d3214198119c1a2f9a6a2b8fcc56d8c324e1a245 (patch) | |
tree | f77fb6c23d6c4bbef96c5855844cf2a1fd21ded9 /gdb/symtab.c | |
parent | cc77ed241bab61c0e86f4620e68be4481063a450 (diff) | |
download | fsf-binutils-gdb-d3214198119c1a2f9a6a2b8fcc56d8c324e1a245.zip fsf-binutils-gdb-d3214198119c1a2f9a6a2b8fcc56d8c324e1a245.tar.gz fsf-binutils-gdb-d3214198119c1a2f9a6a2b8fcc56d8c324e1a245.tar.bz2 |
[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 <tdevries@suse.de>
* 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 <tdevries@suse.de>
* gdb.base/main-psymtab.exp: New file.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r-- | gdb/symtab.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c index 6802801..5f07f3c 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2560,6 +2560,33 @@ lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index, return result; } +/* Find the language for partial symbol with NAME. */ + +static enum language +find_quick_global_symbol_language (const char *name, const domain_enum domain) +{ + for (objfile *objfile : current_program_space->objfiles ()) + { + if (objfile->sf && objfile->sf->qf + && objfile->sf->qf->lookup_global_symbol_language) + continue; + return language_unknown; + } + + for (objfile *objfile : current_program_space->objfiles ()) + { + bool symbol_found_p; + enum language lang + = objfile->sf->qf->lookup_global_symbol_language (objfile, name, domain, + &symbol_found_p); + if (!symbol_found_p) + continue; + return lang; + } + + return language_unknown; +} + /* Private data to be used with lookup_symbol_global_iterator_cb. */ struct global_or_static_sym_lookup_data @@ -6144,6 +6171,16 @@ find_main_name (void) /* The languages above didn't identify the name of the main procedure. Fallback to "main". */ + + /* Try to find language for main in psymtabs. */ + enum language lang + = find_quick_global_symbol_language ("main", VAR_DOMAIN); + if (lang != language_unknown) + { + set_main_name ("main", lang); + return; + } + set_main_name ("main", language_unknown); } |