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