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
)
76 SWITCH_THRU_ALL_UIS ()
78 struct interp
*interp
= top_level_interpreter ();
79 struct interp
*tui
= as_tui_interp (interp
);
80 struct thread_info
*thread
;
85 thread
= inferior_thread ();
86 if (should_print_stop_to_console (interp
, thread
))
87 print_stop_event (tui_ui_out (tui
));
91 /* Observer for the signal_received notification. */
94 tui_on_signal_received (enum gdb_signal siggnal
)
96 SWITCH_THRU_ALL_UIS ()
98 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
103 print_signal_received_reason (tui_ui_out (tui
), siggnal
);
107 /* Observer for the end_stepping_range notification. */
110 tui_on_end_stepping_range (void)
112 SWITCH_THRU_ALL_UIS ()
114 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
119 print_end_stepping_range_reason (tui_ui_out (tui
));
123 /* Observer for the signal_exited notification. */
126 tui_on_signal_exited (enum gdb_signal siggnal
)
128 SWITCH_THRU_ALL_UIS ()
130 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
135 print_signal_exited_reason (tui_ui_out (tui
), siggnal
);
139 /* Observer for the exited notification. */
142 tui_on_exited (int exitstatus
)
144 SWITCH_THRU_ALL_UIS ()
146 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
151 print_exited_reason (tui_ui_out (tui
), exitstatus
);
155 /* Observer for the no_history notification. */
158 tui_on_no_history (void)
160 SWITCH_THRU_ALL_UIS ()
162 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
167 print_no_history_reason (tui_ui_out (tui
));
171 /* Observer for the sync_execution_done notification. */
174 tui_on_sync_execution_done (void)
176 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
181 display_gdb_prompt (NULL
);
184 /* Observer for the command_error notification. */
187 tui_on_command_error (void)
189 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
194 display_gdb_prompt (NULL
);
197 /* Observer for the user_selected_context_changed notification. */
200 tui_on_user_selected_context_changed (user_selected_what selection
)
202 struct thread_info
*tp
;
204 /* This event is suppressed. */
205 if (cli_suppress_notification
.user_selected_context
)
208 tp
= find_thread_ptid (inferior_ptid
);
210 SWITCH_THRU_ALL_UIS ()
212 struct interp
*tui
= as_tui_interp (top_level_interpreter ());
217 if (selection
& USER_SELECTED_INFERIOR
)
218 print_selected_inferior (tui_ui_out (tui
));
221 && ((selection
& (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
))))
222 print_selected_thread_frame (tui_ui_out (tui
), selection
);
227 /* These implement the TUI interpreter. */
230 tui_init (struct interp
*self
, int top_level
)
232 /* Install exit handler to leave the screen in a good shape. */
235 tui_initialize_static_data ();
237 tui_initialize_io ();
238 tui_initialize_win ();
239 if (ui_file_isatty (gdb_stdout
))
240 tui_initialize_readline ();
246 tui_resume (void *data
)
248 struct ui
*ui
= current_ui
;
249 struct ui_file
*stream
;
251 /* gdb_setup_readline will change gdb_stdout. If the TUI was
252 previously writing to gdb_stdout, then set it to the new
253 gdb_stdout afterwards. */
255 stream
= cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
256 if (stream
!= gdb_stdout
)
258 cli_out_set_stream (tui_old_uiout
, stream
);
262 gdb_setup_readline (1);
264 ui
->input_handler
= command_line_handler
;
267 cli_out_set_stream (tui_old_uiout
, gdb_stdout
);
269 if (tui_start_enabled
)
275 tui_suspend (void *data
)
277 tui_start_enabled
= tui_active
;
282 static struct ui_out
*
283 tui_ui_out (struct interp
*self
)
288 return tui_old_uiout
;
291 static struct gdb_exception
292 tui_exec (void *data
, const char *command_str
)
294 internal_error (__FILE__
, __LINE__
, _("tui_exec called"));
297 /* The TUI interpreter's vtable. */
299 static const struct interp_procs tui_interp_procs
= {
306 cli_interpreter_pre_command_loop
,
307 cli_interpreter_supports_command_editing
,
310 /* Factory for TUI interpreters. */
312 static struct interp
*
313 tui_interp_factory (const char *name
)
315 return interp_new (name
, &tui_interp_procs
, NULL
);
318 /* Provide a prototype to silence -Wmissing-prototypes. */
319 extern initialize_file_ftype _initialize_tui_interp
;
322 _initialize_tui_interp (void)
324 interp_factory_register (INTERP_TUI
, tui_interp_factory
);
326 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_TUI
) == 0)
327 tui_start_enabled
= 1;
329 if (interpreter_p
&& strcmp (interpreter_p
, INTERP_CONSOLE
) == 0)
331 xfree (interpreter_p
);
332 interpreter_p
= xstrdup (INTERP_TUI
);
335 /* If changing this, remember to update cli-interp.c as well. */
336 observer_attach_normal_stop (tui_on_normal_stop
);
337 observer_attach_signal_received (tui_on_signal_received
);
338 observer_attach_end_stepping_range (tui_on_end_stepping_range
);
339 observer_attach_signal_exited (tui_on_signal_exited
);
340 observer_attach_exited (tui_on_exited
);
341 observer_attach_no_history (tui_on_no_history
);
342 observer_attach_sync_execution_done (tui_on_sync_execution_done
);
343 observer_attach_command_error (tui_on_command_error
);
344 observer_attach_user_selected_context_changed
345 (tui_on_user_selected_context_changed
);