|
|
1.1 root 1: #
2: /*
3: *
4: * UNIX debugger
5: *
6: */
7:
8: #include "defs.h"
9: #include <signal.h>
10: #include "regs.h"
11:
12: MSG BADEQ;
13: MSG NOMATCH;
14: MSG BADVAR;
15: MSG BADCOM;
16: MSG NOFORK;
17:
18: BOOL executing;
19: char *lp;
20:
21: char lastc;
22: char eqformat[ARB] = "z";
23: char stformat[ARB] = "X\"= \"^i";
24:
25: ADDR ditto;
26:
27: ADDR dot;
28: WORD dotinc;
29: WORD adrval, cntval, loopcnt;
30: int adrflg, cntflg;
31: int adrsp, dotsp, ditsp;
32:
33: /* command decoding */
34:
35: command(buf,defcom)
36: register char *buf;
37: char defcom;
38: {
39: int modifier, regptr;
40: char savc;
41: char *savlp=lp;
42: static char lastcom = '=';
43:
44: if (defcom == 0)
45: defcom = lastcom;
46: if (buf) {
47: if (*buf==EOR)
48: return(FALSE);
49: lp=buf;
50: }
51: do {
52: if (adrflg=expr(0)) {
53: dot=ditto=expv;
54: dotsp=ditsp=expsp;
55: }
56: adrval=dot;
57: adrsp=dotsp;
58: if (rdc()==',' && expr(0)) {
59: cntflg=TRUE;
60: cntval=expv;
61: } else {
62: cntflg=FALSE;
63: cntval=1;
64: reread();
65: }
66: if (!eol(rdc()))
67: lastcom=lastc;
68: else {
69: if (adrflg==0)
70: dot=inkdot(dotinc);
71: reread();
72: lastcom=defcom;
73: }
74: switch(lastcom&STRIP) {
75: case '/':
76: case '=':
77: case '?':
78: acommand(lastcom & STRIP);
79: break;
80:
81: case '>':
82: lastcom=0;
83: savc=rdc();
84: if ((regptr=getreg(savc)) != BADREG)
85: rput(regptr, wtor(dot));
86: else if ((modifier=varchk(savc)) != -1)
87: var[modifier]=dot;
88: else
89: error(BADVAR);
90: break;
91:
92: case '!':
93: lastcom=0;
94: shell();
95: break;
96:
97: case '$':
98: lastcom=0;
99: printtrace(nextchar());
100: break;
101:
102: case ':':
103: if (!executing) {
104: executing=TRUE;
105: subpcs(nextchar());
106: executing=FALSE;
107: lastcom=0;
108: }
109: break;
110:
111: case 0:
112: prints(DBNAME);
113: break;
114:
115: default:
116: error(BADCOM);
117: }
118: flushbuf();
119: } while (rdc()==';');
120: if (buf)
121: lp=savlp;
122: else
123: reread();
124: return(adrflg && dot!=0);
125: }
126:
127: /*
128: * [/?][wml]
129: */
130:
131: acommand(pc)
132: char pc;
133: {
134: register int itype;
135: int eqcom;
136: int star;
137: char wformat[1];
138: ADDR savdot;
139:
140: switch (pc) {
141: case '/':
142: itype = CORF | DATASP;
143: break;
144:
145: case '=':
146: itype = NOSP;
147: break;
148:
149: case '?':
150: itype = SYMF | INSTSP;
151: break;
152: }
153: eqcom = FALSE;
154: star = FALSE;
155: if (pc == '=')
156: eqcom = TRUE;
157: else {
158: if (rdc()=='*')
159: star = TRUE;
160: else
161: reread();
162: if (star) {
163: if (itype & SYMF)
164: itype = SYMF | DATASP;
165: else
166: itype = CORF | INSTSP;
167: }
168: if ((adrsp & SPTYPE) == REGSP) {
169: itype &=~ SPTYPE;
170: itype |= REGSP;
171: }
172: }
173: switch (rdc()) {
174: case 'm':
175: if (eqcom)
176: error(BADEQ);
177: cmdmap(itype, star);
178: break;
179:
180: case 'L':
181: case 'l':
182: if (eqcom)
183: error(BADEQ);
184: cmdsrc(lastc, itype, itype);
185: break;
186:
187: case 'W':
188: case 'w':
189: if (eqcom)
190: error(BADEQ);
191: wformat[0]=lastc;
192: expr(1);
193: do {
194: savdot=dot;
195: psymoff((WORD)dot, itype, itype & SYMF ?"?%16t":"/%16t");
196: exform(1,wformat,itype,itype);
197: errflg=0;
198: dot=savdot;
199: if (wformat[0] == 'W')
200: lput(dot,itype,wtol(expv));
201: else
202: sput(dot,itype,wtos(expv));
203: savdot=dot;
204: printf("=%8t");
205: exform(1,wformat,itype,itype);
206: newline();
207: } while (expr(0) && errflg==0);
208: dot=savdot;
209: chkerr();
210: break;
211:
212: default:
213: reread();
214: getformat(eqcom ? eqformat : stformat);
215: if (!eqcom)
216: psymoff((WORD)dot, itype, itype & SYMF ?"?%16t":"/%16t");
217: scanform(cntval,(eqcom?eqformat:stformat),itype,itype);
218: }
219: }
220:
221: cmdsrc(c, itype, ptype)
222: char c;
223: {
224: register WORD w;
225: register WORD locval, locmsk;
226: ADDR savdot;
227:
228: if (c == 'L')
229: dotinc = sizeof(TLONG);
230: else
231: dotinc = sizeof(TSHORT);
232: savdot=dot;
233: expr(1);
234: locval=expv;
235: if (expr(0))
236: locmsk=expv;
237: else
238: locmsk = ~0;
239: if (c == 'L') {
240: for (;;) {
241: w = ltow(lget(dot, itype));
242: if (errflg || mkfault
243: || (w & locmsk) == locval)
244: break;
245: dot = inkdot(dotinc);
246: }
247: }
248: else {
249: for (;;) {
250: w = stow(sget(dot, itype));
251: if (errflg || mkfault
252: || (w & locmsk) == locval)
253: break;
254: dot = inkdot(dotinc);
255: }
256: }
257: if (errflg) {
258: dot=savdot;
259: errflg=NOMATCH;
260: }
261: psymoff((WORD)dot,ptype,"");
262: }
263:
264: /*
265: * collect a register name; return register offset
266: * this is not what i'd call a good division of labour
267: */
268:
269: int
270: getreg(regnam)
271: {
272: char buf[LINSIZ];
273: register char *p;
274: register int c;
275:
276: p = buf;
277: *p++ = regnam;
278: while (isalnum(c = readchar()))
279: *p++ = c;
280: *p = 0;
281: reread();
282: return (rname(buf));
283: }
284:
285: /*
286: * shell escape
287: */
288:
289: shell()
290: {
291: int rc, status, unixpid;
292: char *sh;
293: char *argp = lp;
294: int (*isig)();
295: extern (*sigint)(), (*sigqit)();
296: char *getenv();
297:
298: if ((sh = getenv("SHELL")) == NULL)
299: sh = "/bin/sh";
300: while (lastc!=EOR)
301: rdc();
302: if ((unixpid=fork())==0) {
303: signal(SIGINT, sigint);
304: signal(SIGQUIT, sigqit);
305: *lp=0;
306: execl(sh, "sh", "-c", argp, 0);
307: _exit(16);
308: } else if (unixpid == -1) {
309: error(NOFORK);
310: } else {
311: isig = signal(SIGINT, SIG_IGN);
312: while ((rc = wait(&status)) != unixpid && rc != -1)
313: ;
314: signal(SIGINT, isig);
315: prints("!");
316: reread();
317: }
318: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.