1 /*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)resume.c 8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11
12 /*
13 * Resume execution, first setting appropriate registers.
14 */
15
16 #include "defs.h"
17 #include <signal.h>
18 #include "process.h"
19 #include "machine.h"
20 #include "main.h"
21 #include "process.rep"
22 #include "runtime/frame.rep"
23
24 #include "machine/pxerrors.h"
25 #include "pxinfo.h"
26
27 /*
28 * Resume execution, set (get) pcode location counter before (after) resuming.
29 */
30
resume()31 resume()
32 {
33 register PROCESS *p;
34
35 p = process;
36 do {
37 if (option('e')) {
38 printf("execution resumes at pc 0x%x, lc %d\n", process->pc, pc);
39 fflush(stdout);
40 }
41 pcont(p);
42 dread(&pc, PCADDR, sizeof(pc)); /* Get pcode pc */
43 if (option('e')) {
44 printf("execution stops at pc 0x%x, lc %d on sig %d\n",
45 process->pc, pc, p->signo);
46 fflush(stdout);
47 }
48 } while (p->signo == SIGCONT);
49 if (option('r') && p->signo != 0) {
50 choose();
51 }
52
53 /*
54 * If px implements a breakpoint by executing a halt instruction
55 * the real pc must be incremented to skip over it.
56 *
57 * Currently, px sends itself a signal so no incrementing is needed.
58 *
59 if (isbperr()) {
60 p->pc++;
61 }
62 */
63 }
64
65 /*
66 * Under the -r option, we offer the opportunity to just get
67 * the px traceback and not actually enter the debugger.
68 *
69 * If the standard input is not a tty but standard error is,
70 * change standard input to be /dev/tty.
71 */
72
choose()73 LOCAL choose()
74 {
75 register int c;
76
77 if (!isterm(stdin)) {
78 if (!isterm(stderr) || freopen("/dev/tty", "r", stdin) == NIL) {
79 unsetsigtraces(process);
80 pcont(process);
81 quit(process->exitval);
82 /* NOTREACHED */
83 }
84 }
85 fprintf(stderr, "\nProgram error");
86 fprintf(stderr, "\nDo you wish to enter the debugger? ");
87 c = getchar();
88 if (c == 'n') {
89 unsetsigtraces(process);
90 pcont(process);
91 quit(process->exitval);
92 }
93 while (c != '\n' && c != EOF) {
94 c = getchar();
95 }
96 fprintf(stderr, "\nEntering debugger ...");
97 init();
98 option('r') = FALSE;
99 fprintf(stderr, " type 'help' for help.\n");
100 }
101