]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-hooks.c
2004-04-21 Andrew Cagney <cagney@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / tui / tui-hooks.c
CommitLineData
2611b1a5 1/* GDB hooks for TUI.
f33c6cbf 2
47d3492a 3 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
2611b1a5
SC
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
21
22#include "defs.h"
23#include "symtab.h"
24#include "inferior.h"
25#include "command.h"
26#include "bfd.h"
27#include "symfile.h"
28#include "objfiles.h"
29#include "target.h"
30#include "gdbcore.h"
31#include "event-loop.h"
2b68e2c5 32#include "event-top.h"
2611b1a5
SC
33#include "frame.h"
34#include "breakpoint.h"
35#include "gdb-events.h"
2b68e2c5
SC
36#include "ui-out.h"
37#include "top.h"
2611b1a5
SC
38#include <unistd.h>
39#include <fcntl.h>
40
d7b2e967 41#include "tui/tui.h"
6a83354a 42#include "tui/tui-hooks.h"
d7b2e967
AC
43#include "tui/tui-data.h"
44#include "tui/tui-layout.h"
45#include "tui/tui-io.h"
46#include "tui/tui-regs.h"
47#include "tui/tui-win.h"
48#include "tui/tui-stack.h"
49#include "tui/tui-windata.h"
50#include "tui/tui-winsource.h"
2611b1a5 51
6a83354a 52#include "gdb_curses.h"
96ec9981 53
4a1bcc8c
MK
54/* This redefines CTRL if it is not already defined, so it must come
55 after terminal state releated include files like <term.h> and
56 "gdb_curses.h". */
57#include "readline/readline.h"
58
2611b1a5
SC
59int tui_target_has_run = 0;
60
61static void (* tui_target_new_objfile_chain) (struct objfile*);
2611b1a5
SC
62
63static void
64tui_new_objfile_hook (struct objfile* objfile)
65{
66 if (tui_active)
1f393769 67 tui_display_main ();
2611b1a5
SC
68
69 if (tui_target_new_objfile_chain)
70 tui_target_new_objfile_chain (objfile);
71}
72
73static int
74tui_query_hook (const char * msg, va_list argp)
75{
76 int retval;
77 int ans2;
78 int answer;
79
80 /* Automatically answer "yes" if input is not from a terminal. */
81 if (!input_from_terminal_p ())
82 return 1;
83
84 echo ();
85 while (1)
86 {
87 wrap_here (""); /* Flush any buffered output */
88 gdb_flush (gdb_stdout);
89
90 vfprintf_filtered (gdb_stdout, msg, argp);
91 printf_filtered ("(y or n) ");
92
93 wrap_here ("");
94 gdb_flush (gdb_stdout);
95
96 answer = tui_getc (stdin);
97 clearerr (stdin); /* in case of C-d */
98 if (answer == EOF) /* C-d */
99 {
100 retval = 1;
101 break;
102 }
103 /* Eat rest of input line, to EOF or newline */
104 if (answer != '\n')
105 do
106 {
107 ans2 = tui_getc (stdin);
108 clearerr (stdin);
109 }
110 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
111
112 if (answer >= 'a')
113 answer -= 040;
114 if (answer == 'Y')
115 {
116 retval = 1;
117 break;
118 }
119 if (answer == 'N')
120 {
121 retval = 0;
122 break;
123 }
124 printf_filtered ("Please answer y or n.\n");
125 }
126 noecho ();
127 return retval;
128}
129
130/* Prevent recursion of registers_changed_hook(). */
131static int tui_refreshing_registers = 0;
132
133static void
134tui_registers_changed_hook (void)
135{
136 struct frame_info *fi;
137
6e7f8b9c 138 fi = deprecated_selected_frame;
2611b1a5
SC
139 if (fi && tui_refreshing_registers == 0)
140 {
141 tui_refreshing_registers = 1;
142#if 0
6ba8e26f 143 tui_check_data_values (fi);
2611b1a5
SC
144#endif
145 tui_refreshing_registers = 0;
146 }
147}
148
149static void
150tui_register_changed_hook (int regno)
151{
152 struct frame_info *fi;
153
6e7f8b9c 154 fi = deprecated_selected_frame;
2611b1a5
SC
155 if (fi && tui_refreshing_registers == 0)
156 {
157 tui_refreshing_registers = 1;
edae1ccf 158 tui_check_data_values (fi);
2611b1a5
SC
159 tui_refreshing_registers = 0;
160 }
161}
162
2611b1a5
SC
163/* Breakpoint creation hook.
164 Update the screen to show the new breakpoint. */
165static void
166tui_event_create_breakpoint (int number)
167{
00b2bad4 168 tui_update_all_breakpoint_info ();
2611b1a5
SC
169}
170
171/* Breakpoint deletion hook.
172 Refresh the screen to update the breakpoint marks. */
173static void
174tui_event_delete_breakpoint (int number)
175{
00b2bad4 176 tui_update_all_breakpoint_info ();
2611b1a5
SC
177}
178
179static void
180tui_event_modify_breakpoint (int number)
181{
00b2bad4 182 tui_update_all_breakpoint_info ();
2611b1a5
SC
183}
184
185static void
186tui_event_default (int number)
187{
188 ;
189}
190
191static struct gdb_events *tui_old_event_hooks;
192
193static struct gdb_events tui_event_hooks =
194{
195 tui_event_create_breakpoint,
196 tui_event_delete_breakpoint,
197 tui_event_modify_breakpoint,
198 tui_event_default,
199 tui_event_default,
200 tui_event_default
201};
202
203/* Called when going to wait for the target.
204 Leave curses mode and setup program mode. */
205static ptid_t
206tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
207{
208 ptid_t res;
209
210 /* Leave tui mode (optional). */
211#if 0
212 if (tui_active)
213 {
214 target_terminal_ours ();
215 endwin ();
216 target_terminal_inferior ();
217 }
218#endif
219 tui_target_has_run = 1;
220 res = target_wait (pid, status);
221
222 if (tui_active)
223 {
224 /* TODO: need to refresh (optional). */
225 }
226 return res;
227}
228
229/* The selected frame has changed. This is happens after a target
230 stop or when the user explicitly changes the frame (up/down/thread/...). */
231static void
232tui_selected_frame_level_changed_hook (int level)
233{
234 struct frame_info *fi;
235
6e7f8b9c 236 fi = deprecated_selected_frame;
2611b1a5
SC
237 /* Ensure that symbols for this frame are read in. Also, determine the
238 source language of this frame, and switch to it if desired. */
239 if (fi)
240 {
241 struct symtab *s;
242
f70a7d61 243 s = find_pc_symtab (get_frame_pc (fi));
2611b1a5
SC
244 /* elz: this if here fixes the problem with the pc not being displayed
245 in the tui asm layout, with no debug symbols. The value of s
246 would be 0 here, and select_source_symtab would abort the
247 command by calling the 'error' function */
248 if (s)
90949d06
SC
249 select_source_symtab (s);
250
251 /* Display the frame position (even if there is no symbols). */
47d3492a 252 tui_show_frame_info (fi);
2611b1a5
SC
253
254 /* Refresh the register window if it's visible. */
255 if (tui_is_window_visible (DATA_WIN))
256 {
257 tui_refreshing_registers = 1;
edae1ccf 258 tui_check_data_values (fi);
2611b1a5
SC
259 tui_refreshing_registers = 0;
260 }
261 }
262}
263
264/* Called from print_frame_info to list the line we stopped in. */
265static void
266tui_print_frame_info_listing_hook (struct symtab *s, int line,
267 int stopline, int noerror)
268{
269 select_source_symtab (s);
47d3492a 270 tui_show_frame_info (deprecated_selected_frame);
2611b1a5
SC
271}
272
cda8ab40
SC
273/* Called when the target process died or is detached.
274 Update the status line. */
275static void
276tui_detach_hook (void)
277{
47d3492a 278 tui_show_frame_info (0);
cda8ab40
SC
279 tui_display_main ();
280}
281
2611b1a5
SC
282/* Install the TUI specific hooks. */
283void
284tui_install_hooks (void)
285{
286 target_wait_hook = tui_target_wait_hook;
287 selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
288 print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
289
290 query_hook = tui_query_hook;
291
292 /* Install the event hooks. */
293 tui_old_event_hooks = set_gdb_event_hooks (&tui_event_hooks);
294
295 registers_changed_hook = tui_registers_changed_hook;
296 register_changed_hook = tui_register_changed_hook;
cda8ab40 297 detach_hook = tui_detach_hook;
2611b1a5
SC
298}
299
300/* Remove the TUI specific hooks. */
301void
302tui_remove_hooks (void)
303{
304 target_wait_hook = 0;
305 selected_frame_level_changed_hook = 0;
306 print_frame_info_listing_hook = 0;
307 query_hook = 0;
308 registers_changed_hook = 0;
309 register_changed_hook = 0;
cda8ab40 310 detach_hook = 0;
2611b1a5
SC
311
312 /* Restore the previous event hooks. */
313 set_gdb_event_hooks (tui_old_event_hooks);
314}
315
021e7609 316void _initialize_tui_hooks (void);
2b68e2c5 317
021e7609
AC
318void
319_initialize_tui_hooks (void)
2611b1a5 320{
2611b1a5
SC
321 /* Install the permanent hooks. */
322 tui_target_new_objfile_chain = target_new_objfile_hook;
323 target_new_objfile_hook = tui_new_objfile_hook;
2611b1a5 324}