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