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