Implemented support for *.map files.

This commit is contained in:
Daniel Beer 2010-03-13 13:41:39 +13:00
parent 78946d0052
commit 67b041ef7a
4 changed files with 81 additions and 1 deletions

View File

@ -26,7 +26,7 @@ clean:
.SUFFIXES: .c .o .SUFFIXES: .c .o
mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.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 $(CC) $(CFLAGS) -o $@ $^ -lusb
.c.o: .c.o:

View File

@ -34,4 +34,8 @@ int elf32_check(FILE *in);
int elf32_extract(FILE *in, imgfunc_t cb); int elf32_extract(FILE *in, imgfunc_t cb);
int elf32_syms(FILE *in); int elf32_syms(FILE *in);
/* *.map file support */
int symmap_check(FILE *in);
int symmap_syms(FILE *in);
#endif #endif

2
main.c
View File

@ -604,6 +604,8 @@ static int cmd_syms(char **arg)
if (elf32_check(in)) if (elf32_check(in))
result = elf32_syms(in); result = elf32_syms(in);
else if (symmap_check(in))
result = symmap_syms(in);
else else
fprintf(stderr, "syms: %s: unknown file type\n", *arg); fprintf(stderr, "syms: %s: unknown file type\n", *arg);

74
symmap.c Normal file
View File

@ -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 <stdlib.h>
#include <string.h>
#include <ctype.h>
#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;
}