diff mbox series

[committed] libphobos: Print stacktrace before terminating program due to uncaught exception.

Message ID 20210930164341.2838182-1-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] libphobos: Print stacktrace before terminating program due to uncaught exception. | expand

Commit Message

Iain Buclaw Sept. 30, 2021, 4:43 p.m. UTC
Hi,

This patch adds adjusts the `throw' entrypoint to print the stacktrace
of an uncaught exception before terminating.

By default, D run-time has a top level exception handler to catch
anything that was uncaught by user code.  However when the
`rt_trapExceptions' flag is cleared, this handler would not be enabled,
and this termination would occur, aborting the program, but without any
information about the exception.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
committed to mainline.

Regards
Iain

---
libphobos/ChangeLog:

	* libdruntime/gcc/deh.d (_d_print_throwable): Declare.
	(_d_throw): Print stacktrace before terminating program due to
	uncaught exception.
---
 libphobos/libdruntime/gcc/deh.d | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/libphobos/libdruntime/gcc/deh.d b/libphobos/libdruntime/gcc/deh.d
index eb83751c59d..a7eb37cfd9e 100644
--- a/libphobos/libdruntime/gcc/deh.d
+++ b/libphobos/libdruntime/gcc/deh.d
@@ -34,6 +34,7 @@  extern(C)
 {
     int _d_isbaseof(ClassInfo, ClassInfo);
     void _d_createTrace(Object, void*);
+    void _d_print_throwable(Throwable t);
 }
 
 /**
@@ -510,7 +511,11 @@  extern(C) void _d_throw(Throwable object)
     // things, almost certainly we will have crashed before now, rather than
     // actually being able to diagnose the problem.
     if (r == _URC_END_OF_STACK)
+    {
+        __gdc_begin_catch(&eh.unwindHeader);
+        _d_print_throwable(object);
         terminate("uncaught exception", __LINE__);
+    }
 
     terminate("unwind error", __LINE__);
 }