Annotation of 43BSD/lib/pcc/stab.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid ="@(#)stab.c       1.12 (Berkeley) 3/27/86";
                      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:     int offset;
                    104:     Boolean ignore;
                    105:     static Boolean firsttime = true;
                    106: 
                    107:     if (oldway) {
                    108:        old_outstab(sym);
                    109:     } else if (gdebug and not zero_length_array(sym)) {
                    110:        if (firsttime) {
                    111:            firsttime = false;
                    112:            inittypes();
                    113:        }
                    114:        ignore = false;
                    115:        p = sym;
                    116:        offset = bytes(p->offset);
                    117:        switch (p->sclass) {
                    118:        case REGISTER:
                    119:            classname = "r";
                    120:            offset = p->offset;
                    121:            break;
                    122: 
                    123:        /*
                    124:         * Locals are the default class.
                    125:         */
                    126:        case AUTO:
                    127:            classname = "";
                    128:            break;
                    129: 
                    130:        case STATIC:
                    131:            if (ISFTN(p->stype)) {
                    132:                ignore = true;
                    133:            } else if (p->slevel <= 1) {
                    134:                classname = "S";
                    135:            } else {
                    136:                classname = "V";
                    137:            }
                    138:            break;
                    139: 
                    140:        case EXTDEF:
                    141:        case EXTERN:
                    142:            if (ISFTN(p->stype)) {
                    143:                ignore = true;
                    144:            } else {
                    145:                classname = "G";
                    146:            }
                    147:            break;
                    148: 
                    149:        case TYPEDEF:
                    150:            classname = "t";
                    151:            break;
                    152: 
                    153:        case PARAM:
                    154:        case MOS:
                    155:        case MOU:
                    156:        case MOE:
                    157:            ignore = true;
                    158:            break;
                    159: 
                    160:        case ENAME:
                    161:        case UNAME:
                    162:        case STNAME:
                    163:            entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
                    164:            ignore = true;
                    165:            break;
                    166: 
                    167:        default:
                    168:            if ((p->sclass&FIELD) == 0) {
                    169:                printf("/* no info for %s (%d) */\n", p->sname, p->sclass);
                    170:            }
                    171:            ignore = true;
                    172:            break;
                    173:        }
                    174:        if (not ignore) {
                    175:            printf("\t.stabs\t\"%s:%s", p->sname, classname);
                    176:            gentype(p);
                    177:            geninfo(p);
                    178:        }
                    179:     }
                    180: }
                    181: 
                    182: /*
                    183:  * Since type names are lost in the travels and because C has
                    184:  * structural type equivalence we keep a table of type words that
                    185:  * we've already seen.  The first time we see a type, it is assigned
                    186:  * (inline) a number and future references just list that number.
                    187:  * Structures, unions, enums, and arrays must be handled carefully
                    188:  * since not all the necessary information is in the type word.
                    189:  */
                    190: 
                    191: typedef struct Typeid *Typeid;
                    192: 
                    193: struct Typeid {
                    194:     TWORD tword;
                    195:     int tarray;
                    196:     int tstruct;
                    197:     int tstrtag;
                    198:     int tnum;
                    199:     Typeid chain;
                    200: };
                    201: 
                    202: #define TABLESIZE 2003
                    203: 
                    204: private int tcount = 1;
                    205: private int t_int, t_char;
                    206: private Typeid typetable[TABLESIZE];
                    207: 
                    208: /*
                    209:  * Look for the given type word in the type table.
                    210:  */
                    211: 
                    212: private Typeid typelookup(type, arrindex, strindex, strtag)
                    213: TWORD type;
                    214: int arrindex;
                    215: int strindex;
                    216: int strtag;
                    217: {
                    218:     register TWORD tword;
                    219:     register int i1, i2;
                    220:     Typeid t;
                    221: 
                    222:     t = typetable[type mod TABLESIZE];
                    223:     while (t != nil) {
                    224:        if (t->tword == type and
                    225:          strindex == t->tstruct and strtag == t->tstrtag) {
                    226:            if (arrindex == NILINDEX) {
                    227:                break;
                    228:            } else {
                    229:                tword = type;
                    230:                i1 = arrindex;
                    231:                i2 = t->tarray;
                    232:                while (ISARY(tword) and dimtab[i1] == dimtab[i2]) {
                    233:                    ++i1;
                    234:                    ++i2;
                    235:                    tword >>= TSHIFT;
                    236:                }
                    237:                if (!ISARY(tword)) {
                    238:                    break;
                    239:                }
                    240:            }
                    241:        }
                    242:        t = t->chain;
                    243:     }
                    244:     return t;
                    245: }
                    246: 
                    247: /*
                    248:  * Enter a type word and associated symtab indices into the type table.
                    249:  */
                    250: 
                    251: private int entertype(type, arrindex, strindex, strtag)
                    252: TWORD type;
                    253: int arrindex;
                    254: int strindex;
                    255: int strtag;
                    256: {
                    257:     register Typeid t;
                    258:     register int i;
                    259: 
                    260:     t = (Typeid) malloc(sizeof(struct Typeid));
                    261:     t->tword = type;
                    262:     t->tarray = arrindex;
                    263:     t->tstruct = strindex;
                    264:     t->tstrtag = strtag;
                    265:     t->tnum = tcount;
                    266:     ++tcount;
                    267:     i = type mod TABLESIZE;
                    268:     t->chain = typetable[i];
                    269:     typetable[i] = t;
                    270:     return t->tnum;
                    271: }
                    272: 
                    273: /*
                    274:  * Change the information associated with a type table entry.
                    275:  * Since I'm lazy this just creates a new entry with the number
                    276:  * as the old one.
                    277:  */
                    278: 
                    279: private reentertype(typeid, type, arrindex, strindex, strtag)
                    280: Typeid typeid;
                    281: TWORD type;
                    282: int arrindex;
                    283: int strindex;
                    284: int strtag;
                    285: {
                    286:     register Typeid t;
                    287:     register int i;
                    288: 
                    289:     t = (Typeid) malloc(sizeof(struct Typeid));
                    290:     t->tword = type;
                    291:     t->tarray = arrindex;
                    292:     t->tstruct = strindex;
                    293:     t->tstrtag = strtag;
                    294:     t->tnum = typeid->tnum;
                    295:     i = type mod TABLESIZE;
                    296:     t->chain = typetable[i];
                    297:     typetable[i] = t;
                    298: }
                    299: 
                    300: /*
                    301:  * Initialize type table with predefined types.
                    302:  */
                    303: 
                    304: #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX)
                    305: 
                    306: private inittypes()
                    307: {
                    308:     int t;
                    309: 
                    310:     t_int = builtintype(INT);
                    311:     t_char = builtintype(CHAR);
                    312:     maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL);
                    313:     maketype("char", t_char, t_char, 0L, 127L);
                    314:     maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL);
                    315:     maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL);
                    316:     maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L);
                    317:     maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL);
                    318:     maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL);
                    319:     maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL);
                    320:     maketype("float", builtintype(FLOAT), t_int, 4L, 0L);
                    321:     maketype("double", builtintype(DOUBLE), t_int, 8L, 0L);
                    322:     t = builtintype(UNDEF);
                    323:     printf("\t.stabs\t\"void:t%d=%d", t, t);
                    324:     geninfo(nil);
                    325:     t = builtintype(FARG);
                    326:     printf("\t.stabs\t\"???:t%d=%d", t, t_int);
                    327:     geninfo(nil);
                    328: }
                    329: 
                    330: /*
                    331:  * Generate info for a new range type.
                    332:  */
                    333: 
                    334: private maketype(name, tnum, eqtnum, lower, upper)
                    335: char *name;
                    336: int tnum, eqtnum;
                    337: long lower, upper;
                    338: {
                    339:     printf("\t.stabs\t\"%s:t%d=r%d;%d;%d;", name, tnum, eqtnum, lower, upper);
                    340:     geninfo(nil);
                    341: }
                    342: 
                    343: /*
                    344:  * Generate debugging information for the given type of the given symbol.
                    345:  */
                    346: 
                    347: private gentype(sym)
                    348: struct symtab *sym;
                    349: {
                    350:     register struct symtab *p;
                    351:     register TWORD t;
                    352:     register TWORD basictype;
                    353:     register Typeid typeid;
                    354:     int i, arrindex, strindex, strtag;
                    355: 
                    356:     p = sym;
                    357:     t = p->stype;
                    358:     if (ISFTN(t)) {
                    359:        t = DECREF(t);
                    360:     }
                    361:     basictype = BTYPE(t);
                    362:     if (ISARY(t)) {
                    363:        arrindex = p->dimoff;
                    364:     } else {
                    365:        arrindex = NILINDEX;
                    366:     }
                    367:     if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) {
                    368:        strindex = dimtab[p->sizoff + 1];
                    369:        if (strindex == -1) {
                    370:            strindex = FORWARD;
                    371:            strtag = dimtab[p->sizoff + 3];
                    372:        } else {
                    373:            strtag = NILINDEX;
                    374:        }
                    375:     } else {
                    376:        strindex = NILINDEX;
                    377:        strtag = NILINDEX;
                    378:     }
                    379:     i = arrindex;
                    380:     typeid = typelookup(t, arrindex, strindex, strtag);
                    381:     while (t != basictype and typeid == nil) {
                    382:        printf("%d=", entertype(t, i, strindex, strtag));
                    383:        switch (t&TMASK) {
                    384:        case PTR:
                    385:            printf("*");
                    386:            break;
                    387: 
                    388:        case FTN:
                    389:            printf("f");
                    390:            break;
                    391: 
                    392:        case ARY:
                    393:            printf("ar%d;0;%d;", t_int, dimtab[i++] - 1);
                    394:            break;
                    395:        }
                    396:        t = DECREF(t);
                    397:        if (i == NILINDEX && ISARY(t)) {
                    398:            i = p->dimoff;
                    399:        }
                    400:        if (t == basictype) {
                    401:            typeid = typelookup(t, NILINDEX, strindex, strtag);
                    402:        } else {
                    403:            typeid = typelookup(t, i, strindex, strtag);
                    404:        }
                    405:     }
                    406:     if (typeid == nil) {
                    407:        if (strindex == FORWARD) {
                    408:            typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
                    409:            if (typeid == nil) {
                    410:                cerror("unbelievable forward reference");
                    411:            }
                    412:            printf("%d", typeid->tnum);
                    413:        } else {
                    414:            genstruct(t, NILINDEX, strindex, p->sname, bsize(p));
                    415:        }
                    416:     } else {
                    417:        printf("%d", typeid->tnum);
                    418:     }
                    419: }
                    420: 
                    421: /*
                    422:  * Generate type information for structures, unions, and enumerations.
                    423:  */
                    424: 
                    425: private genstruct(t, structid, index, name, size)
                    426: TWORD t;
                    427: int structid;
                    428: int index;
                    429: char *name;
                    430: int size;
                    431: {
                    432:     register int i;
                    433:     register struct symtab *field;
                    434:     int id;
                    435: 
                    436:     if (structid == NILINDEX) {
                    437:        id = entertype(t, NILINDEX, index, NILINDEX);
                    438:     } else {
                    439:        id = structid;
                    440:     }
                    441:     switch (t) {
                    442:     case STRTY:
                    443:     case UNIONTY:
                    444:        printf("%d=%c%d", id, t == STRTY ? 's' : 'u', size);
                    445:        i = index;
                    446:        while (dimtab[i] != -1) {
                    447:            field = &stab[dimtab[i]];
                    448:            printf("%s:", field->sname);
                    449:            gentype(field);
                    450:            if (field->sclass > FIELD) {
                    451:                printf(",%d,%d;", field->offset, field->sclass - FIELD);
                    452:            } else {
                    453:                printf(",%d,%d;", field->offset,
                    454:                    tsize(field->stype, field->dimoff, field->sizoff));
                    455:            }
                    456:            ++i;
                    457:        }
                    458:        putchar(';');
                    459:        break;
                    460: 
                    461:     case ENUMTY:
                    462:        printf("%d=e", id);
                    463:        i = index;
                    464:        while (dimtab[i] != -1) {
                    465:            field = &stab[dimtab[i]];
                    466:            printf("%s:%d,", field->sname, field->offset);
                    467:            i++;
                    468:        }
                    469:        putchar(';');
                    470:        break;
                    471: 
                    472:     default:
                    473:        cerror("couldn't find basic type %d for %s\n", t, name);
                    474:        break;
                    475:     }
                    476: }
                    477: 
                    478: /*
                    479:  * Generate offset and size info.
                    480:  */
                    481: 
                    482: private geninfo(p)
                    483: register struct symtab *p;
                    484: {
                    485:     int stabtype;
                    486: 
                    487:     if (p == nil) {
                    488:        printf("\",0x%x,0,0,0\n", N_LSYM);
                    489:     } else {
                    490:        switch (p->sclass) {
                    491:            case EXTERN:
                    492:            case EXTDEF:
                    493:                if (ISFTN(p->stype)) {
                    494:                    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
                    495:                } else {
                    496:                    printf("\",0x%x,0,%d,0\n", N_GSYM, bsize(p));
                    497:                }
                    498:                break;
                    499: 
                    500:            case STATIC:
                    501:                stabtype = stabLCSYM ? N_LCSYM : N_STSYM;
                    502:                if (ISFTN(p->stype)) {
                    503:                    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
                    504:                } else if (p->slevel > 1) {
                    505:                    printf("\",0x%x,0,%d,L%d\n", stabtype, bsize(p), p->offset);
                    506:                } else {
                    507:                    printf("\",0x%x,0,%d,_%s\n", stabtype, bsize(p), p->sname);
                    508:                }
                    509:                break;
                    510: 
                    511:            case REGISTER:
                    512:                printf("\",0x%x,0,%d,%d\n", N_RSYM, bsize(p), p->offset);
                    513:                break;
                    514: 
                    515:            case PARAM:
                    516:                printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
                    517:                break;
                    518: 
                    519:            default:
                    520:                printf("\",0x%x,0,%d,%d\n", N_LSYM, bsize(p), bytes(p->offset));
                    521:                break;
                    522:        }
                    523:     }
                    524: }
                    525: 
                    526: /*
                    527:  * Generate information for a newly-defined structure.
                    528:  */
                    529: 
                    530: outstruct(szindex, paramindex)
                    531: int szindex, paramindex;
                    532: {
                    533:     register Typeid typeid;
                    534:     register struct symtab *p;
                    535:     register int i, t, strindex;
                    536: 
                    537:     if (oldway) {
                    538:        /* do nothing */;
                    539:     } else if (gdebug) {
                    540:        i = dimtab[szindex + 3];
                    541:        p = &stab[i];
                    542:        if (p->sname != nil) {
                    543:            strindex = dimtab[p->sizoff + 1];
                    544:            typeid = typelookup(p->stype, NILINDEX, FORWARD, i);
                    545:            if (typeid == nil) {
                    546:                t = 0;
                    547:            } else {
                    548:                t = typeid->tnum;
                    549:                reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX);
                    550:            }
                    551:            printf("\t.stabs\t\"%s:T", p->sname);
                    552:            genstruct(p->stype, t, strindex, p->sname, bsize(p));
                    553:            geninfo(p);
                    554:        }
                    555:     }
                    556: }
                    557: 
                    558: pstab(name, type)
                    559: char *name;
                    560: int type;
                    561: {
                    562:     register int i;
                    563:     register char c;
                    564: 
                    565:     if (!gdebug) {
                    566:        return;
                    567:     } else if (oldway) {
                    568:        old_pstab(name, type);
                    569:        return;
                    570:     }
                    571:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    572: #ifdef ASSTRINGS
                    573:     if ( name[0] == '\0')
                    574:        printf("\t.stabn\t");
                    575:     else
                    576: #ifndef FLEXNAMES
                    577:        printf("\t.stabs\t\"%.8s\",", name);
                    578: #else
                    579:        printf("\t.stabs\t\"%s\",", name);
                    580: #endif
                    581: #else
                    582:     printf("    .stab   ");
                    583:     for(i=0; i<8; i++) 
                    584:        if (c = name[i]) printf("'%c,", c);
                    585:        else printf("0,");
                    586: #endif
                    587:     printf("0%o,", type);
                    588: }
                    589: 
                    590: #ifdef STABDOT
                    591: pstabdot(type, value)
                    592: int type;
                    593: int value;
                    594: {
                    595:     if ( ! gdebug) {
                    596:        return;
                    597:     } else if (oldway) {
                    598:        old_pstabdot(type, value);
                    599:        return;
                    600:     }
                    601:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    602:     printf("\t.stabd\t");
                    603:     printf("0%o,0,0%o\n",type, value);
                    604: }
                    605: #endif
                    606: 
                    607: extern char NULLNAME[8];
                    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:        register int i;
                    810:        register char c;
                    811:        if (!gdebug) return;
                    812:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    813: #ifdef ASSTRINGS
                    814:        if ( name[0] == '\0')
                    815:                printf("\t.stabn\t");
                    816:        else
                    817: #ifndef FLEXNAMES
                    818:                printf("\t.stabs\t\"%.8s\", ", name);
                    819: #else
                    820:                printf("\t.stabs\t\"%s\", ", name);
                    821: #endif
                    822: #else
                    823:        printf("        .stab   ");
                    824:        for(i=0; i<8; i++) 
                    825:                if (c = name[i]) printf("'%c,", c);
                    826:                else printf("0,");
                    827: #endif
                    828:        printf("0%o,", type);
                    829: }
                    830: 
                    831: #ifdef STABDOT
                    832: private old_pstabdot(type, value)
                    833:        int     type;
                    834:        int     value;
                    835: {
                    836:        if ( ! gdebug) return;
                    837:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
                    838:        printf("\t.stabd\t");
                    839:        printf("0%o,0,0%o\n",type, value);
                    840: }
                    841: #endif
                    842: 
                    843: private old_poffs(p)
                    844: register struct symtab *p; {
                    845:        int s;
                    846:        if (!gdebug) return;
                    847:        if ((s = dimtab[p->sizoff]/SZCHAR) > 1) {
                    848:                old_pstab(p->sname, N_LENG);
                    849:                printf("1,0,%d\n", s);
                    850:        }
                    851: }
                    852: 
                    853: private old_psline() {
                    854:        static int lastlineno;
                    855:        register char *cp, *cq;
                    856:        register int i;
                    857:        
                    858:        if (!gdebug) return;
                    859: 
                    860:        cq = ititle;
                    861:        cp = ftitle;
                    862: 
                    863:        while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
                    864:        if ( *cp == '\0' ) goto eq;
                    865:        
                    866: neq:   for (i=0; i<100; i++)
                    867:                ititle[i] = '\0';
                    868:        cp = ftitle;
                    869:        cq = ititle;
                    870:        while ( *cp )  
                    871:                *cq++ = *cp++;
                    872:        *cq = '\0';
                    873:        *--cq = '\0';
                    874: #ifndef FLEXNAMES
                    875:        for ( cp = ititle+1; *(cp-1); cp += 8 ) {
                    876:                old_pstab(cp, N_SOL);
                    877:                if (gdebug) printf("0,0,LL%d\n", labelno);
                    878:                }
                    879: #else
                    880:        old_pstab(ititle+1, N_SOL);
                    881:        if (gdebug) printf("0,0,LL%d\n", labelno);
                    882: #endif
                    883:        *cq = '"';
                    884:        printf("LL%d:\n", labelno++);
                    885: 
                    886: eq:    if (lineno == lastlineno) return;
                    887:        lastlineno = lineno;
                    888: 
                    889:        if (fdefflag) {
                    890: #ifdef STABDOT
                    891:                old_pstabdot(N_SLINE, lineno);
                    892: #else
                    893:                old_pstab(NULLNAME, N_SLINE);
                    894:                printf("0,%d,LL%d\n", lineno, labelno);
                    895:                printf("LL%d:\n", labelno++);
                    896: #endif
                    897:                }
                    898:        }
                    899:        
                    900: private old_plcstab(level) {
                    901:        if (!gdebug) return;
                    902: #ifdef STABDOT
                    903:        old_pstabdot(N_LBRAC, level);
                    904: #else
                    905:        old_pstab(NULLNAME, N_LBRAC);
                    906:        printf("0,%d,LL%d\n", level, labelno);
                    907:        printf("LL%d:\n", labelno++);
                    908: #endif
                    909:        }
                    910:        
                    911: private old_prcstab(level) {
                    912:        if (!gdebug) return;
                    913: #ifdef STABDOT
                    914:        pstabdot(N_RBRAC, level);
                    915: #else
                    916:        pstab(NULLNAME, N_RBRAC);
                    917:        printf("0,%d,LL%d\n", level, labelno);
                    918:        printf("LL%d:\n", labelno++);
                    919: #endif
                    920:        }
                    921:        
                    922: private old_pfstab(sname) 
                    923: char *sname; {
                    924:        if (!gdebug) return;
                    925:        pstab(sname, N_FUN);
                    926: #ifndef FLEXNAMES
                    927:        printf("0,%d,_%.7s\n", lineno, sname);
                    928: #else
                    929:        printf("0,%d,_%s\n", lineno, sname);
                    930: #endif
                    931: }

unix.superglobalmegacorp.com

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