Index: lldb/include/lldb/Target/PathMappingList.h =================================================================== --- lldb/include/lldb/Target/PathMappingList.h +++ lldb/include/lldb/Target/PathMappingList.h @@ -90,14 +90,9 @@ /// \param[in] orig_spec /// The original source file path to try and remap. /// - /// \param[out] new_spec - /// The newly remapped filespec that is guaranteed to exist. - /// /// \return - /// /b true if \a orig_spec was successfully located and - /// \a new_spec is filled in with an existing file spec, - /// \b false otherwise. - bool FindFile(const FileSpec &orig_spec, FileSpec &new_spec) const; + /// The newly remapped filespec that is guaranteed to exist. + llvm::Optional FindFile(const FileSpec &orig_spec) const; uint32_t FindIndexForPath(ConstString path) const; Index: lldb/source/Core/Module.cpp =================================================================== --- lldb/source/Core/Module.cpp +++ lldb/source/Core/Module.cpp @@ -1598,7 +1598,11 @@ bool Module::FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const { std::lock_guard guard(m_mutex); - return m_source_mappings.FindFile(orig_spec, new_spec); + if (auto remapped = m_source_mappings.FindFile(orig_spec)) { + new_spec = *remapped; + return true; + } + return false; } bool Module::RemapSourceFile(llvm::StringRef path, Index: lldb/source/Core/SourceManager.cpp =================================================================== --- lldb/source/Core/SourceManager.cpp +++ lldb/source/Core/SourceManager.cpp @@ -441,13 +441,17 @@ } // Try remapping if m_file_spec does not correspond to an existing file. if (!FileSystem::Instance().Exists(m_file_spec)) { - FileSpec new_file_spec; // Check target specific source remappings first, then fall back to // modules objects can have individual path remappings that were // detected when the debug info for a module was found. then - if (target->GetSourcePathMap().FindFile(m_file_spec, new_file_spec) || - target->GetImages().FindSourceFile(m_file_spec, new_file_spec)) { - m_file_spec = new_file_spec; + auto remapped = target->GetSourcePathMap().FindFile(m_file_spec); + if (!remapped) { + FileSpec new_spec; + if (target->GetImages().FindSourceFile(m_file_spec, new_spec)) + remapped = new_spec; + } + if (remapped) { + m_file_spec = *remapped; m_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec); } } Index: lldb/source/Symbol/LineEntry.cpp =================================================================== --- lldb/source/Symbol/LineEntry.cpp +++ lldb/source/Symbol/LineEntry.cpp @@ -252,9 +252,8 @@ void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) { if (target_sp) { - // Apply any file remappings to our file - FileSpec new_file_spec; - if (target_sp->GetSourcePathMap().FindFile(original_file, new_file_spec)) - file = new_file_spec; + // Apply any file remappings to our file. + if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile(original_file)) + file = *new_file_spec; } } Index: lldb/source/Target/PathMappingList.cpp =================================================================== --- lldb/source/Target/PathMappingList.cpp +++ lldb/source/Target/PathMappingList.cpp @@ -193,15 +193,16 @@ return false; } -bool PathMappingList::FindFile(const FileSpec &orig_spec, - FileSpec &new_spec) const { +llvm::Optional +PathMappingList::FindFile(const FileSpec &orig_spec) const { + FileSpec new_spec; if (m_pairs.empty()) - return false; + return {}; std::string orig_path = orig_spec.GetPath(); if (orig_path.empty()) - return false; + return {}; bool orig_is_relative = orig_spec.IsRelative(); @@ -230,12 +231,12 @@ new_spec.SetFile(entry.second.GetCString(), FileSpec::Style::native); new_spec.AppendPathComponent(orig_ref); if (FileSystem::Instance().Exists(new_spec)) - return true; + return new_spec; } } new_spec.Clear(); - return false; + return {}; } bool PathMappingList::Replace(ConstString path,