Lint
[deliverable/binutils-gdb.git] / binutils / objdump.c
1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Diddler.
5
6 BFD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 BFD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with BFD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /*
21 * Until there is other documentation, refer to the manual page dump(1) in
22 * the system 5 program's reference manual
23 */
24
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "getopt.h"
28 #include <stdio.h>
29 #include <ctype.h>
30
31 #define ELF_STAB_DISPLAY /* This code works, but uses internal
32 bfd and elf stuff. Flip this define
33 off if you need to just use generic
34 BFD interfaces. */
35
36 #ifdef ELF_STAB_DISPLAY
37 /* Internal headers for the ELF .stab-dump code - sorry. */
38 #define BYTES_IN_WORD 32
39 #include "aout/aout64.h"
40 #include "elf/internal.h"
41 extern Elf_Internal_Shdr *bfd_elf_find_section();
42 #endif /* ELF_STAB_DISPLAY */
43
44 char *xmalloc ();
45
46 char *default_target = NULL; /* default at runtime */
47
48 char *program_name = NULL;
49
50 int dump_section_contents; /* -s */
51 int dump_section_headers; /* -h */
52 boolean dump_file_header; /* -f */
53 int dump_symtab; /* -t */
54 int dump_reloc_info; /* -r */
55 int dump_ar_hdrs; /* -a */
56 int with_line_numbers; /* -l */
57 int dump_stab_section_info; /* -stabs */
58 boolean disassemble; /* -d */
59 boolean info; /* -i */
60 char *only;
61
62 PROTO (void, display_file, (char *filename, char *target));
63 PROTO (void, dump_data, (bfd * abfd));
64 PROTO (void, dump_relocs, (bfd * abfd));
65 PROTO (void, dump_symbols, (bfd * abfd));
66 PROTO (void, print_arelt_descr, (FILE *, bfd * abfd, boolean verbose));
67 \f
68
69
70
71
72
73
74 char *machine = (char *) NULL;
75 asymbol **syms;
76 asymbol **syms2;
77
78
79 unsigned int storage;
80
81 unsigned int symcount = 0;
82
83 void
84 usage ()
85 {
86 fprintf (stderr,
87 "usage: %s [-ahifdrtxsl] [-m machine] [-j section_name] obj ...\n",
88 program_name);
89 exit (1);
90 }
91
92 static struct option long_options[]=
93 {
94 {"syms", no_argument, &dump_symtab, 1},
95 {"reloc", no_argument, &dump_reloc_info, 1},
96 {"header", no_argument, &dump_section_headers, 1},
97 #ifdef ELF_STAB_DISPLAY
98 {"stabs", no_argument, &dump_stab_section_info, 1},
99 #endif
100 {0, no_argument, 0, 0}};
101
102
103 static void
104 dump_headers (abfd)
105 bfd *abfd;
106 {
107 asection *section;
108
109 for (section = abfd->sections;
110 section != (asection *) NULL;
111 section = section->next)
112 {
113 char *comma = "";
114
115 #define PF(x,y) \
116 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
117
118
119 printf ("SECTION %d [%s]\t: size %08x",
120 section->index,
121 section->name,
122 (unsigned) bfd_get_section_size_before_reloc (section));
123 printf (" vma ");
124 printf_vma (section->vma);
125 printf (" align 2**%u\n ",
126 section->alignment_power);
127 PF (SEC_ALLOC, "ALLOC");
128 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
129 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
130 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
131 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
132 PF (SEC_LOAD, "LOAD");
133 PF (SEC_RELOC, "RELOC");
134 PF (SEC_BALIGN, "BALIGN");
135 PF (SEC_READONLY, "READONLY");
136 PF (SEC_CODE, "CODE");
137 PF (SEC_DATA, "DATA");
138 PF (SEC_ROM, "ROM");
139 printf ("\n");
140 #undef PF
141 }
142 }
143
144 static asymbol **
145 DEFUN (slurp_symtab, (abfd),
146 bfd * abfd)
147 {
148 asymbol **sy = (asymbol **) NULL;
149
150 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
151 {
152 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
153 return (NULL);
154 }
155
156 storage = get_symtab_upper_bound (abfd);
157 if (storage)
158 {
159 sy = (asymbol **) malloc (storage);
160 if (sy == NULL)
161 {
162 fprintf (stderr, "%s: out of memory.\n", program_name);
163 exit (1);
164 }
165 }
166 symcount = bfd_canonicalize_symtab (abfd, sy);
167 return sy;
168 }
169
170 /* Sort symbols into value order */
171 static int
172 comp (ap, bp)
173 PTR ap;
174 PTR bp;
175 {
176 asymbol *a = *(asymbol **)ap;
177 asymbol *b = *(asymbol **)bp;
178 int diff;
179
180 if (a->name == (char *) NULL || (a->flags & (BSF_DEBUGGING)))
181 a->the_bfd = 0;
182 if (b->name == (char *) NULL || (b->flags & (BSF_DEBUGGING)))
183 b->the_bfd = 0;
184
185 diff = a->the_bfd - b->the_bfd;
186 if (diff)
187 {
188 return -diff;
189 }
190 diff = a->value - b->value;
191 if (diff)
192 {
193 return diff;
194 }
195 return a->section - b->section;
196 }
197
198 /* Print the supplied address symbolically if possible */
199 void
200 print_address (vma, stream)
201 bfd_vma vma;
202 FILE *stream;
203 {
204 /* Perform a binary search looking for the closest symbol to
205 the required value */
206
207 unsigned int min = 0;
208 unsigned int max = symcount;
209
210 unsigned int thisplace = 1;
211 unsigned int oldthisplace;
212
213 int vardiff;
214
215 if (symcount == 0)
216 {
217 fprintf_vma (stream, vma);
218 }
219 else
220 {
221 while (true)
222 {
223 oldthisplace = thisplace;
224 thisplace = (max + min) / 2;
225 if (thisplace == oldthisplace)
226 break;
227 vardiff = syms[thisplace]->value - vma;
228
229 if (vardiff)
230 {
231 if (vardiff > 0)
232 {
233 max = thisplace;
234 }
235 else
236 {
237 min = thisplace;
238 }
239 }
240 else
241 {
242 /* Totally awesome! the exact right symbol */
243 CONST char *match_name = syms[thisplace]->name;
244 int sym_len = strlen (match_name);
245
246 /* Avoid "filename.o" as a match */
247 if (sym_len > 2
248 && match_name[sym_len - 2] == '.'
249 && match_name[sym_len - 1] == 'o'
250 && thisplace + 1 < symcount
251 && syms[thisplace + 1]->value == vma)
252 match_name = syms[thisplace + 1]->name;
253 /* Totally awesome! the exact right symbol */
254 fprintf_vma (stream, vma);
255 fprintf (stream, " (%s+)0000", syms[thisplace]->name);
256 return;
257 }
258 }
259 /* We've run out of places to look, print the symbol before this one
260 see if this or the symbol before describes this location the best */
261
262 if (thisplace != 0)
263 {
264 if (syms[thisplace - 1]->value - vma >
265 syms[thisplace]->value - vma)
266 {
267 /* Previous symbol is in correct section and is closer */
268 thisplace--;
269 }
270 }
271
272 fprintf_vma (stream, vma);
273 if (syms[thisplace]->value > vma)
274 {
275 fprintf (stream, " (%s-)", syms[thisplace]->name);
276 fprintf (stream, "%04x", syms[thisplace]->value - vma);
277 }
278 else
279 {
280 fprintf (stream, " (%s+)", syms[thisplace]->name);
281 fprintf (stream, "%04x", vma - syms[thisplace]->value);
282 }
283 }
284 }
285
286 void
287 disassemble_data (abfd)
288 bfd *abfd;
289 {
290 bfd_byte *data = NULL;
291 bfd_arch_info_type *info;
292 bfd_size_type datasize = 0;
293 bfd_size_type i;
294 unsigned int (*print) ()= 0;
295 unsigned int print_insn_m68k ();
296 unsigned int print_insn_a29k ();
297 unsigned int print_insn_i960 ();
298 unsigned int print_insn_sparc ();
299 unsigned int print_insn_i386 ();
300 unsigned int print_insn_h8300 ();
301 enum bfd_architecture a;
302
303 asection *section;
304
305 /* Replace symbol section relative values with abs values */
306 boolean done_dot = false;
307
308 for (i = 0; i < symcount; i++)
309 {
310 syms[i]->value += syms[i]->section->vma;
311 }
312
313 /* We keep a copy of the symbols in the original order */
314 syms2 = slurp_symtab (abfd);
315
316 /* Sort the symbols into section and symbol order */
317 (void) qsort (syms, symcount, sizeof (asymbol *), comp);
318
319 /* Find the first useless symbol */
320 {
321 unsigned int i;
322
323 for (i = 0; i < symcount; i++)
324 {
325 if (syms[i]->the_bfd == 0)
326 {
327 symcount = i;
328 break;
329 }
330 }
331 }
332
333
334 if (machine != (char *) NULL)
335 {
336 info = bfd_scan_arch (machine);
337 if (info == 0)
338 {
339 fprintf (stderr, "%s: Can't use supplied machine %s\n",
340 program_name,
341 machine);
342 exit (1);
343 }
344 abfd->arch_info = info;
345 }
346
347 /* See if we can disassemble using bfd */
348
349 if (abfd->arch_info->disassemble)
350 {
351 print = abfd->arch_info->disassemble;
352 }
353 else
354 {
355 a = bfd_get_arch (abfd);
356 switch (a)
357 {
358 case bfd_arch_sparc:
359 print = print_insn_sparc;
360 break;
361 case bfd_arch_i386:
362 print = print_insn_i386;
363 break;
364 case bfd_arch_m68k:
365 print = print_insn_m68k;
366 break;
367 case bfd_arch_a29k:
368 print = print_insn_a29k;
369 break;
370 case bfd_arch_i960:
371 print = print_insn_i960;
372 break;
373 default:
374 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
375 program_name,
376 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
377 exit (1);
378 }
379
380 }
381
382 for (section = abfd->sections;
383 section != (asection *) NULL;
384 section = section->next)
385 {
386
387 if ((section->flags & SEC_LOAD)
388 && (only == (char *) NULL || strcmp (only, section->name) == 0))
389 {
390 printf ("Disassembly of section %s:\n", section->name);
391
392 if (bfd_get_section_size_before_reloc (section) == 0)
393 continue;
394
395 data = (bfd_byte *) malloc (bfd_get_section_size_before_reloc (section));
396
397 if (data == (bfd_byte *) NULL)
398 {
399 fprintf (stderr, "%s: memory exhausted.\n", program_name);
400 exit (1);
401 }
402 datasize = bfd_get_section_size_before_reloc (section);
403
404 bfd_get_section_contents (abfd, section, data, 0, bfd_get_section_size_before_reloc (section));
405
406 i = 0;
407 while (i < bfd_get_section_size_before_reloc (section))
408 {
409 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
410 data[i + 3] == 0)
411 {
412 if (done_dot == false)
413 {
414 printf ("...\n");
415 done_dot = true;
416 }
417 i += 4;
418 }
419 else
420 {
421 done_dot = false;
422 if (with_line_numbers)
423 {
424 static prevline;
425 CONST char *filename;
426 CONST char *functionname;
427 unsigned int line;
428
429 bfd_find_nearest_line (abfd,
430 section,
431 syms,
432 section->vma + i,
433 &filename,
434 &functionname,
435 &line);
436
437 if (filename && functionname && line && line != prevline)
438 {
439 printf ("%s:%u\n", filename, line);
440 prevline = line;
441 }
442 }
443 print_address (section->vma + i, stdout);
444 printf (" ");
445
446 i += print (section->vma + i,
447 data + i,
448 stdout);
449 putchar ('\n');
450 }
451 }
452 free (data);
453 }
454 }
455 }
456 \f
457 #ifdef ELF_STAB_DISPLAY
458
459 /* Define a table of stab values and print-strings. We wish the initializer
460 could be a direct-mapped table, but instead we build one the first
461 time we need it. */
462
463 #define STAB_STRING_LENGTH 6
464
465 char stab_name[256][STAB_STRING_LENGTH];
466
467 struct stab_print {
468 int value;
469 char string[STAB_STRING_LENGTH];
470 };
471
472 struct stab_print stab_print[] = {
473 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
474 #include "aout/stab.def"
475 #undef __define_stab
476 {0, 0}
477 };
478
479 /* This is a kludge for dumping the stabs section from an ELF file that
480 uses Sun stabs encoding. It has to use some hooks into BFD because
481 string table sections are not normally visible to BFD callers. */
482
483 void
484 dump_elf_stabs (abfd)
485 bfd *abfd;
486 {
487 Elf_Internal_Shdr *stab_hdr, *stabstr_hdr;
488 char *strtab;
489 struct internal_nlist *stabs, *stabs_end;
490 int i, j;
491
492 /* Initialize stab name array if first time. */
493 if (stab_name[0][0] == 0)
494 {
495 /* Fill in numeric values for all possible strings. */
496 for (i = 0; i < 256; i++)
497 {
498 sprintf (stab_name[i], "%d", i);
499 }
500 for (i = 0; stab_print[i].string[0]; i++)
501 strcpy (stab_name[stab_print[i].value], stab_print[i].string);
502 }
503
504 if (0 != strncmp ("elf", abfd->xvec->name, 3))
505 {
506 fprintf (stderr, "%s: %s is not in ELF format.\n", program_name,
507 abfd->filename);
508 return;
509 }
510
511 stab_hdr = bfd_elf_find_section (abfd, ".stab");
512 if (0 == stab_hdr)
513 {
514 fprintf (stderr, "%s: %s has no .stab section.\n", program_name,
515 abfd->filename);
516 return;
517 }
518
519 stabstr_hdr = bfd_elf_find_section (abfd, ".stabstr");
520 if (0 == stabstr_hdr)
521 {
522 fprintf (stderr, "%s: %s has no .stabstr section.\n", program_name,
523 abfd->filename);
524 return;
525 }
526
527 stabs = (struct internal_nlist *) xmalloc (stab_hdr ->sh_size);
528 strtab = (char *) xmalloc (stabstr_hdr->sh_size);
529 stabs_end = (struct internal_nlist *) (stab_hdr->sh_size + (char *)stabs);
530
531 if (bfd_seek (abfd, stab_hdr->sh_offset, L_SET) < 0 ||
532 stab_hdr->sh_size != bfd_read ((PTR)stabs, stab_hdr->sh_size, 1, abfd))
533 {
534 fprintf (stderr, "%s: reading .stab section of %s failed.\n",
535 program_name,
536 abfd->filename);
537 return;
538 }
539
540 if (bfd_seek (abfd, stabstr_hdr->sh_offset, L_SET) < 0 ||
541 stabstr_hdr->sh_size != bfd_read ((PTR)strtab, stabstr_hdr->sh_size,
542 1, abfd))
543 {
544 fprintf (stderr, "%s: reading .stabstr section of %s failed.\n",
545 program_name,
546 abfd->filename);
547 return;
548 }
549
550 #define SWAP_SYMBOL(symp, abfd) \
551 { \
552 (symp)->n_strx = bfd_h_get_32(abfd, \
553 (unsigned char *)&(symp)->n_strx); \
554 (symp)->n_desc = bfd_h_get_16 (abfd, \
555 (unsigned char *)&(symp)->n_desc); \
556 (symp)->n_value = bfd_h_get_32 (abfd, \
557 (unsigned char *)&(symp)->n_value); \
558 }
559
560 printf ("Contents of .stab section:\n\n");
561 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
562
563 /* We start the index at -1 because there is a dummy symbol on
564 the front of Sun's stabs-in-elf sections. */
565 for (i = -1; stabs < stabs_end; stabs++, i++)
566 {
567 SWAP_SYMBOL (stabs, abfd);
568 printf ("\n%-6d %-6s %-6d %-6d %08x %-6d", i,
569 stab_name [stabs->n_type],
570 stabs->n_other, stabs->n_desc, stabs->n_value,
571 stabs->n_strx);
572 if (stabs->n_strx < stabstr_hdr->sh_size)
573 printf (" %s", &strtab[stabs->n_strx]);
574 }
575 printf ("\n\n");
576 }
577 #endif /* ELF_STAB_DISPLAY */
578 \f
579 void
580 display_bfd (abfd)
581 bfd *abfd;
582 {
583
584 if (!bfd_check_format (abfd, bfd_object))
585 {
586 fprintf (stderr, "%s: %s not an object file\n", program_name,
587 abfd->filename);
588 return;
589 }
590 printf ("\n%s: file format %s\n", abfd->filename, abfd->xvec->name);
591 if (dump_ar_hdrs)
592 print_arelt_descr (stdout, abfd, true);
593
594 if (dump_file_header)
595 {
596 char *comma = "";
597
598 printf ("architecture: %s, ",
599 bfd_printable_arch_mach (bfd_get_arch (abfd),
600 bfd_get_mach (abfd)));
601 printf ("flags 0x%08x:\n", abfd->flags);
602
603 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
604 PF (HAS_RELOC, "HAS_RELOC");
605 PF (EXEC_P, "EXEC_P");
606 PF (HAS_LINENO, "HAS_LINENO");
607 PF (HAS_DEBUG, "HAS_DEBUG");
608 PF (HAS_SYMS, "HAS_SYMS");
609 PF (HAS_LOCALS, "HAS_LOCALS");
610 PF (DYNAMIC, "DYNAMIC");
611 PF (WP_TEXT, "WP_TEXT");
612 PF (D_PAGED, "D_PAGED");
613 printf ("\nstart address 0x");
614 printf_vma (abfd->start_address);
615 }
616 printf ("\n");
617
618 if (dump_section_headers)
619 dump_headers (abfd);
620 if (dump_symtab || dump_reloc_info || disassemble)
621 {
622 syms = slurp_symtab (abfd);
623 }
624 if (dump_symtab)
625 dump_symbols (abfd);
626 #ifdef ELF_STAB_DISPLAY
627 if (dump_stab_section_info)
628 dump_elf_stabs (abfd);
629 #endif
630 if (dump_reloc_info)
631 dump_relocs (abfd);
632 if (dump_section_contents)
633 dump_data (abfd);
634 if (disassemble)
635 disassemble_data (abfd);
636 }
637
638 void
639 display_file (filename, target)
640 char *filename;
641 char *target;
642 {
643 bfd *file, *arfile = (bfd *) NULL;
644
645 file = bfd_openr (filename, target);
646 if (file == NULL)
647 {
648 bfd_perror (filename);
649 return;
650 }
651
652 if (bfd_check_format (file, bfd_archive) == true)
653 {
654 printf ("In archive %s:\n", bfd_get_filename (file));
655 for (;;)
656 {
657 bfd_error = no_error;
658
659 arfile = bfd_openr_next_archived_file (file, arfile);
660 if (arfile == NULL)
661 {
662 if (bfd_error != no_more_archived_files)
663 bfd_perror (bfd_get_filename (file));
664 return;
665 }
666
667 display_bfd (arfile);
668 /* Don't close the archive elements; we need them for next_archive */
669 }
670 }
671 else
672 display_bfd (file);
673
674 bfd_close (file);
675 }
676 \f
677 /* Actually display the various requested regions */
678
679 void
680 dump_data (abfd)
681 bfd *abfd;
682 {
683 asection *section;
684 bfd_byte *data = 0;
685 bfd_size_type datasize = 0;
686 bfd_size_type i;
687
688 for (section = abfd->sections; section != NULL; section =
689 section->next)
690 {
691 int onaline = 16;
692
693 if (only == (char *) NULL ||
694 strcmp (only, section->name) == 0)
695 {
696 if (section->flags & SEC_HAS_CONTENTS)
697 {
698 printf ("Contents of section %s:\n", section->name);
699
700 if (bfd_get_section_size_before_reloc (section) == 0)
701 continue;
702 data = (bfd_byte *) malloc (bfd_get_section_size_before_reloc (section));
703 if (data == (bfd_byte *) NULL)
704 {
705 fprintf (stderr, "%s: memory exhausted.\n", program_name);
706 exit (1);
707 }
708 datasize = bfd_get_section_size_before_reloc (section);
709
710
711 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_get_section_size_before_reloc (section));
712
713 for (i = 0; i < bfd_get_section_size_before_reloc (section); i += onaline)
714 {
715 bfd_size_type j;
716
717 printf (" %04lx ", (unsigned long int) (i + section->vma));
718 for (j = i; j < i + onaline; j++)
719 {
720 if (j < bfd_get_section_size_before_reloc (section))
721 printf ("%02x", (unsigned) (data[j]));
722 else
723 printf (" ");
724 if ((j & 3) == 3)
725 printf (" ");
726 }
727
728 printf (" ");
729 for (j = i; j < i + onaline; j++)
730 {
731 if (j >= bfd_get_section_size_before_reloc (section))
732 printf (" ");
733 else
734 printf ("%c", isprint (data[j]) ? data[j] : '.');
735 }
736 putchar ('\n');
737 }
738 }
739 }
740 free (data);
741 }
742 }
743
744 /* Should perhaps share code and display with nm? */
745 void
746 dump_symbols (abfd)
747 bfd *abfd;
748 {
749
750 unsigned int count;
751 asymbol **current = syms;
752
753 printf ("SYMBOL TABLE:\n");
754
755 for (count = 0; count < symcount; count++)
756 {
757
758 if (*current && (*current)->the_bfd)
759 {
760 bfd_print_symbol ((*current)->the_bfd,
761 stdout,
762 *current, bfd_print_symbol_all);
763
764 printf ("\n");
765
766 }
767 current++;
768 }
769 printf ("\n");
770 printf ("\n");
771 }
772
773 void
774 dump_relocs (abfd)
775 bfd *abfd;
776 {
777 arelent **relpp;
778 unsigned int relcount;
779 asection *a;
780
781 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
782 {
783 if (a == &bfd_abs_section)
784 continue;
785 if (a == &bfd_und_section)
786 continue;
787 if (a == &bfd_com_section)
788 continue;
789
790 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
791
792 if (bfd_get_reloc_upper_bound (abfd, a) == 0)
793 {
794 printf (" (none)\n\n");
795 }
796 else
797 {
798 arelent **p;
799
800 relpp = (arelent **) xmalloc (bfd_get_reloc_upper_bound (abfd, a));
801 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
802 if (relcount == 0)
803 {
804 printf (" (none)\n\n");
805 }
806 else
807 {
808 printf ("\n");
809 printf ("OFFSET TYPE VALUE \n");
810
811 for (p = relpp; relcount && *p != (arelent *) NULL; p++,
812 relcount--)
813 {
814 arelent *q = *p;
815 CONST char *sym_name;
816
817 /* CONST char *section_name = q->section == (asection *)NULL ? "*abs" :*/
818 /* q->section->name;*/
819 CONST char *section_name = (*(q->sym_ptr_ptr))->section->name;
820
821 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
822 {
823 sym_name = (*(q->sym_ptr_ptr))->name;
824 }
825 else
826 {
827 sym_name = 0;
828 }
829 if (sym_name)
830 {
831 printf_vma (q->address);
832 printf (" %-8s %s",
833 q->howto->name,
834 sym_name);
835 }
836 else
837 {
838 printf_vma (q->address);
839 printf (" %-8s [%s]",
840 q->howto->name,
841 section_name);
842 }
843 if (q->addend)
844 {
845 printf ("+0x");
846 printf_vma (q->addend);
847 }
848 printf ("\n");
849 }
850 printf ("\n\n");
851 free (relpp);
852 }
853 }
854
855 }
856 }
857
858 #ifdef unix
859 #define _DUMMY_NAME_ "/dev/null"
860 #else
861 #define _DUMMY_NAME_ "##dummy"
862 #endif
863 static void
864 DEFUN (display_info_table, (first, last),
865 int first AND int last)
866 {
867 unsigned int i, j;
868 extern bfd_target *target_vector[];
869
870 printf ("\n%12s", " ");
871 for (i = first; i++ < last && target_vector[i];)
872 printf ("%s ", target_vector[i]->name);
873 printf ("\n");
874
875 for (j = (int) bfd_arch_obscure + 1; (int) j < (int) bfd_arch_last; j++)
876 if (strcmp (bfd_printable_arch_mach (j, 0), "UNKNOWN!") != 0)
877 {
878 printf ("%11s ", bfd_printable_arch_mach (j, 0));
879 for (i = first; i++ < last && target_vector[i];)
880 {
881 bfd_target *p = target_vector[i];
882 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
883 int l = strlen (p->name);
884 int ok = bfd_set_arch_mach (abfd, j, 0);
885
886 if (ok)
887 printf ("%s ", p->name);
888 else
889 {
890 while (l--)
891 printf ("%c", ok ? '*' : '-');
892 printf (" ");
893 }
894 }
895 printf ("\n");
896 }
897 }
898
899 static void
900 DEFUN_VOID (display_info)
901 {
902 char *colum;
903 unsigned int i, j, columns;
904 extern bfd_target *target_vector[];
905 extern char *getenv ();
906
907 printf ("BFD header file version %s\n", BFD_VERSION);
908 for (i = 0; target_vector[i]; i++)
909 {
910 bfd_target *p = target_vector[i];
911 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
912
913 printf ("%s\n (header %s, data %s)\n", p->name,
914 p->header_byteorder_big_p ? "big endian" : "little endian",
915 p->byteorder_big_p ? "big endian" : "little endian");
916 for (j = (int) bfd_arch_obscure + 1; j < (int) bfd_arch_last; j++)
917 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) j, 0))
918 printf (" %s\n",
919 bfd_printable_arch_mach ((enum bfd_architecture) j, 0));
920 }
921 columns = 0;
922 if (colum = getenv ("COLUMNS"))
923 columns = atoi (colum);
924 if (!columns)
925 columns = 80;
926 for (i = 0; target_vector[i];)
927 {
928 int old;
929 old = i;
930 for (j = 12; target_vector[i] && j < columns; i++)
931 j += strlen (target_vector[i]->name) + 1;
932 i--;
933 if (old == i)
934 break;
935 display_info_table (old, i);
936 }
937 }
938
939 /** main and like trivia */
940 int
941 main (argc, argv)
942 int argc;
943 char **argv;
944 {
945 int c;
946 extern int optind;
947 extern char *optarg;
948 char *target = default_target;
949 boolean seenflag = false;
950 int ind = 0;
951
952 bfd_init ();
953 program_name = *argv;
954
955 while ((c = getopt_long (argc, argv, "ib:m:dlfahrtxsj:", long_options, &ind))
956 != EOF)
957 {
958 seenflag = true;
959 switch (c)
960 {
961 case 'm':
962 machine = optarg;
963 break;
964 case 'j':
965 only = optarg;
966 break;
967 case 'l':
968 with_line_numbers = 1;
969 break;
970 case 'b':
971 target = optarg;
972 break;
973 case 'f':
974 dump_file_header = true;
975 break;
976 case 'i':
977 info = true;
978 break;
979 case 'x':
980 dump_symtab = 1;
981 dump_reloc_info = 1;
982 dump_file_header = true;
983 dump_ar_hdrs = 1;
984 dump_section_headers = 1;
985 break;
986 case 0:
987 break; /* we've been given a long option */
988 case 't':
989 dump_symtab = 1;
990 break;
991 case 'd':
992 disassemble = true;
993 break;
994 case 's':
995 dump_section_contents = 1;
996 break;
997 case 'r':
998 dump_reloc_info = 1;
999 break;
1000 case 'a':
1001 dump_ar_hdrs = 1;
1002 break;
1003 case 'h':
1004 dump_section_headers = 1;
1005 break;
1006 default:
1007 usage ();
1008 }
1009 }
1010
1011 if (seenflag == false)
1012 usage ();
1013
1014 if (info)
1015 {
1016 display_info ();
1017 }
1018 else
1019 {
1020 if (optind == argc)
1021 display_file ("a.out", target);
1022 else
1023 for (; optind < argc;)
1024 display_file (argv[optind++], target);
1025 }
1026 return 0;
1027 }
This page took 0.091404 seconds and 5 git commands to generate.