|
|
1.1 ! root 1: static char sccsid[] = "@(#)print.c 4.7 8/14/83"; ! 2: /* ! 3: * ! 4: * UNIX debugger ! 5: * ! 6: */ ! 7: #include "defs.h" ! 8: ! 9: MSG LONGFIL; ! 10: MSG NOTOPEN; ! 11: MSG A68BAD; ! 12: MSG A68LNK; ! 13: MSG BADMOD; ! 14: ! 15: MAP txtmap; ! 16: MAP datmap; ! 17: ! 18: ADDR lastframe; ! 19: ADDR callpc; ! 20: ! 21: INT infile; ! 22: INT outfile; ! 23: CHAR *lp; ! 24: L_INT maxoff; ! 25: L_INT maxpos; ! 26: INT radix; ! 27: ! 28: /* symbol management */ ! 29: L_INT localval; ! 30: ! 31: /* breakpoints */ ! 32: BKPTR bkpthead; ! 33: ! 34: REGLIST reglist [] = { ! 35: "p1lr", P1LR, &pcb.pcb_p1lr, ! 36: "p1br", P1BR, &pcb.pcb_p1br, ! 37: "p0lr", P0LR, &pcb.pcb_p0lr, ! 38: "p0br", P0BR, &pcb.pcb_p0br, ! 39: "ksp", KSP, &pcb.pcb_ksp, ! 40: "esp", ESP, &pcb.pcb_esp, ! 41: "ssp", SSP, &pcb.pcb_ssp, ! 42: "psl", PSL, &pcb.pcb_psl, ! 43: "pc", PC, &pcb.pcb_pc, ! 44: "usp", USP, &pcb.pcb_usp, ! 45: "fp", FP, &pcb.pcb_fp, ! 46: "ap", AP, &pcb.pcb_ap, ! 47: "r11", R11, &pcb.pcb_r11, ! 48: "r10", R10, &pcb.pcb_r10, ! 49: "r9", R9, &pcb.pcb_r9, ! 50: "r8", R8, &pcb.pcb_r8, ! 51: "r7", R7, &pcb.pcb_r7, ! 52: "r6", R6, &pcb.pcb_r6, ! 53: "r5", R5, &pcb.pcb_r5, ! 54: "r4", R4, &pcb.pcb_r4, ! 55: "r3", R3, &pcb.pcb_r3, ! 56: "r2", R2, &pcb.pcb_r2, ! 57: "r1", R1, &pcb.pcb_r1, ! 58: "r0", R0, &pcb.pcb_r0, ! 59: }; ! 60: ! 61: char lastc; ! 62: ! 63: INT fcor; ! 64: STRING errflg; ! 65: INT signo; ! 66: INT sigcode; ! 67: ! 68: ! 69: L_INT dot; ! 70: L_INT var[]; ! 71: STRING symfil; ! 72: STRING corfil; ! 73: INT pid; ! 74: L_INT adrval; ! 75: INT adrflg; ! 76: L_INT cntval; ! 77: INT cntflg; ! 78: ! 79: STRING signals[] = { ! 80: "", ! 81: "hangup", ! 82: "interrupt", ! 83: "quit", ! 84: "illegal instruction", ! 85: "trace/BPT", ! 86: "IOT", ! 87: "EMT", ! 88: "floating exception", ! 89: "killed", ! 90: "bus error", ! 91: "memory fault", ! 92: "bad system call", ! 93: "broken pipe", ! 94: "alarm call", ! 95: "terminated", ! 96: "signal 16", ! 97: "stop (signal)", ! 98: "stop (tty)", ! 99: "continue (signal)", ! 100: "child termination", ! 101: "stop (tty input)", ! 102: "stop (tty output)", ! 103: "input available (signal)", ! 104: "cpu timelimit", ! 105: "file sizelimit", ! 106: "signal 26", ! 107: "signal 27", ! 108: "signal 28", ! 109: "signal 29", ! 110: "signal 30", ! 111: "signal 31", ! 112: }; ! 113: ! 114: /* general printing routines ($) */ ! 115: ! 116: printtrace(modif) ! 117: { ! 118: INT narg, i, stat, name, limit; ! 119: POS dynam; ! 120: REG BKPTR bkptr; ! 121: CHAR hi, lo; ! 122: ADDR word; ! 123: STRING comptr; ! 124: ADDR argp, frame, link; ! 125: register struct nlist *sp; ! 126: INT stack; ! 127: INT ntramp; ! 128: ! 129: IF cntflg==0 THEN cntval = -1; FI ! 130: ! 131: switch (modif) { ! 132: ! 133: case '<': ! 134: IF cntval == 0 ! 135: THEN WHILE readchar() != EOR ! 136: DO OD ! 137: lp--; ! 138: break; ! 139: FI ! 140: IF rdc() == '<' ! 141: THEN stack = 1; ! 142: ELSE stack = 0; lp--; ! 143: FI ! 144: /* fall through */ ! 145: case '>': ! 146: {CHAR file[64]; ! 147: CHAR Ifile[128]; ! 148: extern CHAR *Ipath; ! 149: INT index; ! 150: ! 151: index=0; ! 152: IF rdc()!=EOR ! 153: THEN REP file[index++]=lastc; ! 154: IF index>=63 THEN error(LONGFIL); FI ! 155: PER readchar()!=EOR DONE ! 156: file[index]=0; ! 157: IF modif=='<' ! 158: THEN IF Ipath THEN ! 159: strcpy(Ifile, Ipath); ! 160: strcat(Ifile, "/"); ! 161: strcat(Ifile, file); ! 162: FI ! 163: IF strcmp(file, "-")!=0 ! 164: THEN iclose(stack, 0); ! 165: infile=open(file,0); ! 166: IF infile<0 ! 167: THEN infile=open(Ifile,0); ! 168: FI ! 169: ELSE lseek(infile, 0L, 0); ! 170: FI ! 171: IF infile<0 ! 172: THEN infile=0; error(NOTOPEN); ! 173: ELSE IF cntflg ! 174: THEN var[9] = cntval; ! 175: ELSE var[9] = 1; ! 176: FI ! 177: FI ! 178: ELSE oclose(); ! 179: outfile=open(file,1); ! 180: IF outfile<0 ! 181: THEN outfile=creat(file,0644); ! 182: #ifndef EDDT ! 183: ELSE lseek(outfile,0L,2); ! 184: #endif ! 185: FI ! 186: FI ! 187: ! 188: ELSE IF modif == '<' ! 189: THEN iclose(-1, 0); ! 190: ELSE oclose(); ! 191: FI ! 192: FI ! 193: lp--; ! 194: } ! 195: break; ! 196: ! 197: case 'p': ! 198: IF kernel == 0 THEN ! 199: printf("not debugging kernel\n"); ! 200: ELSE ! 201: IF adrflg THEN ! 202: int pte = access(RD, dot, DSP, 0); ! 203: masterpcbb = (pte&PG_PFNUM)*512; ! 204: FI ! 205: getpcb(); ! 206: FI ! 207: break; ! 208: ! 209: case 'd': ! 210: if (adrflg) { ! 211: if (adrval<2 || adrval>16) {printf("must have 2 <= radix <= 16"); break;} ! 212: printf("radix=%d base ten",radix=adrval); ! 213: } ! 214: break; ! 215: ! 216: case 'q': case 'Q': case '%': ! 217: done(); ! 218: ! 219: case 'w': case 'W': ! 220: maxpos=(adrflg?adrval:MAXPOS); ! 221: break; ! 222: ! 223: case 's': case 'S': ! 224: maxoff=(adrflg?adrval:MAXOFF); ! 225: break; ! 226: ! 227: case 'v': case 'V': ! 228: prints("variables\n"); ! 229: FOR i=0;i<=35;i++ ! 230: DO IF var[i] ! 231: THEN printc((i<=9 ? '0' : 'a'-10) + i); ! 232: printf(" = %X\n",var[i]); ! 233: FI ! 234: OD ! 235: break; ! 236: ! 237: case 'm': case 'M': ! 238: printmap("? map",&txtmap); ! 239: printmap("/ map",&datmap); ! 240: break; ! 241: ! 242: case 0: case '?': ! 243: IF pid ! 244: THEN printf("pcs id = %d\n",pid); ! 245: ELSE prints("no process\n"); ! 246: FI ! 247: sigprint(); flushbuf(); ! 248: ! 249: case 'r': case 'R': ! 250: printregs(); ! 251: return; ! 252: ! 253: case 'c': case 'C': ! 254: IF adrflg ! 255: THEN frame=adrval; ! 256: word=get(adrval+6,DSP)&0xFFFF; ! 257: IF word&0x2000 ! 258: THEN /* 'calls', can figure out argp */ ! 259: argp=adrval+20+((word>>14)&3); word &= 0xFFF; ! 260: WHILE word DO IF word&1 THEN argp+=4; FI word>>=1; OD ! 261: ELSE /* 'callg', can't tell where argp is */ argp=frame; ! 262: FI ! 263: callpc=get(frame+16,DSP); ! 264: ELIF kcore THEN ! 265: argp = pcb.pcb_ap; ! 266: frame = pcb.pcb_fp; ! 267: callpc = pcb.pcb_pc; ! 268: ELSE argp= *(ADDR *)(((ADDR)&u)+AP); ! 269: frame= *(ADDR *)(((ADDR)&u)+FP); ! 270: callpc= *(ADDR *)(((ADDR)&u)+PC); ! 271: FI ! 272: lastframe=0; ! 273: ntramp = 0; ! 274: WHILE cntval-- ! 275: DO char *name; ! 276: chkerr(); ! 277: if (callpc > 0x80000000 - 0x200 * UPAGES) { ! 278: name = "sigtramp"; ! 279: ntramp++; ! 280: } else { ! 281: ntramp = 0; ! 282: findsym(callpc,ISYM); ! 283: if (cursym && ! 284: !strcmp(cursym->n_un.n_name, "start")) ! 285: break; ! 286: if (cursym) ! 287: name = cursym->n_un.n_name; ! 288: else ! 289: name = "?"; ! 290: } ! 291: printf("%s(", name); ! 292: narg = get(argp,DSP); IF narg&~0xFF THEN narg=0; FI ! 293: LOOP IF narg==0 THEN break; FI ! 294: printf("%R", get(argp += 4, DSP)); ! 295: IF --narg!=0 THEN printc(','); FI ! 296: POOL ! 297: printf(") from %X\n",callpc); /* jkf mod */ ! 298: ! 299: IF modif=='C' ! 300: THEN WHILE localsym(frame,argp) ! 301: DO word=get(localval,DSP); ! 302: printf("%8t%s:%10t", cursym->n_un.n_name); ! 303: IF errflg THEN prints("?\n"); errflg=0; ELSE printf("%R\n",word); FI ! 304: OD ! 305: FI ! 306: ! 307: if (ntramp == 1) ! 308: callpc=get(frame+84, DSP); ! 309: else ! 310: callpc=get(frame+16, DSP); ! 311: argp=get(frame+8, DSP); ! 312: lastframe=frame; ! 313: frame=get(frame+12, DSP)&EVEN; ! 314: IF frame==0 ORF (!adrflg ANDF !INSTACK(frame)) ! 315: THEN break; ! 316: FI ! 317: OD ! 318: break; ! 319: ! 320: /*print externals*/ ! 321: case 'e': case 'E': ! 322: for (sp = symtab; sp < esymtab; sp++) { ! 323: if (sp->n_type==(N_DATA|N_EXT) ORF sp->n_type==(N_BSS|N_EXT)) ! 324: printf("%s:%12t%R\n", sp->n_un.n_name, get(sp->n_value,DSP)); ! 325: } ! 326: break; ! 327: ! 328: case 'a': case 'A': ! 329: error("No algol 68 on VAX"); ! 330: /*NOTREACHED*/ ! 331: ! 332: /*print breakpoints*/ ! 333: case 'b': case 'B': ! 334: printf("breakpoints\ncount%8tbkpt%24tcommand\n"); ! 335: for (bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt) ! 336: if (bkptr->flag) { ! 337: printf("%-8.8d",bkptr->count); ! 338: psymoff(leng(bkptr->loc),ISYM,"%24t"); ! 339: comptr=bkptr->comm; ! 340: WHILE *comptr DO printc(*comptr++); OD ! 341: } ! 342: break; ! 343: ! 344: default: error(BADMOD); ! 345: } ! 346: ! 347: } ! 348: ! 349: printmap(s,amap) ! 350: STRING s; MAP *amap; ! 351: { ! 352: int file; ! 353: file=amap->ufd; ! 354: printf("%s%12t`%s'\n",s,(file<0 ? "-" : (file==fcor ? corfil : symfil))); ! 355: printf("b1 = %-16R",amap->b1); ! 356: printf("e1 = %-16R",amap->e1); ! 357: printf("f1 = %-16R",amap->f1); ! 358: printf("\nb2 = %-16R",amap->b2); ! 359: printf("e2 = %-16R",amap->e2); ! 360: printf("f2 = %-16R",amap->f2); ! 361: printc(EOR); ! 362: } ! 363: ! 364: printregs() ! 365: { ! 366: REG REGPTR p; ! 367: L_INT v; ! 368: ! 369: FOR p=reglist; p < ®list[24]; p++ ! 370: DO v = kcore ? *p->rkern : *(ADDR *)(((ADDR)&u)+p->roffs); ! 371: printf("%s%6t%R %16t", p->rname, v); ! 372: valpr(v,(p->roffs==PC?ISYM:DSYM)); ! 373: printc(EOR); ! 374: OD ! 375: printpc(); ! 376: } ! 377: ! 378: getreg(regnam) { ! 379: REG REGPTR p; ! 380: REG STRING regptr; ! 381: CHAR *olp; ! 382: CHAR regnxt; ! 383: ! 384: olp=lp; ! 385: FOR p=reglist; p < ®list[24]; p++ ! 386: DO regptr=p->rname; ! 387: IF (regnam == *regptr++) ! 388: THEN ! 389: WHILE *regptr ! 390: DO IF (regnxt=readchar()) != *regptr++ ! 391: THEN --regptr; break; ! 392: FI ! 393: OD ! 394: IF *regptr ! 395: THEN lp=olp; ! 396: ELSE ! 397: int i = kcore ? (int)p->rkern : p->roffs; ! 398: return (i); ! 399: FI ! 400: FI ! 401: OD ! 402: lp=olp; ! 403: return(0); ! 404: } ! 405: ! 406: printpc() ! 407: { ! 408: dot= *(ADDR *)(((ADDR)&u)+PC); ! 409: psymoff(dot,ISYM,":%16t"); printins(0,ISP,chkget(dot,ISP)); ! 410: printc(EOR); ! 411: } ! 412: ! 413: char *illinames[] = { ! 414: "reserved addressing fault", ! 415: "priviliged instruction fault", ! 416: "reserved operand fault" ! 417: }; ! 418: char *fpenames[] = { ! 419: 0, ! 420: "integer overflow trap", ! 421: "integer divide by zero trap", ! 422: "floating overflow trap", ! 423: "floating/decimal divide by zero trap", ! 424: "floating underflow trap", ! 425: "decimal overflow trap", ! 426: "subscript out of range trap", ! 427: "floating overflow fault", ! 428: "floating divide by zero fault", ! 429: "floating undeflow fault" ! 430: }; ! 431: ! 432: sigprint() ! 433: { ! 434: IF (signo>=0) ANDF (signo<sizeof signals/sizeof signals[0]) ! 435: THEN prints(signals[signo]); FI ! 436: switch (signo) { ! 437: ! 438: case SIGFPE: ! 439: IF (sigcode > 0 && ! 440: sigcode < sizeof fpenames / sizeof fpenames[0]) THEN ! 441: prints(" ("); prints(fpenames[sigcode]); prints(")"); ! 442: FI ! 443: break; ! 444: ! 445: case SIGILL: ! 446: IF (sigcode >= 0 && ! 447: sigcode < sizeof illinames / sizeof illinames[0]) THEN ! 448: prints(" ("); prints(illinames[sigcode]); prints(")"); ! 449: FI ! 450: break; ! 451: } ! 452: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.