aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-06-21 01:11:45 +0100
committerPedro Alves <palves@redhat.com>2016-06-21 01:11:45 +0100
commit73ab01a07dfef77a9d845be2ef87754435eeffa1 (patch)
treeecedd002b69377c16f0e6e78a0cec7e6eb4ae39a /gdb/tui
parent8322445e0584be846f5873b9aab257dc9fbda05d (diff)
downloadgdb-73ab01a07dfef77a9d845be2ef87754435eeffa1.zip
gdb-73ab01a07dfef77a9d845be2ef87754435eeffa1.tar.gz
gdb-73ab01a07dfef77a9d845be2ef87754435eeffa1.tar.bz2
Make the intepreters output to all UIs
When we have multiple consoles, MI channels, etc., then we need to broadcast breakpoint hits, etc. to all UIs. In the past, I've adjusted most of the run control to communicate events to the interpreters through observer notifications, so events would be properly sent to console and MI streams, in sync and async modes. This patch does the next logical step -- have each interpreter's observers output interpreter-specific info to _all_ UIs. Note that when we have multiple instances of active cli/tui interpreters, then the cli_interp and tui_interp globals no longer work. This is addressed by this patch. Also, the interpreters currently register some observers when resumed and remove them when suspended. If we have multiple instances of the interpreters, and they can be suspended/resumed at different, independent times, that no longer works. What we instead do is always install the observers, and then have the observers themselves know when to do nothing. An earlier prototype of this series did the looping over struct UIs in common code, and then dispatched events to the interpreters through a matching interp_on_foo method for each observer. That turned out a lot more complicated than the present solution, as we'd end up with having to create a new interp method every time some interpreter wanted to listen to some observer notification, resulting in a lot of duplicated make-work and more coupling than desirable. gdb/ChangeLog: 2016-06-21 Pedro Alves <palves@redhat.com> * cli/cli-interp.c (cli_interp): Delete. (as_cli_interp): New function. (cli_on_normal_stop, cli_on_signal_received) (cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited) (cli_on_no_history): Send output to all CLI UIs. (cli_on_sync_execution_done, cli_on_command_error): Skip output if the top level interpreter is not a CLI. (cli_interpreter_init): Don't set cli_interp or install observers here. (_initialize_cli_interp): Install observers here. * event-top.c (main_ui_, ui_list): New globals. (current_ui): Point to main_ui_. (restore_ui_cleanup, switch_thru_all_uis_init) (switch_thru_all_uis_cond, switch_thru_all_uis_next): New functions. * mi/mi-interp.c (as_mi_interp): New function. (mi_interpreter_init): Don't install observers here. (mi_on_sync_execution_done): Skip output if the top level interpreter is not a MI. (mi_new_thread, mi_thread_exit, mi_record_changed) (mi_inferior_added, mi_inferior_appeared, mi_inferior_exit) (mi_inferior_removed): Send output to all MI UIs. (find_mi_interpreter, mi_interp_data): Delete. (find_mi_interp): New function. (mi_on_signal_received, mi_on_end_stepping_range) (mi_on_signal_exited, mi_on_exited, mi_on_no_history): Send output to all MI UIs. (mi_on_normal_stop): Rename to ... (mi_on_normal_stop_1): ... this. (mi_on_normal_stop): Reimplement, sending output to all MI UIs. (mi_traceframe_changed, mi_tsv_created, mi_tsv_deleted) (mi_tsv_modified, mi_breakpoint_created, mi_breakpoint_deleted) (mi_breakpoint_modified, mi_output_running_pid): Send output to all MI UIs. (mi_on_resume): Rename to ... (mi_on_resume_1): ... this. Don't handle infcalls here. (mi_on_resume): Reimplement, sending output to all MI UIs. (mi_solib_loaded, mi_solib_unloaded, mi_command_param_changed) (mi_memory_changed): Send output to all MI UIs. (report_initial_inferior): Install observers here. * top.h (struct ui) <next>: New field. (ui_list): Declare. (struct switch_thru_all_uis): New. (switch_thru_all_uis_init, switch_thru_all_uis_cond) (switch_thru_all_uis_next): Declare. (SWITCH_THRU_ALL_UIS): New macro. * tui/tui-interp.c (tui_interp): Delete global. (as_tui_interp): New function. (tui_on_normal_stop, tui_on_signal_received) (tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited) (tui_on_no_history): Send output to all TUI UIs. (tui_on_sync_execution_done, tui_on_command_error): Skip output if the top level interpreter is not a TUI. (tui_init): Don't set tui_interp or install observers here. (_initialize_tui_interp): Install observers here.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-interp.c127
1 files changed, 96 insertions, 31 deletions
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 7544500..452dd20 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -38,8 +38,16 @@ static struct ui_out *tui_ui_out (struct interp *self);
gdb. */
static int tui_start_enabled = 0;
-/* The TUI interpreter. */
-static struct interp *tui_interp;
+/* Returns the INTERP if the INTERP is a TUI, and returns NULL
+ otherwise. */
+
+static struct interp *
+as_tui_interp (struct interp *interp)
+{
+ if (strcmp (interp_name (interp), INTERP_TUI) == 0)
+ return interp;
+ return NULL;
+}
/* Cleanup the tui before exiting. */
@@ -60,10 +68,17 @@ tui_exit (void)
static void
tui_on_normal_stop (struct bpstats *bs, int print_frame)
{
- if (!interp_quiet_p (tui_interp))
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
{
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
if (print_frame)
- print_stop_event (tui_ui_out (tui_interp));
+ print_stop_event (tui_ui_out (tui));
}
}
@@ -72,8 +87,17 @@ tui_on_normal_stop (struct bpstats *bs, int print_frame)
static void
tui_on_signal_received (enum gdb_signal siggnal)
{
- if (!interp_quiet_p (tui_interp))
- print_signal_received_reason (tui_ui_out (tui_interp), siggnal);
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
+ {
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
+ print_signal_received_reason (tui_ui_out (tui), siggnal);
+ }
}
/* Observer for the end_stepping_range notification. */
@@ -81,8 +105,17 @@ tui_on_signal_received (enum gdb_signal siggnal)
static void
tui_on_end_stepping_range (void)
{
- if (!interp_quiet_p (tui_interp))
- print_end_stepping_range_reason (tui_ui_out (tui_interp));
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
+ {
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
+ print_end_stepping_range_reason (tui_ui_out (tui));
+ }
}
/* Observer for the signal_exited notification. */
@@ -90,8 +123,17 @@ tui_on_end_stepping_range (void)
static void
tui_on_signal_exited (enum gdb_signal siggnal)
{
- if (!interp_quiet_p (tui_interp))
- print_signal_exited_reason (tui_ui_out (tui_interp), siggnal);
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
+ {
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
+ print_signal_exited_reason (tui_ui_out (tui), siggnal);
+ }
}
/* Observer for the exited notification. */
@@ -99,8 +141,17 @@ tui_on_signal_exited (enum gdb_signal siggnal)
static void
tui_on_exited (int exitstatus)
{
- if (!interp_quiet_p (tui_interp))
- print_exited_reason (tui_ui_out (tui_interp), exitstatus);
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
+ {
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
+ print_exited_reason (tui_ui_out (tui), exitstatus);
+ }
}
/* Observer for the no_history notification. */
@@ -108,8 +159,17 @@ tui_on_exited (int exitstatus)
static void
tui_on_no_history (void)
{
- if (!interp_quiet_p (tui_interp))
- print_no_history_reason (tui_ui_out (tui_interp));
+ struct switch_thru_all_uis state;
+
+ SWITCH_THRU_ALL_UIS (state)
+ {
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ continue;
+
+ print_no_history_reason (tui_ui_out (tui));
+ }
}
/* Observer for the sync_execution_done notification. */
@@ -117,8 +177,12 @@ tui_on_no_history (void)
static void
tui_on_sync_execution_done (void)
{
- if (!interp_quiet_p (tui_interp))
- display_gdb_prompt (NULL);
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ return;
+
+ display_gdb_prompt (NULL);
}
/* Observer for the command_error notification. */
@@ -126,8 +190,12 @@ tui_on_sync_execution_done (void)
static void
tui_on_command_error (void)
{
- if (!interp_quiet_p (tui_interp))
- display_gdb_prompt (NULL);
+ struct interp *tui = as_tui_interp (top_level_interpreter ());
+
+ if (tui == NULL)
+ return;
+
+ display_gdb_prompt (NULL);
}
/* These implement the TUI interpreter. */
@@ -138,9 +206,6 @@ tui_init (struct interp *self, int top_level)
/* Install exit handler to leave the screen in a good shape. */
atexit (tui_exit);
- if (top_level)
- tui_interp = self;
-
tui_initialize_static_data ();
tui_initialize_io ();
@@ -148,16 +213,6 @@ tui_init (struct interp *self, int top_level)
if (ui_file_isatty (gdb_stdout))
tui_initialize_readline ();
- /* If changing this, remember to update cli-interp.c as well. */
- observer_attach_normal_stop (tui_on_normal_stop);
- observer_attach_signal_received (tui_on_signal_received);
- observer_attach_end_stepping_range (tui_on_end_stepping_range);
- observer_attach_signal_exited (tui_on_signal_exited);
- observer_attach_exited (tui_on_exited);
- observer_attach_no_history (tui_on_no_history);
- observer_attach_sync_execution_done (tui_on_sync_execution_done);
- observer_attach_command_error (tui_on_command_error);
-
return NULL;
}
@@ -246,4 +301,14 @@ _initialize_tui_interp (void)
xfree (interpreter_p);
interpreter_p = xstrdup (INTERP_TUI);
}
+
+ /* If changing this, remember to update cli-interp.c as well. */
+ observer_attach_normal_stop (tui_on_normal_stop);
+ observer_attach_signal_received (tui_on_signal_received);
+ observer_attach_end_stepping_range (tui_on_end_stepping_range);
+ observer_attach_signal_exited (tui_on_signal_exited);
+ observer_attach_exited (tui_on_exited);
+ observer_attach_no_history (tui_on_no_history);
+ observer_attach_sync_execution_done (tui_on_sync_execution_done);
+ observer_attach_command_error (tui_on_command_error);
}