aboutsummaryrefslogtreecommitdiff
path: root/gdb/event-top.c
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/event-top.c
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/event-top.c')
-rw-r--r--gdb/event-top.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 664543c..c6e3b7e 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -437,8 +437,55 @@ top_level_prompt (void)
return xstrdup (prompt);
}
-static struct ui current_ui_;
-struct ui *current_ui = &current_ui_;
+/* The main UI. This is the UI that is bound to stdin/stdout/stderr.
+ It always exists and is created automatically when GDB starts
+ up. */
+static struct ui main_ui_;
+
+struct ui *current_ui = &main_ui_;
+struct ui *ui_list = &main_ui_;
+
+/* Cleanup that restores the current UI. */
+
+static void
+restore_ui_cleanup (void *data)
+{
+ current_ui = (struct ui *) data;
+}
+
+/* See top.h. */
+
+void
+switch_thru_all_uis_init (struct switch_thru_all_uis *state)
+{
+ state->iter = ui_list;
+ state->old_chain = make_cleanup (restore_ui_cleanup, current_ui);
+}
+
+/* See top.h. */
+
+int
+switch_thru_all_uis_cond (struct switch_thru_all_uis *state)
+{
+ if (state->iter != NULL)
+ {
+ current_ui = state->iter;
+ return 1;
+ }
+ else
+ {
+ do_cleanups (state->old_chain);
+ return 0;
+ }
+}
+
+/* See top.h. */
+
+void
+switch_thru_all_uis_next (struct switch_thru_all_uis *state)
+{
+ state->iter = state->iter->next;
+}
/* Get a pointer to the current UI's line buffer. This is used to
construct a whole line of input from partial input. */