diff options
author | Tom Tromey <tromey@adacore.com> | 2022-12-05 10:56:23 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-12-13 12:51:53 -0700 |
commit | c88afe9cf5d7fb0bd878acb930d79aafcf182505 (patch) | |
tree | aa074a83270492bc86695706e82b322d67ab34b8 /gdb/posix-hdep.c | |
parent | c1dc47f53cccf633f3079db25a5b41adaee940a8 (diff) | |
download | fsf-binutils-gdb-c88afe9cf5d7fb0bd878acb930d79aafcf182505.zip fsf-binutils-gdb-c88afe9cf5d7fb0bd878acb930d79aafcf182505.tar.gz fsf-binutils-gdb-c88afe9cf5d7fb0bd878acb930d79aafcf182505.tar.bz2 |
Fix control-c handling on Windows
As Hannes pointed out, the Windows target-async patches broke C-c
handling there. Looking into this, I found a few oddities, fixed
here.
First, windows_nat_target::interrupt calls GenerateConsoleCtrlEvent.
I think this event can be ignored by the inferior, so it's not a great
way to interrupt. Instead, using DebugBreakProcess (or a more
complicated thing for Wow64) seems better.
Second, windows_nat_target did not implement the pass_ctrlc method.
Implementing this lets us remove the special code to call
SetConsoleCtrlHandler and instead integrate into gdb's approach to C-c
handling. I believe that this should also fix the race that's
described in the comment that's being removed.
Initially, I thought a simpler version of this patch would work.
However, I think what happens is that some other library (I'm not sure
what) calls SetConsoleCtrlHandler while gdb is running, and this
intercepts and handles C-c -- so that the gdb SIGINT handler is not
called. C-break continues to work, presumably because whatever
handler is installed ignores it.
This patch works around this issue by ensuring that the gdb handler
always comes first.
Diffstat (limited to 'gdb/posix-hdep.c')
-rw-r--r-- | gdb/posix-hdep.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c index 2621197..eddf73f 100644 --- a/gdb/posix-hdep.c +++ b/gdb/posix-hdep.c @@ -21,6 +21,7 @@ #include "gdbsupport/event-loop.h" #include "gdbsupport/gdb_select.h" #include "inferior.h" +#include <signal.h> /* Wrapper for select. Nothing special needed on POSIX platforms. */ @@ -56,3 +57,26 @@ sharing_input_terminal (int pid) return TRIBOOL_UNKNOWN; #endif } + +/* Current C-c handler. */ +static c_c_handler_ftype *current_handler; + +/* A wrapper that reinstalls the current signal handler. */ +static void +handler_wrapper (int num) +{ + signal (num, handler_wrapper); + if (current_handler != SIG_IGN) + current_handler (num); +} + +/* See inferior.h. */ + +c_c_handler_ftype * +install_sigint_handler (c_c_handler_ftype *fn) +{ + signal (SIGINT, handler_wrapper); + c_c_handler_ftype *result = current_handler; + current_handler = fn; + return result; +} |