GDB (xrefs)
tui-hooks.c
Go to the documentation of this file.
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 
58 
59 static void
61 {
62  if (tui_active)
64 }
65 
66 /* Prevent recursion of deprecated_register_changed_hook(). */
67 static int tui_refreshing_registers = 0;
68 
69 static void
71 {
72  struct frame_info *fi;
73 
74  fi = get_selected_frame (NULL);
75  if (tui_refreshing_registers == 0)
76  {
80  }
81 }
82 
83 /* Breakpoint creation hook.
84  Update the screen to show the new breakpoint. */
85 static void
87 {
89 }
90 
91 /* Breakpoint deletion hook.
92  Refresh the screen to update the breakpoint marks. */
93 static void
95 {
97 }
98 
99 static void
101 {
103 }
104 
105 /* Called when a command is about to proceed the inferior. */
106 
107 static void
109 {
110  /* Leave tui mode (optional). */
111 #if 0
112  if (tui_active)
113  {
115  endwin ();
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 even
126  if frame information hasn't changed. */
127 
128 static void
130 {
131  struct frame_info *fi;
132  CORE_ADDR pc;
133  struct cleanup *old_chain;
134  int frame_info_changed_p;
135 
136  if (!has_stack_frames ())
137  return;
138 
141 
142  fi = get_selected_frame (NULL);
143  /* Ensure that symbols for this frame are read in. Also, determine
144  the source language of this frame, and switch to it if
145  desired. */
146  if (get_frame_pc_if_available (fi, &pc))
147  {
148  struct symtab *s;
149 
150  s = find_pc_line_symtab (pc);
151  /* elz: This if here fixes the problem with the pc not being
152  displayed in the tui asm layout, with no debug symbols. The
153  value of s would be 0 here, and select_source_symtab would
154  abort the command by calling the 'error' function. */
155  if (s)
157  }
158 
159  /* Display the frame position (even if there is no symbols or the PC
160  is not known). */
161  frame_info_changed_p = tui_show_frame_info (fi);
162 
163  /* Refresh the register window if it's visible. */
165  && (frame_info_changed_p || registers_too_p))
166  {
170  }
171 
172  do_cleanups (old_chain);
173 }
174 
175 /* Dummy callback for deprecated_print_frame_info_listing_hook which is called
176  from print_frame_info. */
177 
178 static void
180  int line,
181  int stopline,
182  int noerror)
183 {
184 }
185 
186 /* Perform all necessary cleanups regarding our module's inferior data
187  that is required after the inferior INF just exited. */
188 
189 static void
191 {
192  /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
195  tui_display_main ();
196 }
197 
198 /* Observer for the before_prompt notification. */
199 
200 static void
201 tui_before_prompt (const char *current_gdb_prompt)
202 {
203  /* This refresh is intended to catch changes to the selected frame following
204  a call to "up", "down" or "frame". As such we don't necessarily want to
205  refresh registers here unless the frame actually changed by one of these
206  commands. Registers will otherwise be refreshed after a normal stop or by
207  our tui_register_changed_hook. */
208  tui_refresh_frame_and_register_information (/*registers_too_p=*/0);
209 }
210 
211 /* Observer for the normal_stop notification. */
212 
213 static void
215 {
216  /* This refresh is intended to catch changes to the selected frame and to
217  registers following a normal stop. */
218  tui_refresh_frame_and_register_information (/*registers_too_p=*/1);
219 }
220 
221 /* Observers created when installing TUI hooks. */
229 
230 /* Install the TUI specific hooks. */
231 void
233 {
234  /* If this hook is not set to something then print_frame_info will
235  assume that the CLI, not the TUI, is active, and will print the frame info
236  for us in such a way that we are not prepared to handle. This hook is
237  otherwise effectively obsolete. */
240 
241  /* Install the event hooks. */
242  tui_bp_created_observer
244  tui_bp_deleted_observer
246  tui_bp_modified_observer
248  tui_inferior_exit_observer
250  tui_about_to_proceed_observer
252  tui_before_prompt_observer
254  tui_normal_stop_observer
256 
258 }
259 
260 /* Remove the TUI specific hooks. */
261 void
263 {
267 
268  /* Remove our observers. */
269  observer_detach_breakpoint_created (tui_bp_created_observer);
270  tui_bp_created_observer = NULL;
271  observer_detach_breakpoint_deleted (tui_bp_deleted_observer);
272  tui_bp_deleted_observer = NULL;
273  observer_detach_breakpoint_modified (tui_bp_modified_observer);
274  tui_bp_modified_observer = NULL;
275  observer_detach_inferior_exit (tui_inferior_exit_observer);
276  tui_inferior_exit_observer = NULL;
277  observer_detach_about_to_proceed (tui_about_to_proceed_observer);
278  tui_about_to_proceed_observer = NULL;
279  observer_detach_before_prompt (tui_before_prompt_observer);
280  tui_before_prompt_observer = NULL;
281  observer_detach_normal_stop (tui_normal_stop_observer);
282  tui_normal_stop_observer = NULL;
283 }
284 
285 void _initialize_tui_hooks (void);
286 
287 void
289 {
290  /* Install the permanent hooks. */
292 }
static struct observer * tui_normal_stop_observer
Definition: tui-hooks.c:228
void target_terminal_ours(void)
Definition: target.c:491
void observer_detach_breakpoint_deleted(struct observer *observer)
struct observer * observer_attach_breakpoint_deleted(observer_breakpoint_deleted_ftype *f)
struct frame_info * get_selected_frame(const char *message)
Definition: frame.c:1535
void(* deprecated_register_changed_hook)(int regno)
Definition: top.c:227
static void tui_register_changed_hook(int regno)
Definition: tui-hooks.c:70
struct observer * observer_attach_before_prompt(observer_before_prompt_ftype *f)
bfd_vma CORE_ADDR
Definition: common-types.h:41
int tui_active
Definition: tui.c:59
static void tui_refresh_frame_and_register_information(int registers_too_p)
Definition: tui-hooks.c:129
int(* deprecated_query_hook)(const char *, va_list) ATTRIBUTE_FPTR_PRINTF(1
Definition: top.c:191
void observer_detach_breakpoint_modified(struct observer *observer)
int get_frame_pc_if_available(struct frame_info *frame, CORE_ADDR *pc)
Definition: frame.c:2224
void select_source_symtab(struct symtab *s)
Definition: source.c:257
static int tui_refreshing_registers
Definition: tui-hooks.c:67
void(* deprecated_print_frame_info_listing_hook)(struct symtab *s, int line, int stopline, int noerror)
Definition: top.c:185
struct observer * observer_attach_inferior_exit(observer_inferior_exit_ftype *f)
static void tui_event_create_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:86
static void tui_before_prompt(const char *current_gdb_prompt)
Definition: tui-hooks.c:201
static void tui_about_to_proceed(void)
Definition: tui-hooks.c:108
static struct observer * tui_about_to_proceed_observer
Definition: tui-hooks.c:226
static struct observer * tui_bp_deleted_observer
Definition: tui-hooks.c:223
void tui_install_hooks(void)
Definition: tui-hooks.c:232
void tui_set_key_mode(enum tui_key_mode mode)
Definition: tui.c:314
static struct observer * tui_bp_created_observer
Definition: tui-hooks.c:222
static void tui_normal_stop(struct bpstats *bs, int print_frame)
Definition: tui-hooks.c:214
void target_terminal_inferior(void)
Definition: target.c:470
struct observer * observer_attach_breakpoint_created(observer_breakpoint_created_ftype *f)
static struct observer * tui_before_prompt_observer
Definition: tui-hooks.c:227
static void tui_inferior_exit(struct inferior *inf)
Definition: tui-hooks.c:190
void observer_detach_breakpoint_created(struct observer *observer)
Definition: gnu-nat.c:163
static void tui_dummy_print_frame_info_listing_hook(struct symtab *s, int line, int stopline, int noerror)
Definition: tui-hooks.c:179
Definition: symtab.h:925
static void tui_event_modify_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:100
void observer_detach_normal_stop(struct observer *observer)
void tui_check_data_values(struct frame_info *frame)
Definition: tui-windata.c:230
static void print_frame(struct frame_info *frame, int print_level, enum print_what print_what, int print_args, struct symtab_and_line sal)
static void tui_new_objfile_hook(struct objfile *objfile)
Definition: tui-hooks.c:60
int tui_is_window_visible(enum tui_win_type type)
Definition: tui.c:647
struct observer * observer_attach_breakpoint_modified(observer_breakpoint_modified_ftype *f)
static struct observer * tui_inferior_exit_observer
Definition: tui-hooks.c:225
int tui_target_has_run
Definition: tui-hooks.c:57
int line
Definition: symtab.h:1570
static void tui_event_delete_breakpoint(struct breakpoint *b)
Definition: tui-hooks.c:94
void tui_update_all_breakpoint_info(void)
static struct observer * tui_bp_modified_observer
Definition: tui-hooks.c:224
int tui_show_frame_info(struct frame_info *fi)
Definition: tui-stack.c:360
struct observer * observer_attach_normal_stop(observer_normal_stop_ftype *f)
struct observer * observer_attach_new_objfile(observer_new_objfile_ftype *f)
void observer_detach_before_prompt(struct observer *observer)
void target_terminal_ours_for_output(void)
Definition: target.c:503
Definition: tui.h:41
void observer_detach_about_to_proceed(struct observer *observer)
struct symtab * find_pc_line_symtab(CORE_ADDR pc)
Definition: symtab.c:3328
void _initialize_tui_hooks(void)
Definition: tui-hooks.c:288
int has_stack_frames(void)
Definition: frame.c:1506
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
struct cleanup * make_cleanup_restore_target_terminal(void)
Definition: target.c:553
void tui_display_main(void)
Definition: tui-winsource.c:44
void observer_detach_inferior_exit(struct observer *observer)
struct observer * observer_attach_about_to_proceed(observer_about_to_proceed_ftype *f)
void tui_remove_hooks(void)
Definition: tui-hooks.c:262