[Lldb-commits] [PATCH] D104404: Change PathMappingList::RemapPath to return an optional result (NFC)

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 25 14:16:00 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4cf7c6c6a44d: Change PathMappingList::RemapPath to return an optional result (NFC) (authored by aprantl).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D104404?vs=352486&id=354604#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104404/new/

https://reviews.llvm.org/D104404

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


Index: lldb/source/Target/PathMappingList.cpp
===================================================================
--- lldb/source/Target/PathMappingList.cpp
+++ lldb/source/Target/PathMappingList.cpp
@@ -145,18 +145,17 @@
 
 bool PathMappingList::RemapPath(ConstString path,
                                 ConstString &new_path) const {
-  std::string remapped;
-  if (RemapPath(path.GetStringRef(), remapped)) {
-    new_path.SetString(remapped);
+  if (llvm::Optional<FileSpec> remapped = RemapPath(path.GetStringRef())) {
+    new_path.SetString(remapped->GetPath());
     return true;
   }
   return false;
 }
 
-bool PathMappingList::RemapPath(llvm::StringRef path,
-                                std::string &new_path) const {
+llvm::Optional<FileSpec>
+PathMappingList::RemapPath(llvm::StringRef path) const {
   if (m_pairs.empty() || path.empty())
-    return false;
+    return {};
   LazyBool path_is_relative = eLazyBoolCalculate;
   for (const auto &it : m_pairs) {
     auto prefix = it.first.GetStringRef();
@@ -177,10 +176,9 @@
     }
     FileSpec remapped(it.second.GetStringRef());
     remapped.AppendPathComponent(path);
-    new_path = remapped.GetPath();
-    return true;
+    return remapped;
   }
-  return false;
+  return {};
 }
 
 bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) const {
Index: lldb/source/Core/Module.cpp
===================================================================
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -1604,7 +1604,11 @@
 bool Module::RemapSourceFile(llvm::StringRef path,
                              std::string &new_path) const {
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
-  return m_source_mappings.RemapPath(path, new_path);
+  if (auto remapped = m_source_mappings.RemapPath(path)) {
+    new_path = remapped->GetPath();
+    return true;
+  }
+  return false;
 }
 
 void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {
Index: lldb/include/lldb/Target/PathMappingList.h
===================================================================
--- lldb/include/lldb/Target/PathMappingList.h
+++ lldb/include/lldb/Target/PathMappingList.h
@@ -72,13 +72,9 @@
   /// \param[in] path
   ///     The original source file path to try and remap.
   ///
-  /// \param[out] new_path
-  ///     The newly remapped filespec that is may or may not exist.
-  ///
   /// \return
-  ///     /b true if \a path was successfully located and \a new_path
-  ///     is filled in with a new source path, \b false otherwise.
-  bool RemapPath(llvm::StringRef path, std::string &new_path) const;
+  ///     The remapped filespec that may or may not exist on disk.
+  llvm::Optional<FileSpec> RemapPath(llvm::StringRef path) 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: D104404.354604.patch
Type: text/x-patch
Size: 2910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210625/9ba0b1bf/attachment.bin>


More information about the lldb-commits mailing list