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"
49 #include "event-top.h"
51 #include "breakpoint.h"
52 #include "gdb-events.h"
55 #include <readline/readline.h>
61 #include "tuiLayout.h"
66 #include "tuiDataWin.h"
67 #include "tuiSourceWin.h"
69 int tui_target_has_run
= 0;
71 static void (* tui_target_new_objfile_chain
) (struct objfile
*);
74 tui_new_objfile_hook (struct objfile
* objfile
)
79 if (tui_target_new_objfile_chain
)
80 tui_target_new_objfile_chain (objfile
);
84 tui_query_hook (const char * msg
, va_list argp
)
90 /* Automatically answer "yes" if input is not from a terminal. */
91 if (!input_from_terminal_p ())
97 wrap_here (""); /* Flush any buffered output */
98 gdb_flush (gdb_stdout
);
100 vfprintf_filtered (gdb_stdout
, msg
, argp
);
101 printf_filtered ("(y or n) ");
104 gdb_flush (gdb_stdout
);
106 answer
= tui_getc (stdin
);
107 clearerr (stdin
); /* in case of C-d */
108 if (answer
== EOF
) /* C-d */
113 /* Eat rest of input line, to EOF or newline */
117 ans2
= tui_getc (stdin
);
120 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
134 printf_filtered ("Please answer y or n.\n");
140 /* Prevent recursion of registers_changed_hook(). */
141 static int tui_refreshing_registers
= 0;
144 tui_registers_changed_hook (void)
146 struct frame_info
*fi
;
148 fi
= deprecated_selected_frame
;
149 if (fi
&& tui_refreshing_registers
== 0)
151 tui_refreshing_registers
= 1;
153 tuiCheckDataValues (fi
);
155 tui_refreshing_registers
= 0;
160 tui_register_changed_hook (int regno
)
162 struct frame_info
*fi
;
164 fi
= deprecated_selected_frame
;
165 if (fi
&& tui_refreshing_registers
== 0)
167 tui_refreshing_registers
= 1;
168 tuiCheckDataValues (fi
);
169 tui_refreshing_registers
= 0;
173 /* Breakpoint creation hook.
174 Update the screen to show the new breakpoint. */
176 tui_event_create_breakpoint (int number
)
178 tui_update_all_breakpoint_info ();
181 /* Breakpoint deletion hook.
182 Refresh the screen to update the breakpoint marks. */
184 tui_event_delete_breakpoint (int number
)
186 tui_update_all_breakpoint_info ();
190 tui_event_modify_breakpoint (int number
)
192 tui_update_all_breakpoint_info ();
196 tui_event_default (int number
)
201 static struct gdb_events
*tui_old_event_hooks
;
203 static struct gdb_events tui_event_hooks
=
205 tui_event_create_breakpoint
,
206 tui_event_delete_breakpoint
,
207 tui_event_modify_breakpoint
,
213 /* Called when going to wait for the target.
214 Leave curses mode and setup program mode. */
216 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
220 /* Leave tui mode (optional). */
224 target_terminal_ours ();
226 target_terminal_inferior ();
229 tui_target_has_run
= 1;
230 res
= target_wait (pid
, status
);
234 /* TODO: need to refresh (optional). */
239 /* The selected frame has changed. This is happens after a target
240 stop or when the user explicitly changes the frame (up/down/thread/...). */
242 tui_selected_frame_level_changed_hook (int level
)
244 struct frame_info
*fi
;
246 fi
= deprecated_selected_frame
;
247 /* Ensure that symbols for this frame are read in. Also, determine the
248 source language of this frame, and switch to it if desired. */
253 s
= find_pc_symtab (fi
->pc
);
254 /* elz: this if here fixes the problem with the pc not being displayed
255 in the tui asm layout, with no debug symbols. The value of s
256 would be 0 here, and select_source_symtab would abort the
257 command by calling the 'error' function */
259 select_source_symtab (s
);
261 /* Display the frame position (even if there is no symbols). */
262 tuiShowFrameInfo (fi
);
264 /* Refresh the register window if it's visible. */
265 if (tui_is_window_visible (DATA_WIN
))
267 tui_refreshing_registers
= 1;
268 tuiCheckDataValues (fi
);
269 tui_refreshing_registers
= 0;
274 /* Called from print_frame_info to list the line we stopped in. */
276 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
277 int stopline
, int noerror
)
279 select_source_symtab (s
);
280 tuiShowFrameInfo (deprecated_selected_frame
);
283 /* Called when the target process died or is detached.
284 Update the status line. */
286 tui_detach_hook (void)
288 tuiShowFrameInfo (0);
292 /* Install the TUI specific hooks. */
294 tui_install_hooks (void)
296 target_wait_hook
= tui_target_wait_hook
;
297 selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
298 print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
300 query_hook
= tui_query_hook
;
302 /* Install the event hooks. */
303 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
305 registers_changed_hook
= tui_registers_changed_hook
;
306 register_changed_hook
= tui_register_changed_hook
;
307 detach_hook
= tui_detach_hook
;
310 /* Remove the TUI specific hooks. */
312 tui_remove_hooks (void)
314 target_wait_hook
= 0;
315 selected_frame_level_changed_hook
= 0;
316 print_frame_info_listing_hook
= 0;
318 registers_changed_hook
= 0;
319 register_changed_hook
= 0;
322 /* Restore the previous event hooks. */
323 set_gdb_event_hooks (tui_old_event_hooks
);
326 void _initialize_tui_hooks (void);
329 _initialize_tui_hooks (void)
331 /* Install the permanent hooks. */
332 tui_target_new_objfile_chain
= target_new_objfile_hook
;
333 target_new_objfile_hook
= tui_new_objfile_hook
;