diff options
author | Tom Tromey <tom@tromey.com> | 2023-10-21 16:38:23 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-01-08 18:40:22 -0700 |
commit | 309d28d1e49d610f925b286c119be6e2ed2ca81b (patch) | |
tree | 70d3b23a27b2b57004eb12f34bb9647ffbbde87c /gdb | |
parent | 0a008773c59bd80f80c02220537317c865546aca (diff) | |
download | binutils-309d28d1e49d610f925b286c119be6e2ed2ca81b.zip binutils-309d28d1e49d610f925b286c119be6e2ed2ca81b.tar.gz binutils-309d28d1e49d610f925b286c119be6e2ed2ca81b.tar.bz2 |
Optimize lookup_minimal_symbol_text
lookup_minimal_symbol_text always loops over all objfiles, even when
an objfile is passed in as an argument. This patch changes the
function to loop over the minimal number of objfiles in the latter
situation.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/minsyms.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 71e22ce..0e24da9 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -623,38 +623,51 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf) unsigned int hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE; - for (objfile *objfile : current_program_space->objfiles ()) - { - if (found_symbol.minsym != NULL) - break; + auto search = [&] (struct objfile *objfile) + { + for (msymbol = objfile->per_bfd->msymbol_hash[hash]; + msymbol != NULL && found_symbol.minsym == NULL; + msymbol = msymbol->hash_next) + { + if (strcmp (msymbol->linkage_name (), name) == 0 && + (msymbol->type () == mst_text + || msymbol->type () == mst_text_gnu_ifunc + || msymbol->type () == mst_file_text)) + { + switch (msymbol->type ()) + { + case mst_file_text: + found_file_symbol.minsym = msymbol; + found_file_symbol.objfile = objfile; + break; + default: + found_symbol.minsym = msymbol; + found_symbol.objfile = objfile; + break; + } + } + } + }; - if (objf == NULL || objf == objfile - || objf == objfile->separate_debug_objfile_backlink) + if (objf == nullptr) + { + for (objfile *objfile : current_program_space->objfiles ()) { - for (msymbol = objfile->per_bfd->msymbol_hash[hash]; - msymbol != NULL && found_symbol.minsym == NULL; - msymbol = msymbol->hash_next) - { - if (strcmp (msymbol->linkage_name (), name) == 0 && - (msymbol->type () == mst_text - || msymbol->type () == mst_text_gnu_ifunc - || msymbol->type () == mst_file_text)) - { - switch (msymbol->type ()) - { - case mst_file_text: - found_file_symbol.minsym = msymbol; - found_file_symbol.objfile = objfile; - break; - default: - found_symbol.minsym = msymbol; - found_symbol.objfile = objfile; - break; - } - } - } + if (found_symbol.minsym != NULL) + break; + search (objfile); } } + else + { + for (objfile *objfile : objf->separate_debug_objfiles ()) + { + if (found_symbol.minsym != NULL) + break; + search (objfile); + } + } + /* External symbols are best. */ if (found_symbol.minsym) return found_symbol; |