* tui-hooks.c (tui_detach_hook): New hook to know when a process dies.
[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"
49#include "frame.h"
50#include "breakpoint.h"
51#include "gdb-events.h"
52#include <unistd.h>
53#include <fcntl.h>
54
55#include "tui.h"
56#include "tuiData.h"
57#include "tuiLayout.h"
58#include "tuiIO.h"
59#include "tuiRegs.h"
60#include "tuiWin.h"
61#include "tuiStack.h"
62#include "tuiDataWin.h"
63#include "tuiSourceWin.h"
64
65int tui_target_has_run = 0;
66
67static void (* tui_target_new_objfile_chain) (struct objfile*);
68extern void (*selected_frame_level_changed_hook) (int);
69
70static void
71tui_new_objfile_hook (struct objfile* objfile)
72{
73 if (tui_active)
1f393769 74 tui_display_main ();
2611b1a5
SC
75
76 if (tui_target_new_objfile_chain)
77 tui_target_new_objfile_chain (objfile);
78}
79
80static int
81tui_query_hook (const char * msg, va_list argp)
82{
83 int retval;
84 int ans2;
85 int answer;
86
87 /* Automatically answer "yes" if input is not from a terminal. */
88 if (!input_from_terminal_p ())
89 return 1;
90
91 echo ();
92 while (1)
93 {
94 wrap_here (""); /* Flush any buffered output */
95 gdb_flush (gdb_stdout);
96
97 vfprintf_filtered (gdb_stdout, msg, argp);
98 printf_filtered ("(y or n) ");
99
100 wrap_here ("");
101 gdb_flush (gdb_stdout);
102
103 answer = tui_getc (stdin);
104 clearerr (stdin); /* in case of C-d */
105 if (answer == EOF) /* C-d */
106 {
107 retval = 1;
108 break;
109 }
110 /* Eat rest of input line, to EOF or newline */
111 if (answer != '\n')
112 do
113 {
114 ans2 = tui_getc (stdin);
115 clearerr (stdin);
116 }
117 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
118
119 if (answer >= 'a')
120 answer -= 040;
121 if (answer == 'Y')
122 {
123 retval = 1;
124 break;
125 }
126 if (answer == 'N')
127 {
128 retval = 0;
129 break;
130 }
131 printf_filtered ("Please answer y or n.\n");
132 }
133 noecho ();
134 return retval;
135}
136
137/* Prevent recursion of registers_changed_hook(). */
138static int tui_refreshing_registers = 0;
139
140static void
141tui_registers_changed_hook (void)
142{
143 struct frame_info *fi;
144
145 fi = selected_frame;
146 if (fi && tui_refreshing_registers == 0)
147 {
148 tui_refreshing_registers = 1;
149#if 0
150 tuiCheckDataValues (fi);
151#endif
152 tui_refreshing_registers = 0;
153 }
154}
155
156static void
157tui_register_changed_hook (int regno)
158{
159 struct frame_info *fi;
160
161 fi = selected_frame;
162 if (fi && tui_refreshing_registers == 0)
163 {
164 tui_refreshing_registers = 1;
165 tuiCheckDataValues (fi);
166 tui_refreshing_registers = 0;
167 }
168}
169
2611b1a5
SC
170/* Breakpoint creation hook.
171 Update the screen to show the new breakpoint. */
172static void
173tui_event_create_breakpoint (int number)
174{
00b2bad4 175 tui_update_all_breakpoint_info ();
2611b1a5
SC
176}
177
178/* Breakpoint deletion hook.
179 Refresh the screen to update the breakpoint marks. */
180static void
181tui_event_delete_breakpoint (int number)
182{
00b2bad4 183 tui_update_all_breakpoint_info ();
2611b1a5
SC
184}
185
186static void
187tui_event_modify_breakpoint (int number)
188{
00b2bad4 189 tui_update_all_breakpoint_info ();
2611b1a5
SC
190}
191
192static void
193tui_event_default (int number)
194{
195 ;
196}
197
198static struct gdb_events *tui_old_event_hooks;
199
200static struct gdb_events tui_event_hooks =
201{
202 tui_event_create_breakpoint,
203 tui_event_delete_breakpoint,
204 tui_event_modify_breakpoint,
205 tui_event_default,
206 tui_event_default,
207 tui_event_default
208};
209
210/* Called when going to wait for the target.
211 Leave curses mode and setup program mode. */
212static ptid_t
213tui_target_wait_hook (ptid_t pid, struct target_waitstatus *status)
214{
215 ptid_t res;
216
217 /* Leave tui mode (optional). */
218#if 0
219 if (tui_active)
220 {
221 target_terminal_ours ();
222 endwin ();
223 target_terminal_inferior ();
224 }
225#endif
226 tui_target_has_run = 1;
227 res = target_wait (pid, status);
228
229 if (tui_active)
230 {
231 /* TODO: need to refresh (optional). */
232 }
233 return res;
234}
235
236/* The selected frame has changed. This is happens after a target
237 stop or when the user explicitly changes the frame (up/down/thread/...). */
238static void
239tui_selected_frame_level_changed_hook (int level)
240{
241 struct frame_info *fi;
242
243 fi = selected_frame;
244 /* Ensure that symbols for this frame are read in. Also, determine the
245 source language of this frame, and switch to it if desired. */
246 if (fi)
247 {
248 struct symtab *s;
249
250 s = find_pc_symtab (fi->pc);
251 /* elz: this if here fixes the problem with the pc not being displayed
252 in the tui asm layout, with no debug symbols. The value of s
253 would be 0 here, and select_source_symtab would abort the
254 command by calling the 'error' function */
255 if (s)
90949d06
SC
256 select_source_symtab (s);
257
258 /* Display the frame position (even if there is no symbols). */
259 tuiShowFrameInfo (fi);
2611b1a5
SC
260
261 /* Refresh the register window if it's visible. */
262 if (tui_is_window_visible (DATA_WIN))
263 {
264 tui_refreshing_registers = 1;
265 tuiCheckDataValues (fi);
266 tui_refreshing_registers = 0;
267 }
268 }
269}
270
271/* Called from print_frame_info to list the line we stopped in. */
272static void
273tui_print_frame_info_listing_hook (struct symtab *s, int line,
274 int stopline, int noerror)
275{
276 select_source_symtab (s);
277 tuiShowFrameInfo (selected_frame);
278}
279
cda8ab40
SC
280/* Called when the target process died or is detached.
281 Update the status line. */
282static void
283tui_detach_hook (void)
284{
285 tuiShowFrameInfo (0);
286 tui_display_main ();
287}
288
2611b1a5
SC
289/* Install the TUI specific hooks. */
290void
291tui_install_hooks (void)
292{
293 target_wait_hook = tui_target_wait_hook;
294 selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
295 print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
296
297 query_hook = tui_query_hook;
298
299 /* Install the event hooks. */
300 tui_old_event_hooks = set_gdb_event_hooks (&tui_event_hooks);
301
302 registers_changed_hook = tui_registers_changed_hook;
303 register_changed_hook = tui_register_changed_hook;
cda8ab40 304 detach_hook = tui_detach_hook;
2611b1a5
SC
305}
306
307/* Remove the TUI specific hooks. */
308void
309tui_remove_hooks (void)
310{
311 target_wait_hook = 0;
312 selected_frame_level_changed_hook = 0;
313 print_frame_info_listing_hook = 0;
314 query_hook = 0;
315 registers_changed_hook = 0;
316 register_changed_hook = 0;
cda8ab40 317 detach_hook = 0;
2611b1a5
SC
318
319 /* Restore the previous event hooks. */
320 set_gdb_event_hooks (tui_old_event_hooks);
321}
322
323/* Cleanup the tui before exiting. */
324static void
325tui_exit (void)
326{
327 /* Disable the tui. Curses mode is left leaving the screen
328 in a clean state (see endwin()). */
329 tui_disable ();
330}
331
332/* Initialize the tui by installing several gdb hooks, initializing
333 the tui IO and preparing the readline with the kind binding. */
334static void
335tui_init_hook (char *argv0)
336{
337 /* Install exit handler to leave the screen in a good shape. */
338 atexit (tui_exit);
339
340 initializeStaticData ();
341
342 /* Install the permanent hooks. */
343 tui_target_new_objfile_chain = target_new_objfile_hook;
344 target_new_objfile_hook = tui_new_objfile_hook;
345
346 tui_initialize_io ();
347 tui_initialize_readline ();
348
349 /* Decide in which mode to start using GDB (based on -tui). */
350 if (tui_version)
351 {
352 tui_enable ();
353 }
354}
355
356/* Initialize the tui. */
357void
358_initialize_tui (void)
359{
360 /* Setup initialization hook. */
361 init_ui_hook = tui_init_hook;
362}
363
This page took 0.152737 seconds and 4 git commands to generate.