25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: symbol.c,v 1.24 2005/04/10 16:42:56 debug Exp $ |
* $Id: symbol.c,v 1.33 2005/10/26 14:37:02 debug Exp $ |
29 |
* |
* |
30 |
* Address to symbol translation routines. |
* Address to symbol translation routines. |
31 |
* |
* |
32 |
* This module is (probably) independant from the rest of the emulator. |
* This module is (probably) independent from the rest of the emulator. |
33 |
* symbol_init() must be called before any other function in this |
* symbol_init() must be called before any other function in this file is used. |
|
* file is used. |
|
34 |
*/ |
*/ |
35 |
|
|
36 |
#include <stdio.h> |
#include <stdio.h> |
93 |
|
|
94 |
|
|
95 |
/* |
/* |
96 |
* get_symbol_name(): |
* get_symbol_name_and_n_args(): |
97 |
* |
* |
98 |
* 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 |
99 |
* to a static char array, containing the symbol name. (In other words, |
* to a static char array, containing the symbol name. (In other words, |
106 |
* 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 |
107 |
* *offset will be set to 0x8. |
* *offset will be set to 0x8. |
108 |
* |
* |
109 |
|
* If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value. |
110 |
|
* |
111 |
* If no symbol was found, NULL is returned instead. |
* If no symbol was found, NULL is returned instead. |
112 |
*/ |
*/ |
113 |
static char symbol_buf[SYMBOLBUF_MAX+1]; |
static char symbol_buf[SYMBOLBUF_MAX+1]; |
114 |
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, |
115 |
uint64_t *offset) |
uint64_t *offset, int *n_argsp) |
116 |
{ |
{ |
117 |
struct symbol *s; |
struct symbol *s; |
118 |
int stepsize, ofs; |
int stepsize, ofs; |
142 |
(addr - s->addr)); |
(addr - s->addr)); |
143 |
if (offset != NULL) |
if (offset != NULL) |
144 |
*offset = addr - s->addr; |
*offset = addr - s->addr; |
145 |
|
if (n_argsp != NULL) |
146 |
|
*n_argsp = s->n_args; |
147 |
return symbol_buf; |
return symbol_buf; |
148 |
} |
} |
149 |
s = s->next; |
s = s->next; |
166 |
(addr - s->addr)); |
(addr - s->addr)); |
167 |
if (offset != NULL) |
if (offset != NULL) |
168 |
*offset = addr - s->addr; |
*offset = addr - s->addr; |
169 |
|
if (n_argsp != NULL) |
170 |
|
*n_argsp = s->n_args; |
171 |
return symbol_buf; |
return symbol_buf; |
172 |
} |
} |
173 |
|
|
195 |
|
|
196 |
|
|
197 |
/* |
/* |
198 |
|
* get_symbol_name(): |
199 |
|
* |
200 |
|
* See get_symbol_name_and_n_args(). |
201 |
|
*/ |
202 |
|
char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs) |
203 |
|
{ |
204 |
|
return get_symbol_name_and_n_args(sc, addr, offs, NULL); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
/* |
209 |
* add_symbol_name(): |
* add_symbol_name(): |
210 |
* |
* |
211 |
* Add a symbol to the symbol list. |
* Add a symbol to the symbol list. |
212 |
*/ |
*/ |
213 |
void add_symbol_name(struct symbol_context *sc, |
void add_symbol_name(struct symbol_context *sc, |
214 |
uint64_t addr, uint64_t len, char *name, int type) |
uint64_t addr, uint64_t len, char *name, int type, int n_args) |
215 |
{ |
{ |
216 |
struct symbol *s; |
struct symbol *s; |
217 |
|
|
226 |
exit(1); |
exit(1); |
227 |
} |
} |
228 |
|
|
229 |
|
if (name[0] == '\0') |
230 |
|
return; |
231 |
|
|
232 |
/* TODO: Maybe this should be optional? */ |
/* TODO: Maybe this should be optional? */ |
233 |
if (name[0] == '$') |
if (name[0] == '.' || name[0] == '$') |
234 |
return; |
return; |
235 |
|
|
236 |
|
/* Quick test-hack: */ |
237 |
|
if (n_args < 0) { |
238 |
|
if (strcmp(name, "strlen") == 0) |
239 |
|
n_args = 1; |
240 |
|
if (strcmp(name, "strcmp") == 0) |
241 |
|
n_args = 2; |
242 |
|
if (strcmp(name, "strcpy") == 0) |
243 |
|
n_args = 2; |
244 |
|
if (strcmp(name, "strncpy") == 0) |
245 |
|
n_args = 3; |
246 |
|
if (strcmp(name, "strlcpy") == 0) |
247 |
|
n_args = 3; |
248 |
|
if (strcmp(name, "strlcat") == 0) |
249 |
|
n_args = 3; |
250 |
|
if (strcmp(name, "strncmp") == 0) |
251 |
|
n_args = 3; |
252 |
|
if (strcmp(name, "memset") == 0) |
253 |
|
n_args = 3; |
254 |
|
if (strcmp(name, "memcpy") == 0) |
255 |
|
n_args = 3; |
256 |
|
if (strcmp(name, "bzero") == 0) |
257 |
|
n_args = 2; |
258 |
|
if (strcmp(name, "bcopy") == 0) |
259 |
|
n_args = 3; |
260 |
|
} |
261 |
|
|
262 |
if ((addr >> 32) == 0 && (addr & 0x80000000ULL)) |
if ((addr >> 32) == 0 && (addr & 0x80000000ULL)) |
263 |
addr |= 0xffffffff00000000ULL; |
addr |= 0xffffffff00000000ULL; |
264 |
|
|
273 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
274 |
exit(1); |
exit(1); |
275 |
} |
} |
276 |
s->addr = addr; |
s->addr = addr; |
277 |
s->len = len; |
s->len = len; |
278 |
s->type = type; |
s->type = type; |
279 |
|
s->n_args = n_args; |
280 |
|
|
281 |
sc->n_symbols ++; |
sc->n_symbols ++; |
282 |
|
|
317 |
memset(b4, 0, sizeof(b4)); |
memset(b4, 0, sizeof(b4)); |
318 |
fscanf(f, "%s %s\n", b1,b2); |
fscanf(f, "%s %s\n", b1,b2); |
319 |
if (strlen(b2) < 2 && !(b2[0]>='0' && b2[0]<='9')) { |
if (strlen(b2) < 2 && !(b2[0]>='0' && b2[0]<='9')) { |
320 |
strcpy(b3, b2); |
strlcpy(b3, b2, sizeof(b3)); |
321 |
strcpy(b2, "0"); |
strlcpy(b2, "0", sizeof(b2)); |
322 |
fscanf(f, "%s\n", b4); |
fscanf(f, "%s\n", b4); |
323 |
} else { |
} else { |
324 |
fscanf(f, "%s %s\n", b3,b4); |
fscanf(f, "%s %s\n", b3,b4); |
335 |
if (type == 't' || type == 'r' || type == 'g') |
if (type == 't' || type == 'r' || type == 'g') |
336 |
continue; |
continue; |
337 |
|
|
338 |
add_symbol_name(sc, addr, len, b4, type); |
add_symbol_name(sc, addr, len, b4, type, -1); |
339 |
} |
} |
340 |
|
|
341 |
fclose(f); |
fclose(f); |