e51e1b9399714e477ef06c24e31f5c63d59ad3f4
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);
66 static Opaque
_tui_vDo (TuiOpaqueFuncPtr
, va_list);
70 /***********************
72 ************************/
80 extern void init_page_info ();
81 extern void initialize_tui_files (void);
83 initialize_tui_files ();
84 initializeStaticData ();
87 setTermHeightTo (LINES
);
88 setTermWidthTo (COLS
);
90 wrefresh (cmdWin
->generic
.handle
);
92 /* Don't hook debugger output if doing command-window
93 * the XDB way. However, one thing we do want to do in
94 * XDB style is set up the scrolling region to be
95 * the bottom of the screen (tuiTermUnsetup()).
97 fputs_unfiltered_hook
= NULL
;
98 rl_initialize (); /* need readline initialization to
99 * create termcap sequences
101 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
111 tuiInitWindows (void)
115 tuiSetLocatorContent (0);
116 showLayout (SRC_COMMAND
);
117 keypad (cmdWin
->generic
.handle
, TRUE
);
121 tuiSetWinFocusTo (srcWin
);
124 } /* tuiInitWindows */
129 ** Kill signal handler and cleanup termination method
132 tuiResetScreen (void)
134 TuiWinType type
= SRC_WIN
;
136 keypad (cmdWin
->generic
.handle
, FALSE
);
137 for (; type
< MAX_MAJOR_WINDOWS
; type
++)
139 if (m_winPtrNotNull (winList
[type
]) &&
140 winList
[type
]->generic
.type
!= UNDEFINED_WIN
&&
141 !winList
[type
]->generic
.isVisible
)
142 tuiDelWindow (winList
[type
]);
152 } /* tuiResetScreen */
157 ** Kill signal handler and cleanup termination method
163 extern char *term_cursor_move
;
165 signal (SIGINT
, SIG_IGN
);
166 tuiTermSetup (0); /* Restore scrolling region to whole screen */
167 keypad (cmdWin
->generic
.handle
, FALSE
);
170 buffer
= tgoto (term_cursor_move
, 0, termHeight ());
171 tputs (buffer
, 1, putchar
);
182 tuiError (char *string
, int exitGdb
)
184 puts_unfiltered (string
);
197 ** tuiError with args in a va_list.
200 tui_vError (va_list args
)
205 string
= va_arg (args
, char *);
206 exitGdb
= va_arg (args
, int);
208 tuiError (string
, exitGdb
);
216 ** Wrapper on top of free() to ensure that input address is greater than 0x0
221 if (ptr
!= (char *) NULL
)
230 /* tuiGetLowDisassemblyAddress().
231 ** Determine what the low address will be to display in the TUI's
232 ** disassembly window. This may or may not be the same as the
233 ** low address input.
236 tuiGetLowDisassemblyAddress (Opaque low
, Opaque pc
)
242 ** Determine where to start the disassembly so that the pc is about in the
243 ** middle of the viewport.
245 for (line
= 0, newLow
= pc
;
247 line
< (tuiDefaultWinViewportHeight (DISASSEM_WIN
,
248 DISASSEM_COMMAND
) / 2));)
252 newLow
-= sizeof (bfd_getb32 (buffer
));
257 } /* tuiGetLowDisassemblyAddress */
260 /* tui_vGetLowDisassemblyAddress().
261 ** Determine what the low address will be to display in the TUI's
262 ** disassembly window with args in a va_list.
265 tui_vGetLowDisassemblyAddress (va_list args
)
272 low
= va_arg (args
, Opaque
);
273 pc
= va_arg (args
, Opaque
);
275 return (tuiGetLowDisassemblyAddress (low
, pc
));
277 } /* tui_vGetLowDisassemblyAddress */
282 ** General purpose function to execute a tui function. Transitions
283 ** between curses and the are handled here. This function is called
284 ** by non-tui gdb functions.
286 ** Errors are caught here.
287 ** If there is no error, the value returned by 'func' is returned.
288 ** If there is an error, then zero is returned.
290 ** Must not be called with immediate_quit in effect (bad things might
291 ** happen, say we got a signal in the middle of a memcpy to quit_return).
292 ** This is an OK restriction; with very few exceptions immediate_quit can
293 ** be replaced by judicious use of QUIT.
296 tuiDo (TuiOpaqueFuncPtr func
, ...)
298 extern int terminal_is_ours
;
300 Opaque ret
= (Opaque
) NULL
;
302 /* It is an error to be tuiDo'ing if we
303 * don't own the terminal.
305 if (!terminal_is_ours
)
312 va_start (args
, func
);
313 ret
= _tui_vDo (func
, args
);
322 ** tuiDoAndReturnToTop().
323 ** General purpose function to execute a tui function. Transitions
324 ** between curses and the are handled here. This function is called
325 ** by non-tui gdb functions who wish to reset gdb to the top level.
326 ** After the tuiDo is performed, a return to the top level occurs.
328 ** Errors are caught here.
329 ** If there is no error, the value returned by 'func' is returned.
330 ** If there is an error, then zero is returned.
332 ** Must not be called with immediate_quit in effect (bad things might
333 ** happen, say we got a signal in the middle of a memcpy to quit_return).
334 ** This is an OK restriction; with very few exceptions immediate_quit can
335 ** be replaced by judicious use of QUIT.
339 tuiDoAndReturnToTop (TuiOpaqueFuncPtr func
, ...)
341 extern int terminal_is_ours
;
343 Opaque ret
= (Opaque
) NULL
;
345 /* It is an error to be tuiDo'ing if we
346 * don't own the terminal.
348 if (!terminal_is_ours
)
355 va_start (args
, func
);
356 ret
= _tui_vDo (func
, args
);
358 /* force a return to the top level */
359 return_to_top_level (RETURN_ERROR
);
363 } /* tuiDoAndReturnToTop */
367 tui_vSelectSourceSymtab (va_list args
)
369 struct symtab
*s
= va_arg (args
, struct symtab
*);
371 select_source_symtab (s
);
373 } /* tui_vSelectSourceSymtab */
377 ** _initialize_tui().
378 ** Function to initialize gdb commands, for tui window manipulation.
381 _initialize_tui (void)
386 add_com ("toggle", class_tui
, _toggle_command
,
387 "Toggle Terminal UI Features\n\
388 Usage: Toggle $fregs\n\
389 \tToggles between single and double precision floating point registers.\n");
395 helpStr
= "Toggle Specified Features\n\
396 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
398 helpStr
= "Toggle Specified Features\nUsage:toggle breakpoints";
399 add_abbrev_prefix_cmd ("toggle",
407 } /* _initialize_tui */
411 ** va_catch_errors().
412 ** General purpose function to execute a function, catching errors.
413 ** If there is no error, the value returned by 'func' is returned.
414 ** If there is error, then zero is returned.
415 ** Note that 'func' must take a variable argument list as well.
417 ** Must not be called with immediate_quit in effect (bad things might
418 ** happen, say we got a signal in the middle of a memcpy to quit_return).
419 ** This is an OK restriction; with very few exceptions immediate_quit can
420 ** be replaced by judicious use of QUIT.
423 va_catch_errors (TuiOpaqueFuncPtr func
, va_list args
)
425 Opaque ret
= (Opaque
) NULL
;
428 ** We could have used catch_errors(), but it doesn't handle variable args.
429 ** Also, for the tui, we always want to catch all errors, so we don't
430 ** need to pass a mask, or an error string.
435 struct cleanup
*saved_cleanup_chain
;
436 char *saved_error_pre_print
;
437 char *saved_quit_pre_print
;
438 extern jmp_buf error_return
;
439 extern jmp_buf quit_return
;
441 saved_cleanup_chain
= save_cleanups ();
442 saved_error_pre_print
= error_pre_print
;
443 saved_quit_pre_print
= quit_pre_print
;
445 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (jmp_buf));
446 error_pre_print
= "";
447 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
450 if (setjmp (tmp_jmp
) == 0)
452 va_list argList
= args
;
453 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
454 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
455 ret
= func (argList
);
457 restore_cleanups (saved_cleanup_chain
);
458 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
459 error_pre_print
= saved_error_pre_print
;
460 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
461 quit_pre_print
= saved_quit_pre_print
;
468 ** Catch errors occurring in tui or non tui function, handling
469 ** variable param lists. Note that 'func' must take a variable
470 ** argument list as well.
473 vcatch_errors (OpaqueFuncPtr func
, ...)
475 Opaque ret
= (Opaque
) NULL
;
477 va_start (args
, func
);
479 va_arg(args, OpaqueFuncPtr);
481 ret
= va_catch_errors (func
, args
);
489 strcat_to_buf (char *buf
, int buflen
, char *itemToAdd
)
491 if (itemToAdd
!= (char *) NULL
&& buf
!= (char *) NULL
)
493 if ((strlen (buf
) + strlen (itemToAdd
)) <= buflen
)
494 strcat (buf
, itemToAdd
);
496 strncat (buf
, itemToAdd
, (buflen
- strlen (buf
)));
500 } /* strcat_to_buf */
504 strcat_to_buf_with_fmt (char *buf
, int bufLen
, char *format
, ...)
507 struct cleanup
*old_cleanups
;
509 va_start (args
, format
);
510 vasprintf (&linebuffer
, format
, args
);
511 old_cleanups
= make_cleanup (xfree
, linebuffer
);
512 strcat_to_buf (buf
, bufLen
, linebuffer
);
513 do_cleanups (old_cleanups
);
521 /***********************
523 ************************/
528 ** General purpose function to execute a tui function. Transitions
529 ** between curses and the are handled here. This function is called
530 ** by non-tui gdb functions.
532 ** Errors are caught here.
533 ** If there is no error, the value returned by 'func' is returned.
534 ** If there is an error, then zero is returned.
536 ** Must not be called with immediate_quit in effect (bad things might
537 ** happen, say we got a signal in the middle of a memcpy to quit_return).
538 ** This is an OK restriction; with very few exceptions immediate_quit can
539 ** be replaced by judicious use of QUIT.
542 _tui_vDo (TuiOpaqueFuncPtr func
, va_list args
)
544 extern int terminal_is_ours
;
546 Opaque ret
= (Opaque
) NULL
;
548 /* It is an error to be tuiDo'ing if we
549 * don't own the terminal.
551 if (!terminal_is_ours
)
556 /* If doing command window the "XDB way" (command window
557 * is unmanaged by curses...
559 /* Set up terminal for TUI */
562 ret
= va_catch_errors (func
, args
);
564 /* Set up terminal for command window */
565 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
573 _toggle_command (char *arg
, int fromTTY
)
575 printf_filtered ("Specify feature to toggle.\n%s\n",
576 (tui_version
) ? TUI_TOGGLE_USAGE
: TOGGLE_USAGE
);
578 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
583 ** _tui_vToggle_command().
586 _tui_vToggle_command (va_list args
)
591 arg
= va_arg (args
, char *);
593 if (arg
== (char *) NULL
)
594 printf_filtered (TOGGLE_USAGE
);
597 char *ptr
= (char *) tuiStrDup (arg
);
600 for (i
= 0; (ptr
[i
]); i
++)
601 ptr
[i
] = toupper (arg
[i
]);
603 if (subset_compare (ptr
, TUI_FLOAT_REGS_NAME
))
604 tuiToggleFloatRegs ();
605 /* else if (subset_compare(ptr, "ANOTHER TOGGLE OPTION"))
609 printf_filtered (TOGGLE_USAGE
);
614 } /* _tuiToggle_command */
623 ** reset the teletype mode bits to a sensible state.
626 #if ! defined (USG) && defined (TIOCGETC)
628 #endif /* !USG && TIOCGETC */
632 if (ldisc
== NTTYDISC
)
634 ioctl (FILEDES
, TIOCGLTC
, <c
);
635 ltc
.t_suspc
= CHK (ltc
.t_suspc
, CTRL ('Z'));
636 ltc
.t_dsuspc
= CHK (ltc
.t_dsuspc
, CTRL ('Y'));
637 ltc
.t_rprntc
= CHK (ltc
.t_rprntc
, CTRL ('R'));
638 ltc
.t_flushc
= CHK (ltc
.t_flushc
, CTRL ('O'));
639 ltc
.t_werasc
= CHK (ltc
.t_werasc
, CTRL ('W'));
640 ltc
.t_lnextc
= CHK (ltc
.t_lnextc
, CTRL ('V'));
641 ioctl (FILEDES
, TIOCSLTC
, <c
);
643 #endif /* UCB_NTTY */
646 ioctl (FILEDES
, TIOCGETC
, &tbuf
);
647 tbuf
.t_intrc
= CHK (tbuf
.t_intrc
, CTRL ('?'));
648 tbuf
.t_quitc
= CHK (tbuf
.t_quitc
, CTRL ('\\'));
649 tbuf
.t_startc
= CHK (tbuf
.t_startc
, CTRL ('Q'));
650 tbuf
.t_stopc
= CHK (tbuf
.t_stopc
, CTRL ('S'));
651 tbuf
.t_eofc
= CHK (tbuf
.t_eofc
, CTRL ('D'));
652 /* brkc is left alone */
653 ioctl (FILEDES
, TIOCSETC
, &tbuf
);
654 #endif /* TIOCGETC */
655 mode
.sg_flags
&= ~(RAW
659 | VTDELAY
| ALLDELAY
);
660 mode
.sg_flags
|= XTABS
| ECHO
| CRMOD
| ANYP
;
662 ioctl (FILEDES
, TCGETA
, &mode
);
663 mode
.c_cc
[VINTR
] = CHK (mode
.c_cc
[VINTR
], CTRL ('?'));
664 mode
.c_cc
[VQUIT
] = CHK (mode
.c_cc
[VQUIT
], CTRL ('\\'));
665 mode
.c_cc
[VEOF
] = CHK (mode
.c_cc
[VEOF
], CTRL ('D'));
667 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| INLCR
| IGNCR
| IUCLC
| IXOFF
);
668 mode
.c_iflag
|= (BRKINT
| ISTRIP
| ICRNL
| IXON
);
669 mode
.c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|
670 NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
);
671 mode
.c_oflag
|= (OPOST
| ONLCR
);
672 mode
.c_cflag
&= ~(CSIZE
| PARODD
| CLOCAL
);
674 mode
.c_cflag
|= (CS8
| CREAD
);
675 #else /*hp9000s800 */
676 mode
.c_cflag
|= (CS8
| CSTOPB
| CREAD
);
677 #endif /* hp9000s800 */
678 mode
.c_lflag
&= ~(XCASE
| ECHONL
| NOFLSH
);
679 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOK
);
680 ioctl (FILEDES
, TCSETAW
, &mode
);