diff --git a/lldb/bindings/interface/SBDebugger.i b/lldb/bindings/interface/SBDebugger.i --- a/lldb/bindings/interface/SBDebugger.i +++ b/lldb/bindings/interface/SBDebugger.i @@ -124,6 +124,8 @@ static SBError InitializeWithErrorHandling(); + static void PrintStackTraceOnError(); + static void Terminate(); diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -47,6 +47,8 @@ static lldb::SBError InitializeWithErrorHandling(); + static void PrintStackTraceOnError(); + static void Terminate(); // Deprecated, use the one that takes a source_init_files bool. diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -880,6 +880,9 @@ lldbconfig.INITIALIZE = False import lldb + # Print stack traces from coming from inside lldb. + lldb.SBDebugger.PrintStackTraceOnError() + if configuration.capture_path: lldb.SBReproducer.Capture(configuration.capture_path) lldb.SBReproducer.SetAutoGenerate(True) diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -56,6 +56,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; @@ -166,6 +168,14 @@ return LLDB_RECORD_RESULT(error); } +void SBDebugger::PrintStackTraceOnError() { + LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, PrintStackTraceOnError); + 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_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Terminate);