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