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