# HG changeset patch # User Michael Spacefalcon # Date 1395799244 0 # Node ID 8f4996bff9043722f0335161a085afdf01fbf551 # Parent c2445afce514d8ed2b8b715b0755afbf29231742 tiobjd: profile operation implemented diff -r c2445afce514 -r 8f4996bff904 ticoff/main.c --- 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} diff -r c2445afce514 -r 8f4996bff904 ticoff/symtab.c --- 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 #include +#include #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); +}