|
|
1.1 ! root 1: static char sccsid[] = "@(#)xeq.c 4.2 7/8/81"; ! 2: #include "head.h" ! 3: #include <a.out.h> ! 4: #include <stab.h> ! 5: struct user u; ! 6: #include <stdio.h> ! 7: INT signo; ! 8: INT adrflg; ! 9: INT pid; ! 10: ADDR userpc; ! 11: L_INT cntval; ! 12: ! 13: ! 14: /* service routines for sub process control */ ! 15: ! 16: ! 17: /* ! 18: * single step until loc with descriptor format d is modified ! 19: * return its new value. ! 20: */ ! 21: monex(loc, d) ! 22: ADDR loc; char d; { ! 23: register ADDR oldval; ! 24: ! 25: oldval = getval(loc, d, DSP); ! 26: do { ! 27: subpcs('s'); ! 28: } while (oldval == getval(loc, d, DSP)); ! 29: return(getval(loc, d, DSP)); ! 30: } ! 31: ! 32: /* single step count source stmts */ ! 33: singstep(count, cmd) ! 34: char cmd; { ! 35: register int thisline, curline; ! 36: register struct proct *thisproc; ! 37: ! 38: if (sdbttym.sg_flags != userttym.sg_flags) ! 39: stty(2, &userttym); ! 40: dot = *(ADDR *) (((ADDR) &u) + PC); ! 41: thisproc = adrtoprocp(dot); ! 42: thisline = adrtolineno(dot); ! 43: if (count == 0) count = 1; ! 44: for(; count; count--) { ! 45: do { ! 46: if (cmd == 'S') { /* MACHINE DEPENDENT */ ! 47: dot = *(ADDR *) (((ADDR) &u) + PC); ! 48: if ((get(dot,ISP) & 0xff) == 0xfb){ /* calls */ ! 49: int retaddr; ! 50: subpcs('s'); ! 51: retaddr = ! 52: *(ADDR *) (((ADDR) &u) + USP) + 16; ! 53: retaddr = dot = get(retaddr, DSP); ! 54: subpcs('b'); ! 55: subpcs('c'); ! 56: dot = retaddr; ! 57: subpcs('d'); ! 58: dot = *(ADDR *) (((ADDR) &u) + PC); ! 59: if (retaddr != dot && signo == 0) { ! 60: gtty(2, &userttym); ! 61: if (sdbttym.sg_flags != ! 62: userttym.sg_flags) ! 63: stty(2, &sdbttym); ! 64: printf("Breakpoint at \n"); ! 65: return; ! 66: } ! 67: continue; ! 68: } ! 69: } ! 70: ! 71: subpcs('s'); ! 72: dot = *(ADDR *) (((ADDR) &u) + PC); ! 73: curline = adrtolineno(dot); ! 74: } while (!signo && ! 75: ((thisproc == adrtoprocp(dot) && thisline == curline) || ! 76: curline == -1)); ! 77: gtty(2, &userttym); ! 78: if (sdbttym.sg_flags != userttym.sg_flags) ! 79: stty(2, &sdbttym); ! 80: if (signo) return; ! 81: } ! 82: } ! 83: ! 84: doscall() { ! 85: int subargs[NUMARGS]; ! 86: /* subargs[0] = address, ! 87: * subargs[1] = number of arguments ! 88: * subargs[2:NUMARGS] = actual arguments ! 89: */ ! 90: union { ! 91: int w[128-NUMARGS]; ! 92: char c[4*(128-NUMARGS)]; ! 93: }substr; ! 94: ! 95: register int i, numchars, *subargp; ! 96: register char ch; ! 97: ADDR straddr, adr, praddr; ! 98: ADDR j; ! 99: ! 100: praddr = extaddr(proc); ! 101: if (praddr == -1) { ! 102: printf("Cannot find %s\n", proc); ! 103: return; ! 104: } ! 105: straddr = extaddr("_dbargs"); ! 106: if (straddr == -1) { ! 107: error("Program not loaded with -lg"); ! 108: return; ! 109: } ! 110: ! 111: numchars = 0; ! 112: subargp = subargs; ! 113: argsp++; ! 114: *subargp++ = praddr; ! 115: subargp++; ! 116: ! 117: for (i=0; i<NUMARGS - 2; i++) { /* process an argument */ ! 118: ch = *argsp; ! 119: if (ch == '\'') { ! 120: *subargp++ = *(argsp+1); ! 121: argsp += 2; ! 122: } else if (ch == '"') { ! 123: *subargp++ = straddr + sizeof subargs + numchars; ! 124: argsp++; ! 125: for (;;) { ! 126: ch = *argsp++; ! 127: if (ch == '\\') { ! 128: switch(ch = *argsp++) { ! 129: case 'r': ! 130: ch = '\015'; ! 131: break; ! 132: case 'n': ! 133: ch = '\012'; ! 134: break; ! 135: case '\\': ! 136: ch = '\\'; ! 137: break; ! 138: } ! 139: } ! 140: substr.c[numchars++] = ch; ! 141: if (ch == '"') { ! 142: substr.c[numchars-1] = '\0'; ! 143: break; ! 144: } ! 145: if (ch == '\0') { ! 146: error("Unterminated string constant"); ! 147: return; ! 148: } ! 149: if (numchars > sizeof substr.c) { ! 150: error("Too many string constants"); ! 151: return; ! 152: } ! 153: } ! 154: } else if ((ch >= '0' && ch <= '9') || ch == '-') { ! 155: *subargp++ = readint(&argsp); ! 156: } else if ((ch >= 'a' && ch <= 'z') || ! 157: (ch >= 'A' && ch <= 'Z') || ch == '_') { ! 158: cpname(var, argsp); ! 159: j = varaddr(curproc()->pname, var); ! 160: if (j == -1) { ! 161: return; ! 162: } ! 163: *subargp++ = ! 164: sl_class == N_RSYM ? ! 165: *(ADDR *)(((ADDR) &u) + R0 + (WORDSIZE)*j) : ! 166: getval(j, typetodesc(sl_type, 0)[0], DSP); ! 167: do { ! 168: argsp++; ! 169: } while (varchar(*argsp) || number(*argsp)); ! 170: } else if (ch != ')') { ! 171: printf("Unexpected character %c\n", ch); ! 172: return; ! 173: } ! 174: ! 175: do { ! 176: ch = *argsp++; ! 177: } while(ch == ' '); ! 178: if (ch == ')') { ! 179: if (scallx == 0) { ! 180: scallx = 1; ! 181: pcs = *(ADDR *)(((ADDR)&u)+PC); ! 182: fps = *(ADDR *)(((ADDR)&u)+FP); ! 183: aps = *(ADDR *)(((ADDR)&u)+AP); ! 184: if (bkpts = scanbkpt(userpc)) { ! 185: if (flagss = bkpts->flag) { ! 186: bkpts->flag = BKPTSET; ! 187: } ! 188: } ! 189: } ! 190: dot = *(ADDR *)(((ADDR)&u)+PC) = extaddr("_dbsubc"); ! 191: if (dot == -1) { ! 192: error("Internal error - cannot find _dbsubc"); ! 193: return; ! 194: } ! 195: adrflg = 1; ! 196: cntval = 1; ! 197: if (pid == 0 || signo) subpcs('r'); ! 198: subargs[1] = (subargp - subargs) - 2; ! 199: adr = straddr; ! 200: for (j=0; j<=(subargp-subargs); j++) { ! 201: put(adr, DSP, subargs[j]); ! 202: adr += WORDSIZE; ! 203: } ! 204: adr = straddr + sizeof subargs; ! 205: for (j=0; j<(numchars+WORDSIZE-1)/WORDSIZE; j++) { ! 206: put(adr, DSP, substr.w[j]); ! 207: adr += WORDSIZE; ! 208: } ! 209: dschar = *argsp++; ! 210: errflg = 0; ! 211: dopcs('c'); ! 212: if (!signo) printf("Breakpoint"); ! 213: printf(" at\n"); ! 214: return; ! 215: } ! 216: while (*argsp == ' ' || *argsp == ',') ! 217: argsp++; ! 218: } ! 219: ! 220: error ("Too many arguments"); ! 221: ! 222: } ! 223: ! 224: ! 225: /* get arguments from core file, place them in args */ ! 226: getargs() { ! 227: struct proct *procp; ! 228: ADDR p, av; ! 229: int ac, i; ! 230: char *argsp = args; ! 231: union { ! 232: char c[WORDSIZE]; ! 233: int w; ! 234: float f; ! 235: } word; ! 236: ! 237: if ((procp = initframe()) == badproc) goto old1; ! 238: do { ! 239: if (eqstr("main", procp->pname)) ! 240: goto fnd; ! 241: } while ((procp = nextframe()) != badproc); ! 242: ! 243: old1: ! 244: errflg = 0; /* hack */ ! 245: cpstr(args, oldargs); ! 246: printf("%s %s\n", symfil, args); ! 247: return; ! 248: ! 249: fnd: ac = get(argp, DSP); ! 250: if ((ac == 0) || (ac & 0xff)) goto old1; ! 251: ac = get(argp+4, DSP); ! 252: av = (ADDR) get(argp+8, DSP); ! 253: ! 254: av += WORDSIZE; ! 255: ac--; ! 256: ! 257: for (; ac; ac--) { ! 258: p = (ADDR) get(av, DSP); ! 259: av += WORDSIZE; ! 260: for (;;) { ! 261: word.w = get(p, DSP); ! 262: for (i=0; i<WORDSIZE; i++) { ! 263: if (word.c[i] == '\0') goto l1; ! 264: *argsp++ = word.c[i]; ! 265: } ! 266: p += WORDSIZE; ! 267: } ! 268: l1: *argsp++ = ' '; ! 269: } ! 270: *argsp == '\0'; ! 271: printf("%s %s\n", symfil, args); ! 272: return; ! 273: ! 274: ! 275: } ! 276: ! 277: dopcs(c) ! 278: char c; { ! 279: if (c != 'r' && c != 'R' && sdbttym.sg_flags != userttym.sg_flags) ! 280: stty(2, &userttym); ! 281: subpcs(c); ! 282: gtty(2, &userttym); ! 283: if (sdbttym.sg_flags != userttym.sg_flags) ! 284: stty(2, &sdbttym); ! 285: ! 286: if (eqany(c, "cCsS") && ! 287: *(ADDR *)(((ADDR)&u)+PC) == extaddr("_dbsubn")) { ! 288: if (dschar == '/') { ! 289: dispf((ADDR) 0, *argsp ? argsp : "d", N_RSYM, 0, 0, DSP); ! 290: } ! 291: else ! 292: printf("Procedure returned normally\n"); ! 293: userpc = dot = *(ADDR *)(((ADDR)&u)+PC) = pcs; ! 294: *(ADDR *)(((ADDR)&u)+FP) = fps; ! 295: *(ADDR *)(((ADDR)&u)+AP) = aps; ! 296: if (bkpts) ! 297: bkpts->flag = flagss; ! 298: scallx = 0; ! 299: longjmp(env, 0); ! 300: } ! 301: } ! 302: ! 303: /* execute commands from a breakpoint */ ! 304: acommand(cmds) ! 305: char *cmds; { ! 306: char *p = cmds; ! 307: int endflg = 0; ! 308: ! 309: setcur(0); ! 310: do { /* process a command */ ! 311: for (;;) { ! 312: if (*p == ';') { ! 313: *p = '\n'; ! 314: break; ! 315: } ! 316: if (*p == '\n') { ! 317: endflg++; ! 318: break; ! 319: } ! 320: p++; ! 321: } ! 322: if (decode(cmds) == 1) { ! 323: printf("Bad command: "); ! 324: do { ! 325: printf("%c", *cmds); ! 326: } while (*cmds++ != '\n'); ! 327: return; ! 328: } ! 329: docommand(); ! 330: if (!endflg) ! 331: *p = ';'; ! 332: p = cmds = p + 1; ! 333: } while (!endflg); ! 334: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.