diff leo-obj/tool/richsym.c @ 150:df01a4f4c272

tiobjd disasm -g: dump of function locals implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 29 Apr 2014 07:51:28 +0000
parents fdf3137c703a
children 6fe08feee018
line wrap: on
line diff
--- a/leo-obj/tool/richsym.c	Tue Apr 29 07:11:33 2014 +0000
+++ b/leo-obj/tool/richsym.c	Tue Apr 29 07:51:28 2014 +0000
@@ -203,7 +203,19 @@
 	char *buf;
 	int isund, len;
 
-	isund = (sym->name[0] == '_');
+	switch (sym->name[0]) {
+	case '_':
+		isund = 1;
+		break;
+	case '$':
+		if ((sym->type & 0x30) == 0x20)
+			isund = 1;
+		else
+			isund = 0;
+		break;
+	default:
+		isund = 0;
+	}
 	len = strlen(sym->name) + 1;
 	if (isund)
 		len--;
@@ -396,3 +408,70 @@
 	}
 	exit(0);
 }
+
+static int
+localsym_sanity_check(sym)
+	struct internal_syment *sym;
+{
+	if (!sym->aux) {
+		printf("; symbol #%u of class %s has no aux record\n",
+			sym->number, storage_class_to_string(sym->class, 0));
+		return(-1);
+	}
+	if (sym->scnum != -1) {
+		printf("; symbol #%u of class %s: section != ABS\n",
+			sym->number, storage_class_to_string(sym->class, 0));
+		return(-1);
+	}
+	return(0);
+}
+
+void
+richsym_function_locals(headsym)
+	struct internal_syment *headsym;
+{
+	unsigned n;
+	struct internal_syment *sym;
+	char classbuf[8];
+
+	for (n = headsym->number + 1; n < nsymtab; n++) {
+		sym = symtab[n];
+		if (!sym)
+			continue;
+		switch (sym->class) {
+		case C_REG:
+		case C_REGPARM:
+			if (localsym_sanity_check(sym) < 0)
+				continue;
+			if (sym->value > 0xF) {
+				printf(
+	"; symbol #%u of class %s: value is not a valid register number\n",
+					sym->number,
+					storage_class_to_string(sym->class, 0));
+				continue;
+			}
+			printf("; %s r%u: ",
+				storage_class_to_string(sym->class, 0),
+				sym->value);
+			richsym_print_in_c("", sym, 0);
+			continue;
+		case C_ARG:
+		case C_AUTO:
+			if (localsym_sanity_check(sym) < 0)
+				continue;
+			printf("; %s at 0x%x: ",
+				storage_class_to_string(sym->class, 0),
+				sym->value);
+			richsym_print_in_c("", sym, 0);
+			continue;
+		case C_FCN:
+			return;
+		default:
+			printf(
+			"; presumed local symbol #%u: unexpected class %s\n",
+				sym->number,
+				storage_class_to_string(sym->class, classbuf));
+			return;
+		}
+	}
+}