]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-hooks.c
Remove useless assignment from tui_remove_hooks
[thirdparty/binutils-gdb.git] / gdb / tui / tui-hooks.c
CommitLineData
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"
d7b2e967 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
57static void
58tui_new_objfile_hook (struct objfile* objfile)
59{
60 if (tui_active)
1f393769 61 tui_display_main ();
2611b1a5
SC
62}
63
3adda9d8 64/* Prevent recursion of deprecated_register_changed_hook(). */
2611b1a5
SC
65static int tui_refreshing_registers = 0;
66
a9bd710f
PP
67/* Observer for the register_changed notification. */
68
2611b1a5 69static void
a9bd710f 70tui_register_changed (struct frame_info *frame, int regno)
2611b1a5
SC
71{
72 struct frame_info *fi;
73
a9bd710f
PP
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. */
206415a3
DJ
79 fi = get_selected_frame (NULL);
80 if (tui_refreshing_registers == 0)
2611b1a5
SC
81 {
82 tui_refreshing_registers = 1;
115ac53b 83 tui_check_register_values (fi);
2611b1a5
SC
84 tui_refreshing_registers = 0;
85 }
86}
87
2611b1a5
SC
88/* Breakpoint creation hook.
89 Update the screen to show the new breakpoint. */
90static void
8d3788bd 91tui_event_create_breakpoint (struct breakpoint *b)
2611b1a5 92{
0807ab7b 93 tui_update_all_breakpoint_info (nullptr);
2611b1a5
SC
94}
95
96/* Breakpoint deletion hook.
97 Refresh the screen to update the breakpoint marks. */
98static void
8d3788bd 99tui_event_delete_breakpoint (struct breakpoint *b)
2611b1a5 100{
0807ab7b 101 tui_update_all_breakpoint_info (b);
2611b1a5
SC
102}
103
104static void
8d3788bd 105tui_event_modify_breakpoint (struct breakpoint *b)
2611b1a5 106{
0807ab7b 107 tui_update_all_breakpoint_info (nullptr);
2611b1a5
SC
108}
109
0986c744
PP
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
bbcbf914
PP
113 REGISTERS_TOO_P controls whether to refresh our register information even
114 if frame information hasn't changed. */
0986c744 115
2611b1a5 116static void
0986c744 117tui_refresh_frame_and_register_information (int registers_too_p)
2611b1a5
SC
118{
119 struct frame_info *fi;
f23d1b92 120 CORE_ADDR pc;
bbcbf914 121 int frame_info_changed_p;
2611b1a5 122
0986c744 123 if (!has_stack_frames ())
3adda9d8
DJ
124 return;
125
223ffa71
TT
126 target_terminal::scoped_restore_terminal_state term_state;
127 target_terminal::ours_for_output ();
0a75489f 128
3adda9d8 129 fi = get_selected_frame (NULL);
1cc6d956
MS
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. */
f23d1b92 133 if (get_frame_pc_if_available (fi, &pc))
2611b1a5
SC
134 {
135 struct symtab *s;
f23d1b92 136
34248c3a 137 s = find_pc_line_symtab (pc);
1cc6d956 138 /* elz: This if here fixes the problem with the pc not being
f23d1b92
PA
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. */
2611b1a5 142 if (s)
f23d1b92
PA
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). */
bbcbf914 148 frame_info_changed_p = tui_show_frame_info (fi);
f23d1b92
PA
149
150 /* Refresh the register window if it's visible. */
bbcbf914
PP
151 if (tui_is_window_visible (DATA_WIN)
152 && (frame_info_changed_p || registers_too_p))
f23d1b92
PA
153 {
154 tui_refreshing_registers = 1;
115ac53b 155 tui_check_register_values (fi);
f23d1b92 156 tui_refreshing_registers = 0;
2611b1a5
SC
157 }
158}
159
0986c744
PP
160/* Dummy callback for deprecated_print_frame_info_listing_hook which is called
161 from print_frame_info. */
162
2611b1a5 163static void
0986c744
PP
164tui_dummy_print_frame_info_listing_hook (struct symtab *s,
165 int line,
166 int stopline,
167 int noerror)
2611b1a5 168{
2611b1a5
SC
169}
170
d69e6a33
SC
171/* Perform all necessary cleanups regarding our module's inferior data
172 that is required after the inferior INF just exited. */
173
cda8ab40 174static void
d69e6a33 175tui_inferior_exit (struct inferior *inf)
cda8ab40 176{
d69e6a33
SC
177 /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
178 tui_set_key_mode (TUI_COMMAND_MODE);
47d3492a 179 tui_show_frame_info (0);
cda8ab40
SC
180 tui_display_main ();
181}
182
0986c744
PP
183/* Observer for the before_prompt notification. */
184
185static void
186tui_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
bbcbf914
PP
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. */
0986c744
PP
193 tui_refresh_frame_and_register_information (/*registers_too_p=*/0);
194}
195
196/* Observer for the normal_stop notification. */
197
198static void
199tui_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
76727919
TT
206/* Token associated with observers registered while TUI hooks are
207 installed. */
3dcfdc58 208static const gdb::observers::token tui_observers_token {};
76727919
TT
209
210/* Attach or detach a single observer, according to ATTACH. */
211
212template<typename T>
213static void
214attach_or_detach (T &observable, typename T::func_type func, bool attach)
215{
216 if (attach)
217 observable.attach (func, tui_observers_token);
218 else
219 observable.detach (tui_observers_token);
220}
221
222/* Attach or detach TUI observers, according to ATTACH. */
223
224static void
225tui_attach_detach_observers (bool attach)
226{
227 attach_or_detach (gdb::observers::breakpoint_created,
228 tui_event_create_breakpoint, attach);
229 attach_or_detach (gdb::observers::breakpoint_deleted,
230 tui_event_delete_breakpoint, attach);
231 attach_or_detach (gdb::observers::breakpoint_modified,
232 tui_event_modify_breakpoint, attach);
233 attach_or_detach (gdb::observers::inferior_exit,
234 tui_inferior_exit, attach);
235 attach_or_detach (gdb::observers::before_prompt,
236 tui_before_prompt, attach);
237 attach_or_detach (gdb::observers::normal_stop,
238 tui_normal_stop, attach);
239 attach_or_detach (gdb::observers::register_changed,
240 tui_register_changed, attach);
241}
383f836e 242
2611b1a5
SC
243/* Install the TUI specific hooks. */
244void
245tui_install_hooks (void)
246{
0986c744
PP
247 /* If this hook is not set to something then print_frame_info will
248 assume that the CLI, not the TUI, is active, and will print the frame info
249 for us in such a way that we are not prepared to handle. This hook is
250 otherwise effectively obsolete. */
9a2b4c1b 251 deprecated_print_frame_info_listing_hook
0986c744 252 = tui_dummy_print_frame_info_listing_hook;
2611b1a5 253
2611b1a5 254 /* Install the event hooks. */
76727919 255 tui_attach_detach_observers (true);
2611b1a5
SC
256}
257
258/* Remove the TUI specific hooks. */
259void
260tui_remove_hooks (void)
261{
9a4105ab 262 deprecated_print_frame_info_listing_hook = 0;
76727919 263
383f836e 264 /* Remove our observers. */
76727919 265 tui_attach_detach_observers (false);
2611b1a5
SC
266}
267
021e7609
AC
268void
269_initialize_tui_hooks (void)
2611b1a5 270{
2611b1a5 271 /* Install the permanent hooks. */
76727919 272 gdb::observers::new_objfile.attach (tui_new_objfile_hook);
2611b1a5 273}