diff ticoff/symtab.c @ 79:8f4996bff904

tiobjd: profile operation implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 26 Mar 2014 02:00:44 +0000
parents c2445afce514
children da103b9377e3
line wrap: on
line diff
--- a/ticoff/symtab.c	Wed Mar 26 01:24:17 2014 +0000
+++ b/ticoff/symtab.c	Wed Mar 26 02:00:44 2014 +0000
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include "filestruct.h"
 #include "intstruct.h"
 #include "coffconst.h"
@@ -84,3 +85,59 @@
 	}
 	return(0);
 }
+
+extern_profile_report(heading)
+	char *heading;
+{
+	unsigned n;
+	int first_extern = -1, last_extern;
+	struct internal_syment *sym;
+	int defs_started = 0;
+
+	for (n = 0; n < nsymtab; n++) {
+		sym = symtab[n];
+		if (!sym)
+			continue;
+		if (sym->class != C_EXT)
+			continue;
+		if (sym->scnum < 0) {
+			fprintf(stderr,
+		"symbol entry #%u: unexpected negative scnum for C_EXT\n", n);
+			exit(1);
+		}
+		if (sym->scnum == 0) {	/* undef external ref */
+			if (first_extern < 0)
+				first_extern = n;
+			last_extern = n;
+			continue;
+		}
+		if (!defs_started) {
+			printf("%s defines:\n\n", heading);
+			defs_started = 1;
+		}
+		printf("%s (%s)\n", sym->name, sections[sym->scnum - 1].name);
+	}
+	if (defs_started)
+		putchar('\n');
+	if (first_extern < 0)
+		return(0);
+	printf("%s references:\n\n", heading);
+	for (n = first_extern; n <= last_extern; n++) {
+		sym = symtab[n];
+		if (!sym)
+			continue;
+		if (sym->class != C_EXT || sym->scnum)
+			continue;
+		printf("%s\n", sym->name);
+	}
+	putchar('\n');
+	return(0);
+}
+
+cmd_profile()
+{
+	get_int_section_table();
+	get_int_symbol_table();
+	extern_profile_report(objfilename);
+	exit(0);
+}