@@ -1756,6 +1756,50 @@ void Platform::CallLocateModuleCallbackIfSet(const ModuleSpec &module_spec,
17561756 }
17571757}
17581758
1759+ void Platform::CallResolveSourceFileCallbackIfSet (
1760+ const char *build_id, const FileSpec &original_source_file_spec,
1761+ FileSpec &resolved_source_file_spec, bool *did_create_ptr) {
1762+ if (!m_resolve_source_file_callback) {
1763+ // Fetch source file callback is not set.
1764+ return ;
1765+ }
1766+
1767+ FileSpec module_file_spec;
1768+ Status error = m_resolve_source_file_callback (
1769+ build_id, original_source_file_spec, resolved_source_file_spec);
1770+
1771+ // Fetch source file callback is set and called. Check the error.
1772+ Log *log = GetLog (LLDBLog::Platform);
1773+ if (error.Fail ()) {
1774+ LLDB_LOGF (log, " %s: Fetch source file callback failed: %s" ,
1775+ LLVM_PRETTY_FUNCTION, error.AsCString ());
1776+ return ;
1777+ }
1778+
1779+ if (!resolved_source_file_spec) {
1780+ LLDB_LOGF (log,
1781+ " %s: fetch source file callback did not set "
1782+ " resolved_source_file_spec" ,
1783+ LLVM_PRETTY_FUNCTION);
1784+ return ;
1785+ }
1786+
1787+ // If the callback returned a source file, it should exist.
1788+ if (resolved_source_file_spec &&
1789+ !FileSystem::Instance ().Exists (resolved_source_file_spec)) {
1790+ LLDB_LOGF (log,
1791+ " %s: fetch source file callback set a non-existent file to "
1792+ " source_file_spec: %s" ,
1793+ LLVM_PRETTY_FUNCTION,
1794+ resolved_source_file_spec.GetPath ().c_str ());
1795+ // Clear source_file_spec for the error.
1796+ resolved_source_file_spec.Clear ();
1797+ return ;
1798+ }
1799+
1800+ *did_create_ptr = true ;
1801+ }
1802+
17591803bool Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
17601804 lldb::ModuleSP &module_sp,
17611805 bool *did_create_ptr) {
@@ -2161,6 +2205,16 @@ Platform::LocateModuleCallback Platform::GetLocateModuleCallback() const {
21612205 return m_locate_module_callback;
21622206}
21632207
2208+ void Platform::SetResolveSourceFileCallback (
2209+ ResolveSourceFileCallback callback) {
2210+ m_resolve_source_file_callback = callback;
2211+ }
2212+
2213+ Platform::ResolveSourceFileCallback
2214+ Platform::GetResolveSourceFileCallback () const {
2215+ return m_resolve_source_file_callback;
2216+ }
2217+
21642218PlatformSP PlatformList::GetOrCreate (llvm::StringRef name) {
21652219 std::lock_guard<std::recursive_mutex> guard (m_mutex);
21662220 for (const PlatformSP &platform_sp : m_platforms) {
0 commit comments