Re: [hatari-devel] SozobonX symbol table format

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


On Dienstag, 9. Mai 2023 13:37:20 CEST Eero Tamminen wrote:
> I.e. are there any existing SozobonX binaries with symbols?

Not that i know of. Some popular applications where written with SozobonX 
(including ST-Guide, Scripter, appline etc), but none of them seem to have a 
symbol table in the released versions. That does not means of course there 
aren't any ;)

Anyway, the patch seems to be quite minimal, if you decide to use it:




diff --git a/src/debug/symbols-common.c b/src/debug/symbols-common.c
index 919f006e..c5115e68 100644
--- a/src/debug/symbols-common.c
+++ b/src/debug/symbols-common.c
@@ -558,10 +558,12 @@ static symbol_list_t* symbols_load_dri(FILE *fp, const prg_section_t *sections,
 	symbol_list_t *list;
 	symtype_t symtype;
 #define DRI_ENTRY_SIZE	14
-	char name[23];
+	char name[8 + 31 * 8 + 1];
 	uint16_t symid;
 	uint32_t address;
 	bool use_bssdata_offset;
+	bool sozobonx = false;
+
 	uint32_t textlen = sections[0].end - sections[0].offset;
 
 	if (tablesize % DRI_ENTRY_SIZE || !tablesize) {
@@ -577,7 +579,26 @@ static symbol_list_t* symbols_load_dri(FILE *fp, const prg_section_t *sections,
 	use_bssdata_offset = false;
 	count = 0;
 
-	for (i = 1; i <= symbols; i++) {
+	i = 0;
+	/*
+	 * check for SozobonX style tables. They start with a symbol type of 0x4200,
+	 * a value of $0x87654321, and a name of "SozobonX"
+	 */
+	if (symbols > 0 &&
+		fread(name, 8, 1, fp) == 1 &&
+		fread(&symid, sizeof(symid), 1, fp) == 1 &&
+		fread(&address, sizeof(address), 1, fp) == 1) {
+		address = be_swap32(address);
+		symid = be_swap16(symid);
+		if (symid == 0x4200 && address == 0x87654321 && memcmp(name, "SozobonX", 8) == 0) {
+			sozobonx = true;
+			i++;
+		} else {
+			fseek(fp, -DRI_ENTRY_SIZE, SEEK_CUR);
+		}
+	}
+
+	for (; i < symbols; i++) {
 		/* read DRI symbol table slot */
 		if (fread(name, 8, 1, fp) != 1 ||
 		    fread(&symid, sizeof(symid), 1, fp) != 1 ||
@@ -591,12 +612,35 @@ static symbol_list_t* symbols_load_dri(FILE *fp, const prg_section_t *sections,
 		if ((symid & 0x0048)) {
 			/* next slot is rest of name */
 			i += 1;
-			if (fread(name+8, 14, 1, fp) != 1) {
+			if (fread(name+8, DRI_ENTRY_SIZE, 1, fp) != 1) {
 				break;
 			}
-			name[22] = '\0';
+			name[8 + DRI_ENTRY_SIZE] = '\0';
 		} else {
-			name[8] = '\0';
+			int len;
+			uint16_t nextsymid;
+			uint32_t nextaddress;
+
+			len = 8;
+			if ((i + 1) < symbols && sozobonx) {
+				/* check for SozobonX style extended names */
+				while ((i + 1) < symbols && len <= 31 * 8) {
+					if (fread(&name[len], 8, 1, fp) != 1 ||
+					    fread(&nextsymid, sizeof(nextsymid), 1, fp) != 1 ||
+					    fread(&nextaddress, sizeof(nextaddress), 1, fp) != 1) {
+						break;
+					}
+					nextaddress = be_swap32(nextaddress);
+					nextsymid = be_swap16(nextsymid);
+					if ((nextsymid & 0x4200) != 0x4200 || nextaddress != 0x87654321) {
+						fseek(fp, -DRI_ENTRY_SIZE, SEEK_CUR);
+						break;
+					}
+					i++;
+					len += 8;
+				}
+			}
+			name[len] = '\0';
 		}
 
 		/* check section */
@@ -638,7 +682,7 @@ static symbol_list_t* symbols_load_dri(FILE *fp, const prg_section_t *sections,
 		assert(list->names[count].name);
 		count++;
 	}
-	if (i <= symbols) {
+	if (i < symbols) {
 		perror("ERROR: reading symbol failed");
 		symbol_list_free(list);
 		return NULL;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/