Rewrite xcoff*_ppc_relocate_section.
[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 "frame.h"
50 #include "breakpoint.h"
51 #include "gdb-events.h"
52 #include <unistd.h>
53 #include <fcntl.h>
54
55 #include "tui.h"
56 #include "tuiData.h"
57 #include "tuiLayout.h"
58 #include "tuiIO.h"
59 #include "tuiRegs.h"
60 #include "tuiWin.h"
61 #include "tuiStack.h"
62 #include "tuiDataWin.h"
63 #include "tuiSourceWin.h"
64
65 int tui_target_has_run = 0;
66
67 static void (* tui_target_new_objfile_chain) (struct objfile*);
68 extern void (*selected_frame_level_changed_hook) (int);
69
70 static void
71 tui_new_objfile_hook (struct objfile* objfile)
72 {
73 if (tui_active)
74 {
75 tuiDisplayMainFunction ();
76 }
77
78 if (tui_target_new_objfile_chain)
79 tui_target_new_objfile_chain (objfile);
80 }
81
82 static int
83 tui_query_hook (const char * msg, va_list argp)
84 {
85 int retval;
86 int ans2;
87 int answer;
88
89 /* Automatically answer "yes" if input is not from a terminal. */
90 if (!input_from_terminal_p ())
91 return 1;
92
93 echo ();
94 while (1)
95 {
96 wrap_here (""); /* Flush any buffered output */
97 gdb_flush (gdb_stdout);
98
99 vfprintf_filtered (gdb_stdout, msg, argp);
100 printf_filtered ("(y or n) ");
101
102 wrap_here ("");
103 gdb_flush (gdb_stdout);
104
105 answer = tui_getc (stdin);
106 clearerr (stdin); /* in case of C-d */
107 if (answer == EOF) /* C-d */
108 {
109 retval = 1;
110 break;
111 }
112 /* Eat rest of input line, to EOF or newline */
113 if (answer != '\n')
114 do
115 {
116 ans2 = tui_getc (stdin);
117 clearerr (stdin);
118 }
119 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
120
121 if (answer >= 'a')
122 answer -= 040;
123 if (answer == 'Y')
124 {
125 retval = 1;
126 break;
127 }
128 if (answer == 'N')
129 {
130 retval = 0;
131 break;
132 }
133 printf_filtered ("Please answer y or n.\n");
134 }
135 noecho ();
136 return retval;
137 }
138
139 /* Prevent recursion of registers_changed_hook(). */
140 static int tui_refreshing_registers = 0;
141
142 static void
143 tui_registers_changed_hook (void)
144 {
145 struct frame_info *fi;
146
147 fi = selected_frame;
148 if (fi && tui_refreshing_registers == 0)
149 {
150 tui_refreshing_registers = 1;
151 #if 0
152 tuiCheckDataValues (fi);
153 #endif
154 tui_refreshing_registers = 0;
155 }
156 }
157
158 static void
159 tui_register_changed_hook (int regno)
160 {
161 struct frame_info *fi;
162
163 fi = selected_frame;
164 if (fi && tui_refreshing_registers == 0)
165 {
166 tui_refreshing_registers = 1;
167 tuiCheckDataValues (fi);
168 tui_refreshing_registers = 0;
169 }
170 }
171
172 extern struct breakpoint *breakpoint_chain;
173
174 /* Find a breakpoint given its number. Returns null if not found. */
175 static struct breakpoint *
176 get_breakpoint (int number)
177 {
178 struct breakpoint *bp;
179
180 for (bp = breakpoint_chain; bp; bp = bp->next)
181 {
182 if (bp->number == number)
183 return bp;
184 }
185 return 0;
186 }
187
188 /* Breakpoint creation hook.
189 Update the screen to show the new breakpoint. */
190 static void
191 tui_event_create_breakpoint (int number)
192 {
193 struct breakpoint *bp;
194
195 bp = get_breakpoint (number);
196 if (bp)
197 {
198 switch (bp->type)
199 {
200 case bp_breakpoint:
201 case bp_hardware_breakpoint:
202 tuiAllSetHasBreakAt (bp, 1);
203 tuiUpdateAllExecInfos ();
204 break;
205
206 default:
207 break;
208 }
209 }
210 }
211
212 /* Breakpoint deletion hook.
213 Refresh the screen to update the breakpoint marks. */
214 static void
215 tui_event_delete_breakpoint (int number)
216 {
217 struct breakpoint *bp;
218 struct breakpoint *b;
219 int clearIt;
220
221 bp = get_breakpoint (number);
222 if (bp == 0)
223 return;
224
225 /* Before turning off the visuals for the bp, check to see that
226 there are no other bps at the same address. */
227 clearIt = 0;
228 for (b = breakpoint_chain; b; b = b->next)
229 {
230 clearIt = (b == bp || b->address != bp->address);
231 if (!clearIt)
232 break;
233 }
234
235 if (clearIt)
236 {
237 tuiAllSetHasBreakAt (bp, 0);
238 tuiUpdateAllExecInfos ();
239 }
240 }
241
242 static void
243 tui_event_modify_breakpoint (int number)
244 {
245 ;
246 }
247
248 static void
249 tui_event_default (int number)
250 {
251 ;
252 }
253
254 static struct gdb_events *tui_old_event_hooks;
255
256 static struct gdb_events tui_event_hooks =
257 {
258 tui_event_create_breakpoint,
259 tui_event_delete_breakpoint,
260 tui_event_modify_breakpoint,
261 tui_event_default,
262 tui_event_default,
263 tui_event_default
264 };
265
266 /* Called when going to wait for the target.
267 Leave curses mode and setup program mode. */
268 static ptid_t
269 tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
270 {
271 ptid_t res;
272
273 /* Leave tui mode (optional). */
274 #if 0
275 if (tui_active)
276 {
277 target_terminal_ours ();
278 endwin ();
279 target_terminal_inferior ();
280 }
281 #endif
282 tui_target_has_run = 1;
283 res = target_wait (pid, status);
284
285 if (tui_active)
286 {
287 /* TODO: need to refresh (optional). */
288 }
289 return res;
290 }
291
292 /* The selected frame has changed. This is happens after a target
293 stop or when the user explicitly changes the frame (up/down/thread/...). */
294 static void
295 tui_selected_frame_level_changed_hook (int level)
296 {
297 struct frame_info *fi;
298
299 fi = selected_frame;
300 /* Ensure that symbols for this frame are read in. Also, determine the
301 source language of this frame, and switch to it if desired. */
302 if (fi)
303 {
304 struct symtab *s;
305
306 s = find_pc_symtab (fi->pc);
307 /* elz: this if here fixes the problem with the pc not being displayed
308 in the tui asm layout, with no debug symbols. The value of s
309 would be 0 here, and select_source_symtab would abort the
310 command by calling the 'error' function */
311 if (s)
312 {
313 select_source_symtab (s);
314 tuiShowFrameInfo (fi);
315 }
316
317 /* Refresh the register window if it's visible. */
318 if (tui_is_window_visible (DATA_WIN))
319 {
320 tui_refreshing_registers = 1;
321 tuiCheckDataValues (fi);
322 tui_refreshing_registers = 0;
323 }
324 }
325 }
326
327 /* Called from print_frame_info to list the line we stopped in. */
328 static void
329 tui_print_frame_info_listing_hook (struct symtab *s, int line,
330 int stopline, int noerror)
331 {
332 select_source_symtab (s);
333 tuiShowFrameInfo (selected_frame);
334 }
335
336 /* Install the TUI specific hooks. */
337 void
338 tui_install_hooks (void)
339 {
340 target_wait_hook = tui_target_wait_hook;
341 selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
342 print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
343
344 query_hook = tui_query_hook;
345
346 /* Install the event hooks. */
347 tui_old_event_hooks = set_gdb_event_hooks (&tui_event_hooks);
348
349 registers_changed_hook = tui_registers_changed_hook;
350 register_changed_hook = tui_register_changed_hook;
351 }
352
353 /* Remove the TUI specific hooks. */
354 void
355 tui_remove_hooks (void)
356 {
357 target_wait_hook = 0;
358 selected_frame_level_changed_hook = 0;
359 print_frame_info_listing_hook = 0;
360 query_hook = 0;
361 registers_changed_hook = 0;
362 register_changed_hook = 0;
363
364 /* Restore the previous event hooks. */
365 set_gdb_event_hooks (tui_old_event_hooks);
366 }
367
368 /* Cleanup the tui before exiting. */
369 static void
370 tui_exit (void)
371 {
372 /* Disable the tui. Curses mode is left leaving the screen
373 in a clean state (see endwin()). */
374 tui_disable ();
375 }
376
377 /* Initialize the tui by installing several gdb hooks, initializing
378 the tui IO and preparing the readline with the kind binding. */
379 static void
380 tui_init_hook (char *argv0)
381 {
382 /* Install exit handler to leave the screen in a good shape. */
383 atexit (tui_exit);
384
385 initializeStaticData ();
386
387 /* Install the permanent hooks. */
388 tui_target_new_objfile_chain = target_new_objfile_hook;
389 target_new_objfile_hook = tui_new_objfile_hook;
390
391 tui_initialize_io ();
392 tui_initialize_readline ();
393
394 /* Decide in which mode to start using GDB (based on -tui). */
395 if (tui_version)
396 {
397 tui_enable ();
398 }
399 }
400
401 /* Initialize the tui. */
402 void
403 _initialize_tui (void)
404 {
405 /* Setup initialization hook. */
406 init_ui_hook = tui_init_hook;
407 }
408
This page took 0.038197 seconds and 4 git commands to generate.