Commit | Line | Data |
---|---|---|
f377b406 SC |
1 | /* General functions for the WDB TUI. |
2 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc. | |
3 | Contributed by Hewlett-Packard Company. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
c906108c SS |
21 | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <ctype.h> | |
25 | #include <malloc.h> | |
c906108c SS |
26 | #ifdef HAVE_TERM_H |
27 | #include <term.h> | |
28 | #endif | |
29 | #include <signal.h> | |
30 | #include <fcntl.h> | |
31 | #include <termio.h> | |
32 | #include <setjmp.h> | |
33 | #include "defs.h" | |
34 | #include "gdbcmd.h" | |
35 | #include "tui.h" | |
36 | #include "tuiData.h" | |
37 | #include "tuiLayout.h" | |
38 | #include "tuiIO.h" | |
39 | #include "tuiRegs.h" | |
40 | #include "tuiWin.h" | |
41 | ||
42 | /* The Solaris header files seem to provide no declaration for this at | |
43 | all when __STDC__ is defined. This shouldn't conflict with | |
44 | anything. */ | |
45 | extern char *tgoto (); | |
46 | ||
47 | /*********************** | |
48 | ** Local Definitions | |
49 | ************************/ | |
50 | #define FILEDES 2 | |
51 | /* Solaris <sys/termios.h> defines CTRL. */ | |
52 | #ifndef CTRL | |
53 | #define CTRL(x) (x & ~0140) | |
54 | #endif | |
55 | #define CHK(val, dft) (val<=0 ? dft : val) | |
56 | ||
57 | #define TOGGLE_USAGE "Usage:toggle breakpoints" | |
58 | #define TUI_TOGGLE_USAGE "Usage:\ttoggle $fregs\n\ttoggle breakpoints" | |
59 | ||
60 | /***************************** | |
61 | ** Local static forward decls | |
62 | ******************************/ | |
a14ed312 KB |
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); | |
c906108c SS |
67 | |
68 | ||
69 | ||
70 | /*********************** | |
71 | ** Public Functions | |
72 | ************************/ | |
73 | ||
74 | /* | |
c5aa993b JM |
75 | ** tuiInit(). |
76 | */ | |
c906108c SS |
77 | void |
78 | #ifdef __STDC__ | |
79 | tuiInit (char *argv0) | |
80 | #else | |
81 | tuiInit (argv0) | |
82 | char *argv0; | |
83 | #endif | |
84 | { | |
85 | extern void init_page_info (); | |
a14ed312 | 86 | extern void initialize_tui_files (void); |
c906108c SS |
87 | |
88 | initialize_tui_files (); | |
89 | initializeStaticData (); | |
90 | initscr (); | |
91 | refresh (); | |
92 | setTermHeightTo (LINES); | |
93 | setTermWidthTo (COLS); | |
94 | tuiInitWindows (); | |
95 | wrefresh (cmdWin->generic.handle); | |
96 | init_page_info (); | |
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()). | |
c5aa993b | 101 | */ |
c906108c | 102 | fputs_unfiltered_hook = NULL; |
c906108c | 103 | rl_initialize (); /* need readline initialization to |
c5aa993b JM |
104 | * create termcap sequences |
105 | */ | |
c906108c SS |
106 | tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch); |
107 | ||
108 | return; | |
109 | } /* tuiInit */ | |
110 | ||
111 | ||
112 | /* | |
c5aa993b JM |
113 | ** tuiInitWindows(). |
114 | */ | |
c906108c SS |
115 | void |
116 | #ifdef __STDC__ | |
117 | tuiInitWindows (void) | |
118 | #else | |
119 | tuiInitWindows () | |
120 | #endif | |
121 | { | |
122 | TuiWinType type; | |
123 | ||
124 | tuiSetLocatorContent (0); | |
125 | showLayout (SRC_COMMAND); | |
126 | keypad (cmdWin->generic.handle, TRUE); | |
127 | echo (); | |
128 | crmode (); | |
129 | nl (); | |
130 | tuiSetWinFocusTo (srcWin); | |
131 | ||
132 | return; | |
133 | } /* tuiInitWindows */ | |
134 | ||
135 | ||
136 | /* | |
c5aa993b JM |
137 | ** tuiCleanUp(). |
138 | ** Kill signal handler and cleanup termination method | |
139 | */ | |
c906108c SS |
140 | void |
141 | #ifdef __STDC__ | |
142 | tuiResetScreen (void) | |
143 | #else | |
144 | tuiResetScreen () | |
145 | #endif | |
146 | { | |
147 | TuiWinType type = SRC_WIN; | |
148 | ||
149 | keypad (cmdWin->generic.handle, FALSE); | |
150 | for (; type < MAX_MAJOR_WINDOWS; type++) | |
151 | { | |
152 | if (m_winPtrNotNull (winList[type]) && | |
153 | winList[type]->generic.type != UNDEFINED_WIN && | |
154 | !winList[type]->generic.isVisible) | |
155 | tuiDelWindow (winList[type]); | |
156 | } | |
157 | endwin (); | |
158 | initscr (); | |
159 | refresh (); | |
160 | echo (); | |
161 | crmode (); | |
162 | nl (); | |
163 | ||
164 | return; | |
165 | } /* tuiResetScreen */ | |
166 | ||
167 | ||
168 | /* | |
c5aa993b JM |
169 | ** tuiCleanUp(). |
170 | ** Kill signal handler and cleanup termination method | |
171 | */ | |
c906108c SS |
172 | void |
173 | #ifdef __STDC__ | |
174 | tuiCleanUp (void) | |
175 | #else | |
176 | tuiCleanUp () | |
177 | #endif | |
178 | { | |
179 | char *buffer; | |
180 | extern char *term_cursor_move; | |
181 | ||
182 | signal (SIGINT, SIG_IGN); | |
183 | tuiTermSetup (0); /* Restore scrolling region to whole screen */ | |
184 | keypad (cmdWin->generic.handle, FALSE); | |
185 | freeAllWindows (); | |
186 | endwin (); | |
187 | buffer = tgoto (term_cursor_move, 0, termHeight ()); | |
188 | tputs (buffer, 1, putchar); | |
189 | _tuiReset (); | |
190 | ||
191 | return; | |
192 | } /* tuiCleanUp */ | |
193 | ||
194 | ||
195 | /* | |
c5aa993b JM |
196 | ** tuiError(). |
197 | */ | |
c906108c SS |
198 | void |
199 | #ifdef __STDC__ | |
200 | tuiError ( | |
201 | char *string, | |
202 | int exitGdb) | |
203 | #else | |
204 | tuiError (string, exitGdb) | |
205 | char *string; | |
206 | int exitGdb; | |
207 | #endif | |
208 | { | |
209 | puts_unfiltered (string); | |
210 | if (exitGdb) | |
211 | { | |
212 | tuiCleanUp (); | |
213 | exit (-1); | |
214 | } | |
215 | ||
216 | return; | |
217 | } /* tuiError */ | |
218 | ||
219 | ||
220 | /* | |
c5aa993b JM |
221 | ** tui_vError() |
222 | ** tuiError with args in a va_list. | |
223 | */ | |
c906108c SS |
224 | void |
225 | #ifdef __STDC__ | |
226 | tui_vError ( | |
227 | va_list args) | |
228 | #else | |
229 | tui_vError (args) | |
230 | va_list args; | |
231 | #endif | |
232 | { | |
233 | char *string; | |
234 | int exitGdb; | |
235 | ||
236 | string = va_arg (args, char *); | |
237 | exitGdb = va_arg (args, int); | |
238 | ||
239 | tuiError (string, exitGdb); | |
240 | ||
241 | return; | |
242 | } /* tui_vError */ | |
243 | ||
244 | ||
245 | /* | |
c5aa993b JM |
246 | ** tuiFree() |
247 | ** Wrapper on top of free() to ensure that input address is greater than 0x0 | |
248 | */ | |
c906108c SS |
249 | void |
250 | #ifdef __STDC__ | |
251 | tuiFree ( | |
252 | char *ptr) | |
253 | #else | |
254 | tuiFree (ptr) | |
255 | char *ptr; | |
256 | #endif | |
257 | { | |
258 | if (ptr != (char *) NULL) | |
259 | { | |
b8c9b27d | 260 | xfree (ptr); |
c906108c SS |
261 | } |
262 | ||
263 | return; | |
264 | } /* tuiFree */ | |
265 | ||
266 | ||
267 | /* tuiGetLowDisassemblyAddress(). | |
c5aa993b JM |
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. | |
271 | */ | |
c906108c SS |
272 | Opaque |
273 | #ifdef __STDC__ | |
274 | tuiGetLowDisassemblyAddress ( | |
275 | Opaque low, | |
276 | Opaque pc) | |
277 | #else | |
278 | tuiGetLowDisassemblyAddress (low, pc) | |
279 | Opaque low; | |
280 | Opaque pc; | |
281 | #endif | |
282 | { | |
283 | int line; | |
284 | Opaque newLow; | |
285 | ||
286 | /* | |
c5aa993b JM |
287 | ** Determine where to start the disassembly so that the pc is about in the |
288 | ** middle of the viewport. | |
289 | */ | |
c906108c SS |
290 | for (line = 0, newLow = pc; |
291 | (newLow > low && | |
292 | line < (tuiDefaultWinViewportHeight (DISASSEM_WIN, | |
293 | DISASSEM_COMMAND) / 2));) | |
294 | { | |
295 | bfd_byte buffer[4]; | |
296 | ||
297 | newLow -= sizeof (bfd_getb32 (buffer)); | |
298 | line++; | |
299 | } | |
300 | ||
301 | return newLow; | |
302 | } /* tuiGetLowDisassemblyAddress */ | |
303 | ||
304 | ||
305 | /* tui_vGetLowDisassemblyAddress(). | |
c5aa993b JM |
306 | ** Determine what the low address will be to display in the TUI's |
307 | ** disassembly window with args in a va_list. | |
308 | */ | |
c906108c SS |
309 | Opaque |
310 | #ifdef __STDC__ | |
311 | tui_vGetLowDisassemblyAddress ( | |
312 | va_list args) | |
313 | #else | |
314 | tui_vGetLowDisassemblyAddress (args) | |
315 | va_list args; | |
316 | #endif | |
317 | { | |
318 | int line; | |
319 | Opaque newLow; | |
320 | Opaque low; | |
321 | Opaque pc; | |
322 | ||
323 | low = va_arg (args, Opaque); | |
324 | pc = va_arg (args, Opaque); | |
325 | ||
326 | return (tuiGetLowDisassemblyAddress (low, pc)); | |
327 | ||
328 | } /* tui_vGetLowDisassemblyAddress */ | |
329 | ||
330 | ||
331 | /* | |
c5aa993b JM |
332 | ** tuiDo(). |
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. | |
336 | ** | |
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. | |
340 | ** | |
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. | |
345 | */ | |
c906108c SS |
346 | Opaque |
347 | #ifdef __STDC__ | |
348 | tuiDo ( | |
349 | TuiOpaqueFuncPtr func,...) | |
350 | #else | |
351 | tuiDo (func, va_alist) | |
352 | TuiOpaqueFuncPtr func; | |
353 | va_dcl | |
354 | #endif | |
355 | { | |
356 | extern int terminal_is_ours; | |
357 | ||
358 | Opaque ret = (Opaque) NULL; | |
359 | ||
360 | /* It is an error to be tuiDo'ing if we | |
361 | * don't own the terminal. | |
c5aa993b | 362 | */ |
c906108c SS |
363 | if (!terminal_is_ours) |
364 | return ret; | |
365 | ||
366 | if (tui_version) | |
367 | { | |
368 | va_list args; | |
369 | ||
370 | #ifdef __STDC__ | |
371 | va_start (args, func); | |
372 | #else | |
373 | va_start (args); | |
374 | #endif | |
375 | ret = _tui_vDo (func, args); | |
376 | va_end (args); | |
377 | } | |
378 | ||
379 | return ret; | |
380 | } /* tuiDo */ | |
381 | ||
382 | ||
383 | /* | |
c5aa993b JM |
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. | |
389 | ** | |
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. | |
393 | ** | |
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. | |
398 | ** | |
399 | */ | |
c906108c SS |
400 | Opaque |
401 | #ifdef __STDC__ | |
402 | tuiDoAndReturnToTop ( | |
403 | TuiOpaqueFuncPtr func,...) | |
404 | #else | |
405 | tuiDoAndReturnToTop (func, va_alist) | |
406 | TuiOpaqueFuncPtr func; | |
407 | va_dcl | |
408 | #endif | |
409 | { | |
410 | extern int terminal_is_ours; | |
411 | ||
412 | Opaque ret = (Opaque) NULL; | |
413 | ||
414 | /* It is an error to be tuiDo'ing if we | |
415 | * don't own the terminal. | |
c5aa993b | 416 | */ |
c906108c SS |
417 | if (!terminal_is_ours) |
418 | return ret; | |
419 | ||
420 | if (tui_version) | |
421 | { | |
422 | va_list args; | |
423 | ||
424 | #ifdef __STDC__ | |
425 | va_start (args, func); | |
426 | #else | |
427 | va_start (args); | |
428 | #endif | |
429 | ret = _tui_vDo (func, args); | |
430 | ||
431 | /* force a return to the top level */ | |
432 | return_to_top_level (RETURN_ERROR); | |
433 | } | |
434 | ||
435 | return ret; | |
436 | } /* tuiDoAndReturnToTop */ | |
437 | ||
438 | ||
439 | void | |
440 | #ifdef __STDC__ | |
441 | tui_vSelectSourceSymtab ( | |
442 | va_list args) | |
443 | #else | |
444 | tui_vSelectSourceSymtab (args) | |
445 | va_list args; | |
446 | #endif | |
447 | { | |
448 | struct symtab *s = va_arg (args, struct symtab *); | |
449 | ||
450 | select_source_symtab (s); | |
451 | return; | |
452 | } /* tui_vSelectSourceSymtab */ | |
453 | ||
454 | ||
455 | /* | |
c5aa993b JM |
456 | ** _initialize_tui(). |
457 | ** Function to initialize gdb commands, for tui window manipulation. | |
458 | */ | |
c906108c | 459 | void |
fba45db2 | 460 | _initialize_tui (void) |
c906108c SS |
461 | { |
462 | #if 0 | |
463 | if (tui_version) | |
464 | { | |
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"); | |
469 | } | |
470 | #endif | |
471 | char *helpStr; | |
472 | ||
473 | if (tui_version) | |
474 | helpStr = "Toggle Specified Features\n\ | |
475 | Usage:\ttoggle $fregs\n\ttoggle breakpoints"; | |
476 | else | |
477 | helpStr = "Toggle Specified Features\nUsage:toggle breakpoints"; | |
478 | add_abbrev_prefix_cmd ("toggle", | |
479 | class_tui, | |
480 | _toggle_command, | |
481 | helpStr, | |
482 | &togglelist, | |
483 | "toggle ", | |
484 | 1, | |
485 | &cmdlist); | |
c5aa993b | 486 | } /* _initialize_tui */ |
c906108c SS |
487 | |
488 | ||
489 | /* | |
c5aa993b JM |
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. | |
495 | ** | |
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. | |
500 | */ | |
c906108c SS |
501 | Opaque |
502 | #ifdef __STDC__ | |
503 | va_catch_errors ( | |
504 | TuiOpaqueFuncPtr func, | |
505 | va_list args) | |
506 | #else | |
507 | va_catch_errors (func, args) | |
508 | TuiOpaqueFuncPtr func; | |
509 | va_list args; | |
510 | #endif | |
511 | { | |
512 | Opaque ret = (Opaque) NULL; | |
513 | ||
514 | /* | |
c5aa993b JM |
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. | |
518 | */ | |
c906108c SS |
519 | jmp_buf saved_error; |
520 | jmp_buf saved_quit; | |
521 | jmp_buf tmp_jmp; | |
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; | |
527 | ||
528 | saved_cleanup_chain = save_cleanups (); | |
529 | saved_error_pre_print = error_pre_print; | |
530 | saved_quit_pre_print = quit_pre_print; | |
531 | ||
532 | memcpy ((char *) saved_error, (char *) error_return, sizeof (jmp_buf)); | |
533 | error_pre_print = ""; | |
534 | memcpy (saved_quit, quit_return, sizeof (jmp_buf)); | |
535 | quit_pre_print = ""; | |
536 | ||
537 | if (setjmp (tmp_jmp) == 0) | |
538 | { | |
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); | |
543 | } | |
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; | |
549 | ||
550 | return ret; | |
551 | } | |
552 | ||
553 | /* | |
c5aa993b JM |
554 | ** vcatch_errors(). |
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. | |
558 | */ | |
c906108c SS |
559 | Opaque |
560 | #ifdef __STDC__ | |
561 | vcatch_errors ( | |
562 | OpaqueFuncPtr func,...) | |
563 | #else | |
564 | vcatch_errors (va_alist) | |
565 | va_dcl | |
566 | /* | |
c5aa993b JM |
567 | vcatch_errors(func, va_alist) |
568 | OpaqueFuncPtr func; | |
569 | va_dcl | |
570 | */ | |
c906108c SS |
571 | #endif |
572 | { | |
573 | Opaque ret = (Opaque) NULL; | |
574 | va_list args; | |
575 | #ifdef __STDC__ | |
576 | va_start (args, func); | |
577 | /* | |
c5aa993b JM |
578 | va_arg(args, OpaqueFuncPtr); |
579 | */ | |
c906108c SS |
580 | #else |
581 | OpaqueFuncPtr func; | |
582 | ||
583 | va_start (args); | |
584 | func = va_arg (args, OpaqueFuncPtr); | |
585 | #endif | |
586 | ret = va_catch_errors (func, args); | |
587 | va_end (args); | |
588 | ||
589 | return ret; | |
590 | } | |
591 | ||
592 | ||
593 | void | |
594 | #ifdef __STDC__ | |
595 | strcat_to_buf ( | |
596 | char *buf, | |
597 | int buflen, | |
598 | char *itemToAdd) | |
599 | #else | |
600 | strcat_to_buf (buf, buflen, itemToAdd) | |
601 | char *buf; | |
602 | int buflen; | |
603 | char *itemToAdd; | |
604 | #endif | |
605 | { | |
606 | if (itemToAdd != (char *) NULL && buf != (char *) NULL) | |
607 | { | |
608 | if ((strlen (buf) + strlen (itemToAdd)) <= buflen) | |
609 | strcat (buf, itemToAdd); | |
610 | else | |
611 | strncat (buf, itemToAdd, (buflen - strlen (buf))); | |
612 | } | |
613 | ||
614 | return; | |
615 | } /* strcat_to_buf */ | |
616 | ||
617 | /* VARARGS */ | |
618 | void | |
619 | #ifdef ANSI_PROTOTYPES | |
620 | strcat_to_buf_with_fmt ( | |
621 | char *buf, | |
622 | int bufLen, | |
623 | char *format,...) | |
624 | #else | |
625 | strcat_to_buf_with_fmt (va_alist) | |
626 | va_dcl | |
627 | #endif | |
628 | { | |
629 | char *linebuffer; | |
630 | struct cleanup *old_cleanups; | |
631 | va_list args; | |
632 | #ifdef ANSI_PROTOTYPES | |
633 | va_start (args, format); | |
634 | #else | |
635 | char *buf; | |
636 | int bufLen; | |
637 | char *format; | |
638 | ||
639 | va_start (args); | |
640 | buf = va_arg (args, char *); | |
641 | bufLen = va_arg (args, int); | |
642 | format = va_arg (args, char *); | |
643 | #endif | |
644 | vasprintf (&linebuffer, format, args); | |
b8c9b27d | 645 | old_cleanups = make_cleanup (xfree, linebuffer); |
c906108c SS |
646 | strcat_to_buf (buf, bufLen, linebuffer); |
647 | do_cleanups (old_cleanups); | |
648 | va_end (args); | |
649 | } | |
650 | ||
651 | ||
652 | ||
653 | ||
654 | ||
655 | /*********************** | |
656 | ** Static Functions | |
657 | ************************/ | |
658 | ||
659 | ||
660 | /* | |
c5aa993b JM |
661 | ** _tui_vDo(). |
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. | |
665 | ** | |
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. | |
669 | ** | |
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. | |
674 | */ | |
c906108c SS |
675 | static Opaque |
676 | #ifdef __STDC__ | |
677 | _tui_vDo ( | |
678 | TuiOpaqueFuncPtr func, | |
679 | va_list args) | |
680 | #else | |
681 | _tui_vDo (func, args) | |
682 | TuiOpaqueFuncPtr func; | |
683 | va_list args; | |
684 | #endif | |
685 | { | |
686 | extern int terminal_is_ours; | |
687 | ||
688 | Opaque ret = (Opaque) NULL; | |
689 | ||
690 | /* It is an error to be tuiDo'ing if we | |
691 | * don't own the terminal. | |
c5aa993b | 692 | */ |
c906108c SS |
693 | if (!terminal_is_ours) |
694 | return ret; | |
695 | ||
696 | if (tui_version) | |
697 | { | |
698 | /* If doing command window the "XDB way" (command window | |
699 | * is unmanaged by curses... | |
c5aa993b | 700 | */ |
c906108c SS |
701 | /* Set up terminal for TUI */ |
702 | tuiTermSetup (1); | |
703 | ||
704 | ret = va_catch_errors (func, args); | |
705 | ||
706 | /* Set up terminal for command window */ | |
707 | tuiTermUnsetup (1, cmdWin->detail.commandInfo.curch); | |
708 | } | |
709 | ||
710 | return ret; | |
711 | } /* _tui_vDo */ | |
712 | ||
713 | ||
714 | static void | |
715 | #ifdef __STDC__ | |
716 | _toggle_command ( | |
717 | char *arg, | |
718 | int fromTTY) | |
719 | #else | |
720 | _toggle_command (arg, fromTTY) | |
721 | char *arg; | |
722 | int fromTTY; | |
723 | #endif | |
724 | { | |
725 | printf_filtered ("Specify feature to toggle.\n%s\n", | |
726 | (tui_version) ? TUI_TOGGLE_USAGE : TOGGLE_USAGE); | |
727 | /* | |
c5aa993b JM |
728 | tuiDo((TuiOpaqueFuncPtr)_Toggle_command, arg, fromTTY); |
729 | */ | |
c906108c SS |
730 | } |
731 | ||
732 | /* | |
c5aa993b JM |
733 | ** _tui_vToggle_command(). |
734 | */ | |
c906108c SS |
735 | static void |
736 | #ifdef __STDC__ | |
737 | _tui_vToggle_command ( | |
738 | va_list args) | |
739 | #else | |
740 | _tui_vToggle_command (args) | |
741 | va_list args; | |
742 | #endif | |
743 | { | |
744 | char *arg; | |
745 | int fromTTY; | |
746 | ||
747 | arg = va_arg (args, char *); | |
748 | ||
749 | if (arg == (char *) NULL) | |
750 | printf_filtered (TOGGLE_USAGE); | |
751 | else | |
752 | { | |
753 | char *ptr = (char *) tuiStrDup (arg); | |
754 | int i; | |
755 | ||
756 | for (i = 0; (ptr[i]); i++) | |
757 | ptr[i] = toupper (arg[i]); | |
758 | ||
759 | if (subsetCompare (ptr, TUI_FLOAT_REGS_NAME)) | |
760 | tuiToggleFloatRegs (); | |
761 | /* else if (subsetCompare(ptr, "ANOTHER TOGGLE OPTION")) | |
c5aa993b JM |
762 | ... |
763 | */ | |
c906108c SS |
764 | else |
765 | printf_filtered (TOGGLE_USAGE); | |
766 | tuiFree (ptr); | |
767 | } | |
768 | ||
769 | return; | |
770 | } /* _tuiToggle_command */ | |
771 | ||
772 | ||
773 | static void | |
774 | #ifdef __STDC__ | |
775 | _tuiReset (void) | |
776 | #else | |
777 | _tuiReset () | |
778 | #endif | |
779 | { | |
780 | struct termio mode; | |
781 | ||
782 | /* | |
c5aa993b JM |
783 | ** reset the teletype mode bits to a sensible state. |
784 | ** Copied tset.c | |
785 | */ | |
c906108c SS |
786 | #if ! defined (USG) && defined (TIOCGETC) |
787 | struct tchars tbuf; | |
788 | #endif /* !USG && TIOCGETC */ | |
789 | #ifdef UCB_NTTY | |
790 | struct ltchars ltc; | |
791 | ||
792 | if (ldisc == NTTYDISC) | |
793 | { | |
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); | |
802 | } | |
803 | #endif /* UCB_NTTY */ | |
804 | #ifndef USG | |
805 | #ifdef TIOCGETC | |
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 | |
816 | #ifdef CBREAK | |
817 | | CBREAK | |
818 | #endif /* CBREAK */ | |
819 | | VTDELAY | ALLDELAY); | |
820 | mode.sg_flags |= XTABS | ECHO | CRMOD | ANYP; | |
c5aa993b | 821 | #else /*USG */ |
c906108c SS |
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')); | |
826 | ||
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); | |
833 | #ifndef hp9000s800 | |
834 | mode.c_cflag |= (CS8 | CREAD); | |
c5aa993b | 835 | #else /*hp9000s800 */ |
c906108c SS |
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); | |
841 | #endif /* USG */ | |
842 | ||
843 | return; | |
844 | } /* _tuiReset */ |