changeset 149:fdf3137c703a

tiobjd richsym handling: prep for handling function locals
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 29 Apr 2014 07:11:33 +0000
parents 13cc7e19ecec
children df01a4f4c272
files leo-obj/tool/richsym.c
diffstat 1 files changed, 43 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/leo-obj/tool/richsym.c	Tue Apr 29 06:45:45 2014 +0000
+++ b/leo-obj/tool/richsym.c	Tue Apr 29 07:11:33 2014 +0000
@@ -136,6 +136,8 @@
 get_base_type_of_syment(sym, is_typedef)
 	struct internal_syment *sym;
 {
+	unsigned idx;
+
 	switch (sym->type & 0xF) {
 	case T_VOID:
 		return("void");
@@ -155,14 +157,23 @@
 	case T_DOUBLE:
 		return("double");
 	case T_STRUCT:
-		return get_struct_type_name(get_u32(sym->aux), C_STRTAG,
-						is_typedef);
+		idx = get_u32(sym->aux);
+		if (idx)
+			return get_struct_type_name(idx, C_STRTAG, is_typedef);
+		else
+			return("struct ?");
 	case T_UNION:
-		return get_struct_type_name(get_u32(sym->aux), C_UNTAG,
-						is_typedef);
+		idx = get_u32(sym->aux);
+		if (idx)
+			return get_struct_type_name(idx, C_UNTAG, is_typedef);
+		else
+			return("union ?");
 	case T_ENUM:
-		return get_struct_type_name(get_u32(sym->aux), C_ENTAG,
-						is_typedef);
+		idx = get_u32(sym->aux);
+		if (idx)
+			return get_struct_type_name(idx, C_ENTAG, is_typedef);
+		else
+			return("enum ?");
 	case T_UCHAR:
 		if (is_typedef)
 			return("unsigned char");
@@ -185,6 +196,31 @@
 	}
 }
 
+static char *
+cdecl_obj_name(sym)
+	struct internal_syment *sym;
+{
+	char *buf;
+	int isund, len;
+
+	isund = (sym->name[0] == '_');
+	len = strlen(sym->name) + 1;
+	if (isund)
+		len--;
+	else
+		len += 2;
+	buf = malloc(len);
+	if (!buf) {
+		perror("malloc");
+		exit(1);
+	}
+	if (isund)
+		strcpy(buf, sym->name + 1);
+	else
+		sprintf(buf, "\"%s\"", sym->name);
+	return(buf);
+}
+
 richsym_print_in_c(prefix, sym, is_typedef)
 	char *prefix;
 	struct internal_syment *sym;
@@ -194,12 +230,7 @@
 
 	base_type = get_base_type_of_syment(sym, is_typedef);
 	dertype = sym->type >> 4;
-	s1 = malloc(strlen(sym->name));
-	if (!s1) {
-		perror("malloc");
-		exit(1);
-	}
-	strcpy(s1, sym->name + 1);
+	s1 = cdecl_obj_name(sym);
 	last_ptr = 0;
 	narray = 0;
 	for (; dertype; dertype >>= 2) {