changeset 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
files ticoff/main.c ticoff/symtab.c
diffstat 2 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ticoff/main.c	Wed Mar 26 01:24:17 2014 +0000
+++ b/ticoff/main.c	Wed Mar 26 02:00:44 2014 +0000
@@ -10,6 +10,7 @@
 #include "globals.h"
 
 extern int cmd_basics();
+extern int cmd_profile();
 extern int cmd_sechdr();
 extern int cmd_symtab();
 extern int dump_filehdr_info();
@@ -21,6 +22,7 @@
 	{"basics", cmd_basics},
 	{"dumpsym", cmd_symtab},	/* backward compat */
 	{"hdr", dump_filehdr_info},
+	{"profile", cmd_profile},
 	{"sechdr", cmd_sechdr},
 	{"symtab", cmd_symtab},
 	{0, 0}
--- 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);
+}