FreeCalypso > hg > freecalypso-reveng
annotate leo-obj/tool/symtab.c @ 155:15743b40e03a
tiobjd ctypes: print more useful hex byte offsets for struct fields
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 02 May 2014 23:41:44 +0000 |
parents | ed533d469838 |
children |
rev | line source |
---|---|
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Code for working with the symbol table |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
79
8f4996bff904
tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
78
diff
changeset
|
7 #include <stdlib.h> |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include "filestruct.h" |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include "intstruct.h" |
78
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
10 #include "coffconst.h" |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "globals.h" |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
78
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
13 static struct classmap { |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
14 int code; |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
15 char *str; |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
16 } classtab[] = { |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
17 {C_NULL, "NULL"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
18 {C_AUTO, "AUTO"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
19 {C_EXT, "EXT"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
20 {C_STAT, "STAT"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
21 {C_REG, "REG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
22 {C_EXTREF, "EXTREF"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
23 {C_LABEL, "LABEL"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
24 {C_ULABEL, "ULABEL"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
25 {C_MOS, "MOS"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
26 {C_ARG, "ARG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
27 {C_STRTAG, "STRTAG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
28 {C_MOU, "MOU"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
29 {C_UNTAG, "UNTAG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
30 {C_TPDEF, "TPDEF"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
31 {C_USTATIC, "USTATIC"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
32 {C_ENTAG, "ENTAG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
33 {C_MOE, "MOE"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
34 {C_REGPARM, "REGPARM"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
35 {C_FIELD, "FIELD"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
36 {C_UEXT, "UEXT"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
37 {C_STATLAB, "STATLAB"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
38 {C_EXTLAB, "EXTLAB"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
39 {C_SYSTEM, "SYSTEM"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
40 {C_VARARG, "VARARG"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
41 {C_BLOCK, "BLOCK"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
42 {C_FCN, "FCN"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
43 {C_EOS, "EOS"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
44 {C_FILE, "FILE"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
45 {C_LINE, "LINE"}, |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
46 {0, 0} |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
47 }; |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
48 |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
49 char * |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
50 storage_class_to_string(code, numbuf) |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
51 char *numbuf; |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
52 { |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
53 struct classmap *tp; |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
54 |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
55 for (tp = classtab; tp->str; tp++) |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
56 if (tp->code == code) |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
57 return(tp->str); |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
58 sprintf(numbuf, "%d", code); |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
59 return(numbuf); |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
60 } |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
61 |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
62 dump_symtab(show_aux) |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 { |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
64 unsigned n, i; |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 struct internal_syment *sym; |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 char *sec, secstr[8]; |
78
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
67 char *class, classbuf[8]; |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 |
78
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
69 printf("%-5s %-30s %-4s %-7s %-12s %-8s\n", |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 "Num", "Name", "Type", "Class", "Section", "Value"); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 for (n = 0; n < nsymtab; n++) { |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 sym = symtab[n]; |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (!sym) |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 continue; |
80
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
79
diff
changeset
|
75 if (sym->section) |
da103b9377e3
tiobjd: preparation for symbol sorting
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
79
diff
changeset
|
76 sec = sym->section->name; |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 else { |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 sprintf(secstr, "%d", sym->scnum); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 sec = secstr; |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 } |
78
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
81 class = storage_class_to_string(sym->class, classbuf); |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
82 printf("%-5u %-30s %04X %-7s %-12s %08X%s\n", |
c2445afce514
tiobjd: symbol storage classes decoded into mnemonics
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
77
diff
changeset
|
83 n, sym->name, sym->type, class, |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 sec, sym->value, sym->aux ? " Aux" : ""); |
142
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
85 if (sym->aux && show_aux) { |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
86 for (i = 0; i < 18; i++) |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
87 printf("%c%02X", i ? ' ' : '\t', sym->aux[i]); |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
88 putchar('\n'); |
ed533d469838
tiobjd: show symtab aux entries
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
130
diff
changeset
|
89 } |
77
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 return(0); |
590396e27e96
tiobjd: basics dump streamlined
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 } |
79
8f4996bff904
tiobjd: profile operation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
78
diff
changeset
|
93 |
81
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
94 static void |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
95 initial_fill_for_sort(sec) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
96 struct internal_scnhdr *sec; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
97 { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
98 unsigned n, m; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
99 struct internal_syment *sym; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
100 |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
101 m = 0; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
102 for (n = 0; n < nsymtab; n++) { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
103 sym = symtab[n]; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
104 if (!sym) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
105 continue; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
106 if (sym->section != sec) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
107 continue; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
108 sec->sorted_symbols[m++] = sym; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
109 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
110 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
111 |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
112 static int |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
113 compare_for_sort(p1, p2) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
114 struct internal_syment **p1, **p2; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
115 { |
116
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
116 /* sort by value first */ |
81
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
117 if ((*p1)->value < (*p2)->value) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
118 return(-1); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
119 if ((*p1)->value > (*p2)->value) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
120 return(1); |
116
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
121 /* if same value, retain the original symtab order */ |
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
122 if ((*p1)->number < (*p2)->number) |
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
123 return(-1); |
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
124 if ((*p1)->number > (*p2)->number) |
5f4141ee175b
tiobjd: retain the original symtab order for symbols at the same position
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
81
diff
changeset
|
125 return(1); |
81
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
126 else |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
127 return(0); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
128 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
129 |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
130 void |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
131 sort_symbols_of_sec(sec) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
132 struct internal_scnhdr *sec; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
133 { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
134 if (sec->sorted_symbols) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
135 return; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
136 if (!sec->nsymbols) { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
137 fprintf(stderr, |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
138 "BUG: sort_symbols_of_sec() called for section \"%s\" w/o symbols\n", |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
139 sec->name); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
140 exit(1); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
141 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
142 sec->sorted_symbols = malloc(sizeof(void *) * sec->nsymbols); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
143 if (!sec->sorted_symbols) { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
144 perror("malloc"); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
145 exit(1); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
146 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
147 initial_fill_for_sort(sec); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
148 qsort(sec->sorted_symbols, sec->nsymbols, sizeof(void *), |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
149 compare_for_sort); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
150 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
151 |
118
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
152 void |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
153 sort_symbols_of_all_sec() |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
154 { |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
155 unsigned n; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
156 struct internal_scnhdr *sec; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
157 |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
158 for (n = 0; n < nsections; n++) { |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
159 sec = sections + n; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
160 if (!sec->nsymbols) |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
161 continue; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
162 sort_symbols_of_sec(sec); |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
163 } |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
164 } |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
116
diff
changeset
|
165 |
81
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
166 cmd_nm() |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
167 { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
168 unsigned n, m; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
169 struct internal_scnhdr *sec; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
170 struct internal_syment *sym; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
171 char classbuf[8]; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
172 |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
173 get_int_section_table(); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
174 get_int_symbol_table(); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
175 for (n = 0; n < nsections; n++) { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
176 sec = sections + n; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
177 if (!sec->nsymbols) |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
178 continue; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
179 printf("%s:\n\n", sec->name); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
180 sort_symbols_of_sec(sec); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
181 for (m = 0; m < sec->nsymbols; m++) { |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
182 sym = sec->sorted_symbols[m]; |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
183 printf("%08X %-7s %s\n", sym->value, |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
184 storage_class_to_string(sym->class, classbuf), |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
185 sym->name); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
186 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
187 putchar('\n'); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
188 } |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
189 exit(0); |
192da19c7506
tiobjd: symbol sorting implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
80
diff
changeset
|
190 } |