3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
32 #include "event-loop.h"
33 #include "event-top.h"
35 #include "breakpoint.h"
36 #include "gdb-events.h"
44 #include "tui/tui-hooks.h"
45 #include "tui/tui-data.h"
46 #include "tui/tui-layout.h"
47 #include "tui/tui-io.h"
48 #include "tui/tui-regs.h"
49 #include "tui/tui-win.h"
50 #include "tui/tui-stack.h"
51 #include "tui/tui-windata.h"
52 #include "tui/tui-winsource.h"
54 #include "gdb_curses.h"
56 /* This redefines CTRL if it is not already defined, so it must come
57 after terminal state releated include files like <term.h> and
59 #include "readline/readline.h"
61 int tui_target_has_run
= 0;
64 tui_new_objfile_hook (struct objfile
* objfile
)
70 static int ATTR_FORMAT (printf
, 1, 0)
71 tui_query_hook (const char *msg
, va_list argp
)
80 wrap_here (""); /* Flush any buffered output. */
81 gdb_flush (gdb_stdout
);
83 vfprintf_filtered (gdb_stdout
, msg
, argp
);
84 printf_filtered (_("(y or n) "));
87 gdb_flush (gdb_stdout
);
89 answer
= tui_getc (stdin
);
90 clearerr (stdin
); /* in case of C-d */
91 if (answer
== EOF
) /* C-d */
96 /* Eat rest of input line, to EOF or newline. */
100 ans2
= tui_getc (stdin
);
103 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
117 printf_filtered (_("Please answer y or n.\n"));
123 /* Prevent recursion of deprecated_register_changed_hook(). */
124 static int tui_refreshing_registers
= 0;
127 tui_register_changed_hook (int regno
)
129 struct frame_info
*fi
;
131 fi
= get_selected_frame (NULL
);
132 if (tui_refreshing_registers
== 0)
134 tui_refreshing_registers
= 1;
135 tui_check_data_values (fi
);
136 tui_refreshing_registers
= 0;
140 /* Breakpoint creation hook.
141 Update the screen to show the new breakpoint. */
143 tui_event_create_breakpoint (int number
)
145 tui_update_all_breakpoint_info ();
148 /* Breakpoint deletion hook.
149 Refresh the screen to update the breakpoint marks. */
151 tui_event_delete_breakpoint (int number
)
153 tui_update_all_breakpoint_info ();
157 tui_event_modify_breakpoint (int number
)
159 tui_update_all_breakpoint_info ();
163 tui_event_default (int number
)
168 static struct gdb_events
*tui_old_event_hooks
;
170 static struct gdb_events tui_event_hooks
= {
171 tui_event_create_breakpoint
,
172 tui_event_delete_breakpoint
,
173 tui_event_modify_breakpoint
,
179 /* Called when going to wait for the target.
180 Leave curses mode and setup program mode. */
182 tui_target_wait_hook (ptid_t pid
,
183 struct target_waitstatus
*status
)
187 /* Leave tui mode (optional). */
191 target_terminal_ours ();
193 target_terminal_inferior ();
196 tui_target_has_run
= 1;
197 res
= target_wait (pid
, status
);
201 /* TODO: need to refresh (optional). */
206 /* The selected frame has changed. This is happens after a target
207 stop or when the user explicitly changes the frame
208 (up/down/thread/...). */
210 tui_selected_frame_level_changed_hook (int level
)
212 struct frame_info
*fi
;
214 /* Negative level means that the selected frame was cleared. */
218 fi
= get_selected_frame (NULL
);
219 /* Ensure that symbols for this frame are read in. Also, determine
220 the source language of this frame, and switch to it if
226 s
= find_pc_symtab (get_frame_pc (fi
));
227 /* elz: This if here fixes the problem with the pc not being
228 displayed in the tui asm layout, with no debug symbols. The
229 value of s would be 0 here, and select_source_symtab would
230 abort the command by calling the 'error' function. */
232 select_source_symtab (s
);
234 /* Display the frame position (even if there is no symbols). */
235 tui_show_frame_info (fi
);
237 /* Refresh the register window if it's visible. */
238 if (tui_is_window_visible (DATA_WIN
))
240 tui_refreshing_registers
= 1;
241 tui_check_data_values (fi
);
242 tui_refreshing_registers
= 0;
247 /* Called from print_frame_info to list the line we stopped in. */
249 tui_print_frame_info_listing_hook (struct symtab
*s
,
254 select_source_symtab (s
);
255 tui_show_frame_info (get_selected_frame (NULL
));
258 /* Called when the target process died or is detached.
259 Update the status line. */
261 tui_detach_hook (void)
263 tui_show_frame_info (0);
267 /* Install the TUI specific hooks. */
269 tui_install_hooks (void)
271 deprecated_target_wait_hook
= tui_target_wait_hook
;
272 deprecated_selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
273 deprecated_print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
275 deprecated_query_hook
= tui_query_hook
;
277 /* Install the event hooks. */
278 tui_old_event_hooks
= deprecated_set_gdb_event_hooks (&tui_event_hooks
);
280 deprecated_register_changed_hook
= tui_register_changed_hook
;
281 deprecated_detach_hook
= tui_detach_hook
;
284 /* Remove the TUI specific hooks. */
286 tui_remove_hooks (void)
288 deprecated_target_wait_hook
= 0;
289 deprecated_selected_frame_level_changed_hook
= 0;
290 deprecated_print_frame_info_listing_hook
= 0;
291 deprecated_query_hook
= 0;
292 deprecated_register_changed_hook
= 0;
293 deprecated_detach_hook
= 0;
295 /* Restore the previous event hooks. */
296 deprecated_set_gdb_event_hooks (tui_old_event_hooks
);
299 void _initialize_tui_hooks (void);
302 _initialize_tui_hooks (void)
304 /* Install the permanent hooks. */
305 observer_attach_new_objfile (tui_new_objfile_hook
);