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