📄 tui.c
字号:
/* General functions for the WDB TUI. Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Contributed by Hewlett-Packard Company. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <malloc.h>#ifdef HAVE_TERM_H#include <term.h>#endif#include <signal.h>#include <fcntl.h>#if 0#include <termio.h>#endif#include <setjmp.h>#include "defs.h"#include "gdbcmd.h"#include "tui.h"#include "tuiData.h"#include "tuiLayout.h"#include "tuiIO.h"#include "tuiRegs.h"#include "tuiStack.h"#include "tuiWin.h"#include "tuiSourceWin.h"#include "tuiDataWin.h"#include "readline/readline.h"#include "target.h"#include "frame.h"#include "breakpoint.h"#include "inferior.h"#include "symtab.h"#include "source.h"#ifdef HAVE_NCURSES_H #include <ncurses.h>#else#ifdef HAVE_CURSES_H#include <curses.h>#endif#endif/* Tells whether the TUI is active or not. */int tui_active = 0;static int tui_finish_init = 1;enum tui_key_mode tui_current_key_mode = tui_command_mode;struct tui_char_command{ unsigned char key; const char* cmd;};/* Key mapping to gdb commands when the TUI is using the single key mode. */static const struct tui_char_command tui_commands[] = { { 'c', "continue" }, { 'd', "down" }, { 'f', "finish" }, { 'n', "next" }, { 'r', "run" }, { 's', "step" }, { 'u', "up" }, { 'v', "info locals" }, { 'w', "where" }, { 0, 0 },};static Keymap tui_keymap;static Keymap tui_readline_standard_keymap;/* TUI readline command. Switch the output mode between TUI/standard gdb. */static inttui_rl_switch_mode (int notused1, int notused2){ if (tui_active) { tui_disable (); rl_prep_terminal (0); } else { rl_deprep_terminal (); tui_enable (); } /* Clear the readline in case switching occurred in middle of something. */ if (rl_end) rl_kill_text (0, rl_end); /* Since we left the curses mode, the terminal mode is restored to some previous state. That state may not be suitable for readline to work correctly (it may be restored in line mode). We force an exit of the current readline so that readline is re-entered and it will be able to setup the terminal for its needs. By re-entering in readline, we also redisplay its prompt in the non-curses mode. */ rl_newline (1, '\n'); /* Make sure the \n we are returning does not repeat the last command. */ dont_repeat (); return 0;}/* TUI readline command. Change the TUI layout to show a next layout. This function is bound to CTRL-X 2. It is intended to provide a functionality close to the Emacs split-window command. We always show two windows (src+asm), (src+regs) or (asm+regs). */static inttui_rl_change_windows (int notused1, int notused2){ if (!tui_active) tui_rl_switch_mode (0/*notused*/, 0/*notused*/); if (tui_active) { TuiLayoutType new_layout; TuiRegisterDisplayType regs_type = TUI_UNDEFINED_REGS; new_layout = currentLayout (); /* Select a new layout to have a rolling layout behavior with always two windows (except when undefined). */ switch (new_layout) { case SRC_COMMAND: new_layout = SRC_DISASSEM_COMMAND; break; case DISASSEM_COMMAND: new_layout = SRC_DISASSEM_COMMAND; break; case SRC_DATA_COMMAND: new_layout = SRC_DISASSEM_COMMAND; break; case SRC_DISASSEM_COMMAND: new_layout = DISASSEM_DATA_COMMAND; break; case DISASSEM_DATA_COMMAND: new_layout = SRC_DATA_COMMAND; break; default: new_layout = SRC_COMMAND; break; } tuiSetLayout (new_layout, regs_type); } return 0;}/* TUI readline command. Delete the second TUI window to only show one. */static inttui_rl_delete_other_windows (int notused1, int notused2){ if (!tui_active) tui_rl_switch_mode (0/*notused*/, 0/*notused*/); if (tui_active) { TuiLayoutType new_layout; TuiRegisterDisplayType regs_type = TUI_UNDEFINED_REGS; new_layout = currentLayout (); /* Kill one window. */ switch (new_layout) { case SRC_COMMAND: case SRC_DATA_COMMAND: case SRC_DISASSEM_COMMAND: default: new_layout = SRC_COMMAND; break; case DISASSEM_COMMAND: case DISASSEM_DATA_COMMAND: new_layout = DISASSEM_COMMAND; break; } tuiSetLayout (new_layout, regs_type); } return 0;}/* TUI readline command. Switch the active window to give the focus to a next window. */static inttui_rl_other_window (int count, int key){ TuiWinInfoPtr winInfo; if (!tui_active) tui_rl_switch_mode (0/*notused*/, 0/*notused*/); winInfo = tuiNextWin (tuiWinWithFocus ()); if (winInfo) { tuiSetWinFocusTo (winInfo); if (dataWin && dataWin->generic.isVisible) tuiRefreshDataWin (); keypad (cmdWin->generic.handle, (winInfo != cmdWin)); } return 0;}/* TUI readline command. Execute the gdb command bound to the specified key. */static inttui_rl_command_key (int count, int key){ int i; reinitialize_more_filter (); for (i = 0; tui_commands[i].cmd; i++) { if (tui_commands[i].key == key) { /* Must save the command because it can be modified by execute_command. */ char* cmd = alloca (strlen (tui_commands[i].cmd) + 1); strcpy (cmd, tui_commands[i].cmd); execute_command (cmd, TRUE); return 0; } } return 0;}/* TUI readline command. Temporarily leave the TUI SingleKey mode to allow editing a gdb command with the normal readline. Once the command is executed, the TUI SingleKey mode is installed back. */static inttui_rl_command_mode (int count, int key){ tui_set_key_mode (tui_one_command_mode); return rl_insert (count, key);}/* TUI readline command. Switch between TUI SingleKey mode and gdb readline editing. */static inttui_rl_next_keymap (int notused1, int notused2){ if (!tui_active) tui_rl_switch_mode (0/*notused*/, 0/*notused*/); tui_set_key_mode (tui_current_key_mode == tui_command_mode ? tui_single_key_mode : tui_command_mode); return 0;}/* Readline hook to redisplay ourself the gdb prompt. In the SingleKey mode, the prompt is not printed so that the command window is cleaner. It will be displayed if we temporarily leave the SingleKey mode. */static inttui_rl_startup_hook (){ rl_already_prompted = 1; if (tui_current_key_mode != tui_command_mode) tui_set_key_mode (tui_single_key_mode); tui_redisplay_readline (); return 0;}/* Change the TUI key mode by installing the appropriate readline keymap. */voidtui_set_key_mode (enum tui_key_mode mode){ tui_current_key_mode = mode; rl_set_keymap (mode == tui_single_key_mode ? tui_keymap : tui_readline_standard_keymap); tuiShowLocatorContent ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -