3 Copyright (C) 2001-2012 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/>. */
29 #include "event-loop.h"
30 #include "event-top.h"
32 #include "breakpoint.h"
40 #include "tui/tui-hooks.h"
41 #include "tui/tui-data.h"
42 #include "tui/tui-layout.h"
43 #include "tui/tui-io.h"
44 #include "tui/tui-regs.h"
45 #include "tui/tui-win.h"
46 #include "tui/tui-stack.h"
47 #include "tui/tui-windata.h"
48 #include "tui/tui-winsource.h"
50 #include "gdb_curses.h"
52 /* This redefines CTRL if it is not already defined, so it must come
53 after terminal state releated include files like <term.h> and
55 #include "readline/readline.h"
57 int tui_target_has_run
= 0;
60 tui_new_objfile_hook (struct objfile
* objfile
)
66 static int ATTRIBUTE_PRINTF (1, 0)
67 tui_query_hook (const char *msg
, va_list argp
)
73 struct cleanup
*old_chain
;
75 /* Format the question outside of the loop, to avoid reusing
77 question
= xstrvprintf (msg
, argp
);
78 old_chain
= make_cleanup (xfree
, question
);
83 wrap_here (""); /* Flush any buffered output. */
84 gdb_flush (gdb_stdout
);
86 fputs_filtered (question
, gdb_stdout
);
87 printf_filtered (_("(y or n) "));
90 gdb_flush (gdb_stdout
);
92 answer
= tui_getc (stdin
);
93 clearerr (stdin
); /* in case of C-d */
94 if (answer
== EOF
) /* C-d */
99 /* Eat rest of input line, to EOF or newline. */
103 ans2
= tui_getc (stdin
);
106 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
120 printf_filtered (_("Please answer y or n.\n"));
124 do_cleanups (old_chain
);
128 /* Prevent recursion of deprecated_register_changed_hook(). */
129 static int tui_refreshing_registers
= 0;
132 tui_register_changed_hook (int regno
)
134 struct frame_info
*fi
;
136 fi
= get_selected_frame (NULL
);
137 if (tui_refreshing_registers
== 0)
139 tui_refreshing_registers
= 1;
140 tui_check_data_values (fi
);
141 tui_refreshing_registers
= 0;
145 /* Breakpoint creation hook.
146 Update the screen to show the new breakpoint. */
148 tui_event_create_breakpoint (struct breakpoint
*b
)
150 tui_update_all_breakpoint_info ();
153 /* Breakpoint deletion hook.
154 Refresh the screen to update the breakpoint marks. */
156 tui_event_delete_breakpoint (struct breakpoint
*b
)
158 tui_update_all_breakpoint_info ();
162 tui_event_modify_breakpoint (struct breakpoint
*b
)
164 tui_update_all_breakpoint_info ();
167 /* Called when going to wait for the target.
168 Leave curses mode and setup program mode. */
170 tui_target_wait_hook (ptid_t pid
,
171 struct target_waitstatus
*status
, int options
)
175 /* Leave tui mode (optional). */
179 target_terminal_ours ();
181 target_terminal_inferior ();
184 tui_target_has_run
= 1;
185 res
= target_wait (pid
, status
, options
);
189 /* TODO: need to refresh (optional). */
194 /* The selected frame has changed. This is happens after a target
195 stop or when the user explicitly changes the frame
196 (up/down/thread/...). */
198 tui_selected_frame_level_changed_hook (int level
)
200 struct frame_info
*fi
;
203 /* Negative level means that the selected frame was cleared. */
207 fi
= get_selected_frame (NULL
);
208 /* Ensure that symbols for this frame are read in. Also, determine
209 the source language of this frame, and switch to it if
211 if (get_frame_pc_if_available (fi
, &pc
))
215 s
= find_pc_symtab (pc
);
216 /* elz: This if here fixes the problem with the pc not being
217 displayed in the tui asm layout, with no debug symbols. The
218 value of s would be 0 here, and select_source_symtab would
219 abort the command by calling the 'error' function. */
221 select_source_symtab (s
);
224 /* Display the frame position (even if there is no symbols or the PC
226 tui_show_frame_info (fi
);
228 /* Refresh the register window if it's visible. */
229 if (tui_is_window_visible (DATA_WIN
))
231 tui_refreshing_registers
= 1;
232 tui_check_data_values (fi
);
233 tui_refreshing_registers
= 0;
237 /* Called from print_frame_info to list the line we stopped in. */
239 tui_print_frame_info_listing_hook (struct symtab
*s
,
244 select_source_symtab (s
);
245 tui_show_frame_info (get_selected_frame (NULL
));
248 /* Called when the target process died or is detached.
249 Update the status line. */
251 tui_detach_hook (void)
253 tui_show_frame_info (0);
257 /* Observers created when installing TUI hooks. */
258 static struct observer
*tui_bp_created_observer
;
259 static struct observer
*tui_bp_deleted_observer
;
260 static struct observer
*tui_bp_modified_observer
;
262 /* Install the TUI specific hooks. */
264 tui_install_hooks (void)
266 deprecated_target_wait_hook
= tui_target_wait_hook
;
267 deprecated_selected_frame_level_changed_hook
268 = tui_selected_frame_level_changed_hook
;
269 deprecated_print_frame_info_listing_hook
270 = tui_print_frame_info_listing_hook
;
272 deprecated_query_hook
= tui_query_hook
;
274 /* Install the event hooks. */
275 tui_bp_created_observer
276 = observer_attach_breakpoint_created (tui_event_create_breakpoint
);
277 tui_bp_deleted_observer
278 = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint
);
279 tui_bp_modified_observer
280 = observer_attach_breakpoint_modified (tui_event_modify_breakpoint
);
282 deprecated_register_changed_hook
= tui_register_changed_hook
;
283 deprecated_detach_hook
= tui_detach_hook
;
286 /* Remove the TUI specific hooks. */
288 tui_remove_hooks (void)
290 deprecated_target_wait_hook
= 0;
291 deprecated_selected_frame_level_changed_hook
= 0;
292 deprecated_print_frame_info_listing_hook
= 0;
293 deprecated_query_hook
= 0;
294 deprecated_register_changed_hook
= 0;
295 deprecated_detach_hook
= 0;
297 /* Remove our observers. */
298 observer_detach_breakpoint_created (tui_bp_created_observer
);
299 tui_bp_created_observer
= NULL
;
300 observer_detach_breakpoint_deleted (tui_bp_deleted_observer
);
301 tui_bp_deleted_observer
= NULL
;
302 observer_detach_breakpoint_modified (tui_bp_modified_observer
);
303 tui_bp_modified_observer
= NULL
;
306 void _initialize_tui_hooks (void);
309 _initialize_tui_hooks (void)
311 /* Install the permanent hooks. */
312 observer_attach_new_objfile (tui_new_objfile_hook
);