Annotation of researchv9/cmd/sun/pcc/save/stab.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Symbolic debugging info interface.
                      3:  *
                      4:  * Here we generate pseudo-ops that cause the assembler to put
                      5:  * symbolic debugging information into the object file.
                      6:  */
                      7: #include "cpass1.h"
                      8: #include <sys/types.h>
                      9: #include <a.out.h>
                     10: #include "stab.h"
                     11: 
                     12: static int inastruct;
                     13: static int inafunc;
                     14: static int inbegfunc;
                     15: static int inaparam;
                     16: static char strvalfmt[] = "    .stabs  \"%s\",0x%x,0,%d,%d\n";
                     17: static char strsymfmt[] = "    .stabs  \"%s\",0x%x,0,%d,%s\n";
                     18: static char nulvalfmt[] = "    .stabn  0x%x,0,%d,%d\n";
                     19: static char nulsymfmt[] = "    .stabn  0x%x,0,%d,%s\n";
                     20: static char dotfmt[]   = "     .stabd  0x%x,0,%d\n";
                     21: 
                     22: extern int gdebug;
                     23: extern char *strcpy();
                     24: int stabLCSYM;
                     25: 
                     26: /*
                     27:  * Old flag, not used anymore.
                     28:  */
                     29: int oldway = 0;
                     30: 
                     31: /*
                     32:  * Generate information for a newly-defined structure.
                     33:  */
                     34: outstruct(szindex, paramindex)
                     35: int szindex, paramindex;
                     36: {
                     37:        register struct symtab *p;
                     38:        register int i;
                     39: 
                     40:        if (!gdebug)
                     41:                return;
                     42:        inastruct = 1;
                     43:        p = STP(dimtab[szindex + 3]);
                     44:        printf(strvalfmt, p->sname, N_BSTR, p->stype, 0);
                     45:        outstab(STP(dimtab[szindex + 3]));
                     46:        for( i = dimtab[szindex + 1]; dimtab[i] > 0; i++)
                     47:                outstab(STP(dimtab[i]));
                     48:        printf(strvalfmt, p->sname, N_ESTR, p->stype, dimtab[p->sizoff]/SZCHAR);
                     49:        inastruct = 0;
                     50: }
                     51: 
                     52: psline(lineno)
                     53:     int lineno;
                     54: {
                     55:        if (gdebug && !dbfile(NULL))
                     56:                printf(dotfmt, N_SLINE, lineno);
                     57: }
                     58:     
                     59: plcstab(level)
                     60: int level;
                     61: {
                     62:        if (gdebug)
                     63:                printf(dotfmt, N_LBRAC, level);
                     64: }
                     65:     
                     66: prcstab(level)
                     67: int level;
                     68: {
                     69:        if (gdebug)
                     70:                printf(dotfmt, N_RBRAC, level);
                     71: }
                     72:     
                     73: pfstab(sname) 
                     74: char *sname;
                     75: {
                     76:     register struct symtab *p;
                     77: 
                     78:        p = STP(lookup(sname, 0));
                     79:        inafunc = 1;
                     80:        inbegfunc = 1;
                     81: /*     dbfile(exname(p->sname));*/
                     82:        locctr(PROG);
                     83:        printf(strsymfmt, p->sname, N_BFUN, lineno, exname(p->sname));
                     84:        outstab(p);
                     85:        inbegfunc = 0;
                     86: }
                     87: 
                     88: #define BYTOFF(p)      (((off = (p)->offset) < 0 ? -off : off)/SZCHAR)
                     89: 
                     90: /*
                     91:  * Generate debugging info for a parameter.
                     92:  * The offset isn't known when it is first entered into the symbol table
                     93:  * since the types are read later.
                     94:  */
                     95: fixarg(p)
                     96: struct symtab *p;
                     97: {
                     98:        inaparam = 1;
                     99:        outstab(p);
                    100:        inaparam = 0;
                    101: }
                    102: 
                    103: static char labstr[16];
                    104: 
                    105: static char *
                    106: maklab(val)
                    107: {
                    108:        sprintf(labstr, "L%d", val);
                    109:        return labstr;
                    110: }
                    111: 
                    112: # ifndef OUTREGNO
                    113: # define OUTREGNO(p) ((p)->offset)
                    114: # endif
                    115: 
                    116: /*
                    117:  * Generate debugging info for a given symbol.
                    118:  */
                    119: outstab(p)
                    120: register struct symtab *p; {
                    121: 
                    122:        register TWORD t;
                    123:        register off, i;
                    124: 
                    125:        if (ISFTN(p->stype) && !inbegfunc)
                    126:                return;
                    127:        if( p->sclass > FIELD ) {
                    128:                if (!inastruct)
                    129:                        return;
                    130:                printf(strvalfmt, p->sname, N_SFLD,
                    131:                        ((p->sclass - FIELD)<<BTSHIFT)|p->stype, p->offset);
                    132:                return;
                    133:        }
                    134: 
                    135:        switch( p->sclass )
                    136:        {
                    137:        case AUTO:
                    138:                printf(strvalfmt, p->sname, N_LSYM, p->stype, BYTOFF(p));
                    139:                break;
                    140:        case REGISTER:
                    141:                if (!inafunc)
                    142:                        return;
                    143:                if (inaparam) {
                    144:                        p->sclass = PARAM;
                    145:                        outstab(p);
                    146:                        p->sclass = REGISTER;
                    147:                }
                    148:                printf(strvalfmt, p->sname, N_RSYM, p->stype, OUTREGNO(p));
                    149:                break;
                    150:        case PARAM:
                    151:                if (!inaparam)
                    152:                        return;
                    153:                printf(strvalfmt, p->sname, N_PSYM, p->stype, argoff/SZCHAR);
                    154:                break;
                    155:        case EXTERN:
                    156:        case EXTDEF:
                    157:                printf(strvalfmt, p->sname, N_GSYM, p->stype, 0);
                    158:                break;
                    159:        case STATIC:
                    160:                if (ISFTN(p->stype))
                    161:                        printf(strvalfmt, p->sname, N_STFUN, p->stype, 0);
                    162:                else
                    163:                        printf(strsymfmt, p->sname,
                    164:                            stabLCSYM ? N_LCSYM : N_STSYM, p->stype,
                    165:                            p->slevel ? maklab(p->offset) : exname(p->sname));
                    166:                break;
                    167:        case MOS:
                    168:        case MOU:
                    169:                if (!inastruct)
                    170:                        return;
                    171:                printf(strvalfmt, p->sname, N_SSYM, p->stype, BYTOFF(p));
                    172:                break;
                    173:        case MOE:
                    174:                if (!inastruct)
                    175:                        return;
                    176:                printf(strvalfmt, p->sname, N_SSYM, p->stype, p->offset);
                    177:                return;
                    178:        default:
                    179:                return;
                    180:        }
                    181:        /* make another entry to describe structs, unions, enums */
                    182:        switch( BTYPE(p->stype) ) {
                    183:        case STRTY:
                    184:        case UNIONTY:
                    185:        case ENUMTY:
                    186:                printf(strvalfmt, STP(dimtab[p->sizoff+3])->sname,
                    187:                    N_TYID, 0, 0);
                    188:        }
                    189: 
                    190:        /* make other entries with the dimensions */
                    191:        for( t=p->stype, i=p->dimoff; t&TMASK; t = DECREF(t) ) 
                    192:        {
                    193:                if( ISARY(t) ) printf(nulvalfmt, N_DIM, 0, dimtab[i++]);
                    194:        }
                    195: 
                    196: }
                    197: 
                    198: dbfunend( lab )        /* end of a function */
                    199: {
                    200:        inafunc = 0;
                    201:        printf(dotfmt, N_EFUN, lineno);
                    202: }
                    203: 
                    204: beg_file()      /* only used in cgram.y */
                    205: {
                    206:         dbfile(NULL);
                    207: }
                    208: 
                    209: static char orgfile[100], currfile[100], prtfile[100];
                    210: 
                    211: static int srcfilop = N_SO;
                    212: 
                    213: static char *
                    214: makstr(ip)
                    215: register char *ip;
                    216: {
                    217:        register c; register char *jp = prtfile;
                    218:        do {
                    219:                if ((c = *ip++) != '"')
                    220:                        *jp++ = c;
                    221:        } while (c);
                    222:        return prtfile;
                    223: }
                    224: 
                    225: dbfile(pname)
                    226: char *pname;
                    227: {
                    228:        int seg;
                    229:        if (!strcmp(currfile, ftitle))
                    230:                return 0;
                    231:        strcpy(currfile, ftitle);
                    232:        seg = locctr(PROG);
                    233:        if (pname == NULL)
                    234:                printf("%s:", pname = maklab(getlab()));
                    235:        printf(strsymfmt, makstr(currfile), srcfilop, lineno, pname);
                    236:        if (srcfilop == N_SO) { /* first file */
                    237:                strcpy(orgfile, ftitle);
                    238:                srcfilop = N_SOL;
                    239:        }
                    240:        if (seg >= 0)
                    241:                locctr(seg);
                    242:        return 1;
                    243: }
                    244: 
                    245: ejsdb()
                    246: {
                    247:        /* called at the end of the entire file */
                    248:        printf("\t.text\n");
                    249:        printf("%s:", maklab(getlab()));
                    250:        printf(strsymfmt, makstr(orgfile), N_ESO, lineno, labstr);
                    251: }

unix.superglobalmegacorp.com

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