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. */
30 #include "event-loop.h"
32 #include "breakpoint.h"
33 #include "gdb-events.h"
39 #include "tuiLayout.h"
44 #include "tuiDataWin.h"
45 #include "tuiSourceWin.h"
47 int tui_target_has_run
= 0;
49 static void (* tui_target_new_objfile_chain
) (struct objfile
*);
50 extern void (*selected_frame_level_changed_hook
) (int);
53 tui_new_objfile_hook (struct objfile
* objfile
)
57 tuiDisplayMainFunction ();
60 if (tui_target_new_objfile_chain
)
61 tui_target_new_objfile_chain (objfile
);
65 tui_query_hook (const char * msg
, va_list argp
)
71 /* Automatically answer "yes" if input is not from a terminal. */
72 if (!input_from_terminal_p ())
78 wrap_here (""); /* Flush any buffered output */
79 gdb_flush (gdb_stdout
);
81 vfprintf_filtered (gdb_stdout
, msg
, argp
);
82 printf_filtered ("(y or n) ");
85 gdb_flush (gdb_stdout
);
87 answer
= tui_getc (stdin
);
88 clearerr (stdin
); /* in case of C-d */
89 if (answer
== EOF
) /* C-d */
94 /* Eat rest of input line, to EOF or newline */
98 ans2
= tui_getc (stdin
);
101 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
115 printf_filtered ("Please answer y or n.\n");
121 /* Prevent recursion of registers_changed_hook(). */
122 static int tui_refreshing_registers
= 0;
125 tui_registers_changed_hook (void)
127 struct frame_info
*fi
;
130 if (fi
&& tui_refreshing_registers
== 0)
132 tui_refreshing_registers
= 1;
134 tuiCheckDataValues (fi
);
136 tui_refreshing_registers
= 0;
141 tui_register_changed_hook (int regno
)
143 struct frame_info
*fi
;
146 if (fi
&& tui_refreshing_registers
== 0)
148 tui_refreshing_registers
= 1;
149 tuiCheckDataValues (fi
);
150 tui_refreshing_registers
= 0;
154 extern struct breakpoint
*breakpoint_chain
;
156 /* Find a breakpoint given its number. Returns null if not found. */
157 static struct breakpoint
*
158 get_breakpoint (int number
)
160 struct breakpoint
*bp
;
162 for (bp
= breakpoint_chain
; bp
; bp
= bp
->next
)
164 if (bp
->number
== number
)
170 /* Breakpoint creation hook.
171 Update the screen to show the new breakpoint. */
173 tui_event_create_breakpoint (int number
)
175 struct breakpoint
*bp
;
177 bp
= get_breakpoint (number
);
183 case bp_hardware_breakpoint
:
184 tuiAllSetHasBreakAt (bp
, 1);
185 tuiUpdateAllExecInfos ();
194 /* Breakpoint deletion hook.
195 Refresh the screen to update the breakpoint marks. */
197 tui_event_delete_breakpoint (int number
)
199 struct breakpoint
*bp
;
200 struct breakpoint
*b
;
203 bp
= get_breakpoint (number
);
207 /* Before turning off the visuals for the bp, check to see that
208 there are no other bps at the same address. */
210 for (b
= breakpoint_chain
; b
; b
= b
->next
)
212 clearIt
= (b
== bp
|| b
->address
!= bp
->address
);
219 tuiAllSetHasBreakAt (bp
, 0);
220 tuiUpdateAllExecInfos ();
225 tui_event_modify_breakpoint (int number
)
231 tui_event_default (int number
)
236 static struct gdb_events
*tui_old_event_hooks
;
238 static struct gdb_events tui_event_hooks
=
240 tui_event_create_breakpoint
,
241 tui_event_delete_breakpoint
,
242 tui_event_modify_breakpoint
,
248 /* Called when going to wait for the target.
249 Leave curses mode and setup program mode. */
251 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
255 /* Leave tui mode (optional). */
259 target_terminal_ours ();
261 target_terminal_inferior ();
264 tui_target_has_run
= 1;
265 res
= target_wait (pid
, status
);
269 /* TODO: need to refresh (optional). */
274 /* The selected frame has changed. This is happens after a target
275 stop or when the user explicitly changes the frame (up/down/thread/...). */
277 tui_selected_frame_level_changed_hook (int level
)
279 struct frame_info
*fi
;
282 /* Ensure that symbols for this frame are read in. Also, determine the
283 source language of this frame, and switch to it if desired. */
288 s
= find_pc_symtab (fi
->pc
);
289 /* elz: this if here fixes the problem with the pc not being displayed
290 in the tui asm layout, with no debug symbols. The value of s
291 would be 0 here, and select_source_symtab would abort the
292 command by calling the 'error' function */
295 select_source_symtab (s
);
296 tuiShowFrameInfo (fi
);
299 /* Refresh the register window if it's visible. */
300 if (tui_is_window_visible (DATA_WIN
))
302 tui_refreshing_registers
= 1;
303 tuiCheckDataValues (fi
);
304 tui_refreshing_registers
= 0;
309 /* Called from print_frame_info to list the line we stopped in. */
311 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
312 int stopline
, int noerror
)
314 select_source_symtab (s
);
315 tuiShowFrameInfo (selected_frame
);
318 /* Install the TUI specific hooks. */
320 tui_install_hooks (void)
322 target_wait_hook
= tui_target_wait_hook
;
323 selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
324 print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
326 query_hook
= tui_query_hook
;
328 /* Install the event hooks. */
329 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
331 registers_changed_hook
= tui_registers_changed_hook
;
332 register_changed_hook
= tui_register_changed_hook
;
335 /* Remove the TUI specific hooks. */
337 tui_remove_hooks (void)
339 target_wait_hook
= 0;
340 selected_frame_level_changed_hook
= 0;
341 print_frame_info_listing_hook
= 0;
343 registers_changed_hook
= 0;
344 register_changed_hook
= 0;
346 /* Restore the previous event hooks. */
347 set_gdb_event_hooks (tui_old_event_hooks
);
350 /* Cleanup the tui before exiting. */
354 /* Disable the tui. Curses mode is left leaving the screen
355 in a clean state (see endwin()). */
359 /* Initialize the tui by installing several gdb hooks, initializing
360 the tui IO and preparing the readline with the kind binding. */
362 tui_init_hook (char *argv0
)
364 /* Install exit handler to leave the screen in a good shape. */
367 initializeStaticData ();
369 /* Install the permanent hooks. */
370 tui_target_new_objfile_chain
= target_new_objfile_hook
;
371 target_new_objfile_hook
= tui_new_objfile_hook
;
373 tui_initialize_io ();
374 tui_initialize_readline ();
376 /* Decide in which mode to start using GDB (based on -tui). */
383 /* Initialize the tui. */
385 _initialize_tui (void)
387 /* Setup initialization hook. */
388 init_ui_hook
= tui_init_hook
;