comparison leo-obj/tool/disasm.c @ 152:fcf1ef773a57

tiobjd disasm: implemented -l option to show line markers
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 01 May 2014 01:01:58 +0000
parents 6fe08feee018
children 71e25510f5af
comparison
equal deleted inserted replaced
151:6fe08feee018 152:fcf1ef773a57
13 13
14 extern unsigned get_u16(), get_u32(); 14 extern unsigned get_u16(), get_u32();
15 extern char *storage_class_to_string(); 15 extern char *storage_class_to_string();
16 16
17 int auto_xlat_section_relocs = 1; 17 int auto_xlat_section_relocs = 1;
18 int disasm_richsym; 18 int disasm_richsym, disasm_lineno;
19 extern int richsym_print_bitsize; 19 extern int richsym_print_bitsize;
20 20
21 static void 21 static void
22 find_better_symbol(sec, symp, addp) 22 find_better_symbol(sec, symp, addp)
23 struct internal_scnhdr *sec; 23 struct internal_scnhdr *sec;
179 struct internal_syment *sym; 179 struct internal_syment *sym;
180 struct internal_reloc *rel; 180 struct internal_reloc *rel;
181 struct hint *hint = sec->hints; 181 struct hint *hint = sec->hints;
182 u_char *asciz_end; 182 u_char *asciz_end;
183 unsigned asciz_len; 183 unsigned asciz_len;
184 unsigned *lineno_arr;
185 unsigned lineno_cur, lineno_total;
184 186
185 if (sec->nreloc) 187 if (sec->nreloc)
186 get_relocs_of_sec(sec); 188 get_relocs_of_sec(sec);
189 if (disasm_lineno && sec->nlineent)
190 get_lineno_addrs(sec, &lineno_arr, &lineno_total);
191 else {
192 lineno_arr = 0;
193 lineno_total = 0;
194 }
187 symnum = relnum = 0; 195 symnum = relnum = 0;
196 lineno_cur = 0;
188 for (pos = 0; pos < sec->size; pos += incr) { 197 for (pos = 0; pos < sec->size; pos += incr) {
189 headroom = sec->size - pos; 198 headroom = sec->size - pos;
190 while (symnum < sec->nsymbols) { 199 while (symnum < sec->nsymbols) {
191 sym = sec->sorted_symbols[symnum]; 200 sym = sec->sorted_symbols[symnum];
192 if (sym->value > pos) { 201 if (sym->value > pos) {
219 } 228 }
220 } else 229 } else
221 gothint = 0; 230 gothint = 0;
222 if (gothint && pos == hint->pos && hint->linebrk) 231 if (gothint && pos == hint->pos && hint->linebrk)
223 putchar('\n'); 232 putchar('\n');
233 if (lineno_cur < lineno_total) {
234 if (pos >= lineno_arr[lineno_cur]) {
235 puts("; line");
236 lineno_cur++;
237 } else {
238 if (lineno_arr[lineno_cur] - pos < headroom)
239 headroom = lineno_arr[lineno_cur] - pos;
240 }
241 }
224 printf("%8x:\t", pos); 242 printf("%8x:\t", pos);
225 if (gothint && hint->type) { 243 if (gothint && hint->type) {
226 if (rel) { 244 if (rel) {
227 printf("error: hint/reloc conflict\n"); 245 printf("error: hint/reloc conflict\n");
228 return; 246 return;
349 handle_symbol(sym, &state, &linebrk); 367 handle_symbol(sym, &state, &linebrk);
350 symnum++; 368 symnum++;
351 } 369 }
352 if (linebrk) 370 if (linebrk)
353 printf("%8x:\t<end of section>\n", sec->size); 371 printf("%8x:\t<end of section>\n", sec->size);
372 if (lineno_arr)
373 free(lineno_arr);
354 } 374 }
355 375
356 void 376 void
357 disasm_bss(sec) 377 disasm_bss(sec)
358 struct internal_scnhdr *sec; 378 struct internal_scnhdr *sec;
412 char *hintsfile = 0; 432 char *hintsfile = 0;
413 struct internal_scnhdr *sec; 433 struct internal_scnhdr *sec;
414 unsigned secnum; 434 unsigned secnum;
415 int c; 435 int c;
416 436
417 while ((c = getopt(argc, argv, "bgh:s")) != EOF) 437 while ((c = getopt(argc, argv, "bgh:ls")) != EOF)
418 switch (c) { 438 switch (c) {
419 case 'b': 439 case 'b':
420 richsym_print_bitsize++; 440 richsym_print_bitsize++;
421 continue; 441 continue;
422 case 'g': 442 case 'g':
423 disasm_richsym++; 443 disasm_richsym++;
424 continue; 444 continue;
425 case 'h': 445 case 'h':
426 hintsfile = optarg; 446 hintsfile = optarg;
447 continue;
448 case 'l':
449 disasm_lineno++;
427 continue; 450 continue;
428 case 's': 451 case 's':
429 auto_xlat_section_relocs = 0; 452 auto_xlat_section_relocs = 0;
430 continue; 453 continue;
431 default: 454 default: