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; | |
72 | ||
2611b1a5 SC |
73 | echo (); |
74 | while (1) | |
75 | { | |
1cc6d956 | 76 | wrap_here (""); /* Flush any buffered output. */ |
2611b1a5 SC |
77 | gdb_flush (gdb_stdout); |
78 | ||
79 | vfprintf_filtered (gdb_stdout, msg, argp); | |
a3f17187 | 80 | printf_filtered (_("(y or n) ")); |
2611b1a5 SC |
81 | |
82 | wrap_here (""); | |
83 | gdb_flush (gdb_stdout); | |
84 | ||
85 | answer = tui_getc (stdin); | |
86 | clearerr (stdin); /* in case of C-d */ | |
87 | if (answer == EOF) /* C-d */ | |
88 | { | |
89 | retval = 1; | |
90 | break; | |
91 | } | |
1cc6d956 | 92 | /* Eat rest of input line, to EOF or newline. */ |
2611b1a5 SC |
93 | if (answer != '\n') |
94 | do | |
95 | { | |
96 | ans2 = tui_getc (stdin); | |
97 | clearerr (stdin); | |
98 | } | |
99 | while (ans2 != EOF && ans2 != '\n' && ans2 != '\r'); | |
100 | ||
101 | if (answer >= 'a') | |
102 | answer -= 040; | |
103 | if (answer == 'Y') | |
104 | { | |
105 | retval = 1; | |
106 | break; | |
107 | } | |
108 | if (answer == 'N') | |
109 | { | |
110 | retval = 0; | |
111 | break; | |
112 | } | |
a3f17187 | 113 | printf_filtered (_("Please answer y or n.\n")); |
2611b1a5 SC |
114 | } |
115 | noecho (); | |
116 | return retval; | |
117 | } | |
118 | ||
3adda9d8 | 119 | /* Prevent recursion of deprecated_register_changed_hook(). */ |
2611b1a5 SC |
120 | static int tui_refreshing_registers = 0; |
121 | ||
2611b1a5 SC |
122 | static void |
123 | tui_register_changed_hook (int regno) | |
124 | { | |
125 | struct frame_info *fi; | |
126 | ||
206415a3 DJ |
127 | fi = get_selected_frame (NULL); |
128 | if (tui_refreshing_registers == 0) | |
2611b1a5 SC |
129 | { |
130 | tui_refreshing_registers = 1; | |
edae1ccf | 131 | tui_check_data_values (fi); |
2611b1a5 SC |
132 | tui_refreshing_registers = 0; |
133 | } | |
134 | } | |
135 | ||
2611b1a5 SC |
136 | /* Breakpoint creation hook. |
137 | Update the screen to show the new breakpoint. */ | |
138 | static void | |
8d3788bd | 139 | tui_event_create_breakpoint (struct breakpoint *b) |
2611b1a5 | 140 | { |
00b2bad4 | 141 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
142 | } |
143 | ||
144 | /* Breakpoint deletion hook. | |
145 | Refresh the screen to update the breakpoint marks. */ | |
146 | static void | |
8d3788bd | 147 | tui_event_delete_breakpoint (struct breakpoint *b) |
2611b1a5 | 148 | { |
00b2bad4 | 149 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
150 | } |
151 | ||
152 | static void | |
8d3788bd | 153 | tui_event_modify_breakpoint (struct breakpoint *b) |
2611b1a5 | 154 | { |
00b2bad4 | 155 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
156 | } |
157 | ||
2611b1a5 SC |
158 | /* Called when going to wait for the target. |
159 | Leave curses mode and setup program mode. */ | |
160 | static ptid_t | |
08ef48c5 | 161 | tui_target_wait_hook (ptid_t pid, |
47608cb1 | 162 | struct target_waitstatus *status, int options) |
2611b1a5 SC |
163 | { |
164 | ptid_t res; | |
165 | ||
166 | /* Leave tui mode (optional). */ | |
167 | #if 0 | |
168 | if (tui_active) | |
169 | { | |
170 | target_terminal_ours (); | |
171 | endwin (); | |
172 | target_terminal_inferior (); | |
173 | } | |
174 | #endif | |
175 | tui_target_has_run = 1; | |
47608cb1 | 176 | res = target_wait (pid, status, options); |
2611b1a5 SC |
177 | |
178 | if (tui_active) | |
179 | { | |
180 | /* TODO: need to refresh (optional). */ | |
181 | } | |
182 | return res; | |
183 | } | |
184 | ||
185 | /* The selected frame has changed. This is happens after a target | |
1cc6d956 MS |
186 | stop or when the user explicitly changes the frame |
187 | (up/down/thread/...). */ | |
2611b1a5 SC |
188 | static void |
189 | tui_selected_frame_level_changed_hook (int level) | |
190 | { | |
191 | struct frame_info *fi; | |
f23d1b92 | 192 | CORE_ADDR pc; |
2611b1a5 | 193 | |
3adda9d8 DJ |
194 | /* Negative level means that the selected frame was cleared. */ |
195 | if (level < 0) | |
196 | return; | |
197 | ||
198 | fi = get_selected_frame (NULL); | |
1cc6d956 MS |
199 | /* Ensure that symbols for this frame are read in. Also, determine |
200 | the source language of this frame, and switch to it if | |
201 | desired. */ | |
f23d1b92 | 202 | if (get_frame_pc_if_available (fi, &pc)) |
2611b1a5 SC |
203 | { |
204 | struct symtab *s; | |
f23d1b92 PA |
205 | |
206 | s = find_pc_symtab (pc); | |
1cc6d956 | 207 | /* elz: This if here fixes the problem with the pc not being |
f23d1b92 PA |
208 | displayed in the tui asm layout, with no debug symbols. The |
209 | value of s would be 0 here, and select_source_symtab would | |
210 | abort the command by calling the 'error' function. */ | |
2611b1a5 | 211 | if (s) |
f23d1b92 PA |
212 | select_source_symtab (s); |
213 | } | |
214 | ||
215 | /* Display the frame position (even if there is no symbols or the PC | |
216 | is not known). */ | |
217 | tui_show_frame_info (fi); | |
218 | ||
219 | /* Refresh the register window if it's visible. */ | |
220 | if (tui_is_window_visible (DATA_WIN)) | |
221 | { | |
222 | tui_refreshing_registers = 1; | |
223 | tui_check_data_values (fi); | |
224 | tui_refreshing_registers = 0; | |
2611b1a5 SC |
225 | } |
226 | } | |
227 | ||
228 | /* Called from print_frame_info to list the line we stopped in. */ | |
229 | static void | |
08ef48c5 MS |
230 | tui_print_frame_info_listing_hook (struct symtab *s, |
231 | int line, | |
232 | int stopline, | |
233 | int noerror) | |
2611b1a5 SC |
234 | { |
235 | select_source_symtab (s); | |
206415a3 | 236 | tui_show_frame_info (get_selected_frame (NULL)); |
2611b1a5 SC |
237 | } |
238 | ||
cda8ab40 SC |
239 | /* Called when the target process died or is detached. |
240 | Update the status line. */ | |
241 | static void | |
242 | tui_detach_hook (void) | |
243 | { | |
47d3492a | 244 | tui_show_frame_info (0); |
cda8ab40 SC |
245 | tui_display_main (); |
246 | } | |
247 | ||
383f836e TT |
248 | /* Observers created when installing TUI hooks. */ |
249 | static struct observer *tui_bp_created_observer; | |
250 | static struct observer *tui_bp_deleted_observer; | |
251 | static struct observer *tui_bp_modified_observer; | |
252 | ||
2611b1a5 SC |
253 | /* Install the TUI specific hooks. */ |
254 | void | |
255 | tui_install_hooks (void) | |
256 | { | |
9a4105ab | 257 | deprecated_target_wait_hook = tui_target_wait_hook; |
9a2b4c1b MS |
258 | deprecated_selected_frame_level_changed_hook |
259 | = tui_selected_frame_level_changed_hook; | |
260 | deprecated_print_frame_info_listing_hook | |
261 | = tui_print_frame_info_listing_hook; | |
2611b1a5 | 262 | |
9a4105ab | 263 | deprecated_query_hook = tui_query_hook; |
2611b1a5 SC |
264 | |
265 | /* Install the event hooks. */ | |
383f836e TT |
266 | tui_bp_created_observer |
267 | = observer_attach_breakpoint_created (tui_event_create_breakpoint); | |
268 | tui_bp_deleted_observer | |
269 | = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint); | |
270 | tui_bp_modified_observer | |
271 | = observer_attach_breakpoint_modified (tui_event_modify_breakpoint); | |
2611b1a5 | 272 | |
9a4105ab AC |
273 | deprecated_register_changed_hook = tui_register_changed_hook; |
274 | deprecated_detach_hook = tui_detach_hook; | |
2611b1a5 SC |
275 | } |
276 | ||
277 | /* Remove the TUI specific hooks. */ | |
278 | void | |
279 | tui_remove_hooks (void) | |
280 | { | |
9a4105ab AC |
281 | deprecated_target_wait_hook = 0; |
282 | deprecated_selected_frame_level_changed_hook = 0; | |
283 | deprecated_print_frame_info_listing_hook = 0; | |
284 | deprecated_query_hook = 0; | |
9a4105ab AC |
285 | deprecated_register_changed_hook = 0; |
286 | deprecated_detach_hook = 0; | |
2611b1a5 | 287 | |
383f836e TT |
288 | /* Remove our observers. */ |
289 | observer_detach_breakpoint_created (tui_bp_created_observer); | |
290 | tui_bp_created_observer = NULL; | |
291 | observer_detach_breakpoint_deleted (tui_bp_deleted_observer); | |
292 | tui_bp_deleted_observer = NULL; | |
293 | observer_detach_breakpoint_modified (tui_bp_modified_observer); | |
294 | tui_bp_modified_observer = NULL; | |
2611b1a5 SC |
295 | } |
296 | ||
021e7609 | 297 | void _initialize_tui_hooks (void); |
2b68e2c5 | 298 | |
021e7609 AC |
299 | void |
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 | } |