|
|
1.1 root 1: /*
2: * adb - symbol table routines
3: */
4: #include "defs.h"
5: #include <a.out.h>
6: #include <stab.h>
7: #include <sys/types.h>
8:
9: /*
10: * Lookup a symbol by name
11: * leave a pointer to the symbol in cursym
12: */
13: struct nlist *
14: lookup(symstr)
15: register char *symstr;
16: {
17: register struct nlist *sp;
18:
19: cursym = 0;
20: if (symtab)
21: for (sp = symtab; sp < esymtab; sp++)
22: switch (sp->n_type &~ N_EXT) {
23: case N_FUN:
24: case N_STSYM:
25: case N_TEXT:
26: case N_DATA:
27: case N_BSS:
28: case N_ABS:
29: if (eqsym(sp->n_un.n_name, symstr, '_'))
30: return(cursym = sp);
31: }
32: return (0);
33: }
34:
35: /*
36: * find the symbols for a routine
37: */
38:
39: int
40: findrtn(rtn)
41: char *rtn;
42: {
43: register struct nlist *sp;
44:
45: cursym = 0;
46: if (symtab)
47: for (sp = symtab; sp < esymtab; sp++)
48: switch (sp->n_type &~ N_EXT) {
49: case N_FUN:
50: case N_TEXT:
51: if (eqsym(sp->n_un.n_name, rtn, '_')) {
52: cursym = sp;
53: return (1);
54: }
55: }
56: return (0);
57: }
58:
59: /*
60: * Find the closest symbol to val, and return
61: * the difference between val and the symbol found.
62: * Leave a pointer to the symbol found as cursym.
63: */
64: WORD
65: findsym(val, type)
66: register WORD val;
67: int type;
68: {
69: register WORD diff;
70: register struct nlist *sp;
71:
72: cursym = 0;
73: diff = HUGE;
74: if ((type & SPTYPE) == NOSP || symtab == 0)
75: return (diff);
76: for (sp = symtab; sp < esymtab; sp++)
77: switch (sp->n_type) {
78: case N_TEXT|N_EXT:
79: case N_DATA|N_EXT:
80: case N_BSS|N_EXT:
81: case N_ABS|N_EXT:
82: case N_FUN:
83: case N_STSYM:
84: /* data objects? */
85: /* should look at type here */
86: if (val - sp->n_value < diff && val >= sp->n_value) {
87: diff = val - sp->n_value;
88: cursym = sp;
89: if (diff == 0)
90: break;
91: }
92: }
93: if (cursym && cursym->n_value == 0 && diff != 0)
94: return (HUGE);
95: return (diff);
96: }
97:
98: /*
99: * advance cursym to the next local variable
100: * return 0 if the next variable is a global
101: */
102: int
103: localsym()
104: {
105: register struct nlist *sp;
106:
107: if (cursym == NULL)
108: return (0);
109: for (sp = cursym; ++sp < esymtab; )
110: switch (sp->n_type) {
111: case N_TEXT:
112: case N_DATA:
113: if (sp->n_un.n_name[0] == '_') /* C global */
114: return (0);
115: continue;
116: case N_LSYM:
117: case N_PSYM:
118: case N_RSYM:
119: case N_STSYM:
120: cursym = sp;
121: return (1);
122:
123: case N_FUN:
124: case N_EFUN:
125: return (0);
126: }
127: cursym = 0;
128: return (0);
129: }
130:
131: /*
132: * Print value v and then the string s.
133: * If v is not zero, then we look for a nearby symbol
134: * and print name+offset if we find a symbol for which
135: * offset is small enough.
136: */
137: psymoff(v, type, s)
138: WORD v;
139: int type;
140: char *s;
141: {
142: WORD w;
143: int r;
144:
145: if ((type & SPTYPE) == REGSP) {
146: printf("%%%R", v);
147: printf(s);
148: return;
149: }
150: if (v)
151: w = findsym(v, type);
152: if (v==0 || w >= maxoff)
153: printf("%R", v);
154: else {
155: printf("%s", cursym->n_un.n_name);
156: if (w)
157: printf("+%R", w);
158: }
159: printf(s);
160: }
161:
162: /*
163: * Print value v symbolically if it has a reasonable
164: * interpretation as name+offset. If not, print nothing.
165: * Used in printing out registers $r.
166: */
167: valpr(v, idsp)
168: WORD v;
169: {
170: WORD d;
171:
172: d = findsym(v, idsp);
173: if (d >= maxoff)
174: return;
175: printf("%s", cursym->n_un.n_name);
176: if (d)
177: printf("+%R", d);
178: }
179:
180: eqsym(s1, s2, c)
181: register char *s1, *s2;
182: {
183:
184: if (!strcmp(s1,s2))
185: return (1);
186: if (*s1 == c && !strcmp(s1+1, s2))
187: return (1);
188: return (0);
189: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.