diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -72,9 +72,17 @@ /// \param[in] path /// The original source file path to try and remap. /// + /// \param[in] check_filesystem + /// If \b true, besides matching \p path with the remapping rules, this tries + /// to check with the filesystem that the remapped file exists. If no valid + /// file is found, \b None is returned. This might be expensive, specially + /// on a network. + /// + /// If \b false, then the existence of the returned remapping is not checked. + /// /// \return /// The remapped filespec that may or may not exist on disk. - llvm::Optional RemapPath(llvm::StringRef path) const; + llvm::Optional RemapPath(llvm::StringRef path, bool check_filesystem = false) const; bool RemapPath(const char *, std::string &) const = delete; bool ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const; diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -165,7 +165,7 @@ } llvm::Optional -PathMappingList::RemapPath(llvm::StringRef path) const { +PathMappingList::RemapPath(llvm::StringRef path, bool check_filesystem) const { if (m_pairs.empty() || path.empty()) return {}; LazyBool path_is_relative = eLazyBoolCalculate; @@ -190,7 +190,8 @@ auto orig_style = FileSpec::GuessPathStyle(prefix).getValueOr( llvm::sys::path::Style::native); AppendPathComponents(remapped, path, orig_style); - return remapped; + if (!check_filesystem || FileSystem::Instance().Exists(remapped)) + return remapped; } return {}; } @@ -213,8 +214,7 @@ llvm::Optional PathMappingList::FindFile(const FileSpec &orig_spec) const { - if (auto remapped = RemapPath(orig_spec.GetPath())) - if (FileSystem::Instance().Exists(*remapped)) + if (auto remapped = RemapPath(orig_spec.GetPath(), /*check_filesystem=*/true)) return remapped; return {};