[Lldb-commits] [PATCH] D106723: [source maps] fix source mapping when there are multiple matching rules

walter erquinigo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 23 16:23:19 PDT 2021


wallace created this revision.
wallace added a reviewer: clayborg.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This error was introduced in D104406 <https://reviews.llvm.org/D104406>. If there are multiple matchings rules for a given path, lldb was only checking for the validity in the filesystem  of the first match instead of looking exhaustively one by one until a valid file is found.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106723

Files:
  lldb/include/lldb/Target/PathMappingList.h
  lldb/source/Target/PathMappingList.cpp


Index: lldb/source/Target/PathMappingList.cpp
===================================================================
--- lldb/source/Target/PathMappingList.cpp
+++ lldb/source/Target/PathMappingList.cpp
@@ -165,7 +165,7 @@
 }
 
 llvm::Optional<FileSpec>
-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<FileSpec> 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 {};
Index: lldb/include/lldb/Target/PathMappingList.h
===================================================================
--- lldb/include/lldb/Target/PathMappingList.h
+++ 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<FileSpec> RemapPath(llvm::StringRef path) const;
+  llvm::Optional<FileSpec> 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106723.361376.patch
Type: text/x-patch
Size: 2273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210723/a1bc9822/attachment.bin>


More information about the lldb-commits mailing list