https://github.com/rchamala updated https://github.com/llvm/llvm-project/pull/181528
>From 3df61c5fca0f3feee446f7091796856a5094a9df Mon Sep 17 00:00:00 2001 From: Rahul Reddy Chamala <[email protected]> Date: Sun, 15 Feb 2026 00:00:56 -0800 Subject: [PATCH] [lldb] Use ForEachScriptedTarget in LocateSourceFile Replace the manual owning-target lookup in LocateSourceFile with ForEachScriptedTarget, matching the pattern used by LocateExecutableObjectFile, LocateExecutableSymbolFile, and DownloadObjectAndSymbolFile. The previous implementation searched for the owning target by iterating all debuggers/targets and calling FindModule(module_sp.get()). This fails for APK container modules (e.g., VrShell.apk on Android) that get evicted from all target image lists when their embedded .so files are loaded during symbol resolution, causing locate_source_file to never be called. Using ForEachScriptedTarget dispatches to all targets with a registered scripted locator without requiring an owning-target lookup. --- .../Scripted/SymbolLocatorScripted.cpp | 82 ++++++++----------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp index cfbb11582a042..fde8b1c12474d 100644 --- a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp +++ b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp @@ -141,61 +141,43 @@ SymbolLocatorScripted::LocateSourceFile(const lldb::ModuleSP &module_sp, if (!module_sp) return {}; - // Find the target that owns this module. - Target *owning_target = nullptr; - for (size_t di = 0; di < Debugger::GetNumDebuggers(); di++) { - DebuggerSP debugger_sp = Debugger::GetDebuggerAtIndex(di); - if (!debugger_sp) - continue; - TargetList &target_list = debugger_sp->GetTargetList(); - for (size_t ti = 0; ti < target_list.GetNumTargets(); ti++) { - TargetSP target_sp = target_list.GetTargetAtIndex(ti); - if (!target_sp) - continue; - ModuleSP found_module = - target_sp->GetImages().FindModule(module_sp.get()); - if (found_module) { - owning_target = target_sp.get(); - break; - } - } - if (owning_target) - break; - } - - if (!owning_target) - return {}; - - auto interface_sp = owning_target->GetScriptedSymbolLocatorInterface(); - if (!interface_sp) - return {}; - - // Cache resolved source files to avoid repeated Python calls for the same - // (module, source_file) pair. + std::optional<FileSpec> result; std::string cache_key = module_sp->GetUUID().GetAsString() + ":" + original_source_file.GetPath(); - std::optional<FileSpec> cached; - if (owning_target->LookupScriptedSourceFileCache(cache_key, cached)) - return cached; + ForEachScriptedTarget( + [&](Target &target, + ScriptedSymbolLocatorInterfaceSP &interface_sp) -> bool { + // Check the per-target cache first. + std::optional<FileSpec> cached; + if (target.LookupScriptedSourceFileCache(cache_key, cached)) { + result = cached; + return result.has_value(); + } - Status error; - auto located = - interface_sp->LocateSourceFile(module_sp, original_source_file, error); + Status error; + auto located = interface_sp->LocateSourceFile( + module_sp, original_source_file, error); - Log *log = GetLog(LLDBLog::Symbols); - if (!error.Success()) { - LLDB_LOG(log, "SymbolLocatorScripted: locate_source_file failed: {0}", - error); - } + if (!error.Success()) { + Log *log = GetLog(LLDBLog::Symbols); + LLDB_LOG(log, "SymbolLocatorScripted: locate_source_file failed: {0}", + error); + } - owning_target->InsertScriptedSourceFileCache(cache_key, located); + target.InsertScriptedSourceFileCache(cache_key, located); - if (located) { - LLDB_LOGF(log, - "SymbolLocatorScripted::%s: resolved source file '%s' to '%s'", - __FUNCTION__, original_source_file.GetPath().c_str(), - located->GetPath().c_str()); - } - return located; + if (located) { + Log *log = GetLog(LLDBLog::Symbols); + LLDB_LOGF(log, + "SymbolLocatorScripted::%s: resolved source file '%s' " + "to '%s'", + __FUNCTION__, original_source_file.GetPath().c_str(), + located->GetPath().c_str()); + result = located; + return true; + } + return false; + }); + return result; } _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
