fix copyright
[unix-history] / usr / src / usr.bin / pascal / pdx / process / runcont.c
CommitLineData
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
8static 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 27typedef char *String;
2eea383b
ML
28
29LOCAL BOOLEAN just_started;
30LOCAL int argc;
c6f95754
ML
31LOCAL String argv[MAXNARGS];
32LOCAL String infile;
33LOCAL String outfile;
f9e6f1f3 34LOCAL PROCESS pbuf;
9fcd5a25 35PROCESS *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
42LOCAL String mode;
43LOCAL String realname;
44
45setargs(m, r)
46char *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
56arginit()
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
79newarg(arg)
c6f95754 80String 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
92inarg(filename)
c6f95754 93String 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
106outarg(filename)
c6f95754 107String 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
120initstart()
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
135run()
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
157typedef int INTFUNC();
158
159LOCAL INTFUNC *dbintr;
160LOCAL intr();
161
f9e6f1f3
ML
162#define succeeds == TRUE
163#define fails == FALSE
2eea383b
ML
164
165cont()
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
203LOCAL intr()
204{
f9e6f1f3 205 signal(SIGINT, intr);
2eea383b
ML
206}
207
208fixintr()
209{
f9e6f1f3 210 signal(SIGINT, dbintr);
2eea383b 211}