1 /* General functions for the WDB TUI.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
37 #include "tuiLayout.h"
42 /* The Solaris header files seem to provide no declaration for this at
43 all when __STDC__ is defined. This shouldn't conflict with
45 extern char *tgoto ();
47 /***********************
49 ************************/
51 /* Solaris <sys/termios.h> defines CTRL. */
53 #define CTRL(x) (x & ~0140)
55 #define CHK(val, dft) (val<=0 ? dft : val)
57 #define TOGGLE_USAGE "Usage:toggle breakpoints"
58 #define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints"
60 /*****************************
61 ** Local static forward decls
62 ******************************/
63 static void _tuiReset (void);
64 static void _toggle_command (char *, int);
65 static void _tui_vToggle_command (va_list);
69 /***********************
71 ************************/
79 extern void init_page_info ();
80 extern void initialize_tui_files (void);
82 initialize_tui_files ();
83 initializeStaticData ();
86 setTermHeightTo (LINES
);
87 setTermWidthTo (COLS
);
89 wrefresh (cmdWin
->generic
.handle
);
91 /* Don't hook debugger output if doing command-window
92 * the XDB way. However, one thing we do want to do in
93 * XDB style is set up the scrolling region to be
94 * the bottom of the screen (tuiTermUnsetup()).
96 fputs_unfiltered_hook
= NULL
;
97 rl_initialize (); /* need readline initialization to
98 * create termcap sequences
100 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
110 tuiInitWindows (void)
114 tuiSetLocatorContent (0);
115 showLayout (SRC_COMMAND
);
116 keypad (cmdWin
->generic
.handle
, TRUE
);
120 tuiSetWinFocusTo (srcWin
);
123 } /* tuiInitWindows */
128 ** Kill signal handler and cleanup termination method
131 tuiResetScreen (void)
133 TuiWinType type
= SRC_WIN
;
135 keypad (cmdWin
->generic
.handle
, FALSE
);
136 for (; type
< MAX_MAJOR_WINDOWS
; type
++)
138 if (m_winPtrNotNull (winList
[type
]) &&
139 winList
[type
]->generic
.type
!= UNDEFINED_WIN
&&
140 !winList
[type
]->generic
.isVisible
)
141 tuiDelWindow (winList
[type
]);
151 } /* tuiResetScreen */
156 ** Kill signal handler and cleanup termination method
162 extern char *term_cursor_move
;
164 signal (SIGINT
, SIG_IGN
);
165 tuiTermSetup (0); /* Restore scrolling region to whole screen */
166 keypad (cmdWin
->generic
.handle
, FALSE
);
169 buffer
= tgoto (term_cursor_move
, 0, termHeight ());
170 tputs (buffer
, 1, putchar
);
181 tuiError (char *string
, int exitGdb
)
183 puts_unfiltered (string
);
196 ** tuiError with args in a va_list.
199 tui_vError (va_list args
)
204 string
= va_arg (args
, char *);
205 exitGdb
= va_arg (args
, int);
207 tuiError (string
, exitGdb
);
215 ** Wrapper on top of free() to ensure that input address is greater than 0x0
220 if (ptr
!= (char *) NULL
)
229 /* tuiGetLowDisassemblyAddress().
230 ** Determine what the low address will be to display in the TUI's
231 ** disassembly window. This may or may not be the same as the
232 ** low address input.
235 tuiGetLowDisassemblyAddress (Opaque low
, Opaque pc
)
241 ** Determine where to start the disassembly so that the pc is about in the
242 ** middle of the viewport.
244 for (line
= 0, newLow
= pc
;
246 line
< (tuiDefaultWinViewportHeight (DISASSEM_WIN
,
247 DISASSEM_COMMAND
) / 2));)
251 newLow
-= sizeof (bfd_getb32 (buffer
));
256 } /* tuiGetLowDisassemblyAddress */
259 /* tui_vGetLowDisassemblyAddress().
260 ** Determine what the low address will be to display in the TUI's
261 ** disassembly window with args in a va_list.
264 tui_vGetLowDisassemblyAddress (va_list args
)
271 low
= va_arg (args
, Opaque
);
272 pc
= va_arg (args
, Opaque
);
274 return (tuiGetLowDisassemblyAddress (low
, pc
));
276 } /* tui_vGetLowDisassemblyAddress */
280 tui_vSelectSourceSymtab (va_list args
)
282 struct symtab
*s
= va_arg (args
, struct symtab
*);
284 select_source_symtab (s
);
286 } /* tui_vSelectSourceSymtab */
290 ** _initialize_tui().
291 ** Function to initialize gdb commands, for tui window manipulation.
294 _initialize_tui (void)
299 add_com ("toggle", class_tui
, _toggle_command
,
300 "Toggle Terminal UI Features\n\
301 Usage: Toggle $fregs\n\
302 \tToggles between single and double precision floating point registers.\n");
308 helpStr
= "Toggle Specified Features\n\
309 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
311 helpStr
= "Toggle Specified Features\nUsage:toggle breakpoints";
312 add_abbrev_prefix_cmd ("toggle",
320 } /* _initialize_tui */
324 strcat_to_buf (char *buf
, int buflen
, char *itemToAdd
)
326 if (itemToAdd
!= (char *) NULL
&& buf
!= (char *) NULL
)
328 if ((strlen (buf
) + strlen (itemToAdd
)) <= buflen
)
329 strcat (buf
, itemToAdd
);
331 strncat (buf
, itemToAdd
, (buflen
- strlen (buf
)));
335 } /* strcat_to_buf */
339 strcat_to_buf_with_fmt (char *buf
, int bufLen
, char *format
, ...)
342 struct cleanup
*old_cleanups
;
344 va_start (args
, format
);
345 vasprintf (&linebuffer
, format
, args
);
346 old_cleanups
= make_cleanup (xfree
, linebuffer
);
347 strcat_to_buf (buf
, bufLen
, linebuffer
);
348 do_cleanups (old_cleanups
);
356 /***********************
358 ************************/
363 _toggle_command (char *arg
, int fromTTY
)
365 printf_filtered ("Specify feature to toggle.\n%s\n",
366 (tui_version
) ? TUI_TOGGLE_USAGE
: TOGGLE_USAGE
);
368 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
373 ** _tui_vToggle_command().
376 _tui_vToggle_command (va_list args
)
381 arg
= va_arg (args
, char *);
383 if (arg
== (char *) NULL
)
384 printf_filtered (TOGGLE_USAGE
);
387 char *ptr
= (char *) tuiStrDup (arg
);
390 for (i
= 0; (ptr
[i
]); i
++)
391 ptr
[i
] = toupper (arg
[i
]);
393 if (subset_compare (ptr
, TUI_FLOAT_REGS_NAME
))
394 tuiToggleFloatRegs ();
395 /* else if (subset_compare(ptr, "ANOTHER TOGGLE OPTION"))
399 printf_filtered (TOGGLE_USAGE
);
404 } /* _tuiToggle_command */
413 ** reset the teletype mode bits to a sensible state.
416 #if ! defined (USG) && defined (TIOCGETC)
418 #endif /* !USG && TIOCGETC */
422 if (ldisc
== NTTYDISC
)
424 ioctl (FILEDES
, TIOCGLTC
, <c
);
425 ltc
.t_suspc
= CHK (ltc
.t_suspc
, CTRL ('Z'));
426 ltc
.t_dsuspc
= CHK (ltc
.t_dsuspc
, CTRL ('Y'));
427 ltc
.t_rprntc
= CHK (ltc
.t_rprntc
, CTRL ('R'));
428 ltc
.t_flushc
= CHK (ltc
.t_flushc
, CTRL ('O'));
429 ltc
.t_werasc
= CHK (ltc
.t_werasc
, CTRL ('W'));
430 ltc
.t_lnextc
= CHK (ltc
.t_lnextc
, CTRL ('V'));
431 ioctl (FILEDES
, TIOCSLTC
, <c
);
433 #endif /* UCB_NTTY */
436 ioctl (FILEDES
, TIOCGETC
, &tbuf
);
437 tbuf
.t_intrc
= CHK (tbuf
.t_intrc
, CTRL ('?'));
438 tbuf
.t_quitc
= CHK (tbuf
.t_quitc
, CTRL ('\\'));
439 tbuf
.t_startc
= CHK (tbuf
.t_startc
, CTRL ('Q'));
440 tbuf
.t_stopc
= CHK (tbuf
.t_stopc
, CTRL ('S'));
441 tbuf
.t_eofc
= CHK (tbuf
.t_eofc
, CTRL ('D'));
442 /* brkc is left alone */
443 ioctl (FILEDES
, TIOCSETC
, &tbuf
);
444 #endif /* TIOCGETC */
445 mode
.sg_flags
&= ~(RAW
449 | VTDELAY
| ALLDELAY
);
450 mode
.sg_flags
|= XTABS
| ECHO
| CRMOD
| ANYP
;
452 ioctl (FILEDES
, TCGETA
, &mode
);
453 mode
.c_cc
[VINTR
] = CHK (mode
.c_cc
[VINTR
], CTRL ('?'));
454 mode
.c_cc
[VQUIT
] = CHK (mode
.c_cc
[VQUIT
], CTRL ('\\'));
455 mode
.c_cc
[VEOF
] = CHK (mode
.c_cc
[VEOF
], CTRL ('D'));
457 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| INLCR
| IGNCR
| IUCLC
| IXOFF
);
458 mode
.c_iflag
|= (BRKINT
| ISTRIP
| ICRNL
| IXON
);
459 mode
.c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|
460 NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
);
461 mode
.c_oflag
|= (OPOST
| ONLCR
);
462 mode
.c_cflag
&= ~(CSIZE
| PARODD
| CLOCAL
);
464 mode
.c_cflag
|= (CS8
| CREAD
);
465 #else /*hp9000s800 */
466 mode
.c_cflag
|= (CS8
| CSTOPB
| CREAD
);
467 #endif /* hp9000s800 */
468 mode
.c_lflag
&= ~(XCASE
| ECHONL
| NOFLSH
);
469 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOK
);
470 ioctl (FILEDES
, TCSETAW
, &mode
);