Annotation of 43BSDReno/libexec/pcc/ccom.tahoe/stab.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid ="@(#)stab.c       1.6 (Berkeley) 12/10/87";
                      3: #endif
                      4: /*
                      5:  * Symbolic debugging info interface.
                      6:  *
                      7:  * Here we generate pseudo-ops that cause the assembler to put
                      8:  * symbolic debugging information into the object file.
                      9:  */
                     10: 
                     11: #include "pass1.h"
                     12: 
                     13: #include <sys/types.h>
                     14: #include <a.out.h>
                     15: #include <stab.h>
                     16: 
                     17: #define private static
                     18: #define and &&
                     19: #define or ||
                     20: #define not !
                     21: #define div /
                     22: #define mod %
                     23: #define nil 0
                     24: 
                     25: #define bytes(bits) ((bits) / SZCHAR)
                     26: #define bsize(p) bytes(dimtab[p->sizoff])      /* size in bytes of a symbol */
                     27: 
                     28: #define NILINDEX -1
                     29: #define FORWARD -2
                     30: 
                     31: typedef int Boolean;
                     32: 
                     33: #define false 0
                     34: #define true 1
                     35: 
                     36: extern int ddebug;
                     37: extern int gdebug;
                     38: extern char *malloc();
                     39: 
                     40: int stabLCSYM;
                     41: 
                     42: /*
                     43:  * Flag for producing either sdb or dbx symbol information.
                     44:  */
                     45: int oldway = false;
                     46: 
                     47: /*
                     48:  * Generate debugging info for a parameter.
                     49:  * The offset isn't known when it is first entered into the symbol table
                     50:  * since the types are read later.
                     51:  */
                     52: 
                     53: fixarg(p)
                     54: struct symtab *p;
                     55: {
                     56:     if (oldway) {
                     57:        old_fixarg(p);
                     58:     } else if (gdebug) {
                     59:        printf("\t.stabs\t\"%s:p", p->sname);
                     60:        gentype(p);
                     61:        printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
                     62:     }
                     63: }
                     64: 
                     65: /*
                     66:  * Determine if the given symbol is a global array with dimension 0,
                     67:  * which only makes sense if it's dimension is to be given later.
                     68:  * We therefore currently do not generate symbol information for
                     69:  * such entries.
                     70:  */
                     71: 
                     72: #define isglobal(class) ( \
                     73:     class == EXTDEF or class == EXTERN or class == STATIC \
                     74: )
                     75: 
                     76: private Boolean zero_length_array(p)
                     77: register struct symtab *p;
                     78: {
                     79:     Boolean b;
                     80:     int t;
                     81: 
                     82:     if (not isglobal(p->sclass)) {
                     83:        b = false;
                     84:     } else {
                     85:        t = p->stype;
                     86:        if (ISFTN(t)) {
                     87:            t = DECREF(t);
                     88:        }
                     89:        b = (Boolean) (ISARY(t) and dimtab[p->dimoff] == 0);
                     90:     }
                     91:     return b;
                     92: }
                     93: 
                     94: /*
                     95:  * Generate debugging info for a given symbol.
                     96:  */
                     97: 
                     98: outstab(sym)
                     99: struct symtab *sym;
                    100: {
                    101:     register struct symtab *p;
                    102:     char *classname;
                    103:     Boolean ignore;
                    104:     static Boolean firsttime = true;
                    105: 
                    106:     if (oldway) {
                    107:        old_outstab(sym);
                    108:     } else if (gdebug and not zero_length_array(sym)) {
                    109:        if (firsttime) {
                    110:            firsttime = false;
                    111:            inittypes();
                    112:        }
                    113:        ignore = false;
                    114:        p = sym;
                    115:        switch (p->sclass) {
                    116:        case REGISTER:
                    117:            classname = "r";
                    118:            break;
                    119: 
                    120:        /*
                    121:         * Locals are the default class.
                    122:         */
                    123:        case AUTO:
                    124:            classname = "";
                    125:            break;
                    126: 
                    127:        case STATIC:
                    128:            if (ISFTN(p->stype)) {
                    129:                ignore = true;
                    130:            } else if (p->slevel <= 1) {
                    131:                classname = "S";
                    132:            } else {
                    133:                classname = "V";
                    134:            }
                    135:            break;
                    136: 
                    137:        case EXTDEF:
                    138:        case EXTERN:
                    139:            if (ISFTN(p->stype)) {
                    140:                ignore = true;
                    141:            } else {
                    142:                classname = "G";
                    143:            }
                    144:            break;
                    145: 
                    146:        case TYPEDEF:
                    147:            classname = "t";
                    148:            break;
                    149: 
                    150:        case PARAM:
                    151:        case MOS:
                    152:        case MOU:
                    153:        case MOE:
                    154:            ignore = true;
                    155:            break;
                    156: 
                    157:        case ENAME:
                    158:        case UNAME:
                    159:        case STNAME:
                    160:            (void) entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
                    161:            ignore = true;
                    162:            break;
                    163: 
                    164:        default:
                    165:            if ((p->sclass&FIELD) == 0) {
                    166:                printf("/* no info for %s (%d) */\n", p->sname, p->sclass);
                    167:            }
                    168:            ignore = true;
                    169:            break;
                    170:        }
                    171:        if (not ignore) {
                    172:            printf("\t.stabs\t\"%s:%s", p->sname, classname);
                    173:            gentype(p);
                    174:            geninfo(p);
                    175:        }
                    176:     }
                    177: }
                    178: 
                    179: /*
                    180:  * Since type names are lost in the travels and because C has
                    181:  * structural type equivalence we keep a table of type words that
                    182:  * we've already seen.  The first time we see a type, it is assigned
                    183:  * (inline) a number and future references just list that number.
                    184:  * Structures, unions, enums, and arrays must be handled carefully
                    185:  * since not all the necessary information is in the type word.
                    186:  */
                    187: 
                    188: typedef struct Typeid *Typeid;
                    189: 
                    190: struct Typeid {
                    191:     TWORD tword;
                    192:     int tarray;
                    193:     int tstruct;
                    194:     int tstrtag;
                    195:     int tnum;
                    196:     Typeid chain;
                    197: };
                    198: 
                    199: #define TABLESIZE 2003
                    200: 
                    201: private int tcount = 1;
                    202: private int t_int, t_char;
                    203: private Typeid typetable[TABLESIZE];
                    204: 
                    205: /*
                    206:  * Look for the given type word in the type table.
                    207:  */
                    208: 
                    209: private Typeid typelookup(type, arrindex, strindex, strtag)
                    210: TWORD type;
                    211: int arrindex;
                    212: int strindex;
                    213: int strtag;
                    214: {
                    215:     register TWORD tword;
                    216:     register int i1, i2;
                    217:     Typeid t;
                    218: 
                    219:     t = typetable[type mod TABLESIZE];
                    220:     while (t != nil) {
                    221:        if (t->tword == type and
                    222:          strindex == t->tstruct and strtag == t->tstrtag) {
                    223:            if (arrindex == NILINDEX) {
                    224:                break;
                    225:            } else {
                    226:                tword = type;
                    227:                i1 = arrindex;
                    228:                i2 = t->tarray;
                    229:                while (ISARY(tword) and dimtab[i1] == dimtab[i2]) {
                    230:                    ++i1;
                    231:                    ++i2;
                    232:                    tword >>= TSHIFT;
                    233:                }
                    234:                if (!ISARY(tword)) {
                    235:                    break;
                    236:                }
                    237:            }
                    238:        }
                    239:        t = t->chain;
                    240:     }
                    241:     return t;
                    242: }
                    243: 
                    244: /*
                    245:  * Enter a type word and associated symtab indices into the type table.
                    246:  */
                    247: 
                    248: private int entertype(type, arrindex, strindex, strtag)
                    249: TWORD type;
                    250: int arrindex;
                    251: int strindex;
                    252: int strtag;
                    253: {
                    254:     register Typeid t;
                    255:     register int i;
                    256: 
                    257:     t = (Typeid) malloc(sizeof(struct Typeid));
                    258:     t->tword = type;
                    259:     t->tarray = arrindex;
                    260:     t->tstruct = strindex;
                    261:     t->tstrtag = strtag;
                    262:     t->tnum = tcount;
                    263:     ++tcount;
                    264:     i = type mod TABLESIZE;
                    265:     t->chain = typetable[i];
                    266:     typetable[i] = t;
                    267:     return t->tnum;
                    268: }
                    269: 
                    270: /*
                    271:  * Change the information associated with a type table entry.
                    272:  * Since I'm lazy this just creates a new entry with the number
                    273:  * as the old one.
                    274:  */
                    275: 
                    276: private reentertype(typeid, type, arrindex, strindex, strtag)
                    277: Typeid typeid;
                    278: TWORD type;
                    279: int arrindex;
                    280: int strindex;
                    281: int strtag;
                    282: {
                    283:     register Typeid t;
                    284:     register int i;
                    285: 
                    286:     t = (Typeid) malloc(sizeof(struct Typeid));
                    287:     t->tword = type;
                    288:     t->tarray = arrindex;
                    289:     t->tstruct = strindex;
                    290:     t->tstrtag = strtag;
                    291:     t->tnum = typeid->tnum;
                    292:     i = type mod TABLESIZE;
                    293:     t->chain = typetable[i];
                    294:     typetable[i] = t;
                    295: }
                    296: 
                    297: /*
                    298:  * Initialize type table with predefined types.
                    299:  */
                    300: 
                    301: #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX)
                    302: 
                    303: private inittypes()
                    304: {
                    305:     int t;
                    306: 
                    307:     t_int = builtintype(INT);
                    308:     t_char = builtintype(CHAR);
                    309:     maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL);
                    310:     maketype("char", t_char, t_char, 0L, 127L);
                    311:     maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL);
                    312:     maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL);
                    313:     maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L);
                    314:     maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL);
                    315:     maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL);
                    316:     maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL);
                    317:     maketype("float", builtintype(FLOAT), t_int, 4L, 0L);
                    318:     maketype("double", builtintype(DOUBLE), t_int, 8L, 0L);
                    319:     t = builtintype(UNDEF);
                    320:     printf("\t.stabs\t\"void:t%d=%d", t, t);
                    321:     geninfo((struct symtab *)nil);
                    322:     t = builtintype(FARG);
                    323:     printf("\t.stabs\t\"???:t%d=%d", t, t_int);
                    324:     geninfo((struct symtab *)nil);
                    325: }
                    326: 
                    327: /*
                    328:  * Generate info for a new range type.
                    329:  */
                    330: 
                    331: private maketype(name, tnum, eqtnum, lower, upper)
                    332: char *name;
                    333: int tnum, eqtnum;
                    334: long lower, upper;
                    335: {
                    336:     printf("\t.stabs\t\"%s:t%d=r%d;%d;%d;", name, tnum, eqtnum, lower, upper);
                    337:     geninfo((struct symtab *)nil);
                    338: }
                    339: 
                    340: /*
                    341:  * Generate debugging information for the given type of the given symbol.
                    342:  */
                    343: 
                    344: private gentype(sym)
                    345: struct symtab *sym;
                    346: {
                    347:     register struct symtab *p;
                    348:     register TWORD t;
                    349:     register TWORD basictype;
                    350:     register Typeid typeid;
                    351:     int i, arrindex, strindex, strtag;
                    352: 
                    353:     p = sym;
                    354:     t = p->stype;
                    355:     if (ISFTN(t)) {
                    356:        t = DECREF(t);
                    357:     }
                    358:     basictype = BTYPE(t);
                    359:     if (ISARY(t)) {
                    360:        arrindex = p->dimoff;
                    361:     } else {
                    362:        arrindex = NILINDEX;
                    363:     }
                    364:     if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) {
                    365:        strindex = dimtab[p->sizoff + 1];
                    366:        if (strindex == -1) {
                    367:            strindex = FORWARD;
                    368:            strtag = dimtab[p->sizoff + 3];
                    369:        } else {
                    370:            strtag = NILINDEX;
                    371:        }
                    372:     } else {
                    373:        strindex = NILINDEX;
                    374:        strtag = NILINDEX;
                    375:     }
                    376:     i = arrindex;
                    377:     typeid = typelookup(t, arrindex, strindex, strtag);
                    378:     while (t != basictype and typeid == nil) {
                    379:        printf("%d=", entertype(t, i, strindex, strtag));
                    380:        switch (t&TMASK) {
                    381:        case PTR:
                    382:            printf("*");
                    383:            break;
                    384: 
                    385:        case FTN:
                    386:            printf("f");
                    387:            break;
                    388: 
                    389:        case ARY:
                    390:            printf("ar%d;0;%d;", t_int, dimtab[i++] - 1);
                    391:            break;
                    392:        }
                    393:        t = DECREF(t);
                    394:        if (i == NILINDEX && ISARY(t)) {
                    395:            i = p->dimoff;
                    396:        }
                    397:        if (t == basictype) {
                    398:            typeid = typelookup(t, NILINDEX, strindex, strtag);
                    399:        } else {
                    400:            typeid = typelookup(t, i, strindex, strtag);
                    401:        }
                    402:     }
                    403:     if (typeid == nil) {
                    404:        if (strindex == FORWARD) {
                    405:            typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
                    406:            if (typeid == nil) {
                    407:                cerror("unbelievable forward reference");
                    408:            }
                    409:            printf("%d", typeid->tnum);
                    410:        } else {
                    411:            genstruct(t, NILINDEX, strindex, p->sname, bsize(p));
                    412:        }
                    413:     } else {
                    414:        printf("%d", typeid->tnum);
                    415:     }
                    416: }
                    417: 
                    418: /*
                    419:  * Generate type information for structures, unions, and enumerations.
                    420:  */
                    421: 
                    422: private genstruct(t, structid, index, name, size)
                    423: TWORD t;
                    424: int structid;
                    425: int index;
                    426: char *name;
                    427: int size;
                    428: {
                    429:     register int i;
                    430:     register struct symtab *field;
                    431:     int id;
                    432: 
                    433:     if (structid == NILINDEX) {
                    434:        id = entertype(t, NILINDEX, index, NILINDEX);
                    435:     } else {
                    436:        id = structid;
                    437:     }
                    438:     switch (t) {
                    439:     case STRTY:
                    440:     case UNIONTY:
                    441:        printf("%d=%c%d", id, t == STRTY ? 's' : 'u', size);
                    442:        i = index;
                    443:        while (dimtab[i] != -1) {
                    444:            field = &stab[dimtab[i]];
                    445:            printf("%s:", field->sname);
                    446:            gentype(field);
                    447:            if (field->sclass > FIELD) {
                    448:                printf(",%d,%d;", field->offset, field->sclass - FIELD);
                    449:            } else {
                    450:                printf(",%d,%d;", field->offset,
                    451:                    tsize(field->stype, field->dimoff, field->sizoff));
                    452:            }
                    453:            ++i;
                    454:        }
                    455:        putchar(';');
                    456:        break;
                    457: 
                    458:     case ENUMTY:
                    459:        printf("%d=e", id);
                    460:        i = index;
                    461:        while (dimtab[i] != -1) {
                    462:            field = &stab[dimtab[i]];
                    463:            printf("%s:%d,", field->sname, field->offset);
                    464:            i++;
                    465:        }
                    466:        putchar(';');
                    467:        break;
                    468: 
                    469:     default:
                    470:        cerror("couldn't find basic type %d for %s\n", t, name);
                    471:        break;
                    472:     }
                    473: }
                    474: 
                    475: /*
                    476:  * Generate offset and size info.
                    477:  */
                    478: 
                    479: private geninfo(p)
                    480: register struct symtab *p;
                    481: {
                    482:     int stabtype;
                    483: 
                    484:     if (p == nil) {
                    485:        printf("\",0x%x,0,0,0\n", N_LSYM);
                    486:     } else {
                    487:        switch (p->sclass) {
                    488:            case EXTERN:
                    489:            case EXTDEF:
                    490:                if (ISFTN(p->stype)) {
                    491:                    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
                    492:                } else {
                    493:                    printf("\",0x%x,0,%d,0\n", N_GSYM, bsize(p));
                    494:                }
                    495:                break;
                    496: 
                    497:            case STATIC:
                    498:                stabtype = stabLCSYM ? N_LCSYM : N_STSYM;
                    499:                if (ISFTN(p->stype)) {
                    500:                    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
                    501:                } else if (p->slevel > 1) {
                    502:                    printf("\",0x%x,0,%d,L%d\n", stabtype, bsize(p), p->offset);
                    503:                } else {
                    504:                    printf("\",0x%x,0,%d,_%s\n", stabtype, bsize(p), p->sname);
                    505:                }
                    506:                break;
                    507: 
                    508:            case REGISTER:
                    509:                printf("\",0x%x,0,%d,%d\n", N_RSYM, bsize(p), p->offset);
                    510:                break;
                    511: 
                    512:            case PARAM:
                    513:                printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
                    514:                break;
                    515: 
                    516:            default:
                    517:                printf("\",0x%x,0,%d,%d\n", N_LSYM, bsize(p), bytes(p->offset));
                    518:                break;
                    519:        }
                    520:     }
                    521: }
                    522: 
                    523: /*
                    524:  * Generate information for a newly-defined structure.
                    525:  */
                    526: 
                    527: /*ARGSUSED*/
                    528: outstruct(szindex, paramindex)
                    529: int szindex, paramindex;
                    530: {
                    531:     register Typeid typeid;
                    532:     register struct symtab *p;
                    533:     register int i, t, strindex;
                    534: 
                    535:     if (oldway) {
                    536:        /* do nothing */;
                    537:     } else if (gdebug) {
                    538:        if ((i = dimtab[szindex + 3]) >= 0 && (p = &stab[i])->sname != nil) {
                    539:            strindex = dimtab[p->sizoff + 1];
                    540:            typeid = typelookup(p->stype, NILINDEX, FORWARD, i);
                    541:            if (typeid == nil) {
                    542:                t = 0;
                    543:            } else {
                    544:                t = typeid->tnum;
                    545:                reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX);
                    546:            }
                    547:            printf("\t.stabs\t\"%s:T", p->sname);
                    548:            genstruct(p->stype, t, strindex, p->sname, bsize(p));
                    549:            geninfo(p);
                    550:        }
                    551:     }
                    552: }
                    553: 
                    554: pstab(name, type)
                    555: char *name;
                    556: int type;
                    557: {
                    558: #ifndef ASSTRINGS
                    559:     register int i;
                    560:     register char c;
                    561: #endif
                    562: 
                    563:     if (!gdebug) {
                    564:        return;
                    565:     } else if (oldway) {
                    566:        old_pstab(name, type);
                    567:        return;
                    568:     }
                    569:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    570: #ifdef ASSTRINGS
                    571:     if ( name[0] == '\0')
                    572:        printf("\t.stabn\t");
                    573:     else
                    574: #ifndef FLEXNAMES
                    575:        printf("\t.stabs\t\"%.8s\",", name);
                    576: #else
                    577:        printf("\t.stabs\t\"%s\",", name);
                    578: #endif
                    579: #else
                    580:     printf("    .stab   ");
                    581:     for(i=0; i<8; i++) 
                    582:        if (c = name[i]) printf("'%c,", c);
                    583:        else printf("0,");
                    584: #endif
                    585:     printf("0%o,", type);
                    586: }
                    587: 
                    588: #ifdef STABDOT
                    589: pstabdot(type, value)
                    590: int type;
                    591: int value;
                    592: {
                    593:     if ( ! gdebug) {
                    594:        return;
                    595:     } else if (oldway) {
                    596:        old_pstabdot(type, value);
                    597:        return;
                    598:     }
                    599:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    600:     printf("\t.stabd\t");
                    601:     printf("0%o,0,0%o\n",type, value);
                    602: }
                    603: #endif
                    604: 
                    605: #ifndef STABDOT
                    606: extern char NULLNAME[8];
                    607: #endif
                    608: extern int  labelno;
                    609: extern int  fdefflag;
                    610: 
                    611: psline()
                    612: {
                    613:     static int lastlineno;
                    614:     register char *cp, *cq;
                    615:     register int i;
                    616:     
                    617:     if (!gdebug) {
                    618:        return;
                    619:     } else if (oldway) {
                    620:        old_psline();
                    621:        return;
                    622:     }
                    623: 
                    624:     cq = ititle;
                    625:     cp = ftitle;
                    626: 
                    627:     while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
                    628:     if ( *cp == '\0' ) goto eq;
                    629:     
                    630: neq:    for (i=0; i<100; i++)
                    631:        ititle[i] = '\0';
                    632:     cp = ftitle;
                    633:     cq = ititle;
                    634:     while ( *cp )  
                    635:        *cq++ = *cp++;
                    636:     *cq = '\0';
                    637:     *--cq = '\0';
                    638: #ifndef FLEXNAMES
                    639:     for ( cp = ititle+1; *(cp-1); cp += 8 ) {
                    640:        pstab(cp, N_SOL);
                    641:        if (gdebug) printf("0,0,LL%d\n", labelno);
                    642:     }
                    643: #else
                    644:     pstab(ititle+1, N_SOL);
                    645:     if (gdebug) printf("0,0,LL%d\n", labelno);
                    646: #endif
                    647:     *cq = '"';
                    648:     printf("LL%d:\n", labelno++);
                    649: 
                    650: eq: if (lineno == lastlineno) return;
                    651:     lastlineno = lineno;
                    652: 
                    653:     if (fdefflag) {
                    654: #ifdef STABDOT
                    655:        pstabdot(N_SLINE, lineno);
                    656: #else
                    657:        pstab(NULLNAME, N_SLINE);
                    658:        printf("0,%d,LL%d\n", lineno, labelno);
                    659:        printf("LL%d:\n", labelno++);
                    660: #endif
                    661:     }
                    662: }
                    663:     
                    664: plcstab(level)
                    665: int level;
                    666: {
                    667:     if (!gdebug) {
                    668:        return;
                    669:     } else if (oldway) {
                    670:        old_plcstab(level);
                    671:        return;
                    672:     }
                    673: #ifdef STABDOT
                    674:     pstabdot(N_LBRAC, level);
                    675: #else
                    676:     pstab(NULLNAME, N_LBRAC);
                    677:     printf("0,%d,LL%d\n", level, labelno);
                    678:     printf("LL%d:\n", labelno++);
                    679: #endif
                    680: }
                    681:     
                    682: prcstab(level)
                    683: int level;
                    684: {
                    685:     if (!gdebug) {
                    686:        return;
                    687:     } else if (oldway) {
                    688:        old_prcstab(level);
                    689:        return;
                    690:     }
                    691: #ifdef STABDOT
                    692:     pstabdot(N_RBRAC, level);
                    693: #else
                    694:     pstab(NULLNAME, N_RBRAC);
                    695:     printf("0,%d,LL%d\n", level, labelno);
                    696:     printf("LL%d:\n", labelno++);
                    697: #endif
                    698: }
                    699:     
                    700: pfstab(sname) 
                    701: char *sname;
                    702: {
                    703:     register struct symtab *p;
                    704: 
                    705:     if (gdebug) {
                    706:        if (oldway) {
                    707:            old_pfstab(sname);
                    708:        } else {
                    709:            p = &stab[lookup(sname, 0)];
                    710:            printf("\t.stabs\t\"%s:", p->sname);
                    711:            putchar((p->sclass == STATIC) ? 'f' : 'F');
                    712:            gentype(p);
                    713:            geninfo(p);
                    714:        }
                    715:     }
                    716: }
                    717: 
                    718: /*
                    719:  * Old way of doing things.
                    720:  */
                    721: 
                    722: private old_fixarg(p)
                    723: struct symtab *p; {
                    724:        if (gdebug) {
                    725:                old_pstab(p->sname, N_PSYM);
                    726:                if (gdebug) printf("0,%d,%d\n", p->stype, argoff/SZCHAR);
                    727:                old_poffs(p);
                    728:        }
                    729: }
                    730: 
                    731: private old_outstab(p)
                    732: struct symtab *p; {
                    733:        register TWORD ptype;
                    734:        register char *pname;
                    735:        register char pclass;
                    736:        register int poffset;
                    737: 
                    738:        if (!gdebug) return;
                    739: 
                    740:        ptype = p->stype;
                    741:        pname = p->sname;
                    742:        pclass = p->sclass;
                    743:        poffset = p->offset;
                    744: 
                    745:        if (ISFTN(ptype)) {
                    746:                return;
                    747:        }
                    748:        
                    749:        switch (pclass) {
                    750:        
                    751:        case AUTO:
                    752:                old_pstab(pname, N_LSYM);
                    753:                printf("0,%d,%d\n", ptype, (-poffset)/SZCHAR);
                    754:                old_poffs(p);
                    755:                return;
                    756:        
                    757:        case EXTDEF:
                    758:        case EXTERN:
                    759:                old_pstab(pname, N_GSYM);
                    760:                printf("0,%d,0\n", ptype);
                    761:                old_poffs(p);
                    762:                return;
                    763:                        
                    764:        case STATIC:
                    765: #ifdef LCOMM
                    766:                /* stabLCSYM is 1 during nidcl so we can get stab type right */
                    767:                old_pstab(pname, stabLCSYM ? N_LCSYM : N_STSYM);
                    768: #else
                    769:                old_pstab(pname, N_STSYM);
                    770: #endif
                    771:                if (p->slevel > 1) {
                    772:                        printf("0,%d,L%d\n", ptype, poffset);
                    773:                } else {
                    774:                        printf("0,%d,%s\n", ptype, exname(pname));
                    775:                }
                    776:                old_poffs(p);
                    777:                return;
                    778:        
                    779:        case REGISTER:
                    780:                old_pstab(pname, N_RSYM);
                    781:                printf("0,%d,%d\n", ptype, poffset);
                    782:                old_poffs(p);
                    783:                return;
                    784:        
                    785:        case MOS:
                    786:        case MOU:
                    787:                old_pstab(pname, N_SSYM);
                    788:                printf("0,%d,%d\n", ptype, poffset/SZCHAR);
                    789:                old_poffs(p);
                    790:                return;
                    791:        
                    792:        case PARAM:
                    793:                /* parameter stab entries are processed in dclargs() */
                    794:                return;
                    795:        
                    796:        default:
                    797: #ifndef FLEXNAMES
                    798:                if (ddebug) printf("    No .stab for %.8s\n", pname);
                    799: #else
                    800:                if (ddebug) printf("    No .stab for %s\n", pname);
                    801: #endif
                    802:                
                    803:        }
                    804: }
                    805: 
                    806: private old_pstab(name, type)
                    807: char *name;
                    808: int type; {
                    809: #ifndef ASSTRINGS
                    810:        register int i;
                    811:        register char c;
                    812: #endif
                    813:        if (!gdebug) return;
                    814:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    815: #ifdef ASSTRINGS
                    816:        if ( name[0] == '\0')
                    817:                printf("\t.stabn\t");
                    818:        else
                    819: #ifndef FLEXNAMES
                    820:                printf("\t.stabs\t\"%.8s\", ", name);
                    821: #else
                    822:                printf("\t.stabs\t\"%s\", ", name);
                    823: #endif
                    824: #else
                    825:        printf("        .stab   ");
                    826:        for(i=0; i<8; i++) 
                    827:                if (c = name[i]) printf("'%c,", c);
                    828:                else printf("0,");
                    829: #endif
                    830:        printf("0%o,", type);
                    831: }
                    832: 
                    833: #ifdef STABDOT
                    834: private old_pstabdot(type, value)
                    835:        int     type;
                    836:        int     value;
                    837: {
                    838:        if ( ! gdebug) return;
                    839:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    840:        printf("\t.stabd\t");
                    841:        printf("0%o,0,0%o\n",type, value);
                    842: }
                    843: #endif
                    844: 
                    845: private old_poffs(p)
                    846: register struct symtab *p; {
                    847:        int s;
                    848:        if (!gdebug) return;
                    849:        if ((s = dimtab[p->sizoff]/SZCHAR) > 1) {
                    850:                old_pstab(p->sname, N_LENG);
                    851:                printf("1,0,%d\n", s);
                    852:        }
                    853: }
                    854: 
                    855: private old_psline() {
                    856:        static int lastlineno;
                    857:        register char *cp, *cq;
                    858:        register int i;
                    859:        
                    860:        if (!gdebug) return;
                    861: 
                    862:        cq = ititle;
                    863:        cp = ftitle;
                    864: 
                    865:        while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
                    866:        if ( *cp == '\0' ) goto eq;
                    867:        
                    868: neq:   for (i=0; i<100; i++)
                    869:                ititle[i] = '\0';
                    870:        cp = ftitle;
                    871:        cq = ititle;
                    872:        while ( *cp )  
                    873:                *cq++ = *cp++;
                    874:        *cq = '\0';
                    875:        *--cq = '\0';
                    876: #ifndef FLEXNAMES
                    877:        for ( cp = ititle+1; *(cp-1); cp += 8 ) {
                    878:                old_pstab(cp, N_SOL);
                    879:                if (gdebug) printf("0,0,LL%d\n", labelno);
                    880:                }
                    881: #else
                    882:        old_pstab(ititle+1, N_SOL);
                    883:        if (gdebug) printf("0,0,LL%d\n", labelno);
                    884: #endif
                    885:        *cq = '"';
                    886:        printf("LL%d:\n", labelno++);
                    887: 
                    888: eq:    if (lineno == lastlineno) return;
                    889:        lastlineno = lineno;
                    890: 
                    891:        if (fdefflag) {
                    892: #ifdef STABDOT
                    893:                old_pstabdot(N_SLINE, lineno);
                    894: #else
                    895:                old_pstab(NULLNAME, N_SLINE);
                    896:                printf("0,%d,LL%d\n", lineno, labelno);
                    897:                printf("LL%d:\n", labelno++);
                    898: #endif
                    899:                }
                    900:        }
                    901:        
                    902: private old_plcstab(level) {
                    903:        if (!gdebug) return;
                    904: #ifdef STABDOT
                    905:        old_pstabdot(N_LBRAC, level);
                    906: #else
                    907:        old_pstab(NULLNAME, N_LBRAC);
                    908:        printf("0,%d,LL%d\n", level, labelno);
                    909:        printf("LL%d:\n", labelno++);
                    910: #endif
                    911:        }
                    912:        
                    913: private old_prcstab(level) {
                    914:        if (!gdebug) return;
                    915: #ifdef STABDOT
                    916:        pstabdot(N_RBRAC, level);
                    917: #else
                    918:        pstab(NULLNAME, N_RBRAC);
                    919:        printf("0,%d,LL%d\n", level, labelno);
                    920:        printf("LL%d:\n", labelno++);
                    921: #endif
                    922:        }
                    923:        
                    924: private old_pfstab(sname) 
                    925: char *sname; {
                    926:        if (!gdebug) return;
                    927:        pstab(sname, N_FUN);
                    928: #ifndef FLEXNAMES
                    929:        printf("0,%d,_%.7s\n", lineno, sname);
                    930: #else
                    931:        printf("0,%d,_%s\n", lineno, sname);
                    932: #endif
                    933: }

unix.superglobalmegacorp.com

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