3 ** General functions for the WDB TUI
22 #include "tuiLayout.h"
27 /* The Solaris header files seem to provide no declaration for this at
28 all when __STDC__ is defined. This shouldn't conflict with
30 extern char *tgoto ();
32 /***********************
34 ************************/
36 /* Solaris <sys/termios.h> defines CTRL. */
38 #define CTRL(x) (x & ~0140)
40 #define CHK(val, dft) (val<=0 ? dft : val)
42 #define TOGGLE_USAGE "Usage:toggle breakpoints"
43 #define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints"
45 /*****************************
46 ** Local static forward decls
47 ******************************/
48 static void _tuiReset
PARAMS ((void));
49 static void _toggle_command
PARAMS ((char *, int));
50 static void _tui_vToggle_command
PARAMS ((va_list));
51 static Opaque _tui_vDo
PARAMS ((TuiOpaqueFuncPtr
, va_list));
55 /***********************
57 ************************/
70 extern void init_page_info ();
71 extern void initialize_tui_files
PARAMS ((void));
73 initialize_tui_files ();
74 initializeStaticData ();
77 setTermHeightTo (LINES
);
78 setTermWidthTo (COLS
);
80 wrefresh (cmdWin
->generic
.handle
);
82 /* Don't hook debugger output if doing command-window
83 * the XDB way. However, one thing we do want to do in
84 * XDB style is set up the scrolling region to be
85 * the bottom of the screen (tuiTermUnsetup()).
87 fputs_unfiltered_hook
= NULL
;
88 rl_initialize (); /* need readline initialization to
89 * create termcap sequences
91 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
102 tuiInitWindows (void)
109 tuiSetLocatorContent (0);
110 showLayout (SRC_COMMAND
);
111 keypad (cmdWin
->generic
.handle
, TRUE
);
115 tuiSetWinFocusTo (srcWin
);
118 } /* tuiInitWindows */
123 ** Kill signal handler and cleanup termination method
127 tuiResetScreen (void)
132 TuiWinType type
= SRC_WIN
;
134 keypad (cmdWin
->generic
.handle
, FALSE
);
135 for (; type
< MAX_MAJOR_WINDOWS
; type
++)
137 if (m_winPtrNotNull (winList
[type
]) &&
138 winList
[type
]->generic
.type
!= UNDEFINED_WIN
&&
139 !winList
[type
]->generic
.isVisible
)
140 tuiDelWindow (winList
[type
]);
150 } /* tuiResetScreen */
155 ** Kill signal handler and cleanup termination method
165 extern char *term_cursor_move
;
167 signal (SIGINT
, SIG_IGN
);
168 tuiTermSetup (0); /* Restore scrolling region to whole screen */
169 keypad (cmdWin
->generic
.handle
, FALSE
);
172 buffer
= tgoto (term_cursor_move
, 0, termHeight ());
173 tputs (buffer
, 1, putchar
);
189 tuiError (string
, exitGdb
)
194 puts_unfiltered (string
);
207 ** tuiError with args in a va_list.
221 string
= va_arg (args
, char *);
222 exitGdb
= va_arg (args
, int);
224 tuiError (string
, exitGdb
);
232 ** Wrapper on top of free() to ensure that input address is greater than 0x0
243 if (ptr
!= (char *) NULL
)
252 /* tuiGetLowDisassemblyAddress().
253 ** Determine what the low address will be to display in the TUI's
254 ** disassembly window. This may or may not be the same as the
255 ** low address input.
259 tuiGetLowDisassemblyAddress (
263 tuiGetLowDisassemblyAddress (low
, pc
)
272 ** Determine where to start the disassembly so that the pc is about in the
273 ** middle of the viewport.
275 for (line
= 0, newLow
= pc
;
277 line
< (tuiDefaultWinViewportHeight (DISASSEM_WIN
,
278 DISASSEM_COMMAND
) / 2));)
282 newLow
-= sizeof (bfd_getb32 (buffer
));
287 } /* tuiGetLowDisassemblyAddress */
290 /* tui_vGetLowDisassemblyAddress().
291 ** Determine what the low address will be to display in the TUI's
292 ** disassembly window with args in a va_list.
296 tui_vGetLowDisassemblyAddress (
299 tui_vGetLowDisassemblyAddress (args
)
308 low
= va_arg (args
, Opaque
);
309 pc
= va_arg (args
, Opaque
);
311 return (tuiGetLowDisassemblyAddress (low
, pc
));
313 } /* tui_vGetLowDisassemblyAddress */
318 ** General purpose function to execute a tui function. Transitions
319 ** between curses and the are handled here. This function is called
320 ** by non-tui gdb functions.
322 ** Errors are caught here.
323 ** If there is no error, the value returned by 'func' is returned.
324 ** If there is an error, then zero is returned.
326 ** Must not be called with immediate_quit in effect (bad things might
327 ** happen, say we got a signal in the middle of a memcpy to quit_return).
328 ** This is an OK restriction; with very few exceptions immediate_quit can
329 ** be replaced by judicious use of QUIT.
334 TuiOpaqueFuncPtr func
,...)
336 tuiDo (func
, va_alist
)
337 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
)
356 va_start (args
, func
);
360 ret
= _tui_vDo (func
, args
);
369 ** tuiDoAndReturnToTop().
370 ** General purpose function to execute a tui function. Transitions
371 ** between curses and the are handled here. This function is called
372 ** by non-tui gdb functions who wish to reset gdb to the top level.
373 ** After the tuiDo is performed, a return to the top level occurs.
375 ** Errors are caught here.
376 ** If there is no error, the value returned by 'func' is returned.
377 ** If there is an error, then zero is returned.
379 ** Must not be called with immediate_quit in effect (bad things might
380 ** happen, say we got a signal in the middle of a memcpy to quit_return).
381 ** This is an OK restriction; with very few exceptions immediate_quit can
382 ** be replaced by judicious use of QUIT.
387 tuiDoAndReturnToTop (
388 TuiOpaqueFuncPtr func
,...)
390 tuiDoAndReturnToTop (func
, va_alist
)
391 TuiOpaqueFuncPtr func
;
395 extern int terminal_is_ours
;
397 Opaque ret
= (Opaque
) NULL
;
399 /* It is an error to be tuiDo'ing if we
400 * don't own the terminal.
402 if (!terminal_is_ours
)
410 va_start (args
, func
);
414 ret
= _tui_vDo (func
, args
);
416 /* force a return to the top level */
417 return_to_top_level (RETURN_ERROR
);
421 } /* tuiDoAndReturnToTop */
426 tui_vSelectSourceSymtab (
429 tui_vSelectSourceSymtab (args
)
433 struct symtab
*s
= va_arg (args
, struct symtab
*);
435 select_source_symtab (s
);
437 } /* tui_vSelectSourceSymtab */
441 ** _initialize_tui().
442 ** Function to initialize gdb commands, for tui window manipulation.
450 add_com ("toggle", class_tui
, _toggle_command
,
451 "Toggle Terminal UI Features\n\
452 Usage: Toggle $fregs\n\
453 \tToggles between single and double precision floating point registers.\n");
459 helpStr
= "Toggle Specified Features\n\
460 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
462 helpStr
= "Toggle Specified Features\nUsage:toggle breakpoints";
463 add_abbrev_prefix_cmd ("toggle",
471 } /* _initialize_tui */
475 ** va_catch_errors().
476 ** General purpose function to execute a function, catching errors.
477 ** If there is no error, the value returned by 'func' is returned.
478 ** If there is error, then zero is returned.
479 ** Note that 'func' must take a variable argument list as well.
481 ** Must not be called with immediate_quit in effect (bad things might
482 ** happen, say we got a signal in the middle of a memcpy to quit_return).
483 ** This is an OK restriction; with very few exceptions immediate_quit can
484 ** be replaced by judicious use of QUIT.
489 TuiOpaqueFuncPtr func
,
492 va_catch_errors (func
, args
)
493 TuiOpaqueFuncPtr func
;
497 Opaque ret
= (Opaque
) NULL
;
500 ** We could have used catch_errors(), but it doesn't handle variable args.
501 ** Also, for the tui, we always want to catch all errors, so we don't
502 ** need to pass a mask, or an error string.
507 struct cleanup
*saved_cleanup_chain
;
508 char *saved_error_pre_print
;
509 char *saved_quit_pre_print
;
510 extern jmp_buf error_return
;
511 extern jmp_buf quit_return
;
513 saved_cleanup_chain
= save_cleanups ();
514 saved_error_pre_print
= error_pre_print
;
515 saved_quit_pre_print
= quit_pre_print
;
517 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (jmp_buf));
518 error_pre_print
= "";
519 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
522 if (setjmp (tmp_jmp
) == 0)
524 va_list argList
= args
;
525 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
526 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
527 ret
= func (argList
);
529 restore_cleanups (saved_cleanup_chain
);
530 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
531 error_pre_print
= saved_error_pre_print
;
532 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
533 quit_pre_print
= saved_quit_pre_print
;
540 ** Catch errors occurring in tui or non tui function, handling
541 ** variable param lists. Note that 'func' must take a variable
542 ** argument list as well.
547 OpaqueFuncPtr func
,...)
549 vcatch_errors (va_alist
)
552 vcatch_errors(func, va_alist)
558 Opaque ret
= (Opaque
) NULL
;
561 va_start (args
, func
);
563 va_arg(args, OpaqueFuncPtr);
569 func
= va_arg (args
, OpaqueFuncPtr
);
571 ret
= va_catch_errors (func
, args
);
585 strcat_to_buf (buf
, buflen
, itemToAdd
)
591 if (itemToAdd
!= (char *) NULL
&& buf
!= (char *) NULL
)
593 if ((strlen (buf
) + strlen (itemToAdd
)) <= buflen
)
594 strcat (buf
, itemToAdd
);
596 strncat (buf
, itemToAdd
, (buflen
- strlen (buf
)));
600 } /* strcat_to_buf */
604 #ifdef ANSI_PROTOTYPES
605 strcat_to_buf_with_fmt (
610 strcat_to_buf_with_fmt (va_alist
)
615 struct cleanup
*old_cleanups
;
617 #ifdef ANSI_PROTOTYPES
618 va_start (args
, format
);
625 buf
= va_arg (args
, char *);
626 bufLen
= va_arg (args
, int);
627 format
= va_arg (args
, char *);
629 vasprintf (&linebuffer
, format
, args
);
630 old_cleanups
= make_cleanup (free
, linebuffer
);
631 strcat_to_buf (buf
, bufLen
, linebuffer
);
632 do_cleanups (old_cleanups
);
640 /***********************
642 ************************/
647 ** General purpose function to execute a tui function. Transitions
648 ** between curses and the are handled here. This function is called
649 ** by non-tui gdb functions.
651 ** Errors are caught here.
652 ** If there is no error, the value returned by 'func' is returned.
653 ** If there is an error, then zero is returned.
655 ** Must not be called with immediate_quit in effect (bad things might
656 ** happen, say we got a signal in the middle of a memcpy to quit_return).
657 ** This is an OK restriction; with very few exceptions immediate_quit can
658 ** be replaced by judicious use of QUIT.
663 TuiOpaqueFuncPtr func
,
666 _tui_vDo (func
, args
)
667 TuiOpaqueFuncPtr func
;
671 extern int terminal_is_ours
;
673 Opaque ret
= (Opaque
) NULL
;
675 /* It is an error to be tuiDo'ing if we
676 * don't own the terminal.
678 if (!terminal_is_ours
)
683 /* If doing command window the "XDB way" (command window
684 * is unmanaged by curses...
686 /* Set up terminal for TUI */
689 ret
= va_catch_errors (func
, args
);
691 /* Set up terminal for command window */
692 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
705 _toggle_command (arg
, fromTTY
)
710 printf_filtered ("Specify feature to toggle.\n%s\n",
711 (tui_version
) ? TUI_TOGGLE_USAGE
: TOGGLE_USAGE
);
713 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
718 ** _tui_vToggle_command().
722 _tui_vToggle_command (
725 _tui_vToggle_command (args
)
732 arg
= va_arg (args
, char *);
734 if (arg
== (char *) NULL
)
735 printf_filtered (TOGGLE_USAGE
);
738 char *ptr
= (char *) tuiStrDup (arg
);
741 for (i
= 0; (ptr
[i
]); i
++)
742 ptr
[i
] = toupper (arg
[i
]);
744 if (subsetCompare (ptr
, TUI_FLOAT_REGS_NAME
))
745 tuiToggleFloatRegs ();
746 /* else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
750 printf_filtered (TOGGLE_USAGE
);
755 } /* _tuiToggle_command */
768 ** reset the teletype mode bits to a sensible state.
771 #if ! defined (USG) && defined (TIOCGETC)
773 #endif /* !USG && TIOCGETC */
777 if (ldisc
== NTTYDISC
)
779 ioctl (FILEDES
, TIOCGLTC
, <c
);
780 ltc
.t_suspc
= CHK (ltc
.t_suspc
, CTRL ('Z'));
781 ltc
.t_dsuspc
= CHK (ltc
.t_dsuspc
, CTRL ('Y'));
782 ltc
.t_rprntc
= CHK (ltc
.t_rprntc
, CTRL ('R'));
783 ltc
.t_flushc
= CHK (ltc
.t_flushc
, CTRL ('O'));
784 ltc
.t_werasc
= CHK (ltc
.t_werasc
, CTRL ('W'));
785 ltc
.t_lnextc
= CHK (ltc
.t_lnextc
, CTRL ('V'));
786 ioctl (FILEDES
, TIOCSLTC
, <c
);
788 #endif /* UCB_NTTY */
791 ioctl (FILEDES
, TIOCGETC
, &tbuf
);
792 tbuf
.t_intrc
= CHK (tbuf
.t_intrc
, CTRL ('?'));
793 tbuf
.t_quitc
= CHK (tbuf
.t_quitc
, CTRL ('\\'));
794 tbuf
.t_startc
= CHK (tbuf
.t_startc
, CTRL ('Q'));
795 tbuf
.t_stopc
= CHK (tbuf
.t_stopc
, CTRL ('S'));
796 tbuf
.t_eofc
= CHK (tbuf
.t_eofc
, CTRL ('D'));
797 /* brkc is left alone */
798 ioctl (FILEDES
, TIOCSETC
, &tbuf
);
799 #endif /* TIOCGETC */
800 mode
.sg_flags
&= ~(RAW
804 | VTDELAY
| ALLDELAY
);
805 mode
.sg_flags
|= XTABS
| ECHO
| CRMOD
| ANYP
;
807 ioctl (FILEDES
, TCGETA
, &mode
);
808 mode
.c_cc
[VINTR
] = CHK (mode
.c_cc
[VINTR
], CTRL ('?'));
809 mode
.c_cc
[VQUIT
] = CHK (mode
.c_cc
[VQUIT
], CTRL ('\\'));
810 mode
.c_cc
[VEOF
] = CHK (mode
.c_cc
[VEOF
], CTRL ('D'));
812 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| INLCR
| IGNCR
| IUCLC
| IXOFF
);
813 mode
.c_iflag
|= (BRKINT
| ISTRIP
| ICRNL
| IXON
);
814 mode
.c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|
815 NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
);
816 mode
.c_oflag
|= (OPOST
| ONLCR
);
817 mode
.c_cflag
&= ~(CSIZE
| PARODD
| CLOCAL
);
819 mode
.c_cflag
|= (CS8
| CREAD
);
820 #else /*hp9000s800 */
821 mode
.c_cflag
|= (CS8
| CSTOPB
| CREAD
);
822 #endif /* hp9000s800 */
823 mode
.c_lflag
&= ~(XCASE
| ECHONL
| NOFLSH
);
824 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOK
);
825 ioctl (FILEDES
, TCSETAW
, &mode
);
This page took 0.045459 seconds and 4 git commands to generate.