Annotation of researchv8dc/cmd/ccom/vax/debug.c, revision 1.1

1.1     ! root        1: # include "mfile1.h"
        !             2: # include "debug.h"
        !             3: 
        !             4: /*     File where debugging information is collected and printed out */
        !             5: 
        !             6: /*     This file is for pi */
        !             7: 
        !             8: int gdebug, slineno;
        !             9: 
        !            10: #define SYMTAB struct symtab
        !            11: 
        !            12: /* (year-80) month day(in dec), as 4 hexits */
        !            13: 
        !            14: static vernum = 0x4501;
        !            15: 
        !            16: static char verstr[] = "vaxpcc2";
        !            17: 
        !            18: static char strvalfmt[] = "    .stabs  \"%s\",0x%x,0,%d,%d\n";
        !            19: 
        !            20: static char strsymfmt[] = "    .stabs  \"%s\",0x%x,0,%d,%s\n";
        !            21: 
        !            22: static char nulvalfmt[] = "    .stabn  0x%x,0,%d,%d\n";
        !            23: 
        !            24: static char nulsymfmt[] = "    .stabn  0x%x,0,%d,%s\n";
        !            25: 
        !            26: static char dotfmt[]   = "     .stabd  0x%x,0,%d\n";
        !            27: 
        !            28: static char labstr[16];
        !            29: 
        !            30: static char *
        !            31: maklab(val)
        !            32: {
        !            33:        sprintx(labstr, LABFMT, val);
        !            34:        return labstr;
        !            35: }
        !            36: 
        !            37: static
        !            38: wasused( p )
        !            39: register SYMTAB *p; 
        !            40: {
        !            41:        register i;
        !            42: 
        !            43:        switch( p->sclass ) {
        !            44:        case STNAME:
        !            45:        case UNAME:
        !            46:        case ENAME:
        !            47:                for (i = dimtab[p->sizoff+1]; i >= 0 && dimtab[i] >= 0; i++)
        !            48:                        if (wasused( &stab[dimtab[i]] ))
        !            49:                                return 1;
        !            50:                return 0;
        !            51:        default:
        !            52:                return p->suse < 0;
        !            53:        }
        !            54: }
        !            55: 
        !            56: dbnargs( n )   /* number of argument bytes in call to a function */
        !            57: {
        !            58:        if (gdebug)
        !            59:                printx(dotfmt, N_NARGS, n/SZCHAR );
        !            60: }
        !            61: 
        !            62: dbfunbeg( p )  /* beginning of a function */
        !            63: SYMTAB *p;
        !            64: {
        !            65:        dbfile(exname(p->sname));
        !            66:        printx(strsymfmt, p->sname, N_BFUN, lineno, exname(p->sname));
        !            67:        ppstab(p);
        !            68: }
        !            69: 
        !            70: dbfunarg( p )  /* called for each argument of a function */
        !            71: SYMTAB *p; 
        !            72: {
        !            73:        ppstab( p );            /* we can pick up the reg later */
        !            74: }
        !            75: 
        !            76: dbfunret()     /* return from a function */
        !            77: {
        !            78:        if (gdebug) {
        !            79:                dbfile(NULL);
        !            80:                printx(dotfmt, N_RFUN, slineno ? slineno : lineno );
        !            81:                slineno = 0;
        !            82:        }
        !            83: }
        !            84: 
        !            85: dbfunend( lab )        /* end of a function */
        !            86: {
        !            87:        register SYMTAB *p = &stab[curftn];
        !            88: 
        !            89:        printx("%s:", maklab(lab));
        !            90:        dbfile(labstr);
        !            91:        printx(strsymfmt, p->sname, N_EFUN, lineno, labstr);
        !            92: }
        !            93: 
        !            94: dblbrac()      /* block level when a { is seen */
        !            95: {
        !            96:        if (gdebug)
        !            97:                printx(dotfmt, N_LBRAC, blevel);
        !            98: }
        !            99: 
        !           100: dbrbrac()      /* block level when a } is seen */
        !           101: {
        !           102:        if (gdebug)
        !           103:                printx(dotfmt, N_RBRAC, blevel);
        !           104: }
        !           105: 
        !           106: aobeg()        /* called before printing out the autos */
        !           107: {
        !           108: }
        !           109: 
        !           110: aocode(p)
        !           111: register struct symtab *p; 
        !           112: {
        !           113:        /* called when automatic p removed from stab */
        !           114: 
        !           115:        switch( p->sclass ) {
        !           116:        case REGISTER:
        !           117:        case AUTO:
        !           118:        case STATIC:
        !           119:        case EXTDEF:
        !           120:        case STNAME:
        !           121:        case UNAME:
        !           122:        case ENAME:
        !           123:                if(!ISFTN(p->stype) && (gdebug || wasused(p)))
        !           124:                        ppstab( p );
        !           125:                return;
        !           126:        case EXTERN:
        !           127:                /*      for now, do not report externs  */
        !           128:                return;
        !           129:        }
        !           130: }
        !           131: 
        !           132: aoend()
        !           133: {
        !           134: }
        !           135: 
        !           136: # ifndef OUTREGNO
        !           137: # define OUTREGNO(p) ((p)->offset)
        !           138: # endif
        !           139: 
        !           140: #define BYTOFF(p)      (((off = (p)->offset) < 0 ? -off : off)/SZCHAR)
        !           141: 
        !           142: ppstab( p )
        !           143: register SYMTAB *p; 
        !           144: {
        !           145:        /* write out .stabs for the symbol p */
        !           146:        register TWORD t;
        !           147:        register off, i;
        !           148: 
        !           149:        if( p->stype == TNULL ) return;
        !           150: 
        !           151:        if( p->sclass & FIELD ) {
        !           152:                printx(strvalfmt, p->sname, N_SFLD,
        !           153:                        ((p->sclass&FLDSIZ)<<BTSHIFT)|p->stype, p->offset);
        !           154:                return;
        !           155:        }
        !           156: 
        !           157:        switch( p->sclass )
        !           158:        {
        !           159:        case AUTO:
        !           160:                printx(strvalfmt, p->sname, N_LSYM, p->stype, BYTOFF(p));
        !           161:                break;
        !           162:        case REGISTER:
        !           163:                printx(strvalfmt, p->sname, N_RSYM, p->stype, OUTREGNO(p));
        !           164:                break;
        !           165:        case PARAM:
        !           166:                printx(strvalfmt, p->sname, N_PSYM, p->stype, BYTOFF(p));
        !           167:                break;
        !           168:        case EXTERN:
        !           169:        case EXTDEF:
        !           170:                printx(strvalfmt, p->sname, N_GSYM, p->stype, 0);
        !           171:                break;
        !           172: /*
        !           173:        case EXTDEF:
        !           174:                printx(strsymfmt, p->sname, N_GSYM, p->stype,
        !           175:                        exname(p->sname));
        !           176:                break;
        !           177: */
        !           178:        case STATIC:
        !           179:                if (ISFTN(p->stype))
        !           180:                        printx(strvalfmt, p->sname, N_STFUN, p->stype, 0);
        !           181:                else
        !           182:                        printx(strsymfmt, p->sname,
        !           183:                            (p->sflags&SBSS) ? N_LCSYM : N_STSYM, p->stype,
        !           184:                            p->slevel ? maklab(p->offset) : exname(p->sname));
        !           185:                break;
        !           186:        case STNAME:
        !           187:        case UNAME:
        !           188:        case ENAME:
        !           189:                printx(strvalfmt, p->sname, N_BSTR, p->stype, 0);
        !           190:                for (i = dimtab[p->sizoff+1]; i >= 0 && dimtab[i] >= 0; i++)
        !           191:                        ppstab( &stab[dimtab[i]] );
        !           192:                printx(strvalfmt, p->sname, N_ESTR, p->stype,
        !           193:                        dimtab[p->sizoff]/SZCHAR);
        !           194:                return;
        !           195:        case MOS:
        !           196:        case MOU:
        !           197:                printx(strvalfmt, p->sname, N_SSYM, p->stype, BYTOFF(p));
        !           198:                break;
        !           199:        case MOE:
        !           200:                printx(strvalfmt, p->sname, N_SSYM, p->stype, p->offset);
        !           201:                return;
        !           202:        case TYPEDEF: /* !? */
        !           203:                return;
        !           204:        default:
        !           205:                fprintf(stderr,"unexpected stab class %d: %s, type = 0x%04x\n",
        !           206:                        p->sclass, p->sname, p->stype);
        !           207:                fflush(stderr);
        !           208:                return;
        !           209:        }
        !           210:        /* make another entry to describe structs, unions, enums */
        !           211:        switch( BTYPE(p->stype) ) {
        !           212:        case STRTY:
        !           213:        case UNIONTY:
        !           214:        case ENUMTY:
        !           215:                printx(strvalfmt, stab[dimtab[p->sizoff+3]].sname,
        !           216:                    N_TYID, 0, 0);
        !           217:        }
        !           218: 
        !           219:        /* make other entries with the dimensions */
        !           220:        for( t=p->stype, i=p->dimoff; t&TMASK; t = DECREF(t) ) 
        !           221:        {
        !           222:                if( ISARY(t) ) printx(nulvalfmt, N_DIM, 0, dimtab[i++]);
        !           223:        }
        !           224: }
        !           225: 
        !           226: static char orgfile[100], curfile[100], prtfile[100];
        !           227: 
        !           228: static int srcfilop = N_SO;
        !           229: 
        !           230: static char *
        !           231: makstr(ip)
        !           232: register char *ip;
        !           233: {
        !           234:        register c; register char *jp = prtfile;
        !           235:        do {
        !           236:                if ((c = *ip++) != '"')
        !           237:                        *jp++ = c;
        !           238:        } while (c);
        !           239:        return prtfile;
        !           240: }
        !           241: 
        !           242: dbfile(pname)
        !           243: char *pname;
        !           244: {
        !           245:        int seg;
        !           246:        if (strcmp(curfile, ftitle) == 0)
        !           247:                return 0;
        !           248:        strcpy(curfile, ftitle);
        !           249:        seg = locctr(PROG);
        !           250:        if (pname == NULL)
        !           251:                printx("%s:", pname = maklab(getlab()));
        !           252:        printx(strsymfmt, makstr(curfile), srcfilop,
        !           253:            slineno ? slineno : lineno, pname);
        !           254:        slineno = 0;
        !           255:        if (srcfilop == N_SO) { /* first file */
        !           256:                printx(strvalfmt, verstr, N_VER, vernum, time(0));
        !           257:                strcpy(orgfile, ftitle);
        !           258:                srcfilop = N_SOL;
        !           259:        }
        !           260:        if (seg >= 0)
        !           261:                locctr(seg);
        !           262:        return 1;
        !           263: }
        !           264: 
        !           265: dbline()
        !           266: {
        !           267:        int seg;
        !           268:        if (blevel && !dbfile(NULL) && gdebug) {
        !           269:                seg = locctr(PROG);
        !           270:                printx(dotfmt, N_SLINE, slineno ? slineno : lineno);
        !           271:                slineno = 0;
        !           272:                if (seg >= 0)
        !           273:                        locctr(seg);
        !           274:        }
        !           275: }
        !           276: 
        !           277: ejsdb()
        !           278: {
        !           279:        /* called at the end of the entire file */
        !           280:        register struct symtab *p;
        !           281:        extern Pflag, bbcnt;
        !           282:        int i;
        !           283:        if(Pflag) {
        !           284:                printx("\t.data\nlocprof:\t.long %d\n", bbcnt+4);
        !           285:                printx("\t.long 0\n\t.long L%db\n", bbcnt);
        !           286:                printx("\t.space %d\n", 4*bbcnt+4);
        !           287:                printx("L%db:\t.byte ", bbcnt);
        !           288:                for(i = 0; curfile[i]; i++)
        !           289:                        printx("0x%x,", curfile[i]);
        !           290:                printx("0\n");
        !           291:        }
        !           292:        for( p = &stab[SYMTSZ]; --p>=stab; )
        !           293:        {
        !           294:                if( p->stype != TNULL && !ISFTN(p->stype) ) 
        !           295:                {
        !           296:                        switch( p->sclass ) 
        !           297:                        {
        !           298:                        case EXTERN:
        !           299:                                if( p->suse > 0 ) continue;     /* unused */
        !           300:                        case EXTDEF:
        !           301:                        case STATIC:
        !           302:                        case STNAME:
        !           303:                        case UNAME:
        !           304:                        case ENAME:
        !           305:                                if (gdebug || wasused(p))
        !           306:                                        ppstab(p);
        !           307:                                break;
        !           308:                        }
        !           309:                }
        !           310:        }
        !           311:        printx("        .text\n");
        !           312:        printx("%s:", maklab(getlab()));
        !           313:        printx(strsymfmt, makstr(orgfile), N_ESO, lineno, labstr);
        !           314: }

unix.superglobalmegacorp.com

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