[Lldb-commits] [lldb] 59eb705 - [lldb] Remove FileSystem::Initialize from VFS mapping

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 3 11:02:16 PST 2022


Author: Jonas Devlieghere
Date: 2022-03-03T11:02:11-08:00
New Revision: 59eb70527741594fe3c92d0a1b6704ed45111437

URL: https://github.com/llvm/llvm-project/commit/59eb70527741594fe3c92d0a1b6704ed45111437
DIFF: https://github.com/llvm/llvm-project/commit/59eb70527741594fe3c92d0a1b6704ed45111437.diff

LOG: [lldb] Remove FileSystem::Initialize from VFS mapping

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.

Differential revision: https://reviews.llvm.org/D120923

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/FileSystem.h b/lldb/include/lldb/Host/FileSystem.h
index 9f863e8a9d7e2..50c48648fecda 100644
--- a/lldb/include/lldb/Host/FileSystem.h
+++ b/lldb/include/lldb/Host/FileSystem.h
@@ -33,11 +33,10 @@ class FileSystem {
 
   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 @@ class FileSystem {
 
   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 @@ class FileSystem {
   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 @@ class FileSystem {
   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
 

diff  --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp
index 26a98fa0a4ec4..4a8cc3a21ea43 100644
--- a/lldb/source/Host/common/FileSystem.cpp
+++ b/lldb/source/Host/common/FileSystem.cpp
@@ -54,22 +54,6 @@ void FileSystem::Initialize(std::shared_ptr<FileCollectorBase> collector) {
   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 @@ FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
   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 @@ Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
   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 @@ Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
   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());
 }

diff  --git a/lldb/source/Host/macosx/objcxx/Host.mm b/lldb/source/Host/macosx/objcxx/Host.mm
index 06d14ede35c38..0a51e534896a1 100644
--- a/lldb/source/Host/macosx/objcxx/Host.mm
+++ b/lldb/source/Host/macosx/objcxx/Host.mm
@@ -1305,15 +1305,12 @@ static bool ShouldLaunchUsingXPC(ProcessLaunchInfo &launch_info) {
 
   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

diff  --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 7994aefa185c8..bb44d9116717c 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -43,36 +43,6 @@ SystemInitializerCommon::~SystemInitializerCommon() = default;
 /// 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());


        


More information about the lldb-commits mailing list