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