Home | History | Annotate | Line # | Download | only in tui
tui.c revision 1.1
      1  1.1  christos /* General functions for the WDB TUI.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 1998-2014 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    Contributed by Hewlett-Packard Company.
      6  1.1  christos 
      7  1.1  christos    This file is part of GDB.
      8  1.1  christos 
      9  1.1  christos    This program is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos    (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos    This program is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21  1.1  christos 
     22  1.1  christos #include "defs.h"
     23  1.1  christos #include "gdbcmd.h"
     24  1.1  christos #include "tui/tui.h"
     25  1.1  christos #include "tui/tui-hooks.h"
     26  1.1  christos #include "tui/tui-data.h"
     27  1.1  christos #include "tui/tui-layout.h"
     28  1.1  christos #include "tui/tui-io.h"
     29  1.1  christos #include "tui/tui-regs.h"
     30  1.1  christos #include "tui/tui-stack.h"
     31  1.1  christos #include "tui/tui-win.h"
     32  1.1  christos #include "tui/tui-winsource.h"
     33  1.1  christos #include "tui/tui-windata.h"
     34  1.1  christos #include "target.h"
     35  1.1  christos #include "frame.h"
     36  1.1  christos #include "breakpoint.h"
     37  1.1  christos #include "inferior.h"
     38  1.1  christos #include "symtab.h"
     39  1.1  christos #include "source.h"
     40  1.1  christos 
     41  1.1  christos #include <stdio.h>
     42  1.1  christos #include <stdlib.h>
     43  1.1  christos #include <ctype.h>
     44  1.1  christos #include <signal.h>
     45  1.1  christos #include <fcntl.h>
     46  1.1  christos #if 0
     47  1.1  christos #include <termio.h>
     48  1.1  christos #endif
     49  1.1  christos #include <setjmp.h>
     50  1.1  christos 
     51  1.1  christos #include "gdb_curses.h"
     52  1.1  christos 
     53  1.1  christos /* This redefines CTRL if it is not already defined, so it must come
     54  1.1  christos    after terminal state releated include files like <term.h> and
     55  1.1  christos    "gdb_curses.h".  */
     56  1.1  christos #include "readline/readline.h"
     57  1.1  christos 
     58  1.1  christos /* Tells whether the TUI is active or not.  */
     59  1.1  christos int tui_active = 0;
     60  1.1  christos static int tui_finish_init = 1;
     61  1.1  christos 
     62  1.1  christos enum tui_key_mode tui_current_key_mode = TUI_COMMAND_MODE;
     63  1.1  christos 
     64  1.1  christos struct tui_char_command
     65  1.1  christos {
     66  1.1  christos   unsigned char key;
     67  1.1  christos   const char *cmd;
     68  1.1  christos };
     69  1.1  christos 
     70  1.1  christos /* Key mapping to gdb commands when the TUI is using the single key
     71  1.1  christos    mode.  */
     72  1.1  christos static const struct tui_char_command tui_commands[] = {
     73  1.1  christos   { 'c', "continue" },
     74  1.1  christos   { 'd', "down" },
     75  1.1  christos   { 'f', "finish" },
     76  1.1  christos   { 'n', "next" },
     77  1.1  christos   { 'r', "run" },
     78  1.1  christos   { 's', "step" },
     79  1.1  christos   { 'u', "up" },
     80  1.1  christos   { 'v', "info locals" },
     81  1.1  christos   { 'w', "where" },
     82  1.1  christos   { 0, 0 },
     83  1.1  christos };
     84  1.1  christos 
     85  1.1  christos static Keymap tui_keymap;
     86  1.1  christos static Keymap tui_readline_standard_keymap;
     87  1.1  christos 
     88  1.1  christos /* TUI readline command.
     89  1.1  christos    Switch the output mode between TUI/standard gdb.  */
     90  1.1  christos static int
     91  1.1  christos tui_rl_switch_mode (int notused1, int notused2)
     92  1.1  christos {
     93  1.1  christos   if (tui_active)
     94  1.1  christos     {
     95  1.1  christos       tui_disable ();
     96  1.1  christos       rl_prep_terminal (0);
     97  1.1  christos     }
     98  1.1  christos   else
     99  1.1  christos     {
    100  1.1  christos       rl_deprep_terminal ();
    101  1.1  christos       tui_enable ();
    102  1.1  christos     }
    103  1.1  christos 
    104  1.1  christos   /* Clear the readline in case switching occurred in middle of
    105  1.1  christos      something.  */
    106  1.1  christos   if (rl_end)
    107  1.1  christos     rl_kill_text (0, rl_end);
    108  1.1  christos 
    109  1.1  christos   /* Since we left the curses mode, the terminal mode is restored to
    110  1.1  christos      some previous state.  That state may not be suitable for readline
    111  1.1  christos      to work correctly (it may be restored in line mode).  We force an
    112  1.1  christos      exit of the current readline so that readline is re-entered and
    113  1.1  christos      it will be able to setup the terminal for its needs.  By
    114  1.1  christos      re-entering in readline, we also redisplay its prompt in the
    115  1.1  christos      non-curses mode.  */
    116  1.1  christos   rl_newline (1, '\n');
    117  1.1  christos 
    118  1.1  christos   /* Make sure the \n we are returning does not repeat the last
    119  1.1  christos      command.  */
    120  1.1  christos   dont_repeat ();
    121  1.1  christos   return 0;
    122  1.1  christos }
    123  1.1  christos 
    124  1.1  christos /* TUI readline command.
    125  1.1  christos    Change the TUI layout to show a next layout.
    126  1.1  christos    This function is bound to CTRL-X 2.  It is intended to provide
    127  1.1  christos    a functionality close to the Emacs split-window command.  We
    128  1.1  christos    always show two windows (src+asm), (src+regs) or (asm+regs).  */
    129  1.1  christos static int
    130  1.1  christos tui_rl_change_windows (int notused1, int notused2)
    131  1.1  christos {
    132  1.1  christos   if (!tui_active)
    133  1.1  christos     tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
    134  1.1  christos 
    135  1.1  christos   if (tui_active)
    136  1.1  christos     {
    137  1.1  christos       enum tui_layout_type new_layout;
    138  1.1  christos       enum tui_register_display_type regs_type = TUI_UNDEFINED_REGS;
    139  1.1  christos 
    140  1.1  christos       new_layout = tui_current_layout ();
    141  1.1  christos 
    142  1.1  christos       /* Select a new layout to have a rolling layout behavior with
    143  1.1  christos 	 always two windows (except when undefined).  */
    144  1.1  christos       switch (new_layout)
    145  1.1  christos 	{
    146  1.1  christos 	case SRC_COMMAND:
    147  1.1  christos 	  new_layout = SRC_DISASSEM_COMMAND;
    148  1.1  christos 	  break;
    149  1.1  christos 
    150  1.1  christos 	case DISASSEM_COMMAND:
    151  1.1  christos 	  new_layout = SRC_DISASSEM_COMMAND;
    152  1.1  christos 	  break;
    153  1.1  christos 
    154  1.1  christos 	case SRC_DATA_COMMAND:
    155  1.1  christos 	  new_layout = SRC_DISASSEM_COMMAND;
    156  1.1  christos 	  break;
    157  1.1  christos 
    158  1.1  christos 	case SRC_DISASSEM_COMMAND:
    159  1.1  christos 	  new_layout = DISASSEM_DATA_COMMAND;
    160  1.1  christos 	  break;
    161  1.1  christos 
    162  1.1  christos 	case DISASSEM_DATA_COMMAND:
    163  1.1  christos 	  new_layout = SRC_DATA_COMMAND;
    164  1.1  christos 	  break;
    165  1.1  christos 
    166  1.1  christos 	default:
    167  1.1  christos 	  new_layout = SRC_COMMAND;
    168  1.1  christos 	  break;
    169  1.1  christos 	}
    170  1.1  christos       tui_set_layout (new_layout, regs_type);
    171  1.1  christos     }
    172  1.1  christos   return 0;
    173  1.1  christos }
    174  1.1  christos 
    175  1.1  christos /* TUI readline command.
    176  1.1  christos    Delete the second TUI window to only show one.  */
    177  1.1  christos static int
    178  1.1  christos tui_rl_delete_other_windows (int notused1, int notused2)
    179  1.1  christos {
    180  1.1  christos   if (!tui_active)
    181  1.1  christos     tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
    182  1.1  christos 
    183  1.1  christos   if (tui_active)
    184  1.1  christos     {
    185  1.1  christos       enum tui_layout_type new_layout;
    186  1.1  christos       enum tui_register_display_type regs_type = TUI_UNDEFINED_REGS;
    187  1.1  christos 
    188  1.1  christos       new_layout = tui_current_layout ();
    189  1.1  christos 
    190  1.1  christos       /* Kill one window.  */
    191  1.1  christos       switch (new_layout)
    192  1.1  christos 	{
    193  1.1  christos 	case SRC_COMMAND:
    194  1.1  christos 	case SRC_DATA_COMMAND:
    195  1.1  christos 	case SRC_DISASSEM_COMMAND:
    196  1.1  christos 	default:
    197  1.1  christos 	  new_layout = SRC_COMMAND;
    198  1.1  christos 	  break;
    199  1.1  christos 
    200  1.1  christos 	case DISASSEM_COMMAND:
    201  1.1  christos 	case DISASSEM_DATA_COMMAND:
    202  1.1  christos 	  new_layout = DISASSEM_COMMAND;
    203  1.1  christos 	  break;
    204  1.1  christos 	}
    205  1.1  christos       tui_set_layout (new_layout, regs_type);
    206  1.1  christos     }
    207  1.1  christos   return 0;
    208  1.1  christos }
    209  1.1  christos 
    210  1.1  christos /* TUI readline command.
    211  1.1  christos    Switch the active window to give the focus to a next window.  */
    212  1.1  christos static int
    213  1.1  christos tui_rl_other_window (int count, int key)
    214  1.1  christos {
    215  1.1  christos   struct tui_win_info *win_info;
    216  1.1  christos 
    217  1.1  christos   if (!tui_active)
    218  1.1  christos     tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
    219  1.1  christos 
    220  1.1  christos   win_info = tui_next_win (tui_win_with_focus ());
    221  1.1  christos   if (win_info)
    222  1.1  christos     {
    223  1.1  christos       tui_set_win_focus_to (win_info);
    224  1.1  christos       if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
    225  1.1  christos         tui_refresh_data_win ();
    226  1.1  christos       keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
    227  1.1  christos     }
    228  1.1  christos   return 0;
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos /* TUI readline command.
    232  1.1  christos    Execute the gdb command bound to the specified key.  */
    233  1.1  christos static int
    234  1.1  christos tui_rl_command_key (int count, int key)
    235  1.1  christos {
    236  1.1  christos   int i;
    237  1.1  christos 
    238  1.1  christos   reinitialize_more_filter ();
    239  1.1  christos   for (i = 0; tui_commands[i].cmd; i++)
    240  1.1  christos     {
    241  1.1  christos       if (tui_commands[i].key == key)
    242  1.1  christos         {
    243  1.1  christos           /* Insert the command in the readline buffer.
    244  1.1  christos              Avoid calling the gdb command here since it creates
    245  1.1  christos              a possible recursion on readline if prompt_for_continue
    246  1.1  christos              is called (See PR 9584).  The command will also appear
    247  1.1  christos              in the readline history which turns out to be better.  */
    248  1.1  christos           rl_insert_text (tui_commands[i].cmd);
    249  1.1  christos           rl_newline (1, '\n');
    250  1.1  christos 
    251  1.1  christos           /* Switch to gdb command mode while executing the command.
    252  1.1  christos              This way the gdb's continue prompty will be displayed.  */
    253  1.1  christos           tui_set_key_mode (TUI_ONE_COMMAND_MODE);
    254  1.1  christos           return 0;
    255  1.1  christos         }
    256  1.1  christos     }
    257  1.1  christos   return 0;
    258  1.1  christos }
    259  1.1  christos 
    260  1.1  christos /* TUI readline command.
    261  1.1  christos    Temporarily leave the TUI SingleKey mode to allow editing
    262  1.1  christos    a gdb command with the normal readline.  Once the command
    263  1.1  christos    is executed, the TUI SingleKey mode is installed back.  */
    264  1.1  christos static int
    265  1.1  christos tui_rl_command_mode (int count, int key)
    266  1.1  christos {
    267  1.1  christos   tui_set_key_mode (TUI_ONE_COMMAND_MODE);
    268  1.1  christos   return rl_insert (count, key);
    269  1.1  christos }
    270  1.1  christos 
    271  1.1  christos /* TUI readline command.
    272  1.1  christos    Switch between TUI SingleKey mode and gdb readline editing.  */
    273  1.1  christos static int
    274  1.1  christos tui_rl_next_keymap (int notused1, int notused2)
    275  1.1  christos {
    276  1.1  christos   if (!tui_active)
    277  1.1  christos     tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
    278  1.1  christos 
    279  1.1  christos   tui_set_key_mode (tui_current_key_mode == TUI_COMMAND_MODE
    280  1.1  christos                     ? TUI_SINGLE_KEY_MODE : TUI_COMMAND_MODE);
    281  1.1  christos   return 0;
    282  1.1  christos }
    283  1.1  christos 
    284  1.1  christos /* Readline hook to redisplay ourself the gdb prompt.
    285  1.1  christos    In the SingleKey mode, the prompt is not printed so that
    286  1.1  christos    the command window is cleaner.  It will be displayed if
    287  1.1  christos    we temporarily leave the SingleKey mode.  */
    288  1.1  christos static int
    289  1.1  christos tui_rl_startup_hook (void)
    290  1.1  christos {
    291  1.1  christos   rl_already_prompted = 1;
    292  1.1  christos   if (tui_current_key_mode != TUI_COMMAND_MODE && immediate_quit == 0)
    293  1.1  christos     tui_set_key_mode (TUI_SINGLE_KEY_MODE);
    294  1.1  christos   tui_redisplay_readline ();
    295  1.1  christos   return 0;
    296  1.1  christos }
    297  1.1  christos 
    298  1.1  christos /* Change the TUI key mode by installing the appropriate readline
    299  1.1  christos    keymap.  */
    300  1.1  christos void
    301  1.1  christos tui_set_key_mode (enum tui_key_mode mode)
    302  1.1  christos {
    303  1.1  christos   tui_current_key_mode = mode;
    304  1.1  christos   rl_set_keymap (mode == TUI_SINGLE_KEY_MODE
    305  1.1  christos                  ? tui_keymap : tui_readline_standard_keymap);
    306  1.1  christos   tui_show_locator_content ();
    307  1.1  christos }
    308  1.1  christos 
    309  1.1  christos /* Initialize readline and configure the keymap for the switching
    310  1.1  christos    key shortcut.  */
    311  1.1  christos void
    312  1.1  christos tui_initialize_readline (void)
    313  1.1  christos {
    314  1.1  christos   int i;
    315  1.1  christos   Keymap tui_ctlx_keymap;
    316  1.1  christos 
    317  1.1  christos   rl_initialize ();
    318  1.1  christos 
    319  1.1  christos   rl_add_defun ("tui-switch-mode", tui_rl_switch_mode, -1);
    320  1.1  christos   rl_add_defun ("gdb-command", tui_rl_command_key, -1);
    321  1.1  christos   rl_add_defun ("next-keymap", tui_rl_next_keymap, -1);
    322  1.1  christos 
    323  1.1  christos   tui_keymap = rl_make_bare_keymap ();
    324  1.1  christos   tui_ctlx_keymap = rl_make_bare_keymap ();
    325  1.1  christos   tui_readline_standard_keymap = rl_get_keymap ();
    326  1.1  christos 
    327  1.1  christos   for (i = 0; tui_commands[i].cmd; i++)
    328  1.1  christos     rl_bind_key_in_map (tui_commands[i].key, tui_rl_command_key, tui_keymap);
    329  1.1  christos 
    330  1.1  christos   rl_generic_bind (ISKMAP, "\\C-x", (char*) tui_ctlx_keymap, tui_keymap);
    331  1.1  christos 
    332  1.1  christos   /* Bind all other keys to tui_rl_command_mode so that we switch
    333  1.1  christos      temporarily from SingleKey mode and can enter a gdb command.  */
    334  1.1  christos   for (i = ' '; i < 0x7f; i++)
    335  1.1  christos     {
    336  1.1  christos       int j;
    337  1.1  christos 
    338  1.1  christos       for (j = 0; tui_commands[j].cmd; j++)
    339  1.1  christos         if (tui_commands[j].key == i)
    340  1.1  christos           break;
    341  1.1  christos 
    342  1.1  christos       if (tui_commands[j].cmd)
    343  1.1  christos         continue;
    344  1.1  christos 
    345  1.1  christos       rl_bind_key_in_map (i, tui_rl_command_mode, tui_keymap);
    346  1.1  christos     }
    347  1.1  christos 
    348  1.1  christos   rl_bind_key_in_map ('a', tui_rl_switch_mode, emacs_ctlx_keymap);
    349  1.1  christos   rl_bind_key_in_map ('a', tui_rl_switch_mode, tui_ctlx_keymap);
    350  1.1  christos   rl_bind_key_in_map ('A', tui_rl_switch_mode, emacs_ctlx_keymap);
    351  1.1  christos   rl_bind_key_in_map ('A', tui_rl_switch_mode, tui_ctlx_keymap);
    352  1.1  christos   rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, emacs_ctlx_keymap);
    353  1.1  christos   rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, tui_ctlx_keymap);
    354  1.1  christos   rl_bind_key_in_map ('1', tui_rl_delete_other_windows, emacs_ctlx_keymap);
    355  1.1  christos   rl_bind_key_in_map ('1', tui_rl_delete_other_windows, tui_ctlx_keymap);
    356  1.1  christos   rl_bind_key_in_map ('2', tui_rl_change_windows, emacs_ctlx_keymap);
    357  1.1  christos   rl_bind_key_in_map ('2', tui_rl_change_windows, tui_ctlx_keymap);
    358  1.1  christos   rl_bind_key_in_map ('o', tui_rl_other_window, emacs_ctlx_keymap);
    359  1.1  christos   rl_bind_key_in_map ('o', tui_rl_other_window, tui_ctlx_keymap);
    360  1.1  christos   rl_bind_key_in_map ('q', tui_rl_next_keymap, tui_keymap);
    361  1.1  christos   rl_bind_key_in_map ('s', tui_rl_next_keymap, emacs_ctlx_keymap);
    362  1.1  christos   rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap);
    363  1.1  christos }
    364  1.1  christos 
    365  1.1  christos /* Enter in the tui mode (curses).
    366  1.1  christos    When in normal mode, it installs the tui hooks in gdb, redirects
    367  1.1  christos    the gdb output, configures the readline to work in tui mode.
    368  1.1  christos    When in curses mode, it does nothing.  */
    369  1.1  christos void
    370  1.1  christos tui_enable (void)
    371  1.1  christos {
    372  1.1  christos   if (!tui_allowed_p ())
    373  1.1  christos     error (_("TUI mode not allowed"));
    374  1.1  christos 
    375  1.1  christos   if (tui_active)
    376  1.1  christos     return;
    377  1.1  christos 
    378  1.1  christos   /* To avoid to initialize curses when gdb starts, there is a defered
    379  1.1  christos      curses initialization.  This initialization is made only once
    380  1.1  christos      and the first time the curses mode is entered.  */
    381  1.1  christos   if (tui_finish_init)
    382  1.1  christos     {
    383  1.1  christos       WINDOW *w;
    384  1.1  christos 
    385  1.1  christos       w = initscr ();
    386  1.1  christos 
    387  1.1  christos       cbreak ();
    388  1.1  christos       noecho ();
    389  1.1  christos       /* timeout (1); */
    390  1.1  christos       nodelay(w, FALSE);
    391  1.1  christos       nl();
    392  1.1  christos       keypad (w, TRUE);
    393  1.1  christos       rl_initialize ();
    394  1.1  christos       tui_set_term_height_to (LINES);
    395  1.1  christos       tui_set_term_width_to (COLS);
    396  1.1  christos       def_prog_mode ();
    397  1.1  christos 
    398  1.1  christos       tui_show_frame_info (0);
    399  1.1  christos       tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
    400  1.1  christos       tui_set_win_focus_to (TUI_SRC_WIN);
    401  1.1  christos       keypad (TUI_CMD_WIN->generic.handle, TRUE);
    402  1.1  christos       wrefresh (TUI_CMD_WIN->generic.handle);
    403  1.1  christos       tui_finish_init = 0;
    404  1.1  christos     }
    405  1.1  christos   else
    406  1.1  christos     {
    407  1.1  christos      /* Save the current gdb setting of the terminal.
    408  1.1  christos         Curses will restore this state when endwin() is called.  */
    409  1.1  christos      def_shell_mode ();
    410  1.1  christos      clearok (stdscr, TRUE);
    411  1.1  christos    }
    412  1.1  christos 
    413  1.1  christos   /* Install the TUI specific hooks.  */
    414  1.1  christos   tui_install_hooks ();
    415  1.1  christos   rl_startup_hook = tui_rl_startup_hook;
    416  1.1  christos 
    417  1.1  christos   tui_update_variables ();
    418  1.1  christos 
    419  1.1  christos   tui_setup_io (1);
    420  1.1  christos 
    421  1.1  christos   tui_active = 1;
    422  1.1  christos   if (deprecated_safe_get_selected_frame ())
    423  1.1  christos      tui_show_frame_info (deprecated_safe_get_selected_frame ());
    424  1.1  christos 
    425  1.1  christos   /* Restore TUI keymap.  */
    426  1.1  christos   tui_set_key_mode (tui_current_key_mode);
    427  1.1  christos   tui_refresh_all_win ();
    428  1.1  christos 
    429  1.1  christos   /* Update gdb's knowledge of its terminal.  */
    430  1.1  christos   target_terminal_save_ours ();
    431  1.1  christos   tui_update_gdb_sizes ();
    432  1.1  christos }
    433  1.1  christos 
    434  1.1  christos /* Leave the tui mode.
    435  1.1  christos    Remove the tui hooks and configure the gdb output and readline
    436  1.1  christos    back to their original state.  The curses mode is left so that
    437  1.1  christos    the terminal setting is restored to the point when we entered.  */
    438  1.1  christos void
    439  1.1  christos tui_disable (void)
    440  1.1  christos {
    441  1.1  christos   if (!tui_active)
    442  1.1  christos     return;
    443  1.1  christos 
    444  1.1  christos   /* Restore initial readline keymap.  */
    445  1.1  christos   rl_set_keymap (tui_readline_standard_keymap);
    446  1.1  christos 
    447  1.1  christos   /* Remove TUI hooks.  */
    448  1.1  christos   tui_remove_hooks ();
    449  1.1  christos   rl_startup_hook = 0;
    450  1.1  christos   rl_already_prompted = 0;
    451  1.1  christos 
    452  1.1  christos   /* Leave curses and restore previous gdb terminal setting.  */
    453  1.1  christos   endwin ();
    454  1.1  christos 
    455  1.1  christos   /* gdb terminal has changed, update gdb internal copy of it
    456  1.1  christos      so that terminal management with the inferior works.  */
    457  1.1  christos   tui_setup_io (0);
    458  1.1  christos 
    459  1.1  christos   /* Update gdb's knowledge of its terminal.  */
    460  1.1  christos   target_terminal_save_ours ();
    461  1.1  christos 
    462  1.1  christos   tui_active = 0;
    463  1.1  christos   tui_update_gdb_sizes ();
    464  1.1  christos }
    465  1.1  christos 
    466  1.1  christos void
    467  1.1  christos strcat_to_buf (char *buf, int buflen,
    468  1.1  christos 	       const char *item_to_add)
    469  1.1  christos {
    470  1.1  christos   if (item_to_add != (char *) NULL && buf != (char *) NULL)
    471  1.1  christos     {
    472  1.1  christos       if ((strlen (buf) + strlen (item_to_add)) <= buflen)
    473  1.1  christos 	strcat (buf, item_to_add);
    474  1.1  christos       else
    475  1.1  christos 	strncat (buf, item_to_add, (buflen - strlen (buf)));
    476  1.1  christos     }
    477  1.1  christos }
    478  1.1  christos 
    479  1.1  christos #if 0
    480  1.1  christos /* Solaris <sys/termios.h> defines CTRL.  */
    481  1.1  christos #ifndef CTRL
    482  1.1  christos #define CTRL(x)         (x & ~0140)
    483  1.1  christos #endif
    484  1.1  christos 
    485  1.1  christos #define FILEDES         2
    486  1.1  christos #define CHK(val, dft)   (val<=0 ? dft : val)
    487  1.1  christos 
    488  1.1  christos static void
    489  1.1  christos tui_reset (void)
    490  1.1  christos {
    491  1.1  christos   struct termio mode;
    492  1.1  christos 
    493  1.1  christos   /* Reset the teletype mode bits to a sensible state.
    494  1.1  christos      Copied tset.c.  */
    495  1.1  christos #if defined (TIOCGETC)
    496  1.1  christos   struct tchars tbuf;
    497  1.1  christos #endif /* TIOCGETC */
    498  1.1  christos #ifdef UCB_NTTY
    499  1.1  christos   struct ltchars ltc;
    500  1.1  christos 
    501  1.1  christos   if (ldisc == NTTYDISC)
    502  1.1  christos     {
    503  1.1  christos       ioctl (FILEDES, TIOCGLTC, &ltc);
    504  1.1  christos       ltc.t_suspc = CHK (ltc.t_suspc, CTRL ('Z'));
    505  1.1  christos       ltc.t_dsuspc = CHK (ltc.t_dsuspc, CTRL ('Y'));
    506  1.1  christos       ltc.t_rprntc = CHK (ltc.t_rprntc, CTRL ('R'));
    507  1.1  christos       ltc.t_flushc = CHK (ltc.t_flushc, CTRL ('O'));
    508  1.1  christos       ltc.t_werasc = CHK (ltc.t_werasc, CTRL ('W'));
    509  1.1  christos       ltc.t_lnextc = CHK (ltc.t_lnextc, CTRL ('V'));
    510  1.1  christos       ioctl (FILEDES, TIOCSLTC, &ltc);
    511  1.1  christos     }
    512  1.1  christos #endif /* UCB_NTTY */
    513  1.1  christos #ifdef TIOCGETC
    514  1.1  christos   ioctl (FILEDES, TIOCGETC, &tbuf);
    515  1.1  christos   tbuf.t_intrc = CHK (tbuf.t_intrc, CTRL ('?'));
    516  1.1  christos   tbuf.t_quitc = CHK (tbuf.t_quitc, CTRL ('\\'));
    517  1.1  christos   tbuf.t_startc = CHK (tbuf.t_startc, CTRL ('Q'));
    518  1.1  christos   tbuf.t_stopc = CHK (tbuf.t_stopc, CTRL ('S'));
    519  1.1  christos   tbuf.t_eofc = CHK (tbuf.t_eofc, CTRL ('D'));
    520  1.1  christos   /* brkc is left alone.  */
    521  1.1  christos   ioctl (FILEDES, TIOCSETC, &tbuf);
    522  1.1  christos #endif /* TIOCGETC */
    523  1.1  christos   mode.sg_flags &= ~(RAW
    524  1.1  christos #ifdef CBREAK
    525  1.1  christos 		     | CBREAK
    526  1.1  christos #endif /* CBREAK */
    527  1.1  christos 		     | VTDELAY | ALLDELAY);
    528  1.1  christos   mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP;
    529  1.1  christos 
    530  1.1  christos   return;
    531  1.1  christos }
    532  1.1  christos #endif
    533  1.1  christos 
    534  1.1  christos void
    535  1.1  christos tui_show_source (const char *fullname, int line)
    536  1.1  christos {
    537  1.1  christos   struct symtab_and_line cursal = get_current_source_symtab_and_line ();
    538  1.1  christos 
    539  1.1  christos   /* Make sure that the source window is displayed.  */
    540  1.1  christos   tui_add_win_to_layout (SRC_WIN);
    541  1.1  christos 
    542  1.1  christos   tui_update_source_windows_with_line (cursal.symtab, line);
    543  1.1  christos   tui_update_locator_fullname (fullname);
    544  1.1  christos }
    545  1.1  christos 
    546  1.1  christos void
    547  1.1  christos tui_show_assembly (struct gdbarch *gdbarch, CORE_ADDR addr)
    548  1.1  christos {
    549  1.1  christos   tui_add_win_to_layout (DISASSEM_WIN);
    550  1.1  christos   tui_update_source_windows_with_addr (gdbarch, addr);
    551  1.1  christos }
    552  1.1  christos 
    553  1.1  christos int
    554  1.1  christos tui_is_window_visible (enum tui_win_type type)
    555  1.1  christos {
    556  1.1  christos   if (tui_active == 0)
    557  1.1  christos     return 0;
    558  1.1  christos 
    559  1.1  christos   if (tui_win_list[type] == 0)
    560  1.1  christos     return 0;
    561  1.1  christos 
    562  1.1  christos   return tui_win_list[type]->generic.is_visible;
    563  1.1  christos }
    564  1.1  christos 
    565  1.1  christos int
    566  1.1  christos tui_get_command_dimension (unsigned int *width,
    567  1.1  christos 			   unsigned int *height)
    568  1.1  christos {
    569  1.1  christos   if (!tui_active || (TUI_CMD_WIN == NULL))
    570  1.1  christos     {
    571  1.1  christos       return 0;
    572  1.1  christos     }
    573  1.1  christos 
    574  1.1  christos   *width = TUI_CMD_WIN->generic.width;
    575  1.1  christos   *height = TUI_CMD_WIN->generic.height;
    576  1.1  christos   return 1;
    577  1.1  christos }
    578