1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993 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 struct objdump_disasm_info
{
60 char *machine
= (char *) NULL
;
65 unsigned int symcount
= 0;
67 /* Forward declarations. */
70 display_file
PARAMS ((char *filename
, char *target
));
73 dump_data
PARAMS ((bfd
*abfd
));
76 dump_relocs
PARAMS ((bfd
*abfd
));
79 dump_symbols
PARAMS ((bfd
*abfd
));
82 display_bfd
PARAMS ((bfd
*abfd
));
85 usage (stream
, status
)
90 Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
91 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
92 [--section-headers] [--headers] [--info] [--section=section-name]\n\
93 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
94 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
95 at least one option besides -l (--line-numbers) must be given\n",
100 static struct option long_options
[]=
102 {"all-headers", no_argument
, NULL
, 'x'},
103 {"architecture", required_argument
, NULL
, 'm'},
104 {"archive-headers", no_argument
, NULL
, 'a'},
105 {"disassemble", no_argument
, NULL
, 'd'},
106 {"file-headers", no_argument
, NULL
, 'f'},
107 {"full-contents", no_argument
, NULL
, 's'},
108 {"headers", no_argument
, NULL
, 'h'},
109 {"help", no_argument
, NULL
, 'H'},
110 {"info", no_argument
, NULL
, 'i'},
111 {"line-numbers", no_argument
, NULL
, 'l'},
112 {"reloc", no_argument
, NULL
, 'r'},
113 {"section", required_argument
, NULL
, 'j'},
114 {"section-headers", no_argument
, NULL
, 'h'},
115 {"stabs", no_argument
, &dump_stab_section_info
, 1},
116 {"syms", no_argument
, NULL
, 't'},
117 {"target", required_argument
, NULL
, 'b'},
118 {"version", no_argument
, &show_version
, 1},
119 {0, no_argument
, 0, 0}
129 for (section
= abfd
->sections
;
130 section
!= (asection
*) NULL
;
131 section
= section
->next
)
136 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
139 printf ("SECTION %d [%s]\t: size %08x",
142 (unsigned) bfd_get_section_size_before_reloc (section
));
144 printf_vma (section
->vma
);
145 printf (" align 2**%u\n ",
146 section
->alignment_power
);
147 PF (SEC_ALLOC
, "ALLOC");
148 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
149 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
150 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
151 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
152 PF (SEC_LOAD
, "LOAD");
153 PF (SEC_RELOC
, "RELOC");
155 PF (SEC_BALIGN
, "BALIGN");
157 PF (SEC_READONLY
, "READONLY");
158 PF (SEC_CODE
, "CODE");
159 PF (SEC_DATA
, "DATA");
161 PF (SEC_DEBUGGING
, "DEBUGGING");
168 DEFUN (slurp_symtab
, (abfd
),
171 asymbol
**sy
= (asymbol
**) NULL
;
173 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
175 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
179 storage
= get_symtab_upper_bound (abfd
);
182 sy
= (asymbol
**) xmalloc (storage
);
184 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
187 fprintf (stderr
, "%s: %s: Invalid symbol table\n",
188 program_name
, bfd_get_filename (abfd
));
194 /* Filter out (in place) symbols that are useless for dis-assemble.
195 Return count of useful symbols. */
197 int remove_useless_symbols (syms
, count
)
201 register asymbol
**in_ptr
= syms
;
202 register asymbol
**out_ptr
= syms
;
204 while ( --count
>= 0 )
206 asymbol
*sym
= *in_ptr
++;
208 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
210 if (sym
->flags
& (BSF_DEBUGGING
))
212 if (sym
->section
== &bfd_und_section
213 || bfd_is_com_section (sym
->section
))
218 return out_ptr
- syms
;
222 /* Sort symbols into value order */
228 asymbol
*a
= *(asymbol
**)ap
;
229 asymbol
*b
= *(asymbol
**)bp
;
231 if (a
->value
> b
->value
)
233 else if (a
->value
< b
->value
)
236 if (a
->section
> b
->section
)
238 else if (a
->section
< b
->section
)
243 /* Print the supplied address symbolically if possible */
245 objdump_print_address (vma
, info
)
247 struct disassemble_info
*info
;
249 /* Perform a binary search looking for the closest symbol to
250 the required value. */
251 /* @@ For relocateable files, should filter out symbols belonging to
252 the wrong section. Unfortunately, not enough information is supplied
253 to this routine to determine the correct section in all cases. */
254 /* @@ Would it speed things up to cache the last two symbols returned,
255 and maybe their address ranges? For many processors, only one memory
256 operand can be present at a time, so the 2-entry cache wouldn't be
257 constantly churned by code doing heavy memory accesses. */
259 unsigned int min
= 0;
260 unsigned int max
= symcount
;
262 unsigned int thisplace
= 1;
263 unsigned int oldthisplace
;
267 fprintf_vma (info
->stream
, vma
);
273 asymbol
*sym
; asection
*sym_sec
;
274 oldthisplace
= thisplace
;
275 thisplace
= (max
+ min
) / 2;
276 if (thisplace
== oldthisplace
)
278 sym
= syms
[thisplace
];
279 vardiff
= sym
->value
- vma
;
280 sym_sec
= sym
->section
;
284 else if (vardiff
< 0)
289 /* We've run out of places to look, print the symbol before this one
290 see if this or the symbol before describes this location the best */
294 if (syms
[thisplace
- 1]->value
- vma
>
295 syms
[thisplace
]->value
- vma
)
297 /* Previous symbol is in correct section and is closer */
304 bfd_vma val
= syms
[thisplace
]->value
;
306 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
307 for (i
= thisplace
- 1; i
>= 0; i
--)
309 if (syms
[i
]->value
== val
310 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
311 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
312 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
318 if (syms
[thisplace
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
319 for (i
= thisplace
+ 1; i
< symcount
; i
++)
321 if (syms
[i
]->value
== val
322 && (!(syms
[i
]->flags
& (BSF_LOCAL
|BSF_DEBUGGING
))
323 || ((syms
[thisplace
]->flags
& BSF_DEBUGGING
)
324 && !(syms
[i
]->flags
& BSF_DEBUGGING
))))
332 /* If the file is relocateable, and the symbol could be from this
333 section, prefer a symbol from this section over symbols from
334 others, even if the other symbol's value might be closer.
336 Note that this may be wrong for some symbol references if the
337 sections have overlapping memory ranges, but in that case there's
338 no way to tell what's desired without looking at the relocation
340 struct objdump_disasm_info
*aux
;
343 aux
= (struct objdump_disasm_info
*) info
->application_data
;
344 if (aux
->abfd
->flags
& HAS_RELOC
345 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
346 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
347 + bfd_get_section_size_before_reloc (aux
->sec
))
348 && syms
[thisplace
]->section
!= aux
->sec
)
350 for (i
= thisplace
+ 1; i
< symcount
; i
++)
351 if (syms
[i
]->value
!= syms
[thisplace
]->value
)
354 if (syms
[i
]->section
== aux
->sec
)
361 fprintf (info
->stream
, " <%s", syms
[thisplace
]->name
);
362 if (syms
[thisplace
]->value
> vma
)
364 char buf
[30], *p
= buf
;
365 sprintf_vma (buf
, syms
[thisplace
]->value
- vma
);
368 fprintf (info
->stream
, "-%s", p
);
370 else if (vma
> syms
[thisplace
]->value
)
372 char buf
[30], *p
= buf
;
373 sprintf_vma (buf
, vma
- syms
[thisplace
]->value
);
376 fprintf (info
->stream
, "+%s", p
);
378 fprintf (info
->stream
, ">");
400 disassemble_data (abfd
)
403 bfd_byte
*data
= NULL
;
404 bfd_arch_info_type
*info
;
405 bfd_size_type datasize
= 0;
407 unsigned int (*print
) ()= 0; /* Old style */
408 disassembler_ftype disassemble
= 0; /* New style */
409 enum bfd_architecture a
;
410 struct disassemble_info disasm_info
;
411 struct objdump_disasm_info aux
;
414 CONST
char *prev_function
= "";
418 /* Replace symbol section relative values with abs values */
419 boolean done_dot
= false;
421 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
);
422 disasm_info
.application_data
= (PTR
) &aux
;
424 disasm_info
.print_address_func
= objdump_print_address
;
426 for (i
= 0; i
< symcount
; i
++)
428 syms
[i
]->value
+= syms
[i
]->section
->vma
;
431 symcount
= remove_useless_symbols (syms
, symcount
);
433 /* Sort the symbols into section and symbol order */
434 (void) qsort (syms
, symcount
, sizeof (asymbol
*), comp
);
436 if (machine
!= (char *) NULL
)
438 info
= bfd_scan_arch (machine
);
441 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
446 abfd
->arch_info
= info
;
449 /* See if we can disassemble using bfd */
451 if (abfd
->arch_info
->disassemble
)
453 print
= abfd
->arch_info
->disassemble
;
457 a
= bfd_get_arch (abfd
);
460 /* If you add a case to this table, also add it to the
461 ARCH_all definition right above this function. */
464 /* As far as I know we only handle big-endian 29k objects. */
465 disassemble
= print_insn_big_a29k
;
470 disassemble
= print_insn_alpha
;
475 if (bfd_get_mach(abfd
) == bfd_mach_h8300h
)
476 disassemble
= print_insn_h8300h
;
478 disassemble
= print_insn_h8300
;
483 disassemble
= print_insn_h8500
;
488 disassemble
= print_insn_hppa
;
493 disassemble
= print_insn_i386
;
498 disassemble
= print_insn_i960
;
503 disassemble
= print_insn_m68k
;
508 disassemble
= print_insn_m88k
;
513 if (abfd
->xvec
->byteorder_big_p
)
514 disassemble
= print_insn_big_mips
;
516 disassemble
= print_insn_little_mips
;
520 case bfd_arch_rs6000
:
521 disassemble
= print_insn_rs6000
;
526 disassemble
= print_insn_sh
;
531 disassemble
= print_insn_sparc
;
536 if (bfd_get_mach(abfd
) == bfd_mach_z8001
)
537 disassemble
= print_insn_z8001
;
539 disassemble
= print_insn_z8002
;
543 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
545 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
551 for (section
= abfd
->sections
;
552 section
!= (asection
*) NULL
;
553 section
= section
->next
)
557 if ((section
->flags
& SEC_LOAD
)
558 && (only
== (char *) NULL
|| strcmp (only
, section
->name
) == 0))
560 printf ("Disassembly of section %s:\n", section
->name
);
562 if (bfd_get_section_size_before_reloc (section
) == 0)
565 data
= (bfd_byte
*) xmalloc ((size_t) bfd_get_section_size_before_reloc (section
));
567 datasize
= bfd_get_section_size_before_reloc (section
);
569 bfd_get_section_contents (abfd
, section
, data
, 0, bfd_get_section_size_before_reloc (section
));
571 disasm_info
.buffer
= data
;
572 disasm_info
.buffer_vma
= section
->vma
;
573 disasm_info
.buffer_length
=
574 bfd_get_section_size_before_reloc (section
);
576 while (i
< disasm_info
.buffer_length
)
578 if (data
[i
] == 0 && data
[i
+ 1] == 0 && data
[i
+ 2] == 0 &&
581 if (done_dot
== false)
591 if (with_line_numbers
)
593 CONST
char *filename
;
594 CONST
char *functionname
;
597 if (bfd_find_nearest_line (abfd
,
605 if (functionname
&& *functionname
606 && strcmp(functionname
, prev_function
))
608 printf ("%s():\n", functionname
);
609 prev_function
= functionname
;
613 if (line
&& line
!= prevline
)
615 printf ("%s:%u\n", filename
, line
);
620 objdump_print_address (section
->vma
+ i
, &disasm_info
);
623 if (disassemble
) /* New style */
625 int bytes
= (*disassemble
)(section
->vma
+ i
,
632 i
+= print (section
->vma
+ i
,
644 /* Define a table of stab values and print-strings. We wish the initializer
645 could be a direct-mapped table, but instead we build one the first
655 struct stab_print stab_print
[] = {
656 #define __define_stab(NAME, CODE, STRING) {CODE, STRING},
657 #include "aout/stab.def"
662 void dump_stabs_1 ();
664 /* This dumps the stabs section from object files that have a section that
665 uses Sun stabs encoding. It has to use some hooks into BFD because
666 string table sections are not normally visible to BFD callers. */
674 /* Allocate and initialize stab name array if first time. */
675 if (stab_name
== NULL
)
677 stab_name
= (char **) xmalloc (256 * sizeof(char *));
678 /* Clear the array. */
679 for (i
= 0; i
< 256; i
++)
681 /* Fill in the defined stabs. */
682 for (i
= 0; *stab_print
[i
].string
; i
++)
683 stab_name
[stab_print
[i
].value
] = stab_print
[i
].string
;
686 dump_stabs_1 (abfd
, ".stab", ".stabstr");
687 dump_stabs_1 (abfd
, ".stab.excl", ".stab.exclstr");
688 dump_stabs_1 (abfd
, ".stab.index", ".stab.indexstr");
689 dump_stabs_1 (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
693 dump_stabs_1 (abfd
, name1
, name2
)
695 char *name1
; /* Section name of .stab */
696 char *name2
; /* Section name of its string section */
698 Elf_Internal_Shdr
*stab_hdr
, *stabstr_hdr
;
699 asection
*stabsect
, *stabstrsect
;
701 struct internal_nlist
*stabs
, *stabs_end
;
703 int stab_size
, stabstr_size
;
704 unsigned file_string_table_offset
, next_file_string_table_offset
;
705 int is_elf
= (0 == strncmp ("elf", abfd
->xvec
->name
, 3));
709 stab_hdr
= bfd_elf_find_section (abfd
, name1
);
713 stabsect
= bfd_get_section_by_name (abfd
, name1
);
716 if (is_elf
? (0 == stab_hdr
) : (0 == stabsect
))
718 printf ("No %s section present.\n\n", name1
);
724 stabstr_hdr
= bfd_elf_find_section (abfd
, name2
);
728 stabstrsect
= bfd_get_section_by_name (abfd
, name2
);
731 if (is_elf
? (0 == stabstr_hdr
) : (0 == stabstrsect
))
733 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
734 abfd
->filename
, name2
);
738 stab_size
= (is_elf
? stab_hdr
->sh_size
: bfd_section_size (abfd
, stabsect
));
739 stabstr_size
= (is_elf
? stabstr_hdr
->sh_size
: bfd_section_size (abfd
, stabstrsect
));
741 stabs
= (struct internal_nlist
*) xmalloc (stab_size
);
742 strtab
= (char *) xmalloc (stabstr_size
);
743 stabs_end
= (struct internal_nlist
*) (stab_size
+ (char *) stabs
);
747 if (bfd_seek (abfd
, stab_hdr
->sh_offset
, SEEK_SET
) < 0 ||
748 stab_size
!= bfd_read ((PTR
) stabs
, stab_size
, 1, abfd
))
750 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
758 bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
);
763 if (bfd_seek (abfd
, stabstr_hdr
->sh_offset
, SEEK_SET
) < 0 ||
764 stabstr_size
!= bfd_read ((PTR
) strtab
, stabstr_size
, 1, abfd
))
766 fprintf (stderr
, "%s: Reading %s section of %s failed\n",
774 bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0, stabstr_size
);
777 #define SWAP_SYMBOL(symp, abfd) \
779 (symp)->n_strx = bfd_h_get_32(abfd, \
780 (unsigned char *)&(symp)->n_strx); \
781 (symp)->n_desc = bfd_h_get_16 (abfd, \
782 (unsigned char *)&(symp)->n_desc); \
783 (symp)->n_value = bfd_h_get_32 (abfd, \
784 (unsigned char *)&(symp)->n_value); \
787 printf ("Contents of %s section:\n\n", name1
);
788 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
790 file_string_table_offset
= 0;
791 next_file_string_table_offset
= 0;
793 /* Loop through all symbols and print them.
795 We start the index at -1 because there is a dummy symbol on
796 the front of stabs-in-{coff,elf} sections that supplies sizes. */
798 for (i
= -1; stabs
< stabs_end
; stabs
++, i
++)
800 SWAP_SYMBOL (stabs
, abfd
);
801 printf ("\n%-6d ", i
);
802 /* Print either the stab name, or, if unnamed, print its number
803 again (makes consistent formatting for tools like awk). */
804 if (stab_name
[stabs
->n_type
])
805 printf ("%-6s", stab_name
[stabs
->n_type
]);
808 printf (" %-6d %-6d ", stabs
->n_other
, stabs
->n_desc
);
809 printf_vma (stabs
->n_value
);
810 printf (" %-6lu", stabs
->n_strx
);
812 /* Symbols with type == 0 (N_UNDF) specify the length of the
813 string table associated with this file. We use that info
814 to know how to relocate the *next* file's string table indices. */
816 if (stabs
->n_type
== N_UNDF
)
818 file_string_table_offset
= next_file_string_table_offset
;
819 next_file_string_table_offset
+= stabs
->n_value
;
823 /* Now, using the possibly updated string table offset, print the
824 string (if any) associated with this symbol. */
826 if ((stabs
->n_strx
+ file_string_table_offset
) < stabstr_size
)
827 printf (" %s", &strtab
[stabs
->n_strx
+ file_string_table_offset
]);
836 list_matching_formats()
838 char **p
= bfd_matching_formats ();
840 fprintf(stderr
, "%s: Matching formats:", program_name
);
842 fprintf(stderr
, " %s", *p
++);
843 fprintf(stderr
, "\n");
850 if (!bfd_check_format (abfd
, bfd_object
))
852 fprintf (stderr
, "%s: %s: %s\n", program_name
, abfd
->filename
,
853 bfd_errmsg (bfd_error
));
854 if (bfd_error
== file_ambiguously_recognized
)
855 list_matching_formats();
858 printf ("\n%s: file format %s\n", abfd
->filename
, abfd
->xvec
->name
);
860 print_arelt_descr (stdout
, abfd
, true);
862 if (dump_file_header
)
866 printf ("architecture: %s, ",
867 bfd_printable_arch_mach (bfd_get_arch (abfd
),
868 bfd_get_mach (abfd
)));
869 printf ("flags 0x%08x:\n", abfd
->flags
);
871 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
872 PF (HAS_RELOC
, "HAS_RELOC");
873 PF (EXEC_P
, "EXEC_P");
874 PF (HAS_LINENO
, "HAS_LINENO");
875 PF (HAS_DEBUG
, "HAS_DEBUG");
876 PF (HAS_SYMS
, "HAS_SYMS");
877 PF (HAS_LOCALS
, "HAS_LOCALS");
878 PF (DYNAMIC
, "DYNAMIC");
879 PF (WP_TEXT
, "WP_TEXT");
880 PF (D_PAGED
, "D_PAGED");
881 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
882 printf ("\nstart address 0x");
883 printf_vma (abfd
->start_address
);
887 if (dump_section_headers
)
889 if (dump_symtab
|| dump_reloc_info
|| disassemble
)
891 syms
= slurp_symtab (abfd
);
895 if (dump_stab_section_info
)
899 if (dump_section_contents
)
901 /* Note that disassemble_data re-orders the syms table, but that is
902 safe - as long as it is done last! */
904 disassemble_data (abfd
);
908 display_file (filename
, target
)
912 bfd
*file
, *arfile
= (bfd
*) NULL
;
914 file
= bfd_openr (filename
, target
);
917 fprintf (stderr
, "%s: ", program_name
);
918 bfd_perror (filename
);
919 if (bfd_error
== file_ambiguously_recognized
)
920 list_matching_formats();
924 if (bfd_check_format (file
, bfd_archive
) == true)
926 printf ("In archive %s:\n", bfd_get_filename (file
));
929 bfd_error
= no_error
;
931 arfile
= bfd_openr_next_archived_file (file
, arfile
);
934 if (bfd_error
!= no_more_archived_files
)
936 fprintf (stderr
, "%s: ", program_name
);
937 bfd_perror (bfd_get_filename (file
));
942 display_bfd (arfile
);
943 /* Don't close the archive elements; we need them for next_archive */
952 /* Actually display the various requested regions */
960 bfd_size_type datasize
= 0;
963 for (section
= abfd
->sections
; section
!= NULL
; section
=
968 if (only
== (char *) NULL
||
969 strcmp (only
, section
->name
) == 0)
971 if (section
->flags
& SEC_HAS_CONTENTS
)
973 printf ("Contents of section %s:\n", section
->name
);
975 if (bfd_section_size (abfd
, section
) == 0)
977 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
978 datasize
= bfd_section_size (abfd
, section
);
981 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
983 for (i
= 0; i
< bfd_section_size (abfd
, section
); i
+= onaline
)
987 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
988 for (j
= i
; j
< i
+ onaline
; j
++)
990 if (j
< bfd_section_size (abfd
, section
))
991 printf ("%02x", (unsigned) (data
[j
]));
999 for (j
= i
; j
< i
+ onaline
; j
++)
1001 if (j
>= bfd_section_size (abfd
, section
))
1004 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1014 /* Should perhaps share code and display with nm? */
1021 asymbol
**current
= syms
;
1023 printf ("SYMBOL TABLE:\n");
1025 for (count
= 0; count
< symcount
; count
++)
1030 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1033 bfd_print_symbol (cur_bfd
,
1035 *current
, bfd_print_symbol_all
);
1051 unsigned int relcount
;
1054 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1056 if (a
== &bfd_abs_section
)
1058 if (a
== &bfd_und_section
)
1060 if (bfd_is_com_section (a
))
1065 if (strcmp (only
, a
->name
))
1068 else if ((a
->flags
& SEC_RELOC
) == 0)
1071 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1073 if (bfd_get_reloc_upper_bound (abfd
, a
) == 0)
1075 printf (" (none)\n\n");
1081 relpp
= (arelent
**) xmalloc (bfd_get_reloc_upper_bound (abfd
, a
));
1082 /* Note that this must be done *before* we sort the syms table. */
1083 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1086 printf (" (none)\n\n");
1091 /* Get column headers lined up reasonably. */
1097 sprintf_vma (buf
, (bfd_vma
) -1);
1098 width
= strlen (buf
) - 7;
1100 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1103 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++,
1107 CONST
char *sym_name
;
1108 CONST
char *section_name
;
1110 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1112 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1113 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1118 section_name
= NULL
;
1122 printf_vma (q
->address
);
1123 printf (" %-16s %s",
1129 if (section_name
== (CONST
char *) NULL
)
1130 section_name
= "*unknown*";
1131 printf_vma (q
->address
);
1132 printf (" %-16s [%s]",
1139 printf_vma (q
->addend
);
1152 #define _DUMMY_NAME_ "/dev/null"
1154 #define _DUMMY_NAME_ "##dummy"
1157 DEFUN (display_info_table
, (first
, last
),
1158 int first AND
int last
)
1161 extern bfd_target
*target_vector
[];
1163 printf ("\n%12s", " ");
1164 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1165 printf ("%s ", target_vector
[i
]->name
);
1168 for (j
= (int) bfd_arch_obscure
+ 1; (int) j
< (int) bfd_arch_last
; j
++)
1169 if (strcmp (bfd_printable_arch_mach (j
, 0), "UNKNOWN!") != 0)
1171 printf ("%11s ", bfd_printable_arch_mach (j
, 0));
1172 for (i
= first
; i
++ < last
&& target_vector
[i
];)
1174 bfd_target
*p
= target_vector
[i
];
1175 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1176 int l
= strlen (p
->name
);
1178 bfd_set_format (abfd
, bfd_object
);
1179 ok
= bfd_set_arch_mach (abfd
, j
, 0);
1182 printf ("%s ", p
->name
);
1186 printf ("%c", ok
? '*' : '-');
1195 DEFUN_VOID (display_info
)
1198 unsigned int i
, j
, columns
;
1199 extern bfd_target
*target_vector
[];
1200 extern char *getenv ();
1202 printf ("BFD header file version %s\n", BFD_VERSION
);
1203 for (i
= 0; target_vector
[i
]; i
++)
1205 bfd_target
*p
= target_vector
[i
];
1206 bfd
*abfd
= bfd_openw (_DUMMY_NAME_
, p
->name
);
1207 bfd_set_format (abfd
, bfd_object
);
1208 printf ("%s\n (header %s, data %s)\n", p
->name
,
1209 p
->header_byteorder_big_p
? "big endian" : "little endian",
1210 p
->byteorder_big_p
? "big endian" : "little endian");
1211 for (j
= (int) bfd_arch_obscure
+ 1; j
< (int) bfd_arch_last
; j
++)
1212 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) j
, 0))
1214 bfd_printable_arch_mach ((enum bfd_architecture
) j
, 0));
1217 if ((colum
= getenv ("COLUMNS")) != (char *) NULL
)
1218 columns
= atoi (colum
);
1221 for (i
= 0; target_vector
[i
];)
1225 for (j
= 12; target_vector
[i
] && j
< columns
; i
++)
1226 j
+= strlen (target_vector
[i
]->name
) + 1;
1230 display_info_table (old
, i
);
1234 /** main and like trivia */
1242 extern char *optarg
;
1243 char *target
= default_target
;
1244 boolean seenflag
= false;
1247 program_name
= *argv
;
1249 while ((c
= getopt_long (argc
, argv
, "ib:m:Vdlfahrtxsj:", long_options
,
1257 break; /* we've been given a long option */
1265 with_line_numbers
= 1;
1271 dump_file_header
= true;
1274 formats_info
= true;
1278 dump_reloc_info
= 1;
1279 dump_file_header
= true;
1281 dump_section_headers
= 1;
1290 dump_section_contents
= 1;
1293 dump_reloc_info
= 1;
1299 dump_section_headers
= 1;
1313 printf ("GNU %s version %s\n", program_name
, program_version
);
1317 if (seenflag
== false)
1327 display_file ("a.out", target
);
1329 for (; optind
< argc
;)
1330 display_file (argv
[optind
++], target
);