3 Copyright 2001, 2002, 2003, 2004, 2005 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 #include "event-loop.h"
32 #include "event-top.h"
34 #include "breakpoint.h"
35 #include "gdb-events.h"
42 #include "tui/tui-hooks.h"
43 #include "tui/tui-data.h"
44 #include "tui/tui-layout.h"
45 #include "tui/tui-io.h"
46 #include "tui/tui-regs.h"
47 #include "tui/tui-win.h"
48 #include "tui/tui-stack.h"
49 #include "tui/tui-windata.h"
50 #include "tui/tui-winsource.h"
52 #include "gdb_curses.h"
54 /* This redefines CTRL if it is not already defined, so it must come
55 after terminal state releated include files like <term.h> and
57 #include "readline/readline.h"
59 int tui_target_has_run = 0;
61 static void (* tui_target_new_objfile_chain) (struct objfile*);
64 tui_new_objfile_hook (struct objfile* objfile)
69 if (tui_target_new_objfile_chain)
70 tui_target_new_objfile_chain (objfile);
73 static int ATTR_FORMAT (printf, 1, 0)
74 tui_query_hook (const char * msg, va_list argp)
80 /* Automatically answer "yes" if input is not from a terminal. */
81 if (!input_from_terminal_p ())
87 wrap_here (""); /* Flush any buffered output */
88 gdb_flush (gdb_stdout);
90 vfprintf_filtered (gdb_stdout, msg, argp);
91 printf_filtered (_("(y or n) "));
94 gdb_flush (gdb_stdout);
96 answer = tui_getc (stdin);
97 clearerr (stdin); /* in case of C-d */
98 if (answer == EOF) /* C-d */
103 /* Eat rest of input line, to EOF or newline */
107 ans2 = tui_getc (stdin);
110 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
124 printf_filtered (_("Please answer y or n.\n"));
130 /* Prevent recursion of deprecated_registers_changed_hook(). */
131 static int tui_refreshing_registers = 0;
134 tui_registers_changed_hook (void)
136 struct frame_info *fi;
138 fi = deprecated_selected_frame;
139 if (fi && tui_refreshing_registers == 0)
141 tui_refreshing_registers = 1;
143 tui_check_data_values (fi);
145 tui_refreshing_registers = 0;
150 tui_register_changed_hook (int regno)
152 struct frame_info *fi;
154 fi = deprecated_selected_frame;
155 if (fi && tui_refreshing_registers == 0)
157 tui_refreshing_registers = 1;
158 tui_check_data_values (fi);
159 tui_refreshing_registers = 0;
163 /* Breakpoint creation hook.
164 Update the screen to show the new breakpoint. */
166 tui_event_create_breakpoint (int number)
168 tui_update_all_breakpoint_info ();
171 /* Breakpoint deletion hook.
172 Refresh the screen to update the breakpoint marks. */
174 tui_event_delete_breakpoint (int number)
176 tui_update_all_breakpoint_info ();
180 tui_event_modify_breakpoint (int number)
182 tui_update_all_breakpoint_info ();
186 tui_event_default (int number)
191 static struct gdb_events *tui_old_event_hooks;
193 static struct gdb_events tui_event_hooks =
195 tui_event_create_breakpoint,
196 tui_event_delete_breakpoint,
197 tui_event_modify_breakpoint,
203 /* Called when going to wait for the target.
204 Leave curses mode and setup program mode. */
206 tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
210 /* Leave tui mode (optional). */
214 target_terminal_ours ();
216 target_terminal_inferior ();
219 tui_target_has_run = 1;
220 res = target_wait (pid, status);
224 /* TODO: need to refresh (optional). */
229 /* The selected frame has changed. This is happens after a target
230 stop or when the user explicitly changes the frame (up/down/thread/...). */
232 tui_selected_frame_level_changed_hook (int level)
234 struct frame_info *fi;
236 fi = deprecated_selected_frame;
237 /* Ensure that symbols for this frame are read in. Also, determine the
238 source language of this frame, and switch to it if desired. */
243 s = find_pc_symtab (get_frame_pc (fi));
244 /* elz: this if here fixes the problem with the pc not being displayed
245 in the tui asm layout, with no debug symbols. The value of s
246 would be 0 here, and select_source_symtab would abort the
247 command by calling the 'error' function */
249 select_source_symtab (s);
251 /* Display the frame position (even if there is no symbols). */
252 tui_show_frame_info (fi);
254 /* Refresh the register window if it's visible. */
255 if (tui_is_window_visible (DATA_WIN))
257 tui_refreshing_registers = 1;
258 tui_check_data_values (fi);
259 tui_refreshing_registers = 0;
264 /* Called from print_frame_info to list the line we stopped in. */
266 tui_print_frame_info_listing_hook (struct symtab *s, int line,
267 int stopline, int noerror)
269 select_source_symtab (s);
270 tui_show_frame_info (deprecated_selected_frame);
273 /* Called when the target process died or is detached.
274 Update the status line. */
276 tui_detach_hook (void)
278 tui_show_frame_info (0);
282 /* Install the TUI specific hooks. */
284 tui_install_hooks (void)
286 deprecated_target_wait_hook = tui_target_wait_hook;
287 deprecated_selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
288 deprecated_print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
290 deprecated_query_hook = tui_query_hook;
292 /* Install the event hooks. */
293 tui_old_event_hooks = deprecated_set_gdb_event_hooks (&tui_event_hooks);
295 deprecated_registers_changed_hook = tui_registers_changed_hook;
296 deprecated_register_changed_hook = tui_register_changed_hook;
297 deprecated_detach_hook = tui_detach_hook;
300 /* Remove the TUI specific hooks. */
302 tui_remove_hooks (void)
304 deprecated_target_wait_hook = 0;
305 deprecated_selected_frame_level_changed_hook = 0;
306 deprecated_print_frame_info_listing_hook = 0;
307 deprecated_query_hook = 0;
308 deprecated_registers_changed_hook = 0;
309 deprecated_register_changed_hook = 0;
310 deprecated_detach_hook = 0;
312 /* Restore the previous event hooks. */
313 deprecated_set_gdb_event_hooks (tui_old_event_hooks);
316 void _initialize_tui_hooks (void);
319 _initialize_tui_hooks (void)
321 /* Install the permanent hooks. */
322 tui_target_new_objfile_chain = deprecated_target_new_objfile_hook;
323 deprecated_target_new_objfile_hook = tui_new_objfile_hook;