25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: symbol.c,v 1.26 2005/06/21 16:22:52 debug Exp $ |
* $Id: symbol.c,v 1.29 2005/08/09 17:18:22 debug Exp $ |
29 |
* |
* |
30 |
* Address to symbol translation routines. |
* Address to symbol translation routines. |
31 |
* |
* |
94 |
|
|
95 |
|
|
96 |
/* |
/* |
97 |
* get_symbol_name(): |
* get_symbol_name_and_n_args(): |
98 |
* |
* |
99 |
* Translate an address into a symbol name. The return value is a pointer |
* Translate an address into a symbol name. The return value is a pointer |
100 |
* to a static char array, containing the symbol name. (In other words, |
* to a static char array, containing the symbol name. (In other words, |
107 |
* 0x1008, the symbol's name will be found in the static char array, and |
* 0x1008, the symbol's name will be found in the static char array, and |
108 |
* *offset will be set to 0x8. |
* *offset will be set to 0x8. |
109 |
* |
* |
110 |
|
* If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value. |
111 |
|
* |
112 |
* If no symbol was found, NULL is returned instead. |
* If no symbol was found, NULL is returned instead. |
113 |
*/ |
*/ |
114 |
static char symbol_buf[SYMBOLBUF_MAX+1]; |
static char symbol_buf[SYMBOLBUF_MAX+1]; |
115 |
char *get_symbol_name(struct symbol_context *sc, uint64_t addr, |
char *get_symbol_name_and_n_args(struct symbol_context *sc, uint64_t addr, |
116 |
uint64_t *offset) |
uint64_t *offset, int *n_argsp) |
117 |
{ |
{ |
118 |
struct symbol *s; |
struct symbol *s; |
119 |
int stepsize, ofs; |
int stepsize, ofs; |
143 |
(addr - s->addr)); |
(addr - s->addr)); |
144 |
if (offset != NULL) |
if (offset != NULL) |
145 |
*offset = addr - s->addr; |
*offset = addr - s->addr; |
146 |
|
if (n_argsp != NULL) |
147 |
|
*n_argsp = s->n_args; |
148 |
return symbol_buf; |
return symbol_buf; |
149 |
} |
} |
150 |
s = s->next; |
s = s->next; |
167 |
(addr - s->addr)); |
(addr - s->addr)); |
168 |
if (offset != NULL) |
if (offset != NULL) |
169 |
*offset = addr - s->addr; |
*offset = addr - s->addr; |
170 |
|
if (n_argsp != NULL) |
171 |
|
*n_argsp = s->n_args; |
172 |
return symbol_buf; |
return symbol_buf; |
173 |
} |
} |
174 |
|
|
196 |
|
|
197 |
|
|
198 |
/* |
/* |
199 |
|
* get_symbol_name(): |
200 |
|
* |
201 |
|
* See get_symbol_name_and_n_args(). |
202 |
|
*/ |
203 |
|
char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs) |
204 |
|
{ |
205 |
|
return get_symbol_name_and_n_args(sc, addr, offs, NULL); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
/* |
210 |
* add_symbol_name(): |
* add_symbol_name(): |
211 |
* |
* |
212 |
* Add a symbol to the symbol list. |
* Add a symbol to the symbol list. |
213 |
*/ |
*/ |
214 |
void add_symbol_name(struct symbol_context *sc, |
void add_symbol_name(struct symbol_context *sc, |
215 |
uint64_t addr, uint64_t len, char *name, int type) |
uint64_t addr, uint64_t len, char *name, int type, int n_args) |
216 |
{ |
{ |
217 |
struct symbol *s; |
struct symbol *s; |
218 |
|
|
231 |
return; |
return; |
232 |
|
|
233 |
/* TODO: Maybe this should be optional? */ |
/* TODO: Maybe this should be optional? */ |
234 |
if (name[0] == '$') |
if (name[0] == '.' || name[0] == '$') |
235 |
return; |
return; |
236 |
|
|
237 |
|
/* Quick test-hack: */ |
238 |
|
if (n_args < 0) { |
239 |
|
if (strcmp(name, "strlen") == 0) |
240 |
|
n_args = 1; |
241 |
|
if (strcmp(name, "strcmp") == 0) |
242 |
|
n_args = 2; |
243 |
|
if (strcmp(name, "strcpy") == 0) |
244 |
|
n_args = 2; |
245 |
|
if (strcmp(name, "strncmp") == 0) |
246 |
|
n_args = 3; |
247 |
|
if (strcmp(name, "memset") == 0) |
248 |
|
n_args = 3; |
249 |
|
if (strcmp(name, "memcpy") == 0) |
250 |
|
n_args = 3; |
251 |
|
if (strcmp(name, "bzero") == 0) |
252 |
|
n_args = 2; |
253 |
|
if (strcmp(name, "bcopy") == 0) |
254 |
|
n_args = 3; |
255 |
|
} |
256 |
|
|
257 |
if ((addr >> 32) == 0 && (addr & 0x80000000ULL)) |
if ((addr >> 32) == 0 && (addr & 0x80000000ULL)) |
258 |
addr |= 0xffffffff00000000ULL; |
addr |= 0xffffffff00000000ULL; |
259 |
|
|
268 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
269 |
exit(1); |
exit(1); |
270 |
} |
} |
271 |
s->addr = addr; |
s->addr = addr; |
272 |
s->len = len; |
s->len = len; |
273 |
s->type = type; |
s->type = type; |
274 |
|
s->n_args = n_args; |
275 |
|
|
276 |
sc->n_symbols ++; |
sc->n_symbols ++; |
277 |
|
|
330 |
if (type == 't' || type == 'r' || type == 'g') |
if (type == 't' || type == 'r' || type == 'g') |
331 |
continue; |
continue; |
332 |
|
|
333 |
add_symbol_name(sc, addr, len, b4, type); |
add_symbol_name(sc, addr, len, b4, type, -1); |
334 |
} |
} |
335 |
|
|
336 |
fclose(f); |
fclose(f); |