53b8452df6903a4b8e4b5825de3647222cffc919
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
;
89 rl_initialize (); /* need readline initialization to
90 * create termcap sequences
92 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
103 tuiInitWindows (void)
110 tuiSetLocatorContent (0);
111 showLayout (SRC_COMMAND
);
112 keypad (cmdWin
->generic
.handle
, TRUE
);
116 tuiSetWinFocusTo (srcWin
);
119 } /* tuiInitWindows */
124 ** Kill signal handler and cleanup termination method
128 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
166 extern char *term_cursor_move
;
168 signal (SIGINT
, SIG_IGN
);
169 tuiTermSetup (0); /* Restore scrolling region to whole screen */
170 keypad (cmdWin
->generic
.handle
, FALSE
);
173 buffer
= tgoto (term_cursor_move
, 0, termHeight ());
174 tputs (buffer
, 1, putchar
);
190 tuiError (string
, exitGdb
)
195 puts_unfiltered (string
);
208 ** tuiError with args in a va_list.
222 string
= va_arg (args
, char *);
223 exitGdb
= va_arg (args
, int);
225 tuiError (string
, exitGdb
);
233 ** Wrapper on top of free() to ensure that input address is greater than 0x0
244 if (ptr
!= (char *) NULL
)
253 /* tuiGetLowDisassemblyAddress().
254 ** Determine what the low address will be to display in the TUI's
255 ** disassembly window. This may or may not be the same as the
256 ** low address input.
260 tuiGetLowDisassemblyAddress (
264 tuiGetLowDisassemblyAddress (low
, pc
)
273 ** Determine where to start the disassembly so that the pc is about in the
274 ** middle of the viewport.
276 for (line
= 0, newLow
= pc
;
278 line
< (tuiDefaultWinViewportHeight (DISASSEM_WIN
,
279 DISASSEM_COMMAND
) / 2));)
283 newLow
-= sizeof (bfd_getb32 (buffer
));
288 } /* tuiGetLowDisassemblyAddress */
291 /* tui_vGetLowDisassemblyAddress().
292 ** Determine what the low address will be to display in the TUI's
293 ** disassembly window with args in a va_list.
297 tui_vGetLowDisassemblyAddress (
300 tui_vGetLowDisassemblyAddress (args
)
309 low
= va_arg (args
, Opaque
);
310 pc
= va_arg (args
, Opaque
);
312 return (tuiGetLowDisassemblyAddress (low
, pc
));
314 } /* tui_vGetLowDisassemblyAddress */
319 ** General purpose function to execute a tui function. Transitions
320 ** between curses and the are handled here. This function is called
321 ** by non-tui gdb functions.
323 ** Errors are caught here.
324 ** If there is no error, the value returned by 'func' is returned.
325 ** If there is an error, then zero is returned.
327 ** Must not be called with immediate_quit in effect (bad things might
328 ** happen, say we got a signal in the middle of a memcpy to quit_return).
329 ** This is an OK restriction; with very few exceptions immediate_quit can
330 ** be replaced by judicious use of QUIT.
335 TuiOpaqueFuncPtr func
,...)
337 tuiDo (func
, va_alist
)
338 TuiOpaqueFuncPtr func
;
342 extern int terminal_is_ours
;
344 Opaque ret
= (Opaque
) NULL
;
346 /* It is an error to be tuiDo'ing if we
347 * don't own the terminal.
349 if (!terminal_is_ours
)
357 va_start (args
, func
);
361 ret
= _tui_vDo (func
, args
);
370 ** tuiDoAndReturnToTop().
371 ** General purpose function to execute a tui function. Transitions
372 ** between curses and the are handled here. This function is called
373 ** by non-tui gdb functions who wish to reset gdb to the top level.
374 ** After the tuiDo is performed, a return to the top level occurs.
376 ** Errors are caught here.
377 ** If there is no error, the value returned by 'func' is returned.
378 ** If there is an error, then zero is returned.
380 ** Must not be called with immediate_quit in effect (bad things might
381 ** happen, say we got a signal in the middle of a memcpy to quit_return).
382 ** This is an OK restriction; with very few exceptions immediate_quit can
383 ** be replaced by judicious use of QUIT.
388 tuiDoAndReturnToTop (
389 TuiOpaqueFuncPtr func
,...)
391 tuiDoAndReturnToTop (func
, va_alist
)
392 TuiOpaqueFuncPtr func
;
396 extern int terminal_is_ours
;
398 Opaque ret
= (Opaque
) NULL
;
400 /* It is an error to be tuiDo'ing if we
401 * don't own the terminal.
403 if (!terminal_is_ours
)
411 va_start (args
, func
);
415 ret
= _tui_vDo (func
, args
);
417 /* force a return to the top level */
418 return_to_top_level (RETURN_ERROR
);
422 } /* tuiDoAndReturnToTop */
427 tui_vSelectSourceSymtab (
430 tui_vSelectSourceSymtab (args
)
434 struct symtab
*s
= va_arg (args
, struct symtab
*);
436 select_source_symtab (s
);
438 } /* tui_vSelectSourceSymtab */
442 ** _initialize_tui().
443 ** Function to initialize gdb commands, for tui window manipulation.
451 add_com ("toggle", class_tui
, _toggle_command
,
452 "Toggle Terminal UI Features\n\
453 Usage: Toggle $fregs\n\
454 \tToggles between single and double precision floating point registers.\n");
460 helpStr
= "Toggle Specified Features\n\
461 Usage:\ttoggle $fregs\n\ttoggle breakpoints";
463 helpStr
= "Toggle Specified Features\nUsage:toggle breakpoints";
464 add_abbrev_prefix_cmd ("toggle",
472 } /* _initialize_tui */
476 ** va_catch_errors().
477 ** General purpose function to execute a function, catching errors.
478 ** If there is no error, the value returned by 'func' is returned.
479 ** If there is error, then zero is returned.
480 ** Note that 'func' must take a variable argument list as well.
482 ** Must not be called with immediate_quit in effect (bad things might
483 ** happen, say we got a signal in the middle of a memcpy to quit_return).
484 ** This is an OK restriction; with very few exceptions immediate_quit can
485 ** be replaced by judicious use of QUIT.
490 TuiOpaqueFuncPtr func
,
493 va_catch_errors (func
, args
)
494 TuiOpaqueFuncPtr func
;
498 Opaque ret
= (Opaque
) NULL
;
501 ** We could have used catch_errors(), but it doesn't handle variable args.
502 ** Also, for the tui, we always want to catch all errors, so we don't
503 ** need to pass a mask, or an error string.
508 struct cleanup
*saved_cleanup_chain
;
509 char *saved_error_pre_print
;
510 char *saved_quit_pre_print
;
511 extern jmp_buf error_return
;
512 extern jmp_buf quit_return
;
514 saved_cleanup_chain
= save_cleanups ();
515 saved_error_pre_print
= error_pre_print
;
516 saved_quit_pre_print
= quit_pre_print
;
518 memcpy ((char *) saved_error
, (char *) error_return
, sizeof (jmp_buf));
519 error_pre_print
= "";
520 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
523 if (setjmp (tmp_jmp
) == 0)
525 va_list argList
= args
;
526 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
527 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
528 ret
= func (argList
);
530 restore_cleanups (saved_cleanup_chain
);
531 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
532 error_pre_print
= saved_error_pre_print
;
533 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
534 quit_pre_print
= saved_quit_pre_print
;
541 ** Catch errors occurring in tui or non tui function, handling
542 ** variable param lists. Note that 'func' must take a variable
543 ** argument list as well.
548 OpaqueFuncPtr func
,...)
550 vcatch_errors (va_alist
)
553 vcatch_errors(func, va_alist)
559 Opaque ret
= (Opaque
) NULL
;
562 va_start (args
, func
);
564 va_arg(args, OpaqueFuncPtr);
570 func
= va_arg (args
, OpaqueFuncPtr
);
572 ret
= va_catch_errors (func
, args
);
586 strcat_to_buf (buf
, buflen
, itemToAdd
)
592 if (itemToAdd
!= (char *) NULL
&& buf
!= (char *) NULL
)
594 if ((strlen (buf
) + strlen (itemToAdd
)) <= buflen
)
595 strcat (buf
, itemToAdd
);
597 strncat (buf
, itemToAdd
, (buflen
- strlen (buf
)));
601 } /* strcat_to_buf */
605 #ifdef ANSI_PROTOTYPES
606 strcat_to_buf_with_fmt (
611 strcat_to_buf_with_fmt (va_alist
)
616 struct cleanup
*old_cleanups
;
618 #ifdef ANSI_PROTOTYPES
619 va_start (args
, format
);
626 buf
= va_arg (args
, char *);
627 bufLen
= va_arg (args
, int);
628 format
= va_arg (args
, char *);
630 vasprintf (&linebuffer
, format
, args
);
631 old_cleanups
= make_cleanup (free
, linebuffer
);
632 strcat_to_buf (buf
, bufLen
, linebuffer
);
633 do_cleanups (old_cleanups
);
641 /***********************
643 ************************/
648 ** General purpose function to execute a tui function. Transitions
649 ** between curses and the are handled here. This function is called
650 ** by non-tui gdb functions.
652 ** Errors are caught here.
653 ** If there is no error, the value returned by 'func' is returned.
654 ** If there is an error, then zero is returned.
656 ** Must not be called with immediate_quit in effect (bad things might
657 ** happen, say we got a signal in the middle of a memcpy to quit_return).
658 ** This is an OK restriction; with very few exceptions immediate_quit can
659 ** be replaced by judicious use of QUIT.
664 TuiOpaqueFuncPtr func
,
667 _tui_vDo (func
, args
)
668 TuiOpaqueFuncPtr func
;
672 extern int terminal_is_ours
;
674 Opaque ret
= (Opaque
) NULL
;
676 /* It is an error to be tuiDo'ing if we
677 * don't own the terminal.
679 if (!terminal_is_ours
)
684 /* If doing command window the "XDB way" (command window
685 * is unmanaged by curses...
687 /* Set up terminal for TUI */
690 ret
= va_catch_errors (func
, args
);
692 /* Set up terminal for command window */
693 tuiTermUnsetup (1, cmdWin
->detail
.commandInfo
.curch
);
706 _toggle_command (arg
, fromTTY
)
711 printf_filtered ("Specify feature to toggle.\n%s\n",
712 (tui_version
) ? TUI_TOGGLE_USAGE
: TOGGLE_USAGE
);
714 tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY);
719 ** _tui_vToggle_command().
723 _tui_vToggle_command (
726 _tui_vToggle_command (args
)
733 arg
= va_arg (args
, char *);
735 if (arg
== (char *) NULL
)
736 printf_filtered (TOGGLE_USAGE
);
739 char *ptr
= (char *) tuiStrDup (arg
);
742 for (i
= 0; (ptr
[i
]); i
++)
743 ptr
[i
] = toupper (arg
[i
]);
745 if (subsetCompare (ptr
, TUI_FLOAT_REGS_NAME
))
746 tuiToggleFloatRegs ();
747 /* else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION"))
751 printf_filtered (TOGGLE_USAGE
);
756 } /* _tuiToggle_command */
769 ** reset the teletype mode bits to a sensible state.
772 #if ! defined (USG) && defined (TIOCGETC)
774 #endif /* !USG && TIOCGETC */
778 if (ldisc
== NTTYDISC
)
780 ioctl (FILEDES
, TIOCGLTC
, <c
);
781 ltc
.t_suspc
= CHK (ltc
.t_suspc
, CTRL ('Z'));
782 ltc
.t_dsuspc
= CHK (ltc
.t_dsuspc
, CTRL ('Y'));
783 ltc
.t_rprntc
= CHK (ltc
.t_rprntc
, CTRL ('R'));
784 ltc
.t_flushc
= CHK (ltc
.t_flushc
, CTRL ('O'));
785 ltc
.t_werasc
= CHK (ltc
.t_werasc
, CTRL ('W'));
786 ltc
.t_lnextc
= CHK (ltc
.t_lnextc
, CTRL ('V'));
787 ioctl (FILEDES
, TIOCSLTC
, <c
);
789 #endif /* UCB_NTTY */
792 ioctl (FILEDES
, TIOCGETC
, &tbuf
);
793 tbuf
.t_intrc
= CHK (tbuf
.t_intrc
, CTRL ('?'));
794 tbuf
.t_quitc
= CHK (tbuf
.t_quitc
, CTRL ('\\'));
795 tbuf
.t_startc
= CHK (tbuf
.t_startc
, CTRL ('Q'));
796 tbuf
.t_stopc
= CHK (tbuf
.t_stopc
, CTRL ('S'));
797 tbuf
.t_eofc
= CHK (tbuf
.t_eofc
, CTRL ('D'));
798 /* brkc is left alone */
799 ioctl (FILEDES
, TIOCSETC
, &tbuf
);
800 #endif /* TIOCGETC */
801 mode
.sg_flags
&= ~(RAW
805 | VTDELAY
| ALLDELAY
);
806 mode
.sg_flags
|= XTABS
| ECHO
| CRMOD
| ANYP
;
808 ioctl (FILEDES
, TCGETA
, &mode
);
809 mode
.c_cc
[VINTR
] = CHK (mode
.c_cc
[VINTR
], CTRL ('?'));
810 mode
.c_cc
[VQUIT
] = CHK (mode
.c_cc
[VQUIT
], CTRL ('\\'));
811 mode
.c_cc
[VEOF
] = CHK (mode
.c_cc
[VEOF
], CTRL ('D'));
813 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| INLCR
| IGNCR
| IUCLC
| IXOFF
);
814 mode
.c_iflag
|= (BRKINT
| ISTRIP
| ICRNL
| IXON
);
815 mode
.c_oflag
&= ~(OLCUC
| OCRNL
| ONOCR
| ONLRET
| OFILL
| OFDEL
|
816 NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
);
817 mode
.c_oflag
|= (OPOST
| ONLCR
);
818 mode
.c_cflag
&= ~(CSIZE
| PARODD
| CLOCAL
);
820 mode
.c_cflag
|= (CS8
| CREAD
);
821 #else /*hp9000s800 */
822 mode
.c_cflag
|= (CS8
| CSTOPB
| CREAD
);
823 #endif /* hp9000s800 */
824 mode
.c_lflag
&= ~(XCASE
| ECHONL
| NOFLSH
);
825 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOK
);
826 ioctl (FILEDES
, TCSETAW
, &mode
);
This page took 0.083206 seconds and 4 git commands to generate.