werat updated this revision to Diff 406480. werat added a comment. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Call `sys::PrintStackTraceOnErrorSignal()` in `SBDebugger::Initialize()`. 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,11 @@ /// process, print a stack trace and then exit. void sys::PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting) { - ::Argv0 = Argv0; + // This function may get called multiple times and some of the calls might + // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the + // provided value is non-empty. + if (!Argv0.empty()) + ::Argv0 = Argv0; if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) Process::PreventCoreFiles(); Index: llvm/lib/Support/Unix/Signals.inc =================================================================== --- llvm/lib/Support/Unix/Signals.inc +++ llvm/lib/Support/Unix/Signals.inc @@ -637,7 +637,11 @@ /// process, print a stack trace and then exit. void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting) { - ::Argv0 = Argv0; + // This function may get called multiple times and some of the calls might + // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the + // provided value is non-empty. + if (!Argv0.empty()) + ::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();
Index: llvm/lib/Support/Windows/Signals.inc =================================================================== --- llvm/lib/Support/Windows/Signals.inc +++ llvm/lib/Support/Windows/Signals.inc @@ -504,7 +504,11 @@ /// process, print a stack trace and then exit. void sys::PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting) { - ::Argv0 = Argv0; + // This function may get called multiple times and some of the calls might + // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the + // provided value is non-empty. + if (!Argv0.empty()) + ::Argv0 = Argv0; if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) Process::PreventCoreFiles(); Index: llvm/lib/Support/Unix/Signals.inc =================================================================== --- llvm/lib/Support/Unix/Signals.inc +++ llvm/lib/Support/Unix/Signals.inc @@ -637,7 +637,11 @@ /// process, print a stack trace and then exit. void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting) { - ::Argv0 = Argv0; + // This function may get called multiple times and some of the calls might + // have empty (aka unknown) Argv0. Overwrite global ::Argv0 only if the + // provided value is non-empty. + if (!Argv0.empty()) + ::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();
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits