https://github.com/rchamala updated https://github.com/llvm/llvm-project/pull/183674
>From 875a23256fa551b0deca166adb67b43620480acc Mon Sep 17 00:00:00 2001 From: Rahul Reddy Chamala <[email protected]> Date: Thu, 26 Feb 2026 14:55:33 -0800 Subject: [PATCH] [lldb] Add LocateSourceFile callback to SymbolLocator plugin interface Add a LocateSourceFile callback slot to the SymbolLocator plugin interface and wire it into source file resolution via LineEntry::ApplyFileMappings. This is NFC for existing plugins: Default and DebugSymbols use the default nullptr, and Debuginfod passes an explicit nullptr since DebuggerInitialize follows it in the argument list. The new callback takes (ModuleSP, FileSpec) with no TargetSP, following the global plugin model. When a SymbolLocator plugin provides a LocateSourceFile implementation, it is called before the existing target.source-map resolution path in ApplyFileMappings. The ApplyFileMappings signature gains a `const Address &address` parameter so the implementation can extract the ModuleSP from the address. All four call sites (Module.cpp, StackFrame.cpp, StackFrameList.cpp, ThreadPlanStepRange.cpp) are updated accordingly. --- lldb/include/lldb/Core/PluginManager.h | 4 ++++ lldb/include/lldb/Symbol/LineEntry.h | 2 +- lldb/include/lldb/lldb-private-interfaces.h | 2 ++ lldb/source/Core/Module.cpp | 2 +- lldb/source/Core/PluginManager.cpp | 22 +++++++++++++++++-- .../Debuginfod/SymbolLocatorDebuginfod.cpp | 2 +- lldb/source/Symbol/LineEntry.cpp | 17 +++++++++++++- lldb/source/Target/StackFrame.cpp | 3 ++- lldb/source/Target/StackFrameList.cpp | 3 ++- lldb/source/Target/ThreadPlanStepRange.cpp | 3 ++- 10 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index 4d116f52460ff..3fd3e6177afa0 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -455,6 +455,7 @@ class PluginManager { SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file = nullptr, SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle = nullptr, + SymbolLocatorLocateSourceFile locate_source_file = nullptr, DebuggerInitializeCallback debugger_init_callback = nullptr); static bool UnregisterPlugin(SymbolLocatorCreateInstance create_callback); @@ -479,6 +480,9 @@ class PluginManager { const UUID *uuid, const ArchSpec *arch); + static FileSpec LocateSourceFile(const lldb::ModuleSP &module_sp, + const FileSpec &original_source_file); + // Trace static bool RegisterPlugin( llvm::StringRef name, llvm::StringRef description, diff --git a/lldb/include/lldb/Symbol/LineEntry.h b/lldb/include/lldb/Symbol/LineEntry.h index adf2e989e3e34..f0554805e2b74 100644 --- a/lldb/include/lldb/Symbol/LineEntry.h +++ b/lldb/include/lldb/Symbol/LineEntry.h @@ -128,7 +128,7 @@ struct LineEntry { /// /// \param[in] target_sp /// Shared pointer to the target this LineEntry belongs to. - void ApplyFileMappings(lldb::TargetSP target_sp); + void ApplyFileMappings(lldb::TargetSP target_sp, lldb::ModuleSP module_sp); /// Helper to access the file. const FileSpec &GetFile() const { return file_sp->GetSpecOnly(); } diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h index a87e01769c555..6d71b8d671b71 100644 --- a/lldb/include/lldb/lldb-private-interfaces.h +++ b/lldb/include/lldb/lldb-private-interfaces.h @@ -110,6 +110,8 @@ typedef std::optional<FileSpec> (*SymbolLocatorLocateExecutableSymbolFile)( typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)( ModuleSpec &module_spec, Status &error, bool force_lookup, bool copy_executable); +typedef std::optional<FileSpec> (*SymbolLocatorLocateSourceFile)( + const lldb::ModuleSP &module_sp, const FileSpec &original_source_file); using BreakpointHitCallback = std::function<bool(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)>; diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 659190833c20d..ccff98e6fcd19 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -476,7 +476,7 @@ uint32_t Module::ResolveSymbolContextForAddress( symfile->ResolveSymbolContext(so_addr, resolve_scope, sc); if ((resolve_scope & eSymbolContextLineEntry) && sc.line_entry.IsValid()) - sc.line_entry.ApplyFileMappings(sc.target_sp); + sc.line_entry.ApplyFileMappings(sc.target_sp, so_addr.GetModule()); } // Resolve the symbol if requested, but don't re-look it up if we've diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 64130d700a006..5b8bcc7cc68ef 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -1476,18 +1476,21 @@ struct SymbolLocatorInstance SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file, SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file, SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle, + SymbolLocatorLocateSourceFile locate_source_file, DebuggerInitializeCallback debugger_init_callback) : PluginInstance<SymbolLocatorCreateInstance>( name, description, create_callback, debugger_init_callback), locate_executable_object_file(locate_executable_object_file), locate_executable_symbol_file(locate_executable_symbol_file), download_object_symbol_file(download_object_symbol_file), - find_symbol_file_in_bundle(find_symbol_file_in_bundle) {} + find_symbol_file_in_bundle(find_symbol_file_in_bundle), + locate_source_file(locate_source_file) {} SymbolLocatorLocateExecutableObjectFile locate_executable_object_file; SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file; SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file; SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle; + SymbolLocatorLocateSourceFile locate_source_file; }; typedef PluginInstances<SymbolLocatorInstance> SymbolLocatorInstances; @@ -1503,11 +1506,12 @@ bool PluginManager::RegisterPlugin( SymbolLocatorLocateExecutableSymbolFile locate_executable_symbol_file, SymbolLocatorDownloadObjectAndSymbolFile download_object_symbol_file, SymbolLocatorFindSymbolFileInBundle find_symbol_file_in_bundle, + SymbolLocatorLocateSourceFile locate_source_file, DebuggerInitializeCallback debugger_init_callback) { return GetSymbolLocatorInstances().RegisterPlugin( name, description, create_callback, locate_executable_object_file, locate_executable_symbol_file, download_object_symbol_file, - find_symbol_file_in_bundle, debugger_init_callback); + find_symbol_file_in_bundle, locate_source_file, debugger_init_callback); } bool PluginManager::UnregisterPlugin( @@ -1591,6 +1595,20 @@ FileSpec PluginManager::FindSymbolFileInBundle(const FileSpec &symfile_bundle, return {}; } +FileSpec PluginManager::LocateSourceFile(const lldb::ModuleSP &module_sp, + const FileSpec &original_source_file) { + auto instances = GetSymbolLocatorInstances().GetSnapshot(); + for (auto &instance : instances) { + if (instance.locate_source_file) { + std::optional<FileSpec> result = + instance.locate_source_file(module_sp, original_source_file); + if (result) + return *result; + } + } + return {}; +} + #pragma mark Trace struct TraceInstance diff --git a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp index a09bb356e3a8c..bdef57f0671e1 100644 --- a/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp +++ b/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp @@ -111,7 +111,7 @@ void SymbolLocatorDebuginfod::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, LocateExecutableObjectFile, LocateExecutableSymbolFile, nullptr, - nullptr, SymbolLocatorDebuginfod::DebuggerInitialize); + nullptr, nullptr, SymbolLocatorDebuginfod::DebuggerInitialize); llvm::HTTPClient::initialize(); }); } diff --git a/lldb/source/Symbol/LineEntry.cpp b/lldb/source/Symbol/LineEntry.cpp index dcfbac8789863..4e467755ff2b2 100644 --- a/lldb/source/Symbol/LineEntry.cpp +++ b/lldb/source/Symbol/LineEntry.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include "lldb/Symbol/LineEntry.h" +#include "lldb/Core/Address.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" @@ -242,8 +244,21 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange( return complete_line_range; } -void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) { +void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp, + lldb::ModuleSP module_sp) { if (target_sp) { + // Try SymbolLocator plugins for source file resolution. The plugin + // handles the fast path internally (returns immediately when no + // scripted locators are registered). + if (module_sp) { + FileSpec resolved = PluginManager::LocateSourceFile( + module_sp, original_file_sp->GetSpecOnly()); + if (resolved) { + file_sp = std::make_shared<SupportFile>(resolved); + return; + } + } + // Apply any file remappings to our file. if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile( original_file_sp->GetSpecOnly())) { diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 9fb26176e43c0..2b97443a6a0fd 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -412,7 +412,8 @@ StackFrame::GetSymbolContext(SymbolContextItem resolve_scope) { if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) { m_sc.line_entry = sc.line_entry; - m_sc.line_entry.ApplyFileMappings(m_sc.target_sp); + m_sc.line_entry.ApplyFileMappings(m_sc.target_sp, + lookup_addr.GetModule()); } } } else { diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index 825d538e3815b..183a0b3e474ac 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -563,7 +563,8 @@ bool StackFrameList::FetchFramesUpTo(uint32_t end_idx, while (unwind_sc.GetParentOfInlinedScope( curr_frame_address, next_frame_sc, next_frame_address)) { - next_frame_sc.line_entry.ApplyFileMappings(target_sp); + next_frame_sc.line_entry.ApplyFileMappings( + target_sp, curr_frame_address.GetModule()); behaves_like_zeroth_frame = false; StackFrameSP frame_sp(new StackFrame( m_thread.shared_from_this(), m_frames.size(), idx, diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp index 3a9deb6f5c6fd..c1d1dbe5762c5 100644 --- a/lldb/source/Target/ThreadPlanStepRange.cpp +++ b/lldb/source/Target/ThreadPlanStepRange.cpp @@ -433,7 +433,8 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() { top_most_line_entry.range = range; top_most_line_entry.file_sp = std::make_shared<SupportFile>(); top_most_line_entry.ApplyFileMappings( - GetThread().CalculateTarget()); + GetThread().CalculateTarget(), + range.GetBaseAddress().GetModule()); if (!top_most_line_entry.file_sp->GetSpecOnly()) top_most_line_entry.file_sp = top_most_line_entry.original_file_sp; _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
