https://github.com/DmT021 created https://github.com/llvm/llvm-project/pull/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. >From c417f458aed8a177e752222ae83ead687d7b64a0 Mon Sep 17 00:00:00 2001 From: Dmitrii Galimzianov <dmt...@gmail.com> Date: Mon, 12 Aug 2024 01:09:33 +0200 Subject: [PATCH] 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. --- lldb/source/Expression/IRExecutionUnit.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index f220704423627d..ad089e36eba7d6 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -785,6 +785,10 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names, return LLDB_INVALID_ADDRESS; } + ModuleList images = target->GetImages(); + // We'll process module_sp separately, before the other modules. + images.Remove(sc.module_sp); + LoadAddressResolver resolver(target, symbol_was_missing_weak); ModuleFunctionSearchOptions function_options; @@ -799,20 +803,21 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names, sc_list); if (auto load_addr = resolver.Resolve(sc_list)) return *load_addr; - } - if (sc.target_sp) { - SymbolContextList sc_list; - sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull, - function_options, sc_list); + sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, + sc_list); if (auto load_addr = resolver.Resolve(sc_list)) return *load_addr; } - if (sc.target_sp) { + { SymbolContextList sc_list; - sc.target_sp->GetImages().FindSymbolsWithNameAndType( - name, lldb::eSymbolTypeAny, sc_list); + images.FindFunctions(name, lldb::eFunctionNameTypeFull, function_options, + sc_list); + if (auto load_addr = resolver.Resolve(sc_list)) + return *load_addr; + + images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list); if (auto load_addr = resolver.Resolve(sc_list)) return *load_addr; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits