Skip to content

Commit d2457e6

Browse files
authored
Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols (#102835)
When we search for a symbol, we first check if it is in the module_sp of the current SymbolContext, and if not, we check in the target's modules. However, the target's ModuleList also includes the already checked module, which leads to a redundant search in it.
1 parent a98466a commit d2457e6

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,22 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
780780
return LLDB_INVALID_ADDRESS;
781781
}
782782

783+
ModuleList non_local_images = target->GetImages();
784+
// We'll process module_sp separately, before the other modules.
785+
non_local_images.Remove(sc.module_sp);
786+
783787
LoadAddressResolver resolver(target, symbol_was_missing_weak);
784788

785789
ModuleFunctionSearchOptions function_options;
786790
function_options.include_symbols = true;
787791
function_options.include_inlines = false;
788792

789793
for (const ConstString &name : names) {
794+
// The lookup order here is as follows:
795+
// 1) Functions in `sc.module_sp`
796+
// 2) Functions in the other modules
797+
// 3) Symbols in `sc.module_sp`
798+
// 4) Symbols in the other modules
790799
if (sc.module_sp) {
791800
SymbolContextList sc_list;
792801
sc.module_sp->FindFunctions(name, CompilerDeclContext(),
@@ -796,18 +805,26 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
796805
return *load_addr;
797806
}
798807

799-
if (sc.target_sp) {
808+
{
809+
SymbolContextList sc_list;
810+
non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
811+
function_options, sc_list);
812+
if (auto load_addr = resolver.Resolve(sc_list))
813+
return *load_addr;
814+
}
815+
816+
if (sc.module_sp) {
800817
SymbolContextList sc_list;
801-
sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull,
802-
function_options, sc_list);
818+
sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
819+
sc_list);
803820
if (auto load_addr = resolver.Resolve(sc_list))
804821
return *load_addr;
805822
}
806823

807-
if (sc.target_sp) {
824+
{
808825
SymbolContextList sc_list;
809-
sc.target_sp->GetImages().FindSymbolsWithNameAndType(
810-
name, lldb::eSymbolTypeAny, sc_list);
826+
non_local_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
827+
sc_list);
811828
if (auto load_addr = resolver.Resolve(sc_list))
812829
return *load_addr;
813830
}

0 commit comments

Comments
 (0)