Remove make_cleanup_restore_target_terminal
[deliverable/binutils-gdb.git] / gdb / tui / tui-hooks.c
1 /* GDB hooks for TUI.
2
3 Copyright (C) 2001-2017 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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"
30 #include "event-top.h"
31 #include "frame.h"
32 #include "breakpoint.h"
33 #include "ui-out.h"
34 #include "top.h"
35 #include "observer.h"
36 #include <unistd.h>
37 #include <fcntl.h>
38
39 #include "tui/tui.h"
40 #include "tui/tui-hooks.h"
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"
49
50 #include "gdb_curses.h"
51
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
57 static void
58 tui_new_objfile_hook (struct objfile* objfile)
59 {
60 if (tui_active)
61 tui_display_main ();
62 }
63
64 /* Prevent recursion of deprecated_register_changed_hook(). */
65 static int tui_refreshing_registers = 0;
66
67 /* Observer for the register_changed notification. */
68
69 static void
70 tui_register_changed (struct frame_info *frame, int regno)
71 {
72 struct frame_info *fi;
73
74 /* The frame of the register that was changed may differ from the selected
75 frame, but we only want to show the register values of the selected frame.
76 And even if the frames differ a register change made in one can still show
77 up in the other. So we always use the selected frame here, and ignore
78 FRAME. */
79 fi = get_selected_frame (NULL);
80 if (tui_refreshing_registers == 0)
81 {
82 tui_refreshing_registers = 1;
83 tui_check_data_values (fi);
84 tui_refreshing_registers = 0;
85 }
86 }
87
88 /* Breakpoint creation hook.
89 Update the screen to show the new breakpoint. */
90 static void
91 tui_event_create_breakpoint (struct breakpoint *b)
92 {
93 tui_update_all_breakpoint_info ();
94 }
95
96 /* Breakpoint deletion hook.
97 Refresh the screen to update the breakpoint marks. */
98 static void
99 tui_event_delete_breakpoint (struct breakpoint *b)
100 {
101 tui_update_all_breakpoint_info ();
102 }
103
104 static void
105 tui_event_modify_breakpoint (struct breakpoint *b)
106 {
107 tui_update_all_breakpoint_info ();
108 }
109
110 /* Refresh TUI's frame and register information. This is a hook intended to be
111 used to update the screen after potential frame and register changes.
112
113 REGISTERS_TOO_P controls whether to refresh our register information even
114 if frame information hasn't changed. */
115
116 static void
117 tui_refresh_frame_and_register_information (int registers_too_p)
118 {
119 struct frame_info *fi;
120 CORE_ADDR pc;
121 int frame_info_changed_p;
122
123 if (!has_stack_frames ())
124 return;
125
126 target_terminal::scoped_restore_terminal_state term_state;
127 target_terminal::ours_for_output ();
128
129 fi = get_selected_frame (NULL);
130 /* Ensure that symbols for this frame are read in. Also, determine
131 the source language of this frame, and switch to it if
132 desired. */
133 if (get_frame_pc_if_available (fi, &pc))
134 {
135 struct symtab *s;
136
137 s = find_pc_line_symtab (pc);
138 /* elz: This if here fixes the problem with the pc not being
139 displayed in the tui asm layout, with no debug symbols. The
140 value of s would be 0 here, and select_source_symtab would
141 abort the command by calling the 'error' function. */
142 if (s)
143 select_source_symtab (s);
144 }
145
146 /* Display the frame position (even if there is no symbols or the PC
147 is not known). */
148 frame_info_changed_p = tui_show_frame_info (fi);
149
150 /* Refresh the register window if it's visible. */
151 if (tui_is_window_visible (DATA_WIN)
152 && (frame_info_changed_p || registers_too_p))
153 {
154 tui_refreshing_registers = 1;
155 tui_check_data_values (fi);
156 tui_refreshing_registers = 0;
157 }
158 }
159
160 /* Dummy callback for deprecated_print_frame_info_listing_hook which is called
161 from print_frame_info. */
162
163 static void
164 tui_dummy_print_frame_info_listing_hook (struct symtab *s,
165 int line,
166 int stopline,
167 int noerror)
168 {
169 }
170
171 /* Perform all necessary cleanups regarding our module's inferior data
172 that is required after the inferior INF just exited. */
173
174 static void
175 tui_inferior_exit (struct inferior *inf)
176 {
177 /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
178 tui_set_key_mode (TUI_COMMAND_MODE);
179 tui_show_frame_info (0);
180 tui_display_main ();
181 }
182
183 /* Observer for the before_prompt notification. */
184
185 static void
186 tui_before_prompt (const char *current_gdb_prompt)
187 {
188 /* This refresh is intended to catch changes to the selected frame following
189 a call to "up", "down" or "frame". As such we don't necessarily want to
190 refresh registers here unless the frame actually changed by one of these
191 commands. Registers will otherwise be refreshed after a normal stop or by
192 our tui_register_changed_hook. */
193 tui_refresh_frame_and_register_information (/*registers_too_p=*/0);
194 }
195
196 /* Observer for the normal_stop notification. */
197
198 static void
199 tui_normal_stop (struct bpstats *bs, int print_frame)
200 {
201 /* This refresh is intended to catch changes to the selected frame and to
202 registers following a normal stop. */
203 tui_refresh_frame_and_register_information (/*registers_too_p=*/1);
204 }
205
206 /* Observers created when installing TUI hooks. */
207 static struct observer *tui_bp_created_observer;
208 static struct observer *tui_bp_deleted_observer;
209 static struct observer *tui_bp_modified_observer;
210 static struct observer *tui_inferior_exit_observer;
211 static struct observer *tui_before_prompt_observer;
212 static struct observer *tui_normal_stop_observer;
213 static struct observer *tui_register_changed_observer;
214
215 /* Install the TUI specific hooks. */
216 void
217 tui_install_hooks (void)
218 {
219 /* If this hook is not set to something then print_frame_info will
220 assume that the CLI, not the TUI, is active, and will print the frame info
221 for us in such a way that we are not prepared to handle. This hook is
222 otherwise effectively obsolete. */
223 deprecated_print_frame_info_listing_hook
224 = tui_dummy_print_frame_info_listing_hook;
225
226 /* Install the event hooks. */
227 tui_bp_created_observer
228 = observer_attach_breakpoint_created (tui_event_create_breakpoint);
229 tui_bp_deleted_observer
230 = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint);
231 tui_bp_modified_observer
232 = observer_attach_breakpoint_modified (tui_event_modify_breakpoint);
233 tui_inferior_exit_observer
234 = observer_attach_inferior_exit (tui_inferior_exit);
235 tui_before_prompt_observer
236 = observer_attach_before_prompt (tui_before_prompt);
237 tui_normal_stop_observer
238 = observer_attach_normal_stop (tui_normal_stop);
239 tui_register_changed_observer
240 = observer_attach_register_changed (tui_register_changed);
241 }
242
243 /* Remove the TUI specific hooks. */
244 void
245 tui_remove_hooks (void)
246 {
247 deprecated_print_frame_info_listing_hook = 0;
248 deprecated_query_hook = 0;
249 /* Remove our observers. */
250 observer_detach_breakpoint_created (tui_bp_created_observer);
251 tui_bp_created_observer = NULL;
252 observer_detach_breakpoint_deleted (tui_bp_deleted_observer);
253 tui_bp_deleted_observer = NULL;
254 observer_detach_breakpoint_modified (tui_bp_modified_observer);
255 tui_bp_modified_observer = NULL;
256 observer_detach_inferior_exit (tui_inferior_exit_observer);
257 tui_inferior_exit_observer = NULL;
258 observer_detach_before_prompt (tui_before_prompt_observer);
259 tui_before_prompt_observer = NULL;
260 observer_detach_normal_stop (tui_normal_stop_observer);
261 tui_normal_stop_observer = NULL;
262 observer_detach_register_changed (tui_register_changed_observer);
263 tui_register_changed_observer = NULL;
264 }
265
266 void
267 _initialize_tui_hooks (void)
268 {
269 /* Install the permanent hooks. */
270 observer_attach_new_objfile (tui_new_objfile_hook);
271 }
This page took 0.052462 seconds and 5 git commands to generate.