3 Copyright (C) 2001-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
29 #include "event-loop.h"
30 #include "event-top.h"
32 #include "breakpoint.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"
50 #include "gdb_curses.h"
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
55 #include "readline/readline.h"
57 int tui_target_has_run
= 0;
60 tui_new_objfile_hook (struct objfile
* objfile
)
66 /* Prevent recursion of deprecated_register_changed_hook(). */
67 static int tui_refreshing_registers
= 0;
70 tui_register_changed_hook (int regno
)
72 struct frame_info
*fi
;
74 fi
= get_selected_frame (NULL
);
75 if (tui_refreshing_registers
== 0)
77 tui_refreshing_registers
= 1;
78 tui_check_data_values (fi
);
79 tui_refreshing_registers
= 0;
83 /* Breakpoint creation hook.
84 Update the screen to show the new breakpoint. */
86 tui_event_create_breakpoint (struct breakpoint
*b
)
88 tui_update_all_breakpoint_info ();
91 /* Breakpoint deletion hook.
92 Refresh the screen to update the breakpoint marks. */
94 tui_event_delete_breakpoint (struct breakpoint
*b
)
96 tui_update_all_breakpoint_info ();
100 tui_event_modify_breakpoint (struct breakpoint
*b
)
102 tui_update_all_breakpoint_info ();
105 /* Called when a command is about to proceed the inferior. */
108 tui_about_to_proceed (void)
110 /* Leave tui mode (optional). */
114 target_terminal_ours ();
116 target_terminal_inferior ();
119 tui_target_has_run
= 1;
122 /* The selected frame has changed. This is happens after a target
123 stop or when the user explicitly changes the frame
124 (up/down/thread/...). */
126 tui_selected_frame_level_changed_hook (int level
)
128 struct frame_info
*fi
;
131 /* Negative level means that the selected frame was cleared. */
135 fi
= get_selected_frame (NULL
);
136 /* Ensure that symbols for this frame are read in. Also, determine
137 the source language of this frame, and switch to it if
139 if (get_frame_pc_if_available (fi
, &pc
))
143 s
= find_pc_line_symtab (pc
);
144 /* elz: This if here fixes the problem with the pc not being
145 displayed in the tui asm layout, with no debug symbols. The
146 value of s would be 0 here, and select_source_symtab would
147 abort the command by calling the 'error' function. */
149 select_source_symtab (s
);
152 /* Display the frame position (even if there is no symbols or the PC
154 tui_show_frame_info (fi
);
156 /* Refresh the register window if it's visible. */
157 if (tui_is_window_visible (DATA_WIN
))
159 tui_refreshing_registers
= 1;
160 tui_check_data_values (fi
);
161 tui_refreshing_registers
= 0;
165 /* Called from print_frame_info to list the line we stopped in. */
167 tui_print_frame_info_listing_hook (struct symtab
*s
,
172 select_source_symtab (s
);
173 tui_show_frame_info (get_selected_frame (NULL
));
176 /* Perform all necessary cleanups regarding our module's inferior data
177 that is required after the inferior INF just exited. */
180 tui_inferior_exit (struct inferior
*inf
)
182 /* Leave the SingleKey mode to make sure the gdb prompt is visible. */
183 tui_set_key_mode (TUI_COMMAND_MODE
);
184 tui_show_frame_info (0);
188 /* Observers created when installing TUI hooks. */
189 static struct observer
*tui_bp_created_observer
;
190 static struct observer
*tui_bp_deleted_observer
;
191 static struct observer
*tui_bp_modified_observer
;
192 static struct observer
*tui_inferior_exit_observer
;
193 static struct observer
*tui_about_to_proceed_observer
;
195 /* Install the TUI specific hooks. */
197 tui_install_hooks (void)
199 deprecated_selected_frame_level_changed_hook
200 = tui_selected_frame_level_changed_hook
;
201 deprecated_print_frame_info_listing_hook
202 = tui_print_frame_info_listing_hook
;
204 /* Install the event hooks. */
205 tui_bp_created_observer
206 = observer_attach_breakpoint_created (tui_event_create_breakpoint
);
207 tui_bp_deleted_observer
208 = observer_attach_breakpoint_deleted (tui_event_delete_breakpoint
);
209 tui_bp_modified_observer
210 = observer_attach_breakpoint_modified (tui_event_modify_breakpoint
);
211 tui_inferior_exit_observer
212 = observer_attach_inferior_exit (tui_inferior_exit
);
213 tui_about_to_proceed_observer
214 = observer_attach_about_to_proceed (tui_about_to_proceed
);
216 deprecated_register_changed_hook
= tui_register_changed_hook
;
219 /* Remove the TUI specific hooks. */
221 tui_remove_hooks (void)
223 deprecated_selected_frame_level_changed_hook
= 0;
224 deprecated_print_frame_info_listing_hook
= 0;
225 deprecated_query_hook
= 0;
226 deprecated_register_changed_hook
= 0;
228 /* Remove our observers. */
229 observer_detach_breakpoint_created (tui_bp_created_observer
);
230 tui_bp_created_observer
= NULL
;
231 observer_detach_breakpoint_deleted (tui_bp_deleted_observer
);
232 tui_bp_deleted_observer
= NULL
;
233 observer_detach_breakpoint_modified (tui_bp_modified_observer
);
234 tui_bp_modified_observer
= NULL
;
235 observer_detach_inferior_exit (tui_inferior_exit_observer
);
236 tui_inferior_exit_observer
= NULL
;
237 observer_detach_about_to_proceed (tui_about_to_proceed_observer
);
238 tui_about_to_proceed_observer
= NULL
;
241 void _initialize_tui_hooks (void);
244 _initialize_tui_hooks (void)
246 /* Install the permanent hooks. */
247 observer_attach_new_objfile (tui_new_objfile_hook
);