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