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/symfile.c | |
parent | cc77ed241bab61c0e86f4620e68be4481063a450 (diff) | |
download | gdb-d3214198119c1a2f9a6a2b8fcc56d8c324e1a245.zip gdb-d3214198119c1a2f9a6a2b8fcc56d8c324e1a245.tar.gz 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/symfile.c')
-rw-r--r-- | gdb/symfile.c | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c index 3b63887..bd27a1f 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1667,16 +1667,7 @@ symbol_file_command (const char *args, int from_tty) } } -/* 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. */ +/* Set the initial language. */ void set_initial_language (void) |