Commit | Line | Data |
---|---|---|
2eea383b ML |
1 | /* Copyright (c) 1982 Regents of the University of California */ |
2 | ||
9fcd5a25 | 3 | static char sccsid[] = "@(#)runcont.c 1.5 %G%"; |
2eea383b ML |
4 | |
5 | /* | |
c6f95754 | 6 | * Execution management. |
2eea383b ML |
7 | */ |
8 | ||
9 | #include "defs.h" | |
10 | #include <signal.h> | |
11 | #include "process.h" | |
12 | #include "machine.h" | |
13 | #include "object.h" | |
c6f95754 | 14 | #include "main.h" |
2eea383b ML |
15 | #include "breakpoint.h" |
16 | #include "command.h" | |
17 | #include "process.rep" | |
18 | ||
f9e6f1f3 | 19 | #define MAXNARGS 100 /* maximum number of arguments to RUN */ |
2eea383b | 20 | |
c6f95754 | 21 | typedef char *String; |
2eea383b ML |
22 | |
23 | LOCAL BOOLEAN just_started; | |
24 | LOCAL int argc; | |
c6f95754 ML |
25 | LOCAL String argv[MAXNARGS]; |
26 | LOCAL String infile; | |
27 | LOCAL String outfile; | |
f9e6f1f3 | 28 | LOCAL PROCESS pbuf; |
9fcd5a25 | 29 | PROCESS *process = &pbuf; |
2eea383b ML |
30 | |
31 | /* | |
c6f95754 ML |
32 | * This is a px-related kludge to deal with the possibility |
33 | * of object code magically coming from a tmp file. | |
34 | */ | |
35 | ||
36 | LOCAL String mode; | |
37 | LOCAL String realname; | |
38 | ||
39 | setargs(m, r) | |
40 | char *m, *r; | |
41 | { | |
f9e6f1f3 ML |
42 | mode = m; |
43 | realname = r; | |
c6f95754 ML |
44 | } |
45 | ||
46 | /* | |
47 | * Initialize the argument list. | |
2eea383b ML |
48 | */ |
49 | ||
50 | arginit() | |
51 | { | |
f9e6f1f3 ML |
52 | infile = NIL; |
53 | outfile = NIL; | |
54 | # if (isvaxpx) | |
55 | argv[0] = mode; | |
56 | argv[1] = objname; | |
57 | if (option('t') && realname == NIL) { | |
58 | argc = 2; | |
59 | } else { | |
60 | argv[2] = realname; | |
61 | argc = 3; | |
62 | } | |
63 | # else | |
64 | argv[0] = objname; | |
65 | argc = 1; | |
66 | # endif | |
2eea383b ML |
67 | } |
68 | ||
69 | /* | |
c6f95754 | 70 | * Add an argument to the list for the debuggee. |
2eea383b ML |
71 | */ |
72 | ||
73 | newarg(arg) | |
c6f95754 | 74 | String arg; |
2eea383b | 75 | { |
f9e6f1f3 ML |
76 | if (argc >= MAXNARGS) { |
77 | error("too many arguments to run"); | |
78 | } | |
79 | argv[argc++] = arg; | |
2eea383b ML |
80 | } |
81 | ||
82 | /* | |
c6f95754 | 83 | * Set the standard input for the debuggee. |
2eea383b ML |
84 | */ |
85 | ||
86 | inarg(filename) | |
c6f95754 | 87 | String filename; |
2eea383b | 88 | { |
f9e6f1f3 ML |
89 | if (infile != NIL) { |
90 | error("multiple input redirects"); | |
91 | } | |
92 | infile = filename; | |
2eea383b ML |
93 | } |
94 | ||
95 | /* | |
c6f95754 ML |
96 | * Set the standard output for the debuggee. |
97 | * Probably should check to avoid overwriting an existing file. | |
2eea383b ML |
98 | */ |
99 | ||
100 | outarg(filename) | |
c6f95754 | 101 | String filename; |
2eea383b | 102 | { |
f9e6f1f3 ML |
103 | if (outfile != NIL) { |
104 | error("multiple output redirect"); | |
105 | } | |
106 | outfile = filename; | |
2eea383b ML |
107 | } |
108 | ||
109 | /* | |
c6f95754 ML |
110 | * Initial start of the process. The idea is to get it to the point |
111 | * where the object code has been loaded but execution has not begun. | |
112 | */ | |
113 | ||
114 | initstart() | |
115 | { | |
f9e6f1f3 ML |
116 | arginit(); |
117 | argv[argc] = NIL; | |
f9e6f1f3 ML |
118 | initcache(process); |
119 | start(argv, infile, outfile); | |
875f8c0a ML |
120 | if (process->status != STOPPED) { |
121 | panic("could not start program"); | |
122 | } | |
c6f95754 ML |
123 | } |
124 | ||
125 | /* | |
126 | * Run starts debuggee executing. | |
2eea383b ML |
127 | */ |
128 | ||
129 | run() | |
130 | { | |
f9e6f1f3 ML |
131 | fixbps(); |
132 | curline = 0; | |
133 | argv[argc] = NIL; | |
134 | start(argv, infile, outfile); | |
875f8c0a ML |
135 | if (process->status == STOPPED) { |
136 | just_started = TRUE; | |
137 | isstopped = FALSE; | |
138 | cont(); | |
139 | } else if (option('r')) { | |
140 | panic("could not start program"); | |
141 | } | |
2eea383b ML |
142 | } |
143 | ||
144 | /* | |
c6f95754 | 145 | * Continue execution wherever we left off. |
2eea383b ML |
146 | * |
147 | * Note that this routine never returns. Eventually bpact() will fail | |
148 | * and we'll call printstatus or step will call it. | |
149 | */ | |
150 | ||
151 | typedef int INTFUNC(); | |
152 | ||
153 | LOCAL INTFUNC *dbintr; | |
154 | LOCAL intr(); | |
155 | ||
f9e6f1f3 ML |
156 | #define succeeds == TRUE |
157 | #define fails == FALSE | |
2eea383b ML |
158 | |
159 | cont() | |
160 | { | |
f9e6f1f3 ML |
161 | dbintr = signal(SIGINT, intr); |
162 | if (just_started) { | |
163 | just_started = FALSE; | |
164 | } else { | |
165 | if (!isstopped) { | |
166 | error("can't continue execution"); | |
2eea383b | 167 | } |
f9e6f1f3 ML |
168 | isstopped = FALSE; |
169 | step(); | |
170 | } | |
171 | for (;;) { | |
172 | if (single_stepping) { | |
173 | printnews(); | |
174 | } else { | |
175 | setallbps(); | |
176 | resume(); | |
177 | unsetallbps(); | |
178 | if (bpact() fails) { | |
179 | printstatus(); | |
180 | } | |
2eea383b | 181 | } |
f9e6f1f3 ML |
182 | step(); |
183 | } | |
184 | /* NOTREACHED */ | |
2eea383b ML |
185 | } |
186 | ||
187 | /* | |
188 | * This routine is called if we get an interrupt while "running" px | |
189 | * but actually in the debugger. Could happen, for example, while | |
190 | * processing breakpoints. | |
191 | * | |
192 | * We basically just want to keep going; the assumption is | |
193 | * that when the process resumes it will get the interrupt | |
194 | * which will then be handled. | |
195 | */ | |
196 | ||
197 | LOCAL intr() | |
198 | { | |
f9e6f1f3 | 199 | signal(SIGINT, intr); |
2eea383b ML |
200 | } |
201 | ||
202 | fixintr() | |
203 | { | |
f9e6f1f3 | 204 | signal(SIGINT, dbintr); |
2eea383b | 205 | } |