Annotation of researchv9/cmd/sun/pcc/stab.c, revision 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: 
        !             8: 
        !             9: #ifndef lint
        !            10: static char sccsid[] = "@(#)stab.c 1.1 86/02/03 SMI"; /* from UCB X.X XX/XX/XX */
        !            11: #endif
        !            12: #include "cpass1.h"
        !            13: 
        !            14: 
        !            15: #include <sys/types.h>
        !            16: #include <a.out.h>
        !            17: #include "stab.h"
        !            18: 
        !            19: #define private static
        !            20: #define and &&
        !            21: #define or ||
        !            22: #define not !
        !            23: #define div /
        !            24: #define mod %
        !            25: #define nil 0
        !            26: 
        !            27: #define bytes(bits) ((bits) / SZCHAR)
        !            28: #define bsize(p) bytes(dimtab[p->sizoff])      /* size in bytes of a symbol */
        !            29: 
        !            30: #define NILINDEX -1
        !            31: #define FORWARD -2
        !            32: private int nfield;
        !            33: #define NSTABFIELDS 7
        !            34: 
        !            35: typedef int Boolean;
        !            36: #define false 0
        !            37: #define true 1
        !            38: 
        !            39: typedef enum{ xname, lname, value } Valueform;
        !            40: 
        !            41: extern int ddebug;
        !            42: extern int gdebug;
        !            43: extern int optimize;
        !            44: extern char *malloc();
        !            45: extern char *strcpy();
        !            46: 
        !            47: int stabLCSYM;
        !            48: 
        !            49: /* the values of the stab fields we are currently working on */
        !            50: private unsigned char typeval;
        !            51: private short descval;
        !            52: private Valueform vform;
        !            53: private unsigned valueval;
        !            54: 
        !            55: /*
        !            56:  * Flag for producing either sdb or dbx symbol information.
        !            57:  */
        !            58: int oldway = false;
        !            59: 
        !            60: 
        !            61: /*
        !            62:  * Since type names are lost in the travels and because C has
        !            63:  * structural type equivalence we keep a table of type words that
        !            64:  * we've already seen.  The first time we see a type, it is assigned
        !            65:  * (inline) a number and future references just list that number.
        !            66:  * Structures, unions, enums, and arrays must be handled carefully
        !            67:  * since not all the necessary information is in the type word.
        !            68:  */
        !            69: 
        !            70: typedef struct Typeid *Typeid;
        !            71: 
        !            72: struct Typeid {
        !            73:     TWORD tword;
        !            74:     int tarray;
        !            75:     int tstruct;
        !            76:     int tstrtag;
        !            77:     int f_index;                       /* File index */
        !            78:     int tnum;                          /* Type number */
        !            79:     Typeid chain;
        !            80: };
        !            81: 
        !            82: Typeid entertype();
        !            83: 
        !            84: #define TABLESIZE 2003
        !            85: #define FTBL_SIZE 11
        !            86: 
        !            87: struct file    {
        !            88:        char    *ftitle;                /* Copy of ftitle name */
        !            89:        int     f_index;                /* File name index */
        !            90:        int     tnum;                   /* Next type num within this file */
        !            91: };
        !            92: 
        !            93: struct file    dummy;
        !            94: struct file    *file_stack[FTBL_SIZE]; /* Hashed file table */
        !            95: struct file    **stkp = file_stack;    /* Stack pointer into file_stack[] */
        !            96: struct file    *curfile = &dummy;      /* Current file as we know it */
        !            97: int    f_index;                        /* Next file index */
        !            98: 
        !            99: private int t_int, t_char;
        !           100: private Typeid typetable[TABLESIZE];
        !           101: 
        !           102: private Boolean firsttime = true;
        !           103: 
        !           104: /*
        !           105:  * Generate debugging info for a parameter.
        !           106:  * The offset isn't known when it is first entered into the symbol table
        !           107:  * since the types are read later.
        !           108:  */
        !           109: 
        !           110: fixarg(p)
        !           111: struct symtab *p;
        !           112: {
        !           113:     int offset;
        !           114:     if (oldway) {
        !           115:        old_fixarg(p);
        !           116:     } else if (gdebug) {
        !           117:        printf("\t.stabs\t\"%s:p", p->sname);
        !           118:        gentype(p);
        !           119:        offset = bytes(argoff);
        !           120: #ifdef mc68000
        !           121:        if ( (p->stype==STRTY || p->stype==UNIONTY) && dimtab[p->sizoff]<=2*SZCHAR )
        !           122:            /* offset of itty bitty structs off by two */
        !           123:            offset += 2;
        !           124: #endif
        !           125:        printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), offset);
        !           126:     }
        !           127: }
        !           128: 
        !           129: /*
        !           130:  * Determine if the given symbol is a global array with dimension 0,
        !           131:  * which only makes sense if it's dimension is to be given later.
        !           132:  * We therefore currently do not generate symbol information for
        !           133:  * such entries.
        !           134:  */
        !           135: 
        !           136: #define isglobal(class) ( \
        !           137:     class == EXTDEF or class == EXTERN or class == STATIC \
        !           138: )
        !           139: 
        !           140: private Boolean zero_length_array(p)
        !           141: register struct symtab *p;
        !           142: {
        !           143:     Boolean b;
        !           144:     int t;
        !           145: 
        !           146:     if (not isglobal(p->sclass)) {
        !           147:        b = false;
        !           148:     } else {
        !           149:        t = p->stype;
        !           150:        if (ISFTN(t)) {
        !           151:            t = DECREF(t);
        !           152:        }
        !           153:        b = (Boolean) (ISARY(t) and dimtab[p->dimoff] == 0);
        !           154:     }
        !           155:     return b;
        !           156: }
        !           157: 
        !           158: /* 
        !           159:  * for dbx, the collating sequence of registers includes two
        !           160:  * pseudo-registers following a0-a7. These are of no interest to
        !           161:  * the rest of the compiler, so the remainder of the register
        !           162:  * sequence (i.e., fp0-fp7) must be adjusted accordingly.
        !           163:  */
        !           164: #define stabregno(r) ((r) >= FP0 ? (r)+2 : (r))
        !           165: 
        !           166: /*
        !           167:  * Generate debugging info for a given symbol.
        !           168:  */
        !           169: 
        !           170: outstab(sym)
        !           171: struct symtab *sym;
        !           172: {
        !           173:     register struct symtab *p;
        !           174:     char *classname;
        !           175:     int offset;
        !           176:     Boolean ignore;
        !           177: 
        !           178:     if (oldway) {
        !           179:        old_outstab(sym);
        !           180:     } else if (gdebug and not zero_length_array(sym)) {
        !           181:        if (firsttime) {
        !           182:            firsttime = false;
        !           183:            inittypes();
        !           184:        }
        !           185:        ignore = false;
        !           186:        p = sym;
        !           187:        offset = bytes(p->offset);
        !           188:        switch (p->sclass) {
        !           189:        case REGISTER:
        !           190:            classname = "r";
        !           191:            offset = stabregno(p->offset);
        !           192:            break;
        !           193: 
        !           194:        /*
        !           195:         * Locals are the default class.
        !           196:         */
        !           197:        case AUTO:
        !           198:            classname = "";
        !           199:            break;
        !           200: 
        !           201:        case STATIC:
        !           202:            if (ISFTN(p->stype)) {
        !           203:                ignore = true;
        !           204:            } else if (p->slevel <= 1) {
        !           205:                classname = "S";
        !           206:            } else {
        !           207:                classname = "V";
        !           208:            }
        !           209:            break;
        !           210: 
        !           211:        case EXTDEF:
        !           212:        case EXTERN:
        !           213:            if (ISFTN(p->stype)) {
        !           214:                ignore = true;
        !           215:            } else {
        !           216:                classname = "G";
        !           217:            }
        !           218:            break;
        !           219: 
        !           220:        case TYPEDEF:
        !           221:            classname = "t";
        !           222:            break;
        !           223: 
        !           224:        case PARAM:
        !           225:        case MOS:
        !           226:        case MOU:
        !           227:        case MOE:
        !           228:            ignore = true;
        !           229:            break;
        !           230: 
        !           231:        case ENAME:
        !           232:        case UNAME:
        !           233:        case STNAME:
        !           234:            entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
        !           235:            ignore = true;
        !           236:            break;
        !           237: 
        !           238:        default:
        !           239:            if ((p->sclass&FIELD) == 0) {
        !           240:                printf("||| no info for %s (%d) \n", p->sname, p->sclass);
        !           241:            }
        !           242:            ignore = true;
        !           243:            break;
        !           244:        }
        !           245:        if ( BTYPE(p->stype) == TERROR ) {
        !           246:            /* don't try to output symbols entered in error */
        !           247:            ignore = true;
        !           248:        }
        !           249:        if (not ignore) {
        !           250:            printf("\t.stabs\t\"%s:%s", p->sname, classname);
        !           251:            setinfo(p);
        !           252:            gentype(p);
        !           253:            geninfo(p);
        !           254:        }
        !           255:     }
        !           256: }
        !           257: /*
        !           258:  * Look for the given type word in the type table.
        !           259:  */
        !           260: 
        !           261: private Typeid typelookup(type, arrindex, strindex, strtag)
        !           262: TWORD type;
        !           263: int arrindex;
        !           264: int strindex;
        !           265: int strtag;
        !           266: {
        !           267:     register TWORD tword;
        !           268:     register int i1, i2;
        !           269:     Typeid t;
        !           270: 
        !           271:     for (t = typetable[type mod TABLESIZE]; t != nil; t = t->chain) {
        !           272:        if (t->tword == type and
        !           273:          strindex == t->tstruct and strtag == t->tstrtag) {
        !           274:            if (arrindex == NILINDEX) {
        !           275:                break;
        !           276:            } else {
        !           277:                tword = type;
        !           278:                i1 = arrindex;
        !           279:                i2 = t->tarray;
        !           280:                while (ISARY(tword) and dimtab[i1] == dimtab[i2]) {
        !           281:                    ++i1;
        !           282:                    ++i2;
        !           283:                    tword >>= TSHIFT;
        !           284:                }
        !           285:                if (!ISARY(tword)) {
        !           286:                    break;
        !           287:                }
        !           288:            }
        !           289:        }
        !           290:     }
        !           291:     return t;
        !           292: }
        !           293: 
        !           294: /*
        !           295:  * Enter a type word and associated symtab indices into the type table.
        !           296:  */
        !           297: 
        !           298: private Typeid entertype(type, arrindex, strindex, strtag)
        !           299: TWORD type;
        !           300: int arrindex;
        !           301: int strindex;
        !           302: int strtag;
        !           303: {
        !           304:     register Typeid t;
        !           305:     register int i;
        !           306: 
        !           307:     t = (Typeid) malloc(sizeof(struct Typeid));
        !           308:     t->tword = type;
        !           309:     t->tarray = arrindex;
        !           310:     t->tstruct = strindex;
        !           311:     t->tstrtag = strtag;
        !           312:     t->f_index = curfile->f_index;
        !           313:     t->tnum = curfile->tnum++;
        !           314:     i = type mod TABLESIZE;
        !           315:     t->chain = typetable[i];
        !           316:     typetable[i] = t;
        !           317:     return t;
        !           318: }
        !           319: 
        !           320: /*
        !           321:  * Change the information associated with a type table entry.
        !           322:  * Since I'm lazy this just creates a new entry with the number
        !           323:  * as the old one.
        !           324:  */
        !           325: 
        !           326: private reentertype(typeid, type, arrindex, strindex, strtag)
        !           327: Typeid typeid;
        !           328: TWORD type;
        !           329: int arrindex;
        !           330: int strindex;
        !           331: int strtag;
        !           332: {
        !           333:     register Typeid t;
        !           334:     register int i;
        !           335: 
        !           336:     t = (Typeid) malloc(sizeof(struct Typeid));
        !           337:     t->tword = type;
        !           338:     t->tarray = arrindex;
        !           339:     t->tstruct = strindex;
        !           340:     t->tstrtag = strtag;
        !           341:     t->f_index = typeid->f_index;
        !           342:     t->tnum = typeid->tnum;
        !           343:     i = type mod TABLESIZE;
        !           344:     t->chain = typetable[i];
        !           345:     typetable[i] = t;
        !           346: }
        !           347: 
        !           348: /*
        !           349:  * Initialize type table with predefined types.
        !           350:  */
        !           351: 
        !           352: #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX)->tnum
        !           353: 
        !           354: private inittypes()
        !           355: {
        !           356:     int t;
        !           357: 
        !           358:     t_int = builtintype(INT);
        !           359:     t_char = builtintype(CHAR);
        !           360:     maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL);
        !           361:     maketype("char", t_char, t_char, 0L, 127L);
        !           362:     maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL);
        !           363:     maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL);
        !           364:     maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L);
        !           365:     maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL);
        !           366:     maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL);
        !           367:     maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL);
        !           368:     maketype("float", builtintype(FLOAT), t_int, 4L, 0L);
        !           369:     maketype("double", builtintype(DOUBLE), t_int, 8L, 0L);
        !           370:     t = builtintype(UNDEF);
        !           371:     printf("\t.stabs\t\"void:t(%d,%d)=(%d,%d)", curfile->f_index, t, 
        !           372:       curfile->f_index, t);
        !           373:     geninfo(nil);
        !           374:     t = builtintype(FARG);
        !           375:     printf("\t.stabs\t\"???:t(%d,%d)=(%d,%d)", curfile->f_index, t, 
        !           376:       curfile->f_index, t_int);
        !           377:     geninfo(nil);
        !           378: }
        !           379: 
        !           380: /*
        !           381:  * Generate info for a new range type.
        !           382:  */
        !           383: 
        !           384: private maketype(name, tnum, eqtnum, lower, upper)
        !           385: char *name;
        !           386: int tnum, eqtnum;
        !           387: long lower, upper;
        !           388: {
        !           389:     printf("\t.stabs\t\"%s:t(%d,%d)=r(%d,%d);%d;%d;", 
        !           390:        name, curfile->f_index, tnum, curfile->f_index, eqtnum, lower, upper);
        !           391:     geninfo(nil);
        !           392: }
        !           393: 
        !           394: /*
        !           395:  * Generate debugging information for the given type of the given symbol.
        !           396:  */
        !           397: 
        !           398: private gentype(sym)
        !           399: struct symtab *sym;
        !           400: {
        !           401:     register struct symtab *p;
        !           402:     register TWORD t;
        !           403:     register TWORD basictype;
        !           404:     register Typeid typeid;
        !           405:     int i, arrindex, strindex, strtag;
        !           406:     char basicchar;
        !           407: 
        !           408:     p = sym;
        !           409:     t = p->stype;
        !           410:     if (ISFTN(t)) {
        !           411:        t = DECREF(t);
        !           412:     }
        !           413:     basictype = BTYPE(t);
        !           414:     if (ISARY(t)) {
        !           415:        arrindex = p->dimoff;
        !           416:     } else {
        !           417:        arrindex = NILINDEX;
        !           418:     }
        !           419:     if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) {
        !           420:        strindex = dimtab[p->sizoff + 1];
        !           421:        if (strindex == -1) {
        !           422:            strindex = FORWARD;
        !           423:            strtag = dimtab[p->sizoff + 3];
        !           424:        } else {
        !           425:            strtag = NILINDEX;
        !           426:        }
        !           427:     } else {
        !           428:        strindex = NILINDEX;
        !           429:        strtag = NILINDEX;
        !           430:     }
        !           431:     i = arrindex;
        !           432:     typeid = typelookup(t, arrindex, strindex, strtag); 
        !           433:     while (t != basictype and typeid == nil) {
        !           434:        typeid = entertype(t, i, strindex, strtag);
        !           435:        printf("(%d,%d)=", typeid->f_index, typeid->tnum);
        !           436:        switch (t&TMASK) {
        !           437:        case PTR:
        !           438:            printf("*");
        !           439:            break;
        !           440: 
        !           441:        case FTN:
        !           442:            printf("f");
        !           443:            break;
        !           444: 
        !           445:        case ARY:
        !           446:            printf("ar(0,%d);0;%d;", t_int, dimtab[i++] - 1);
        !           447:            break;
        !           448:        }
        !           449:        t = DECREF(t);
        !           450:        if (t == basictype) {
        !           451:            typeid = typelookup(t, NILINDEX, strindex, strtag);
        !           452:        } else {
        !           453:            typeid = typelookup(t, i, strindex, strtag);
        !           454:        }
        !           455:     }
        !           456:     if (typeid == nil) {
        !           457:        if (strindex == FORWARD) {
        !           458:            typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
        !           459:            if (typeid == nil) {
        !           460:                cerror("unbelievable forward reference");
        !           461:            }
        !           462:            printf("(%d,%d)", typeid->f_index, typeid->tnum);
        !           463:        } else {
        !           464:            genstruct(t, NILINDEX, NILINDEX, strindex, p->sname, bsize(p));
        !           465:        }
        !           466:     } else {
        !           467:        printf("(%d,%d)", typeid->f_index, typeid->tnum);
        !           468:        p = STP(strtag);
        !           469:        if (typeid->tstruct == FORWARD and (p->sflags & SPRFORWARD) == 0) {
        !           470:            switch (basictype) {
        !           471:            case STRTY:
        !           472:                basicchar = 's';
        !           473:                break;
        !           474:            case UNIONTY:
        !           475:                basicchar = 'u';
        !           476:                break;
        !           477:            case ENUMTY:
        !           478:                basicchar = 'e';
        !           479:                break;
        !           480:            default:
        !           481:                cerror("Bad basic type, %d, in gentype", basictype);
        !           482:                basicchar = 's';
        !           483:            }
        !           484:            printf("=x%c%s:", basicchar, STP(strtag)->sname);
        !           485:            p->sflags |= SPRFORWARD;
        !           486:        }
        !           487:     }
        !           488: }
        !           489: 
        !           490: /*
        !           491:  * Generate type information for structures, unions, and enumerations.
        !           492:  */
        !           493: 
        !           494: private genstruct(t, fileid, structid, index, name, size)
        !           495: TWORD t;
        !           496: int fileid;
        !           497: int structid;
        !           498: int index;
        !           499: char *name;
        !           500: int size;
        !           501: {
        !           502:     Typeid typeid;
        !           503:     register int i;
        !           504:     register struct symtab *field;
        !           505:     int id;
        !           506:     int fid;
        !           507: 
        !           508:     if (structid == NILINDEX) {
        !           509:        typeid = entertype(t, NILINDEX, index, NILINDEX);
        !           510:        id = typeid->tnum;
        !           511:        fid = typeid->f_index;
        !           512:     } else {
        !           513:        id = structid;
        !           514:        fid = fileid;
        !           515:     }
        !           516:     switch (t) {
        !           517:     case STRTY:
        !           518:     case UNIONTY:
        !           519:        printf("(%d,%d)=%c%d", fid, id, t == STRTY ? 's' : 'u', size);
        !           520:        i = index;
        !           521:        while (dimtab[i] != -1) {
        !           522:            if (nfield > NSTABFIELDS && dimtab[i+1] != -1){
        !           523:                continue_stab();
        !           524:            }
        !           525:            field = STP(dimtab[i]);
        !           526:            printf("%s:", field->sname);
        !           527:            gentype(field);
        !           528:            if (field->sclass > FIELD) {
        !           529:                printf(",%d,%d;", field->offset, field->sclass - FIELD);
        !           530:            } else {
        !           531:                printf(",%d,%d;", field->offset,
        !           532:                    tsize(field->stype, field->dimoff, field->sizoff));
        !           533:            }
        !           534:            ++i;
        !           535:            ++nfield;
        !           536:        }
        !           537:        putchar(';');
        !           538:        break;
        !           539: 
        !           540:     case ENUMTY:
        !           541:        printf("(%d,%d)=e", fid, id);
        !           542:        i = index;
        !           543:        while (dimtab[i] != -1 ) {
        !           544:            if (nfield > NSTABFIELDS && dimtab[i+1] != -1){
        !           545:                continue_stab();
        !           546:            }
        !           547:            field = STP(dimtab[i]);
        !           548:            printf("%s:%d,", field->sname, field->offset);
        !           549:            ++i;
        !           550:            ++nfield;
        !           551:        }
        !           552:        putchar(';');
        !           553:        break;
        !           554: 
        !           555:     default:
        !           556:        cerror("couldn't find basic type %d for %s\n", t, name);
        !           557:        break;
        !           558:     }
        !           559: }
        !           560: 
        !           561: /*
        !           562:  * Generate offset and size info.
        !           563:  */
        !           564: 
        !           565: private setinfo(p)
        !           566: register struct symtab *p;
        !           567: {
        !           568:     int stabtype;
        !           569: 
        !           570:     if (p == nil) {
        !           571:        typeval = N_LSYM;
        !           572:        descval = 0;
        !           573:        vform = value;
        !           574:        valueval = 0;
        !           575:     } else {
        !           576:        descval = bsize(p);
        !           577:        switch (p->sclass) {
        !           578:            case EXTERN:
        !           579:            case EXTDEF:
        !           580:                if (ISFTN(p->stype)) {
        !           581:                    typeval = N_FUN;
        !           582:                    vform = xname;
        !           583:                    valueval = (unsigned)p->sname;
        !           584:                } else {
        !           585:                    typeval = N_GSYM;
        !           586:                    vform = value;
        !           587:                    valueval = 0;
        !           588:                }
        !           589:                break;
        !           590: 
        !           591:            case STATIC:
        !           592:                typeval = stabLCSYM ? N_LCSYM : N_STSYM;
        !           593:                vform = xname;
        !           594:                valueval = (unsigned)p->sname;
        !           595:                if (ISFTN(p->stype)) {
        !           596:                    typeval = N_FUN;
        !           597:                } else if (p->slevel > 1) {
        !           598:                    vform = lname;
        !           599:                    valueval = p->offset;
        !           600:                }
        !           601:                break;
        !           602: 
        !           603:            case REGISTER:
        !           604:                typeval = N_RSYM;
        !           605:                vform = value;
        !           606:                valueval = stabregno(p->offset);
        !           607:                break;
        !           608: 
        !           609:            case PARAM:
        !           610:                typeval = N_PSYM;
        !           611:                vform = value;
        !           612:                valueval = bytes(argoff);
        !           613:                break;
        !           614: 
        !           615:            default:
        !           616:                typeval = N_LSYM;
        !           617:                vform = value;
        !           618:                valueval = bytes(p->offset);
        !           619:                break;
        !           620:        }
        !           621:     }
        !           622: }
        !           623: 
        !           624: private geninfo(p)
        !           625: struct symtab *p;
        !           626: {
        !           627:     setinfo( p );
        !           628:     printf("\",0x%x,0,%d," , typeval, descval );
        !           629:     switch (vform){
        !           630:     case value:        printf("%d\n", valueval); break;
        !           631:     case xname:        printf("_%s\n", valueval); break;
        !           632:     case lname:        printf("L%d\n", valueval); break;
        !           633:     }
        !           634:     nfield = 0;
        !           635: }
        !           636: 
        !           637: /* stab strings for structures can be very big. Sometimes we would
        !           638:  * like to continue them on a second line. For this case, we must
        !           639:  * write out a back-slash at the end of the quoted string, then
        !           640:  * put out the rest of the stab entry information, followed by a new
        !           641:  * .stabs line. The information we put must be setup in globals by
        !           642:  * a previous call to setinfo.
        !           643:  */
        !           644: 
        !           645: private continue_stab()
        !           646: {
        !           647:     printf("\\\\\",0x%x,0,%d," , typeval, descval );
        !           648:     switch (vform){
        !           649:     case value:        printf("%d\n", valueval); break;
        !           650:     case xname:        printf("_%s\n", valueval); break;
        !           651:     case lname:        printf("L%d\n", valueval); break;
        !           652:     }
        !           653:     printf("\t.stabs\t\"");
        !           654:     nfield = 0;
        !           655: }
        !           656: 
        !           657: /*
        !           658:  * Generate information for a newly-defined structure.
        !           659:  */
        !           660: 
        !           661: outstruct(szindex, paramindex)
        !           662: int szindex, paramindex;
        !           663: {
        !           664:     register Typeid typeid;
        !           665:     register struct symtab *p;
        !           666:     register int i, strindex;
        !           667: 
        !           668:     if (oldway) {
        !           669:        /* do nothing */;
        !           670:     } else if (gdebug) {
        !           671:        i = dimtab[szindex + 3];
        !           672:        p = STP(i);
        !           673:        if (i != -1 ) {
        !           674:            strindex = dimtab[p->sizoff + 1];
        !           675:            typeid = typelookup(p->stype, NILINDEX, FORWARD, i);
        !           676:            if (typeid != nil) {
        !           677:                if (typeid->f_index == curfile->f_index) {
        !           678:                    reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX);
        !           679:                } else {
        !           680:                    typeid = entertype(p->stype, NILINDEX, FORWARD, NILINDEX);
        !           681:                }
        !           682:                printf("\t.stabs\t\"%s:T", p->sname);
        !           683:                setinfo(p);
        !           684:                genstruct(p->stype, typeid->f_index, typeid->tnum, strindex, 
        !           685:                  p->sname, bsize(p));
        !           686:                geninfo(p);
        !           687:            } else {
        !           688:                cerror("Couldn't find struct %s", p->sname);
        !           689:            }
        !           690:        }
        !           691:     }
        !           692: }
        !           693: 
        !           694: pstab(name, type)
        !           695: char *name;
        !           696: int type;
        !           697: {
        !           698:     register int i;
        !           699:     register char c;
        !           700: 
        !           701:     if (!gdebug) {
        !           702:        return;
        !           703:     } else if (oldway) {
        !           704:        old_pstab(name, type);
        !           705:        return;
        !           706:     }
        !           707:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
        !           708: #ifdef ASSTRINGS
        !           709:     if ( name[0] == '\0')
        !           710:        printf("\t.stabn\t");
        !           711:     else
        !           712: #ifndef FLEXNAMES
        !           713:        printf("\t.stabs\t\"%.8s\",", name);
        !           714: #else
        !           715:        printf("\t.stabs\t\"%s\",", name);
        !           716: #endif
        !           717: #else
        !           718:     printf("    .stab   ");
        !           719:     for(i=0; i<8; i++) 
        !           720:        if (c = name[i]) printf("'%c,", c);
        !           721:        else printf("0,");
        !           722: #endif
        !           723:     printf("0%o,", type);
        !           724: }
        !           725: 
        !           726: #ifdef STABDOT
        !           727: pstabdot(type, value)
        !           728: int type;
        !           729: int value;
        !           730: {
        !           731:     if ( ! gdebug) {
        !           732:        return;
        !           733:     } else if (oldway) {
        !           734:        old_pstabdot(type, value);
        !           735:        return;
        !           736:     }
        !           737:     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
        !           738:     printf("\t.stabd\t");
        !           739:     printf("0%o,0,0%o\n",type, value);
        !           740: }
        !           741: #endif
        !           742: 
        !           743: extern char NULLNAME[8];
        !           744: extern int  labelno;
        !           745: extern int  fdefflag;
        !           746: 
        !           747: psline(lineno)
        !           748:     int lineno;
        !           749: {
        !           750:     static int nrecur = 0;
        !           751:     static int lastlineno;
        !           752:     register char *cp, *cq;
        !           753:     register int i;
        !           754:     int tmp;
        !           755:     
        !           756:     if (nrecur) {
        !           757:        /*
        !           758:         * N_SLINE and N_SOL .stab lines must go into .text space.
        !           759:         * We use locctr() to get there and back, but locctr()
        !           760:         * turns around and calls US, so...
        !           761:         */
        !           762:        return;
        !           763:     }
        !           764:     if (!gdebug) {
        !           765:        return;
        !           766:     } else if (oldway) {
        !           767:        old_psline(lineno);
        !           768:        return;
        !           769:     }
        !           770: 
        !           771:     cq = ititle;
        !           772:     cp = ftitle;
        !           773: 
        !           774:     while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
        !           775:     if ( *cp == '\0' ) goto eq;
        !           776:     
        !           777: neq:    for (i=0; i<100; i++)
        !           778:        ititle[i] = '\0';
        !           779:     cp = ftitle;
        !           780:     cq = ititle;
        !           781:     while ( *cp )  
        !           782:        *cq++ = *cp++;
        !           783:     *cq = '\0';
        !           784:     *--cq = '\0';
        !           785:     nrecur++; tmp = locctr(PROG);
        !           786: #ifndef FLEXNAMES
        !           787:     for ( cp = ititle+1; *(cp-1); cp += 8 ) {
        !           788:        pstab(cp, N_SOL);
        !           789:        if (gdebug) printf("0,0,LL%d\n", labelno);
        !           790:     }
        !           791: #else
        !           792:     pstab(ititle+1, N_SOL);
        !           793:     if (gdebug) printf("0,0,LL%d\n", labelno);
        !           794: #endif
        !           795:     *cq = '"';
        !           796:     printf("LL%d:\n", labelno++);
        !           797:     locctr(tmp); nrecur--;
        !           798: 
        !           799: eq: if (lineno == lastlineno) return;
        !           800:     lastlineno = lineno;
        !           801: 
        !           802:     nrecur++; tmp = locctr(PROG);
        !           803:     if ((tmp == PROG) and not optimize) {
        !           804: #ifdef STABDOT
        !           805:        pstabdot(N_SLINE, lineno);
        !           806: #else
        !           807:        pstab(NULLNAME, N_SLINE);
        !           808:        printf("0,%d,LL%d\n", lineno, labelno);
        !           809:        printf("LL%d:\n", labelno++);
        !           810: #endif
        !           811:     }
        !           812:     locctr(tmp); nrecur--;
        !           813: }
        !           814:     
        !           815: plcstab(level)
        !           816: int level;
        !           817: {
        !           818:     if (!gdebug) {
        !           819:        return;
        !           820:     } else if (oldway) {
        !           821:        old_plcstab(level);
        !           822:        return;
        !           823:     }
        !           824: #ifdef STABDOT
        !           825:     pstabdot(N_LBRAC, level);
        !           826: #else
        !           827:     pstab(NULLNAME, N_LBRAC);
        !           828:     printf("0,%d,LL%d\n", level, labelno);
        !           829:     printf("LL%d:\n", labelno++);
        !           830: #endif
        !           831: }
        !           832:     
        !           833: prcstab(level)
        !           834: int level;
        !           835: {
        !           836:     if (!gdebug) {
        !           837:        return;
        !           838:     } else if (oldway) {
        !           839:        old_prcstab(level);
        !           840:        return;
        !           841:     }
        !           842: #ifdef STABDOT
        !           843:     pstabdot(N_RBRAC, level);
        !           844: #else
        !           845:     pstab(NULLNAME, N_RBRAC);
        !           846:     printf("0,%d,LL%d\n", level, labelno);
        !           847:     printf("LL%d:\n", labelno++);
        !           848: #endif
        !           849: }
        !           850:     
        !           851: pfstab(sname) 
        !           852: char *sname;
        !           853: {
        !           854:     register struct symtab *p;
        !           855: 
        !           856:     if (gdebug) {
        !           857:        if (oldway) {
        !           858:            old_pfstab(sname);
        !           859:        } else {
        !           860:            p = STP(lookup(sname, 0));
        !           861:            printf("\t.stabs\t\"%s:", p->sname); 
        !           862:            putchar((p->sclass == STATIC) ? 'f' : 'F'); setinfo(p);
        !           863:            gentype(p);
        !           864:            geninfo(p);
        !           865:        }
        !           866:     }
        !           867: }
        !           868: 
        !           869: /*
        !           870:  * Have the beginning of an include file.
        !           871:  * Change our notion of the current file.
        !           872:  */
        !           873: stab_startheader()
        !           874: {
        !           875:        char    buf[256];
        !           876: 
        !           877:        if (!gdebug) {
        !           878:                return;
        !           879:        }
        !           880:        if (firsttime) {
        !           881:                firsttime = false;
        !           882:                inittypes();
        !           883:        }
        !           884:        strcpy(buf, ftitle + 1);
        !           885:        buf[strlen(buf) - 1] = '\0';
        !           886:        insert_filename(buf);
        !           887:        pstab(buf, N_BINCL);
        !           888:        printf("0,0,0\n");
        !           889: }
        !           890: 
        !           891: /*
        !           892:  * Have the end of an include file.
        !           893:  */
        !           894: stab_endheader()
        !           895: {
        !           896:        char    buf[256];
        !           897: 
        !           898:        if (!gdebug) {
        !           899:                return;
        !           900:        }
        !           901:        strcpy(buf, ftitle + 1);
        !           902:        buf[strlen(buf) - 1] = '\0';
        !           903:        pstab("", N_EINCL);
        !           904:        printf("0,0,0\n");
        !           905:        curfile = *--stkp;
        !           906: }
        !           907: 
        !           908: /*
        !           909:  * Old way of doing things.
        !           910:  */
        !           911: 
        !           912: private old_fixarg(p)
        !           913: struct symtab *p; {
        !           914:        if (gdebug) {
        !           915:                old_pstab(p->sname, N_PSYM);
        !           916:                if (gdebug) printf("0,%d,%d\n", p->stype, argoff/SZCHAR);
        !           917:                old_poffs(p);
        !           918:        }
        !           919: }
        !           920: 
        !           921: private old_outstab(p)
        !           922: struct symtab *p; {
        !           923:        register TWORD ptype;
        !           924:        register char *pname;
        !           925:        register char pclass;
        !           926:        register int poffset;
        !           927: 
        !           928:        if (!gdebug) return;
        !           929: 
        !           930:        ptype = p->stype;
        !           931:        pname = p->sname;
        !           932:        pclass = p->sclass;
        !           933:        poffset = p->offset;
        !           934: 
        !           935:        if (ISFTN(ptype)) {
        !           936:                return;
        !           937:        }
        !           938:        
        !           939:        switch (pclass) {
        !           940:        
        !           941:        case AUTO:
        !           942:                old_pstab(pname, N_LSYM);
        !           943:                printf("0,%d,%d\n", ptype, (-poffset)/SZCHAR);
        !           944:                old_poffs(p);
        !           945:                return;
        !           946:        
        !           947:        case EXTDEF:
        !           948:        case EXTERN:
        !           949:                old_pstab(pname, N_GSYM);
        !           950:                printf("0,%d,0\n", ptype);
        !           951:                old_poffs(p);
        !           952:                return;
        !           953:                        
        !           954:        case STATIC:
        !           955: #ifdef LCOMM
        !           956:                /* stabLCSYM is 1 during nidcl so we can get stab type right */
        !           957:                old_pstab(pname, stabLCSYM ? N_LCSYM : N_STSYM);
        !           958: #else
        !           959:                old_pstab(pname, N_STSYM);
        !           960: #endif
        !           961:                if (p->slevel > 1) {
        !           962:                        printf("0,%d,L%d\n", ptype, poffset);
        !           963:                } else {
        !           964:                        printf("0,%d,%s\n", ptype, exname(pname));
        !           965:                }
        !           966:                old_poffs(p);
        !           967:                return;
        !           968:        
        !           969:        case REGISTER:
        !           970:                old_pstab(pname, N_RSYM);
        !           971:                printf("0,%d,%d\n", ptype, poffset);
        !           972:                old_poffs(p);
        !           973:                return;
        !           974:        
        !           975:        case MOS:
        !           976:        case MOU:
        !           977:                old_pstab(pname, N_SSYM);
        !           978:                printf("0,%d,%d\n", ptype, poffset/SZCHAR);
        !           979:                old_poffs(p);
        !           980:                return;
        !           981:        
        !           982:        case PARAM:
        !           983:                /* parameter stab entries are processed in dclargs() */
        !           984:                return;
        !           985:        
        !           986:        default:
        !           987: #ifndef FLEXNAMES
        !           988:                if (ddebug) printf("    No .stab for %.8s\n", pname);
        !           989: #else
        !           990:                if (ddebug) printf("    No .stab for %s\n", pname);
        !           991: #endif
        !           992:                
        !           993:        }
        !           994: }
        !           995: 
        !           996: private old_pstab(name, type)
        !           997: char *name;
        !           998: int type; {
        !           999:        register int i;
        !          1000:        register char c;
        !          1001:        if (!gdebug) return;
        !          1002:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
        !          1003: #ifdef ASSTRINGS
        !          1004:        if ( name[0] == '\0')
        !          1005:                printf("\t.stabn\t");
        !          1006:        else
        !          1007: #ifndef FLEXNAMES
        !          1008:                printf("\t.stabs\t\"%.8s\", ", name);
        !          1009: #else
        !          1010:                printf("\t.stabs\t\"%s\", ", name);
        !          1011: #endif
        !          1012: #else
        !          1013:        printf("        .stab   ");
        !          1014:        for(i=0; i<8; i++) 
        !          1015:                if (c = name[i]) printf("'%c,", c);
        !          1016:                else printf("0,");
        !          1017: #endif
        !          1018:        printf("0%o,", type);
        !          1019: }
        !          1020: 
        !          1021: #ifdef STABDOT
        !          1022: private old_pstabdot(type, value)
        !          1023:        int     type;
        !          1024:        int     value;
        !          1025: {
        !          1026:        if ( ! gdebug) return;
        !          1027:        /* locctr(PROG);  /* .stabs must appear in .text for c2 */
        !          1028:        printf("\t.stabd\t");
        !          1029:        printf("0%o,0,0%o\n",type, value);
        !          1030: }
        !          1031: #endif
        !          1032: 
        !          1033: private old_poffs(p)
        !          1034: register struct symtab *p; {
        !          1035:        int s;
        !          1036:        if (!gdebug) return;
        !          1037:        if ((s = dimtab[p->sizoff]/SZCHAR) > 1) {
        !          1038:                old_pstab(p->sname, N_LENG);
        !          1039:                printf("1,0,%d\n", s);
        !          1040:        }
        !          1041: }
        !          1042: 
        !          1043: private old_psline(lineno) 
        !          1044:        int lineno;
        !          1045: {
        !          1046:        static int lastlineno;
        !          1047:        register char *cp, *cq;
        !          1048:        register int i;
        !          1049:        
        !          1050:        if (!gdebug) return;
        !          1051: 
        !          1052:        cq = ititle;
        !          1053:        cp = ftitle;
        !          1054: 
        !          1055:        while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
        !          1056:        if ( *cp == '\0' ) goto eq;
        !          1057:        
        !          1058: neq:   for (i=0; i<100; i++)
        !          1059:                ititle[i] = '\0';
        !          1060:        cp = ftitle;
        !          1061:        cq = ititle;
        !          1062:        while ( *cp )  
        !          1063:                *cq++ = *cp++;
        !          1064:        *cq = '\0';
        !          1065:        *--cq = '\0';
        !          1066: #ifndef FLEXNAMES
        !          1067:        for ( cp = ititle+1; *(cp-1); cp += 8 ) {
        !          1068:                old_pstab(cp, N_SOL);
        !          1069:                if (gdebug) printf("0,0,LL%d\n", labelno);
        !          1070:                }
        !          1071: #else
        !          1072:        old_pstab(ititle+1, N_SOL);
        !          1073:        if (gdebug) printf("0,0,LL%d\n", labelno);
        !          1074: #endif
        !          1075:        *cq = '"';
        !          1076:        printf("LL%d:\n", labelno++);
        !          1077: 
        !          1078: eq:    if (lineno == lastlineno) return;
        !          1079:        lastlineno = lineno;
        !          1080: 
        !          1081:        if (fdefflag) {
        !          1082: #ifdef STABDOT
        !          1083:                old_pstabdot(N_SLINE, lineno);
        !          1084: #else
        !          1085:                old_pstab(NULLNAME, N_SLINE);
        !          1086:                printf("0,%d,LL%d\n", lineno, labelno);
        !          1087:                printf("LL%d:\n", labelno++);
        !          1088: #endif
        !          1089:                }
        !          1090:        }
        !          1091:        
        !          1092: private old_plcstab(level) {
        !          1093:        if (!gdebug) return;
        !          1094: #ifdef STABDOT
        !          1095:        old_pstabdot(N_LBRAC, level);
        !          1096: #else
        !          1097:        old_pstab(NULLNAME, N_LBRAC);
        !          1098:        printf("0,%d,LL%d\n", level, labelno);
        !          1099:        printf("LL%d:\n", labelno++);
        !          1100: #endif
        !          1101:        }
        !          1102:        
        !          1103: private old_prcstab(level) {
        !          1104:        if (!gdebug) return;
        !          1105: #ifdef STABDOT
        !          1106:        pstabdot(N_RBRAC, level);
        !          1107: #else
        !          1108:        pstab(NULLNAME, N_RBRAC);
        !          1109:        printf("0,%d,LL%d\n", level, labelno);
        !          1110:        printf("LL%d:\n", labelno++);
        !          1111: #endif
        !          1112:        }
        !          1113:        
        !          1114: private old_pfstab(sname) 
        !          1115: char *sname; {
        !          1116:        if (!gdebug) return;
        !          1117:        pstab(sname, N_FUN);
        !          1118: #ifndef FLEXNAMES
        !          1119:        printf("0,%d,_%.7s\n", lineno, sname);
        !          1120: #else
        !          1121:        printf("0,%d,_%s\n", lineno, sname);
        !          1122: #endif
        !          1123: }
        !          1124: 
        !          1125: /*
        !          1126:  * Have entered a new file.
        !          1127:  * Allocate a node for it.
        !          1128:  */
        !          1129: insert_filename(file)
        !          1130: char   *file;
        !          1131: {
        !          1132:        *stkp++ = curfile;
        !          1133:        curfile = (struct file *) malloc(sizeof(struct file));
        !          1134:        curfile->ftitle = strcpy(malloc(strlen(file) + 1), file);
        !          1135:        curfile->f_index = f_index++;
        !          1136:        curfile->tnum = 1;
        !          1137: }

unix.superglobalmegacorp.com

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