|
|
1.1 root 1: static char sccsid[] = "@(#)bp.c 2.6";
2:
3: #include <ctype.h>
4: #include "cdb.h"
5:
6:
7: #ifdef M68000
8: #define cbBp 2 /* size of a breakpoint */
9: #ifdef SUN
10: short vinsBp = 0x4e4f; /* a 'trap #15' instruction */
11: #else
12: short vinsBp = 0x4e41; /* the breakpoint instruction */
13: #endif
14: #endif
15:
16: #ifdef ONYX
17: #define cbBp 2 /* size of a breakpoint */
18: int vinsBp = 0x7fff; /* the breakpoint instruction */
19: #endif
20:
21: #ifdef TAHOE
22: #define cbBp 1 /* size of BPT instruction */
23: int vinsBp = 0x30; /* a BPT instruction */
24: #endif
25:
26: #ifdef VAX
27: #define cbBp 1 /* size of BPT instruction */
28: int vinsBp = 03; /* a BPT instruction */
29: #endif
30:
31: export int vibpMac, vibpMax;
32: export int vibpTemp; /* always 0, used for temp BP execution */
33: export pBPR vrgBp; /* allocated in InitAll */
34:
35: #ifdef REGULUS
36: local void CopyBp(bp1, bp2)
37: pBPR bp1, bp2;
38: {
39: bp1->adr = bp2->adr;
40: bp1->count = bp2->count;
41: bp1->inst = bp2->inst;
42: strncpy(bp1->sbBp, bp2->sbBp, 100);
43: } /* CopyBp */
44: #endif
45:
46: /* L I S T B P */
47:
48: export void ListBp()
49: {
50: int ibp;
51:
52: for (ibp=vibpTemp+1; ibp< vibpMac; ibp++) {
53: printf("%2d ", ibp);
54: PrintPos(vrgBp[ibp].adr, fmtProc+fmtLn+fmtSave);
55: printf(" count: %d", vrgBp[ibp].count);
56: /* for debugging purposes
57: printf(" addr: %d", vrgBp[ibp].adr);
58: printf(" inst: %d", vrgBp[ibp].inst);
59: */
60: if (vrgBp[ibp].count <= 0)
61: printf(" (temp)");
62: if (vrgBp[ibp].sbBp[0] != chNull)
63: printf(" <%s>", vrgBp[ibp].sbBp);
64: printf("\n");
65: } /* for */
66: } /* ListBp */
67:
68:
69: /* F C L E A R B P */
70:
71: export FLAGT FClearBp(adr)
72: ADRT adr;
73: {
74: int ibp;
75:
76: for (ibp=vibpTemp+1; ibp<vibpMac; ibp++) {
77: if (vrgBp[ibp].adr == adr) {
78: #ifdef REGULUS
79: CopyBp(vrgBp+ibp, vrgBp+(vibpMac-1));
80: #else
81: vrgBp[ibp] = vrgBp[vibpMac-1];
82: #endif
83: vibpMac--;
84: return(true);
85: } /* if */
86: } /* for */
87: return(false);
88: } /* FClearBp */
89:
90:
91: /* C L E A R A L L */
92:
93: export void ClearAll()
94: {
95: vibpMac = 1; /* we allow for the temp in 0 */
96: printf("All breakpoints deleted\n");
97: } /* ClearAll */
98:
99:
100: /* I B P F B R K I N */
101:
102: export int IbpFBrkIn(pc)
103: ADRT pc;
104: {
105: int i;
106:
107: for (i=vibpTemp+1; i < vibpMac; i++) {
108: if (vrgBp[i].adr == pc)
109: return(i); /* don't install anything if we are on a break */
110: } /* for */
111:
112: for (i=vibpTemp+1; i < vibpMac; i++) {
113: GetBlock(vrgBp[i].adr, spaceText, (ADRT)&(vrgBp[i].inst), cbBp);
114: #ifdef TAHOE
115: PutBlock(vrgBp[i].adr, spaceText, ((char *)&vinsBp)+3, cbBp);
116: #else
117: PutBlock(vrgBp[i].adr, spaceText, (ADRT)&vinsBp, cbBp);
118: #endif
119: } /* for */
120: return(ibpNil);
121: } /* IbpFBrkIn */
122:
123:
124: /* B R K O U T */
125:
126: export int BrkOut(padr)
127: ADRT *padr;
128: {
129: int ibp, i;
130: #ifdef M68000
131: ushort val;
132: #else
133: uint val;
134: #endif
135: pBPR bp;
136: ADRT adr;
137:
138: adr = *padr;
139: #ifndef BSD41
140: /* vax backs up pc for us */
141: GetBlock(adr-cbBp, spaceText, (ADRT)&val, cbBp);
142: if (val == vinsBp) /* back up, if we are at a breakpoint */
143: *padr = adr -= cbBp;
144: #endif
145:
146: /* we now restore original instructions for all active bp's */
147: ibp = ibpNil;
148: for (i=vibpTemp+1; i < vibpMac; i++) {
149: bp = vrgBp + i;
150: PutBlock(bp->adr, spaceText, (ADRT)&(bp->inst), cbBp);
151: /* put back the real instruction */
152: if (bp->count == 0) { /* it was set by single-step */
153: FClearBp(vrgBp[i].adr);
154: i--; /* FClearBp shuffles things, back up one */
155: }
156: else if (bp->adr == adr) {
157: /* this is THE break that we hit, adjust its count */
158: ibp = ibpContinue; /* ignore break, will change if appropriate */
159: if (bp->count < 0) {
160: /* it's a temp break */
161: if ((bp->count += 1) == 0) {
162: #ifdef REGULUS
163: CopyBp(vrgBp+vibpTemp, bp);
164: #else
165: vrgBp[vibpTemp] = *bp; /* transfer into the holding slot */
166: #endif
167: ibp = vibpTemp;
168: FClearBp(vrgBp[i].adr);
169: i--; /* FClearBp shuffles things, back up one */
170: } /* if */
171: }
172: else {
173: /* it's a permanent break, deal with it */
174: if ((bp->count -= 1) <= 0) {
175: bp->count = 1; /* we refresh it if it goes 0 */
176: ibp = i;
177: } /* if */
178: } /* if */
179: } /* if */
180: } /* if */
181: return(ibp);
182: } /* BrkOut */
183:
184:
185: /* I B P F A D R */
186:
187: export int IbpFAdr(adr, count, sbCmd)
188: ADRT adr;
189: int count;
190: char *sbCmd;
191: {
192: int ibp;
193:
194: /* see if we already have this one - if so, reuse the slot */
195: for (ibp=vibpTemp+1; ibp<vibpMac; ibp++) {
196: if (vrgBp[ibp].adr == adr) {
197: if (count == 0)
198: return(ibp); /* there's already a PERMANENT one there */
199: else break;
200: } /* if */
201: } /* for */
202:
203: if (ibp == vibpMac) {
204: if (vibpMac >= vibpMax)
205: UError("Ran out of breakpoints");
206: vibpMac++;
207: } /* if */
208:
209: vrgBp[ibp].adr = adr;
210: vrgBp[ibp].count = count;
211: if (sbCmd == sbNil) {
212: vrgBp[ibp].sbBp[0] = chNull;
213: }
214: else {
215: strcpy(vrgBp[ibp].sbBp, sbCmd);
216: } /* if */
217: return(ibp);
218: } /* IbpFAdr */
219:
220:
221: /* I B P F S E T */
222:
223: export int IbpFSet(chStyle, cnt, sbCmd)
224: char chStyle;
225: int cnt;
226: char *sbCmd;
227: {
228: int ipd, ibp, ipdSave, ilnSave, ifdSave, cb;
229: char *sbSave, sbTok[50];
230: FLAGT fTemp;
231: ADRT pc, fp, ap;
232: TKE tk;
233:
234: ipd = ipdSave = vipd;
235: ifdSave = vifd;
236: ilnSave = viln;
237:
238: if (isupper(chStyle)) {
239: fTemp = true; /* upper gives a one shot breakpoint */
240: chStyle = tolower(chStyle);
241: }
242: else {
243: fTemp = false;
244: } /* if */
245:
246: fp = vfp;
247: ap = vap;
248: pc = vpc;
249: if (cnt >= 0) {
250: /* they want to do this stack relative */
251: while ((cnt > 0) AND fp) {
252: NextFrame(&fp, &ap, &pc);
253: --cnt;
254: }
255: if (fp == 0)
256: UError("Stack isn't that deep!");
257: } /* if */
258:
259: switch (chStyle) {
260: default:
261: UError("Unknown breakpoint type `%c'", chStyle);
262: case 't': /* trace breakpoint */
263: if (cnt >= 0) {
264: if ((ipd = IpdFAdr(pc)) == ipdNil)
265: UError("No symbols for that procedure");
266: vipd = ipd;
267: }
268: else {
269: sbSave = sbCmd; /* in case we want to undo next line */
270: tk = TkFStr(&sbCmd, sbTok, &cb); /* look at first item */
271: if ( (tk == tkStr)
272: AND ((ipd = IpdFName(sbTok)) != ipdNil) ) {
273: vipd = ipd;
274: }
275: else {
276: /* restore string */
277: sbCmd = sbSave;
278: } /* if */
279: } /* if */
280: /* set break at exit */
281: ibp = IbpFSet( ((fTemp) ? 'X':'x'), -1, "Q;$result/d;c");
282: /* set break at entrance */
283: if ((sbCmd == sbNil) OR (*sbCmd == chNull))
284: sbCmd = "Q;2t;c"; /* print caller and continue on entry */
285: ibp = IbpFSet( ((fTemp) ? 'B':'b'), -1, sbCmd);
286: printf("Tracing %s\n", vrgPd[vipd].sbProc);
287: ibp = ibpNil; /* a signal to caller not to print anything */
288: pc = adrNil;
289: break;
290: case 'b':
291: if (cnt >= 0) {
292: if ((ipd = IpdFAdr(pc)) == ipdNil)
293: UError("No symbols for that procedure");
294: }
295: else {
296: ipd = vipd;
297: } /* if */
298: OpenIpd(ipd, true); /* force it open */
299: pc = AdrFIfdLn(vifd, viln);
300: break;
301: case 'x':
302: if (cnt >= 0) {
303: if ((ipd = IpdFAdr(pc)) == ipdNil)
304: UError("No symbols for that procedure");
305: }
306: else {
307: ipd = vipd;
308: } /* if */
309: pc = AdrFEndOfProc(ipd);
310: break;
311: case 'u':
312: /* move past instruction which fixes the stack pointer */
313: pc = AdrFStackFix(pc);
314: break;
315: } /* switch */
316:
317: if (pc != adrNil)
318: ibp = IbpFAdr(pc, (fTemp) ? -1 : 1, sbCmd);
319: vipd = ipdSave;
320: vifd = ifdSave;
321: viln = ilnSave;
322: return(ibp);
323: } /* IbpFSet */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.