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
53{
54 if (tui_active)
56}
57
58static void
61
62static void
65
66/* Prevent recursion of deprecated_register_changed_hook(). */
67static bool tui_refreshing_registers = false;
68
69/* Observer for the register_changed notification. */
70
71static void
73{
75
77 return;
78
79 /* The frame of the register that was changed may differ from the selected
80 frame, but we only want to show the register values of the selected frame.
81 And even if the frames differ a register change made in one can still show
82 up in the other. So we always use the selected frame here, and ignore
83 FRAME. */
84 fi = get_selected_frame (NULL);
86 {
88 TUI_DATA_WIN->check_register_values (fi);
90 }
91}
92
93/* Breakpoint creation hook.
94 Update the screen to show the new breakpoint. */
95static void
100
101/* Breakpoint deletion hook.
102 Refresh the screen to update the breakpoint marks. */
103static void
108
109static void
114
115/* This is set to true if the next window refresh should come from the
116 current stack frame. */
117
118static bool from_stack;
119
120/* This is set to true if the next window refresh should come from the
121 current source symtab. */
122
124
125/* Refresh TUI's frame and register information. This is a hook intended to be
126 used to update the screen after potential frame and register changes. */
127
128static void
130{
132 return;
133
136
138 {
140
141 /* Display the frame position (even if there is no symbols or
142 the PC is not known). */
143 bool frame_info_changed_p = tui_show_frame_info (fi);
144
145 /* Refresh the register window if it's visible. */
147 && (frame_info_changed_p || from_stack))
148 {
150 TUI_DATA_WIN->check_register_values (fi);
152 }
153 }
154 else if (!from_stack)
155 {
156 /* Make sure that the source window is displayed. */
158
161 }
162}
163
164/* Dummy callback for deprecated_print_frame_info_listing_hook which is called
165 from print_frame_info. */
166
167static void
169 int line,
170 int stopline,
171 int noerror)
172{
173}
174
175/* Perform all necessary cleanups regarding our module's inferior data
176 that is required after the inferior INF just exited. */
177
178static void
180{
181 /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
185}
186
187/* Observer for the before_prompt notification. */
188
189static void
190tui_before_prompt (const char *current_gdb_prompt)
191{
193 from_stack = false;
194 from_source_symtab = false;
195}
196
197/* Observer for the normal_stop notification. */
198
199static void
201{
202 from_stack = true;
203}
204
205/* Observer for user_selected_context_changed. */
206
207static void
208tui_context_changed (user_selected_what ignore)
209{
210 from_stack = true;
211}
212
213/* Observer for current_source_symtab_and_line_changed. */
214
215static void
217{
218 from_source_symtab = true;
219}
220
221/* Token associated with observers registered while TUI hooks are
222 installed. */
223static const gdb::observers::token tui_observers_token {};
224
225/* Attach or detach a single observer, according to ATTACH. */
226
227template<typename T>
228static void
229attach_or_detach (T &observable, typename T::func_type func, bool attach)
230{
231 if (attach)
232 observable.attach (func, tui_observers_token, "tui-hooks");
233 else
234 observable.detach (tui_observers_token);
235}
236
237/* Attach or detach TUI observers, according to ATTACH. */
238
239static void
261
262/* Install the TUI specific hooks. */
263void
265{
266 /* If this hook is not set to something then print_frame_info will
267 assume that the CLI, not the TUI, is active, and will print the frame info
268 for us in such a way that we are not prepared to handle. This hook is
269 otherwise effectively obsolete. */
272
273 /* Install the event hooks. */
275}
276
277/* Remove the TUI specific hooks. */
278void
280{
282
283 /* Remove our observers. */
285}
286
288void
290{
291 /* Install the permanent hooks. */
294 "tui-hooks");
295}
static void ours_for_output()
Definition target.c:1088
void(* deprecated_print_frame_info_listing_hook)(struct symtab *s, int line, int stopline, int noerror)
Definition top.c:214
bool has_stack_frames()
Definition frame.c:1859
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
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< program_space * > all_objfiles_removed
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:239
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:153
struct program_space * pspace
Definition symtab.h:2326
#define TUI_DATA_WIN
Definition tui-data.h:197
static bool from_stack
Definition tui-hooks.c:118
void tui_remove_hooks(void)
Definition tui-hooks.c:279
static void tui_normal_stop(struct bpstat *bs, int print_frame)
Definition tui-hooks.c:200
static void tui_new_objfile_hook(struct objfile *objfile)
Definition tui-hooks.c:59
static void tui_before_prompt(const char *current_gdb_prompt)
Definition tui-hooks.c:190
static bool from_source_symtab
Definition tui-hooks.c:123
static bool tui_refreshing_registers
Definition tui-hooks.c:67
static void tui_register_changed(frame_info_ptr frame, int regno)
Definition tui-hooks.c:72
static void tui_event_delete_breakpoint(struct breakpoint *b)
Definition tui-hooks.c:104
static void tui_symtab_changed()
Definition tui-hooks.c:216
static void tui_context_changed(user_selected_what ignore)
Definition tui-hooks.c:208
static void tui_attach_detach_observers(bool attach)
Definition tui-hooks.c:240
static void tui_event_modify_breakpoint(struct breakpoint *b)
Definition tui-hooks.c:110
static void attach_or_detach(T &observable, typename T::func_type func, bool attach)
Definition tui-hooks.c:229
void tui_install_hooks(void)
Definition tui-hooks.c:264
static void tui_dummy_print_frame_info_listing_hook(struct symtab *s, int line, int stopline, int noerror)
Definition tui-hooks.c:168
void _initialize_tui_hooks()
Definition tui-hooks.c:289
static void tui_all_objfiles_removed(program_space *pspace)
Definition tui-hooks.c:63
static void tui_event_create_breakpoint(struct breakpoint *b)
Definition tui-hooks.c:96
static void tui_inferior_exit(struct inferior *inf)
Definition tui-hooks.c:179
static void tui_on_objfiles_changed()
Definition tui-hooks.c:52
static void tui_refresh_frame_and_register_information()
Definition tui-hooks.c:129
static const gdb::observers::token tui_observers_token
Definition tui-hooks.c:223
void tui_add_win_to_layout(enum tui_win_type type)
Definition tui-layout.c:155
bool tui_show_frame_info(frame_info_ptr fi)
Definition tui-stack.c:256
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()
bool tui_is_window_visible(enum tui_win_type type)
Definition tui.c:581
bool tui_active
Definition tui.c:73
void tui_set_key_mode(enum tui_key_mode mode)
Definition tui.c:283
@ DATA_WIN
Definition tui.h:56
@ SRC_WIN
Definition tui.h:54
@ TUI_COMMAND_MODE
Definition tui.h:83