3 ** General functions for the WDB TUI
21 #include "tuiLayout.h"
26 /* The Solaris header files seem to provide no declaration for this at
27 all when __STDC__ is defined. This shouldn't conflict with
29 extern char *tgoto ();
31 /***********************
33 ************************/
35 /* Solaris <sys/termios.h> defines CTRL. */
37 #define CTRL(x) (x & ~0140)
39 #define CHK(val, dft) (val<=0 ? dft : val)
41 #define TOGGLE_USAGE "Usage:toggle breakpoints"
42 #define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints"
44 /*****************************
45 ** Local static forward decls
46 ******************************/
47 static void _tuiReset (void);
48 static void _toggle_command (char *, int);
49 static void _tui_vToggle_command (va_list);
50 static Opaque _tui_vDo (TuiOpaqueFuncPtr, va_list);
54 /***********************
56 ************************/
69 extern void init_page_info ();
70 extern void initialize_tui_files (void);
72 initialize_tui_files ();
73 initializeStaticData ();
76 setTermHeightTo (LINES);
77 setTermWidthTo (COLS);
79 wrefresh (cmdWin->generic.handle);
81 /* Don't hook debugger output if doing command-window
82 * the XDB way. However, one thing we do want to do in
83 * XDB style is set up the scrolling region to be
84 * the bottom of the screen (tuiTermUnsetup()).
86 fputs_unfiltered_hook = NULL;
87 rl_initialize (); /* need readline initialization to
88 * create termcap sequences
90 tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
101 tuiInitWindows (void)
108 tuiSetLocatorContent (0);
109 showLayout (SRC_COMMAND);
110 keypad (cmdWin->generic.handle, TRUE);
114 tuiSetWinFocusTo (srcWin);
117 } /* tuiInitWindows */
122 ** Kill signal handler and cleanup termination method
126 tuiResetScreen (void)
131 TuiWinType type = SRC_WIN;
133 keypad (cmdWin->generic.handle, FALSE);
134 for (; type < MAX_MAJOR_WINDOWS; type++)
136 if (m_winPtrNotNull (winList[type]) &&
137 winList[type]->generic.type != UNDEFINED_WIN &&
138 !winList[type]->generic.isVisible)
139 tuiDelWindow (winList[type]);
149 } /* tuiResetScreen */
154 ** Kill signal handler and cleanup termination method
164 extern char *term_cursor_move;
166 signal (SIGINT, SIG_IGN);
167 tuiTermSetup (0); /* Restore scrolling region to whole screen */
168 keypad (cmdWin->generic.handle, FALSE);
171 buffer = tgoto (term_cursor_move, 0, termHeight ());
172 tputs (buffer, 1, putchar);
188 tuiError (string, exitGdb)
193 puts_unfiltered (string);
206 ** tuiError with args in a va_list.
220 string = va_arg (args, char *);
221 exitGdb = va_arg (args, int);
223 tuiError (string, exitGdb);
231 ** Wrapper on top of free() to ensure that input address is greater than 0x0
242 if (ptr != (char *) NULL)
251 /* tuiGetLowDisassemblyAddress().
252 ** Determine what the low address will be to display in the TUI's
253 ** disassembly window. This may or may not be the same as the
254 ** low address input.
258 tuiGetLowDisassemblyAddress (
262 tuiGetLowDisassemblyAddress (low, pc)
271 ** Determine where to start the disassembly so that the pc is about in the
272 ** middle of the viewport.
274 for (line = 0, newLow = pc;
276 line < (tuiDefaultWinViewportHeight (DISASSEM_WIN,
277 DISASSEM_COMMAND) / 2));)
281 newLow -= sizeof (bfd_getb32 (buffer));
286 } /* tuiGetLowDisassemblyAddress */
289 /* tui_vGetLowDisassemblyAddress().
290 ** Determine what the low address will be to display in the TUI's
291 ** disassembly window with args in a va_list.
295 tui_vGetLowDisassemblyAddress (
298 tui_vGetLowDisassemblyAddress (args)
307 low = va_arg (args, Opaque);
308 pc = va_arg (args, Opaque);
310 return (tuiGetLowDisassemblyAddress (low, pc));
312 } /* tui_vGetLowDisassemblyAddress */
317 ** General purpose function to execute a tui function. Transitions
318 ** between curses and the are handled here. This function is called
319 ** by non-tui gdb functions.
321 ** Errors are caught here.
322 ** If there is no error, the value returned by 'func' is returned.
323 ** If there is an error, then zero is returned.
325 ** Must not be called with immediate_quit in effect (bad things might
326 ** happen, say we got a signal in the middle of a memcpy to quit_return).
327 ** This is an OK restriction; with very few exceptions immediate_quit can
328 ** be replaced by judicious use of QUIT.
333 TuiOpaqueFuncPtr func,...)
335 tuiDo (func, va_alist)
336 TuiOpaqueFuncPtr func;
340 extern int terminal_is_ours;
342 Opaque ret = (Opaque) NULL;
344 /* It is an error to be tuiDo'ing if we
345 * don't own the terminal.
347 if (!terminal_is_ours)
355 va_start (args, func);
359 ret = _tui_vDo (func, args);
368 ** tuiDoAndReturnToTop().
369 ** General purpose function to execute a tui function. Transitions
370 ** between curses and the are handled here. This function is called
371 ** by non-tui gdb functions who wish to reset gdb to the top level.
372 ** After the tuiDo is performed, a return to the top level occurs.
374 ** Errors are caught here.
375 ** If there is no error, the value returned by 'func' is returned.
376 ** If there is an error, then zero is returned.
378 ** Must not be called with immediate_quit in effect (bad things might
379 ** happen, say we got a signal in the middle of a memcpy to quit_return).
380 ** This is an OK restriction; with very few exceptions immediate_quit can
381 ** be replaced by judicious use of QUIT.
386 tuiDoAndReturnToTop (
387 TuiOpaqueFuncPtr func,...)
389 tuiDoAndReturnToTop (func, va_alist)
390 TuiOpaqueFuncPtr func;
394 extern int terminal_is_ours;
396 Opaque ret = (Opaque) NULL;
398 /* It is an error to be tuiDo'ing if we
399 * don't own the terminal.
401 if (!terminal_is_ours)
409 va_start (args, func);
413 ret = _tui_vDo (func, args);
415 /* force a return to the top level */
416 return_to_top_level (RETURN_ERROR);
420 } /* tuiDoAndReturnToTop */
425 tui_vSelectSourceSymtab (
428 tui_vSelectSourceSymtab (args)
432 struct symtab *s = va_arg (args, struct symtab *);
434 select_source_symtab (s);
436 } /* tui_vSelectSourceSymtab */
440 ** _initialize_tui().
441 ** Function to initialize gdb commands, for tui window manipulation.
449 add_com ("toggle", class_tui, _toggle_command,
450 "Toggle Terminal UI Features\n\
451 Usage: Toggle $fregs\n\
452 \tToggles between single and double precision floating point registers.\n");
458 helpStr = "Toggle Specified Features\n\
459 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
461 helpStr = "Toggle Specified Features\nUsage:toggle breakpoints";
462 add_abbrev_prefix_cmd ("toggle",
470 } /* _initialize_tui */
474 ** va_catch_errors().
475 ** General purpose function to execute a function, catching errors.
476 ** If there is no error, the value returned by 'func' is returned.
477 ** If there is error, then zero is returned.
478 ** Note that 'func' must take a variable argument list as well.
480 ** Must not be called with immediate_quit in effect (bad things might
481 ** happen, say we got a signal in the middle of a memcpy to quit_return).
482 ** This is an OK restriction; with very few exceptions immediate_quit can
483 ** be replaced by judicious use of QUIT.
488 TuiOpaqueFuncPtr func,
491 va_catch_errors (func, args)
492 TuiOpaqueFuncPtr func;
496 Opaque ret = (Opaque) NULL;
499 ** We could have used catch_errors(), but it doesn't handle variable args.
500 ** Also, for the tui, we always want to catch all errors, so we don't
501 ** need to pass a mask, or an error string.
506 struct cleanup *saved_cleanup_chain;
507 char *saved_error_pre_print;
508 char *saved_quit_pre_print;
509 extern jmp_buf error_return;
510 extern jmp_buf quit_return;
512 saved_cleanup_chain = save_cleanups ();
513 saved_error_pre_print = error_pre_print;
514 saved_quit_pre_print = quit_pre_print;
516 memcpy ((char *) saved_error, (char *) error_return, sizeof (jmp_buf));
517 error_pre_print = "";
518 memcpy (saved_quit, quit_return, sizeof (jmp_buf));
521 if (setjmp (tmp_jmp) == 0)
523 va_list argList = args;
524 memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
525 memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
526 ret = func (argList);
528 restore_cleanups (saved_cleanup_chain);
529 memcpy (error_return, saved_error, sizeof (jmp_buf));
530 error_pre_print = saved_error_pre_print;
531 memcpy (quit_return, saved_quit, sizeof (jmp_buf));
532 quit_pre_print = saved_quit_pre_print;
539 ** Catch errors occurring in tui or non tui function, handling
540 ** variable param lists. Note that 'func' must take a variable
541 ** argument list as well.
546 OpaqueFuncPtr func,...)
548 vcatch_errors (va_alist)
551 vcatch_errors(func, va_alist)
557 Opaque ret = (Opaque) NULL;
560 va_start (args, func);
562 va_arg(args, OpaqueFuncPtr);
568 func = va_arg (args, OpaqueFuncPtr);
570 ret = va_catch_errors (func, args);
584 strcat_to_buf (buf, buflen, itemToAdd)
590 if (itemToAdd != (char *) NULL && buf != (char *) NULL)
592 if ((strlen (buf) + strlen (itemToAdd)) <= buflen)
593 strcat (buf, itemToAdd);
595 strncat (buf, itemToAdd, (buflen - strlen (buf)));
599 } /* strcat_to_buf */
603 #ifdef ANSI_PROTOTYPES
604 strcat_to_buf_with_fmt (
609 strcat_to_buf_with_fmt (va_alist)
614 struct cleanup *old_cleanups;
616 #ifdef ANSI_PROTOTYPES
617 va_start (args, format);
624 buf = va_arg (args, char *);
625 bufLen = va_arg (args, int);
626 format = va_arg (args, char *);
628 vasprintf (&linebuffer, format, args);
629 old_cleanups = make_cleanup (free, linebuffer);
630 strcat_to_buf (buf, bufLen, linebuffer);
631 do_cleanups (old_cleanups);
639 /***********************
641 ************************/
646 ** General purpose function to execute a tui function. Transitions
647 ** between curses and the are handled here. This function is called
648 ** by non-tui gdb functions.
650 ** Errors are caught here.
651 ** If there is no error, the value returned by 'func' is returned.
652 ** If there is an error, then zero is returned.
654 ** Must not be called with immediate_quit in effect (bad things might
655 ** happen, say we got a signal in the middle of a memcpy to quit_return).
656 ** This is an OK restriction; with very few exceptions immediate_quit can
657 ** be replaced by judicious use of QUIT.
662 TuiOpaqueFuncPtr func,
665 _tui_vDo (func, args)
666 TuiOpaqueFuncPtr func;
670 extern int terminal_is_ours;
672 Opaque ret = (Opaque) NULL;
674 /* It is an error to be tuiDo'ing if we
675 * don't own the terminal.
677 if (!terminal_is_ours)
682 /* If doing command window the "XDB way" (command window
683 * is unmanaged by curses...
685 /* Set up terminal for TUI */
688 ret = va_catch_errors (func, args);
690 /* Set up terminal for command window */
691 tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch);
704 _toggle_command (arg, fromTTY)
709 printf_filtered ("Specify feature to toggle.\n%s\n",
710 (tui_version) ? TUI_TOGGLE_USAGE : TOGGLE_USAGE);
712 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
717 ** _tui_vToggle_command().
721 _tui_vToggle_command (
724 _tui_vToggle_command (args)
731 arg = va_arg (args, char *);
733 if (arg == (char *) NULL)
734 printf_filtered (TOGGLE_USAGE);
737 char *ptr = (char *) tuiStrDup (arg);
740 for (i = 0; (ptr[i]); i++)
741 ptr[i] = toupper (arg[i]);
743 if (subsetCompare (ptr, TUI_FLOAT_REGS_NAME))
744 tuiToggleFloatRegs ();
745 /* else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
749 printf_filtered (TOGGLE_USAGE);
754 } /* _tuiToggle_command */
767 ** reset the teletype mode bits to a sensible state.
770 #if ! defined (USG) && defined (TIOCGETC)
772 #endif /* !USG && TIOCGETC */
776 if (ldisc == NTTYDISC)
778 ioctl (FILEDES, TIOCGLTC, <c);
779 ltc.t_suspc = CHK (ltc.t_suspc, CTRL ('Z'));
780 ltc.t_dsuspc = CHK (ltc.t_dsuspc, CTRL ('Y'));
781 ltc.t_rprntc = CHK (ltc.t_rprntc, CTRL ('R'));
782 ltc.t_flushc = CHK (ltc.t_flushc, CTRL ('O'));
783 ltc.t_werasc = CHK (ltc.t_werasc, CTRL ('W'));
784 ltc.t_lnextc = CHK (ltc.t_lnextc, CTRL ('V'));
785 ioctl (FILEDES, TIOCSLTC, <c);
787 #endif /* UCB_NTTY */
790 ioctl (FILEDES, TIOCGETC, &tbuf);
791 tbuf.t_intrc = CHK (tbuf.t_intrc, CTRL ('?'));
792 tbuf.t_quitc = CHK (tbuf.t_quitc, CTRL ('\\'));
793 tbuf.t_startc = CHK (tbuf.t_startc, CTRL ('Q'));
794 tbuf.t_stopc = CHK (tbuf.t_stopc, CTRL ('S'));
795 tbuf.t_eofc = CHK (tbuf.t_eofc, CTRL ('D'));
796 /* brkc is left alone */
797 ioctl (FILEDES, TIOCSETC, &tbuf);
798 #endif /* TIOCGETC */
799 mode.sg_flags &= ~(RAW
803 | VTDELAY | ALLDELAY);
804 mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP;
806 ioctl (FILEDES, TCGETA, &mode);
807 mode.c_cc[VINTR] = CHK (mode.c_cc[VINTR], CTRL ('?'));
808 mode.c_cc[VQUIT] = CHK (mode.c_cc[VQUIT], CTRL ('\\'));
809 mode.c_cc[VEOF] = CHK (mode.c_cc[VEOF], CTRL ('D'));
811 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | INLCR | IGNCR | IUCLC | IXOFF);
812 mode.c_iflag |= (BRKINT | ISTRIP | ICRNL | IXON);
813 mode.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |
814 NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY);
815 mode.c_oflag |= (OPOST | ONLCR);
816 mode.c_cflag &= ~(CSIZE | PARODD | CLOCAL);
818 mode.c_cflag |= (CS8 | CREAD);
819 #else /*hp9000s800 */
820 mode.c_cflag |= (CS8 | CSTOPB | CREAD);
821 #endif /* hp9000s800 */
822 mode.c_lflag &= ~(XCASE | ECHONL | NOFLSH);
823 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOK);
824 ioctl (FILEDES, TCSETAW, &mode);