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 ************************/
85 extern void init_page_info ();
86 extern void initialize_tui_files (void);
88 initialize_tui_files ();
89 initializeStaticData ();
92 setTermHeightTo (LINES
);
93 setTermWidthTo (COLS
);
95 wrefresh (cmdWin
->generic
.handle
);
97 /* Don't hook debugger output if doing command-window
98 * the XDB way. However, one thing we do want to do in
99 * XDB style is set up the scrolling region to be
100 * the bottom of the screen (tuiTermUnsetup()).
102 fputs_unfiltered_hook
= NULL
;
103 rl_initialize (); /* need readline initialization to
104 * create termcap sequences
106 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
117 tuiInitWindows (void)
124 tuiSetLocatorContent (0);
125 showLayout (SRC_COMMAND
);
126 keypad (cmdWin
->generic
.handle
, TRUE
);
130 tuiSetWinFocusTo (srcWin
);
133 } /* tuiInitWindows */
138 ** Kill signal handler and cleanup termination method
142 tuiResetScreen (void)
147 TuiWinType type
= SRC_WIN
;
149 keypad (cmdWin
->generic
.handle
, FALSE
);
150 for (; type
< MAX_MAJOR_WINDOWS
; type
++)
152 if (m_winPtrNotNull (winList
[type
]) &&
153 winList
[type
]->generic
.type
!= UNDEFINED_WIN
&&
154 !winList
[type
]->generic
.isVisible
)
155 tuiDelWindow (winList
[type
]);
165 } /* tuiResetScreen */
170 ** Kill signal handler and cleanup termination method
180 extern char *term_cursor_move
;
182 signal (SIGINT
, SIG_IGN
);
183 tuiTermSetup (0); /* Restore scrolling region to whole screen */
184 keypad (cmdWin
->generic
.handle
, FALSE
);
187 buffer
= tgoto (term_cursor_move
, 0, termHeight ());
188 tputs (buffer
, 1, putchar
);
204 tuiError (string
, exitGdb
)
209 puts_unfiltered (string
);
222 ** tuiError with args in a va_list.
236 string
= va_arg (args
, char *);
237 exitGdb
= va_arg (args
, int);
239 tuiError (string
, exitGdb
);
247 ** Wrapper on top of free() to ensure that input address is greater than 0x0
258 if (ptr
!= (char *) NULL
)
267 /* tuiGetLowDisassemblyAddress().
268 ** Determine what the low address will be to display in the TUI's
269 ** disassembly window. This may or may not be the same as the
270 ** low address input.
274 tuiGetLowDisassemblyAddress (
278 tuiGetLowDisassemblyAddress (low
, pc
)
287 ** Determine where to start the disassembly so that the pc is about in the
288 ** middle of the viewport.
290 for (line
= 0, newLow
= pc
;
292 line
< (tuiDefaultWinViewportHeight (DISASSEM_WIN
,
293 DISASSEM_COMMAND
) / 2));)
297 newLow
-= sizeof (bfd_getb32 (buffer
));
302 } /* tuiGetLowDisassemblyAddress */
305 /* tui_vGetLowDisassemblyAddress().
306 ** Determine what the low address will be to display in the TUI's
307 ** disassembly window with args in a va_list.
311 tui_vGetLowDisassemblyAddress (
314 tui_vGetLowDisassemblyAddress (args
)
323 low
= va_arg (args
, Opaque
);
324 pc
= va_arg (args
, Opaque
);
326 return (tuiGetLowDisassemblyAddress (low
, pc
));
328 } /* tui_vGetLowDisassemblyAddress */
333 ** General purpose function to execute a tui function. Transitions
334 ** between curses and the are handled here. This function is called
335 ** by non-tui gdb functions.
337 ** Errors are caught here.
338 ** If there is no error, the value returned by 'func' is returned.
339 ** If there is an error, then zero is returned.
341 ** Must not be called with immediate_quit in effect (bad things might
342 ** happen, say we got a signal in the middle of a memcpy to quit_return).
343 ** This is an OK restriction; with very few exceptions immediate_quit can
344 ** be replaced by judicious use of QUIT.
349 TuiOpaqueFuncPtr func
,...)
351 tuiDo (func
, va_alist
)
352 TuiOpaqueFuncPtr func
;
356 extern int terminal_is_ours
;
358 Opaque ret
= (Opaque
) NULL
;
360 /* It is an error to be tuiDo'ing if we
361 * don't own the terminal.
363 if (!terminal_is_ours
)
371 va_start (args
, func
);
375 ret
= _tui_vDo (func
, args
);
384 ** tuiDoAndReturnToTop().
385 ** General purpose function to execute a tui function. Transitions
386 ** between curses and the are handled here. This function is called
387 ** by non-tui gdb functions who wish to reset gdb to the top level.
388 ** After the tuiDo is performed, a return to the top level occurs.
390 ** Errors are caught here.
391 ** If there is no error, the value returned by 'func' is returned.
392 ** If there is an error, then zero is returned.
394 ** Must not be called with immediate_quit in effect (bad things might
395 ** happen, say we got a signal in the middle of a memcpy to quit_return).
396 ** This is an OK restriction; with very few exceptions immediate_quit can
397 ** be replaced by judicious use of QUIT.
402 tuiDoAndReturnToTop (
403 TuiOpaqueFuncPtr func
,...)
405 tuiDoAndReturnToTop (func
, va_alist
)
406 TuiOpaqueFuncPtr func
;
410 extern int terminal_is_ours
;
412 Opaque ret
= (Opaque
) NULL
;
414 /* It is an error to be tuiDo'ing if we
415 * don't own the terminal.
417 if (!terminal_is_ours
)
425 va_start (args
, func
);
429 ret
= _tui_vDo (func
, args
);
431 /* force a return to the top level */
432 return_to_top_level (RETURN_ERROR
);
436 } /* tuiDoAndReturnToTop */
441 tui_vSelectSourceSymtab (
444 tui_vSelectSourceSymtab (args
)
448 struct symtab
*s
= va_arg (args
, struct symtab
*);
450 select_source_symtab (s
);
452 } /* tui_vSelectSourceSymtab */
456 ** _initialize_tui().
457 ** Function to initialize gdb commands, for tui window manipulation.
460 _initialize_tui (void)
465 add_com ("toggle", class_tui
, _toggle_command
,
466 "Toggle Terminal UI Features\n\
467 Usage: Toggle $fregs\n\
468 \tToggles between single and double precision floating point registers.\n");
474 helpStr
= "Toggle Specified Features\n\
475 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
477 helpStr
= "Toggle Specified Features\nUsage:toggle breakpoints";
478 add_abbrev_prefix_cmd ("toggle",
486 } /* _initialize_tui */
490 ** va_catch_errors().
491 ** General purpose function to execute a function, catching errors.
492 ** If there is no error, the value returned by 'func' is returned.
493 ** If there is error, then zero is returned.
494 ** Note that 'func' must take a variable argument list as well.
496 ** Must not be called with immediate_quit in effect (bad things might
497 ** happen, say we got a signal in the middle of a memcpy to quit_return).
498 ** This is an OK restriction; with very few exceptions immediate_quit can
499 ** be replaced by judicious use of QUIT.
504 TuiOpaqueFuncPtr func
,
507 va_catch_errors (func
, args
)
508 TuiOpaqueFuncPtr func
;
512 Opaque ret
= (Opaque
) NULL
;
515 ** We could have used catch_errors(), but it doesn't handle variable args.
516 ** Also, for the tui, we always want to catch all errors, so we don't
517 ** need to pass a mask, or an error string.
522 struct cleanup
*saved_cleanup_chain
;
523 char *saved_error_pre_print
;
524 char *saved_quit_pre_print
;
525 extern jmp_buf error_return
;
526 extern jmp_buf quit_return
;
528 saved_cleanup_chain
= save_cleanups ();
529 saved_error_pre_print
= error_pre_print
;
530 saved_quit_pre_print
= quit_pre_print
;
532 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (jmp_buf));
533 error_pre_print
= "";
534 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
537 if (setjmp (tmp_jmp
) == 0)
539 va_list argList
= args
;
540 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
541 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
542 ret
= func (argList
);
544 restore_cleanups (saved_cleanup_chain
);
545 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
546 error_pre_print
= saved_error_pre_print
;
547 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
548 quit_pre_print
= saved_quit_pre_print
;
555 ** Catch errors occurring in tui or non tui function, handling
556 ** variable param lists. Note that 'func' must take a variable
557 ** argument list as well.
562 OpaqueFuncPtr func
,...)
564 vcatch_errors (va_alist
)
567 vcatch_errors(func, va_alist)
573 Opaque ret
= (Opaque
) NULL
;
576 va_start (args
, func
);
578 va_arg(args, OpaqueFuncPtr);
584 func
= va_arg (args
, OpaqueFuncPtr
);
586 ret
= va_catch_errors (func
, args
);
600 strcat_to_buf (buf
, buflen
, itemToAdd
)
606 if (itemToAdd
!= (char *) NULL
&& buf
!= (char *) NULL
)
608 if ((strlen (buf
) + strlen (itemToAdd
)) <= buflen
)
609 strcat (buf
, itemToAdd
);
611 strncat (buf
, itemToAdd
, (buflen
- strlen (buf
)));
615 } /* strcat_to_buf */
619 #ifdef ANSI_PROTOTYPES
620 strcat_to_buf_with_fmt (
625 strcat_to_buf_with_fmt (va_alist
)
630 struct cleanup
*old_cleanups
;
632 #ifdef ANSI_PROTOTYPES
633 va_start (args
, format
);
640 buf
= va_arg (args
, char *);
641 bufLen
= va_arg (args
, int);
642 format
= va_arg (args
, char *);
644 vasprintf (&linebuffer
, format
, args
);
645 old_cleanups
= make_cleanup (xfree
, linebuffer
);
646 strcat_to_buf (buf
, bufLen
, linebuffer
);
647 do_cleanups (old_cleanups
);
655 /***********************
657 ************************/
662 ** General purpose function to execute a tui function. Transitions
663 ** between curses and the are handled here. This function is called
664 ** by non-tui gdb functions.
666 ** Errors are caught here.
667 ** If there is no error, the value returned by 'func' is returned.
668 ** If there is an error, then zero is returned.
670 ** Must not be called with immediate_quit in effect (bad things might
671 ** happen, say we got a signal in the middle of a memcpy to quit_return).
672 ** This is an OK restriction; with very few exceptions immediate_quit can
673 ** be replaced by judicious use of QUIT.
678 TuiOpaqueFuncPtr func
,
681 _tui_vDo (func
, args
)
682 TuiOpaqueFuncPtr func
;
686 extern int terminal_is_ours
;
688 Opaque ret
= (Opaque
) NULL
;
690 /* It is an error to be tuiDo'ing if we
691 * don't own the terminal.
693 if (!terminal_is_ours
)
698 /* If doing command window the "XDB way" (command window
699 * is unmanaged by curses...
701 /* Set up terminal for TUI */
704 ret
= va_catch_errors (func
, args
);
706 /* Set up terminal for command window */
707 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
720 _toggle_command (arg
, fromTTY
)
725 printf_filtered ("Specify feature to toggle.\n%s\n",
726 (tui_version
) ? TUI_TOGGLE_USAGE
: TOGGLE_USAGE
);
728 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
733 ** _tui_vToggle_command().
737 _tui_vToggle_command (
740 _tui_vToggle_command (args
)
747 arg
= va_arg (args
, char *);
749 if (arg
== (char *) NULL
)
750 printf_filtered (TOGGLE_USAGE
);
753 char *ptr
= (char *) tuiStrDup (arg
);
756 for (i
= 0; (ptr
[i
]); i
++)
757 ptr
[i
] = toupper (arg
[i
]);
759 if (subsetCompare (ptr
, TUI_FLOAT_REGS_NAME
))
760 tuiToggleFloatRegs ();
761 /* else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
765 printf_filtered (TOGGLE_USAGE
);
770 } /* _tuiToggle_command */
783 ** reset the teletype mode bits to a sensible state.
786 #if ! defined (USG) && defined (TIOCGETC)
788 #endif /* !USG && TIOCGETC */
792 if (ldisc
== NTTYDISC
)
794 ioctl (FILEDES
, TIOCGLTC
, <c
);
795 ltc
.t_suspc
= CHK (ltc
.t_suspc
, CTRL ('Z'));
796 ltc
.t_dsuspc
= CHK (ltc
.t_dsuspc
, CTRL ('Y'));
797 ltc
.t_rprntc
= CHK (ltc
.t_rprntc
, CTRL ('R'));
798 ltc
.t_flushc
= CHK (ltc
.t_flushc
, CTRL ('O'));
799 ltc
.t_werasc
= CHK (ltc
.t_werasc
, CTRL ('W'));
800 ltc
.t_lnextc
= CHK (ltc
.t_lnextc
, CTRL ('V'));
801 ioctl (FILEDES
, TIOCSLTC
, <c
);
803 #endif /* UCB_NTTY */
806 ioctl (FILEDES
, TIOCGETC
, &tbuf
);
807 tbuf
.t_intrc
= CHK (tbuf
.t_intrc
, CTRL ('?'));
808 tbuf
.t_quitc
= CHK (tbuf
.t_quitc
, CTRL ('\\'));
809 tbuf
.t_startc
= CHK (tbuf
.t_startc
, CTRL ('Q'));
810 tbuf
.t_stopc
= CHK (tbuf
.t_stopc
, CTRL ('S'));
811 tbuf
.t_eofc
= CHK (tbuf
.t_eofc
, CTRL ('D'));
812 /* brkc is left alone */
813 ioctl (FILEDES
, TIOCSETC
, &tbuf
);
814 #endif /* TIOCGETC */
815 mode
.sg_flags
&= ~(RAW
819 | VTDELAY
| ALLDELAY
);
820 mode
.sg_flags
|= XTABS
| ECHO
| CRMOD
| ANYP
;
822 ioctl (FILEDES
, TCGETA
, &mode
);
823 mode
.c_cc
[VINTR
] = CHK (mode
.c_cc
[VINTR
], CTRL ('?'));
824 mode
.c_cc
[VQUIT
] = CHK (mode
.c_cc
[VQUIT
], CTRL ('\\'));
825 mode
.c_cc
[VEOF
] = CHK (mode
.c_cc
[VEOF
], CTRL ('D'));
827 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| INLCR
| IGNCR
| IUCLC
| IXOFF
);
828 mode
.c_iflag
|= (BRKINT
| ISTRIP
| ICRNL
| IXON
);
829 mode
.c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|
830 NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
);
831 mode
.c_oflag
|= (OPOST
| ONLCR
);
832 mode
.c_cflag
&= ~(CSIZE
| PARODD
| CLOCAL
);
834 mode
.c_cflag
|= (CS8
| CREAD
);
835 #else /*hp9000s800 */
836 mode
.c_cflag
|= (CS8
| CSTOPB
| CREAD
);
837 #endif /* hp9000s800 */
838 mode
.c_lflag
&= ~(XCASE
| ECHONL
| NOFLSH
);
839 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOK
);
840 ioctl (FILEDES
, TCSETAW
, &mode
);
This page took 0.062163 seconds and 4 git commands to generate.