FreeCalypso > hg > freecalypso-reveng
comparison ticoff/symtab.c @ 81:192da19c7506
tiobjd: symbol sorting implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 26 Mar 2014 03:23:20 +0000 |
parents | da103b9377e3 |
children | 5f4141ee175b |
comparison
equal
deleted
inserted
replaced
80:da103b9377e3 | 81:192da19c7506 |
---|---|
139 get_int_section_table(); | 139 get_int_section_table(); |
140 get_int_symbol_table(); | 140 get_int_symbol_table(); |
141 extern_profile_report(objfilename); | 141 extern_profile_report(objfilename); |
142 exit(0); | 142 exit(0); |
143 } | 143 } |
144 | |
145 static void | |
146 initial_fill_for_sort(sec) | |
147 struct internal_scnhdr *sec; | |
148 { | |
149 unsigned n, m; | |
150 struct internal_syment *sym; | |
151 | |
152 m = 0; | |
153 for (n = 0; n < nsymtab; n++) { | |
154 sym = symtab[n]; | |
155 if (!sym) | |
156 continue; | |
157 if (sym->section != sec) | |
158 continue; | |
159 sec->sorted_symbols[m++] = sym; | |
160 } | |
161 } | |
162 | |
163 static int | |
164 compare_for_sort(p1, p2) | |
165 struct internal_syment **p1, **p2; | |
166 { | |
167 if ((*p1)->value < (*p2)->value) | |
168 return(-1); | |
169 if ((*p1)->value > (*p2)->value) | |
170 return(1); | |
171 else | |
172 return(0); | |
173 } | |
174 | |
175 void | |
176 sort_symbols_of_sec(sec) | |
177 struct internal_scnhdr *sec; | |
178 { | |
179 if (sec->sorted_symbols) | |
180 return; | |
181 if (!sec->nsymbols) { | |
182 fprintf(stderr, | |
183 "BUG: sort_symbols_of_sec() called for section \"%s\" w/o symbols\n", | |
184 sec->name); | |
185 exit(1); | |
186 } | |
187 sec->sorted_symbols = malloc(sizeof(void *) * sec->nsymbols); | |
188 if (!sec->sorted_symbols) { | |
189 perror("malloc"); | |
190 exit(1); | |
191 } | |
192 initial_fill_for_sort(sec); | |
193 qsort(sec->sorted_symbols, sec->nsymbols, sizeof(void *), | |
194 compare_for_sort); | |
195 } | |
196 | |
197 cmd_nm() | |
198 { | |
199 unsigned n, m; | |
200 struct internal_scnhdr *sec; | |
201 struct internal_syment *sym; | |
202 char classbuf[8]; | |
203 | |
204 get_int_section_table(); | |
205 get_int_symbol_table(); | |
206 for (n = 0; n < nsections; n++) { | |
207 sec = sections + n; | |
208 if (!sec->nsymbols) | |
209 continue; | |
210 printf("%s:\n\n", sec->name); | |
211 sort_symbols_of_sec(sec); | |
212 for (m = 0; m < sec->nsymbols; m++) { | |
213 sym = sec->sorted_symbols[m]; | |
214 printf("%08X %-7s %s\n", sym->value, | |
215 storage_class_to_string(sym->class, classbuf), | |
216 sym->name); | |
217 } | |
218 putchar('\n'); | |
219 } | |
220 exit(0); | |
221 } |