Forced quit cases handled by resetting sync_quit_force_run
authorKevin Buettner <kevinb@redhat.com>
Mon, 27 Feb 2023 23:11:37 +0000 (16:11 -0700)
committerKevin Buettner <kevinb@redhat.com>
Mon, 27 Feb 2023 23:20:39 +0000 (16:20 -0700)
commit96e3f4e3c32865fecdb266c2a41532337c75e316
tree1c72d7b954b7b0119b98a39a29c758739284c62e
parent80d03917838c16ee0da53a4a8642d5df3bee724e
Forced quit cases handled by resetting sync_quit_force_run

During my audit of the use of gdb_exception with regard to QUIT
processing, I found a try/catch in the scoped_switch_fork_info
destructor.

Static analysis found this call path from the destructor to
maybe_quit():

  scoped_switch_fork_info::~scoped_switch_fork_info()
    -> remove_breakpoints()
    -> remove_breakpoint(bp_location*)
    -> remove_breakpoint_1(bp_location*, remove_bp_reason)
    -> memory_validate_breakpoint(gdbarch*, bp_target_info*)
    -> target_read_memory(unsigned long, unsigned char*, long)
    -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long)
    -> maybe_quit()

Since it's not safe to do a 'throw' from a destructor, we simply
call set_quit_flag and, for gdb_exception_forced_quit, also
set sync_quit_force_run.  This will cause the appropriate
exception to be rethrown at the next QUIT check.

Another case is the try / catch in tui_getc() in tui-io.c.  The
existing catch swallows the exception.  I've added a catch for
'gdb_exception_forced_quit', which also swallows the exception,
but also sets sync_quit_force_run and calls set_quit_flag in
order to restart forced quit processing at the next QUIT check.
This is required because it isn't safe to throw into/through
readline.

Thanks to Pedro Alves for suggesting this idea.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761
Tested-by: Tom de Vries <tdevries@suse.de>
Approved-By: Pedro Alves <pedro@palves.net>
gdb/linux-fork.c
gdb/tui/tui-io.c
gdb/tui/tui.c