3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
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>
48 #include "event-loop.h"
50 #include "breakpoint.h"
51 #include "gdb-events.h"
57 #include "tuiLayout.h"
62 #include "tuiDataWin.h"
63 #include "tuiSourceWin.h"
65 int tui_target_has_run
= 0;
67 static void (* tui_target_new_objfile_chain
) (struct objfile
*);
68 extern void (*selected_frame_level_changed_hook
) (int);
71 tui_new_objfile_hook (struct objfile
* objfile
)
76 if (tui_target_new_objfile_chain
)
77 tui_target_new_objfile_chain (objfile
);
81 tui_query_hook (const char * msg
, va_list argp
)
87 /* Automatically answer "yes" if input is not from a terminal. */
88 if (!input_from_terminal_p ())
94 wrap_here (""); /* Flush any buffered output */
95 gdb_flush (gdb_stdout
);
97 vfprintf_filtered (gdb_stdout
, msg
, argp
);
98 printf_filtered ("(y or n) ");
101 gdb_flush (gdb_stdout
);
103 answer
= tui_getc (stdin
);
104 clearerr (stdin
); /* in case of C-d */
105 if (answer
== EOF
) /* C-d */
110 /* Eat rest of input line, to EOF or newline */
114 ans2
= tui_getc (stdin
);
117 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
131 printf_filtered ("Please answer y or n.\n");
137 /* Prevent recursion of registers_changed_hook(). */
138 static int tui_refreshing_registers
= 0;
141 tui_registers_changed_hook (void)
143 struct frame_info
*fi
;
146 if (fi
&& tui_refreshing_registers
== 0)
148 tui_refreshing_registers
= 1;
150 tuiCheckDataValues (fi
);
152 tui_refreshing_registers
= 0;
157 tui_register_changed_hook (int regno
)
159 struct frame_info
*fi
;
162 if (fi
&& tui_refreshing_registers
== 0)
164 tui_refreshing_registers
= 1;
165 tuiCheckDataValues (fi
);
166 tui_refreshing_registers
= 0;
170 extern struct breakpoint
*breakpoint_chain
;
172 /* Find a breakpoint given its number. Returns null if not found. */
173 static struct breakpoint
*
174 get_breakpoint (int number
)
176 struct breakpoint
*bp
;
178 for (bp
= breakpoint_chain
; bp
; bp
= bp
->next
)
180 if (bp
->number
== number
)
186 /* Breakpoint creation hook.
187 Update the screen to show the new breakpoint. */
189 tui_event_create_breakpoint (int number
)
191 struct breakpoint
*bp
;
193 bp
= get_breakpoint (number
);
199 case bp_hardware_breakpoint
:
200 tuiAllSetHasBreakAt (bp
, 1);
201 tuiUpdateAllExecInfos ();
210 /* Breakpoint deletion hook.
211 Refresh the screen to update the breakpoint marks. */
213 tui_event_delete_breakpoint (int number
)
215 struct breakpoint
*bp
;
216 struct breakpoint
*b
;
219 bp
= get_breakpoint (number
);
223 /* Before turning off the visuals for the bp, check to see that
224 there are no other bps at the same address. */
226 for (b
= breakpoint_chain
; b
; b
= b
->next
)
228 clearIt
= (b
== bp
|| b
->address
!= bp
->address
);
235 tuiAllSetHasBreakAt (bp
, 0);
236 tuiUpdateAllExecInfos ();
241 tui_event_modify_breakpoint (int number
)
247 tui_event_default (int number
)
252 static struct gdb_events
*tui_old_event_hooks
;
254 static struct gdb_events tui_event_hooks
=
256 tui_event_create_breakpoint
,
257 tui_event_delete_breakpoint
,
258 tui_event_modify_breakpoint
,
264 /* Called when going to wait for the target.
265 Leave curses mode and setup program mode. */
267 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
271 /* Leave tui mode (optional). */
275 target_terminal_ours ();
277 target_terminal_inferior ();
280 tui_target_has_run
= 1;
281 res
= target_wait (pid
, status
);
285 /* TODO: need to refresh (optional). */
290 /* The selected frame has changed. This is happens after a target
291 stop or when the user explicitly changes the frame (up/down/thread/...). */
293 tui_selected_frame_level_changed_hook (int level
)
295 struct frame_info
*fi
;
298 /* Ensure that symbols for this frame are read in. Also, determine the
299 source language of this frame, and switch to it if desired. */
304 s
= find_pc_symtab (fi
->pc
);
305 /* elz: this if here fixes the problem with the pc not being displayed
306 in the tui asm layout, with no debug symbols. The value of s
307 would be 0 here, and select_source_symtab would abort the
308 command by calling the 'error' function */
310 select_source_symtab (s
);
312 /* Display the frame position (even if there is no symbols). */
313 tuiShowFrameInfo (fi
);
315 /* Refresh the register window if it's visible. */
316 if (tui_is_window_visible (DATA_WIN
))
318 tui_refreshing_registers
= 1;
319 tuiCheckDataValues (fi
);
320 tui_refreshing_registers
= 0;
325 /* Called from print_frame_info to list the line we stopped in. */
327 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
328 int stopline
, int noerror
)
330 select_source_symtab (s
);
331 tuiShowFrameInfo (selected_frame
);
334 /* Install the TUI specific hooks. */
336 tui_install_hooks (void)
338 target_wait_hook
= tui_target_wait_hook
;
339 selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
340 print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
342 query_hook
= tui_query_hook
;
344 /* Install the event hooks. */
345 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
347 registers_changed_hook
= tui_registers_changed_hook
;
348 register_changed_hook
= tui_register_changed_hook
;
351 /* Remove the TUI specific hooks. */
353 tui_remove_hooks (void)
355 target_wait_hook
= 0;
356 selected_frame_level_changed_hook
= 0;
357 print_frame_info_listing_hook
= 0;
359 registers_changed_hook
= 0;
360 register_changed_hook
= 0;
362 /* Restore the previous event hooks. */
363 set_gdb_event_hooks (tui_old_event_hooks
);
366 /* Cleanup the tui before exiting. */
370 /* Disable the tui. Curses mode is left leaving the screen
371 in a clean state (see endwin()). */
375 /* Initialize the tui by installing several gdb hooks, initializing
376 the tui IO and preparing the readline with the kind binding. */
378 tui_init_hook (char *argv0
)
380 /* Install exit handler to leave the screen in a good shape. */
383 initializeStaticData ();
385 /* Install the permanent hooks. */
386 tui_target_new_objfile_chain
= target_new_objfile_hook
;
387 target_new_objfile_hook
= tui_new_objfile_hook
;
389 tui_initialize_io ();
390 tui_initialize_readline ();
392 /* Decide in which mode to start using GDB (based on -tui). */
399 /* Initialize the tui. */
401 _initialize_tui (void)
403 /* Setup initialization hook. */
404 init_ui_hook
= tui_init_hook
;