GDB (xrefs)
Loading...
Searching...
No Matches
tui-hooks.c
Go to the documentation of this file.
1/* GDB hooks for TUI.
2
3 Copyright (C) 2001-2023 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 "gdbsupport/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 "observable.h"
36#include "source.h"
37#include <unistd.h>
38#include <fcntl.h>
39
40#include "tui/tui.h"
41#include "tui/tui-hooks.h"
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-winsource.h"
49
50#include "gdb_curses.h"
51
52static void
54{
55 if (tui_active)
57}
58
59/* Prevent recursion of deprecated_register_changed_hook(). */
60static bool tui_refreshing_registers = false;
61
62/* Observer for the register_changed notification. */
63
64static void
66{
68
70 return;
71
72 /* The frame of the register that was changed may differ from the selected
73 frame, but we only want to show the register values of the selected frame.
74 And even if the frames differ a register change made in one can still show
75 up in the other. So we always use the selected frame here, and ignore
76 FRAME. */
77 fi = get_selected_frame (NULL);
79 {
81 TUI_DATA_WIN->check_register_values (fi);
83 }
84}
85
86/* Breakpoint creation hook.
87 Update the screen to show the new breakpoint. */
88static void
90{
92}
93
94/* Breakpoint deletion hook.
95 Refresh the screen to update the breakpoint marks. */
96static void
98{
100}
101
102static void
104{
106}
107
108/* This is set to true if the next window refresh should come from the
109 current stack frame. */
110
111static bool from_stack;
112
113/* This is set to true if the next window refresh should come from the
114 current source symtab. */
115
117
118/* Refresh TUI's frame and register information. This is a hook intended to be
119 used to update the screen after potential frame and register changes. */
120
121static void
123{
125 return;
126
129
131 {
133
134 /* Display the frame position (even if there is no symbols or
135 the PC is not known). */
136 bool frame_info_changed_p = tui_show_frame_info (fi);
137
138 /* Refresh the register window if it's visible. */
140 && (frame_info_changed_p || from_stack))
141 {
143 TUI_DATA_WIN->check_register_values (fi);
145 }
146 }
147 else if (!from_stack)
148 {
149 /* Make sure that the source window is displayed. */
151
154 }
155}
156
157/* Dummy callback for deprecated_print_frame_info_listing_hook which is called
158 from print_frame_info. */
159
160static void
162 int line,
163 int stopline,
164 int noerror)
165{
166}
167
168/* Perform all necessary cleanups regarding our module's inferior data
169 that is required after the inferior INF just exited. */
170
171static void
173{
174 /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
178}
179
180/* Observer for the before_prompt notification. */
181
182static void
183tui_before_prompt (const char *current_gdb_prompt)
184{
186 from_stack = false;
187 from_source_symtab = false;
188}
189
190/* Observer for the normal_stop notification. */
191
192static void
194{
195 from_stack = true;
196}
197
198/* Observer for user_selected_context_changed. */
199
200static void
201tui_context_changed (user_selected_what ignore)
202{
203 from_stack = true;
204}
205
206/* Observer for current_source_symtab_and_line_changed. */
207
208static void
210{
211 from_source_symtab = true;
212}
213
214/* Token associated with observers registered while TUI hooks are
215 installed. */
216static const gdb::observers::token tui_observers_token {};
217
218/* Attach or detach a single observer, according to ATTACH. */
219
220template<typename T>
221static void
222attach_or_detach (T &observable, typename T::func_type func, bool attach)
223{
224 if (attach)
225 observable.attach (func, tui_observers_token, "tui-hooks");
226 else
227 observable.detach (tui_observers_token);
228}
229
230/* Attach or detach TUI observers, according to ATTACH. */
231
232static void
234{
242 tui_inferior_exit, attach);
244 tui_before_prompt, attach);
246 tui_normal_stop, attach);
248 tui_register_changed, attach);
250 tui_context_changed, attach);
252 tui_symtab_changed, attach);
253}
254
255/* Install the TUI specific hooks. */
256void
258{
259 /* If this hook is not set to something then print_frame_info will
260 assume that the CLI, not the TUI, is active, and will print the frame info
261 for us in such a way that we are not prepared to handle. This hook is
262 otherwise effectively obsolete. */
265
266 /* Install the event hooks. */
268}
269
270/* Remove the TUI specific hooks. */
271void
273{
275
276 /* Remove our observers. */
278}
279
281void
283{
284 /* Install the permanent hooks. */
286}
static void ours_for_output()
Definition: target.c:1083
void(* deprecated_print_frame_info_listing_hook)(struct symtab *s, int line, int stopline, int noerror)
Definition: top.c:213
bool has_stack_frames()
Definition: frame.c:1784
frame_info_ptr get_selected_frame(const char *message)
Definition: frame.c:1813
observable current_source_symtab_and_line_changed
observable< struct inferior * > inferior_exit
observable< struct breakpoint * > breakpoint_created
observable< struct breakpoint * > breakpoint_modified
observable< struct breakpoint * > breakpoint_deleted
observable< struct objfile * > new_objfile
observable< const char * > before_prompt
observable< user_selected_what > user_selected_context_changed
observable< struct bpstat *, int > normal_stop
observable< frame_info_ptr, int > register_changed
void(* func)(remote_target *remote, char *)
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition: source.c:238
static void print_frame(const frame_print_options &opts, frame_info_ptr frame, int print_level, enum print_what print_what, int print_args, struct symtab_and_line sal)
Definition: 1.cc:26
Definition: gnu-nat.c:154
#define TUI_DATA_WIN
Definition: tui-data.h:188
static bool from_stack
Definition: tui-hooks.c:111
void tui_remove_hooks(void)
Definition: tui-hooks.c:272
static void tui_normal_stop(struct bpstat *bs, int print_frame)
Definition: tui-hooks.c:193
static void tui_new_objfile_hook(struct objfile *objfile)
Definition: tui-hooks.c:53
static void tui_before_prompt(const char *current_gdb_prompt)
Definition: tui-hooks.c:183
static bool from_source_symtab
Definition: tui-hooks.c:116
static bool tui_refreshing_registers
Definition: tui-hooks.c:60
static void tui_register_changed(frame_info_ptr frame, int regno)
Definition: tui-hooks.c:65
static void tui_event_delete_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:97
static void tui_symtab_changed()
Definition: tui-hooks.c:209
static void tui_context_changed(user_selected_what ignore)
Definition: tui-hooks.c:201
static void tui_attach_detach_observers(bool attach)
Definition: tui-hooks.c:233
static void tui_event_modify_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:103
static void attach_or_detach(T &observable, typename T::func_type func, bool attach)
Definition: tui-hooks.c:222
void tui_install_hooks(void)
Definition: tui-hooks.c:257
static void tui_dummy_print_frame_info_listing_hook(struct symtab *s, int line, int stopline, int noerror)
Definition: tui-hooks.c:161
void _initialize_tui_hooks()
Definition: tui-hooks.c:282
static void tui_event_create_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:89
static void tui_inferior_exit(struct inferior *inf)
Definition: tui-hooks.c:172
static void tui_refresh_frame_and_register_information()
Definition: tui-hooks.c:122
static const gdb::observers::token tui_observers_token
Definition: tui-hooks.c:216
void tui_add_win_to_layout(enum tui_win_type type)
Definition: tui-layout.c:156
bool tui_show_frame_info(frame_info_ptr fi)
Definition: tui-stack.c:253
void tui_update_all_breakpoint_info(struct breakpoint *being_deleted)
void tui_update_source_windows_with_line(struct symtab_and_line sal)
void tui_display_main()
Definition: tui-winsource.c:47
bool tui_is_window_visible(enum tui_win_type type)
Definition: tui.c:568
bool tui_active
Definition: tui.c:72
void tui_set_key_mode(enum tui_key_mode mode)
Definition: tui.c:270
@ DATA_WIN
Definition: tui.h:53
@ SRC_WIN
Definition: tui.h:51
@ TUI_COMMAND_MODE
Definition: tui.h:80