[PATCH] D94811: [lldb] Fix fallthrough with strictly virtual working directory.

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 10:56:10 PST 2021


JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, teemperor, shafik.
Herald added subscribers: dexonsmith, hiraditya.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.

LLDB needs to change the virtual current working directory without it
breaking fallthrough. Most reproducers will contain a virtual working
directory that does not exist in the real file system during replay.

Currently, calling setCurrentWorkingDirectory on RedirectingFileSystem
will attempt to change the working directory for the external FS and if
that fails, it will set ExternalFSValidWD to false which prevents
fallthrough.


https://reviews.llvm.org/D94811

Files:
  lldb/source/Initialization/SystemInitializerCommon.cpp
  lldb/source/Utility/Reproducer.cpp
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp


Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1070,13 +1070,14 @@
 }
 
 std::error_code
-RedirectingFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
+RedirectingFileSystem::setCurrentWorkingDirectoryImpl(const Twine &Path,
+                                                      bool SetExternalCWD) {
   // Don't change the working directory if the path doesn't exist.
   if (!exists(Path))
     return errc::no_such_file_or_directory;
 
   // Always change the external FS but ignore its result.
-  if (ExternalFS) {
+  if (ExternalFS && SetExternalCWD) {
     auto EC = ExternalFS->setCurrentWorkingDirectory(Path);
     ExternalFSValidWD = !static_cast<bool>(EC);
   }
@@ -1089,6 +1090,16 @@
   return {};
 }
 
+std::error_code
+RedirectingFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
+  return setCurrentWorkingDirectoryImpl(Path, true);
+}
+
+std::error_code
+RedirectingFileSystem::setVirtualWorkingDirectory(const Twine &Path) {
+  return setCurrentWorkingDirectoryImpl(Path, false);
+}
+
 std::error_code RedirectingFileSystem::isLocal(const Twine &Path,
                                                bool &Result) {
   return ExternalFS->isLocal(Path, Result);
Index: llvm/include/llvm/Support/VirtualFileSystem.h
===================================================================
--- llvm/include/llvm/Support/VirtualFileSystem.h
+++ llvm/include/llvm/Support/VirtualFileSystem.h
@@ -720,6 +720,9 @@
   /// Get the status of a given an \c Entry.
   ErrorOr<Status> status(const Twine &Path, Entry *E);
 
+  std::error_code setCurrentWorkingDirectoryImpl(const Twine &Path,
+                                                 bool SetExternalCWD);
+
 public:
   /// Looks up \p Path in \c Roots.
   ErrorOr<Entry *> lookupPath(const Twine &Path) const;
@@ -758,6 +761,8 @@
 
   void setFallthrough(bool Fallthrough);
 
+  std::error_code setVirtualWorkingDirectory(const Twine &Path);
+
   std::vector<llvm::StringRef> getRoots() const;
 
   void dump(raw_ostream &OS) const;
Index: lldb/source/Utility/Reproducer.cpp
===================================================================
--- lldb/source/Utility/Reproducer.cpp
+++ lldb/source/Utility/Reproducer.cpp
@@ -307,7 +307,7 @@
     if (working_dir) {
       if (!vfs->exists(*working_dir))
         warning_callback("working directory '" + *working_dir + "' not in VFS");
-      vfs->setCurrentWorkingDirectory(*working_dir);
+      redirecting_vfs.setVirtualWorkingDirectory(*working_dir);
     } else {
       warning_callback("no working directory in reproducer: " +
                        toString(working_dir.takeError()));
Index: lldb/source/Initialization/SystemInitializerCommon.cpp
===================================================================
--- lldb/source/Initialization/SystemInitializerCommon.cpp
+++ lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -56,9 +56,11 @@
         repro::GetDirectoryFrom<WorkingDirectoryProvider>(loader);
     if (!working_dir)
       return working_dir.takeError();
-    if (std::error_code ec = FileSystem::Instance()
-                                 .GetVirtualFileSystem()
-                                 ->setCurrentWorkingDirectory(*working_dir)) {
+
+    auto &redirecting_vfs = static_cast<llvm::vfs::RedirectingFileSystem &>(
+        *FileSystem::Instance().GetVirtualFileSystem());
+    if (std::error_code ec =
+            redirecting_vfs.setVirtualWorkingDirectory(*working_dir)) {
       return llvm::errorCodeToError(ec);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94811.317025.patch
Type: text/x-patch
Size: 3661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210115/ff673b2d/attachment.bin>


More information about the llvm-commits mailing list