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
)
75 tuiDisplayMainFunction ();
78 if (tui_target_new_objfile_chain
)
79 tui_target_new_objfile_chain (objfile
);
83 tui_query_hook (const char * msg
, va_list argp
)
89 /* Automatically answer "yes" if input is not from a terminal. */
90 if (!input_from_terminal_p ())
96 wrap_here (""); /* Flush any buffered output */
97 gdb_flush (gdb_stdout
);
99 vfprintf_filtered (gdb_stdout
, msg
, argp
);
100 printf_filtered ("(y or n) ");
103 gdb_flush (gdb_stdout
);
105 answer
= tui_getc (stdin
);
106 clearerr (stdin
); /* in case of C-d */
107 if (answer
== EOF
) /* C-d */
112 /* Eat rest of input line, to EOF or newline */
116 ans2
= tui_getc (stdin
);
119 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
133 printf_filtered ("Please answer y or n.\n");
139 /* Prevent recursion of registers_changed_hook(). */
140 static int tui_refreshing_registers
= 0;
143 tui_registers_changed_hook (void)
145 struct frame_info
*fi
;
148 if (fi
&& tui_refreshing_registers
== 0)
150 tui_refreshing_registers
= 1;
152 tuiCheckDataValues (fi
);
154 tui_refreshing_registers
= 0;
159 tui_register_changed_hook (int regno
)
161 struct frame_info
*fi
;
164 if (fi
&& tui_refreshing_registers
== 0)
166 tui_refreshing_registers
= 1;
167 tuiCheckDataValues (fi
);
168 tui_refreshing_registers
= 0;
172 extern struct breakpoint
*breakpoint_chain
;
174 /* Find a breakpoint given its number. Returns null if not found. */
175 static struct breakpoint
*
176 get_breakpoint (int number
)
178 struct breakpoint
*bp
;
180 for (bp
= breakpoint_chain
; bp
; bp
= bp
->next
)
182 if (bp
->number
== number
)
188 /* Breakpoint creation hook.
189 Update the screen to show the new breakpoint. */
191 tui_event_create_breakpoint (int number
)
193 struct breakpoint
*bp
;
195 bp
= get_breakpoint (number
);
201 case bp_hardware_breakpoint
:
202 tuiAllSetHasBreakAt (bp
, 1);
203 tuiUpdateAllExecInfos ();
212 /* Breakpoint deletion hook.
213 Refresh the screen to update the breakpoint marks. */
215 tui_event_delete_breakpoint (int number
)
217 struct breakpoint
*bp
;
218 struct breakpoint
*b
;
221 bp
= get_breakpoint (number
);
225 /* Before turning off the visuals for the bp, check to see that
226 there are no other bps at the same address. */
228 for (b
= breakpoint_chain
; b
; b
= b
->next
)
230 clearIt
= (b
== bp
|| b
->address
!= bp
->address
);
237 tuiAllSetHasBreakAt (bp
, 0);
238 tuiUpdateAllExecInfos ();
243 tui_event_modify_breakpoint (int number
)
249 tui_event_default (int number
)
254 static struct gdb_events
*tui_old_event_hooks
;
256 static struct gdb_events tui_event_hooks
=
258 tui_event_create_breakpoint
,
259 tui_event_delete_breakpoint
,
260 tui_event_modify_breakpoint
,
266 /* Called when going to wait for the target.
267 Leave curses mode and setup program mode. */
269 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
273 /* Leave tui mode (optional). */
277 target_terminal_ours ();
279 target_terminal_inferior ();
282 tui_target_has_run
= 1;
283 res
= target_wait (pid
, status
);
287 /* TODO: need to refresh (optional). */
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/...). */
295 tui_selected_frame_level_changed_hook (int level
)
297 struct frame_info
*fi
;
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. */
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 */
313 select_source_symtab (s
);
314 tuiShowFrameInfo (fi
);
317 /* Refresh the register window if it's visible. */
318 if (tui_is_window_visible (DATA_WIN
))
320 tui_refreshing_registers
= 1;
321 tuiCheckDataValues (fi
);
322 tui_refreshing_registers
= 0;
327 /* Called from print_frame_info to list the line we stopped in. */
329 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
330 int stopline
, int noerror
)
332 select_source_symtab (s
);
333 tuiShowFrameInfo (selected_frame
);
336 /* Install the TUI specific hooks. */
338 tui_install_hooks (void)
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
;
344 query_hook
= tui_query_hook
;
346 /* Install the event hooks. */
347 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
349 registers_changed_hook
= tui_registers_changed_hook
;
350 register_changed_hook
= tui_register_changed_hook
;
353 /* Remove the TUI specific hooks. */
355 tui_remove_hooks (void)
357 target_wait_hook
= 0;
358 selected_frame_level_changed_hook
= 0;
359 print_frame_info_listing_hook
= 0;
361 registers_changed_hook
= 0;
362 register_changed_hook
= 0;
364 /* Restore the previous event hooks. */
365 set_gdb_event_hooks (tui_old_event_hooks
);
368 /* Cleanup the tui before exiting. */
372 /* Disable the tui. Curses mode is left leaving the screen
373 in a clean state (see endwin()). */
377 /* Initialize the tui by installing several gdb hooks, initializing
378 the tui IO and preparing the readline with the kind binding. */
380 tui_init_hook (char *argv0
)
382 /* Install exit handler to leave the screen in a good shape. */
385 initializeStaticData ();
387 /* Install the permanent hooks. */
388 tui_target_new_objfile_chain
= target_new_objfile_hook
;
389 target_new_objfile_hook
= tui_new_objfile_hook
;
391 tui_initialize_io ();
392 tui_initialize_readline ();
394 /* Decide in which mode to start using GDB (based on -tui). */
401 /* Initialize the tui. */
403 _initialize_tui (void)
405 /* Setup initialization hook. */
406 init_ui_hook
= tui_init_hook
;