1 /* TUI Interpreter definitions for GDB, the GNU debugger.
3 Copyright (C) 2003-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "cli/cli-interp.h"
24 #include "event-top.h"
25 #include "event-loop.h"
28 #include "tui/tui-data.h"
29 #include "readline/readline.h"
30 #include "tui/tui-win.h"
32 #include "tui/tui-io.h"
35 #include "gdbthread.h"
37 static struct ui_out
*tui_ui_out (struct interp
*self
);
39 /* Set to 1 when the TUI mode must be activated when we first start
41 static int tui_start_enabled
= 0;
43 /* Returns the INTERP if the INTERP is a TUI, and returns NULL
46 static struct interp
*
47 as_tui_interp (struct interp
*interp
)
49 if (strcmp (interp_name (interp
), INTERP_TUI
) == 0)
54 /* Cleanup the tui before exiting. */
59 /* Disable the tui. Curses mode is left leaving the screen in a
60 clean state (see endwin()). */
64 /* Observers for several run control events. If the interpreter is
65 quiet (i.e., another interpreter is being run with
66 interpreter-exec), print nothing. */
68 /* Observer for the normal_stop notification. */
71 tui_on_normal_stop (struct bpstats
*bs
, int print_frame
)
73 struct switch_thru_all_uis state
;
78 SWITCH_THRU_ALL_UIS (state
)
80 struct interp
*interp
= top_level_interpreter ();
81 struct interp
*tui
= as_tui_interp (interp
);
82 struct thread_info
*thread
;
87 thread
= inferior_thread ();
88 if (should_print_stop_to_console (interp
, thread
))
89 print_stop_event (tui_ui_out (tui
));
93 /* Observer for the signal_received notification. */
96 tui_on_signal_received (enum gdb_signal siggnal
)
98 struct switch_thru_all_uis state
;
100 SWITCH_THRU_ALL_UIS (state
)
102 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
107 print_signal_received_reason (tui_ui_out (tui
), siggnal
);
111 /* Observer for the end_stepping_range notification. */
114 tui_on_end_stepping_range (void)
116 struct switch_thru_all_uis state
;
118 SWITCH_THRU_ALL_UIS (state
)
120 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
125 print_end_stepping_range_reason (tui_ui_out (tui
));
129 /* Observer for the signal_exited notification. */
132 tui_on_signal_exited (enum gdb_signal siggnal
)
134 struct switch_thru_all_uis state
;
136 SWITCH_THRU_ALL_UIS (state
)
138 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
143 print_signal_exited_reason (tui_ui_out (tui
), siggnal
);
147 /* Observer for the exited notification. */
150 tui_on_exited (int exitstatus
)
152 struct switch_thru_all_uis state
;
154 SWITCH_THRU_ALL_UIS (state
)
156 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
161 print_exited_reason (tui_ui_out (tui
), exitstatus
);
165 /* Observer for the no_history notification. */
168 tui_on_no_history (void)
170 struct switch_thru_all_uis state
;
172 SWITCH_THRU_ALL_UIS (state
)
174 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
179 print_no_history_reason (tui_ui_out (tui
));
183 /* Observer for the sync_execution_done notification. */
186 tui_on_sync_execution_done (void)
188 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
193 display_gdb_prompt (NULL
);
196 /* Observer for the command_error notification. */
199 tui_on_command_error (void)
201 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
206 display_gdb_prompt (NULL
);
209 /* Observer for the user_selected_context_changed notification. */
212 tui_on_user_selected_context_changed (user_selected_what selection
)
214 struct switch_thru_all_uis state
;
215 struct thread_info
*tp
;
217 /* This event is suppressed. */
218 if (cli_suppress_notification
.user_selected_context
)
221 tp
= find_thread_ptid (inferior_ptid
);
223 SWITCH_THRU_ALL_UIS (state
)
225 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
230 if (selection
& USER_SELECTED_INFERIOR
)
231 print_selected_inferior (tui_ui_out (tui
));
234 && ((selection
& (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
))))
235 print_selected_thread_frame (tui_ui_out (tui
), selection
);
240 /* These implement the TUI interpreter. */
243 tui_init (struct interp
*self
, int top_level
)
245 /* Install exit handler to leave the screen in a good shape. */
248 tui_initialize_static_data ();
250 tui_initialize_io ();
251 tui_initialize_win ();
252 if (ui_file_isatty (gdb_stdout
))
253 tui_initialize_readline ();
259 tui_resume (void *data
)
261 struct ui
*ui
= current_ui
;
262 struct ui_file
*stream
;
264 /* gdb_setup_readline will change gdb_stdout. If the TUI was
265 previously writing to gdb_stdout, then set it to the new
266 gdb_stdout afterwards. */
268 stream
= cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
269 if (stream
!= gdb_stdout
)
271 cli_out_set_stream (tui_old_uiout
, stream
);
275 gdb_setup_readline (1);
277 ui
->input_handler
= command_line_handler
;
280 cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
282 if (tui_start_enabled
)
288 tui_suspend (void *data
)
290 tui_start_enabled
= tui_active
;
295 static struct ui_out
*
296 tui_ui_out (struct interp
*self
)
301 return tui_old_uiout
;
304 static struct gdb_exception
305 tui_exec (void *data
, const char *command_str
)
307 internal_error (__FILE__
, __LINE__
, _("tui_exec called"));
310 /* The TUI interpreter's vtable. */
312 static const struct interp_procs tui_interp_procs
= {
319 cli_interpreter_pre_command_loop
,
320 cli_interpreter_supports_command_editing
,
323 /* Factory for TUI interpreters. */
325 static struct interp
*
326 tui_interp_factory (const char *name
)
328 return interp_new (name
, &tui_interp_procs
, NULL
);
331 /* Provide a prototype to silence -Wmissing-prototypes. */
332 extern initialize_file_ftype _initialize_tui_interp
;
335 _initialize_tui_interp (void)
337 interp_factory_register (INTERP_TUI
, tui_interp_factory
);
339 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_TUI
) == 0)
340 tui_start_enabled
= 1;
342 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_CONSOLE
) == 0)
344 xfree (interpreter_p
);
345 interpreter_p
= xstrdup (INTERP_TUI
);
348 /* If changing this, remember to update cli-interp.c as well. */
349 observer_attach_normal_stop (tui_on_normal_stop
);
350 observer_attach_signal_received (tui_on_signal_received
);
351 observer_attach_end_stepping_range (tui_on_end_stepping_range
);
352 observer_attach_signal_exited (tui_on_signal_exited
);
353 observer_attach_exited (tui_on_exited
);
354 observer_attach_no_history (tui_on_no_history
);
355 observer_attach_sync_execution_done (tui_on_sync_execution_done
);
356 observer_attach_command_error (tui_on_command_error
);
357 observer_attach_user_selected_context_changed
358 (tui_on_user_selected_context_changed
);