public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Forced quit cases handled by resetting sync_quit_force_run
@ 2023-02-27 23:21 Kevin Buettner
0 siblings, 0 replies; only message in thread
From: Kevin Buettner @ 2023-02-27 23:21 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=96e3f4e3c32865fecdb266c2a41532337c75e316
commit 96e3f4e3c32865fecdb266c2a41532337c75e316
Author: Kevin Buettner <kevinb@redhat.com>
Date: Mon Feb 27 16:11:37 2023 -0700
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>
Diff:
---
gdb/linux-fork.c | 12 ++++++++++++
gdb/tui/tui-io.c | 8 ++++++++
gdb/tui/tui.c | 7 +++++++
3 files changed, 27 insertions(+)
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 61545b859ea..a6e74c0cb52 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -430,6 +430,18 @@ public:
fork_load_infrun_state (m_oldfp);
insert_breakpoints ();
}
+ catch (const gdb_exception_quit &ex)
+ {
+ /* We can't throw from a destructor, so re-set the quit flag
+ for later QUIT checking. */
+ set_quit_flag ();
+ }
+ catch (const gdb_exception_forced_quit &ex)
+ {
+ /* Like above, but (eventually) cause GDB to terminate by
+ setting sync_quit_force_run. */
+ set_force_quit_flag ();
+ }
catch (const gdb_exception &ex)
{
warning (_("Couldn't restore checkpoint state in %s: %s"),
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index a17cf38a1f2..7752701378e 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -1271,6 +1271,14 @@ tui_getc (FILE *fp)
{
return tui_getc_1 (fp);
}
+ catch (const gdb_exception_forced_quit &ex)
+ {
+ /* As noted below, it's not safe to let an exception escape
+ to newline, so, for this case, reset the quit flag for
+ later QUIT checking. */
+ set_force_quit_flag ();
+ return 0;
+ }
catch (const gdb_exception &ex)
{
/* Just in case, don't ever let an exception escape to readline.
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index cdae9ffe02b..3604194a760 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -122,6 +122,13 @@ tui_rl_switch_mode (int notused1, int notused2)
tui_enable ();
}
}
+ catch (const gdb_exception_forced_quit &ex)
+ {
+ /* Ideally, we'd do a 'throw' here, but as noted above, we can't
+ do that, so, instead, we'll set the necessary flags so that
+ a later QUIT check will restart the forced quit. */
+ set_force_quit_flag ();
+ }
catch (const gdb_exception &ex)
{
exception_print (gdb_stderr, ex);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-27 23:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 23:21 [binutils-gdb] Forced quit cases handled by resetting sync_quit_force_run Kevin Buettner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).