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