Re: [PATCH 00/30] Stop throwing exceptions from signal handlers

Simon Marchi
2016-03-21T19:52:20Z

On 16-03-18 03:18 PM, Pedro Alves wrote:
> Aka, get rid of immediate_quit.
>
> Throwing exceptions from signal handlers is undefined C++. So for C++
> conversion we need to replace the immediate_quit mechanism by
> something else.
>
> This series:
>
> - Replaces all immediate_quit uses with something else.
>
> - Removes a few custom SIGINT handlers, centralizing more on the
> "quit" flag and GDB's default SIGINT handler.
>
> - Fixes several classical signal handler / mainline code races, using
> the self-pipe trick.
>
> - Introduces a "struct serial_event" abstraction to hide the self-pipe
> trick -- on Windows we don't use pipes at all, and on Linux, we
> could use eventfd (but I didn't do that, at least yet).
>
> - Stumbles on a few bogus clear_quit_flag uses, and thus completely
> eliminates it, for good measure.
>
> - Decouples target_interrupt from all-stop/non-stop modes
>
> - Fixes a few cases of indefinitely-delayed Ctrl-C handling.
>
> - Fixes/incorrect handling of EINTR in ser-*.c backends
>
> - Goes through the tree fixing all target_terminal_ours calls that
> should be target_terminal_ours_for_output instead. We only end up
> with a few target_terminal_ours calls, at places were we need to
> handle input.
>
> - Plugs a few leaks along the way.
>
> - Fixes a bug where you can't answer y/n to an internal error if the
> target has the terminal.
>
> - Introduces the concept of quit handlers.
>
> - Does a few clean ups along the way.
>
> Tested on x86-64 Fedora 23, native and gdbserver.
>
> A slightly older version manually test on mingw64/Windows 7, to make
> sure Ctrl-C still works as expected there.
>
> This applies on top of the "target mips" elimination patch:
> https://sourceware.org/ml/gdb-patches/2016-03/msg00313.html
>
> I've pushed the whole series to users/palves/immediate_quit.
>
> Pedro Alves (30):
> Don't rely on immediate_quit in command_line_input
> Inline command_loop in read_command_line
> TUI: check whether in secondary prompt instead of immediate_quit
> Don't set immediate_quit in prompt_for_continue
> Stop remote-fileio.c from throwing from SIGINT handler
> Remove unused struct serial::name field
> Introduce a serial interface for select'able events
> Fix signal handler/event-loop races
> Introduce interruptible_select
> Make Python use a struct serial event
> Don't call clear_quit_flag after check_quit_flag
> Don't call clear_quit_flag in command_handler
> Don't call clear_quit_flag in prepare_to_throw_exception
> Don't call clear_quit_flag in captured_main
> Eliminate clear_quit_flag
> Decouple target_interrupt from all-stop/non-stop modes
> Pass Ctrl-C to the target in target_terminal_inferior
> Fix inconsistent handling of EINTR in ser-*.c backends
> ada-lang.c: Introduce type_as_string and use it
> Use target_terminal_ours_for_output in cp-support.c
> Use target_terminal_ours_for_output in exceptions.c
> Use target_terminal_ours_for_output in infcmd.c
> Use target_terminal_ours_for_output in warning/internal_error
> Add missing cleanups to defaulted_query and prompt_for_continue
> Do target_terminal_ours in query & friends instead of in all callers
> Use target_terminal_ours_for_output in MI
> TUI: GC tui_target_has_run
> target remote: Don't rely on immediate_quit (introduce quit handlers)
> Eliminate immediate_quit
> Eliminate target_check_pending_interrupt
>
> gdb/Makefile.in | 6 +-
> gdb/ada-lang.c | 74 ++++++-----
> gdb/cp-support.c | 4 +-
> gdb/defs.h | 58 +++++++--
> gdb/event-loop.c | 41 ++++--
> gdb/event-loop.h | 26 +---
> gdb/event-top.c | 165 ++++++++++++++++++++++---
> gdb/exceptions.c | 17 ++-
> gdb/extension-priv.h | 5 +-
> gdb/extension.c | 34 +++--
> gdb/gdb_select.h | 15 +++
> gdb/gnu-nat.c | 12 +-
> gdb/guile/guile.c | 1 -
> gdb/guile/scm-ports.c | 4 +-
> gdb/i386-tdep.c | 49 ++------
> gdb/infcmd.c | 10 +-
> gdb/linux-nat.c | 10 --
> gdb/linux-record.c | 54 +++-----
> gdb/main.c | 1 -
> gdb/mi/mi-interp.c | 125 ++++++++++++++++---
> gdb/mi/mi-main.c | 7 +-
> gdb/mingw-hdep.c | 52 +-------
> gdb/nto-procfs.c | 4 -
> gdb/posix-hdep.c | 13 --
> gdb/python/python.c | 44 +++----
> gdb/record-full.c | 22 ++--
> gdb/remote-fileio.c | 34 +----
> gdb/remote-sim.c | 5 +-
> gdb/remote.c | 329 +++++++++++++++++++++----------------------------
> gdb/ser-base.c | 30 ++++-
> gdb/ser-event.c | 220 +++++++++++++++++++++++++++++++++
> gdb/ser-event.h | 51 ++++++++
> gdb/ser-go32.c | 4 +
> gdb/ser-unix.c | 108 ++--------------
> gdb/serial.c | 66 ++++++----
> gdb/serial.h | 8 +-
> gdb/target-delegates.c | 25 ++--
> gdb/target.c | 17 ++-
> gdb/target.h | 19 +--
> gdb/top.c | 67 +++++-----
> gdb/tui/tui-hooks.c | 24 ----
> gdb/tui/tui-io.c | 2 +-
> gdb/tui/tui.c | 4 +-
> gdb/ui-file.c | 8 +-
> gdb/utils.c | 66 ++++++----
> 45 files changed, 1115 insertions(+), 825 deletions(-)
> create mode 100644 gdb/ser-event.c
> create mode 100644 gdb/ser-event.h
>

I went over the series, and I understood some of the words used. What I understood
looked very good. For the rest, I trust you are doing the right thing. :)

Thanks a lot for doing this, since this is the major roadblock before we can't start
using C++!