--- hatari/src/debug/symbols.c 2019/04/09 08:48:37 1.1 +++ hatari/src/debug/symbols.c 2019/04/09 08:52:00 1.1.1.4 @@ -12,7 +12,8 @@ * Symbol/address file contents are identical to "nm" output i.e. composed * of a hexadecimal addresses followed by a space, letter indicating symbol * type (T = text/code, D = data, B = BSS), space and the symbol name. - * Empty lines and lines starting with '#' are ignored. + * Empty lines and lines starting with '#' are ignored. AHCC SYM output + * compatible. */ const char Symbols_fileid[] = "Hatari symbols.c : " __DATE__ " " __TIME__; @@ -34,7 +35,7 @@ typedef struct { } symbol_t; typedef struct { - int count; + unsigned int count; symbol_t *addresses; /* items sorted by address */ symbol_t *names; /* items sorted by symbol name */ } symbol_list_t; @@ -83,7 +84,8 @@ static int symbols_by_name(const void *s ret = strcmp(name1, name2); if (!ret) { - fprintf(stderr, "WARNING: symbol '%s' listed twice.\n", name1); + fprintf(stderr, "WARNING: addresses 0x%x & 0x%x have the same '%s' name.\n", + ((const symbol_t*)s1)->address, ((const symbol_t*)s2)->address, name1); } return ret; } @@ -97,7 +99,7 @@ static int symbols_by_name(const void *s static symbol_list_t* Symbols_Load(const char *filename, Uint32 offset, Uint32 maxaddr, symtype_t gettype) { symbol_list_t *list; - char symchar, buffer[80], name[MAX_SYM_SIZE+1], *buf; + char symchar, buffer[128], name[MAX_SYM_SIZE+1], *buf; int count, line, symbols; symtype_t symtype; Uint32 address; @@ -111,8 +113,8 @@ static symbol_list_t* Symbols_Load(const /* count content lines */ symbols = 0; while (fgets(buffer, sizeof(buffer), fp)) { - /* skip comments */ - if (*buffer == '#') { + /* skip comments (AHCC SYM file comments start with '*') */ + if (*buffer == '#' || *buffer == '*') { continue; } /* skip empty lines */ @@ -139,8 +141,8 @@ static symbol_list_t* Symbols_Load(const /* read symbols */ count = 0; for (line = 1; fgets(buffer, sizeof(buffer), fp); line++) { - /* skip comments */ - if (*buffer == '#') { + /* skip comments (AHCC SYM file comments start with '*') */ + if (*buffer == '#' || *buffer == '*') { continue; } /* skip empty lines */ @@ -149,7 +151,7 @@ static symbol_list_t* Symbols_Load(const continue; } assert(count < symbols); /* file not modified in meanwhile? */ - if (sscanf(buffer, "%x %c %32[0-9A-Za-z_]s", &address, &symchar, name) != 3) { + if (sscanf(buffer, "%x %c %32[0-9A-Za-z_.]s", &address, &symchar, name) != 3) { fprintf(stderr, "WARNING: syntax error in '%s' on line %d, skipping.\n", filename, line); continue; } @@ -160,6 +162,7 @@ static symbol_list_t* Symbols_Load(const } switch (toupper(symchar)) { case 'T': symtype = SYMTYPE_TEXT; break; + case 'O': symtype = SYMTYPE_DATA; break; /* AHCC type for _StkSize etc */ case 'D': symtype = SYMTYPE_DATA; break; case 'B': symtype = SYMTYPE_BSS; break; default: @@ -210,7 +213,7 @@ static symbol_list_t* Symbols_Load(const */ static void Symbols_Free(symbol_list_t* list) { - int i; + unsigned int i; if (!list) { return; @@ -235,8 +238,8 @@ static void Symbols_Free(symbol_list_t* */ static char* Symbols_MatchByName(symbol_list_t* list, symtype_t symtype, const char *text, int state) { + static unsigned int i, len; const symbol_t *entry; - static int i, len; if (!list) { return NULL; @@ -426,8 +429,8 @@ const char* Symbols_GetByDspAddress(Uint static void Symbols_Show(symbol_list_t* list, const char *sorttype) { symbol_t *entry, *entries; + unsigned int i; char symchar; - int i; if (!list) { fprintf(stderr, "No symbols!\n"); @@ -538,3 +541,15 @@ int Symbols_Command(int nArgc, char *psA } return DEBUGGER_CMDDONE; } + +/** + * Return how many symbols are loaded/available + */ +unsigned int Symbols_CpuCount(void) +{ + return (CpuSymbolsList ? CpuSymbolsList->count : 0); +} +unsigned int Symbols_DspCount(void) +{ + return (DspSymbolsList ? DspSymbolsList->count : 0); +}