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 /* Breakpoint creation hook.
171 Update the screen to show the new breakpoint. */
173 tui_event_create_breakpoint (int number
)
175 tui_update_all_breakpoint_info ();
178 /* Breakpoint deletion hook.
179 Refresh the screen to update the breakpoint marks. */
181 tui_event_delete_breakpoint (int number
)
183 tui_update_all_breakpoint_info ();
187 tui_event_modify_breakpoint (int number
)
189 tui_update_all_breakpoint_info ();
193 tui_event_default (int number
)
198 static struct gdb_events
*tui_old_event_hooks
;
200 static struct gdb_events tui_event_hooks
=
202 tui_event_create_breakpoint
,
203 tui_event_delete_breakpoint
,
204 tui_event_modify_breakpoint
,
210 /* Called when going to wait for the target.
211 Leave curses mode and setup program mode. */
213 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
217 /* Leave tui mode (optional). */
221 target_terminal_ours ();
223 target_terminal_inferior ();
226 tui_target_has_run
= 1;
227 res
= target_wait (pid
, status
);
231 /* TODO: need to refresh (optional). */
236 /* The selected frame has changed. This is happens after a target
237 stop or when the user explicitly changes the frame (up/down/thread/...). */
239 tui_selected_frame_level_changed_hook (int level
)
241 struct frame_info
*fi
;
244 /* Ensure that symbols for this frame are read in. Also, determine the
245 source language of this frame, and switch to it if desired. */
250 s
= find_pc_symtab (fi
->pc
);
251 /* elz: this if here fixes the problem with the pc not being displayed
252 in the tui asm layout, with no debug symbols. The value of s
253 would be 0 here, and select_source_symtab would abort the
254 command by calling the 'error' function */
256 select_source_symtab (s
);
258 /* Display the frame position (even if there is no symbols). */
259 tuiShowFrameInfo (fi
);
261 /* Refresh the register window if it's visible. */
262 if (tui_is_window_visible (DATA_WIN
))
264 tui_refreshing_registers
= 1;
265 tuiCheckDataValues (fi
);
266 tui_refreshing_registers
= 0;
271 /* Called from print_frame_info to list the line we stopped in. */
273 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
274 int stopline
, int noerror
)
276 select_source_symtab (s
);
277 tuiShowFrameInfo (selected_frame
);
280 /* Called when the target process died or is detached.
281 Update the status line. */
283 tui_detach_hook (void)
285 tuiShowFrameInfo (0);
289 /* Install the TUI specific hooks. */
291 tui_install_hooks (void)
293 target_wait_hook
= tui_target_wait_hook
;
294 selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
295 print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
297 query_hook
= tui_query_hook
;
299 /* Install the event hooks. */
300 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
302 registers_changed_hook
= tui_registers_changed_hook
;
303 register_changed_hook
= tui_register_changed_hook
;
304 detach_hook
= tui_detach_hook
;
307 /* Remove the TUI specific hooks. */
309 tui_remove_hooks (void)
311 target_wait_hook
= 0;
312 selected_frame_level_changed_hook
= 0;
313 print_frame_info_listing_hook
= 0;
315 registers_changed_hook
= 0;
316 register_changed_hook
= 0;
319 /* Restore the previous event hooks. */
320 set_gdb_event_hooks (tui_old_event_hooks
);
323 /* Cleanup the tui before exiting. */
327 /* Disable the tui. Curses mode is left leaving the screen
328 in a clean state (see endwin()). */
332 /* Initialize the tui by installing several gdb hooks, initializing
333 the tui IO and preparing the readline with the kind binding. */
335 tui_init_hook (char *argv0
)
337 /* Install exit handler to leave the screen in a good shape. */
340 initializeStaticData ();
342 /* Install the permanent hooks. */
343 tui_target_new_objfile_chain
= target_new_objfile_hook
;
344 target_new_objfile_hook
= tui_new_objfile_hook
;
346 tui_initialize_io ();
347 tui_initialize_readline ();
349 /* Decide in which mode to start using GDB (based on -tui). */
356 /* Initialize the tui. */
358 _initialize_tui (void)
360 /* Setup initialization hook. */
361 init_ui_hook
= tui_init_hook
;