Annotation of researchv8dc/cmd/adb/print.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *
                      3:  *     UNIX debugger
                      4:  *
                      5:  */
                      6: #include "defs.h"
                      7: #include "regs.h"
                      8: #include <a.out.h>
                      9: 
                     10: MSG    LONGFIL;
                     11: MSG    NOTOPEN;
                     12: MSG    BADMOD;
                     13: 
                     14: int    infile;
                     15: int    outfile;
                     16: int    maxpos;
                     17: int    radix;
                     18: 
                     19: BKPT *bkpthead;
                     20: 
                     21: char   lastc;
                     22: 
                     23: char *signals[] = {
                     24:        "",
                     25:        "hangup",
                     26:        "interrupt",
                     27:        "quit",
                     28:        "illegal instruction",
                     29:        "trace/BPT",
                     30:        "IOT",
                     31:        "EMT",
                     32:        "floating exception",
                     33:        "killed",
                     34:        "bus error",
                     35:        "memory fault",
                     36:        "bad system call",
                     37:        "broken pipe",
                     38:        "alarm call",
                     39:        "terminated",
                     40:        "signal 16",
                     41:        "stopped",
                     42:        "stop (tty)",
                     43:        "continue (signal)",
                     44:        "child termination",
                     45:        "stop (tty input)",
                     46:        "stop (tty output)",
                     47:        "input available (signal)",
                     48:        "cpu timelimit",
                     49:        "file sizelimit",
                     50:        "signal 26",
                     51:        "signal 27",
                     52:        "signal 28",
                     53:        "signal 29",
                     54:        "signal 30",
                     55:        "signal 31",
                     56: };
                     57: 
                     58: /* general printing routines ($) */
                     59: 
                     60: printtrace(modif)
                     61: {
                     62:        int     i;
                     63:        register BKPT *bk;
                     64:        char    *comptr;
                     65:        register struct nlist *sp;
                     66:        int     stack;
                     67: 
                     68:        if (cntflg==0)
                     69:                cntval = -1;
                     70:        switch (modif) {
                     71: 
                     72:        case '<':
                     73:                if (cntval == 0) {
                     74:                        while (readchar() != EOR)
                     75:                                ;
                     76:                        reread();
                     77:                        break;
                     78:                }
                     79:                if (rdc() == '<')
                     80:                        stack = 1;
                     81:                else {
                     82:                        stack = 0;
                     83:                        reread();
                     84:                }
                     85:                /* fall through */
                     86:        case '>':
                     87:                {
                     88:                        char    file[64];
                     89:                        char    Ifile[128];
                     90:                        extern char     *Ipath;
                     91:                        int     index;
                     92: 
                     93:                        index=0;
                     94:                        if (modif=='<')
                     95:                                iclose(stack, 0);
                     96:                        else
                     97:                                oclose();
                     98:                        if (rdc()!=EOR) {
                     99:                                do {
                    100:                                        file[index++]=lastc;
                    101:                                        if (index>=63)
                    102:                                                error(LONGFIL);
                    103:                                } while (readchar()!=EOR);
                    104:                                file[index]=0;
                    105:                                if (modif=='<') {
                    106:                                        if (Ipath) {
                    107:                                                strcpy(Ifile, Ipath);
                    108:                                                strcat(Ifile, "/");
                    109:                                                strcat(Ifile, file);
                    110:                                        }
                    111:                                        infile=open(file,0);
                    112:                                        if (infile<0 && (infile=open(Ifile,0))<0) {
                    113:                                                infile=STDIN;
                    114:                                                error(NOTOPEN);
                    115:                                        } else {
                    116:                                                if (cntflg)
                    117:                                                        var[9] = cntval;
                    118:                                                else
                    119:                                                        var[9] = 1;
                    120:                                        }
                    121:                                } else {
                    122:                                        outfile=open(file,1);
                    123:                                        if (outfile<0)
                    124:                                                outfile=creat(file,0644);
                    125:                                        else
                    126:                                                lseek(outfile,0L,2);
                    127:                                }
                    128: 
                    129:                        } else {
                    130:                                if (modif == '<')
                    131:                                        iclose(-1, 0);
                    132:                        }
                    133:                        reread();
                    134:                }
                    135:                break;
                    136: 
                    137:        case 'p':
                    138:                kmproc();
                    139:                break;
                    140: 
                    141:        case 'k':
                    142:                kmsys();
                    143:                break;
                    144: 
                    145:        case 'd':
                    146:                if (adrflg) {
                    147:                        if (adrval != 0
                    148:                        &&  (adrval<2 || adrval>16))
                    149:                                error("radix should be between 2 and 16, or 0");
                    150:                        radix = adrval;
                    151:                        if (radix)
                    152:                                printf("radix=%d base ten",radix);
                    153:                        else
                    154:                                printf("radix=magic");
                    155:                }
                    156:                break;
                    157: 
                    158:        case 'q':
                    159:        case 'Q':
                    160:                done();
                    161: 
                    162:        case 'w':
                    163:        case 'W':
                    164:                maxpos=(adrflg?adrval:MAXPOS);
                    165:                break;
                    166: 
                    167:        case 's':
                    168:        case 'S':
                    169:                maxoff=(adrflg?adrval:MAXOFF);
                    170:                break;
                    171: 
                    172:        case 'v':
                    173:        case 'V':
                    174:                prints("variables\n");
                    175:                for (i=0;i<NVARS;i++) {
                    176:                        if (var[i]) {
                    177:                                printc((i<=9 ? '0' : 'a'-10) + i);
                    178:                                printf(" = %R\n", var[i]);
                    179:                        }
                    180:                }
                    181:                break;
                    182: 
                    183:        case 'm':
                    184:        case 'M':
                    185:                printmap("? map", symmap);
                    186:                printmap("/ map", cormap);
                    187:                break;
                    188: 
                    189:        case 0:
                    190:        case '?':
                    191:                if (pid)
                    192:                        printf("pcs id = %d\n",pid);
                    193:                else
                    194:                        prints("no process\n");
                    195:                sigprint();
                    196:                flushbuf();
                    197: 
                    198:        case 'r':
                    199:        case 'R':
                    200:                printregs(modif);
                    201:                return;
                    202: 
                    203:        case 'c':
                    204:        case 'C':
                    205:                ctrace(modif);
                    206:                break;
                    207: 
                    208:                /*print externals*/
                    209:        case 'e':
                    210:        case 'E':
                    211:                for (sp = symtab; sp < esymtab; sp++) {
                    212:                        if (sp->n_type==(N_DATA|N_EXT) || sp->n_type==(N_BSS|N_EXT))
                    213:                                printf("%s:%12t%R\n", sp->n_un.n_name,
                    214:                                        ltow(lget(sp->n_value,CORF|DATASP)));
                    215:                }
                    216:                break;
                    217: 
                    218:                /*print breakpoints*/
                    219:        case 'b':
                    220:        case 'B':
                    221:                printf("breakpoints\ncount%8tbkpt%24tcommand\n");
                    222:                for (bk=bkpthead; bk; bk=bk->nxtbkpt)
                    223:                        if (bk->flag) {
                    224:                                printf("%-8.8d",bk->count);
                    225:                                psymoff((WORD)bk->loc,INSTSP,"%24t");
                    226:                                comptr=bk->comm;
                    227:                                while (*comptr)
                    228:                                        printc(*comptr++);
                    229:                        }
                    230:                break;
                    231: 
                    232:        default:
                    233:                error(BADMOD);
                    234:        }
                    235: 
                    236: }
                    237: 
                    238: printmap(s,mp)
                    239: char *s;
                    240: register MAP *mp;
                    241: {
                    242:        char *maptype();
                    243: 
                    244:        if (mp == symmap)
                    245:                printf("%s%12t`%s'\n", s, fsym < 0 ? "-" : symfil);
                    246:        else if (mp == cormap)
                    247:                printf("%s%12t`%s'\n", s, fcor < 0 ? "-" : corfil);
                    248:        else
                    249:                printf("%s\n", s);
                    250:        for (; mp->flag & MPINUSE; mp++)
                    251:                printf("%-8s b = %-16Re = %-16Rf = %-16R\n",
                    252:                    maptype(mp->sp), (WORD)mp->b, (WORD)mp->e, (WORD)mp->f);
                    253: }
                    254: 
                    255: char *
                    256: maptype(sp)
                    257: int sp;
                    258: {
                    259: 
                    260:        switch (sp & SPTYPE) {
                    261:        case INSTSP:
                    262:                return ("text");
                    263:        case DATASP:
                    264:                return ("data");
                    265:        case UBLKSP:
                    266:                return ("user");
                    267:        default:
                    268:                return ("nonsense");
                    269:        }
                    270: }
                    271: 
                    272: printpc()
                    273: {
                    274:        TLONG w;
                    275: 
                    276:        dot = (ADDR)rtow(rget(PC));
                    277:        psymoff((WORD)dot, INSTSP, "?%16t");
                    278:        w = lget(dot, SYMF|INSTSP);
                    279:        chkerr();
                    280:        printins(SYMF|INSTSP, w);
                    281:        printc(EOR);
                    282: }
                    283: 
                    284: char   *illinames[] = {
                    285:        "reserved addressing fault",
                    286:        "privileged instruction fault",
                    287:        "reserved operand fault"
                    288: };
                    289: char   *fpenames[] = {
                    290:        0,
                    291:        "integer overflow trap",
                    292:        "integer divide by zero trap",
                    293:        "floating overflow trap",
                    294:        "floating/decimal divide by zero trap",
                    295:        "floating underflow trap",
                    296:        "decimal overflow trap",
                    297:        "subscript out of range trap",
                    298:        "floating overflow fault",
                    299:        "floating divide by zero fault",
                    300:        "floating undeflow fault"
                    301: };
                    302: 
                    303: sigprint()
                    304: {
                    305:        if ((signo>=0) && (signo<sizeof signals/sizeof signals[0]))
                    306:                prints(signals[signo]);
                    307:        switch (signo) {
                    308: 
                    309:        case SIGFPE:
                    310:                if ((sigcode > 0
                    311:                &&  sigcode < sizeof fpenames / sizeof fpenames[0]))
                    312:                        printf(" (%s)", fpenames[sigcode]);
                    313:                break;
                    314: 
                    315:        case SIGILL:
                    316:                if ((sigcode >= 0
                    317:                &&  sigcode < sizeof illinames / sizeof illinames[0]))
                    318:                        printf(" (%s)", illinames[sigcode]);
                    319:                break;
                    320:        }
                    321: }

unix.superglobalmegacorp.com

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