Annotation of 43BSDTahoe/bin/adb/adb.tahoe/print.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.