1: static  char sccsid[] = "@(#)print.c 4.11 5/2/85";
   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 thru... */
 145: 
 146:         case '>':
 147:         {CHAR       file[64];
 148:         CHAR        Ifile[128];
 149:         extern CHAR *Ipath;
 150:         INT     index;
 151: 
 152:         index=0;
 153:         IF rdc()!=EOR
 154:         THEN    REP file[index++]=lastc;
 155:                 IF index>=63 THEN error(LONGFIL); FI
 156:             PER readchar()!=EOR DONE
 157:             file[index]=0;
 158:             IF modif=='<'
 159:             THEN    IF Ipath THEN
 160:                     strcpy(Ifile, Ipath);
 161:                     strcat(Ifile, "/");
 162:                     strcat(Ifile, file);
 163:                 FI
 164:                 IF strcmp(file, "-")!=0
 165:                 THEN    iclose(stack, 0);
 166:                     infile=open(file,0);
 167:                     IF infile<0
 168:                     THEN    infile=open(Ifile,0);
 169:                     FI
 170:                 ELSE    lseek(infile, 0L, 0);
 171:                 FI
 172:                 IF infile<0
 173:                 THEN    infile=0; error(NOTOPEN);
 174:                 ELSE    IF cntflg
 175:                     THEN    var[9] = cntval;
 176:                     ELSE    var[9] = 1;
 177:                     FI
 178:                 FI
 179:             ELSE    oclose();
 180:                 outfile=open(file,1);
 181:                 IF outfile<0
 182:                 THEN    outfile=creat(file,0644);
 183: #ifndef EDDT
 184:                 ELSE    lseek(outfile,0L,2);
 185: #endif
 186:                 FI
 187:             FI
 188: 
 189:         ELSE    IF modif == '<'
 190:             THEN    iclose(-1, 0);
 191:             ELSE    oclose();
 192:             FI
 193:         FI
 194:         lp--;
 195:         }
 196:         break;
 197: 
 198:         case 'p':
 199:         IF kernel == 0
 200:         THEN    printf("not debugging kernel\n");
 201:         ELSE    IF adrflg
 202:             THEN    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:         THEN    IF adrval < 2 ORF adrval > 16
 212:             THEN    printf("must have 2 <= radix <= 16");
 213:                 break;
 214:             FI
 215:             printf("radix=%d base ten",radix=adrval);
 216:         FI
 217:         break;
 218: 
 219:         case 'q': case 'Q': case '%':
 220:         done();
 221: 
 222:         case 'w': case 'W':
 223:         maxpos=(adrflg?adrval:MAXPOS);
 224:         break;
 225: 
 226:         case 's': case 'S':
 227:         maxoff=(adrflg?adrval:MAXOFF);
 228:         break;
 229: 
 230:         case 'v': case 'V':
 231:         prints("variables\n");
 232:         FOR i=0;i<=35;i++
 233:         DO  IF var[i]
 234:             THEN printc((i<=9 ? '0' : 'a'-10) + i);
 235:                 printf(" = %x\n",var[i]);
 236:             FI
 237:         OD
 238:         break;
 239: 
 240:         case 'm': case 'M':
 241:         printmap("? map",&txtmap);
 242:         printmap("/ map",&datmap);
 243:         break;
 244: 
 245:         case 0: case '?':
 246:         IF pid
 247:         THEN printf("pcs id = %d\n",pid);
 248:         ELSE prints("no process\n");
 249:         FI
 250:         sigprint(); flushbuf();
 251: 
 252:         case 'r': case 'R':
 253:         printregs();
 254:         return;
 255: 
 256:         case 'c': case 'C':
 257:         IF adrflg
 258:         THEN    frame=adrval;
 259:             word=get(adrval+6,DSP)&0xFFFF;
 260:             IF word&0x2000
 261:             THEN    /* 'calls', can figure out argp */
 262:                 argp=adrval+20+((word>>14)&3); word &= 0xFFF;
 263:                 WHILE word
 264:                 DO  IF word&1
 265:                     THEN    argp+=4;
 266:                     FI
 267:                     word>>=1;
 268:                 OD
 269:             ELSE    /* 'callg', can't tell where argp is */
 270:                 argp=frame;
 271:             FI
 272:             callpc=get(frame+16,DSP);
 273:         ELIF kcore
 274:         THEN    argp = pcb.pcb_ap;
 275:             frame = pcb.pcb_fp;
 276:             callpc = pcb.pcb_pc;
 277:         ELSE    argp= *(ADDR *)(((ADDR)&u)+AP);
 278:             frame= *(ADDR *)(((ADDR)&u)+FP);
 279:             callpc= *(ADDR *)(((ADDR)&u)+PC);
 280:         FI
 281:         lastframe=0;
 282:         ntramp = 0;
 283:         WHILE cntval--
 284:         DO  char *name;
 285:             chkerr();
 286:             /* if in extended pcb must be signal trampoline code */
 287:             IF KERNOFF - ctob(UPAGES) < callpc ANDF
 288:                 (unsigned)callpc < KERNOFF
 289:             THEN    name = "sigtramp";
 290:                 ntramp++;
 291:             ELSE    ntramp = 0;
 292:                 findsym(callpc,ISYM);
 293:                 IF cursym ANDF
 294:                     !strcmp(cursym->n_un.n_name, "start")
 295:                 THEN break;
 296:                 FI
 297:                 IF cursym
 298:                 THEN name = cursym->n_un.n_name;
 299:                 ELSE name = "?";
 300:                 FI
 301:             FI
 302:             printf("%s(", name);
 303:             narg = get(argp,DSP); IF narg&~0xFF THEN narg=0; FI
 304:             LOOP    IF narg==0 THEN break; FI
 305:                 printf("%R", get(argp += 4, DSP));
 306:                 IF --narg!=0 THEN printc(','); FI
 307:             POOL
 308:             IF ntramp == 1
 309:             THEN callpc=get(frame+92, DSP);
 310:             ELSE callpc=get(frame+16, DSP);
 311:             FI
 312:             IF callpc != 0
 313:             THEN    prints(") from ");
 314:                 psymoff(callpc, ISYM, "\n");
 315:             ELSE    prints(")\n");
 316:             FI
 317: 
 318:             IF modif=='C'
 319:             THEN    WHILE localsym(frame,argp)
 320:                 DO  word=get(localval,DSP);
 321:                     printf("%8t%s:%10t",
 322:                         cursym->n_un.n_name);
 323:                     IF errflg
 324:                     THEN prints("?\n"); errflg=0;
 325:                     ELSE printf("%R\n",word);
 326:                     FI
 327:                 OD
 328:             FI
 329: 
 330:             argp=get(frame+8, DSP);
 331:             lastframe=frame;
 332:             frame=get(frame+12, DSP)&EVEN;
 333:             IF frame==0 THEN break; FI
 334:             IF !adrflg ANDF !INSTACK(frame)
 335:             THEN    IF !kcore ORF !kstackaddr(frame)
 336:                 THEN break;
 337:                 FI
 338:             FI
 339:         OD
 340:         break;
 341: 
 342:         /*print externals*/
 343:         case 'e': case 'E':
 344:         FOR sp = symtab; sp < esymtab; sp++
 345:         DO  IF sp->n_type == (N_DATA|N_EXT) ORF
 346:                sp->n_type == (N_BSS|N_EXT)
 347:             THEN printf("%s:%12t%R\n", sp->n_un.n_name,
 348:                     get(sp->n_value,DSP));
 349:             FI
 350:         OD
 351:         break;
 352: 
 353:         case 'a': case 'A':
 354:         error("No algol 68 on VAX");
 355:         /*NOTREACHED*/
 356: 
 357:         /*print breakpoints*/
 358:         case 'b': case 'B':
 359:         printf("breakpoints\ncount%8tbkpt%24tcommand\n");
 360:         FOR bkptr=bkpthead; bkptr; bkptr=bkptr->nxtbkpt
 361:         DO  IF bkptr->flag
 362:             THEN    printf("%-8.8d",bkptr->count);
 363:                 psymoff(leng(bkptr->loc),ISYM,"%24t");
 364:                 comptr=bkptr->comm;
 365:                 WHILE *comptr DO printc(*comptr++); OD
 366:             FI
 367:         OD
 368:         break;
 369: 
 370:         default:
 371:         error(BADMOD);
 372:     }
 373: 
 374: }
 375: 
 376: printmap(s,amap)
 377: STRING  s; MAP *amap;
 378: {
 379:     int file;
 380:     file=amap->ufd;
 381:     printf("%s%12t`%s'\n", s,
 382:         (file<0 ? "-" : (file==fcor ? corfil : symfil)));
 383:     printf("b1 = %-16R",amap->b1);
 384:     printf("e1 = %-16R",amap->e1);
 385:     printf("f1 = %-16R",amap->f1);
 386:     printf("\nb2 = %-16R",amap->b2);
 387:     printf("e2 = %-16R",amap->e2);
 388:     printf("f2 = %-16R",amap->f2);
 389:     printc(EOR);
 390: }
 391: 
 392: printregs()
 393: {
 394:     REG REGPTR  p;
 395:     L_INT       v;
 396: 
 397:     FOR p=reglist; p < &reglist[24]; p++
 398:     DO  v = kcore ? *p->rkern : *(ADDR *)(((ADDR)&u)+p->roffs);
 399:         printf("%s%6t%R %16t", p->rname, v);
 400:         valpr(v,(p->roffs==PC?ISYM:DSYM));
 401:         printc(EOR);
 402:     OD
 403:     printpc();
 404: }
 405: 
 406: getreg(regnam) {
 407:     REG REGPTR  p;
 408:     REG STRING  regptr;
 409:     CHAR    *olp;
 410:     CHAR        regnxt;
 411: 
 412:     olp=lp;
 413:     FOR p=reglist; p < &reglist[24]; p++
 414:     DO  regptr=p->rname;
 415:         IF (regnam == *regptr++)
 416:         THEN
 417:             WHILE *regptr
 418:             DO IF (regnxt=readchar()) != *regptr++
 419:                 THEN --regptr; break;
 420:                 FI
 421:             OD
 422:             IF *regptr
 423:             THEN lp=olp;
 424:             ELSE
 425:                 int i = kcore ? (int)p->rkern : p->roffs;
 426:                 return (i);
 427:             FI
 428:         FI
 429:     OD
 430:     lp=olp;
 431:     return(0);
 432: }
 433: 
 434: printpc()
 435: {
 436:     dot= *(ADDR *)(((ADDR)&u)+PC);
 437:     psymoff(dot,ISYM,":%16t"); printins(0,ISP,chkget(dot,ISP));
 438:     printc(EOR);
 439: }
 440: 
 441: char    *illinames[] = {
 442:     "reserved addressing fault",
 443:     "priviliged instruction fault",
 444:     "reserved operand fault"
 445: };
 446: char    *fpenames[] = {
 447:     0,
 448:     "integer overflow trap",
 449:     "integer divide by zero trap",
 450:     "floating overflow trap",
 451:     "floating/decimal divide by zero trap",
 452:     "floating underflow trap",
 453:     "decimal overflow trap",
 454:     "subscript out of range trap",
 455:     "floating overflow fault",
 456:     "floating divide by zero fault",
 457:     "floating undeflow fault"
 458: };
 459: 
 460: sigprint()
 461: {
 462:     IF (signo>=0) ANDF (signo<sizeof signals/sizeof signals[0])
 463:     THEN prints(signals[signo]); FI
 464:     switch (signo) {
 465: 
 466:     case SIGFPE:
 467:         IF (sigcode > 0 &&
 468:             sigcode < sizeof fpenames / sizeof fpenames[0]) THEN
 469:             prints(" ("); prints(fpenames[sigcode]); prints(")");
 470:         FI
 471:         break;
 472: 
 473:     case SIGILL:
 474:         IF (sigcode >= 0 &&
 475:             sigcode < sizeof illinames / sizeof illinames[0]) THEN
 476:             prints(" ("); prints(illinames[sigcode]); prints(")");
 477:         FI
 478:         break;
 479:     }
 480: }

Defined functions

getreg defined in line 406; used 2 times
printmap defined in line 376; used 2 times
printpc defined in line 434; used 2 times
printregs defined in line 392; used 1 times
printtrace defined in line 116; used 1 times
sigprint defined in line 460; used 3 times

Defined variables

fpenames defined in line 446; used 3 times
illinames defined in line 441; used 3 times
lastc defined in line 61; used 1 times
sccsid defined in line 1; never used
Last modified: 1985-05-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1628
Valid CSS Valid XHTML 1.0 Strict