]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/tui/tui-hooks.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / tui / tui-hooks.c
1 /* GDB hooks for TUI.
2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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. */
22
23 #include "defs.h"
24 #include "symtab.h"
25 #include "inferior.h"
26 #include "command.h"
27 #include "bfd.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "target.h"
31 #include "gdbcore.h"
32 #include "event-loop.h"
33 #include "event-top.h"
34 #include "frame.h"
35 #include "breakpoint.h"
36 #include "gdb-events.h"
37 #include "ui-out.h"
38 #include "top.h"
39 #include <unistd.h>
40 #include <fcntl.h>
41
42 #include "tui/tui.h"
43 #include "tui/tui-hooks.h"
44 #include "tui/tui-data.h"
45 #include "tui/tui-layout.h"
46 #include "tui/tui-io.h"
47 #include "tui/tui-regs.h"
48 #include "tui/tui-win.h"
49 #include "tui/tui-stack.h"
50 #include "tui/tui-windata.h"
51 #include "tui/tui-winsource.h"
52
53 #include "gdb_curses.h"
54
55 /* This redefines CTRL if it is not already defined, so it must come
56 after terminal state releated include files like <term.h> and
57 "gdb_curses.h". */
58 #include "readline/readline.h"
59
60 int tui_target_has_run = 0;
61
62 static void (* tui_target_new_objfile_chain) (struct objfile*);
63
64 static void
65 tui_new_objfile_hook (struct objfile* objfile)
66 {
67 if (tui_active)
68 tui_display_main ();
69
70 if (tui_target_new_objfile_chain)
71 tui_target_new_objfile_chain (objfile);
72 }
73
74 static int ATTR_FORMAT (printf, 1, 0)
75 tui_query_hook (const char * msg, va_list argp)
76 {
77 int retval;
78 int ans2;
79 int answer;
80
81 echo ();
82 while (1)
83 {
84 wrap_here (""); /* Flush any buffered output */
85 gdb_flush (gdb_stdout);
86
87 vfprintf_filtered (gdb_stdout, msg, argp);
88 printf_filtered (_("(y or n) "));
89
90 wrap_here ("");
91 gdb_flush (gdb_stdout);
92
93 answer = tui_getc (stdin);
94 clearerr (stdin); /* in case of C-d */
95 if (answer == EOF) /* C-d */
96 {
97 retval = 1;
98 break;
99 }
100 /* Eat rest of input line, to EOF or newline */
101 if (answer != '\n')
102 do
103 {
104 ans2 = tui_getc (stdin);
105 clearerr (stdin);
106 }
107 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
108
109 if (answer >= 'a')
110 answer -= 040;
111 if (answer == 'Y')
112 {
113 retval = 1;
114 break;
115 }
116 if (answer == 'N')
117 {
118 retval = 0;
119 break;
120 }
121 printf_filtered (_("Please answer y or n.\n"));
122 }
123 noecho ();
124 return retval;
125 }
126
127 /* Prevent recursion of deprecated_registers_changed_hook(). */
128 static int tui_refreshing_registers = 0;
129
130 static void
131 tui_registers_changed_hook (void)
132 {
133 struct frame_info *fi;
134
135 fi = deprecated_selected_frame;
136 if (fi && tui_refreshing_registers == 0)
137 {
138 tui_refreshing_registers = 1;
139 #if 0
140 tui_check_data_values (fi);
141 #endif
142 tui_refreshing_registers = 0;
143 }
144 }
145
146 static void
147 tui_register_changed_hook (int regno)
148 {
149 struct frame_info *fi;
150
151 fi = deprecated_selected_frame;
152 if (fi && tui_refreshing_registers == 0)
153 {
154 tui_refreshing_registers = 1;
155 tui_check_data_values (fi);
156 tui_refreshing_registers = 0;
157 }
158 }
159
160 /* Breakpoint creation hook.
161 Update the screen to show the new breakpoint. */
162 static void
163 tui_event_create_breakpoint (int number)
164 {
165 tui_update_all_breakpoint_info ();
166 }
167
168 /* Breakpoint deletion hook.
169 Refresh the screen to update the breakpoint marks. */
170 static void
171 tui_event_delete_breakpoint (int number)
172 {
173 tui_update_all_breakpoint_info ();
174 }
175
176 static void
177 tui_event_modify_breakpoint (int number)
178 {
179 tui_update_all_breakpoint_info ();
180 }
181
182 static void
183 tui_event_default (int number)
184 {
185 ;
186 }
187
188 static struct gdb_events *tui_old_event_hooks;
189
190 static struct gdb_events tui_event_hooks =
191 {
192 tui_event_create_breakpoint,
193 tui_event_delete_breakpoint,
194 tui_event_modify_breakpoint,
195 tui_event_default,
196 tui_event_default,
197 tui_event_default
198 };
199
200 /* Called when going to wait for the target.
201 Leave curses mode and setup program mode. */
202 static ptid_t
203 tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
204 {
205 ptid_t res;
206
207 /* Leave tui mode (optional). */
208 #if 0
209 if (tui_active)
210 {
211 target_terminal_ours ();
212 endwin ();
213 target_terminal_inferior ();
214 }
215 #endif
216 tui_target_has_run = 1;
217 res = target_wait (pid, status);
218
219 if (tui_active)
220 {
221 /* TODO: need to refresh (optional). */
222 }
223 return res;
224 }
225
226 /* The selected frame has changed. This is happens after a target
227 stop or when the user explicitly changes the frame (up/down/thread/...). */
228 static void
229 tui_selected_frame_level_changed_hook (int level)
230 {
231 struct frame_info *fi;
232
233 fi = deprecated_selected_frame;
234 /* Ensure that symbols for this frame are read in. Also, determine the
235 source language of this frame, and switch to it if desired. */
236 if (fi)
237 {
238 struct symtab *s;
239
240 s = find_pc_symtab (get_frame_pc (fi));
241 /* elz: this if here fixes the problem with the pc not being displayed
242 in the tui asm layout, with no debug symbols. The value of s
243 would be 0 here, and select_source_symtab would abort the
244 command by calling the 'error' function */
245 if (s)
246 select_source_symtab (s);
247
248 /* Display the frame position (even if there is no symbols). */
249 tui_show_frame_info (fi);
250
251 /* Refresh the register window if it's visible. */
252 if (tui_is_window_visible (DATA_WIN))
253 {
254 tui_refreshing_registers = 1;
255 tui_check_data_values (fi);
256 tui_refreshing_registers = 0;
257 }
258 }
259 }
260
261 /* Called from print_frame_info to list the line we stopped in. */
262 static void
263 tui_print_frame_info_listing_hook (struct symtab *s, int line,
264 int stopline, int noerror)
265 {
266 select_source_symtab (s);
267 tui_show_frame_info (deprecated_selected_frame);
268 }
269
270 /* Called when the target process died or is detached.
271 Update the status line. */
272 static void
273 tui_detach_hook (void)
274 {
275 tui_show_frame_info (0);
276 tui_display_main ();
277 }
278
279 /* Install the TUI specific hooks. */
280 void
281 tui_install_hooks (void)
282 {
283 deprecated_target_wait_hook = tui_target_wait_hook;
284 deprecated_selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
285 deprecated_print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
286
287 deprecated_query_hook = tui_query_hook;
288
289 /* Install the event hooks. */
290 tui_old_event_hooks = deprecated_set_gdb_event_hooks (&tui_event_hooks);
291
292 deprecated_registers_changed_hook = tui_registers_changed_hook;
293 deprecated_register_changed_hook = tui_register_changed_hook;
294 deprecated_detach_hook = tui_detach_hook;
295 }
296
297 /* Remove the TUI specific hooks. */
298 void
299 tui_remove_hooks (void)
300 {
301 deprecated_target_wait_hook = 0;
302 deprecated_selected_frame_level_changed_hook = 0;
303 deprecated_print_frame_info_listing_hook = 0;
304 deprecated_query_hook = 0;
305 deprecated_registers_changed_hook = 0;
306 deprecated_register_changed_hook = 0;
307 deprecated_detach_hook = 0;
308
309 /* Restore the previous event hooks. */
310 deprecated_set_gdb_event_hooks (tui_old_event_hooks);
311 }
312
313 void _initialize_tui_hooks (void);
314
315 void
316 _initialize_tui_hooks (void)
317 {
318 /* Install the permanent hooks. */
319 tui_target_new_objfile_chain = deprecated_target_new_objfile_hook;
320 deprecated_target_new_objfile_hook = tui_new_objfile_hook;
321 }