[Lldb-commits] [PATCH] D119009: [Support] Ensure handlers are set up before printing the stacktrace

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 7 08:59:39 PST 2022


werat updated this revision to Diff 406487.
werat added a comment.

Restore accidentally removed code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119009/new/

https://reviews.llvm.org/D119009

Files:
  lldb/source/API/SystemInitializerFull.cpp
  llvm/lib/Support/Unix/Signals.inc
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===================================================================
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -504,6 +504,11 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
                                        bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+    return;
+
   ::Argv0 = Argv0;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
Index: llvm/lib/Support/Unix/Signals.inc
===================================================================
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,6 +637,11 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
                                              bool DisableCrashReporting) {
+  // If ::Argv0 is non-empty, then this function has already been called and
+  // there's no need to initialize the error handling again.
+  if (!::Argv0.empty())
+    return;
+
   ::Argv0 = Argv0;
 
   AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
Index: lldb/source/API/SystemInitializerFull.cpp
===================================================================
--- lldb/source/API/SystemInitializerFull.cpp
+++ lldb/source/API/SystemInitializerFull.cpp
@@ -18,6 +18,7 @@
 #include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/Timer.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 
 #pragma clang diagnostic push
@@ -53,6 +54,12 @@
   if (error)
     return error;
 
+  // On Windows certain functions from Signals.h require that the global state
+  // is initialized. For LLDB driver the initialization happens in the `main`
+  // function via the `llvm::InitLLVM` helper, but for LLDB dynamic library
+  // (liblldb) that doesn't happen.
+  llvm::sys::PrintStackTraceOnErrorSignal(/*Argv0=*/{});
+
   // Initialize LLVM and Clang
   llvm::InitializeAllTargets();
   llvm::InitializeAllAsmPrinters();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119009.406487.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220207/35ad99b5/attachment-0001.bin>


More information about the lldb-commits mailing list