1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program 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)
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 /* Internal headers for the ELF .stab-dump code - sorry. */
29 #define BYTES_IN_WORD 32
30 #include "aout/aout64.h"
31 #include "elf/internal.h"
32 extern Elf_Internal_Shdr
*bfd_elf_find_section();
34 #ifndef FPRINTF_ALREADY_DECLARED
35 extern int fprintf
PARAMS ((FILE *, CONST
char *, ...));
38 char *default_target
= NULL
; /* default at runtime */
40 extern char *program_version
;
42 int show_version
= 0; /* show the version number */
43 int dump_section_contents
; /* -s */
44 int dump_section_headers
; /* -h */
45 boolean dump_file_header
; /* -f */
46 int dump_symtab
; /* -t */
47 int dump_reloc_info
; /* -r */
48 int dump_ar_hdrs
; /* -a */
49 int with_line_numbers
; /* -l */
50 int dump_stab_section_info
; /* --stabs */
51 boolean disassemble
; /* -d */
52 boolean formats_info
; /* -i */
53 char *only
; /* -j secname */
55 /* Extra info to pass to the disassembler address printing function. */
56 struct objdump_disasm_info
{
61 /* Architecture to disassemble for, or default if NULL. */
62 char *machine
= (char *) NULL
;
64 /* The symbol table. */
67 /* Number of bytes allocated for `syms'. */
70 /* Number of symbols in `syms'. */
71 unsigned int symcount
= 0;
73 /* Forward declarations. */
76 display_file
PARAMS ((char *filename
, char *target
));
79 dump_data
PARAMS ((bfd
*abfd
));
82 dump_relocs
PARAMS ((bfd
*abfd
));
85 dump_symbols
PARAMS ((bfd
*abfd
));
88 display_bfd
PARAMS ((bfd
*abfd
));
91 usage (stream
, status
)
96 Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
97 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
98 [--section-headers] [--headers] [--info] [--section=section-name]\n\
99 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
100 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
101 at least one option besides -l (--line-numbers) must be given\n",
106 static struct option long_options
[]=
108 {"all-headers", no_argument
, NULL
, 'x'},
109 {"architecture", required_argument
, NULL
, 'm'},
110 {"archive-headers", no_argument
, NULL
, 'a'},
111 {"disassemble", no_argument
, NULL
, 'd'},
112 {"file-headers", no_argument
, NULL
, 'f'},
113 {"full-contents", no_argument
, NULL
, 's'},
114 {"headers", no_argument
, NULL
, 'h'},
115 {"help", no_argument
, NULL
, 'H'},
116 {"info", no_argument
, NULL
, 'i'},
117 {"line-numbers", no_argument
, NULL
, 'l'},
118 {"reloc", no_argument
, NULL
, 'r'},
119 {"section", required_argument
, NULL
, 'j'},
120 {"section-headers", no_argument
, NULL
, 'h'},
121 {"stabs", no_argument
, &dump_stab_section_info
, 1},
122 {"syms", no_argument
, NULL
, 't'},
123 {"target", required_argument
, NULL
, 'b'},
124 {"version", no_argument
, &show_version
, 1},
125 {0, no_argument
, 0, 0}
129 dump_section_header (abfd
, section
, ignored
)
137 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
140 printf ("SECTION %d [%s]\t: size %08x",
143 (unsigned) bfd_get_section_size_before_reloc (section
));
145 printf_vma (section
->vma
);
146 printf (" align 2**%u\n ",
147 section
->alignment_power
);
148 PF (SEC_ALLOC
, "ALLOC");
149 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
150 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
151 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
152 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
153 PF (SEC_LOAD
, "LOAD");
154 PF (SEC_RELOC
, "RELOC");
156 PF (SEC_BALIGN
, "BALIGN");
158 PF (SEC_READONLY
, "READONLY");
159 PF (SEC_CODE
, "CODE");
160 PF (SEC_DATA
, "DATA");
162 PF (SEC_DEBUGGING
, "DEBUGGING");
171 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
178 asymbol
**sy
= (asymbol
**) NULL
;
180 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
182 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
186 storage
= get_symtab_upper_bound (abfd
);
189 sy
= (asymbol
**) xmalloc (storage
);
191 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
194 fprintf (stderr
, "%s: %s: Invalid symbol table\n",
195 program_name
, bfd_get_filename (abfd
));
201 /* Filter out (in place) symbols that are useless for disassembly.
202 COUNT is the number of elements in SYMBOLS.
203 Return the number of useful symbols. */
206 remove_useless_symbols (symbols
, count
)
210 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
214 asymbol
*sym
= *in_ptr
++;
216 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
218 if (sym
->flags
& (BSF_DEBUGGING
))
220 if (sym
->section
== &bfd_und_section
221 || bfd_is_com_section (sym
->section
))
226 return out_ptr
- symbols
;
229 /* Sort symbols into value order. */
232 compare_symbols (ap
, bp
)
236 asymbol
*a
= *(asymbol
**)ap
;
237 asymbol
*b
= *(asymbol
**)bp
;
239 if (a
->value
> b
->value
)
241 else if (a
->value
< b
->value
)
244 if (a
->section
> b
->section
)
246 else if (a
->section
< b
->section
)
251 /* Print VMA symbolically to INFO if possible. */
254 objdump_print_address (vma
, info
)
256 struct disassemble_info
*info
;
258 /* @@ For relocateable files, should filter out symbols belonging to
259 the wrong section. Unfortunately, not enough information is supplied
260 to this routine to determine the correct section in all cases. */
261 /* @@ Would it speed things up to cache the last two symbols returned,
262 and maybe their address ranges? For many processors, only one memory
263 operand can be present at a time, so the 2-entry cache wouldn't be
264 constantly churned by code doing heavy memory accesses. */
266 /* Indices in `syms'. */
267 unsigned int min
= 0;
268 unsigned int max
= symcount
;
269 unsigned int thisplace
= 1;
270 unsigned int oldthisplace
;
274 fprintf_vma (info
->stream
, vma
);
279 /* Perform a binary search looking for the closest symbol to
280 the required value. */
287 oldthisplace
= thisplace
;
288 thisplace
= (max
+ min
) / 2;
289 if (thisplace
== oldthisplace
)
291 sym
= syms
[thisplace
];
292 vardiff
= sym
->value
- vma
;
294 sym_sec
= sym
->section
;
299 else if (vardiff
< 0)
304 /* We've run out of places to look; see whether this or the
305 symbol before this describes this location the best. */
309 if (syms
[thisplace
- 1]->value
- vma
< syms
[thisplace
]->value
- vma
)
311 /* Previous symbol is in correct section and is closer. */
318 /* If this symbol isn't global, search for one with the same value
320 bfd_vma val
= syms
[thisplace
]->value
;
322 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
323 for (i
= thisplace
- 1; i
>= 0; i
--)
325 if (syms
[i
]->value
== val
326 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
327 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
328 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
334 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
335 for (i
= thisplace
+ 1; i
< symcount
; i
++)
337 if (syms
[i
]->value
== val
338 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
339 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
340 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
348 /* If the file is relocateable, and the symbol could be from this
349 section, prefer a symbol from this section over symbols from
350 others, even if the other symbol's value might be closer.
352 Note that this may be wrong for some symbol references if the
353 sections have overlapping memory ranges, but in that case there's
354 no way to tell what's desired without looking at the relocation
356 struct objdump_disasm_info
*aux
;
359 aux
= (struct objdump_disasm_info
*) info
->application_data
;
360 if ((aux
->abfd
->flags
& HAS_RELOC
)
361 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
362 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
363 + bfd_get_section_size_before_reloc (aux
->sec
))
364 && syms
[thisplace
]->section
!= aux
->sec
)
366 for (i
= thisplace
+ 1; i
< symcount
; i
++)
367 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
370 if (syms
[i
]->section
== aux
->sec
)
377 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
378 if (syms
[thisplace
]->value
> vma
)
380 char buf
[30], *p
= buf
;
381 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
384 fprintf (info
->stream
, "-%s", p
);
386 else if (vma
> syms
[thisplace
]->value
)
388 char buf
[30], *p
= buf
;
389 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
392 fprintf (info
->stream
, "+%s", p
);
394 fprintf (info
->stream
, ">");
415 disassemble_data (abfd
)
419 unsigned int (*print
) () = 0; /* Old style */
420 disassembler_ftype disassemble
= 0; /* New style */
421 struct disassemble_info disasm_info
;
422 struct objdump_disasm_info aux
;
425 CONST
char *prev_function
= "";
429 boolean done_dot
= false;
431 /* Replace symbol section relative values with abs values. */
432 for (i
= 0; i
< symcount
; i
++)
434 syms
[i
]->value
+= syms
[i
]->section
->vma
;
437 symcount
= remove_useless_symbols (syms
, symcount
);
439 /* Sort the symbols into section and symbol order */
440 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
442 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
443 disasm_info
.application_data
= (PTR
) &aux
;
445 disasm_info
.print_address_func
= objdump_print_address
;
447 if (machine
!= (char *) NULL
)
449 bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
452 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
457 abfd
->arch_info
= info
;
460 /* See if we can disassemble using bfd. */
462 if (abfd
->arch_info
->disassemble
)
464 print
= abfd
->arch_info
->disassemble
;
468 enum bfd_architecture a
= bfd_get_arch (abfd
);
471 /* If you add a case to this table, also add it to the
472 ARCH_all definition right above this function. */
475 /* As far as I know we only handle big-endian 29k objects. */
476 disassemble
= print_insn_big_a29k
;
481 disassemble
= print_insn_alpha
;
486 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
487 disassemble
= print_insn_h8300h
;
489 disassemble
= print_insn_h8300
;
494 disassemble
= print_insn_h8500
;
499 disassemble
= print_insn_hppa
;
504 disassemble
= print_insn_i386
;
509 disassemble
= print_insn_i960
;
514 disassemble
= print_insn_m68k
;
519 disassemble
= print_insn_m88k
;
524 if (abfd
->xvec
->byteorder_big_p
)
525 disassemble
= print_insn_big_mips
;
527 disassemble
= print_insn_little_mips
;
531 case bfd_arch_rs6000
:
532 disassemble
= print_insn_rs6000
;
537 disassemble
= print_insn_sh
;
542 disassemble
= print_insn_sparc
;
547 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
548 disassemble
= print_insn_z8001
;
550 disassemble
= print_insn_z8002
;
554 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
556 bfd_printable_arch_mach (a
, 0));
562 for (section
= abfd
->sections
;
563 section
!= (asection
*) NULL
;
564 section
= section
->next
)
566 bfd_byte
*data
= NULL
;
567 bfd_size_type datasize
= 0;
569 if (!(section
->flags
& SEC_LOAD
))
571 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
574 printf ("Disassembly of section %s:\n", section
->name
);
576 datasize
= bfd_get_section_size_before_reloc (section
);
580 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
582 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
585 disasm_info
.buffer
= data
;
586 disasm_info
.buffer_vma
= section
->vma
;
587 disasm_info
.buffer_length
= datasize
;
589 while (i
< disasm_info
.buffer_length
)
591 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
594 if (done_dot
== false)
604 if (with_line_numbers
)
606 CONST
char *filename
;
607 CONST
char *functionname
;
610 if (bfd_find_nearest_line (abfd
,
618 if (functionname
&& *functionname
619 && strcmp(functionname
, prev_function
))
621 printf ("%s():\n", functionname
);
622 prev_function
= functionname
;
626 if (line
&& line
!= prevline
)
628 printf ("%s:%u\n", filename
, line
);
633 objdump_print_address (section
->vma
+ i
, &disasm_info
);
636 if (disassemble
) /* New style */
638 int bytes
= (*disassemble
)(section
->vma
+ i
,
645 i
+= print (section
->vma
+ i
,
656 /* Define a table of stab values and print-strings. We wish the initializer
657 could be a direct-mapped table, but instead we build one the first
667 struct stab_print stab_print
[] = {
668 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
669 #include "aout/stab.def"
674 void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
675 char *strsect_name
));
677 /* Dump the stabs sections from an object file that has a section that
678 uses Sun stabs encoding. It has to use some hooks into BFD because
679 string table sections are not normally visible to BFD callers. */
685 /* Allocate and initialize stab name array if first time. */
686 if (stab_name
== NULL
)
690 stab_name
= (char **) xmalloc (256 * sizeof(char *));
691 /* Clear the array. */
692 for (i
= 0; i
< 256; i
++)
694 /* Fill in the defined stabs. */
695 for (i
= 0; *stab_print
[i
].string
; i
++)
696 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
699 dump_section_stabs (abfd
, ".stab", ".stabstr");
700 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
701 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
702 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
705 static struct internal_nlist
*stabs
;
706 static bfd_size_type stab_size
;
709 static bfd_size_type stabstr_size
;
711 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
712 and string table section STRSECT_NAME into `strtab'.
713 If the section exists and was read, allocate the space and return true.
714 Otherwise return false. */
717 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
722 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
723 asection
*stabsect
, *stabstrsect
;
724 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
727 stab_hdr
= bfd_elf_find_section (abfd
, stabsect_name
);
729 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
731 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
733 printf ("No %s section present\n\n", stabsect_name
);
738 stabstr_hdr
= bfd_elf_find_section (abfd
, strsect_name
);
740 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
742 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
744 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
745 bfd_get_filename (abfd
), strsect_name
);
749 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
750 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
752 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
753 strtab
= (char *) xmalloc (stabstr_size
);
757 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
758 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
760 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
761 program_name
, stabsect_name
,
762 bfd_get_filename (abfd
));
770 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
775 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
776 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
778 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
779 program_name
, strsect_name
,
780 bfd_get_filename (abfd
));
788 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
793 #define SWAP_SYMBOL(symp, abfd) \
795 (symp)->n_strx = bfd_h_get_32(abfd, \
796 (unsigned char *)&(symp)->n_strx); \
797 (symp)->n_desc = bfd_h_get_16 (abfd, \
798 (unsigned char *)&(symp)->n_desc); \
799 (symp)->n_value = bfd_h_get_32 (abfd, \
800 (unsigned char *)&(symp)->n_value); \
803 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
804 using string table section STRSECT_NAME (in `strtab'). */
807 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
813 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
814 struct internal_nlist
*stabp
= stabs
,
815 *stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
817 printf ("Contents of %s section:\n\n", stabsect_name
);
818 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
820 /* Loop through all symbols and print them.
822 We start the index at -1 because there is a dummy symbol on
823 the front of stabs-in-{coff,elf} sections that supplies sizes. */
825 for (i
= -1; stabp
< stabs_end
; stabp
++, i
++)
827 SWAP_SYMBOL (stabp
, abfd
);
828 printf ("\n%-6d ", i
);
829 /* Either print the stab name, or, if unnamed, print its number
830 again (makes consistent formatting for tools like awk). */
831 if (stab_name
[stabp
->n_type
])
832 printf ("%-6s", stab_name
[stabp
->n_type
]);
835 printf (" %-6d %-6d ", stabp
->n_other
, stabp
->n_desc
);
836 printf_vma (stabp
->n_value
);
837 printf (" %-6lu", stabp
->n_strx
);
839 /* Symbols with type == 0 (N_UNDF) specify the length of the
840 string table associated with this file. We use that info
841 to know how to relocate the *next* file's string table indices. */
843 if (stabp
->n_type
== N_UNDF
)
845 file_string_table_offset
= next_file_string_table_offset
;
846 next_file_string_table_offset
+= stabp
->n_value
;
850 /* Using the (possibly updated) string table offset, print the
851 string (if any) associated with this symbol. */
853 if ((stabp
->n_strx
+ file_string_table_offset
) < stabstr_size
)
854 printf (" %s", &strtab
[stabp
->n_strx
+ file_string_table_offset
]);
863 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
868 if (read_section_stabs (abfd
, stabsect_name
, strsect_name
))
870 print_section_stabs (abfd
, stabsect_name
, strsect_name
);
877 dump_bfd_header (abfd
)
882 printf ("architecture: %s, ",
883 bfd_printable_arch_mach (bfd_get_arch (abfd
),
884 bfd_get_mach (abfd
)));
885 printf ("flags 0x%08x:\n", abfd
->flags
);
887 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
888 PF (HAS_RELOC
, "HAS_RELOC");
889 PF (EXEC_P
, "EXEC_P");
890 PF (HAS_LINENO
, "HAS_LINENO");
891 PF (HAS_DEBUG
, "HAS_DEBUG");
892 PF (HAS_SYMS
, "HAS_SYMS");
893 PF (HAS_LOCALS
, "HAS_LOCALS");
894 PF (DYNAMIC
, "DYNAMIC");
895 PF (WP_TEXT
, "WP_TEXT");
896 PF (D_PAGED
, "D_PAGED");
897 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
898 printf ("\nstart address 0x");
899 printf_vma (abfd
->start_address
);
908 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
910 bfd_nonfatal (bfd_get_filename (abfd
));
911 if (bfd_error
== file_ambiguously_recognized
)
913 list_matching_formats (matching
);
919 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
922 print_arelt_descr (stdout
, abfd
, true);
923 if (dump_file_header
)
924 dump_bfd_header (abfd
);
926 if (dump_section_headers
)
928 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
930 syms
= slurp_symtab (abfd
);
934 if (dump_stab_section_info
)
938 if (dump_section_contents
)
940 /* Note that disassemble_data re-orders the syms table, but that is
941 safe - as long as it is done last! */
943 disassemble_data (abfd
);
947 display_file (filename
, target
)
951 bfd
*file
, *arfile
= (bfd
*) NULL
;
953 file
= bfd_openr (filename
, target
);
956 bfd_nonfatal (filename
);
960 if (bfd_check_format (file
, bfd_archive
) == true)
962 printf ("In archive %s:\n", bfd_get_filename (file
));
965 bfd_error
= no_error
;
967 arfile
= bfd_openr_next_archived_file (file
, arfile
);
970 if (bfd_error
!= no_more_archived_files
)
972 bfd_nonfatal (bfd_get_filename (file
));
977 display_bfd (arfile
);
978 /* Don't close the archive elements; we need them for next_archive */
987 /* Actually display the various requested regions */
995 bfd_size_type datasize
= 0;
998 for (section
= abfd
->sections
; section
!= NULL
; section
=
1003 if (only
== (char *) NULL
||
1004 strcmp (only
, section
->name
) == 0)
1006 if (section
->flags
& SEC_HAS_CONTENTS
)
1008 printf ("Contents of section %s:\n", section
->name
);
1010 if (bfd_section_size (abfd
, section
) == 0)
1012 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
1013 datasize
= bfd_section_size (abfd
, section
);
1016 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1018 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
1022 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1023 for (j
= i
; j
< i
+ onaline
; j
++)
1025 if (j
< bfd_section_size (abfd
, section
))
1026 printf ("%02x", (unsigned) (data
[j
]));
1034 for (j
= i
; j
< i
+ onaline
; j
++)
1036 if (j
>= bfd_section_size (abfd
, section
))
1039 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1049 /* Should perhaps share code and display with nm? */
1056 asymbol
**current
= syms
;
1058 printf ("SYMBOL TABLE:\n");
1060 for (count
= 0; count
< symcount
; count
++)
1065 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1068 bfd_print_symbol (cur_bfd
,
1070 *current
, bfd_print_symbol_all
);
1086 unsigned int relcount
;
1089 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1091 if (a
== &bfd_abs_section
)
1093 if (a
== &bfd_und_section
)
1095 if (bfd_is_com_section (a
))
1100 if (strcmp (only
, a
->name
))
1103 else if ((a
->flags
& SEC_RELOC
) == 0)
1106 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1108 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1110 printf (" (none)\n\n");
1116 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1117 /* Note that this must be done *before* we sort the syms table. */
1118 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1121 printf (" (none)\n\n");
1126 /* Get column headers lined up reasonably. */
1132 sprintf_vma (buf
, (bfd_vma
) -1);
1133 width
= strlen (buf
) - 7;
1135 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1138 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1142 CONST
char *sym_name
;
1143 CONST
char *section_name
;
1145 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1147 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1148 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1153 section_name
= NULL
;
1157 printf_vma (q
->address
);
1158 printf (" %-16s %s",
1164 if (section_name
== (CONST
char *) NULL
)
1165 section_name
= "*unknown*";
1166 printf_vma (q
->address
);
1167 printf (" %-16s [%s]",
1174 printf_vma (q
->addend
);
1186 /* A file to open each BFD on. It will never actually be written to. */
1188 #define _DUMMY_NAME_ "/dev/null"
1190 #define _DUMMY_NAME_ "##dummy"
1193 /* The length of the longest architecture name + 1. */
1194 #define LONGEST_ARCH sizeof("rs6000:6000")
1196 /* List the targets that BFD is configured to support, each followed
1197 by its endianness and the architectures it supports. */
1200 display_target_list ()
1202 extern bfd_target
*bfd_target_vector
[];
1205 for (t
= 0; bfd_target_vector
[t
]; t
++)
1208 bfd_target
*p
= bfd_target_vector
[t
];
1209 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1211 /* It *is* possible that bfd_openw might fail; avoid the
1212 tragic consequences that would otherwise ensue. */
1215 bfd_nonfatal (_DUMMY_NAME_
);
1218 bfd_set_format (abfd
, bfd_object
);
1219 printf ("%s\n (header %s, data %s)\n", p
->name
,
1220 p
->header_byteorder_big_p
? "big endian" : "little endian",
1221 p
->byteorder_big_p
? "big endian" : "little endian");
1222 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1223 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1225 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1229 /* Print a table showing which architectures are supported for entries
1230 FIRST through LAST-1 of bfd_target_vector (targets across,
1231 architectures down). */
1234 display_info_table (first
, last
)
1239 extern bfd_target
*bfd_target_vector
[];
1241 /* Print heading of target names. */
1242 printf ("\n%*s", LONGEST_ARCH
, " ");
1243 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1244 printf ("%s ", bfd_target_vector
[t
]->name
);
1247 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1248 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1250 printf ("%*s ", LONGEST_ARCH
- 1, bfd_printable_arch_mach (a
, 0));
1251 for (t
= first
; t
++ < last
&& bfd_target_vector
[t
];)
1253 bfd_target
*p
= bfd_target_vector
[t
];
1254 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1256 /* Just in case the open failed somehow. */
1259 bfd_nonfatal (_DUMMY_NAME_
);
1262 bfd_set_format (abfd
, bfd_object
);
1263 if (bfd_set_arch_mach (abfd
, a
, 0))
1264 printf ("%s ", p
->name
);
1267 int l
= strlen (p
->name
);
1277 /* Print tables of all the target-architecture combinations that
1278 BFD has been configured to support. */
1281 display_target_tables ()
1284 extern bfd_target
*bfd_target_vector
[];
1286 extern char *getenv ();
1289 colum
= getenv ("COLUMNS");
1291 columns
= atoi (colum
);
1295 for (t
= 0; bfd_target_vector
[t
];)
1299 for (wid
= LONGEST_ARCH
; bfd_target_vector
[t
] && wid
< columns
; t
++)
1300 wid
+= strlen (bfd_target_vector
[t
]->name
) + 1;
1304 display_info_table (oldt
, t
);
1311 printf ("BFD header file version %s\n", BFD_VERSION
);
1312 display_target_list ();
1313 display_target_tables ();
1322 char *target
= default_target
;
1323 boolean seenflag
= false;
1326 program_name
= *argv
;
1328 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1336 break; /* we've been given a long option */
1344 with_line_numbers
= 1;
1350 dump_file_header
= true;
1353 formats_info
= true;
1357 dump_reloc_info
= 1;
1358 dump_file_header
= true;
1360 dump_section_headers
= 1;
1369 dump_section_contents
= 1;
1372 dump_reloc_info
= 1;
1378 dump_section_headers
= 1;
1392 printf ("GNU %s version %s\n", program_name
, program_version
);
1396 if (seenflag
== false)
1406 display_file ("a.out", target
);
1408 for (; optind
< argc
;)
1409 display_file (argv
[optind
++], target
);