[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:57:25 PST 2022


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

Revert accidental formatting changes


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,7 +504,10 @@
 /// process, print a stack trace and then exit.
 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
                                        bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // 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;
 
   if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
     Process::PreventCoreFiles();
@@ -554,7 +557,9 @@
 
 void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
   // FIXME: Handle "Depth" parameter to print stack trace upto specified Depth
+  RegisterHandler();
   LocalPrintStackTrace(OS, nullptr);
+  LeaveCriticalSection(&CriticalSection);
 }
 
 void llvm::sys::SetInterruptFunction(void (*IF)()) {
Index: llvm/lib/Support/Unix/Signals.inc
===================================================================
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -637,7 +637,10 @@
 /// process, print a stack trace and then exit.
 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
                                              bool DisableCrashReporting) {
-  ::Argv0 = Argv0;
+  // 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;
 
   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.406484.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220207/0dbbd554/attachment.bin>


More information about the lldb-commits mailing list