|
|
1.1 ! root 1: /* $Header: /src386/bin/db/RCS/trace4.c,v 1.2 93/03/11 07:46:10 bin Exp Locker: bin $ ! 2: * ! 3: * The information contained herein is a trade secret of Mark Williams ! 4: * Company, and is confidential information. It is provided under a ! 5: * license agreement, and may be copied or disclosed only under the ! 6: * terms of that agreement. Any reproduction or disclosure of this ! 7: * material without the express written authorization of Mark Williams ! 8: * Company or persuant to the license agreement is unlawful. ! 9: * ! 10: * COHERENT Version 2.3.35 ! 11: * Copyright (c) 1982, 1983, 1984. ! 12: * An unpublished work by Mark Williams Company, Chicago. ! 13: * All rights reserved. ! 14: * ! 15: * Command analyser. ! 16: */ ! 17: ! 18: #include <stdio.h> ! 19: #include <l.out.h> ! 20: #include "trace.h" ! 21: ! 22: /* ! 23: * Execute a command. ! 24: * Return true if more commands may be read. ! 25: */ ! 26: command(vp) ! 27: register VAL *vp; ! 28: { ! 29: register int c; ! 30: register int n; ! 31: ! 32: switch (c=getn()) { ! 33: case '=': ! 34: if (newline() == 0) ! 35: break; ! 36: printx("%lo\n", rvalue(vp, (long)dot)); ! 37: return 1; ! 38: case '?': ! 39: if (newline() == 0) ! 40: break; ! 41: if (errrstr != NULL) ! 42: printx("%s\n", errrstr); ! 43: return 1; ! 44: case 'a': ! 45: if (newline() == 0) ! 46: break; ! 47: putaddr(vsegno(vp, -1), lvalue(vp, (long)dot), I); ! 48: putx('\n'); ! 49: return 1; ! 50: case 'b': ! 51: if (objflag == 0) ! 52: break; ! 53: if ((c=getn()) != 'r') { ! 54: ungetn(c); ! 55: c = 'b'; ! 56: } ! 57: getline("i+.:a\ni+.?i\n:x"); ! 58: n = setubpt(c, (caddr_t)lvalue(vp, (long)dot), miscbuf); ! 59: if (n == 0) ! 60: printe("Cannot set breakpoint"); ! 61: return 1; ! 62: case 'c': ! 63: if (newline() == 0) ! 64: break; ! 65: else ! 66: c = '\n'; ! 67: if (excflag == 0) ! 68: break; ! 69: if (nvalue(vp) == 0) ! 70: setpc((caddr_t)lvalue(vp, (long)0)); ! 71: sinmode = SNULL; ! 72: return 0; ! 73: case 'd': ! 74: if (objflag == 0) ! 75: break; ! 76: if ((c=getn())!='r' && c!='s') { ! 77: ungetn(c); ! 78: c = 'b'; ! 79: } ! 80: if (newline() == 0) ! 81: break; ! 82: if (delubpt(c, (caddr_t)lvalue(vp, (long)dot)) == 0) ! 83: printe("Cannot delete breakpoint"); ! 84: return 1; ! 85: case 'e': ! 86: if (nvalue(vp) == 0) { ! 87: setpc((caddr_t)lvalue(vp, (long)0)); ! 88: } ! 89: getline(""); ! 90: return(runfile()); ! 91: case 'f': ! 92: if (newline() == 0) ! 93: break; ! 94: printx("%s\n", trapstr!=NULL ? trapstr : "No fault"); ! 95: return 1; ! 96: case 'k': ! 97: if (excflag == 0) ! 98: break; ! 99: if (newline() == 0) ! 100: break; ! 101: if (nvalue(vp) != 0) { ! 102: printe("No signal specified"); ! 103: return 1; ! 104: } ! 105: printr("Cannot send %d", (int)rvalue(vp, (long)0)); ! 106: return 1; ! 107: case 'm': ! 108: if (newline() == 0) ! 109: break; ! 110: dispmap(); ! 111: return 1; ! 112: case 'o': ! 113: if (newline() == 0) ! 114: break; ! 115: cantype = rvalue(vp, (long)0); ! 116: return 1; ! 117: case 'p': ! 118: if (newline() == 0) ! 119: break; ! 120: dispbpt(); ! 121: return 1; ! 122: case 'q': ! 123: if (newline() == 0) ! 124: break; ! 125: if (rvalue(vp, (long)1)) ! 126: leave(); ! 127: return 1; ! 128: case 'r': ! 129: if (newline() == 0) ! 130: break; ! 131: else ! 132: c = '\n'; ! 133: if (regflag == 0) ! 134: break; ! 135: dispreg(); ! 136: return 1; ! 137: case 's': ! 138: if (excflag == 0) ! 139: break; ! 140: if (nvalue(vp) == 0) ! 141: setpc((caddr_t)lvalue(vp, (long)0)); ! 142: sindecr = rvalue(&vp[1], (long)1); ! 143: sinmode = SCONT; ! 144: if ((c=getn()) != 'c') { ! 145: sinmode = SSTEP; ! 146: ungetn(c); ! 147: } ! 148: getline("i+.?i"); ! 149: sinp = savecom(sinp, miscbuf); ! 150: return 0; ! 151: case 't': ! 152: if (newline() == 0) ! 153: break; ! 154: else ! 155: c = '\n'; ! 156: if (regflag == 0) ! 157: break; ! 158: dispsbt((int)rvalue(vp, (long)0)); ! 159: return 1; ! 160: case 'x': ! 161: if (newline() == 0) ! 162: break; ! 163: if (rvalue(vp, (long)1)) { ! 164: sincmod = sinmode; ! 165: sinmode = SNULL; ! 166: addfilp(stdin); ! 167: } ! 168: return 1; ! 169: } ! 170: printe("Illegal command"); ! 171: while (c != '\n') ! 172: c = getn(); ! 173: return 1; ! 174: } ! 175: ! 176: /* ! 177: * If the next character is a newline, return 1, else 0. ! 178: */ ! 179: newline() ! 180: { ! 181: return (getn()=='\n'); ! 182: } ! 183: ! 184: /* ! 185: * Given a pointer to an allocated buffer and a pointer to a ! 186: * command string, copy the command string in the allocated ! 187: * buffer. If the allocated buffer hasn't been allocated, ! 188: * allocate it. ! 189: */ ! 190: savecom(bp, sp) ! 191: register char *bp; ! 192: register char *sp; ! 193: { ! 194: register char *cp; ! 195: ! 196: if (bp == NULL) ! 197: bp = nalloc(COMSIZE); ! 198: cp = bp; ! 199: while (*sp) { ! 200: if (cp >= &bp[COMSIZE-1]) ! 201: break; ! 202: *cp++ = *sp++; ! 203: } ! 204: *cp++ = '\0'; ! 205: return (bp); ! 206: } ! 207: ! 208: /* ! 209: * Initialize breakpoint table. ! 210: */ ! 211: bptinit() ! 212: { ! 213: register BPT *bp; ! 214: register int n; ! 215: ! 216: for (n=NBPT, bp=bpt; --n; bp++) { ! 217: bp->b_flag = 0; ! 218: bp->b_bcom = NULL; ! 219: bp->b_rcom = NULL; ! 220: } ! 221: } ! 222: ! 223: /* ! 224: * Set a breakpoint (user callable). If the type is 'b', a regular ! 225: * breakpoint. If it is 'r', a return breakpoint. ! 226: */ ! 227: setubpt(t, a, cp) ! 228: caddr_t a; ! 229: char *cp; ! 230: { ! 231: register unsigned n; ! 232: caddr_t pc; ! 233: caddr_t fp; ! 234: ! 235: if (t == 'b') ! 236: n = setibpt(BBPT, a, (caddr_t)0, cp); ! 237: else { ! 238: setretf(&pc, &fp); ! 239: n = setibpt(BRET, pc, fp, cp); ! 240: } ! 241: return (n); ! 242: } ! 243: ! 244: /* ! 245: * Set a breakpoint (internal routine). ! 246: */ ! 247: setibpt(f, a, fp, cp) ! 248: caddr_t a; ! 249: caddr_t fp; ! 250: char *cp; ! 251: { ! 252: register BPT *bp; ! 253: register int n; ! 254: int w; ! 255: ! 256: /* make sure "a" is a valid text address (value fetched is ignored) */ ! 257: add = (long)a; ! 258: if(getb(ISEG, &w, sizeof(w)) == 0) ! 259: return 0; ! 260: ! 261: /* look for existing breakpoint at same address */ ! 262: for (n=NBPT, bp=&bpt[0]; --n; bp++) { ! 263: if (bp->b_flag && bp->b_badd==a) ! 264: goto out; ! 265: } ! 266: ! 267: /* look for unused breakpoint */ ! 268: for (n=NBPT, bp=&bpt[0]; --n; bp++) { ! 269: if (bp->b_flag == 0) ! 270: goto out; ! 271: } ! 272: ! 273: return 0; ! 274: out: ! 275: if (f!=BBPT && (bp->b_flag&f)!=0) ! 276: return 0; ! 277: bp->b_flag |= f; ! 278: bp->b_badd = a; ! 279: switch (f) { ! 280: case BBPT: ! 281: bp->b_bcom = savecom(bp->b_bcom, cp); ! 282: break; ! 283: case BRET: ! 284: fprintf(stderr, "case BRET\n"); ! 285: bp->b_rfpt = fp; ! 286: bp->b_rcom = savecom(bp->b_rcom, cp); ! 287: break; ! 288: case BSIN: ! 289: bp->b_sfpt = fp; ! 290: break; ! 291: } ! 292: return 1; ! 293: } ! 294: ! 295: /* ! 296: * Delete a breakpoint. (user callable) ! 297: * If `r' is set, it is a return breakpoint. ! 298: */ ! 299: delubpt(t, a) ! 300: caddr_t a; ! 301: { ! 302: register int f; ! 303: ! 304: switch (t) { ! 305: case 'b': ! 306: f = BBPT; ! 307: break; ! 308: case 'r': ! 309: f = BRET; ! 310: break; ! 311: case 's': ! 312: f = BSIN; ! 313: break; ! 314: } ! 315: return (delibpt(f, a)); ! 316: } ! 317: ! 318: /* ! 319: * Delete a breakpoint. (internal routine) ! 320: */ ! 321: delibpt(f, a) ! 322: register int f; ! 323: caddr_t a; ! 324: { ! 325: register BPT *bp; ! 326: register int n; ! 327: ! 328: for (n=NBPT, bp=&bpt[0]; --n; bp++) { ! 329: if ((bp->b_flag&f)==0 || bp->b_badd!=a) ! 330: continue; ! 331: bp->b_flag &= ~f; ! 332: return 1; ! 333: } ! 334: return 0; ! 335: } ! 336: ! 337: /* ! 338: * Display breakpoints. ! 339: */ ! 340: dispbpt() ! 341: { ! 342: register BPT *bp; ! 343: register int n; ! 344: ! 345: for (n=NBPT, bp=&bpt[0]; --n; bp++) { ! 346: if (testint()) ! 347: return; ! 348: if ((bp->b_flag&BBPT) != 0) ! 349: putlbpt(' ', bp->b_badd, bp->b_bcom); ! 350: if (testint()) ! 351: return; ! 352: if ((bp->b_flag&BRET) != 0) ! 353: putlbpt('r', bp->b_badd, bp->b_rcom); ! 354: if (testint()) ! 355: return; ! 356: if ((bp->b_flag&BSIN) != 0) ! 357: putlbpt('s', bp->b_badd, ""); ! 358: } ! 359: } ! 360: ! 361: /* ! 362: * Print out a breakpoint address, type and command. ! 363: */ ! 364: putlbpt(t, a, cp) ! 365: caddr_t a; ! 366: register char *cp; ! 367: { ! 368: register int c; ! 369: ! 370: printx(DAFMT, (long)a); ! 371: printx("%c (", t); ! 372: putaddr(1, (long)a, I); ! 373: printx(") "); ! 374: while ((c=*cp++) != '\0') { ! 375: if (c == '\n') { ! 376: printx("\\n"); ! 377: continue; ! 378: } ! 379: if (c == '\\') { ! 380: printx("\\\\"); ! 381: continue; ! 382: } ! 383: putx(c); ! 384: } ! 385: putx('\n'); ! 386: } ! 387: ! 388: /* ! 389: * Print out segmentation map. ! 390: */ ! 391: dispmap() ! 392: { ! 393: register MAP *mp; ! 394: register int n; ! 395: ! 396: for (n=0; n<NSEGM; n++) { ! 397: if ((mp=segmapl[n]) == NULL) ! 398: continue; ! 399: printx("%s", segname[n]); ! 400: while (n<NSEGM-1 && segmapl[n+1]==mp) ! 401: printx(" == %s", segname[++n]); ! 402: printx("\n"); ! 403: for (; mp!=NULL; mp=mp->m_next) { ! 404: printx("["); ! 405: putmadd(mp->m_base); ! 406: printx(", "); ! 407: putmadd(mp->m_bend); ! 408: printx("] => "); ! 409: putmadd(mp->m_offt); ! 410: printx(" (%d)\n", mp->m_segi); ! 411: if (testint()) ! 412: return; ! 413: } ! 414: } ! 415: } ! 416: ! 417: /* ! 418: * Print out a long address for segmentation map. ! 419: */ ! 420: putmadd(l) ! 421: off_t l; ! 422: { ! 423: register int c, n; ! 424: ! 425: if (l!=MLI && l!=LI) { ! 426: printx(VAFMT, l); ! 427: return; ! 428: } ! 429: c = l==MLI ? '-' : '+'; ! 430: n = VAWID; ! 431: while (n--) ! 432: putchar(c); ! 433: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.