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