Commit | Line | Data |
---|---|---|
2611b1a5 | 1 | /* GDB hooks for TUI. |
f33c6cbf | 2 | |
32d0add0 | 3 | Copyright (C) 2001-2015 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 | ||
3adda9d8 | 66 | /* Prevent recursion of deprecated_register_changed_hook(). */ |
2611b1a5 SC |
67 | static int tui_refreshing_registers = 0; |
68 | ||
a9bd710f PP |
69 | /* Observer for the register_changed notification. */ |
70 | ||
2611b1a5 | 71 | static void |
a9bd710f | 72 | tui_register_changed (struct frame_info *frame, int regno) |
2611b1a5 SC |
73 | { |
74 | struct frame_info *fi; | |
75 | ||
a9bd710f PP |
76 | /* The frame of the register that was changed may differ from the selected |
77 | frame, but we only want to show the register values of the selected frame. | |
78 | And even if the frames differ a register change made in one can still show | |
79 | up in the other. So we always use the selected frame here, and ignore | |
80 | FRAME. */ | |
206415a3 DJ |
81 | fi = get_selected_frame (NULL); |
82 | if (tui_refreshing_registers == 0) | |
2611b1a5 SC |
83 | { |
84 | tui_refreshing_registers = 1; | |
edae1ccf | 85 | tui_check_data_values (fi); |
2611b1a5 SC |
86 | tui_refreshing_registers = 0; |
87 | } | |
88 | } | |
89 | ||
2611b1a5 SC |
90 | /* Breakpoint creation hook. |
91 | Update the screen to show the new breakpoint. */ | |
92 | static void | |
8d3788bd | 93 | tui_event_create_breakpoint (struct breakpoint *b) |
2611b1a5 | 94 | { |
00b2bad4 | 95 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
96 | } |
97 | ||
98 | /* Breakpoint deletion hook. | |
99 | Refresh the screen to update the breakpoint marks. */ | |
100 | static void | |
8d3788bd | 101 | tui_event_delete_breakpoint (struct breakpoint *b) |
2611b1a5 | 102 | { |
00b2bad4 | 103 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
104 | } |
105 | ||
106 | static void | |
8d3788bd | 107 | tui_event_modify_breakpoint (struct breakpoint *b) |
2611b1a5 | 108 | { |
00b2bad4 | 109 | tui_update_all_breakpoint_info (); |
2611b1a5 SC |
110 | } |
111 | ||
4ca4d161 | 112 | /* Called when a command is about to proceed the inferior. */ |
2611b1a5 | 113 | |
4ca4d161 SC |
114 | static void |
115 | tui_about_to_proceed (void) | |
116 | { | |
2611b1a5 SC |
117 | /* Leave tui mode (optional). */ |
118 | #if 0 | |
119 | if (tui_active) | |
120 | { | |
121 | target_terminal_ours (); | |
122 | endwin (); | |
123 | target_terminal_inferior (); | |
124 | } | |
125 | #endif | |
126 | tui_target_has_run = 1; | |
2611b1a5 SC |
127 | } |
128 | ||
0986c744 PP |
129 | /* Refresh TUI's frame and register information. This is a hook intended to be |
130 | used to update the screen after potential frame and register changes. | |
131 | ||
bbcbf914 PP |
132 | REGISTERS_TOO_P controls whether to refresh our register information even |
133 | if frame information hasn't changed. */ | |
0986c744 | 134 | |
2611b1a5 | 135 | static void |
0986c744 | 136 | tui_refresh_frame_and_register_information (int registers_too_p) |
2611b1a5 SC |
137 | { |
138 | struct frame_info *fi; | |
f23d1b92 | 139 | CORE_ADDR pc; |
0a75489f | 140 | struct cleanup *old_chain; |
bbcbf914 | 141 | int frame_info_changed_p; |
2611b1a5 | 142 | |
0986c744 | 143 | if (!has_stack_frames ()) |
3adda9d8 DJ |
144 | return; |
145 | ||
0a75489f PP |
146 | old_chain = make_cleanup_restore_target_terminal (); |
147 | target_terminal_ours_for_output (); | |
148 | ||
3adda9d8 | 149 | fi = get_selected_frame (NULL); |
1cc6d956 MS |
150 | /* Ensure that symbols for this frame are read in. Also, determine |
151 | the source language of this frame, and switch to it if | |
152 | desired. */ | |
f23d1b92 | 153 | if (get_frame_pc_if_available (fi, &pc)) |
2611b1a5 SC |
154 | { |
155 | struct symtab *s; | |
f23d1b92 | 156 | |
34248c3a | 157 | s = find_pc_line_symtab (pc); |
1cc6d956 | 158 | /* elz: This if here fixes the problem with the pc not being |
f23d1b92 PA |
159 | displayed in the tui asm layout, with no debug symbols. The |
160 | value of s would be 0 here, and select_source_symtab would | |
161 | abort the command by calling the 'error' function. */ | |
2611b1a5 | 162 | if (s) |
f23d1b92 PA |
163 | select_source_symtab (s); |
164 | } | |
165 | ||
166 | /* Display the frame position (even if there is no symbols or the PC | |
167 | is not known). */ | |
bbcbf914 | 168 | frame_info_changed_p = tui_show_frame_info (fi); |
f23d1b92 PA |
169 | |
170 | /* Refresh the register window if it's visible. */ | |
bbcbf914 PP |
171 | if (tui_is_window_visible (DATA_WIN) |
172 | && (frame_info_changed_p || registers_too_p)) | |
f23d1b92 PA |
173 | { |
174 | tui_refreshing_registers = 1; | |
175 | tui_check_data_values (fi); | |
176 | tui_refreshing_registers = 0; | |
2611b1a5 | 177 | } |
0a75489f PP |
178 | |
179 | do_cleanups (old_chain); | |
2611b1a5 SC |
180 | } |
181 | ||
0986c744 PP |
182 | /* Dummy callback for deprecated_print_frame_info_listing_hook which is called |
183 | from print_frame_info. */ | |
184 | ||
2611b1a5 | 185 | static void |
0986c744 PP |
186 | tui_dummy_print_frame_info_listing_hook (struct symtab *s, |
187 | int line, | |
188 | int stopline, | |
189 | int noerror) | |
2611b1a5 | 190 | { |
2611b1a5 SC |
191 | } |
192 | ||
d69e6a33 SC |
193 | /* Perform all necessary cleanups regarding our module's inferior data |
194 | that is required after the inferior INF just exited. */ | |
195 | ||
cda8ab40 | 196 | static void |
d69e6a33 | 197 | tui_inferior_exit (struct inferior *inf) |
cda8ab40 | 198 | { |
d69e6a33 SC |
199 | /* Leave the SingleKey mode to make sure the gdb prompt is visible. */ |
200 | tui_set_key_mode (TUI_COMMAND_MODE); | |
47d3492a | 201 | tui_show_frame_info (0); |
cda8ab40 SC |
202 | tui_display_main (); |
203 | } | |
204 | ||
0986c744 PP |
205 | /* Observer for the before_prompt notification. */ |
206 | ||
207 | static void | |
208 | tui_before_prompt (const char *current_gdb_prompt) | |
209 | { | |
210 | /* This refresh is intended to catch changes to the selected frame following | |
211 | a call to "up", "down" or "frame". As such we don't necessarily want to | |
bbcbf914 PP |
212 | refresh registers here unless the frame actually changed by one of these |
213 | commands. Registers will otherwise be refreshed after a normal stop or by | |
214 | our tui_register_changed_hook. */ | |
0986c744 PP |
215 | tui_refresh_frame_and_register_information (/*registers_too_p=*/0); |
216 | } | |
217 | ||
218 | /* Observer for the normal_stop notification. */ | |
219 | ||
220 | static void | |
221 | tui_normal_stop (struct bpstats *bs, int print_frame) | |
222 | { | |
223 | /* This refresh is intended to catch changes to the selected frame and to | |
224 | registers following a normal stop. */ | |
225 | tui_refresh_frame_and_register_information (/*registers_too_p=*/1); | |
226 | } | |
227 | ||
383f836e TT |
228 | /* Observers created when installing TUI hooks. */ |
229 | static struct observer *tui_bp_created_observer; | |
230 | static struct observer *tui_bp_deleted_observer; | |
231 | static struct observer *tui_bp_modified_observer; | |
d69e6a33 | 232 | static struct observer *tui_inferior_exit_observer; |
4ca4d161 | 233 | static struct observer *tui_about_to_proceed_observer; |
0986c744 PP |
234 | static struct observer *tui_before_prompt_observer; |
235 | static struct observer *tui_normal_stop_observer; | |
a9bd710f | 236 | static struct observer *tui_register_changed_observer; |
383f836e | 237 | |
2611b1a5 SC |
238 | /* Install the TUI specific hooks. */ |
239 | void | |
240 | tui_install_hooks (void) | |
241 | { | |
0986c744 PP |
242 | /* If this hook is not set to something then print_frame_info will |
243 | assume that the CLI, not the TUI, is active, and will print the frame info | |
244 | for us in such a way that we are not prepared to handle. This hook is | |
245 | otherwise effectively obsolete. */ | |
9a2b4c1b | 246 | deprecated_print_frame_info_listing_hook |
0986c744 | 247 | = tui_dummy_print_frame_info_listing_hook; |
2611b1a5 | 248 | |
2611b1a5 | 249 | /* Install the event hooks. */ |
383f836e TT |
250 | tui_bp_created_observer |
251 | = observer_attach_breakpoint_created (tui_event_create_breakpoint); | |
252 | tui_bp_deleted_observer | |
253 | = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint); | |
254 | tui_bp_modified_observer | |
255 | = observer_attach_breakpoint_modified (tui_event_modify_breakpoint); | |
d69e6a33 SC |
256 | tui_inferior_exit_observer |
257 | = observer_attach_inferior_exit (tui_inferior_exit); | |
4ca4d161 SC |
258 | tui_about_to_proceed_observer |
259 | = observer_attach_about_to_proceed (tui_about_to_proceed); | |
0986c744 PP |
260 | tui_before_prompt_observer |
261 | = observer_attach_before_prompt (tui_before_prompt); | |
262 | tui_normal_stop_observer | |
263 | = observer_attach_normal_stop (tui_normal_stop); | |
a9bd710f PP |
264 | tui_register_changed_observer |
265 | = observer_attach_register_changed (tui_register_changed); | |
2611b1a5 SC |
266 | } |
267 | ||
268 | /* Remove the TUI specific hooks. */ | |
269 | void | |
270 | tui_remove_hooks (void) | |
271 | { | |
9a4105ab AC |
272 | deprecated_print_frame_info_listing_hook = 0; |
273 | deprecated_query_hook = 0; | |
383f836e TT |
274 | /* Remove our observers. */ |
275 | observer_detach_breakpoint_created (tui_bp_created_observer); | |
276 | tui_bp_created_observer = NULL; | |
277 | observer_detach_breakpoint_deleted (tui_bp_deleted_observer); | |
278 | tui_bp_deleted_observer = NULL; | |
279 | observer_detach_breakpoint_modified (tui_bp_modified_observer); | |
280 | tui_bp_modified_observer = NULL; | |
d69e6a33 SC |
281 | observer_detach_inferior_exit (tui_inferior_exit_observer); |
282 | tui_inferior_exit_observer = NULL; | |
4ca4d161 SC |
283 | observer_detach_about_to_proceed (tui_about_to_proceed_observer); |
284 | tui_about_to_proceed_observer = NULL; | |
0986c744 PP |
285 | observer_detach_before_prompt (tui_before_prompt_observer); |
286 | tui_before_prompt_observer = NULL; | |
287 | observer_detach_normal_stop (tui_normal_stop_observer); | |
288 | tui_normal_stop_observer = NULL; | |
a9bd710f PP |
289 | observer_detach_register_changed (tui_register_changed_observer); |
290 | tui_register_changed_observer = NULL; | |
2611b1a5 SC |
291 | } |
292 | ||
021e7609 | 293 | void _initialize_tui_hooks (void); |
2b68e2c5 | 294 | |
021e7609 AC |
295 | void |
296 | _initialize_tui_hooks (void) | |
2611b1a5 | 297 | { |
2611b1a5 | 298 | /* Install the permanent hooks. */ |
06d3b283 | 299 | observer_attach_new_objfile (tui_new_objfile_hook); |
2611b1a5 | 300 | } |