Commit | Line | Data |
---|---|---|
2611b1a5 | 1 | /* GDB hooks for TUI. |
f33c6cbf | 2 | |
c5a57081 | 3 | Copyright (C) 2001-2012 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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
2611b1a5 SC |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2611b1a5 SC |
19 | |
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
22 | #include "inferior.h" | |
23 | #include "command.h" | |
24 | #include "bfd.h" | |
25 | #include "symfile.h" | |
26 | #include "objfiles.h" | |
27 | #include "target.h" | |
28 | #include "gdbcore.h" | |
29 | #include "event-loop.h" | |
2b68e2c5 | 30 | #include "event-top.h" |
2611b1a5 SC |
31 | #include "frame.h" |
32 | #include "breakpoint.h" | |
2b68e2c5 SC |
33 | #include "ui-out.h" |
34 | #include "top.h" | |
06d3b283 | 35 | #include "observer.h" |
2611b1a5 SC |
36 | #include <unistd.h> |
37 | #include <fcntl.h> | |
38 | ||
d7b2e967 | 39 | #include "tui/tui.h" |
6a83354a | 40 | #include "tui/tui-hooks.h" |
d7b2e967 AC |
41 | #include "tui/tui-data.h" |
42 | #include "tui/tui-layout.h" | |
43 | #include "tui/tui-io.h" | |
44 | #include "tui/tui-regs.h" | |
45 | #include "tui/tui-win.h" | |
46 | #include "tui/tui-stack.h" | |
47 | #include "tui/tui-windata.h" | |
48 | #include "tui/tui-winsource.h" | |
2611b1a5 | 49 | |
6a83354a | 50 | #include "gdb_curses.h" |
96ec9981 | 51 | |
4a1bcc8c MK |
52 | /* This redefines CTRL if it is not already defined, so it must come |
53 | after terminal state releated include files like <term.h> and | |
54 | "gdb_curses.h". */ | |
55 | #include "readline/readline.h" | |
56 | ||
2611b1a5 SC |
57 | int tui_target_has_run = 0; |
58 | ||
2611b1a5 SC |
59 | static void |
60 | tui_new_objfile_hook (struct objfile* objfile) | |
61 | { | |
62 | if (tui_active) | |
1f393769 | 63 | tui_display_main (); |
2611b1a5 SC |
64 | } |
65 | ||
a0b31db1 | 66 | static int ATTRIBUTE_PRINTF (1, 0) |
5b6fe301 | 67 | tui_query_hook (const char *msg, va_list argp) |
2611b1a5 SC |
68 | { |
69 | int retval; | |
70 | int ans2; | |
71 | int answer; | |
b09846a9 PA |
72 | char *question; |
73 | struct cleanup *old_chain; | |
74 | ||
75 | /* Format the question outside of the loop, to avoid reusing | |
76 | ARGP. */ | |
77 | question = xstrvprintf (msg, argp); | |
78 | old_chain = make_cleanup (xfree, question); | |
2611b1a5 | 79 | |
2611b1a5 SC |
80 | echo (); |
81 | while (1) | |
82 | { | |
1cc6d956 | 83 | wrap_here (""); /* Flush any buffered output. */ |
2611b1a5 SC |
84 | gdb_flush (gdb_stdout); |
85 | ||
b09846a9 | 86 | fputs_filtered (question, gdb_stdout); |
a3f17187 | 87 | printf_filtered (_("(y or n) ")); |
2611b1a5 SC |
88 | |
89 | wrap_here (""); | |
90 | gdb_flush (gdb_stdout); | |
91 | ||
92 | answer = tui_getc (stdin); | |
93 | clearerr (stdin); /* in case of C-d */ | |
94 | if (answer == EOF) /* C-d */ | |
95 | { | |
96 | retval = 1; | |
97 | break; | |
98 | } | |
1cc6d956 | 99 | /* Eat rest of input line, to EOF or newline. */ |
2611b1a5 SC |
100 | if (answer != '\n') |
101 | do | |
102 | { | |
103 | ans2 = tui_getc (stdin); | |
104 | clearerr (stdin); | |
105 | } | |
106 | while (ans2 != EOF && ans2 != '\n' && ans2 != '\r'); | |
107 | ||
108 | if (answer >= 'a') | |
109 | answer -= 040; | |
110 | if (answer == 'Y') | |
111 | { | |
112 | retval = 1; | |
113 | break; | |
114 | } | |
115 | if (answer == 'N') | |
116 | { | |
117 | retval = 0; | |
118 | break; | |
119 | } | |
a3f17187 | 120 | printf_filtered (_("Please answer y or n.\n")); |
2611b1a5 SC |
121 | } |
122 | noecho (); | |
b09846a9 PA |
123 | |
124 | do_cleanups (old_chain); | |
2611b1a5 SC |
125 | return retval; |
126 | } | |
127 | ||
3adda9d8 | 128 | /* Prevent recursion of deprecated_register_changed_hook(). */ |
2611b1a5 SC |
129 | static int tui_refreshing_registers = 0; |
130 | ||
2611b1a5 SC |
131 | static void |
132 | tui_register_changed_hook (int regno) | |
133 | { | |
134 | struct frame_info *fi; | |
135 | ||
206415a3 DJ |
136 | fi = get_selected_frame (NULL); |
137 | if (tui_refreshing_registers == 0) | |
2611b1a5 SC |
138 | { |
139 | tui_refreshing_registers = 1; | |
edae1ccf | 140 | tui_check_data_values (fi); |
2611b1a5 SC |
141 | tui_refreshing_registers = 0; |
142 | } | |
143 | } | |
144 | ||
2611b1a5 SC |
145 | /* Breakpoint creation hook. |
146 | Update the screen to show the new breakpoint. */ | |
147 | static void | |
8d3788bd | 148 | tui_event_create_breakpoint (struct breakpoint *b) |
2611b1a5 | 149 | { |
00b2bad4 | 150 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
151 | } |
152 | ||
153 | /* Breakpoint deletion hook. | |
154 | Refresh the screen to update the breakpoint marks. */ | |
155 | static void | |
8d3788bd | 156 | tui_event_delete_breakpoint (struct breakpoint *b) |
2611b1a5 | 157 | { |
00b2bad4 | 158 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
159 | } |
160 | ||
161 | static void | |
8d3788bd | 162 | tui_event_modify_breakpoint (struct breakpoint *b) |
2611b1a5 | 163 | { |
00b2bad4 | 164 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
165 | } |
166 | ||
2611b1a5 SC |
167 | /* Called when going to wait for the target. |
168 | Leave curses mode and setup program mode. */ | |
169 | static ptid_t | |
08ef48c5 | 170 | tui_target_wait_hook (ptid_t pid, |
47608cb1 | 171 | struct target_waitstatus *status, int options) |
2611b1a5 SC |
172 | { |
173 | ptid_t res; | |
174 | ||
175 | /* Leave tui mode (optional). */ | |
176 | #if 0 | |
177 | if (tui_active) | |
178 | { | |
179 | target_terminal_ours (); | |
180 | endwin (); | |
181 | target_terminal_inferior (); | |
182 | } | |
183 | #endif | |
184 | tui_target_has_run = 1; | |
47608cb1 | 185 | res = target_wait (pid, status, options); |
2611b1a5 SC |
186 | |
187 | if (tui_active) | |
188 | { | |
189 | /* TODO: need to refresh (optional). */ | |
190 | } | |
191 | return res; | |
192 | } | |
193 | ||
194 | /* The selected frame has changed. This is happens after a target | |
1cc6d956 MS |
195 | stop or when the user explicitly changes the frame |
196 | (up/down/thread/...). */ | |
2611b1a5 SC |
197 | static void |
198 | tui_selected_frame_level_changed_hook (int level) | |
199 | { | |
200 | struct frame_info *fi; | |
f23d1b92 | 201 | CORE_ADDR pc; |
2611b1a5 | 202 | |
3adda9d8 DJ |
203 | /* Negative level means that the selected frame was cleared. */ |
204 | if (level < 0) | |
205 | return; | |
206 | ||
207 | fi = get_selected_frame (NULL); | |
1cc6d956 MS |
208 | /* Ensure that symbols for this frame are read in. Also, determine |
209 | the source language of this frame, and switch to it if | |
210 | desired. */ | |
f23d1b92 | 211 | if (get_frame_pc_if_available (fi, &pc)) |
2611b1a5 SC |
212 | { |
213 | struct symtab *s; | |
f23d1b92 PA |
214 | |
215 | s = find_pc_symtab (pc); | |
1cc6d956 | 216 | /* elz: This if here fixes the problem with the pc not being |
f23d1b92 PA |
217 | displayed in the tui asm layout, with no debug symbols. The |
218 | value of s would be 0 here, and select_source_symtab would | |
219 | abort the command by calling the 'error' function. */ | |
2611b1a5 | 220 | if (s) |
f23d1b92 PA |
221 | select_source_symtab (s); |
222 | } | |
223 | ||
224 | /* Display the frame position (even if there is no symbols or the PC | |
225 | is not known). */ | |
226 | tui_show_frame_info (fi); | |
227 | ||
228 | /* Refresh the register window if it's visible. */ | |
229 | if (tui_is_window_visible (DATA_WIN)) | |
230 | { | |
231 | tui_refreshing_registers = 1; | |
232 | tui_check_data_values (fi); | |
233 | tui_refreshing_registers = 0; | |
2611b1a5 SC |
234 | } |
235 | } | |
236 | ||
237 | /* Called from print_frame_info to list the line we stopped in. */ | |
238 | static void | |
08ef48c5 MS |
239 | tui_print_frame_info_listing_hook (struct symtab *s, |
240 | int line, | |
241 | int stopline, | |
242 | int noerror) | |
2611b1a5 SC |
243 | { |
244 | select_source_symtab (s); | |
206415a3 | 245 | tui_show_frame_info (get_selected_frame (NULL)); |
2611b1a5 SC |
246 | } |
247 | ||
d69e6a33 SC |
248 | /* Perform all necessary cleanups regarding our module's inferior data |
249 | that is required after the inferior INF just exited. */ | |
250 | ||
cda8ab40 | 251 | static void |
d69e6a33 | 252 | tui_inferior_exit (struct inferior *inf) |
cda8ab40 | 253 | { |
d69e6a33 SC |
254 | /* Leave the SingleKey mode to make sure the gdb prompt is visible. */ |
255 | tui_set_key_mode (TUI_COMMAND_MODE); | |
47d3492a | 256 | tui_show_frame_info (0); |
cda8ab40 SC |
257 | tui_display_main (); |
258 | } | |
259 | ||
383f836e TT |
260 | /* Observers created when installing TUI hooks. */ |
261 | static struct observer *tui_bp_created_observer; | |
262 | static struct observer *tui_bp_deleted_observer; | |
263 | static struct observer *tui_bp_modified_observer; | |
d69e6a33 | 264 | static struct observer *tui_inferior_exit_observer; |
383f836e | 265 | |
2611b1a5 SC |
266 | /* Install the TUI specific hooks. */ |
267 | void | |
268 | tui_install_hooks (void) | |
269 | { | |
9a4105ab | 270 | deprecated_target_wait_hook = tui_target_wait_hook; |
9a2b4c1b MS |
271 | deprecated_selected_frame_level_changed_hook |
272 | = tui_selected_frame_level_changed_hook; | |
273 | deprecated_print_frame_info_listing_hook | |
274 | = tui_print_frame_info_listing_hook; | |
2611b1a5 | 275 | |
9a4105ab | 276 | deprecated_query_hook = tui_query_hook; |
2611b1a5 SC |
277 | |
278 | /* Install the event hooks. */ | |
383f836e TT |
279 | tui_bp_created_observer |
280 | = observer_attach_breakpoint_created (tui_event_create_breakpoint); | |
281 | tui_bp_deleted_observer | |
282 | = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint); | |
283 | tui_bp_modified_observer | |
284 | = observer_attach_breakpoint_modified (tui_event_modify_breakpoint); | |
d69e6a33 SC |
285 | tui_inferior_exit_observer |
286 | = observer_attach_inferior_exit (tui_inferior_exit); | |
2611b1a5 | 287 | |
9a4105ab | 288 | deprecated_register_changed_hook = tui_register_changed_hook; |
2611b1a5 SC |
289 | } |
290 | ||
291 | /* Remove the TUI specific hooks. */ | |
292 | void | |
293 | tui_remove_hooks (void) | |
294 | { | |
9a4105ab AC |
295 | deprecated_target_wait_hook = 0; |
296 | deprecated_selected_frame_level_changed_hook = 0; | |
297 | deprecated_print_frame_info_listing_hook = 0; | |
298 | deprecated_query_hook = 0; | |
9a4105ab | 299 | deprecated_register_changed_hook = 0; |
2611b1a5 | 300 | |
383f836e TT |
301 | /* Remove our observers. */ |
302 | observer_detach_breakpoint_created (tui_bp_created_observer); | |
303 | tui_bp_created_observer = NULL; | |
304 | observer_detach_breakpoint_deleted (tui_bp_deleted_observer); | |
305 | tui_bp_deleted_observer = NULL; | |
306 | observer_detach_breakpoint_modified (tui_bp_modified_observer); | |
307 | tui_bp_modified_observer = NULL; | |
d69e6a33 SC |
308 | observer_detach_inferior_exit (tui_inferior_exit_observer); |
309 | tui_inferior_exit_observer = NULL; | |
2611b1a5 SC |
310 | } |
311 | ||
021e7609 | 312 | void _initialize_tui_hooks (void); |
2b68e2c5 | 313 | |
021e7609 AC |
314 | void |
315 | _initialize_tui_hooks (void) | |
2611b1a5 | 316 | { |
2611b1a5 | 317 | /* Install the permanent hooks. */ |
06d3b283 | 318 | observer_attach_new_objfile (tui_new_objfile_hook); |
2611b1a5 | 319 | } |