Skip to content

Commit 45c91e4

Browse files
committed
Remove redundant symbol lookups in IRExecutionUnit::FindInSymbols
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 3c3df1b commit 45c91e4

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
785785
return LLDB_INVALID_ADDRESS;
786786
}
787787

788+
ModuleList images = target->GetImages();
789+
// We'll process module_sp separately, before the other modules.
790+
images.Remove(sc.module_sp);
791+
788792
LoadAddressResolver resolver(target, symbol_was_missing_weak);
789793

790794
ModuleFunctionSearchOptions function_options;
@@ -799,23 +803,22 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
799803
sc_list);
800804
if (auto load_addr = resolver.Resolve(sc_list))
801805
return *load_addr;
802-
}
803806

804-
if (sc.target_sp) {
805-
SymbolContextList sc_list;
806-
sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull,
807-
function_options, sc_list);
807+
sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
808+
sc_list);
808809
if (auto load_addr = resolver.Resolve(sc_list))
809810
return *load_addr;
810811
}
811812

812-
if (sc.target_sp) {
813-
SymbolContextList sc_list;
814-
sc.target_sp->GetImages().FindSymbolsWithNameAndType(
815-
name, lldb::eSymbolTypeAny, sc_list);
816-
if (auto load_addr = resolver.Resolve(sc_list))
817-
return *load_addr;
818-
}
813+
SymbolContextList sc_list;
814+
images.FindFunctions(name, lldb::eFunctionNameTypeFull, function_options,
815+
sc_list);
816+
if (auto load_addr = resolver.Resolve(sc_list))
817+
return *load_addr;
818+
819+
images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list);
820+
if (auto load_addr = resolver.Resolve(sc_list))
821+
return *load_addr;
819822

820823
lldb::addr_t best_internal_load_address =
821824
resolver.GetBestInternalLoadAddress();

0 commit comments

Comments
 (0)