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. */
27 #include "libiberty.h"
29 /* Internal headers for the ELF .stab-dump code - sorry. */
30 #define BYTES_IN_WORD 32
31 #include "aout/aout64.h"
33 #ifndef FPRINTF_ALREADY_DECLARED
34 extern int fprintf
PARAMS ((FILE *, CONST
char *, ...));
37 char *default_target
= NULL
; /* default at runtime */
39 extern char *program_version
;
41 int show_version
= 0; /* show the version number */
42 int dump_section_contents
; /* -s */
43 int dump_section_headers
; /* -h */
44 boolean dump_file_header
; /* -f */
45 int dump_symtab
; /* -t */
46 int dump_dynamic_symtab
; /* -T */
47 int dump_reloc_info
; /* -r */
48 int dump_dynamic_reloc_info
; /* -R */
49 int dump_ar_hdrs
; /* -a */
50 int with_line_numbers
; /* -l */
51 int dump_stab_section_info
; /* --stabs */
52 boolean disassemble
; /* -d */
53 boolean disassemble_all
; /* -D */
54 boolean formats_info
; /* -i */
55 char *only
; /* -j secname */
57 /* Extra info to pass to the disassembler address printing function. */
58 struct objdump_disasm_info
{
64 /* Architecture to disassemble for, or default if NULL. */
65 char *machine
= (char *) NULL
;
67 /* The symbol table. */
70 /* Number of symbols in `syms'. */
73 /* The dynamic symbol table. */
76 /* Number of symbols in `dynsyms'. */
79 /* Forward declarations. */
82 display_file
PARAMS ((char *filename
, char *target
));
85 dump_data
PARAMS ((bfd
*abfd
));
88 dump_relocs
PARAMS ((bfd
*abfd
));
91 dump_dynamic_relocs
PARAMS ((bfd
* abfd
));
94 dump_reloc_set
PARAMS ((bfd
*, arelent
**, long));
97 dump_symbols
PARAMS ((bfd
*abfd
, boolean dynamic
));
100 display_bfd
PARAMS ((bfd
*abfd
));
103 objdump_print_address
PARAMS ((bfd_vma
, struct disassemble_info
*));
106 usage (stream
, status
)
111 Usage: %s [-ahifdDrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
112 [--archive-headers] [--target=bfdname] [--disassemble]\n\
113 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
114 [--info] [--section=section-name] [--line-numbers]\n\
115 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
116 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
117 [--version] [--help] objfile...\n\
118 at least one option besides -l (--line-numbers) must be given\n",
123 static struct option long_options
[]=
125 {"all-headers", no_argument
, NULL
, 'x'},
126 {"architecture", required_argument
, NULL
, 'm'},
127 {"archive-headers", no_argument
, NULL
, 'a'},
128 {"disassemble", no_argument
, NULL
, 'd'},
129 {"disassemble-all", no_argument
, NULL
, 'D'},
130 {"dynamic-reloc", no_argument
, NULL
, 'R'},
131 {"dynamic-syms", no_argument
, NULL
, 'T'},
132 {"file-headers", no_argument
, NULL
, 'f'},
133 {"full-contents", no_argument
, NULL
, 's'},
134 {"headers", no_argument
, NULL
, 'h'},
135 {"help", no_argument
, NULL
, 'H'},
136 {"info", no_argument
, NULL
, 'i'},
137 {"line-numbers", no_argument
, NULL
, 'l'},
138 {"reloc", no_argument
, NULL
, 'r'},
139 {"section", required_argument
, NULL
, 'j'},
140 {"section-headers", no_argument
, NULL
, 'h'},
141 {"stabs", no_argument
, &dump_stab_section_info
, 1},
142 {"syms", no_argument
, NULL
, 't'},
143 {"target", required_argument
, NULL
, 'b'},
144 {"version", no_argument
, &show_version
, 1},
145 {0, no_argument
, 0, 0}
149 dump_section_header (abfd
, section
, ignored
)
157 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
160 printf ("SECTION %d [%s]\t: size %08x",
163 (unsigned) bfd_get_section_size_before_reloc (section
));
165 printf_vma (section
->vma
);
166 printf (" align 2**%u\n ",
167 section
->alignment_power
);
168 PF (SEC_ALLOC
, "ALLOC");
169 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
170 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
171 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
172 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
173 PF (SEC_LOAD
, "LOAD");
174 PF (SEC_RELOC
, "RELOC");
176 PF (SEC_BALIGN
, "BALIGN");
178 PF (SEC_READONLY
, "READONLY");
179 PF (SEC_CODE
, "CODE");
180 PF (SEC_DATA
, "DATA");
182 PF (SEC_DEBUGGING
, "DEBUGGING");
183 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
192 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
199 asymbol
**sy
= (asymbol
**) NULL
;
202 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
204 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
208 storage
= bfd_get_symtab_upper_bound (abfd
);
210 bfd_fatal (bfd_get_filename (abfd
));
214 sy
= (asymbol
**) xmalloc (storage
);
216 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
218 bfd_fatal (bfd_get_filename (abfd
));
220 fprintf (stderr
, "%s: %s: No symbols\n",
221 program_name
, bfd_get_filename (abfd
));
225 /* Read in the dynamic symbols. */
228 slurp_dynamic_symtab (abfd
)
231 asymbol
**sy
= (asymbol
**) NULL
;
234 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
237 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
239 fprintf (stderr
, "%s: %s: not a dynamic object\n",
240 program_name
, bfd_get_filename (abfd
));
244 bfd_fatal (bfd_get_filename (abfd
));
249 sy
= (asymbol
**) xmalloc (storage
);
251 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
253 bfd_fatal (bfd_get_filename (abfd
));
254 if (dynsymcount
== 0)
255 fprintf (stderr
, "%s: %s: No dynamic symbols\n",
256 program_name
, bfd_get_filename (abfd
));
260 /* Filter out (in place) symbols that are useless for disassembly.
261 COUNT is the number of elements in SYMBOLS.
262 Return the number of useful symbols. */
265 remove_useless_symbols (symbols
, count
)
269 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
273 asymbol
*sym
= *in_ptr
++;
275 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
277 if (sym
->flags
& (BSF_DEBUGGING
))
279 if (bfd_is_und_section (sym
->section
)
280 || bfd_is_com_section (sym
->section
))
285 return out_ptr
- symbols
;
288 /* Sort symbols into value order. */
291 compare_symbols (ap
, bp
)
295 const asymbol
*a
= *(const asymbol
**)ap
;
296 const asymbol
*b
= *(const asymbol
**)bp
;
298 if (a
->value
> b
->value
)
300 else if (a
->value
< b
->value
)
303 if (a
->section
> b
->section
)
305 else if (a
->section
< b
->section
)
310 /* Sort relocs into address order. */
313 compare_relocs (ap
, bp
)
317 const arelent
*a
= *(const arelent
**)ap
;
318 const arelent
*b
= *(const arelent
**)bp
;
320 if (a
->address
> b
->address
)
322 else if (a
->address
< b
->address
)
325 return compare_symbols ((const PTR
) a
->sym_ptr_ptr
,
326 (const PTR
) b
->sym_ptr_ptr
);
329 /* Print VMA symbolically to INFO if possible. */
332 objdump_print_address (vma
, info
)
334 struct disassemble_info
*info
;
336 /* @@ For relocateable files, should filter out symbols belonging to
337 the wrong section. Unfortunately, not enough information is supplied
338 to this routine to determine the correct section in all cases. */
339 /* @@ Would it speed things up to cache the last two symbols returned,
340 and maybe their address ranges? For many processors, only one memory
341 operand can be present at a time, so the 2-entry cache wouldn't be
342 constantly churned by code doing heavy memory accesses. */
344 /* Indices in `syms'. */
349 bfd_signed_vma vardiff
;
351 fprintf_vma (info
->stream
, vma
);
356 /* Perform a binary search looking for the closest symbol to the
357 required value. We are searching the range (min, max]. */
358 while (min
+ 1 < max
)
362 thisplace
= (max
+ min
) / 2;
363 sym
= syms
[thisplace
];
365 vardiff
= sym
->value
- vma
;
369 else if (vardiff
< 0)
378 /* The symbol we want is now in min, the low end of the range we
383 /* If this symbol isn't global, search for one with the same value
385 bfd_vma val
= syms
[thisplace
]->value
;
387 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
388 for (i
= thisplace
- 1; i
>= 0; i
--)
390 if (syms
[i
]->value
== val
391 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
392 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
393 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
399 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
400 for (i
= thisplace
+ 1; i
< symcount
; i
++)
402 if (syms
[i
]->value
== val
403 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
404 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
405 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
413 /* If the file is relocateable, and the symbol could be from this
414 section, prefer a symbol from this section over symbols from
415 others, even if the other symbol's value might be closer.
417 Note that this may be wrong for some symbol references if the
418 sections have overlapping memory ranges, but in that case there's
419 no way to tell what's desired without looking at the relocation
421 struct objdump_disasm_info
*aux
;
424 aux
= (struct objdump_disasm_info
*) info
->application_data
;
425 if (syms
[thisplace
]->section
!= aux
->sec
427 || ((aux
->abfd
->flags
& HAS_RELOC
) != 0
428 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
429 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
430 + bfd_get_section_size_before_reloc (aux
->sec
)))))
432 for (i
= thisplace
+ 1; i
< symcount
; i
++)
434 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
440 if (syms
[i
]->section
== aux
->sec
)
447 if (syms
[thisplace
]->section
!= aux
->sec
)
449 /* We didn't find a good symbol with a smaller value.
450 Look for one with a larger value. */
451 for (i
= thisplace
+ 1; i
< symcount
; i
++)
453 if (syms
[i
]->section
== aux
->sec
)
463 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
464 if (syms
[thisplace
]->value
> vma
)
466 char buf
[30], *p
= buf
;
467 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
470 fprintf (info
->stream
, "-%s", p
);
472 else if (vma
> syms
[thisplace
]->value
)
474 char buf
[30], *p
= buf
;
475 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
478 fprintf (info
->stream
, "+%s", p
);
480 fprintf (info
->stream
, ">");
484 disassemble_data (abfd
)
488 unsigned int (*print
) () = 0; /* Old style */
489 disassembler_ftype disassemble_fn
= 0; /* New style */
490 struct disassemble_info disasm_info
;
491 struct objdump_disasm_info aux
;
494 char *prev_function
= NULL
;
498 boolean done_dot
= false;
500 /* If we are dumping relocation information, read the relocs for
501 each section we are going to disassemble. We must do this before
502 we sort the symbols. */
505 for (section
= abfd
->sections
;
506 section
!= (asection
*) NULL
;
507 section
= section
->next
)
512 if ((section
->flags
& SEC_LOAD
) == 0
513 || (! disassemble_all
515 && (section
->flags
& SEC_CODE
) == 0))
517 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
519 if ((section
->flags
& SEC_RELOC
) == 0)
522 /* We store the reloc information in the reloc_count and
523 orelocation fields. */
525 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
527 bfd_fatal (bfd_get_filename (abfd
));
530 section
->reloc_count
= 0;
535 relpp
= (arelent
**) xmalloc (relsize
);
536 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
538 bfd_fatal (bfd_get_filename (abfd
));
539 section
->reloc_count
= relcount
;
540 section
->orelocation
= relpp
;
545 /* Replace symbol section relative values with abs values. */
546 for (i
= 0; i
< symcount
; i
++)
548 syms
[i
]->value
+= syms
[i
]->section
->vma
;
551 symcount
= remove_useless_symbols (syms
, symcount
);
553 /* Sort the symbols into section and symbol order */
554 qsort (syms
, symcount
, sizeof (asymbol
*), compare_symbols
);
556 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
557 disasm_info
.application_data
= (PTR
) &aux
;
559 disasm_info
.print_address_func
= objdump_print_address
;
561 if (machine
!= (char *) NULL
)
563 bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
566 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
571 abfd
->arch_info
= info
;
574 /* See if we can disassemble using bfd. */
576 if (abfd
->arch_info
->disassemble
)
578 print
= abfd
->arch_info
->disassemble
;
582 disassemble_fn
= disassembler (abfd
);
585 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
587 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
592 for (section
= abfd
->sections
;
593 section
!= (asection
*) NULL
;
594 section
= section
->next
)
596 bfd_byte
*data
= NULL
;
597 bfd_size_type datasize
= 0;
598 arelent
**relpp
= NULL
;
599 arelent
**relppend
= NULL
;
601 if ((section
->flags
& SEC_LOAD
) == 0
602 || (! disassemble_all
604 && (section
->flags
& SEC_CODE
) == 0))
606 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
610 && (section
->flags
& SEC_RELOC
) != 0)
612 /* Sort the relocs by address. */
613 qsort (section
->orelocation
, section
->reloc_count
,
614 sizeof (arelent
*), compare_relocs
);
615 relpp
= section
->orelocation
;
616 relppend
= relpp
+ section
->reloc_count
;
619 printf ("Disassembly of section %s:\n", section
->name
);
621 datasize
= bfd_get_section_size_before_reloc (section
);
625 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
627 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
630 disasm_info
.buffer
= data
;
631 disasm_info
.buffer_vma
= section
->vma
;
632 disasm_info
.buffer_length
= datasize
;
634 while (i
< disasm_info
.buffer_length
)
638 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
641 if (done_dot
== false)
651 if (with_line_numbers
)
653 CONST
char *filename
;
654 CONST
char *functionname
;
657 if (bfd_find_nearest_line (abfd
,
666 && *functionname
!= '\0'
667 && (prev_function
== NULL
668 || strcmp (functionname
, prev_function
) != 0))
670 printf ("%s():\n", functionname
);
671 if (prev_function
!= NULL
)
672 free (prev_function
);
673 prev_function
= xmalloc (strlen (functionname
) + 1);
674 strcpy (prev_function
, functionname
);
678 if (line
&& line
!= prevline
)
680 printf ("%s:%u\n", filename
, line
);
685 aux
.require_sec
= true;
686 objdump_print_address (section
->vma
+ i
, &disasm_info
);
687 aux
.require_sec
= false;
693 bytes
= (*disassemble_fn
) (section
->vma
+ i
, &disasm_info
);
700 bytes
= print (section
->vma
+ i
, data
+ i
, stdout
);
706 && (section
->flags
& SEC_RELOC
) != 0)
708 while (relpp
< relppend
709 && ((*relpp
)->address
>= i
710 && (*relpp
)->address
< i
+ bytes
))
713 const char *sym_name
;
717 printf ("\t\tRELOC: ");
719 printf_vma (section
->vma
+ q
->address
);
721 printf (" %s ", q
->howto
->name
);
723 if (q
->sym_ptr_ptr
!= NULL
724 && *q
->sym_ptr_ptr
!= NULL
)
726 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
727 if (sym_name
== NULL
|| *sym_name
== '\0')
731 sym_sec
= bfd_get_section (*q
->sym_ptr_ptr
);
732 sym_name
= bfd_get_section_name (abfd
, sym_sec
);
733 if (sym_name
== NULL
|| *sym_name
== '\0')
734 sym_name
= "*unknown*";
738 printf ("%s", sym_name
);
743 printf_vma (q
->addend
);
759 /* Define a table of stab values and print-strings. We wish the initializer
760 could be a direct-mapped table, but instead we build one the first
770 struct stab_print stab_print
[] = {
771 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
772 #include "aout/stab.def"
777 void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
778 char *strsect_name
));
780 /* Dump the stabs sections from an object file that has a section that
781 uses Sun stabs encoding. It has to use some hooks into BFD because
782 string table sections are not normally visible to BFD callers. */
788 /* Allocate and initialize stab name array if first time. */
789 if (stab_name
== NULL
)
793 stab_name
= (char **) xmalloc (256 * sizeof(char *));
794 /* Clear the array. */
795 for (i
= 0; i
< 256; i
++)
797 /* Fill in the defined stabs. */
798 for (i
= 0; *stab_print
[i
].string
; i
++)
799 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
802 dump_section_stabs (abfd
, ".stab", ".stabstr");
803 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
804 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
805 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
808 static struct internal_nlist
*stabs
;
809 static bfd_size_type stab_size
;
812 static bfd_size_type stabstr_size
;
814 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
815 and string table section STRSECT_NAME into `strtab'.
816 If the section exists and was read, allocate the space and return true.
817 Otherwise return false. */
820 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
825 asection
*stabsect
, *stabstrsect
;
827 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
830 printf ("No %s section present\n\n", stabsect_name
);
834 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
835 if (0 == stabstrsect
)
837 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
838 bfd_get_filename (abfd
), strsect_name
);
842 stab_size
= bfd_section_size (abfd
, stabsect
);
843 stabstr_size
= bfd_section_size (abfd
, stabstrsect
);
845 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
846 strtab
= (char *) xmalloc (stabstr_size
);
848 if (! bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
))
850 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
851 program_name
, stabsect_name
, bfd_get_filename (abfd
),
852 bfd_errmsg (bfd_get_error ()));
858 if (! bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0,
861 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
862 program_name
, strsect_name
, bfd_get_filename (abfd
),
863 bfd_errmsg (bfd_get_error ()));
872 #define SWAP_SYMBOL(symp, abfd) \
874 (symp)->n_strx = bfd_h_get_32(abfd, \
875 (unsigned char *)&(symp)->n_strx); \
876 (symp)->n_desc = bfd_h_get_16 (abfd, \
877 (unsigned char *)&(symp)->n_desc); \
878 (symp)->n_value = bfd_h_get_32 (abfd, \
879 (unsigned char *)&(symp)->n_value); \
882 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
883 using string table section STRSECT_NAME (in `strtab'). */
886 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
892 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
893 struct internal_nlist
*stabp
= stabs
,
894 *stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
896 printf ("Contents of %s section:\n\n", stabsect_name
);
897 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
899 /* Loop through all symbols and print them.
901 We start the index at -1 because there is a dummy symbol on
902 the front of stabs-in-{coff,elf} sections that supplies sizes. */
904 for (i
= -1; stabp
< stabs_end
; stabp
++, i
++)
906 SWAP_SYMBOL (stabp
, abfd
);
907 printf ("\n%-6d ", i
);
908 /* Either print the stab name, or, if unnamed, print its number
909 again (makes consistent formatting for tools like awk). */
910 if (stab_name
[stabp
->n_type
])
911 printf ("%-6s", stab_name
[stabp
->n_type
]);
912 else if (stabp
->n_type
== N_UNDF
)
915 printf ("%-6d", stabp
->n_type
);
916 printf (" %-6d %-6d ", stabp
->n_other
, stabp
->n_desc
);
917 printf_vma (stabp
->n_value
);
918 printf (" %-6lu", stabp
->n_strx
);
920 /* Symbols with type == 0 (N_UNDF) specify the length of the
921 string table associated with this file. We use that info
922 to know how to relocate the *next* file's string table indices. */
924 if (stabp
->n_type
== N_UNDF
)
926 file_string_table_offset
= next_file_string_table_offset
;
927 next_file_string_table_offset
+= stabp
->n_value
;
931 /* Using the (possibly updated) string table offset, print the
932 string (if any) associated with this symbol. */
934 if ((stabp
->n_strx
+ file_string_table_offset
) < stabstr_size
)
935 printf (" %s", &strtab
[stabp
->n_strx
+ file_string_table_offset
]);
944 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
949 if (read_section_stabs (abfd
, stabsect_name
, strsect_name
))
951 print_section_stabs (abfd
, stabsect_name
, strsect_name
);
958 dump_bfd_header (abfd
)
963 printf ("architecture: %s, ",
964 bfd_printable_arch_mach (bfd_get_arch (abfd
),
965 bfd_get_mach (abfd
)));
966 printf ("flags 0x%08x:\n", abfd
->flags
);
968 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
969 PF (HAS_RELOC
, "HAS_RELOC");
970 PF (EXEC_P
, "EXEC_P");
971 PF (HAS_LINENO
, "HAS_LINENO");
972 PF (HAS_DEBUG
, "HAS_DEBUG");
973 PF (HAS_SYMS
, "HAS_SYMS");
974 PF (HAS_LOCALS
, "HAS_LOCALS");
975 PF (DYNAMIC
, "DYNAMIC");
976 PF (WP_TEXT
, "WP_TEXT");
977 PF (D_PAGED
, "D_PAGED");
978 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
979 printf ("\nstart address 0x");
980 printf_vma (abfd
->start_address
);
989 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
991 bfd_nonfatal (bfd_get_filename (abfd
));
992 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
994 list_matching_formats (matching
);
1000 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
1003 print_arelt_descr (stdout
, abfd
, true);
1004 if (dump_file_header
)
1005 dump_bfd_header (abfd
);
1007 if (dump_section_headers
)
1008 dump_headers (abfd
);
1009 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
1011 syms
= slurp_symtab (abfd
);
1013 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
)
1015 dynsyms
= slurp_dynamic_symtab (abfd
);
1018 dump_symbols (abfd
, false);
1019 if (dump_dynamic_symtab
)
1020 dump_symbols (abfd
, true);
1021 if (dump_stab_section_info
)
1023 if (dump_reloc_info
&& ! disassemble
)
1025 if (dump_dynamic_reloc_info
)
1026 dump_dynamic_relocs (abfd
);
1027 if (dump_section_contents
)
1029 /* Note that disassemble_data re-orders the syms table, but that is
1030 safe - as long as it is done last! */
1032 disassemble_data (abfd
);
1036 display_file (filename
, target
)
1040 bfd
*file
, *arfile
= (bfd
*) NULL
;
1042 file
= bfd_openr (filename
, target
);
1045 bfd_nonfatal (filename
);
1049 if (bfd_check_format (file
, bfd_archive
) == true)
1051 bfd
*last_arfile
= NULL
;
1053 printf ("In archive %s:\n", bfd_get_filename (file
));
1056 bfd_set_error (bfd_error_no_error
);
1058 arfile
= bfd_openr_next_archived_file (file
, arfile
);
1061 if (bfd_get_error () != bfd_error_no_more_archived_files
)
1063 bfd_nonfatal (bfd_get_filename (file
));
1068 display_bfd (arfile
);
1070 if (last_arfile
!= NULL
)
1071 bfd_close (last_arfile
);
1072 last_arfile
= arfile
;
1075 if (last_arfile
!= NULL
)
1076 bfd_close (last_arfile
);
1084 /* Actually display the various requested regions */
1092 bfd_size_type datasize
= 0;
1095 for (section
= abfd
->sections
; section
!= NULL
; section
=
1100 if (only
== (char *) NULL
||
1101 strcmp (only
, section
->name
) == 0)
1103 if (section
->flags
& SEC_HAS_CONTENTS
)
1105 printf ("Contents of section %s:\n", section
->name
);
1107 if (bfd_section_size (abfd
, section
) == 0)
1109 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
1110 datasize
= bfd_section_size (abfd
, section
);
1113 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1115 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
1119 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1120 for (j
= i
; j
< i
+ onaline
; j
++)
1122 if (j
< bfd_section_size (abfd
, section
))
1123 printf ("%02x", (unsigned) (data
[j
]));
1131 for (j
= i
; j
< i
+ onaline
; j
++)
1133 if (j
>= bfd_section_size (abfd
, section
))
1136 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1146 /* Should perhaps share code and display with nm? */
1148 dump_symbols (abfd
, dynamic
)
1162 printf ("DYNAMIC SYMBOL TABLE:\n");
1170 printf ("SYMBOL TABLE:\n");
1173 for (count
= 0; count
< max
; count
++)
1177 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1180 bfd_print_symbol (cur_bfd
,
1182 *current
, bfd_print_symbol_all
);
1200 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1204 if (bfd_is_abs_section (a
))
1206 if (bfd_is_und_section (a
))
1208 if (bfd_is_com_section (a
))
1213 if (strcmp (only
, a
->name
))
1216 else if ((a
->flags
& SEC_RELOC
) == 0)
1219 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1221 relsize
= bfd_get_reloc_upper_bound (abfd
, a
);
1223 bfd_fatal (bfd_get_filename (abfd
));
1227 printf (" (none)\n\n");
1231 relpp
= (arelent
**) xmalloc (relsize
);
1232 /* Note that this must be done *before* we sort the syms table. */
1233 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1235 bfd_fatal (bfd_get_filename (abfd
));
1236 else if (relcount
== 0)
1238 printf (" (none)\n\n");
1243 dump_reloc_set (abfd
, relpp
, relcount
);
1252 dump_dynamic_relocs (abfd
)
1259 printf ("DYNAMIC RELOCATION RECORDS");
1261 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1263 bfd_fatal (bfd_get_filename (abfd
));
1267 printf (" (none)\n\n");
1271 relpp
= (arelent
**) xmalloc (relsize
);
1272 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
1274 bfd_fatal (bfd_get_filename (abfd
));
1275 else if (relcount
== 0)
1277 printf (" (none)\n\n");
1282 dump_reloc_set (abfd
, relpp
, relcount
);
1290 dump_reloc_set (abfd
, relpp
, relcount
)
1297 /* Get column headers lined up reasonably. */
1303 sprintf_vma (buf
, (bfd_vma
) -1);
1304 width
= strlen (buf
) - 7;
1306 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1309 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++, relcount
--)
1312 CONST
char *sym_name
;
1313 CONST
char *section_name
;
1315 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1317 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1318 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1323 section_name
= NULL
;
1327 printf_vma (q
->address
);
1328 printf (" %-16s %s",
1334 if (section_name
== (CONST
char *) NULL
)
1335 section_name
= "*unknown*";
1336 printf_vma (q
->address
);
1337 printf (" %-16s [%s]",
1344 printf_vma (q
->addend
);
1350 /* The length of the longest architecture name + 1. */
1351 #define LONGEST_ARCH sizeof("rs6000:6000")
1353 /* List the targets that BFD is configured to support, each followed
1354 by its endianness and the architectures it supports. */
1357 display_target_list ()
1359 extern char *tmpnam ();
1360 extern bfd_target
*bfd_target_vector
[];
1364 dummy_name
= tmpnam ((char *) NULL
);
1365 for (t
= 0; bfd_target_vector
[t
]; t
++)
1367 bfd_target
*p
= bfd_target_vector
[t
];
1368 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1371 printf ("%s\n (header %s, data %s)\n", p
->name
,
1372 p
->header_byteorder_big_p
? "big endian" : "little endian",
1373 p
->byteorder_big_p
? "big endian" : "little endian");
1377 bfd_nonfatal (dummy_name
);
1381 if (! bfd_set_format (abfd
, bfd_object
))
1383 if (bfd_get_error () != bfd_error_invalid_operation
)
1384 bfd_nonfatal (p
->name
);
1388 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1389 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1391 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1393 unlink (dummy_name
);
1396 /* Print a table showing which architectures are supported for entries
1397 FIRST through LAST-1 of bfd_target_vector (targets across,
1398 architectures down). */
1401 display_info_table (first
, last
)
1405 extern bfd_target
*bfd_target_vector
[];
1406 extern char *tmpnam ();
1410 /* Print heading of target names. */
1411 printf ("\n%*s", (int) LONGEST_ARCH
, " ");
1412 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1413 printf ("%s ", bfd_target_vector
[t
]->name
);
1416 dummy_name
= tmpnam ((char *) NULL
);
1417 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1418 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1420 printf ("%*s ", (int) LONGEST_ARCH
- 1,
1421 bfd_printable_arch_mach (a
, 0));
1422 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1424 bfd_target
*p
= bfd_target_vector
[t
];
1426 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1430 bfd_nonfatal (p
->name
);
1436 if (! bfd_set_format (abfd
, bfd_object
))
1438 if (bfd_get_error () != bfd_error_invalid_operation
)
1439 bfd_nonfatal (p
->name
);
1446 if (! bfd_set_arch_mach (abfd
, a
, 0))
1451 printf ("%s ", p
->name
);
1454 int l
= strlen (p
->name
);
1462 unlink (dummy_name
);
1465 /* Print tables of all the target-architecture combinations that
1466 BFD has been configured to support. */
1469 display_target_tables ()
1472 extern bfd_target
*bfd_target_vector
[];
1474 extern char *getenv ();
1477 colum
= getenv ("COLUMNS");
1479 columns
= atoi (colum
);
1484 while (bfd_target_vector
[t
] != NULL
)
1488 wid
= LONGEST_ARCH
+ strlen (bfd_target_vector
[t
]->name
) + 1;
1490 while (wid
< columns
&& bfd_target_vector
[t
] != NULL
)
1494 newwid
= wid
+ strlen (bfd_target_vector
[t
]->name
) + 1;
1495 if (newwid
>= columns
)
1500 display_info_table (oldt
, t
);
1507 printf ("BFD header file version %s\n", BFD_VERSION
);
1508 display_target_list ();
1509 display_target_tables ();
1518 char *target
= default_target
;
1519 boolean seenflag
= false;
1521 program_name
= *argv
;
1522 xmalloc_set_program_name (program_name
);
1526 while ((c
= getopt_long (argc
, argv
, "ib:m:VdDlfahrRtTxsj:", long_options
,
1534 break; /* we've been given a long option */
1542 with_line_numbers
= 1;
1548 dump_file_header
= true;
1551 formats_info
= true;
1555 dump_reloc_info
= 1;
1556 dump_file_header
= true;
1558 dump_section_headers
= 1;
1564 dump_dynamic_symtab
= 1;
1570 disassemble
= disassemble_all
= true;
1573 dump_section_contents
= 1;
1576 dump_reloc_info
= 1;
1579 dump_dynamic_reloc_info
= 1;
1585 dump_section_headers
= 1;
1599 printf ("GNU %s version %s\n", program_name
, program_version
);
1603 if (seenflag
== false)
1613 display_file ("a.out", target
);
1615 for (; optind
< argc
;)
1616 display_file (argv
[optind
++], target
);