[Lldb-commits] [lldb] ed17b6f - [lldb] Extract FileSystem initialization code into helper (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 20 15:10:44 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-20T15:10:38-07:00
New Revision: ed17b6f6308f81273919532d422e3858d9a7c1da

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

LOG: [lldb] Extract FileSystem initialization code into helper (NFC)

The FileSystem initialization depends on the reproducer mode. It has
been growing organically to the point where it deserves its own helper
function. This also allows for early returns to simplify the code.

Added: 
    

Modified: 
    lldb/source/Initialization/SystemInitializerCommon.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp
index 3d07f92259be..028040b59683 100644
--- a/lldb/source/Initialization/SystemInitializerCommon.cpp
+++ b/lldb/source/Initialization/SystemInitializerCommon.cpp
@@ -39,6 +39,51 @@ SystemInitializerCommon::SystemInitializerCommon() {}
 
 SystemInitializerCommon::~SystemInitializerCommon() {}
 
+/// 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();
+    }
+
+    llvm::Expected<std::string> cwd =
+        loader->LoadBuffer<WorkingDirectoryProvider>();
+    if (!cwd)
+      return cwd.takeError();
+
+    llvm::StringRef working_dir = llvm::StringRef(*cwd).rtrim();
+    if (std::error_code ec = FileSystem::Instance()
+                                 .GetVirtualFileSystem()
+                                 ->setCurrentWorkingDirectory(working_dir)) {
+      return llvm::errorCodeToError(ec);
+    }
+
+    return llvm::Error::success();
+  }
+
+  if (repro::Generator *g = r.GetGenerator()) {
+    repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
+    vp.SetVersion(lldb_private::GetVersion());
+
+    repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
+    FileSystem::Initialize(fp.GetFileCollector());
+
+    repro::WorkingDirectoryProvider &wp =
+        g->GetOrCreate<repro::WorkingDirectoryProvider>();
+    fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
+
+    return llvm::Error::success();
+  }
+
+  FileSystem::Initialize();
+  return llvm::Error::success();
+}
+
 llvm::Error SystemInitializerCommon::Initialize() {
 #if defined(_WIN32)
   const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
@@ -69,36 +114,8 @@ llvm::Error SystemInitializerCommon::Initialize() {
       return e;
   }
 
-  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();
-    }
-    if (llvm::Expected<std::string> cwd =
-            loader->LoadBuffer<WorkingDirectoryProvider>()) {
-      llvm::StringRef working_dir = llvm::StringRef(*cwd).rtrim();
-      if (std::error_code ec = FileSystem::Instance()
-                                   .GetVirtualFileSystem()
-                                   ->setCurrentWorkingDirectory(working_dir)) {
-        return llvm::errorCodeToError(ec);
-      }
-    } else {
-      return cwd.takeError();
-    }
-  } else if (repro::Generator *g = r.GetGenerator()) {
-    repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
-    vp.SetVersion(lldb_private::GetVersion());
-    repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
-    FileSystem::Initialize(fp.GetFileCollector());
-    repro::WorkingDirectoryProvider &wp = g->GetOrCreate<repro::WorkingDirectoryProvider>();
-    fp.RecordInterestingDirectory(wp.GetWorkingDirectory());
-  } else {
-    FileSystem::Initialize();
-  }
+  if (auto e = InitializeFileSystem())
+    return e;
 
   Log::Initialize();
   HostInfo::Initialize();


        


More information about the lldb-commits mailing list