3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011 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 3 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, see <http://www.gnu.org/licenses/>. */
30 #include "event-loop.h"
31 #include "event-top.h"
33 #include "breakpoint.h"
41 #include "tui/tui-hooks.h"
42 #include "tui/tui-data.h"
43 #include "tui/tui-layout.h"
44 #include "tui/tui-io.h"
45 #include "tui/tui-regs.h"
46 #include "tui/tui-win.h"
47 #include "tui/tui-stack.h"
48 #include "tui/tui-windata.h"
49 #include "tui/tui-winsource.h"
51 #include "gdb_curses.h"
53 /* This redefines CTRL if it is not already defined, so it must come
54 after terminal state releated include files like <term.h> and
56 #include "readline/readline.h"
58 int tui_target_has_run
= 0;
61 tui_new_objfile_hook (struct objfile
* objfile
)
67 static int ATTRIBUTE_PRINTF (1, 0)
68 tui_query_hook (const char *msg
, va_list argp
)
77 wrap_here (""); /* Flush any buffered output. */
78 gdb_flush (gdb_stdout
);
80 vfprintf_filtered (gdb_stdout
, msg
, argp
);
81 printf_filtered (_("(y or n) "));
84 gdb_flush (gdb_stdout
);
86 answer
= tui_getc (stdin
);
87 clearerr (stdin
); /* in case of C-d */
88 if (answer
== EOF
) /* C-d */
93 /* Eat rest of input line, to EOF or newline. */
97 ans2
= tui_getc (stdin
);
100 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
114 printf_filtered (_("Please answer y or n.\n"));
120 /* Prevent recursion of deprecated_register_changed_hook(). */
121 static int tui_refreshing_registers
= 0;
124 tui_register_changed_hook (int regno
)
126 struct frame_info
*fi
;
128 fi
= get_selected_frame (NULL
);
129 if (tui_refreshing_registers
== 0)
131 tui_refreshing_registers
= 1;
132 tui_check_data_values (fi
);
133 tui_refreshing_registers
= 0;
137 /* Breakpoint creation hook.
138 Update the screen to show the new breakpoint. */
140 tui_event_create_breakpoint (struct breakpoint
*b
)
142 tui_update_all_breakpoint_info ();
145 /* Breakpoint deletion hook.
146 Refresh the screen to update the breakpoint marks. */
148 tui_event_delete_breakpoint (struct breakpoint
*b
)
150 tui_update_all_breakpoint_info ();
154 tui_event_modify_breakpoint (struct breakpoint
*b
)
156 tui_update_all_breakpoint_info ();
159 /* Called when going to wait for the target.
160 Leave curses mode and setup program mode. */
162 tui_target_wait_hook (ptid_t pid
,
163 struct target_waitstatus
*status
, int options
)
167 /* Leave tui mode (optional). */
171 target_terminal_ours ();
173 target_terminal_inferior ();
176 tui_target_has_run
= 1;
177 res
= target_wait (pid
, status
, options
);
181 /* TODO: need to refresh (optional). */
186 /* The selected frame has changed. This is happens after a target
187 stop or when the user explicitly changes the frame
188 (up/down/thread/...). */
190 tui_selected_frame_level_changed_hook (int level
)
192 struct frame_info
*fi
;
195 /* Negative level means that the selected frame was cleared. */
199 fi
= get_selected_frame (NULL
);
200 /* Ensure that symbols for this frame are read in. Also, determine
201 the source language of this frame, and switch to it if
203 if (get_frame_pc_if_available (fi
, &pc
))
207 s
= find_pc_symtab (pc
);
208 /* elz: This if here fixes the problem with the pc not being
209 displayed in the tui asm layout, with no debug symbols. The
210 value of s would be 0 here, and select_source_symtab would
211 abort the command by calling the 'error' function. */
213 select_source_symtab (s
);
216 /* Display the frame position (even if there is no symbols or the PC
218 tui_show_frame_info (fi
);
220 /* Refresh the register window if it's visible. */
221 if (tui_is_window_visible (DATA_WIN
))
223 tui_refreshing_registers
= 1;
224 tui_check_data_values (fi
);
225 tui_refreshing_registers
= 0;
229 /* Called from print_frame_info to list the line we stopped in. */
231 tui_print_frame_info_listing_hook (struct symtab
*s
,
236 select_source_symtab (s
);
237 tui_show_frame_info (get_selected_frame (NULL
));
240 /* Called when the target process died or is detached.
241 Update the status line. */
243 tui_detach_hook (void)
245 tui_show_frame_info (0);
249 /* Observers created when installing TUI hooks. */
250 static struct observer
*tui_bp_created_observer
;
251 static struct observer
*tui_bp_deleted_observer
;
252 static struct observer
*tui_bp_modified_observer
;
254 /* Install the TUI specific hooks. */
256 tui_install_hooks (void)
258 deprecated_target_wait_hook
= tui_target_wait_hook
;
259 deprecated_selected_frame_level_changed_hook
260 = tui_selected_frame_level_changed_hook
;
261 deprecated_print_frame_info_listing_hook
262 = tui_print_frame_info_listing_hook
;
264 deprecated_query_hook
= tui_query_hook
;
266 /* Install the event hooks. */
267 tui_bp_created_observer
268 = observer_attach_breakpoint_created (tui_event_create_breakpoint
);
269 tui_bp_deleted_observer
270 = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint
);
271 tui_bp_modified_observer
272 = observer_attach_breakpoint_modified (tui_event_modify_breakpoint
);
274 deprecated_register_changed_hook
= tui_register_changed_hook
;
275 deprecated_detach_hook
= tui_detach_hook
;
278 /* Remove the TUI specific hooks. */
280 tui_remove_hooks (void)
282 deprecated_target_wait_hook
= 0;
283 deprecated_selected_frame_level_changed_hook
= 0;
284 deprecated_print_frame_info_listing_hook
= 0;
285 deprecated_query_hook
= 0;
286 deprecated_register_changed_hook
= 0;
287 deprecated_detach_hook
= 0;
289 /* Remove our observers. */
290 observer_detach_breakpoint_created (tui_bp_created_observer
);
291 tui_bp_created_observer
= NULL
;
292 observer_detach_breakpoint_deleted (tui_bp_deleted_observer
);
293 tui_bp_deleted_observer
= NULL
;
294 observer_detach_breakpoint_modified (tui_bp_modified_observer
);
295 tui_bp_modified_observer
= NULL
;
298 void _initialize_tui_hooks (void);
301 _initialize_tui_hooks (void)
303 /* Install the permanent hooks. */
304 observer_attach_new_objfile (tui_new_objfile_hook
);