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/interps.c | |
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/interps.c')
-rw-r--r-- | gdb/interps.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/interps.c b/gdb/interps.c index e3f6ee6..5d061ad 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -383,6 +383,29 @@ current_interpreter (void) return current_ui->current_interpreter; } +/* Helper interps_notify_* functions. Call METHOD on the top-level interpreter + of all UIs. */ + +template <typename ...Args> +void +interps_notify (void (interp::*method) (Args...), Args... args) +{ + SWITCH_THRU_ALL_UIS () + { + interp *tli = top_level_interpreter (); + if (tli != nullptr) + (tli->*method) (args...); + } +} + +/* See interps.h. */ + +void +interps_notify_signal_received (gdb_signal sig) +{ + interps_notify (&interp::on_signal_received, sig); +} + /* This just adds the "interpreter-exec" command. */ void _initialize_interpreter (); void |