2 Copyright 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* If we need <curses.h>, we must include it before we get "bfd.h". */
40 #include "event-loop.h"
42 #include "breakpoint.h"
43 #include "gdb-events.h"
49 #include "tuiLayout.h"
54 #include "tuiDataWin.h"
55 #include "tuiSourceWin.h"
57 int tui_target_has_run = 0;
59 static void (* tui_target_new_objfile_chain) (struct objfile*);
60 extern void (*selected_frame_level_changed_hook) (int);
63 tui_new_objfile_hook (struct objfile* objfile)
67 tuiDisplayMainFunction ();
70 if (tui_target_new_objfile_chain)
71 tui_target_new_objfile_chain (objfile);
75 tui_query_hook (const char * msg, va_list argp)
81 /* Automatically answer "yes" if input is not from a terminal. */
82 if (!input_from_terminal_p ())
88 wrap_here (""); /* Flush any buffered output */
89 gdb_flush (gdb_stdout);
91 vfprintf_filtered (gdb_stdout, msg, argp);
92 printf_filtered ("(y or n) ");
95 gdb_flush (gdb_stdout);
97 answer = tui_getc (stdin);
98 clearerr (stdin); /* in case of C-d */
99 if (answer == EOF) /* C-d */
104 /* Eat rest of input line, to EOF or newline */
108 ans2 = tui_getc (stdin);
111 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
125 printf_filtered ("Please answer y or n.\n");
131 /* Prevent recursion of registers_changed_hook(). */
132 static int tui_refreshing_registers = 0;
135 tui_registers_changed_hook (void)
137 struct frame_info *fi;
140 if (fi && tui_refreshing_registers == 0)
142 tui_refreshing_registers = 1;
144 tuiCheckDataValues (fi);
146 tui_refreshing_registers = 0;
151 tui_register_changed_hook (int regno)
153 struct frame_info *fi;
156 if (fi && tui_refreshing_registers == 0)
158 tui_refreshing_registers = 1;
159 tuiCheckDataValues (fi);
160 tui_refreshing_registers = 0;
164 extern struct breakpoint *breakpoint_chain;
166 /* Find a breakpoint given its number. Returns null if not found. */
167 static struct breakpoint *
168 get_breakpoint (int number)
170 struct breakpoint *bp;
172 for (bp = breakpoint_chain; bp; bp = bp->next)
174 if (bp->number == number)
180 /* Breakpoint creation hook.
181 Update the screen to show the new breakpoint. */
183 tui_event_create_breakpoint (int number)
185 struct breakpoint *bp;
187 bp = get_breakpoint (number);
193 case bp_hardware_breakpoint:
194 tuiAllSetHasBreakAt (bp, 1);
195 tuiUpdateAllExecInfos ();
204 /* Breakpoint deletion hook.
205 Refresh the screen to update the breakpoint marks. */
207 tui_event_delete_breakpoint (int number)
209 struct breakpoint *bp;
210 struct breakpoint *b;
213 bp = get_breakpoint (number);
217 /* Before turning off the visuals for the bp, check to see that
218 there are no other bps at the same address. */
220 for (b = breakpoint_chain; b; b = b->next)
222 clearIt = (b == bp || b->address != bp->address);
229 tuiAllSetHasBreakAt (bp, 0);
230 tuiUpdateAllExecInfos ();
235 tui_event_modify_breakpoint (int number)
241 tui_event_default (int number)
246 static struct gdb_events *tui_old_event_hooks;
248 static struct gdb_events tui_event_hooks =
250 tui_event_create_breakpoint,
251 tui_event_delete_breakpoint,
252 tui_event_modify_breakpoint,
258 /* Called when going to wait for the target.
259 Leave curses mode and setup program mode. */
261 tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
265 /* Leave tui mode (optional). */
269 target_terminal_ours ();
271 target_terminal_inferior ();
274 tui_target_has_run = 1;
275 res = target_wait (pid, status);
279 /* TODO: need to refresh (optional). */
284 /* The selected frame has changed. This is happens after a target
285 stop or when the user explicitly changes the frame (up/down/thread/...). */
287 tui_selected_frame_level_changed_hook (int level)
289 struct frame_info *fi;
292 /* Ensure that symbols for this frame are read in. Also, determine the
293 source language of this frame, and switch to it if desired. */
298 s = find_pc_symtab (fi->pc);
299 /* elz: this if here fixes the problem with the pc not being displayed
300 in the tui asm layout, with no debug symbols. The value of s
301 would be 0 here, and select_source_symtab would abort the
302 command by calling the 'error' function */
305 select_source_symtab (s);
306 tuiShowFrameInfo (fi);
309 /* Refresh the register window if it's visible. */
310 if (tui_is_window_visible (DATA_WIN))
312 tui_refreshing_registers = 1;
313 tuiCheckDataValues (fi);
314 tui_refreshing_registers = 0;
319 /* Called from print_frame_info to list the line we stopped in. */
321 tui_print_frame_info_listing_hook (struct symtab *s, int line,
322 int stopline, int noerror)
324 select_source_symtab (s);
325 tuiShowFrameInfo (selected_frame);
328 /* Install the TUI specific hooks. */
330 tui_install_hooks (void)
332 target_wait_hook = tui_target_wait_hook;
333 selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
334 print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
336 query_hook = tui_query_hook;
338 /* Install the event hooks. */
339 tui_old_event_hooks = set_gdb_event_hooks (&tui_event_hooks);
341 registers_changed_hook = tui_registers_changed_hook;
342 register_changed_hook = tui_register_changed_hook;
345 /* Remove the TUI specific hooks. */
347 tui_remove_hooks (void)
349 target_wait_hook = 0;
350 selected_frame_level_changed_hook = 0;
351 print_frame_info_listing_hook = 0;
353 registers_changed_hook = 0;
354 register_changed_hook = 0;
356 /* Restore the previous event hooks. */
357 set_gdb_event_hooks (tui_old_event_hooks);
360 /* Cleanup the tui before exiting. */
364 /* Disable the tui. Curses mode is left leaving the screen
365 in a clean state (see endwin()). */
369 /* Initialize the tui by installing several gdb hooks, initializing
370 the tui IO and preparing the readline with the kind binding. */
372 tui_init_hook (char *argv0)
374 /* Install exit handler to leave the screen in a good shape. */
377 initializeStaticData ();
379 /* Install the permanent hooks. */
380 tui_target_new_objfile_chain = target_new_objfile_hook;
381 target_new_objfile_hook = tui_new_objfile_hook;
383 tui_initialize_io ();
384 tui_initialize_readline ();
386 /* Decide in which mode to start using GDB (based on -tui). */
393 /* Initialize the tui. */
395 _initialize_tui (void)
397 /* Setup initialization hook. */
398 init_ui_hook = tui_init_hook;