Annotation of researchv10no/cmd/adb/comm/sym.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * adb - symbol table routines
                      3:  */
                      4: #include "defs.h"
                      5: #include "sym.h"
                      6: #include "space.h"
                      7: 
                      8: struct sym *cursym;
                      9: struct sym *symtab;
                     10: 
                     11: static int gsname(), lsname();
                     12: 
                     13: /*
                     14:  * Lookup a symbol by name
                     15:  * leave a pointer to the symbol in cursym
                     16:  */
                     17: struct sym *
                     18: lookup(symstr)
                     19:        register char *symstr;
                     20: {
                     21:        register struct sym *sp;
                     22: 
                     23:        cursym = 0;
                     24:        for (sp = symtab; sp; sp = sp->y_next)
                     25:                if (eqsym(sp, symstr))
                     26:                        return(cursym = sp);
                     27:        return (0);
                     28: }
                     29: 
                     30: /*
                     31:  * find the symbols for a routine
                     32:  */
                     33: 
                     34: int
                     35: findrtn(rtn)
                     36: char *rtn;
                     37: {
                     38:        register struct sym *sp;
                     39: 
                     40:        cursym = 0;
                     41:        for (sp = symtab; sp; sp = sp->y_next)
                     42:                switch (sp->y_type) {
                     43:                case S_TEXT:
                     44:                        if (eqsym(sp, rtn)) {
                     45:                                cursym = sp;
                     46:                                return (1);
                     47:                        }
                     48:                }
                     49:        return (0);
                     50: }
                     51: 
                     52: /*
                     53:  * Find the closest symbol to val, and return
                     54:  * the difference between val and the symbol found.
                     55:  * Leave a pointer to the symbol found as cursym.
                     56:  */
                     57: WORD
                     58: findsym(w, type)
                     59:        WORD w;
                     60:        int type;
                     61: {
                     62:        register unsigned long diff;
                     63:        register unsigned long val;
                     64:        register struct sym *sp;
                     65: 
                     66:        val = w;
                     67:        cursym = 0;
                     68:        diff = HUGE;
                     69:        type &= SPTYPE;
                     70:        if (type == NOSP || symtab == 0)
                     71:                return (diff);
                     72:        for (sp = symtab; sp; sp = sp->y_next) {
                     73:                switch (type) {
                     74:                case INSTSP:
                     75:                        if (sp->y_type != S_TEXT && sp->y_type != S_ABS)
                     76:                                continue;
                     77:                        break;
                     78: 
                     79:                case DATASP:
                     80:                        if (sp->y_type != S_DATA && sp->y_type != S_ABS)
                     81:                                continue;
                     82:                        break;
                     83:                }
                     84:                if (val >= (unsigned long)sp->y_value
                     85:                &&  val - (unsigned long)sp->y_value < diff) {
                     86:                        diff = val - (unsigned long)sp->y_value;
                     87:                        cursym = sp;
                     88:                        if (diff == 0)
                     89:                                break;
                     90:                }
                     91:        }
                     92:        if (cursym && cursym->y_value == 0 && diff != 0)
                     93:                return (HUGE);
                     94:        return (diff);
                     95: }
                     96: 
                     97: /*
                     98:  * advance cursym to the next local variable
                     99:  * return 0 if the next variable is a global
                    100:  */
                    101: int
                    102: localsym()
                    103: {
                    104:        register struct sym *sp;
                    105: 
                    106:        if ((sp = cursym) == NULL)
                    107:                return (0);
                    108:        if (sp->y_type != S_STAB)
                    109:                sp = sp->y_locals;
                    110:        else
                    111:                sp = sp->y_next;
                    112:        cursym = sp;
                    113:        return (cursym != 0);
                    114: }
                    115: 
                    116: /*
                    117:  * Print value v and then the string s.
                    118:  * If v is not zero, then we look for a nearby symbol
                    119:  * and print name+offset if we find a symbol for which
                    120:  * offset is small enough.
                    121:  */
                    122: psymoff(v, type, s)
                    123:        WORD v;
                    124:        int type;
                    125:        char *s;
                    126: {
                    127:        WORD w;
                    128: 
                    129:        if ((type & SPTYPE) == REGSP) {
                    130:                printf("%%%R", v);
                    131:                printf(s);
                    132:                return;
                    133:        }
                    134:        if (v)
                    135:                w = findsym(v, type);
                    136:        if (v==0 || w >= maxoff)
                    137:                printf("%R", v);
                    138:        else {
                    139:                printf("%s", cursym->y_name);
                    140:                if (w)
                    141:                        printf("+%R", w);
                    142:        }
                    143:        printf(s);
                    144: }
                    145: 
                    146: /*
                    147:  * Print value v symbolically if it has a reasonable
                    148:  * interpretation as name+offset.  If not, print nothing.
                    149:  * Used in printing out registers $r.
                    150:  */
                    151: valpr(v, idsp)
                    152:        WORD v;
                    153: {
                    154:        WORD d;
                    155: 
                    156:        d = findsym(v, idsp);
                    157:        if (d >= maxoff)
                    158:                return;
                    159:        printf("%s", cursym->y_name);
                    160:        if (d)
                    161:                printf("+%R", d);
                    162: }
                    163: 
                    164: printsym()
                    165: {
                    166:        register struct sym *sp;
                    167:        register struct sym *lp;
                    168: 
                    169:        for (sp = symtab; sp; sp = sp->y_next) {
                    170:                printf("%8R %c %s\n", sp->y_value, gsname(sp->y_type), sp->y_name);
                    171:                for (lp = sp->y_locals; lp; lp = lp->y_next)
                    172:                        printf("%8R %c %s\n", lp->y_value, lsname(lp->y_ltype), lp->y_name);
                    173:        }
                    174: }
                    175: 
                    176: static
                    177: gsname(t)
                    178: int t;
                    179: {
                    180:        switch (t) {
                    181:        case S_TEXT:
                    182:                return ('T');
                    183:        case S_DATA:
                    184:                return ('D');
                    185:        case S_ABS:
                    186:                return ('A');
                    187:        case S_STAB:
                    188:                return ('L');
                    189:        default:
                    190:                return ('?');
                    191:        }
                    192: }
                    193: 
                    194: static
                    195: lsname(t)
                    196: int t;
                    197: {
                    198:        switch (t) {
                    199:        case S_LSYM:
                    200:                return ('l');
                    201:        case S_PSYM:
                    202:                return ('p');
                    203:        case S_RSYM:
                    204:                return ('r');
                    205:        case S_STSYM:
                    206:                return ('s');
                    207:        default:
                    208:                return ('?');
                    209:        }
                    210: }

unix.superglobalmegacorp.com

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