[Lldb-commits] [PATCH] D91835: [lldb] Add Python bindings to print stack traces on crashes.

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 7 11:21:11 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGee2d9b872356: [lldb] Add Python bindings to print stack traces on crashes. (authored by JDevlieghere).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91835/new/

https://reviews.llvm.org/D91835

Files:
  lldb/bindings/interface/SBDebugger.i
  lldb/include/lldb/API/SBDebugger.h
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/API/SBDebugger.cpp


Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ 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 @@
   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();
 
Index: lldb/packages/Python/lldbsuite/test/dotest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/dotest.py
+++ lldb/packages/Python/lldbsuite/test/dotest.py
@@ -880,6 +880,7 @@
 
     import lldb
     lldb.SBDebugger.Initialize()
+    lldb.SBDebugger.PrintStackTraceOnError()
 
     checkLibcxxSupport()
     checkLibstdcxxSupport()
Index: lldb/include/lldb/API/SBDebugger.h
===================================================================
--- lldb/include/lldb/API/SBDebugger.h
+++ lldb/include/lldb/API/SBDebugger.h
@@ -92,6 +92,8 @@
 
   static lldb::SBError InitializeWithErrorHandling();
 
+  static void PrintStackTraceOnError();
+
   static void Terminate();
 
   // Deprecated, use the one that takes a source_init_files bool.
Index: lldb/bindings/interface/SBDebugger.i
===================================================================
--- lldb/bindings/interface/SBDebugger.i
+++ lldb/bindings/interface/SBDebugger.i
@@ -141,6 +141,8 @@
     static SBError
     InitializeWithErrorHandling();
 
+    static void PrintStackTraceOnError();
+
     static void
     Terminate();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91835.421295.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220407/e7bf1101/attachment.bin>


More information about the lldb-commits mailing list