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

unix.superglobalmegacorp.com

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