[lldb] Add Python bindings to print stack traces on crashes.

As noticed in D87637, when LLDB crashes, we only print stack traces if
LLDB is directly executed, not when used via Python bindings. Enabling
this by default may be undesirable (libraries shouldn't be messing with
signal handlers), so make this an explicit opt-in.

I "commandeered" this patch from Jordan Rupprecht who put this up for
review originally.

Differential revision: https://reviews.llvm.org/D91835
This commit is contained in:
Jonas Devlieghere 2022-04-07 11:12:09 -07:00
parent 50de659adc
commit ee2d9b8723
No known key found for this signature in database
GPG key ID: 49CC0BD90FDEED4D
4 changed files with 16 additions and 0 deletions

View file

@ -141,6 +141,8 @@ public:
static SBError
InitializeWithErrorHandling();
static void PrintStackTraceOnError();
static void
Terminate();

View file

@ -92,6 +92,8 @@ public:
static lldb::SBError InitializeWithErrorHandling();
static void PrintStackTraceOnError();
static void Terminate();
// Deprecated, use the one that takes a source_init_files bool.

View file

@ -880,6 +880,7 @@ def run_suite():
import lldb
lldb.SBDebugger.Initialize()
lldb.SBDebugger.PrintStackTraceOnError()
checkLibcxxSupport()
checkLibstdcxxSupport()

View file

@ -57,6 +57,8 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
using namespace lldb;
using namespace lldb_private;
@ -206,6 +208,15 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() {
return error;
}
void SBDebugger::PrintStackTraceOnError() {
LLDB_INSTRUMENT();
llvm::EnablePrettyStackTrace();
// We don't have a meaningful argv[0] to use, so use "SBDebugger" as a
// substitute.
llvm::sys::PrintStackTraceOnErrorSignal("SBDebugger");
}
void SBDebugger::Terminate() {
LLDB_INSTRUMENT();