[Lldb-commits] [lldb] r363225 - [Reproducers] Include lldb version in the reproducer root

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 12 21:35:22 PDT 2019


Author: jdevlieghere
Date: Wed Jun 12 21:35:22 2019
New Revision: 363225

URL: http://llvm.org/viewvc/llvm-project?rev=363225&view=rev
Log:
[Reproducers] Include lldb version in the reproducer root

Generally, reproducers are rev-locked to the version of LLDB, so it's
valuable to have the LLDB version in the reproducer. For now I just want
the information to be present, without enforcing it, but I envision
emitting a warning during replay in the future.

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

Modified:
    lldb/trunk/include/lldb/Utility/Reproducer.h
    lldb/trunk/lit/Reproducer/TestFileRepro.test
    lldb/trunk/source/Initialization/SystemInitializerCommon.cpp
    lldb/trunk/source/Utility/Reproducer.cpp

Modified: lldb/trunk/include/lldb/Utility/Reproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Reproducer.h?rev=363225&r1=363224&r2=363225&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Reproducer.h (original)
+++ lldb/trunk/include/lldb/Utility/Reproducer.h Wed Jun 12 21:35:22 2019
@@ -109,6 +109,26 @@ private:
   FileCollector m_collector;
 };
 
+/// Provider for the LLDB version number.
+///
+/// When the reproducer is kept, it writes the lldb version to a file named
+/// version.txt in the reproducer root.
+class VersionProvider : public Provider<VersionProvider> {
+public:
+  VersionProvider(const FileSpec &directory) : Provider(directory) {}
+  struct Info {
+    static const char *name;
+    static const char *file;
+  };
+  void SetVersion(std::string version) {
+    assert(m_version.empty());
+    m_version = std::move(version);
+  }
+  void Keep() override;
+  std::string m_version;
+  static char ID;
+};
+
 class DataRecorder {
 public:
   DataRecorder(const FileSpec &filename, std::error_code &ec)

Modified: lldb/trunk/lit/Reproducer/TestFileRepro.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestFileRepro.test?rev=363225&r1=363224&r2=363225&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/TestFileRepro.test (original)
+++ lldb/trunk/lit/Reproducer/TestFileRepro.test Wed Jun 12 21:35:22 2019
@@ -11,6 +11,7 @@
 # RUN: %lldb -x -b -s %S/Inputs/FileCapture.in --capture --capture-path %t.repro %t.out | FileCheck %s --check-prefix CHECK --check-prefix CAPTURE
 # RUN: rm %t.out
 # RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix CHECK --check-prefix REPLAY
+# RUN: cat %t.repro/version.txt | FileCheck %s --check-prefix VERSION
 
 # CAPTURE: testing
 # REPLAY-NOT: testing
@@ -19,3 +20,5 @@
 
 # CAPTURE: Reproducer is in capture mode.
 # CAPTURE: Reproducer written
+
+# VERSION: lldb version

Modified: lldb/trunk/source/Initialization/SystemInitializerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Initialization/SystemInitializerCommon.cpp?rev=363225&r1=363224&r2=363225&view=diff
==============================================================================
--- lldb/trunk/source/Initialization/SystemInitializerCommon.cpp (original)
+++ lldb/trunk/source/Initialization/SystemInitializerCommon.cpp Wed Jun 12 21:35:22 2019
@@ -16,6 +16,7 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
+#include "lldb/lldb-private.h"
 
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
@@ -67,7 +68,6 @@ llvm::Error SystemInitializerCommon::Ini
       return e;
   }
 
-  // Initialize the file system.
   auto &r = repro::Reproducer::Instance();
   if (repro::Loader *loader = r.GetLoader()) {
     FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
@@ -78,6 +78,8 @@ llvm::Error SystemInitializerCommon::Ini
       FileSystem::Initialize();
     }
   } 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());
   } else {

Modified: lldb/trunk/source/Utility/Reproducer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Reproducer.cpp?rev=363225&r1=363224&r2=363225&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Reproducer.cpp (original)
+++ lldb/trunk/source/Utility/Reproducer.cpp Wed Jun 12 21:35:22 2019
@@ -8,6 +8,7 @@
 
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/LLDBAssert.h"
+#include "lldb/lldb-private.h"
 
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
@@ -263,11 +264,23 @@ void CommandProvider::Keep() {
 
 void CommandProvider::Discard() { m_data_recorders.clear(); }
 
+void VersionProvider::Keep() {
+  FileSpec file = GetRoot().CopyByAppendingPathComponent(Info::file);
+  std::error_code ec;
+  llvm::raw_fd_ostream os(file.GetPath(), ec, llvm::sys::fs::F_Text);
+  if (ec)
+    return;
+  os << lldb_private::GetVersion() << "\n";
+}
+
 void ProviderBase::anchor() {}
 char ProviderBase::ID = 0;
-char FileProvider::ID = 0;
 char CommandProvider::ID = 0;
-const char *FileProvider::Info::name = "files";
-const char *FileProvider::Info::file = "files.yaml";
-const char *CommandProvider::Info::name = "command-interpreter";
+char FileProvider::ID = 0;
+char VersionProvider::ID = 0;
 const char *CommandProvider::Info::file = "command-interpreter.yaml";
+const char *CommandProvider::Info::name = "command-interpreter";
+const char *FileProvider::Info::file = "files.yaml";
+const char *FileProvider::Info::name = "files";
+const char *VersionProvider::Info::file = "version.txt";
+const char *VersionProvider::Info::name = "version";




More information about the lldb-commits mailing list