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