--- trunk/src/symbol.c 2007/10/08 16:18:27 10 +++ trunk/src/symbol.c 2007/10/08 16:18:38 12 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $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 $ * * Address to symbol translation routines. * @@ -94,7 +94,7 @@ /* - * get_symbol_name(): + * get_symbol_name_and_n_args(): * * Translate an address into a symbol name. The return value is a pointer * to a static char array, containing the symbol name. (In other words, @@ -107,11 +107,13 @@ * 0x1008, the symbol's name will be found in the static char array, and * *offset will be set to 0x8. * + * If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value. + * * If no symbol was found, NULL is returned instead. */ static char symbol_buf[SYMBOLBUF_MAX+1]; -char *get_symbol_name(struct symbol_context *sc, uint64_t addr, - uint64_t *offset) +char *get_symbol_name_and_n_args(struct symbol_context *sc, uint64_t addr, + uint64_t *offset, int *n_argsp) { struct symbol *s; int stepsize, ofs; @@ -141,6 +143,8 @@ (addr - s->addr)); if (offset != NULL) *offset = addr - s->addr; + if (n_argsp != NULL) + *n_argsp = s->n_args; return symbol_buf; } s = s->next; @@ -163,6 +167,8 @@ (addr - s->addr)); if (offset != NULL) *offset = addr - s->addr; + if (n_argsp != NULL) + *n_argsp = s->n_args; return symbol_buf; } @@ -190,12 +196,23 @@ /* + * get_symbol_name(): + * + * See get_symbol_name_and_n_args(). + */ +char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs) +{ + return get_symbol_name_and_n_args(sc, addr, offs, NULL); +} + + +/* * add_symbol_name(): * * Add a symbol to the symbol list. */ void add_symbol_name(struct symbol_context *sc, - uint64_t addr, uint64_t len, char *name, int type) + uint64_t addr, uint64_t len, char *name, int type, int n_args) { struct symbol *s; @@ -214,9 +231,29 @@ return; /* TODO: Maybe this should be optional? */ - if (name[0] == '$') + if (name[0] == '.' || name[0] == '$') return; + /* Quick test-hack: */ + if (n_args < 0) { + if (strcmp(name, "strlen") == 0) + n_args = 1; + if (strcmp(name, "strcmp") == 0) + n_args = 2; + if (strcmp(name, "strcpy") == 0) + n_args = 2; + if (strcmp(name, "strncmp") == 0) + n_args = 3; + if (strcmp(name, "memset") == 0) + n_args = 3; + if (strcmp(name, "memcpy") == 0) + n_args = 3; + if (strcmp(name, "bzero") == 0) + n_args = 2; + if (strcmp(name, "bcopy") == 0) + n_args = 3; + } + if ((addr >> 32) == 0 && (addr & 0x80000000ULL)) addr |= 0xffffffff00000000ULL; @@ -231,9 +268,10 @@ fprintf(stderr, "out of memory\n"); exit(1); } - s->addr = addr; - s->len = len; - s->type = type; + s->addr = addr; + s->len = len; + s->type = type; + s->n_args = n_args; sc->n_symbols ++; @@ -292,7 +330,7 @@ if (type == 't' || type == 'r' || type == 'g') continue; - add_symbol_name(sc, addr, len, b4, type); + add_symbol_name(sc, addr, len, b4, type, -1); } fclose(f);