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