JDevlieghere created this revision.
JDevlieghere added reviewers: bnbarham, mib, labath.
Herald added a project: All.
JDevlieghere requested review of this revision.

This patch removes the ability to instantiate the LLDB FileSystem class based 
on a VFS overlay. This also removes the "hack" where we cast the VFS to a 
RedirectingFileSystem to obtain the external path. You can still instantiate a 
FileSystem with a VFS, but with the caveat that operations that rely on the 
external path won't work.


https://reviews.llvm.org/D120923

Files:
  lldb/include/lldb/Host/FileSystem.h
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/macosx/objcxx/Host.mm
  lldb/source/Initialization/SystemInitializerCommon.cpp

Index: lldb/source/Initialization/SystemInitializerCommon.cpp
===================================================================
--- lldb/source/Initialization/SystemInitializerCommon.cpp
+++ lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -43,36 +43,6 @@
 /// Initialize the FileSystem based on the current reproducer mode.
 static llvm::Error InitializeFileSystem() {
   auto &r = repro::Reproducer::Instance();
-  if (repro::Loader *loader = r.GetLoader()) {
-    FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
-    if (vfs_mapping) {
-      if (llvm::Error e = FileSystem::Initialize(vfs_mapping))
-        return e;
-    } else {
-      FileSystem::Initialize();
-    }
-
-    // Set the current working directory form the reproducer.
-    llvm::Expected<std::string> working_dir =
-        repro::GetDirectoryFrom<WorkingDirectoryProvider>(loader);
-    if (!working_dir)
-      return working_dir.takeError();
-    if (std::error_code ec = FileSystem::Instance()
-                                 .GetVirtualFileSystem()
-                                 ->setCurrentWorkingDirectory(*working_dir)) {
-      return llvm::errorCodeToError(ec);
-    }
-
-    // Set the home directory from the reproducer.
-    llvm::Expected<std::string> home_dir =
-        repro::GetDirectoryFrom<HomeDirectoryProvider>(loader);
-    if (!home_dir)
-      return home_dir.takeError();
-    FileSystem::Instance().SetHomeDirectory(*home_dir);
-
-    return llvm::Error::success();
-  }
-
   if (repro::Generator *g = r.GetGenerator()) {
     repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
     vp.SetVersion(lldb_private::GetVersion());
Index: lldb/source/Host/macosx/objcxx/Host.mm
===================================================================
--- lldb/source/Host/macosx/objcxx/Host.mm
+++ lldb/source/Host/macosx/objcxx/Host.mm
@@ -1305,15 +1305,12 @@
 
   lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
 
-  // From now on we'll deal with the external (devirtualized) path.
-  auto exe_path = fs.GetExternalPath(exe_spec);
-  if (!exe_path)
-    return Status(exe_path.getError());
+  auto exe_path = exe_spec.GetPath();
 
   if (ShouldLaunchUsingXPC(launch_info))
-    error = LaunchProcessXPC(exe_path->c_str(), launch_info, pid);
+    error = LaunchProcessXPC(exe_path.c_str(), launch_info, pid);
   else
-    error = LaunchProcessPosixSpawn(exe_path->c_str(), launch_info, pid);
+    error = LaunchProcessPosixSpawn(exe_path.c_str(), launch_info, pid);
 
   if (pid != LLDB_INVALID_PROCESS_ID) {
     // If all went well, then set the process ID into the launch info
Index: lldb/source/Host/common/FileSystem.cpp
===================================================================
--- lldb/source/Host/common/FileSystem.cpp
+++ lldb/source/Host/common/FileSystem.cpp
@@ -54,22 +54,6 @@
   InstanceImpl().emplace(collector);
 }
 
-llvm::Error FileSystem::Initialize(const FileSpec &mapping) {
-  lldbassert(!InstanceImpl() && "Already initialized.");
-
-  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
-      llvm::vfs::getRealFileSystem()->getBufferForFile(mapping.GetPath());
-
-  if (!buffer)
-    return llvm::errorCodeToError(buffer.getError());
-
-  InstanceImpl().emplace(llvm::vfs::getVFSFromYAML(std::move(buffer.get()),
-                                                   nullptr, mapping.GetPath()),
-                         true);
-
-  return llvm::Error::success();
-}
-
 void FileSystem::Initialize(IntrusiveRefCntPtr<vfs::FileSystem> fs) {
   lldbassert(!InstanceImpl() && "Already initialized.");
   InstanceImpl().emplace(fs);
@@ -300,21 +284,16 @@
   Collect(path);
 
   const bool is_volatile = !IsLocal(path);
-  const ErrorOr<std::string> external_path = GetExternalPath(path);
-
-  if (!external_path)
-    return nullptr;
-
   std::unique_ptr<llvm::WritableMemoryBuffer> buffer;
   if (size == 0) {
     auto buffer_or_error =
-        llvm::WritableMemoryBuffer::getFile(*external_path, is_volatile);
+        llvm::WritableMemoryBuffer::getFile(path, is_volatile);
     if (!buffer_or_error)
       return nullptr;
     buffer = std::move(*buffer_or_error);
   } else {
     auto buffer_or_error = llvm::WritableMemoryBuffer::getFileSlice(
-        *external_path, size, offset, is_volatile);
+        path, size, offset, is_volatile);
     if (!buffer_or_error)
       return nullptr;
     buffer = std::move(*buffer_or_error);
@@ -457,12 +436,10 @@
   const mode_t open_mode =
       (open_flags & O_CREAT) ? GetOpenMode(permissions) : 0;
 
-  auto path = GetExternalPath(file_spec);
-  if (!path)
-    return errorCodeToError(path.getError());
+  auto path = file_spec.GetPath();
 
   int descriptor = llvm::sys::RetryAfterSignal(
-      -1, OpenWithFS, *this, path->c_str(), open_flags, open_mode);
+      -1, OpenWithFS, *this, path.c_str(), open_flags, open_mode);
 
   if (!File::DescriptorIsValid(descriptor))
     return llvm::errorCodeToError(
@@ -474,29 +451,6 @@
   return std::move(file);
 }
 
-ErrorOr<std::string> FileSystem::GetExternalPath(const llvm::Twine &path) {
-  if (!m_mapped)
-    return path.str();
-
-  // If VFS mapped we know the underlying FS is a RedirectingFileSystem.
-  ErrorOr<vfs::RedirectingFileSystem::LookupResult> Result =
-      static_cast<vfs::RedirectingFileSystem &>(*m_fs).lookupPath(path.str());
-  if (!Result) {
-    if (Result.getError() == llvm::errc::no_such_file_or_directory) {
-      return path.str();
-    }
-    return Result.getError();
-  }
-
-  if (Optional<StringRef> ExtRedirect = Result->getExternalRedirect())
-    return std::string(*ExtRedirect);
-  return make_error_code(llvm::errc::not_supported);
-}
-
-ErrorOr<std::string> FileSystem::GetExternalPath(const FileSpec &file_spec) {
-  return GetExternalPath(file_spec.GetPath());
-}
-
 void FileSystem::Collect(const FileSpec &file_spec) {
   Collect(file_spec.GetPath());
 }
Index: lldb/include/lldb/Host/FileSystem.h
===================================================================
--- lldb/include/lldb/Host/FileSystem.h
+++ lldb/include/lldb/Host/FileSystem.h
@@ -33,11 +33,10 @@
 
   FileSystem() : m_fs(llvm::vfs::getRealFileSystem()), m_collector(nullptr) {}
   FileSystem(std::shared_ptr<llvm::FileCollectorBase> collector)
-      : m_fs(llvm::vfs::getRealFileSystem()), m_collector(std::move(collector)),
-        m_mapped(false) {}
-  FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
-             bool mapped = false)
-      : m_fs(std::move(fs)), m_collector(nullptr), m_mapped(mapped) {}
+      : m_fs(llvm::vfs::getRealFileSystem()),
+        m_collector(std::move(collector)) {}
+  FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs)
+      : m_fs(std::move(fs)), m_collector(nullptr) {}
 
   FileSystem(const FileSystem &fs) = delete;
   FileSystem &operator=(const FileSystem &fs) = delete;
@@ -46,7 +45,6 @@
 
   static void Initialize();
   static void Initialize(std::shared_ptr<llvm::FileCollectorBase> collector);
-  static llvm::Error Initialize(const FileSpec &mapping);
   static void Initialize(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
   static void Terminate();
 
@@ -189,9 +187,6 @@
   std::error_code GetRealPath(const llvm::Twine &path,
                               llvm::SmallVectorImpl<char> &output) const;
 
-  llvm::ErrorOr<std::string> GetExternalPath(const llvm::Twine &path);
-  llvm::ErrorOr<std::string> GetExternalPath(const FileSpec &file_spec);
-
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> GetVirtualFileSystem() {
     return m_fs;
   }
@@ -206,7 +201,6 @@
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
   std::shared_ptr<llvm::FileCollectorBase> m_collector;
   std::string m_home_directory;
-  bool m_mapped = false;
 };
 } // namespace lldb_private
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to