From 3f75a984d27da2801a9c4237b2b40917c68d6f19 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 1 Mar 2023 16:48:36 -0500 Subject: 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 --- gdb/cli/cli-interp.c | 17 +++-------------- gdb/cli/cli-interp.h | 2 ++ 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 84fe34a..51c78d9 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -137,19 +137,10 @@ cli_base_on_normal_stop (struct bpstat *bs, int print_frame) } } -/* Observer for the signal_received notification. */ - -static void -cli_base_on_signal_received (enum gdb_signal siggnal) +void +cli_interp_base::on_signal_received (enum gdb_signal siggnal) { - SWITCH_THRU_ALL_UIS () - { - cli_interp_base *cli = as_cli_interp_base (top_level_interpreter ()); - if (cli == nullptr) - continue; - - print_signal_received_reason (cli->interp_ui_out (), siggnal); - } + print_signal_received_reason (this->interp_ui_out (), siggnal); } /* Observer for the signalled notification. */ @@ -408,8 +399,6 @@ _initialize_cli_interp () /* Note these all work for both the CLI and TUI interpreters. */ gdb::observers::normal_stop.attach (cli_base_on_normal_stop, "cli-interp-base"); - gdb::observers::signal_received.attach (cli_base_on_signal_received, - "cli-interp-base"); gdb::observers::signal_exited.attach (cli_base_on_signal_exited, "cli-interp-base"); gdb::observers::exited.attach (cli_base_on_exited, "cli-interp-base"); diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h index 5ed998f..f7bee45 100644 --- a/gdb/cli/cli-interp.h +++ b/gdb/cli/cli-interp.h @@ -33,6 +33,8 @@ public: void pre_command_loop () override; bool supports_command_editing () override; + void on_signal_received (gdb_signal sig) override; + private: struct saved_output_files { -- cgit v1.1