diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-06-10 10:44:43 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-08-11 12:35:14 +0100 |
commit | fb550a919a88bf4e3950dd7bcdf72f0a18d94206 (patch) | |
tree | c4f38846c2e5e1e9907588656ca923d08f36405b /gdb | |
parent | cc9faa98adc96788e6a560c685bbd8e69c856cb7 (diff) | |
download | binutils-fb550a919a88bf4e3950dd7bcdf72f0a18d94206.zip binutils-fb550a919a88bf4e3950dd7bcdf72f0a18d94206.tar.gz binutils-fb550a919a88bf4e3950dd7bcdf72f0a18d94206.tar.bz2 |
gdb: terminate upon receipt of SIGFPE
GDB's SIGFPE handling is broken, this is PR gdb/16505 and
PR gdb/17891.
We currently try to use an async event token to process SIGFPE. So,
when a SIGFPE arrives the signal handler calls
mark_async_signal_handler then returns, effectively ignoring the
signal (for now).
The intention is that later the event loop will see that the async
token associated with SIGFPE has been marked and will call the async
handler, which just throws an error.
The problem is that SIGFPE is not safe to ignore. Ignoring a
SIGFPE (unless it is generated artificially, e.g. by raise()) is
undefined behaviour, after ignoring the signal on many targets we
return to the instruction that caused the SIGFPE to be raised, which
immediately causes another SIGFPE to be raised, we get stuck in an
infinite loop. The behaviour is certainly true on x86-64.
To view this behaviour I simply added some dummy code to GDB that
performed an integer divide by zero, compiled this on x86-64
GNU/Linux, ran GDB and saw GDB hang.
In this commit, I propose to remove all special handling of SIGFPE and
instead just let GDB make use of the default SIGFPE action, that is,
to terminate the process.
The only user visible change here should be:
- If a user sends a SIGFPE to GDB using something like kill,
previously GDB would just print an error and remain alive, now GDB
will terminate. This is inline with what happens if the user
sends GDB a SIGSEGV from kill though, so I don't see this as an
issue.
- If a bug in GDB causes a real SIGFPE, previously the users GDB
session would hang. Now the GDB session will terminate. Again,
this is inline with what happens if GDB receives a SIGSEGV due to
an internal bug.
In bug gdb/16505 there is mention that it would be nice if GDB did
more than just terminate when receiving a fatal signal. I haven't
done that in this commit, but later commits will move in that
direction.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16505
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17891
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/event-top.c | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c index 002a7dc..ab5179b 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -58,7 +58,6 @@ static void handle_sigquit (int sig); #ifdef SIGHUP static void handle_sighup (int sig); #endif -static void handle_sigfpe (int sig); /* Functions to be invoked by the event loop in response to signals. */ @@ -68,7 +67,6 @@ static void async_do_nothing (gdb_client_data); #ifdef SIGHUP static void async_disconnect (gdb_client_data); #endif -static void async_float_handler (gdb_client_data); #ifdef SIGTSTP static void async_sigtstp_handler (gdb_client_data); #endif @@ -111,7 +109,6 @@ static struct async_signal_handler *sighup_token; #ifdef SIGQUIT static struct async_signal_handler *sigquit_token; #endif -static struct async_signal_handler *sigfpe_token; #ifdef SIGTSTP static struct async_signal_handler *sigtstp_token; #endif @@ -904,7 +901,7 @@ static struct serial_event *quit_serial_event; /* Initialization of signal handlers and tokens. There is a function handle_sig* for each of the signals GDB cares about. Specifically: - SIGINT, SIGFPE, SIGQUIT, SIGTSTP, SIGHUP, SIGWINCH. These + SIGINT, SIGQUIT, SIGTSTP, SIGHUP, SIGWINCH. These functions are the actual signal handlers associated to the signals via calls to signal(). The only job for these functions is to enqueue the appropriate event/procedure with the event loop. Such @@ -955,9 +952,6 @@ async_init_signals (void) sighup_token = create_async_signal_handler (async_do_nothing, NULL, "sighup"); #endif - signal (SIGFPE, handle_sigfpe); - sigfpe_token = - create_async_signal_handler (async_float_handler, NULL, "sigfpe"); #ifdef SIGTSTP sigtstp_token = @@ -1198,23 +1192,6 @@ async_sigtstp_handler (gdb_client_data arg) } #endif /* SIGTSTP */ -/* Tell the event loop what to do if SIGFPE is received. - See event-signal.c. */ -static void -handle_sigfpe (int sig) -{ - mark_async_signal_handler (sigfpe_token); - signal (sig, handle_sigfpe); -} - -/* Event loop will call this function to process a SIGFPE. */ -static void -async_float_handler (gdb_client_data arg) -{ - /* This message is based on ANSI C, section 4.7. Note that integer - divide by zero causes this, so "float" is a misnomer. */ - error (_("Erroneous arithmetic operation.")); -} /* Set things up for readline to be invoked via the alternate |