Switch the license of all .c files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / tui / tui-hooks.c
CommitLineData
2611b1a5 1/* GDB hooks for TUI.
f33c6cbf 2
6aba47ca 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
698ba934 4 Free Software Foundation, Inc.
2611b1a5
SC
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
2611b1a5
SC
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
2611b1a5
SC
20
21#include "defs.h"
22#include "symtab.h"
23#include "inferior.h"
24#include "command.h"
25#include "bfd.h"
26#include "symfile.h"
27#include "objfiles.h"
28#include "target.h"
29#include "gdbcore.h"
30#include "event-loop.h"
2b68e2c5 31#include "event-top.h"
2611b1a5
SC
32#include "frame.h"
33#include "breakpoint.h"
34#include "gdb-events.h"
2b68e2c5
SC
35#include "ui-out.h"
36#include "top.h"
06d3b283 37#include "observer.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
2611b1a5
SC
61static void
62tui_new_objfile_hook (struct objfile* objfile)
63{
64 if (tui_active)
1f393769 65 tui_display_main ();
2611b1a5
SC
66}
67
bee0189a 68static int ATTR_FORMAT (printf, 1, 0)
5b6fe301 69tui_query_hook (const char *msg, va_list argp)
2611b1a5
SC
70{
71 int retval;
72 int ans2;
73 int answer;
74
2611b1a5
SC
75 echo ();
76 while (1)
77 {
1cc6d956 78 wrap_here (""); /* Flush any buffered output. */
2611b1a5
SC
79 gdb_flush (gdb_stdout);
80
81 vfprintf_filtered (gdb_stdout, msg, argp);
a3f17187 82 printf_filtered (_("(y or n) "));
2611b1a5
SC
83
84 wrap_here ("");
85 gdb_flush (gdb_stdout);
86
87 answer = tui_getc (stdin);
88 clearerr (stdin); /* in case of C-d */
89 if (answer == EOF) /* C-d */
90 {
91 retval = 1;
92 break;
93 }
1cc6d956 94 /* Eat rest of input line, to EOF or newline. */
2611b1a5
SC
95 if (answer != '\n')
96 do
97 {
98 ans2 = tui_getc (stdin);
99 clearerr (stdin);
100 }
101 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
102
103 if (answer >= 'a')
104 answer -= 040;
105 if (answer == 'Y')
106 {
107 retval = 1;
108 break;
109 }
110 if (answer == 'N')
111 {
112 retval = 0;
113 break;
114 }
a3f17187 115 printf_filtered (_("Please answer y or n.\n"));
2611b1a5
SC
116 }
117 noecho ();
118 return retval;
119}
120
3adda9d8 121/* Prevent recursion of deprecated_register_changed_hook(). */
2611b1a5
SC
122static int tui_refreshing_registers = 0;
123
2611b1a5
SC
124static void
125tui_register_changed_hook (int regno)
126{
127 struct frame_info *fi;
128
206415a3
DJ
129 fi = get_selected_frame (NULL);
130 if (tui_refreshing_registers == 0)
2611b1a5
SC
131 {
132 tui_refreshing_registers = 1;
edae1ccf 133 tui_check_data_values (fi);
2611b1a5
SC
134 tui_refreshing_registers = 0;
135 }
136}
137
2611b1a5
SC
138/* Breakpoint creation hook.
139 Update the screen to show the new breakpoint. */
140static void
141tui_event_create_breakpoint (int number)
142{
00b2bad4 143 tui_update_all_breakpoint_info ();
2611b1a5
SC
144}
145
146/* Breakpoint deletion hook.
147 Refresh the screen to update the breakpoint marks. */
148static void
149tui_event_delete_breakpoint (int number)
150{
00b2bad4 151 tui_update_all_breakpoint_info ();
2611b1a5
SC
152}
153
154static void
155tui_event_modify_breakpoint (int number)
156{
00b2bad4 157 tui_update_all_breakpoint_info ();
2611b1a5
SC
158}
159
160static void
161tui_event_default (int number)
162{
163 ;
164}
165
166static struct gdb_events *tui_old_event_hooks;
167
08ef48c5 168static struct gdb_events tui_event_hooks = {
2611b1a5
SC
169 tui_event_create_breakpoint,
170 tui_event_delete_breakpoint,
171 tui_event_modify_breakpoint,
172 tui_event_default,
173 tui_event_default,
174 tui_event_default
175};
176
177/* Called when going to wait for the target.
178 Leave curses mode and setup program mode. */
179static ptid_t
08ef48c5
MS
180tui_target_wait_hook (ptid_t pid,
181 struct target_waitstatus *status)
2611b1a5
SC
182{
183 ptid_t res;
184
185 /* Leave tui mode (optional). */
186#if 0
187 if (tui_active)
188 {
189 target_terminal_ours ();
190 endwin ();
191 target_terminal_inferior ();
192 }
193#endif
194 tui_target_has_run = 1;
195 res = target_wait (pid, status);
196
197 if (tui_active)
198 {
199 /* TODO: need to refresh (optional). */
200 }
201 return res;
202}
203
204/* The selected frame has changed. This is happens after a target
1cc6d956
MS
205 stop or when the user explicitly changes the frame
206 (up/down/thread/...). */
2611b1a5
SC
207static void
208tui_selected_frame_level_changed_hook (int level)
209{
210 struct frame_info *fi;
211
3adda9d8
DJ
212 /* Negative level means that the selected frame was cleared. */
213 if (level < 0)
214 return;
215
216 fi = get_selected_frame (NULL);
1cc6d956
MS
217 /* Ensure that symbols for this frame are read in. Also, determine
218 the source language of this frame, and switch to it if
219 desired. */
2611b1a5
SC
220 if (fi)
221 {
222 struct symtab *s;
223
f70a7d61 224 s = find_pc_symtab (get_frame_pc (fi));
1cc6d956
MS
225 /* elz: This if here fixes the problem with the pc not being
226 displayed in the tui asm layout, with no debug symbols. The
227 value of s would be 0 here, and select_source_symtab would
228 abort the command by calling the 'error' function. */
2611b1a5 229 if (s)
90949d06
SC
230 select_source_symtab (s);
231
232 /* Display the frame position (even if there is no symbols). */
47d3492a 233 tui_show_frame_info (fi);
2611b1a5
SC
234
235 /* Refresh the register window if it's visible. */
236 if (tui_is_window_visible (DATA_WIN))
237 {
238 tui_refreshing_registers = 1;
edae1ccf 239 tui_check_data_values (fi);
2611b1a5
SC
240 tui_refreshing_registers = 0;
241 }
242 }
243}
244
245/* Called from print_frame_info to list the line we stopped in. */
246static void
08ef48c5
MS
247tui_print_frame_info_listing_hook (struct symtab *s,
248 int line,
249 int stopline,
250 int noerror)
2611b1a5
SC
251{
252 select_source_symtab (s);
206415a3 253 tui_show_frame_info (get_selected_frame (NULL));
2611b1a5
SC
254}
255
cda8ab40
SC
256/* Called when the target process died or is detached.
257 Update the status line. */
258static void
259tui_detach_hook (void)
260{
47d3492a 261 tui_show_frame_info (0);
cda8ab40
SC
262 tui_display_main ();
263}
264
2611b1a5
SC
265/* Install the TUI specific hooks. */
266void
267tui_install_hooks (void)
268{
9a4105ab
AC
269 deprecated_target_wait_hook = tui_target_wait_hook;
270 deprecated_selected_frame_level_changed_hook = tui_selected_frame_level_changed_hook;
271 deprecated_print_frame_info_listing_hook = tui_print_frame_info_listing_hook;
2611b1a5 272
9a4105ab 273 deprecated_query_hook = tui_query_hook;
2611b1a5
SC
274
275 /* Install the event hooks. */
2726dafc 276 tui_old_event_hooks = deprecated_set_gdb_event_hooks (&tui_event_hooks);
2611b1a5 277
9a4105ab
AC
278 deprecated_register_changed_hook = tui_register_changed_hook;
279 deprecated_detach_hook = tui_detach_hook;
2611b1a5
SC
280}
281
282/* Remove the TUI specific hooks. */
283void
284tui_remove_hooks (void)
285{
9a4105ab
AC
286 deprecated_target_wait_hook = 0;
287 deprecated_selected_frame_level_changed_hook = 0;
288 deprecated_print_frame_info_listing_hook = 0;
289 deprecated_query_hook = 0;
9a4105ab
AC
290 deprecated_register_changed_hook = 0;
291 deprecated_detach_hook = 0;
2611b1a5
SC
292
293 /* Restore the previous event hooks. */
2726dafc 294 deprecated_set_gdb_event_hooks (tui_old_event_hooks);
2611b1a5
SC
295}
296
021e7609 297void _initialize_tui_hooks (void);
2b68e2c5 298
021e7609
AC
299void
300_initialize_tui_hooks (void)
2611b1a5 301{
2611b1a5 302 /* Install the permanent hooks. */
06d3b283 303 observer_attach_new_objfile (tui_new_objfile_hook);
2611b1a5 304}
This page took 1.257871 seconds and 4 git commands to generate.