Annotation of cci/usr/src/bin/adb/sym.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * adb - symbol table routines
        !             3:  */
        !             4: #include "defs.h"
        !             5: #include <stab.h>
        !             6: 
        !             7: /*
        !             8:  * Lookup a symbol by name.
        !             9:  */
        !            10: struct nlist *
        !            11: lookup(symstr)
        !            12:        char *symstr;
        !            13: {
        !            14:        register struct nlist *sp;
        !            15: 
        !            16:        cursym = 0;
        !            17:        if (symtab)
        !            18:        for (sp = symtab; sp < esymtab; sp++)
        !            19:                /* SHOULD DO SOME OF EQSYM INLINE TO SAVE TIME */
        !            20:                if ((sp->n_type&N_STAB)==0 && eqsym(sp->n_un.n_name, symstr, '_'))
        !            21:                        return(cursym = sp);
        !            22:        return (0);
        !            23: }
        !            24: 
        !            25: /*
        !            26:  * Find the closest symbol to val, and return
        !            27:  * the difference between val and the symbol found.
        !            28:  * Leave a pointer to the symbol found as cursym.
        !            29:  */
        !            30: findsym(val, type)
        !            31:        register val;
        !            32:        int type;
        !            33: {
        !            34:        register diff;
        !            35:        register struct nlist *sp;
        !            36: 
        !            37:        cursym = 0;
        !            38:        diff = MAXINT;
        !            39:        if (type == NSYM || symtab == 0)
        !            40:                return (diff);
        !            41:        for (sp = symtab; sp < esymtab; sp++) {
        !            42:                if (sp->n_type&N_STAB || (sp->n_type&N_EXT)==0)
        !            43:                        continue;
        !            44:                if (val - sp->n_value < diff && val >= sp->n_value) {
        !            45:                        diff = val - sp->n_value;
        !            46:                        cursym = sp;
        !            47:                        if (diff == 0)
        !            48:                                break;
        !            49:                }
        !            50:        }
        !            51:        return (diff);
        !            52: }
        !            53: 
        !            54: /*
        !            55:  * Advance cursym to the next local variable.
        !            56:  * Leave its value in localval as a side effect.
        !            57:  * Return 0 at end of file.
        !            58:  */
        !            59: localsym(cframe)
        !            60:        ADDR cframe;
        !            61: {
        !            62:        register int type;
        !            63:        register struct nlist *sp;
        !            64: 
        !            65:        if (cursym)
        !            66:        for (sp = cursym; ++sp < esymtab; ) {
        !            67:                type = sp->n_type;
        !            68:                if (sp->n_un.n_name[0] =='_' || type == N_FN)
        !            69:                        return (0);
        !            70:                switch (type) {
        !            71: 
        !            72:                case N_TEXT:
        !            73:                case N_TEXT|N_EXT:
        !            74:                case N_DATA:
        !            75:                case N_DATA|N_EXT:
        !            76:                case N_BSS:
        !            77:                case N_BSS|N_EXT:
        !            78:                        localval = sp->n_value;
        !            79:                        cursym = sp;
        !            80:                        return (1);
        !            81: 
        !            82:                case N_LSYM:
        !            83:                        localval = cframe - sp->n_value;
        !            84:                        cursym = sp;
        !            85:                        return (1);
        !            86: 
        !            87:                case N_PSYM:
        !            88:                case N_ABS:
        !            89:                        localval = cframe + sp->n_value;
        !            90:                        cursym = sp;
        !            91:                        return (1);
        !            92:                }
        !            93:        }
        !            94:        cursym = 0;
        !            95:        return (0);
        !            96: }
        !            97: 
        !            98: /*
        !            99:  * Print value v and then the string s.
        !           100:  * If v is not zero, then we look for a nearby symbol
        !           101:  * and print name+offset if we find a symbol for which
        !           102:  * offset is small enough.
        !           103:  *
        !           104:  * For values which are just into kernel address space
        !           105:  * that they match exactly or that they be more than maxoff
        !           106:  * bytes into kernel space.
        !           107:  */
        !           108: psymoff(v, type, s)
        !           109:        register v;
        !           110:        int type;
        !           111:        char *s;
        !           112: {
        !           113:        register w;
        !           114: 
        !           115:        if (v) 
        !           116:                w = findsym(v, type);
        !           117:        if (v==0 || w >= maxoff)
        !           118:                printf(LPRMODE, v);
        !           119:        else {
        !           120:                printf("%s", cursym->n_un.n_name);
        !           121:                if (w)
        !           122:                        printf(OFFMODE, w);
        !           123:        }
        !           124:        printf(s);
        !           125: }
        !           126: 
        !           127: /*
        !           128:  * Print value v symbolically if it has a reasonable
        !           129:  * interpretation as name+offset.  If not, print nothing.
        !           130:  * Used in printing out registers $r.
        !           131:  */
        !           132: valpr(v, idsp)
        !           133: {
        !           134:        register off_t d;
        !           135: 
        !           136:        d = findsym(v, idsp);
        !           137:        if (d >= maxoff)
        !           138:                return;
        !           139:        printf("%s", cursym->n_un.n_name);
        !           140:        if (d)
        !           141:                printf(OFFMODE, d);
        !           142: }

unix.superglobalmegacorp.com

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