llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: None (rchamala) <details> <summary>Changes</summary> ## Summary Replace the manual owning-target lookup in `LocateSourceFile` with `ForEachScriptedTarget`, matching the pattern used by `LocateExecutableObjectFile`, `LocateExecutableSymbolFile`, and `DownloadObjectAndSymbolFile`. The previous implementation iterated all debuggers/targets and called `FindModule(module_sp.get())` to find the owning target. This works for standalone `.so` or `.dylib` modules that remain in the target's image list throughout symbol resolution but does not work for Android APK container modules that get evicted from all target image lists when their embedded `.so` files are loaded during symbol resolution, causing the owning-target lookup to fail and `locate_source_file` to never be called. `ForEachScriptedTarget` dispatches to all targets with a registered scripted locator without requiring an owning-target lookup, consistent with how the other SymbolLocator functions dispatch. ## Test plan - [ ] Existing `TestScriptedSymbolLocator.py` tests pass - [ ] APK container module source resolution works on Android targets --- Full diff: https://github.com/llvm/llvm-project/pull/181528.diff 1 Files Affected: - (modified) lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp (+26-50) ``````````diff diff --git a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp index cfbb11582a042..49ae36cfc2827 100644 --- a/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp +++ b/lldb/source/Plugins/SymbolLocator/Scripted/SymbolLocatorScripted.cpp @@ -141,61 +141,37 @@ 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) { + result = located; + return true; + } + return false; + }); + return result; } `````````` </details> https://github.com/llvm/llvm-project/pull/181528 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
