[Lldb-commits] [lldb] ee2d9b8 - [lldb] Add Python bindings to print stack traces on crashes.
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 7 11:21:07 PDT 2022
Author: Jonas Devlieghere
Date: 2022-04-07T11:21:02-07:00
New Revision: ee2d9b8723561fb6a81b9c2c4fd7a93300c6154f
URL: https://github.com/llvm/llvm-project/commit/ee2d9b8723561fb6a81b9c2c4fd7a93300c6154f
DIFF: https://github.com/llvm/llvm-project/commit/ee2d9b8723561fb6a81b9c2c4fd7a93300c6154f.diff
LOG: [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
Added:
Modified:
lldb/bindings/interface/SBDebugger.i
lldb/include/lldb/API/SBDebugger.h
lldb/packages/Python/lldbsuite/test/dotest.py
lldb/source/API/SBDebugger.cpp
Removed:
################################################################################
diff --git a/lldb/bindings/interface/SBDebugger.i b/lldb/bindings/interface/SBDebugger.i
index e9a6168d0c093..2239f049c6514 100644
--- a/lldb/bindings/interface/SBDebugger.i
+++ b/lldb/bindings/interface/SBDebugger.i
@@ -141,6 +141,8 @@ public:
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
index 0893bc60315e6..6a23077175b92 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -92,6 +92,8 @@ class LLDB_API SBDebugger {
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
index 5cf75391d8440..489e6ce7bd7a1 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -880,6 +880,7 @@ def run_suite():
import lldb
lldb.SBDebugger.Initialize()
+ lldb.SBDebugger.PrintStackTraceOnError()
checkLibcxxSupport()
checkLibstdcxxSupport()
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 3391665786d56..4d92a0a9b2805 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -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();
More information about the lldb-commits
mailing list