From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 50579385BAED; Fri, 24 Jun 2022 18:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50579385BAED Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Eliminate TUI/CLI observers duplication X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 86be3050a64c7317754b5682e1a2b6a91f4e3f03 X-Git-Newrev: 5227abd299c632f66505f827cd221fe4bd7f4d0d Message-Id: <20220624185141.50579385BAED@sourceware.org> Date: Fri, 24 Jun 2022 18:51:41 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 18:51:41 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5227abd299c6= 32f66505f827cd221fe4bd7f4d0d commit 5227abd299c632f66505f827cd221fe4bd7f4d0d Author: Pedro Alves Date: Wed Jun 22 17:03:50 2022 +0100 Eliminate TUI/CLI observers duplication =20 For historical reasons, the CLI and the TUI observers are basically exact duplicates, except for the downcast: =20 cli: struct cli_interp *cli =3D as_cli_interp (interp); tui: struct interp *tui =3D as_tui_interp (interp); =20 and how they get at the interpreter's ui_out: =20 cli: cli->cli_uiout tui: tui->interp_ui_out () =20 Since interp_ui_out() is a virtual method that also works for the CLI interpreter, and, both the CLI and the TUI interpreters inherit from the same base class (cli_interp_base), we can convert the CLI observers to cast to cli_interp_base instead and use interp_ui_out() too. With that, the CLI observers will work for the TUI interpreter as well. This lets us completely eliminate the TUI observers. That's what this commit does. =20 Change-Id: Iaf6cf12dfa200ed3ab203a895a72b69dfedbd6e0 Diff: --- gdb/cli/cli-interp.c | 127 +++++++++++++++++----------------- gdb/tui/tui-interp.c | 190 +----------------------------------------------= ---- 2 files changed, 64 insertions(+), 253 deletions(-) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index fe9e4b43f14..036bc723b24 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -70,13 +70,13 @@ cli_interp::~cli_interp () /* Suppress notification struct. */ struct cli_suppress_notification cli_suppress_notification; =20 -/* Returns the INTERP's data cast as cli_interp if INTERP is a CLI, - and returns NULL otherwise. */ +/* Returns the INTERP's data cast as cli_interp_base if INTERP is a + console-like interpreter, and returns NULL otherwise. */ =20 -static struct cli_interp * -as_cli_interp (struct interp *interp) +static cli_interp_base * +as_cli_interp_base (interp *interp) { - return dynamic_cast (interp); + return dynamic_cast (interp); } =20 /* Longjmp-safe wrapper for "execute_command". */ @@ -117,12 +117,13 @@ should_print_stop_to_console (struct interp *console_= interp, =20 /* Observers for several run control events. If the interpreter is quiet (i.e., another interpreter is being run with - interpreter-exec), print nothing. */ + interpreter-exec), print nothing. These are named "cli_base" as + they print to both CLI interpreters and TUI interpreters. */ =20 /* Observer for the normal_stop notification. */ =20 static void -cli_on_normal_stop (struct bpstat *bs, int print_frame) +cli_base_on_normal_stop (struct bpstat *bs, int print_frame) { if (!print_frame) return; @@ -134,106 +135,98 @@ cli_on_normal_stop (struct bpstat *bs, int print_fra= me) SWITCH_THRU_ALL_UIS () { struct interp *interp =3D top_level_interpreter (); - struct cli_interp *cli =3D as_cli_interp (interp); - struct thread_info *thread; - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (interp); + if (cli =3D=3D nullptr) continue; =20 - thread =3D inferior_thread (); + thread_info *thread =3D inferior_thread (); if (should_print_stop_to_console (interp, thread)) - print_stop_event (cli->cli_uiout); + print_stop_event (cli->interp_ui_out ()); } } =20 /* Observer for the signal_received notification. */ =20 static void -cli_on_signal_received (enum gdb_signal siggnal) +cli_base_on_signal_received (enum gdb_signal siggnal) { SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 - print_signal_received_reason (cli->cli_uiout, siggnal); + print_signal_received_reason (cli->interp_ui_out (), siggnal); } } =20 /* Observer for the end_stepping_range notification. */ =20 static void -cli_on_end_stepping_range (void) +cli_base_on_end_stepping_range () { SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 - print_end_stepping_range_reason (cli->cli_uiout); + print_end_stepping_range_reason (cli->interp_ui_out ()); } } =20 /* Observer for the signalled notification. */ =20 static void -cli_on_signal_exited (enum gdb_signal siggnal) +cli_base_on_signal_exited (enum gdb_signal siggnal) { SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 - print_signal_exited_reason (cli->cli_uiout, siggnal); + print_signal_exited_reason (cli->interp_ui_out (), siggnal); } } =20 /* Observer for the exited notification. */ =20 static void -cli_on_exited (int exitstatus) +cli_base_on_exited (int exitstatus) { SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 - print_exited_reason (cli->cli_uiout, exitstatus); + print_exited_reason (cli->interp_ui_out (), exitstatus); } } =20 /* Observer for the no_history notification. */ =20 static void -cli_on_no_history (void) +cli_base_on_no_history () { SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 - print_no_history_reason (cli->cli_uiout); + print_no_history_reason (cli->interp_ui_out ()); } } =20 /* Observer for the sync_execution_done notification. */ =20 static void -cli_on_sync_execution_done (void) +cli_base_on_sync_execution_done () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter ()); + if (cli =3D=3D nullptr) return; =20 display_gdb_prompt (NULL); @@ -242,11 +235,10 @@ cli_on_sync_execution_done (void) /* Observer for the command_error notification. */ =20 static void -cli_on_command_error (void) +cli_base_on_command_error () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter ()); + if (cli =3D=3D nullptr) return; =20 display_gdb_prompt (NULL); @@ -255,27 +247,26 @@ cli_on_command_error (void) /* Observer for the user_selected_context_changed notification. */ =20 static void -cli_on_user_selected_context_changed (user_selected_what selection) +cli_base_on_user_selected_context_changed (user_selected_what selection) { /* This event is suppressed. */ if (cli_suppress_notification.user_selected_context) return; =20 - thread_info *tp =3D inferior_ptid !=3D null_ptid ? inferior_thread () : = NULL; + thread_info *tp =3D inferior_ptid !=3D null_ptid ? inferior_thread () : = nullptr; =20 SWITCH_THRU_ALL_UIS () { - struct cli_interp *cli =3D as_cli_interp (top_level_interpreter ()); - - if (cli =3D=3D NULL) + cli_interp_base *cli =3D as_cli_interp_base (top_level_interpreter (= )); + if (cli =3D=3D nullptr) continue; =20 if (selection & USER_SELECTED_INFERIOR) - print_selected_inferior (cli->cli_uiout); + print_selected_inferior (cli->interp_ui_out ()); =20 - if (tp !=3D NULL + if (tp !=3D nullptr && ((selection & (USER_SELECTED_THREAD | USER_SELECTED_FRAME)))) - print_selected_thread_frame (cli->cli_uiout, selection); + print_selected_thread_frame (cli->interp_ui_out (), selection); } } =20 @@ -465,17 +456,21 @@ _initialize_cli_interp () { interp_factory_register (INTERP_CONSOLE, cli_interp_factory); =20 - /* If changing this, remember to update tui-interp.c as well. */ - gdb::observers::normal_stop.attach (cli_on_normal_stop, "cli-interp"); - gdb::observers::end_stepping_range.attach (cli_on_end_stepping_range, - "cli-interp"); - gdb::observers::signal_received.attach (cli_on_signal_received, "cli-int= erp"); - gdb::observers::signal_exited.attach (cli_on_signal_exited, "cli-interp"= ); - gdb::observers::exited.attach (cli_on_exited, "cli-interp"); - gdb::observers::no_history.attach (cli_on_no_history, "cli-interp"); - gdb::observers::sync_execution_done.attach (cli_on_sync_execution_done, - "cli-interp"); - gdb::observers::command_error.attach (cli_on_command_error, "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::end_stepping_range.attach (cli_base_on_end_stepping_rang= e, + "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"); + gdb::observers::no_history.attach (cli_base_on_no_history, "cli-interp-b= ase"); + gdb::observers::sync_execution_done.attach (cli_base_on_sync_execution_d= one, + "cli-interp-base"); + gdb::observers::command_error.attach (cli_base_on_command_error, + "cli-interp-base"); gdb::observers::user_selected_context_changed.attach - (cli_on_user_selected_context_changed, "cli-interp"); + (cli_base_on_user_selected_context_changed, "cli-interp-base"); } diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c index b4faede8ce6..1c4ffbbc3aa 100644 --- a/gdb/tui/tui-interp.c +++ b/gdb/tui/tui-interp.c @@ -53,15 +53,6 @@ public: ui_out *interp_ui_out () override; }; =20 -/* Returns the INTERP if the INTERP is a TUI, and returns NULL - otherwise. */ - -static tui_interp * -as_tui_interp (struct interp *interp) -{ - return dynamic_cast (interp); -} - /* Cleanup the tui before exiting. */ =20 static void @@ -72,171 +63,6 @@ tui_exit (void) tui_disable (); } =20 -/* Observers for several run control events. If the interpreter is - quiet (i.e., another interpreter is being run with - interpreter-exec), print nothing. */ - -/* Observer for the normal_stop notification. */ - -static void -tui_on_normal_stop (struct bpstat *bs, int print_frame) -{ - if (!print_frame) - return; - - /* This event is suppressed. */ - if (cli_suppress_notification.normal_stop) - return; - - SWITCH_THRU_ALL_UIS () - { - struct interp *interp =3D top_level_interpreter (); - struct interp *tui =3D as_tui_interp (interp); - struct thread_info *thread; - - if (tui =3D=3D NULL) - continue; - - thread =3D inferior_thread (); - if (should_print_stop_to_console (interp, thread)) - print_stop_event (tui->interp_ui_out ()); - } -} - -/* Observer for the signal_received notification. */ - -static void -tui_on_signal_received (enum gdb_signal siggnal) -{ - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - print_signal_received_reason (tui->interp_ui_out (), siggnal); - } -} - -/* Observer for the end_stepping_range notification. */ - -static void -tui_on_end_stepping_range (void) -{ - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - print_end_stepping_range_reason (tui->interp_ui_out ()); - } -} - -/* Observer for the signal_exited notification. */ - -static void -tui_on_signal_exited (enum gdb_signal siggnal) -{ - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - print_signal_exited_reason (tui->interp_ui_out (), siggnal); - } -} - -/* Observer for the exited notification. */ - -static void -tui_on_exited (int exitstatus) -{ - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - print_exited_reason (tui->interp_ui_out (), exitstatus); - } -} - -/* Observer for the no_history notification. */ - -static void -tui_on_no_history (void) -{ - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - print_no_history_reason (tui->interp_ui_out ()); - } -} - -/* Observer for the sync_execution_done notification. */ - -static void -tui_on_sync_execution_done (void) -{ - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - return; - - display_gdb_prompt (NULL); -} - -/* Observer for the command_error notification. */ - -static void -tui_on_command_error (void) -{ - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - return; - - display_gdb_prompt (NULL); -} - -/* Observer for the user_selected_context_changed notification. */ - -static void -tui_on_user_selected_context_changed (user_selected_what selection) -{ - /* This event is suppressed. */ - if (cli_suppress_notification.user_selected_context) - return; - - thread_info *tp =3D inferior_ptid !=3D null_ptid ? inferior_thread () : = NULL; - - SWITCH_THRU_ALL_UIS () - { - struct interp *tui =3D as_tui_interp (top_level_interpreter ()); - - if (tui =3D=3D NULL) - continue; - - if (selection & USER_SELECTED_INFERIOR) - print_selected_inferior (tui->interp_ui_out ()); - - if (tp !=3D NULL - && ((selection & (USER_SELECTED_THREAD | USER_SELECTED_FRAME)))) - print_selected_thread_frame (tui->interp_ui_out (), selection); - - } -} - /* These implement the TUI interpreter. */ =20 void @@ -349,17 +175,7 @@ _initialize_tui_interp () if (interpreter_p =3D=3D INTERP_CONSOLE) interpreter_p =3D INTERP_TUI; =20 - /* If changing this, remember to update cli-interp.c as well. */ - gdb::observers::normal_stop.attach (tui_on_normal_stop, "tui-interp"); - gdb::observers::signal_received.attach (tui_on_signal_received, "tui-int= erp"); - gdb::observers::end_stepping_range.attach (tui_on_end_stepping_range, - "tui-interp"); - gdb::observers::signal_exited.attach (tui_on_signal_exited, "tui-interp"= ); - gdb::observers::exited.attach (tui_on_exited, "tui-interp"); - gdb::observers::no_history.attach (tui_on_no_history, "tui-interp"); - gdb::observers::sync_execution_done.attach (tui_on_sync_execution_done, - "tui-interp"); - gdb::observers::command_error.attach (tui_on_command_error, "tui-interp"= ); - gdb::observers::user_selected_context_changed.attach - (tui_on_user_selected_context_changed, "tui-interp"); + /* There are no observers here because the CLI interpreter's + observers work for the TUI interpreter as well. See + cli-interp.c. */ }