diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-03-01 16:48:36 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-05-30 15:07:26 -0400 |
commit | 3f75a984d27da2801a9c4237b2b40917c68d6f19 (patch) | |
tree | 59968832cd95ee956927f94c2e6649214f3a81ff /gdb/mi | |
parent | 37d9880d653c1d91e763c6b6ab22c28883996447 (diff) | |
download | gdb-3f75a984d27da2801a9c4237b2b40917c68d6f19.zip gdb-3f75a984d27da2801a9c4237b2b40917c68d6f19.tar.gz gdb-3f75a984d27da2801a9c4237b2b40917c68d6f19.tar.bz2 |
gdb: add interp::on_signal_received method
Instead of having the interpreter code registering observers for the
signal_received observable, add a "signal_received" virtual method to
struct interp. Add a interps_notify_signal_received function that loops
over all UIs and calls the signal_received method on the interpreter.
Finally, add a notify_signal_received function that calls
interps_notify_signal_received and then notifies the observers. Replace
all existing notifications to the signal_received observers with calls
to notify_signal_received.
Before this patch, the CLI and MI code both register a signal_received
observer. These observer go over all UIs, and, for those that have a
interpreter of the right kind, print the stop notifiation.
After this patch, we have just one "loop over all UIs", inside
interps_notify_signal_received. Since the interp::on_signal_received
method gets called once for each interpreter, the implementations only
need to deal with the current interpreter (the "this" pointer).
The motivation for this patch comes from a future patch, that makes the
amdgpu code register an observer to print a warning after the CLI's
signal stop message. Since the amdgpu and the CLI code both use
observers, the order of the two messages is not stable, unless we define
the priority using the observer dependency system. However, the
approach of using virtual methods on the interpreters seems like a good
change anyway, I think it's more straightforward and simple to
understand than the current solution that uses observers. We are sure
that the amdgpu message gets printed after the CLI message, since
observers are notified after interpreters.
Keep the signal_received, even if nothing uses if, because we will be
using it in the upcoming amdgpu patch implementing the warning described
above.
Change-Id: I4d8614bb8f6e0717f4bfc2a59abded3702f23ac4
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/mi-interp.c | 20 | ||||
-rw-r--r-- | gdb/mi/mi-interp.h | 2 |
2 files changed, 6 insertions, 16 deletions
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index d8b49ae..b77494e 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -60,7 +60,6 @@ static int mi_interp_query_hook (const char *ctlstr, va_list ap) static void mi_insert_notify_hooks (void); static void mi_remove_notify_hooks (void); -static void mi_on_signal_received (enum gdb_signal siggnal); static void mi_on_signal_exited (enum gdb_signal siggnal); static void mi_on_exited (int exitstatus); static void mi_on_normal_stop (struct bpstat *bs, int print_frame); @@ -525,21 +524,11 @@ find_mi_interp (void) inferior has stopped to both the MI event channel and to the MI console. If the MI interpreter is not active, print nothing. */ -/* Observer for the signal_received notification. */ - -static void -mi_on_signal_received (enum gdb_signal siggnal) +void +mi_interp::on_signal_received (enum gdb_signal siggnal) { - SWITCH_THRU_ALL_UIS () - { - struct mi_interp *mi = find_mi_interp (); - - if (mi == NULL) - continue; - - print_signal_received_reason (mi->mi_uiout, siggnal); - print_signal_received_reason (mi->cli_uiout, siggnal); - } + print_signal_received_reason (this->mi_uiout, siggnal); + print_signal_received_reason (this->cli_uiout, siggnal); } /* Observer for the signal_exited notification. */ @@ -1304,7 +1293,6 @@ _initialize_mi_interp () interp_factory_register (INTERP_MI4, mi_interp_factory); interp_factory_register (INTERP_MI, mi_interp_factory); - gdb::observers::signal_received.attach (mi_on_signal_received, "mi-interp"); gdb::observers::signal_exited.attach (mi_on_signal_exited, "mi-interp"); gdb::observers::exited.attach (mi_on_exited, "mi-interp"); gdb::observers::no_history.attach (mi_on_no_history, "mi-interp"); diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h index eb81cbe..a8fd7b6 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -42,6 +42,8 @@ public: bool debug_redirect) override; void pre_command_loop () override; + void on_signal_received (gdb_signal sig) override; + /* MI's output channels */ mi_console_file *out; mi_console_file *err; |