]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: register SIGBUS, SIGFPE, and SIGABRT handlers
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 18 Jun 2021 13:26:30 +0000 (14:26 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 11 Aug 2021 11:35:14 +0000 (12:35 +0100)
Register handlers for SIGBUS, SIGFPE, and SIGABRT.  All of these
signals are setup as fatal signals that will cause GDB to terminate.
However, by passing these signals through the handle_fatal_signal
function, a user can arrange to see a backtrace when GDB
terminates (see maint set backtrace-on-fatal-signal).

In normal use of GDB there should be no user visible changes after
this commit.  Only if GDB terminates with one of the above signals
will GDB change slightly, potentially printing a backtrace before
aborting.

I've added new tests for SIGFPE, SIGBUS, and SIGABRT.

gdb/event-top.c
gdb/testsuite/gdb.base/bt-on-fatal-signal.exp

index 210440ad80bfd2c7c564752a39a22fe90334a57e..9233a3650ac401e2b34637a556f96e8429f8c8ea 100644 (file)
@@ -1025,7 +1025,10 @@ static struct serial_event *quit_serial_event;
    with the reception of the signal.
 
    For SIGSEGV the handle_sig* function does all the work for handling this
-   signal.  */
+   signal.
+
+   For SIGFPE, SIGBUS, and SIGABRT, these signals will all cause GDB to
+   terminate immediately.  */
 void
 gdb_init_signals (void)
 {
@@ -1061,6 +1064,18 @@ gdb_init_signals (void)
     create_async_signal_handler (async_sigtstp_handler, NULL, "sigtstp");
 #endif
 
+#ifdef SIGFPE
+  signal (SIGFPE, handle_fatal_signal);
+#endif
+
+#ifdef SIGBUS
+  signal (SIGBUS, handle_fatal_signal);
+#endif
+
+#ifdef SIGABRT
+  signal (SIGABRT, handle_fatal_signal);
+#endif
+
   install_handle_sigsegv ();
 }
 
index 7a9f8e45fde346c8958dd530f503cc3d0aa246f2..8875d00fdb115926df3d54fc338d24ede2a47a49 100644 (file)
@@ -54,7 +54,10 @@ gdb_test_multiple "maint set backtrace-on-fatal-signal on" "" {
 }
 
 # Now the actual test loop.
-foreach test_data {{SEGV "Segmentation fault"}} {
+foreach test_data {{SEGV "Segmentation fault"} \
+                      {FPE "Floating point exception"} \
+                      {BUS "Bus error"} \
+                      {ABRT "Aborted"}} {
     set sig [lindex ${test_data} 0]
     set msg [lindex ${test_data} 1]
     with_test_prefix ${sig} {