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 /* These implement the TUI interpreter. */
212 tui_init (struct interp
*self
, int top_level
)
214 /* Install exit handler to leave the screen in a good shape. */
217 tui_initialize_static_data ();
219 tui_initialize_io ();
220 tui_initialize_win ();
221 if (ui_file_isatty (gdb_stdout
))
222 tui_initialize_readline ();
228 tui_resume (void *data
)
230 struct ui
*ui
= current_ui
;
231 struct ui_file
*stream
;
233 /* gdb_setup_readline will change gdb_stdout. If the TUI was
234 previously writing to gdb_stdout, then set it to the new
235 gdb_stdout afterwards. */
237 stream
= cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
238 if (stream
!= gdb_stdout
)
240 cli_out_set_stream (tui_old_uiout
, stream
);
244 gdb_setup_readline (1);
246 ui
->input_handler
= command_line_handler
;
249 cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
251 if (tui_start_enabled
)
257 tui_suspend (void *data
)
259 tui_start_enabled
= tui_active
;
264 static struct ui_out
*
265 tui_ui_out (struct interp
*self
)
270 return tui_old_uiout
;
273 static struct gdb_exception
274 tui_exec (void *data
, const char *command_str
)
276 internal_error (__FILE__
, __LINE__
, _("tui_exec called"));
279 /* The TUI interpreter's vtable. */
281 static const struct interp_procs tui_interp_procs
= {
288 cli_interpreter_pre_command_loop
,
289 cli_interpreter_supports_command_editing
,
292 /* Factory for TUI interpreters. */
294 static struct interp
*
295 tui_interp_factory (const char *name
)
297 return interp_new (name
, &tui_interp_procs
, NULL
);
300 /* Provide a prototype to silence -Wmissing-prototypes. */
301 extern initialize_file_ftype _initialize_tui_interp
;
304 _initialize_tui_interp (void)
306 interp_factory_register (INTERP_TUI
, tui_interp_factory
);
308 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_TUI
) == 0)
309 tui_start_enabled
= 1;
311 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_CONSOLE
) == 0)
313 xfree (interpreter_p
);
314 interpreter_p
= xstrdup (INTERP_TUI
);
317 /* If changing this, remember to update cli-interp.c as well. */
318 observer_attach_normal_stop (tui_on_normal_stop
);
319 observer_attach_signal_received (tui_on_signal_received
);
320 observer_attach_end_stepping_range (tui_on_end_stepping_range
);
321 observer_attach_signal_exited (tui_on_signal_exited
);
322 observer_attach_exited (tui_on_exited
);
323 observer_attach_no_history (tui_on_no_history
);
324 observer_attach_sync_execution_done (tui_on_sync_execution_done
);
325 observer_attach_command_error (tui_on_command_error
);