3 Copyright 2001, 2002, 2003, 2004 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. */
31 #include "event-loop.h"
32 #include "event-top.h"
34 #include "breakpoint.h"
35 #include "gdb-events.h"
38 #include "readline/readline.h"
43 #include "tui/tui-hooks.h"
44 #include "tui/tui-data.h"
45 #include "tui/tui-layout.h"
46 #include "tui/tui-io.h"
47 #include "tui/tui-regs.h"
48 #include "tui/tui-win.h"
49 #include "tui/tui-stack.h"
50 #include "tui/tui-windata.h"
51 #include "tui/tui-winsource.h"
53 #include "gdb_curses.h"
55 int tui_target_has_run
= 0;
57 static void (* tui_target_new_objfile_chain
) (struct objfile
*);
60 tui_new_objfile_hook (struct objfile
* objfile
)
65 if (tui_target_new_objfile_chain
)
66 tui_target_new_objfile_chain (objfile
);
70 tui_query_hook (const char * msg
, va_list argp
)
76 /* Automatically answer "yes" if input is not from a terminal. */
77 if (!input_from_terminal_p ())
83 wrap_here (""); /* Flush any buffered output */
84 gdb_flush (gdb_stdout
);
86 vfprintf_filtered (gdb_stdout
, msg
, argp
);
87 printf_filtered ("(y or n) ");
90 gdb_flush (gdb_stdout
);
92 answer
= tui_getc (stdin
);
93 clearerr (stdin
); /* in case of C-d */
94 if (answer
== EOF
) /* C-d */
99 /* Eat rest of input line, to EOF or newline */
103 ans2
= tui_getc (stdin
);
106 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
120 printf_filtered ("Please answer y or n.\n");
126 /* Prevent recursion of registers_changed_hook(). */
127 static int tui_refreshing_registers
= 0;
130 tui_registers_changed_hook (void)
132 struct frame_info
*fi
;
134 fi
= deprecated_selected_frame
;
135 if (fi
&& tui_refreshing_registers
== 0)
137 tui_refreshing_registers
= 1;
139 tui_check_data_values (fi
);
141 tui_refreshing_registers
= 0;
146 tui_register_changed_hook (int regno
)
148 struct frame_info
*fi
;
150 fi
= deprecated_selected_frame
;
151 if (fi
&& tui_refreshing_registers
== 0)
153 tui_refreshing_registers
= 1;
154 tui_check_data_values (fi
);
155 tui_refreshing_registers
= 0;
159 /* Breakpoint creation hook.
160 Update the screen to show the new breakpoint. */
162 tui_event_create_breakpoint (int number
)
164 tui_update_all_breakpoint_info ();
167 /* Breakpoint deletion hook.
168 Refresh the screen to update the breakpoint marks. */
170 tui_event_delete_breakpoint (int number
)
172 tui_update_all_breakpoint_info ();
176 tui_event_modify_breakpoint (int number
)
178 tui_update_all_breakpoint_info ();
182 tui_event_default (int number
)
187 static struct gdb_events
*tui_old_event_hooks
;
189 static struct gdb_events tui_event_hooks
=
191 tui_event_create_breakpoint
,
192 tui_event_delete_breakpoint
,
193 tui_event_modify_breakpoint
,
199 /* Called when going to wait for the target.
200 Leave curses mode and setup program mode. */
202 tui_target_wait_hook (ptid_t pid
, struct target_waitstatus
*status
)
206 /* Leave tui mode (optional). */
210 target_terminal_ours ();
212 target_terminal_inferior ();
215 tui_target_has_run
= 1;
216 res
= target_wait (pid
, status
);
220 /* TODO: need to refresh (optional). */
225 /* The selected frame has changed. This is happens after a target
226 stop or when the user explicitly changes the frame (up/down/thread/...). */
228 tui_selected_frame_level_changed_hook (int level
)
230 struct frame_info
*fi
;
232 fi
= deprecated_selected_frame
;
233 /* Ensure that symbols for this frame are read in. Also, determine the
234 source language of this frame, and switch to it if desired. */
239 s
= find_pc_symtab (get_frame_pc (fi
));
240 /* elz: this if here fixes the problem with the pc not being displayed
241 in the tui asm layout, with no debug symbols. The value of s
242 would be 0 here, and select_source_symtab would abort the
243 command by calling the 'error' function */
245 select_source_symtab (s
);
247 /* Display the frame position (even if there is no symbols). */
248 tui_show_frame_info (fi
);
250 /* Refresh the register window if it's visible. */
251 if (tui_is_window_visible (DATA_WIN
))
253 tui_refreshing_registers
= 1;
254 tui_check_data_values (fi
);
255 tui_refreshing_registers
= 0;
260 /* Called from print_frame_info to list the line we stopped in. */
262 tui_print_frame_info_listing_hook (struct symtab
*s
, int line
,
263 int stopline
, int noerror
)
265 select_source_symtab (s
);
266 tui_show_frame_info (deprecated_selected_frame
);
269 /* Called when the target process died or is detached.
270 Update the status line. */
272 tui_detach_hook (void)
274 tui_show_frame_info (0);
278 /* Install the TUI specific hooks. */
280 tui_install_hooks (void)
282 target_wait_hook
= tui_target_wait_hook
;
283 selected_frame_level_changed_hook
= tui_selected_frame_level_changed_hook
;
284 print_frame_info_listing_hook
= tui_print_frame_info_listing_hook
;
286 query_hook
= tui_query_hook
;
288 /* Install the event hooks. */
289 tui_old_event_hooks
= set_gdb_event_hooks (&tui_event_hooks
);
291 registers_changed_hook
= tui_registers_changed_hook
;
292 register_changed_hook
= tui_register_changed_hook
;
293 detach_hook
= tui_detach_hook
;
296 /* Remove the TUI specific hooks. */
298 tui_remove_hooks (void)
300 target_wait_hook
= 0;
301 selected_frame_level_changed_hook
= 0;
302 print_frame_info_listing_hook
= 0;
304 registers_changed_hook
= 0;
305 register_changed_hook
= 0;
308 /* Restore the previous event hooks. */
309 set_gdb_event_hooks (tui_old_event_hooks
);
312 void _initialize_tui_hooks (void);
315 _initialize_tui_hooks (void)
317 /* Install the permanent hooks. */
318 tui_target_new_objfile_chain
= target_new_objfile_hook
;
319 target_new_objfile_hook
= tui_new_objfile_hook
;