[Lldb-commits] [lldb] 066e817 - [lldb/Reproducers] Add a flag to always generating a reproducer

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 15 19:46:01 PST 2020


Author: Jonas Devlieghere
Date: 2020-01-15T19:45:54-08:00
New Revision: 066e817b421e8502a72735988e14713940517aaa

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

LOG: [lldb/Reproducers] Add a flag to always generating a reproducer

Add a flag which always generates a reproducer when normally it would be
discarded. This is meant for testing purposes to capture a debugger
session without modification the session itself.

Added: 
    

Modified: 
    lldb/include/lldb/API/SBReproducer.h
    lldb/include/lldb/Utility/Reproducer.h
    lldb/source/API/SBReproducer.cpp
    lldb/source/Utility/Reproducer.cpp
    lldb/test/Shell/Reproducer/TestDriverOptions.test
    lldb/tools/driver/Driver.cpp
    lldb/tools/driver/Options.td

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/API/SBReproducer.h b/lldb/include/lldb/API/SBReproducer.h
index 93d78f55fd76..0a25bcbf541e 100644
--- a/lldb/include/lldb/API/SBReproducer.h
+++ b/lldb/include/lldb/API/SBReproducer.h
@@ -23,6 +23,7 @@ class LLDB_API SBReproducer {
   static const char *Replay(const char *path);
   static const char *Replay(const char *path, bool skip_version_check);
   static const char *GetPath();
+  static bool SetAutoGenerate(bool b);
   static bool Generate();
 };
 

diff  --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h
index 0d23fe8571ff..0524bcf6b24d 100644
--- a/lldb/include/lldb/Utility/Reproducer.h
+++ b/lldb/include/lldb/Utility/Reproducer.h
@@ -231,6 +231,9 @@ class Generator final {
   /// might need to clean up files already written to disk.
   void Discard();
 
+  /// Enable or disable auto generate.
+  void SetAutoGenerate(bool b);
+
   /// Create and register a new provider.
   template <typename T> T *Create() {
     std::unique_ptr<ProviderBase> provider = std::make_unique<T>(m_root);
@@ -272,6 +275,9 @@ class Generator final {
 
   /// Flag to ensure that we never call both keep and discard.
   bool m_done = false;
+
+  /// Flag to auto generate a reproducer when it would otherwise be discarded.
+  bool m_auto_generate = false;
 };
 
 class Loader final {

diff  --git a/lldb/source/API/SBReproducer.cpp b/lldb/source/API/SBReproducer.cpp
index 3d2de0727444..6d78eba52efb 100644
--- a/lldb/source/API/SBReproducer.cpp
+++ b/lldb/source/API/SBReproducer.cpp
@@ -178,6 +178,15 @@ bool SBReproducer::Generate() {
   return false;
 }
 
+bool SBReproducer::SetAutoGenerate(bool b) {
+  auto &r = Reproducer::Instance();
+  if (auto generator = r.GetGenerator()) {
+    generator->SetAutoGenerate(b);
+    return true;
+  }
+  return false;
+}
+
 const char *SBReproducer::GetPath() {
   static std::string path;
   auto &r = Reproducer::Instance();

diff  --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp
index e243d784d185..8957763b7fd5 100644
--- a/lldb/source/Utility/Reproducer.cpp
+++ b/lldb/source/Utility/Reproducer.cpp
@@ -167,8 +167,12 @@ Generator::Generator(FileSpec root) : m_root(MakeAbsolute(std::move(root))) {
 }
 
 Generator::~Generator() {
-  if (!m_done)
-    Discard();
+  if (!m_done) {
+    if (m_auto_generate)
+      Keep();
+    else
+      Discard();
+  }
 }
 
 ProviderBase *Generator::Register(std::unique_ptr<ProviderBase> provider) {
@@ -199,6 +203,8 @@ void Generator::Discard() {
   llvm::sys::fs::remove_directories(m_root.GetPath());
 }
 
+void Generator::SetAutoGenerate(bool b) { m_auto_generate = b; }
+
 const FileSpec &Generator::GetRoot() const { return m_root; }
 
 void Generator::AddProvidersToIndex() {

diff  --git a/lldb/test/Shell/Reproducer/TestDriverOptions.test b/lldb/test/Shell/Reproducer/TestDriverOptions.test
index 4b5dfbf063ca..e249a401d15b 100644
--- a/lldb/test/Shell/Reproducer/TestDriverOptions.test
+++ b/lldb/test/Shell/Reproducer/TestDriverOptions.test
@@ -11,7 +11,14 @@
 # RUN: %lldb --capture --capture-path %t.repro -b -o 'reproducer status' 2>&1 | FileCheck %s --check-prefix NO-WARNING --check-prefix STATUS-CAPTURE
 # RUN: %lldb --capture -b -o 'reproducer status' 2>&1 | FileCheck %s --check-prefix NO-WARNING --check-prefix STATUS-CAPTURE
 # RUN: %lldb --capture-path %t.repro -b -o 'reproducer status' 2>&1 | FileCheck %s --check-prefix WARNING --check-prefix STATUS-CAPTURE
+# RUN: %lldb --capture-path %t.repro -b -o 'reproducer status' --reproducer-auto-generate  2>&1 | FileCheck %s --check-prefix WARNING2
 #
 # NO-WARNING-NOT: warning: -capture-path specified without -capture
 # WARNING: warning: -capture-path specified without -capture
+# WARNING2: warning: -reproducer-auto-generate specified without -capture
 # STATUS-CAPTURE: Reproducer is in capture mode.
+
+# Check auto generate.
+# RUN: rm -rf %t.repro
+# RUN: %lldb --capture --capture-path %t.repro -b --reproducer-auto-generate -o 'reproducer status' 2>&1 | FileCheck %s --check-prefix NO-WARNING
+# RUN: cat %t.repro/index.yaml

diff  --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 73874389aa1b..670361787f1f 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -807,8 +807,14 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {
   }
 
   bool capture = input_args.hasArg(OPT_capture);
+  bool auto_generate = input_args.hasArg(OPT_auto_generate);
   auto *capture_path = input_args.getLastArg(OPT_capture_path);
 
+  if (auto_generate && !capture) {
+    WithColor::warning()
+        << "-reproducer-auto-generate specified without -capture\n";
+  }
+
   if (capture || capture_path) {
     if (capture_path) {
       if (!capture)
@@ -824,6 +830,8 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {
         return 1;
       }
     }
+    if (auto_generate)
+      SBReproducer::SetAutoGenerate(true);
   }
 
   return llvm::None;

diff  --git a/lldb/tools/driver/Options.td b/lldb/tools/driver/Options.td
index c237f568f64c..e459a153d618 100644
--- a/lldb/tools/driver/Options.td
+++ b/lldb/tools/driver/Options.td
@@ -234,5 +234,7 @@ def replay: Separate<["--", "-"], "replay">,
   HelpText<"Tells the debugger to replay a reproducer from <filename>.">;
 def skip_version_check: F<"reproducer-skip-version-check">,
   HelpText<"Skip the reproducer version check.">;
+def auto_generate: F<"reproducer-auto-generate">,
+  HelpText<"Generate reproducer on exit.">;
 
 def REM : R<["--"], "">;


        


More information about the lldb-commits mailing list