|
|
1.1 root 1: /*
2: * machine-specific functions for running the debugged process
3: * v7-style (ptrace)
4: */
5:
6: #include "defs.h"
7: #include "regs.h"
8: #include "ptrace.h"
9: #include <sys/param.h>
10: #include <signal.h>
11:
12: extern char lastc, peekc;
13: extern ADDR txtsize;
14:
15: /*
16: * kill process
17: */
18:
19: killpcs()
20: {
21:
22: ptrace(P_KILL, pid, 0, 0);
23: }
24:
25: /*
26: * grab the process already opened (but not traced);
27: * stop it so we can look at it
28: */
29:
30: grab()
31: {
32:
33: error("antique system, can't grab");
34: }
35:
36: /*
37: * turn off tracing & let it go
38: */
39:
40: ungrab()
41: {
42:
43: error("antique system, can't ungrab");
44: }
45:
46: /*
47: * get the program to be debugged ready to run
48: * program is left stopped at the beginning (so we can poke in breakpoints)
49: */
50:
51: extern int (*sigint)(), (*sigqit)();
52:
53: startpcs()
54: {
55:
56: if ((pid = fork()) == 0) {
57: close(fsym);
58: close(fcor);
59: signal(SIGINT, sigint);
60: signal(SIGQUIT, sigqit);
61: doexec();
62: exit(0);
63: }
64: if (pid == -1)
65: error("cannot fork");
66: bpwait();
67: if (adrflg)
68: rput(PC, wtoa(adrval));
69: while (rdc() != EOR)
70: ;
71: reread();
72: }
73:
74: /*
75: * set process running, single-stepped
76: */
77:
78: runstep(keepsig)
79: int keepsig;
80: {
81:
82: delbp();
83: ptrace(P_STEP, pid, CONTNEXT, keepsig ? signo : 0);
84: }
85:
86: /*
87: * set process running
88: */
89:
90: runrun(keepsig)
91: int keepsig;
92: {
93:
94: ptrace(P_CONT, pid, CONTNEXT, keepsig ? signo : 0);
95: }
96:
97: /*
98: * exec the program to be debugged
99: * opening standard input and output as requested
100: */
101:
102: extern char **environ;
103:
104: doexec()
105: {
106: char *argl[MAXARG];
107: char args[LINSIZ];
108: register char *p;
109: register char **ap;
110: register char *thisarg;
111:
112: ap = argl;
113: p = args;
114: *ap++ = symfil;
115: for (rdc(); lastc != EOR;) {
116: thisarg = p;
117: if (lastc == '<' || lastc == '>') {
118: *p++ = lastc;
119: rdc();
120: }
121: while (lastc != EOR && lastc != SPC && lastc != TB) {
122: *p++ = lastc;
123: readchar();
124: }
125: if (lastc == SPC || lastc == TB)
126: rdc();
127: *p++ = 0;
128: if (*thisarg == '<') {
129: close(0);
130: if (open(&thisarg[1], 0) < 0) {
131: printf("%s: cannot open\n", &thisarg[1]);
132: _exit(0);
133: }
134: }
135: else if (*thisarg == '>') {
136: close(1);
137: if (creat(&thisarg[1], 0666) < 0) {
138: printf("%s: cannot create\n", &thisarg[1]);
139: _exit(0);
140: }
141: }
142: else
143: *ap++ = thisarg;
144: }
145: *ap = NULL;
146: ptrace(P_INIT, 0, (int *)0, 0);
147: execve(symfil, argl, environ);
148: perror(symfil);
149: }
150:
151: /*
152: * wait for the process to stop;
153: * pick up status and registers when it does
154: */
155:
156: #define WSLEEP 10
157:
158: extern int errno;
159:
160: bpwait()
161: {
162: register int w;
163: int stat;
164: int (*isig)();
165: int nulsig();
166:
167: isig = signal(SIGINT, SIG_IGN);
168: while ((w = wait(&stat)) != -1 && w != pid)
169: ;
170: signal(SIGINT, isig);
171: if (w == -1)
172: errflg = "wait failed";
173: else if ((stat & 0177) == 0177) { /* trace status */
174: signo = (stat >> 8) & 0177;
175: mapimage();
176: if (signo == SIGTRAP)
177: signo = 0;
178: else {
179: sigprint();
180: newline();
181: }
182: return;
183: }
184: else {
185: errflg = "process terminated";
186: sigcode = 0;
187: if ((signo = stat & 0177) != 0)
188: sigprint();
189: if (stat & 0200) {
190: prints(" - core dumped");
191: corfil = "core";
192: }
193: pid = 0;
194: setcor();
195: }
196: }
197:
198: /*
199: * is the right-hand file a process image?
200: */
201:
202: trcimage()
203: {
204:
205: return (pid != 0);
206: }
207:
208: /*
209: * grab some data from the user block,
210: * before maps are set up (ugh)
211: */
212:
213: int
214: trcunab(off)
215: int off;
216: {
217: int data;
218:
219: errno = 0;
220: data = ptrace(P_RDU, pid, off, 0);
221: if (errno) {
222: errflg = "can't read user block";
223: return (0);
224: }
225: return (data);
226: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.