[Lldb-commits] [lldb] r355936 - [Reproducers] Support capturing a reproducer without an explicit path.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 12 09:44:19 PDT 2019


Author: jdevlieghere
Date: Tue Mar 12 09:44:18 2019
New Revision: 355936

URL: http://llvm.org/viewvc/llvm-project?rev=355936&view=rev
Log:
[Reproducers] Support capturing a reproducer without an explicit path.

Tablegen doesn't support options that are both flags and take values as
an argument. I noticed this when doing the tablegen rewrite, but forgot
that that affected the reproducer --capture flag.

This patch makes --capture a flag and adds --capture-path to specify a
path for the reproducer. In reality I expect this to be mostly used for
testing, but it could be useful nonetheless.

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

Modified:
    lldb/trunk/include/lldb/API/SBReproducer.h
    lldb/trunk/lit/Reproducer/Functionalities/TestDataFormatter.test
    lldb/trunk/lit/Reproducer/Functionalities/TestImageList.test
    lldb/trunk/lit/Reproducer/Functionalities/TestStepping.test
    lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test
    lldb/trunk/lit/Reproducer/TestDriverOptions.test
    lldb/trunk/lit/Reproducer/TestFileRepro.test
    lldb/trunk/lit/Reproducer/TestGDBRemoteRepro.test
    lldb/trunk/source/API/SBReproducer.cpp
    lldb/trunk/tools/driver/Driver.cpp
    lldb/trunk/tools/driver/Options.td

Modified: lldb/trunk/include/lldb/API/SBReproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBReproducer.h?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBReproducer.h (original)
+++ lldb/trunk/include/lldb/API/SBReproducer.h Tue Mar 12 09:44:18 2019
@@ -18,6 +18,7 @@ namespace lldb {
 /// in the interface or implementation of this class.
 class LLDB_API SBReproducer {
 public:
+  static const char *Capture();
   static const char *Capture(const char *path);
   static const char *Replay(const char *path);
 };

Modified: lldb/trunk/lit/Reproducer/Functionalities/TestDataFormatter.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Functionalities/TestDataFormatter.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/Functionalities/TestDataFormatter.test (original)
+++ lldb/trunk/lit/Reproducer/Functionalities/TestDataFormatter.test Tue Mar 12 09:44:18 2019
@@ -5,7 +5,7 @@
 # RUN: rm -rf %t.repro
 # RUN: %clangxx %S/Inputs/foo.cpp -g -o %t.out
 
-# RUN: %lldb -x -b -s %S/Inputs/DataFormatter.in --capture %t.repro %t.out | FileCheck %s
+# RUN: %lldb -x -b -s %S/Inputs/DataFormatter.in --capture --capture-path %t.repro %t.out | FileCheck %s
 # RUN: %lldb --replay %t.repro | FileCheck %s
 
 # CHECK: stop reason = breakpoint 1.1

Modified: lldb/trunk/lit/Reproducer/Functionalities/TestImageList.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Functionalities/TestImageList.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/Functionalities/TestImageList.test (original)
+++ lldb/trunk/lit/Reproducer/Functionalities/TestImageList.test Tue Mar 12 09:44:18 2019
@@ -8,7 +8,7 @@
 # RUN: rm -rf %t.txt
 
 # RUN: echo "CAPTURE" >> %t.txt
-# RUN: %lldb -x -b  --capture %t.repro \
+# RUN: %lldb -x -b  --capture --capture-path %t.repro \
 # RUN:    -o 'run' \
 # RUN:    -o 'image list' \
 # RUN:    -o 'reproducer generate' \

Modified: lldb/trunk/lit/Reproducer/Functionalities/TestStepping.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Functionalities/TestStepping.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/Functionalities/TestStepping.test (original)
+++ lldb/trunk/lit/Reproducer/Functionalities/TestStepping.test Tue Mar 12 09:44:18 2019
@@ -2,10 +2,11 @@
 
 # This tests that stepping continues to work when replaying a reproducer.
 
+# RUN: rm -rf %t.repro
 # RUN: %clang %S/Inputs/stepping.c -O0 -g -o %t.out
 # RUN: grep -v '#' %s > %t.in
 
-# RUN: %lldb -x -b -s %t.in --capture %t.repro %t.out | FileCheck %s --check-prefix CHECK
+# RUN: %lldb -x -b -s %t.in --capture --capture-path %t.repro %t.out | FileCheck %s --check-prefix CHECK
 # RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix CHECK
 
 # Set breakpoints in a,b and c and verify we stop there when stepping.

Modified: lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test (original)
+++ lldb/trunk/lit/Reproducer/Modules/TestModuleCXX.test Tue Mar 12 09:44:18 2019
@@ -1,6 +1,7 @@
 # REQUIRES: system-darwin
 
 # Start fresh.
+# RUN: rm -rf %t.repro
 # RUN: rm -rf %t.root
 # RUN: rm -rf %t.clang-cache
 # RUN: rm -rf %t.lldb-cache
@@ -18,7 +19,7 @@
 # RUN: %clang %t.root/main.cpp -g -fmodules -fcxx-modules -fmodules-cache-path=%t.clang-cache -o %t.root/a.out
 
 # Capture the debug session.
-# RUN: %lldb -x -b -o 'settings set symbols.clang-modules-cache-path %t.lldb-cache' -s %S/Inputs/ModuleCXX.in --capture %t.repro %t.root/a.out | FileCheck %s --check-prefix CAPTURE
+# RUN: %lldb -x -b -o 'settings set symbols.clang-modules-cache-path %t.lldb-cache' -s %S/Inputs/ModuleCXX.in --capture --capture-path %t.repro %t.root/a.out | FileCheck %s --check-prefix CAPTURE
 # CAPTURE: (success = 0)
 
 # RUN: cat %t.repro/files.yaml | FileCheck %s --check-prefix YAML

Modified: lldb/trunk/lit/Reproducer/TestDriverOptions.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestDriverOptions.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/TestDriverOptions.test (original)
+++ lldb/trunk/lit/Reproducer/TestDriverOptions.test Tue Mar 12 09:44:18 2019
@@ -1,7 +1,17 @@
 # Check that errors are propagated to the driver.
+#
+# RUN: not %lldb --capture --capture-path %t/bogus/bogus 2>&1 | FileCheck %s --check-prefix INVALID-CAPTURE
+# RUN: not %lldb --replay %t/bogus/bogus  2>&1 | FileCheck %s --check-prefix INVALID-REPLAY
+#
+# INVALID-CAPTURE: unable to create reproducer directory
+# INVALID-REPLAY: unable to load reproducer index
 
-# RUN: not %lldb --capture %t/bogus/bogus 2>&1 | FileCheck %s --check-prefix CAPTURE
-# RUN: not %lldb --replay %t/bogus/bogus  2>&1 | FileCheck %s --check-prefix REPLAY
-
-# CAPTURE: unable to create reproducer directory
-# REPLAY: unable to load reproducer index
+# Check that all option combination work as expected.
+#
+# 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
+#
+# NO-WARNING-NOT: warning: -capture-path specified without -capture
+# WARNING: warning: -capture-path specified without -capture
+# STATUS-CAPTURE: Reproducer is in capture mode.

Modified: lldb/trunk/lit/Reproducer/TestFileRepro.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestFileRepro.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/TestFileRepro.test (original)
+++ lldb/trunk/lit/Reproducer/TestFileRepro.test Tue Mar 12 09:44:18 2019
@@ -6,8 +6,9 @@
 # process. To ensure we're not actually running the original binary we check
 # that the string "testing" is not printed.
 
+# RUN: rm -rf %t.repro
 # RUN: %clang %S/Inputs/simple.c -g -o %t.out
-# RUN: %lldb -x -b -s %S/Inputs/FileCapture.in --capture %t.repro %t.out | FileCheck %s --check-prefix CHECK --check-prefix CAPTURE
+# 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
 

Modified: lldb/trunk/lit/Reproducer/TestGDBRemoteRepro.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Reproducer/TestGDBRemoteRepro.test?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/lit/Reproducer/TestGDBRemoteRepro.test (original)
+++ lldb/trunk/lit/Reproducer/TestGDBRemoteRepro.test Tue Mar 12 09:44:18 2019
@@ -6,8 +6,9 @@
 # process. To ensure we're not actually running the original binary we check
 # that the string "testing" is not printed.
 
+# RUN: rm -rf %t.repro
 # RUN: %clang %S/Inputs/simple.c -g -o %t.out
-# RUN: %lldb -x -b -s %S/Inputs/GDBRemoteCapture.in --capture %t.repro %t.out | FileCheck %s --check-prefix CHECK --check-prefix CAPTURE
+# RUN: %lldb -x -b -s %S/Inputs/GDBRemoteCapture.in --capture --capture-path %t.repro %t.out | FileCheck %s --check-prefix CHECK --check-prefix CAPTURE
 # RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix CHECK --check-prefix REPLAY
 
 # CHECK: Breakpoint 1

Modified: lldb/trunk/source/API/SBReproducer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBReproducer.cpp?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/source/API/SBReproducer.cpp (original)
+++ lldb/trunk/source/API/SBReproducer.cpp Tue Mar 12 09:44:18 2019
@@ -2940,6 +2940,15 @@ SBRegistry::SBRegistry() {
   }
 }
 
+const char *SBReproducer::Capture() {
+  static std::string error;
+  if (auto e = Reproducer::Initialize(ReproducerMode::Capture, llvm::None)) {
+    error = llvm::toString(std::move(e));
+    return error.c_str();
+  }
+  return nullptr;
+}
+
 const char *SBReproducer::Capture(const char *path) {
   static std::string error;
   if (auto e =

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Tue Mar 12 09:44:18 2019
@@ -849,6 +849,38 @@ EXAMPLES:
   llvm::outs() << examples;
 }
 
+llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {
+  if (auto *replay_path = input_args.getLastArg(OPT_replay)) {
+    if (const char *error = SBReproducer::Replay(replay_path->getValue())) {
+      WithColor::error() << "reproducer replay failed: " << error << '\n';
+      return 1;
+    }
+    return 0;
+  }
+
+  bool capture = input_args.hasArg(OPT_capture);
+  auto *capture_path = input_args.getLastArg(OPT_capture_path);
+
+  if (capture || capture_path) {
+    if (capture_path) {
+      if (!capture)
+        WithColor::warning() << "-capture-path specified without -capture\n";
+      if (const char *error = SBReproducer::Capture(capture_path->getValue())) {
+        WithColor::error() << "reproducer capture failed: " << error << '\n';
+        return 1;
+      }
+    } else {
+      const char *error = SBReproducer::Capture();
+      if (error) {
+        WithColor::error() << "reproducer capture failed: " << error << '\n';
+        return 1;
+      }
+    }
+  }
+
+  return llvm::None;
+}
+
 int
 #ifdef _MSC_VER
 wmain(int argc, wchar_t const *wargv[])
@@ -889,23 +921,8 @@ main(int argc, char const *argv[])
                          << '\n';
   }
 
-  if (auto *arg = input_args.getLastArg(OPT_capture)) {
-    auto arg_value = arg->getValue();
-    const char *error = SBReproducer::Capture(arg_value);
-    if (error) {
-      WithColor::error() << "reproducer capture failed: " << error << '\n';
-      return 1;
-    }
-  }
-
-  if (auto *arg = input_args.getLastArg(OPT_replay)) {
-    auto arg_value = arg->getValue();
-    const char *error = SBReproducer::Replay(arg_value);
-    if (error) {
-      WithColor::error() << "reproducer replay failed: " << error << '\n';
-      return 1;
-    }
-    return 0;
+  if (auto exit_code = InitializeReproducer(input_args)) {
+    return *exit_code;
   }
 
   SBError error = SBDebugger::InitializeWithErrorHandling();

Modified: lldb/trunk/tools/driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Options.td?rev=355936&r1=355935&r2=355936&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Options.td (original)
+++ lldb/trunk/tools/driver/Options.td Tue Mar 12 09:44:18 2019
@@ -219,9 +219,11 @@ def: Flag<["-"], "d">,
   Alias<debug>,
   HelpText<"Alias for --debug">;
 
-def capture: Separate<["--", "-"], "capture">,
+def capture: F<"capture">,
+  HelpText<"Tells the debugger to capture a reproducer.">;
+def capture_path: Separate<["--", "-"], "capture-path">,
   MetaVarName<"<filename>">,
-  HelpText<"Tells the debugger to capture a reproducer to <filename>.">;
+  HelpText<"Tells the debugger to use the given filename for the reproducer.">;
 def replay: Separate<["--", "-"], "replay">,
   MetaVarName<"<filename>">,
   HelpText<"Tells the debugger to replay a reproducer from <filename>.">;




More information about the lldb-commits mailing list