1: #
2: /*
3: *
4: * UNIX debugger
5: *
6: */
7:
8: #include "defs.h"
9:
10:
11: MSG BADSYM;
12: MSG BADVAR;
13: MSG BADKET;
14: MSG BADSYN;
15: MSG NOCFN;
16: MSG NOADR;
17: MSG BADLOC;
18:
19: SYMTAB symbol;
20: INT lastframe;
21: INT kernel;
22: INT savlastf;
23: L_INT savframe;
24: OVTAG svlastov;
25: INT savpc;
26: INT callpc;
27:
28:
29:
30: CHAR *lp;
31: INT octal;
32: STRING errflg;
33: L_INT localval;
34: CHAR isymbol[8];
35:
36: CHAR lastc;
37: POS *uar0;
38: POS *corhdr;
39: OVTAG curov, startov;
40: OVTAG lastsymov;
41: int overlay;
42:
43: L_INT dot;
44: L_INT ditto;
45: INT dotinc;
46: L_INT var[];
47: L_INT expv;
48:
49:
50:
51:
52: expr(a)
53: { /* term | term dyadic expr | */
54: INT rc;
55: L_INT lhs;
56:
57: lastsymov = 0;
58: rdc(); lp--; rc=term(a);
59:
60: WHILE rc
61: DO lhs = expv;
62:
63: switch (readchar()) {
64:
65: case '+':
66: term(a|1); expv += lhs; break;
67:
68: case '-':
69: term(a|1); expv = lhs - expv; break;
70:
71: case '#':
72: term(a|1); expv = round(lhs,expv); break;
73:
74: case '*':
75: term(a|1); expv *= lhs; break;
76:
77: case '%':
78: term(a|1); expv = lhs/expv; break;
79:
80: case '&':
81: term(a|1); expv &= lhs; break;
82:
83: case '|':
84: term(a|1); expv |= lhs; break;
85:
86: case ')':
87: IF (a&2)==0 THEN error(BADKET); FI
88:
89: default:
90: lp--;
91: return(rc);
92: }
93: OD
94: return(rc);
95: }
96:
97: term(a)
98: { /* item | monadic item | (expr) | */
99:
100: switch (readchar()) {
101:
102: case '*':
103: term(a|1); expv=chkget(expv,DSP); return(1);
104:
105: case '@':
106: term(a|1); expv=chkget(expv,ISP); return(1);
107:
108: case '-':
109: term(a|1); expv = -expv; return(1);
110:
111: case '~':
112: term(a|1); expv = ~expv; return(1);
113:
114: case '(':
115: expr(2);
116: IF *lp!=')'
117: THEN error(BADSYN);
118: ELSE lp++; return(1);
119: FI
120:
121: default:
122: lp--;
123: return(item(a));
124: }
125: }
126:
127: item(a)
128: { /* name [ . local ] | number | . | ^ | <var | <register | 'x | | */
129: INT base, d, frpt, regptr;
130: CHAR savc;
131: BOOL hex;
132: L_INT frame;
133: UNION{REAL r; L_INT i;} real;
134: SYMPTR symp;
135: OVTAG savov;
136:
137: hex=FALSE;
138:
139: readchar();
140: IF symchar(0)
141: THEN readsym();
142: IF lastc=='.'
143: THEN frame=(kernel?corhdr[KR5]:uar0[R5])&EVEN;
144: lastframe=0; callpc=kernel?(-2):uar0[PC];
145: if (overlay){
146: savov = curov;
147: setovmap(startov);
148: }
149: WHILE errflg==0
150: DO savpc=callpc;
151: findroutine(frame);
152: IF eqsym(symbol.symc,isymbol,'~')
153: THEN break;
154: FI
155: lastframe=frame;
156: frame=get(frame,DSP)&EVEN;
157: IF frame==0
158: THEN error(NOCFN);
159: FI
160: OD
161: savlastf=lastframe; savframe=frame;
162: svlastov = curov;
163: readchar();
164: IF symchar(0)
165: THEN chkloc(expv=frame);
166: FI
167: if (overlay)
168: setovmap(savov);
169: ELIF (symp=lookupsym(isymbol))==0 THEN error(BADSYM);
170: ELSE expv = symp->symv; lastsymov=symp->ovnumb;
171: FI
172: lp--;
173:
174:
175: ELIF digit(lastc) ORF (hex=TRUE, lastc=='#' ANDF hexdigit(readchar()))
176: THEN expv = 0;
177: base = (lastc == '0' ORF octal ? 8 : (hex ? 16 : 10));
178: WHILE (hex ? hexdigit(lastc) : digit(lastc))
179: DO expv *= base;
180: IF (d=convdig(lastc))>=base THEN error(BADSYN); FI
181: expv += d; readchar();
182: IF expv==0 ANDF (lastc=='x' ORF lastc=='X')
183: THEN hex=TRUE; base=16; readchar();
184: FI
185: OD
186: IF lastc=='.' ANDF (base==10 ORF expv==0) ANDF !hex
187: THEN real.r=expv; frpt=0; base=10;
188: WHILE digit(readchar())
189: DO real.r *= base; frpt++;
190: real.r += lastc-'0';
191: OD
192: WHILE frpt--
193: DO real.r /= base; OD
194: expv = real.i;
195: FI
196: lp--;
197:
198: ELIF lastc=='.'
199: THEN readchar();
200: IF symchar(0)
201: THEN savov = curov;
202: curov = svlastov;
203: lastframe=savlastf; callpc=savpc; findroutine(savframe);
204: chkloc(savframe);
205: if(overlay)
206: setovmap(savov);
207: ELSE expv=dot;
208: FI
209: lp--;
210:
211: ELIF lastc=='"'
212: THEN expv=ditto;
213:
214: ELIF lastc=='+'
215: THEN expv=inkdot(dotinc);
216:
217: ELIF lastc=='^'
218: THEN expv=inkdot(-dotinc);
219:
220: ELIF lastc=='<'
221: THEN savc=rdc();
222: IF (regptr=getreg(savc)) != NOREG
223: THEN expv=uar0[regptr];
224: ELIF (base=varchk(savc)) != -1
225: THEN expv=var[base];
226: ELSE error(BADVAR);
227: FI
228:
229: ELIF lastc=='\''
230: THEN d=4; expv=0;
231: WHILE quotchar()
232: DO IF d--
233: THEN IF d==1 THEN expv =<<16; FI
234: expv |= ((d&1)?lastc:lastc<<8);
235: ELSE error(BADSYN);
236: FI
237: OD
238:
239: ELIF a
240: THEN error(NOADR);
241: ELSE lp--; return(0);
242: FI
243: return(1);
244: }
245:
246: /* service routines for expression reading */
247:
248: readsym()
249: {
250: REG char *p;
251:
252: p = isymbol;
253: REP IF p < &isymbol[8]
254: THEN *p++ = lastc;
255: FI
256: readchar();
257: PER symchar(1) DONE
258: WHILE p < &isymbol[8] DO *p++ = 0; OD
259: }
260:
261: SYMPTR lookupsym(symstr)
262: STRING symstr;
263: {
264: SYMPTR symp;
265: symset();
266: WHILE (symp=symget())
267: DO IF (symp->symf&SYMCHK)==symp->symf
268: THEN IF overlay ANDF (symp->symf&SYMCHK)==ISYM ANDF
269: eqsym(symp->symc, symstr,'~')
270: THEN return(symp);
271: ELIF eqsym(symp->symc, symstr,'_')
272: THEN return(symp);
273: FI
274: FI
275: OD
276: return(0);
277: }
278:
279: hexdigit(c)
280: CHAR c;
281: { return((c>='0' ANDF c<='9') ORF (c>='a' ANDF c<='f'));
282: }
283:
284: convdig(c)
285: CHAR c;
286: {
287: IF digit(c)
288: THEN return(c-'0');
289: ELIF hexdigit(c)
290: THEN return(c-'a'+10);
291: ELSE return(17);
292: FI
293: }
294:
295: digit(c) char c; {return(c>='0' ANDF c<='9');}
296:
297: letter(c) char c; {return(c>='a' ANDF c<='z' ORF c>='A' ANDF c<='Z');}
298:
299: symchar(dig)
300: {
301: IF lastc=='\\' THEN readchar(); return(TRUE); FI
302: return( letter(lastc) ORF lastc=='_' ORF dig ANDF digit(lastc) );
303: }
304:
305: varchk(name)
306: {
307: IF digit(name) THEN return(name-'0'); FI
308: IF letter(name) THEN return((name&037)-1+10); FI
309: return(-1);
310: }
311:
312: chkloc(frame)
313: L_INT frame;
314: {
315: readsym();
316: REP IF localsym(frame)==0 THEN error(BADLOC); FI
317: expv=localval;
318: PER !eqsym(symbol.symc,isymbol,'~') DONE
319: }
320:
321: eqsym(s1, s2, c)
322: REG STRING s1, s2;
323: CHAR c;
324: {
325: IF eqstr(s1,s2)
326: THEN return(TRUE);
327: ELIF *s1==c
328: THEN CHAR s3[8];
329: REG INT i;
330:
331: s3[0]=c;
332: FOR i=1; i<8; i++
333: DO s3[i] = *s2++; OD
334:
335: return(eqstr(s1,s3));
336: FI
337: }
Defined functions
expr
defined in line
52; used 9 times
item
defined in line
127; used 1 times
term
defined in line
97; used 12 times
Defined variables