diff --git a/Makefile b/Makefile index 358b520..2b9955e 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ clean: .SUFFIXES: .c .o mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.o \ - bsl.o sim.o + bsl.o sim.o symmap.o $(CC) $(CFLAGS) -o $@ $^ -lusb .c.o: diff --git a/binfile.h b/binfile.h index 494dba6..2927e8b 100644 --- a/binfile.h +++ b/binfile.h @@ -34,4 +34,8 @@ int elf32_check(FILE *in); int elf32_extract(FILE *in, imgfunc_t cb); int elf32_syms(FILE *in); +/* *.map file support */ +int symmap_check(FILE *in); +int symmap_syms(FILE *in); + #endif diff --git a/main.c b/main.c index 7b606c1..eead061 100644 --- a/main.c +++ b/main.c @@ -604,6 +604,8 @@ static int cmd_syms(char **arg) if (elf32_check(in)) result = elf32_syms(in); + else if (symmap_check(in)) + result = symmap_syms(in); else fprintf(stderr, "syms: %s: unknown file type\n", *arg); diff --git a/symmap.c b/symmap.c new file mode 100644 index 0000000..41060b6 --- /dev/null +++ b/symmap.c @@ -0,0 +1,74 @@ +/* MSPDebug - debugging tool for the eZ430 + * Copyright (C) 2009, 2010 Daniel Beer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include "binfile.h" +#include "stab.h" + +int symmap_check(FILE *in) +{ + char buf[128]; + int i; + int spc_count = 0; + + rewind(in); + if (!fgets(buf, sizeof(buf), in)) + return 0; + + for (i = 0; buf[i]; i++) { + if (buf[i] == '\r' || buf[i] == '\n') + break; + + if (buf[i] < 32 || buf[i] > 126) + return 0; + + if (isspace(buf[i])) + spc_count++; + } + + return spc_count >= 2; +} + +int symmap_syms(FILE *in) +{ + rewind(in); + char buf[128]; + + while (fgets(buf, sizeof(buf), in)) { + char *addr = strtok(buf, " \t\r\n"); + char *name; + + strtok(NULL, " \t\r\n"); + name = strtok(NULL, " \t\r\n"); + + if (addr && name) { + int addr_val = strtoul(addr, NULL, 16); + int offset = stab_add_string(NULL, 0); + + if (stab_add_string(name, strlen(name) + 1) < 0) + return -1; + + if (stab_add_symbol(offset, addr_val) < 0) + return -1; + } + } + + return 0; +}