[Lldb-commits] [lldb] 10aa9e1 - [LLDB/Reproducers] Add flag to avoid installing the signal handler.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 9 11:50:55 PDT 2020


Author: Jonas Devlieghere
Date: 2020-07-09T11:50:45-07:00
New Revision: 10aa9e19fa2f4bf214131d30d7885f8b258b216f

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

LOG: [LLDB/Reproducers] Add flag to avoid installing the signal handler.

There are bugs where you don't want the signal handler to trigger, most
notably when that will cause another crash. Examples of this are lldb
running out of memory or a bug in the reproducer generation code. This
adds an escape hatch trough a (developer oriented) flag to not install
the signal handler.

rdar://problem/65149595

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

Added: 
    

Modified: 
    lldb/test/Shell/Reproducer/TestCrash.test
    lldb/tools/driver/Driver.cpp
    lldb/tools/driver/Options.td

Removed: 
    


################################################################################
diff  --git a/lldb/test/Shell/Reproducer/TestCrash.test b/lldb/test/Shell/Reproducer/TestCrash.test
index 1389a9b76ad3..530dd8ad398d 100644
--- a/lldb/test/Shell/Reproducer/TestCrash.test
+++ b/lldb/test/Shell/Reproducer/TestCrash.test
@@ -10,3 +10,8 @@
 # CHECK: Crash reproducer for
 # CHECK: Reproducer written to
 # CHECK: ********************
+
+# RUN: %lldb -b --capture --capture-path %t.repro --reproducer-no-generate-on-signal -o 'reproducer xcrash -s SIGSEGV' | FileCheck %s --check-prefix NOHANDLER
+
+# NOHANDLER-NOT: Crash reproducer
+# NOHANDLER-NOT: Reproducer written

diff  --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index 6b248329ce7b..cea9e5a44aa8 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -797,7 +797,8 @@ static void printHelp(LLDBOptTable &table, llvm::StringRef tool_name) {
   llvm::outs() << examples << '\n';
 }
 
-llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {
+llvm::Optional<int> InitializeReproducer(llvm::StringRef argv0,
+                                         opt::InputArgList &input_args) {
   if (auto *replay_path = input_args.getLastArg(OPT_replay)) {
     const bool no_version_check = input_args.hasArg(OPT_no_version_check);
     if (const char *error =
@@ -818,6 +819,12 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {
   }
 
   if (capture || capture_path) {
+    // Register the reproducer signal handler.
+    if (!input_args.hasArg(OPT_no_generate_on_signal)) {
+      llvm::sys::AddSignalHandler(reproducer_handler,
+                                  const_cast<char *>(argv0.data()));
+    }
+
     if (capture_path) {
       if (!capture)
         WithColor::warning() << "-capture-path specified without -capture\n";
@@ -867,13 +874,10 @@ int main(int argc, char const *argv[]) {
     return 1;
   }
 
-  if (auto exit_code = InitializeReproducer(input_args)) {
+  if (auto exit_code = InitializeReproducer(argv[0], input_args)) {
     return *exit_code;
   }
 
-  // Register the reproducer signal handler.
-  llvm::sys::AddSignalHandler(reproducer_handler, const_cast<char *>(argv[0]));
-
   SBError error = SBDebugger::InitializeWithErrorHandling();
   if (error.Fail()) {
     WithColor::error() << "initialization failed: " << error.GetCString()

diff  --git a/lldb/tools/driver/Options.td b/lldb/tools/driver/Options.td
index f5c360de6a14..96f696ec3ca6 100644
--- a/lldb/tools/driver/Options.td
+++ b/lldb/tools/driver/Options.td
@@ -234,6 +234,8 @@ def replay: Separate<["--", "-"], "replay">,
   HelpText<"Tells the debugger to replay a reproducer from <filename>.">;
 def no_version_check: F<"reproducer-no-version-check">,
   HelpText<"Disable the reproducer version check.">;
+def no_generate_on_signal: F<"reproducer-no-generate-on-signal">,
+  HelpText<"Don't generate reproducer when a signal is received.">;
 def generate_on_exit: F<"reproducer-generate-on-exit">,
   HelpText<"Generate reproducer on exit.">;
 


        


More information about the lldb-commits mailing list