1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 91, 92, 93, 94, 95, 1996 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "libiberty.h"
30 #ifdef ANSI_PROTOTYPES
36 /* Internal headers for the ELF .stab-dump code - sorry. */
37 #define BYTES_IN_WORD 32
38 #include "aout/aout64.h"
40 #ifdef NEED_DECLARATION_FPRINTF
41 /* This is needed by INIT_DISASSEMBLE_INFO. */
42 extern int fprintf
PARAMS ((FILE *, const char *, ...));
45 static char *default_target
= NULL
; /* default at runtime */
47 extern char *program_version
;
49 static int show_version
= 0; /* show the version number */
50 static int dump_section_contents
; /* -s */
51 static int dump_section_headers
; /* -h */
52 static boolean dump_file_header
; /* -f */
53 static int dump_symtab
; /* -t */
54 static int dump_dynamic_symtab
; /* -T */
55 static int dump_reloc_info
; /* -r */
56 static int dump_dynamic_reloc_info
; /* -R */
57 static int dump_ar_hdrs
; /* -a */
58 static int dump_private_headers
; /* -p */
59 static int with_line_numbers
; /* -l */
60 static boolean with_source_code
; /* -S */
61 static int show_raw_insn
; /* --show-raw-insn */
62 static int dump_stab_section_info
; /* --stabs */
63 static boolean disassemble
; /* -d */
64 static boolean disassemble_all
; /* -D */
65 static boolean formats_info
; /* -i */
66 static char *only
; /* -j secname */
67 static int wide_output
; /* -w */
68 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
69 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
70 static int dump_debugging
; /* --debugging */
72 /* Extra info to pass to the disassembler address printing function. */
73 struct objdump_disasm_info
{
79 /* Architecture to disassemble for, or default if NULL. */
80 static char *machine
= (char *) NULL
;
82 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
83 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
85 /* The symbol table. */
86 static asymbol
**syms
;
88 /* Number of symbols in `syms'. */
89 static long symcount
= 0;
91 /* The sorted symbol table. */
92 static asymbol
**sorted_syms
;
94 /* Number of symbols in `sorted_syms'. */
95 static long sorted_symcount
= 0;
97 /* The dynamic symbol table. */
98 static asymbol
**dynsyms
;
100 /* Number of symbols in `dynsyms'. */
101 static long dynsymcount
= 0;
103 /* Forward declarations. */
106 display_file
PARAMS ((char *filename
, char *target
));
109 dump_data
PARAMS ((bfd
*abfd
));
112 dump_relocs
PARAMS ((bfd
*abfd
));
115 dump_dynamic_relocs
PARAMS ((bfd
* abfd
));
118 dump_reloc_set
PARAMS ((bfd
*, asection
*, arelent
**, long));
121 dump_symbols
PARAMS ((bfd
*abfd
, boolean dynamic
));
124 display_bfd
PARAMS ((bfd
*abfd
));
127 objdump_print_value
PARAMS ((bfd_vma
, struct disassemble_info
*));
130 objdump_print_address
PARAMS ((bfd_vma
, struct disassemble_info
*));
133 show_line
PARAMS ((bfd
*, asection
*, bfd_vma
));
136 endian_string
PARAMS ((enum bfd_endian
));
139 usage (stream
, status
)
144 Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
145 [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
146 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
147 [--info] [--section=section-name] [--line-numbers] [--source]\n",
150 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
151 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
152 [--wide] [--version] [--help] [--private-headers]\n\
153 [--start-address=addr] [--stop-address=addr]\n\
154 [--show-raw-insn] [-EB|-EL] [--endian={big|little}] objfile...\n\
155 at least one option besides -l (--line-numbers) must be given\n");
156 list_supported_targets (program_name
, stream
);
160 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
162 #define OPTION_ENDIAN (150)
163 #define OPTION_START_ADDRESS (OPTION_ENDIAN + 1)
164 #define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
166 static struct option long_options
[]=
168 {"all-headers", no_argument
, NULL
, 'x'},
169 {"private-headers", no_argument
, NULL
, 'p'},
170 {"architecture", required_argument
, NULL
, 'm'},
171 {"archive-headers", no_argument
, NULL
, 'a'},
172 {"debugging", no_argument
, &dump_debugging
, 1},
173 {"disassemble", no_argument
, NULL
, 'd'},
174 {"disassemble-all", no_argument
, NULL
, 'D'},
175 {"dynamic-reloc", no_argument
, NULL
, 'R'},
176 {"dynamic-syms", no_argument
, NULL
, 'T'},
177 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
178 {"file-headers", no_argument
, NULL
, 'f'},
179 {"full-contents", no_argument
, NULL
, 's'},
180 {"headers", no_argument
, NULL
, 'h'},
181 {"help", no_argument
, NULL
, 'H'},
182 {"info", no_argument
, NULL
, 'i'},
183 {"line-numbers", no_argument
, NULL
, 'l'},
184 {"reloc", no_argument
, NULL
, 'r'},
185 {"section", required_argument
, NULL
, 'j'},
186 {"section-headers", no_argument
, NULL
, 'h'},
187 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
188 {"source", no_argument
, NULL
, 'S'},
189 {"stabs", no_argument
, &dump_stab_section_info
, 1},
190 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
191 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
192 {"syms", no_argument
, NULL
, 't'},
193 {"target", required_argument
, NULL
, 'b'},
194 {"version", no_argument
, &show_version
, 1},
195 {"wide", no_argument
, &wide_output
, 'w'},
196 {0, no_argument
, 0, 0}
200 dump_section_header (abfd
, section
, ignored
)
207 printf ("%3d %-13s %08lx ", section
->index
,
208 bfd_get_section_name (abfd
, section
),
209 (unsigned long) bfd_section_size (abfd
, section
));
210 printf_vma (bfd_get_section_vma (abfd
, section
));
212 printf_vma (section
->lma
);
213 printf (" %08lx 2**%u", section
->filepos
,
214 bfd_get_section_alignment (abfd
, section
));
220 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
222 PF (SEC_HAS_CONTENTS
, "CONTENTS");
223 PF (SEC_ALLOC
, "ALLOC");
224 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
225 PF (SEC_CONSTRUCTOR_TEXT
, "CONSTRUCTOR TEXT");
226 PF (SEC_CONSTRUCTOR_DATA
, "CONSTRUCTOR DATA");
227 PF (SEC_CONSTRUCTOR_BSS
, "CONSTRUCTOR BSS");
228 PF (SEC_LOAD
, "LOAD");
229 PF (SEC_RELOC
, "RELOC");
231 PF (SEC_BALIGN
, "BALIGN");
233 PF (SEC_READONLY
, "READONLY");
234 PF (SEC_CODE
, "CODE");
235 PF (SEC_DATA
, "DATA");
237 PF (SEC_DEBUGGING
, "DEBUGGING");
238 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
239 PF (SEC_EXCLUDE
, "EXCLUDE");
240 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
242 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
246 switch (section
->flags
& SEC_LINK_DUPLICATES
)
250 case SEC_LINK_DUPLICATES_DISCARD
:
251 ls
= "LINK_ONCE_DISCARD";
253 case SEC_LINK_DUPLICATES_ONE_ONLY
:
254 ls
= "LINK_ONCE_ONE_ONLY";
256 case SEC_LINK_DUPLICATES_SAME_SIZE
:
257 ls
= "LINK_ONCE_SAME_SIZE";
259 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
260 ls
= "LINK_ONCE_SAME_CONTENTS";
263 printf ("%s%s", comma
, ls
);
275 printf ("Sections:\n");
277 printf ("Idx Name Size VMA LMA File off Algn\n");
279 printf ("Idx Name Size VMA LMA File off Algn\n");
281 bfd_map_over_sections (abfd
, dump_section_header
, (PTR
) NULL
);
288 asymbol
**sy
= (asymbol
**) NULL
;
291 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
293 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd
));
298 storage
= bfd_get_symtab_upper_bound (abfd
);
300 bfd_fatal (bfd_get_filename (abfd
));
304 sy
= (asymbol
**) xmalloc (storage
);
306 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
308 bfd_fatal (bfd_get_filename (abfd
));
310 fprintf (stderr
, "%s: %s: No symbols\n",
311 program_name
, bfd_get_filename (abfd
));
315 /* Read in the dynamic symbols. */
318 slurp_dynamic_symtab (abfd
)
321 asymbol
**sy
= (asymbol
**) NULL
;
324 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
327 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
329 fprintf (stderr
, "%s: %s: not a dynamic object\n",
330 program_name
, bfd_get_filename (abfd
));
335 bfd_fatal (bfd_get_filename (abfd
));
340 sy
= (asymbol
**) xmalloc (storage
);
342 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
344 bfd_fatal (bfd_get_filename (abfd
));
345 if (dynsymcount
== 0)
346 fprintf (stderr
, "%s: %s: No dynamic symbols\n",
347 program_name
, bfd_get_filename (abfd
));
351 /* Filter out (in place) symbols that are useless for disassembly.
352 COUNT is the number of elements in SYMBOLS.
353 Return the number of useful symbols. */
356 remove_useless_symbols (symbols
, count
)
360 register asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
364 asymbol
*sym
= *in_ptr
++;
366 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
368 if (sym
->flags
& (BSF_DEBUGGING
))
370 if (bfd_is_und_section (sym
->section
)
371 || bfd_is_com_section (sym
->section
))
376 return out_ptr
- symbols
;
379 /* Sort symbols into value order. */
382 compare_symbols (ap
, bp
)
386 const asymbol
*a
= *(const asymbol
**)ap
;
387 const asymbol
*b
= *(const asymbol
**)bp
;
391 flagword aflags
, bflags
;
393 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
395 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
398 if (a
->section
> b
->section
)
400 else if (a
->section
< b
->section
)
403 an
= bfd_asymbol_name (a
);
404 bn
= bfd_asymbol_name (b
);
408 /* The symbols gnu_compiled and gcc2_compiled convey no real
409 information, so put them after other symbols with the same value. */
411 af
= (strstr (an
, "gnu_compiled") != NULL
412 || strstr (an
, "gcc2_compiled") != NULL
);
413 bf
= (strstr (bn
, "gnu_compiled") != NULL
414 || strstr (bn
, "gcc2_compiled") != NULL
);
421 /* We use a heuristic for the file name, to try to sort it after
422 more useful symbols. It may not work on non Unix systems, but it
423 doesn't really matter; the only difference is precisely which
424 symbol names get printed. */
426 #define file_symbol(s, sn, snl) \
427 (((s)->flags & BSF_FILE) != 0 \
428 || ((sn)[(snl) - 2] == '.' \
429 && ((sn)[(snl) - 1] == 'o' \
430 || (sn)[(snl) - 1] == 'a')))
432 af
= file_symbol (a
, an
, anl
);
433 bf
= file_symbol (b
, bn
, bnl
);
440 /* Try to sort global symbols before local symbols before debugging
446 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
448 if ((aflags
& BSF_DEBUGGING
) != 0)
453 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
455 if ((aflags
& BSF_LOCAL
) != 0)
460 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
462 if ((aflags
& BSF_GLOBAL
) != 0)
468 /* Symbols that start with '.' might be section names, so sort them
469 after symbols that don't start with '.'. */
470 if (an
[0] == '.' && bn
[0] != '.')
472 if (an
[0] != '.' && bn
[0] == '.')
475 /* Finally, if we can't distinguish them in any other way, try to
476 get consistent results by sorting the symbols by name. */
477 return strcmp (an
, bn
);
480 /* Sort relocs into address order. */
483 compare_relocs (ap
, bp
)
487 const arelent
*a
= *(const arelent
**)ap
;
488 const arelent
*b
= *(const arelent
**)bp
;
490 if (a
->address
> b
->address
)
492 else if (a
->address
< b
->address
)
495 /* So that associated relocations tied to the same address show up
496 in the correct order, we don't do any further sorting. */
505 /* Print VMA to STREAM with no leading zeroes. */
508 objdump_print_value (vma
, info
)
510 struct disassemble_info
*info
;
515 sprintf_vma (buf
, vma
);
516 for (p
= buf
; *p
== '0'; ++p
)
518 (*info
->fprintf_func
) (info
->stream
, "%s", p
);
521 /* Print VMA symbolically to INFO if possible. */
524 objdump_print_address (vma
, info
)
526 struct disassemble_info
*info
;
530 /* @@ Would it speed things up to cache the last two symbols returned,
531 and maybe their address ranges? For many processors, only one memory
532 operand can be present at a time, so the 2-entry cache wouldn't be
533 constantly churned by code doing heavy memory accesses. */
535 /* Indices in `sorted_syms'. */
537 long max
= sorted_symcount
;
540 sprintf_vma (buf
, vma
);
541 (*info
->fprintf_func
) (info
->stream
, "%s", buf
);
543 if (sorted_symcount
< 1)
546 /* Perform a binary search looking for the closest symbol to the
547 required value. We are searching the range (min, max]. */
548 while (min
+ 1 < max
)
552 thisplace
= (max
+ min
) / 2;
553 sym
= sorted_syms
[thisplace
];
555 if (bfd_asymbol_value (sym
) > vma
)
557 else if (bfd_asymbol_value (sym
) < vma
)
566 /* The symbol we want is now in min, the low end of the range we
567 were searching. If there are several symbols with the same
568 value, we want the first one. */
571 && (bfd_asymbol_value (sorted_syms
[thisplace
])
572 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
576 /* If the file is relocateable, and the symbol could be from this
577 section, prefer a symbol from this section over symbols from
578 others, even if the other symbol's value might be closer.
580 Note that this may be wrong for some symbol references if the
581 sections have overlapping memory ranges, but in that case there's
582 no way to tell what's desired without looking at the relocation
584 struct objdump_disasm_info
*aux
;
587 aux
= (struct objdump_disasm_info
*) info
->application_data
;
588 if (sorted_syms
[thisplace
]->section
!= aux
->sec
590 || ((aux
->abfd
->flags
& HAS_RELOC
) != 0
591 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
592 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
593 + bfd_section_size (aux
->abfd
, aux
->sec
)))))
595 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
597 if (bfd_asymbol_value (sorted_syms
[i
])
598 != bfd_asymbol_value (sorted_syms
[thisplace
]))
604 if (sorted_syms
[i
]->section
== aux
->sec
606 || sorted_syms
[i
- 1]->section
!= aux
->sec
607 || (bfd_asymbol_value (sorted_syms
[i
])
608 != bfd_asymbol_value (sorted_syms
[i
- 1]))))
615 if (sorted_syms
[thisplace
]->section
!= aux
->sec
)
617 /* We didn't find a good symbol with a smaller value.
618 Look for one with a larger value. */
619 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
621 if (sorted_syms
[i
]->section
== aux
->sec
)
629 if (sorted_syms
[thisplace
]->section
!= aux
->sec
631 || ((aux
->abfd
->flags
& HAS_RELOC
) != 0
632 && vma
>= bfd_get_section_vma (aux
->abfd
, aux
->sec
)
633 && vma
< (bfd_get_section_vma (aux
->abfd
, aux
->sec
)
634 + bfd_section_size (aux
->abfd
, aux
->sec
)))))
638 (*info
->fprintf_func
) (info
->stream
, " <%s",
639 bfd_get_section_name (aux
->abfd
, aux
->sec
));
640 secaddr
= bfd_get_section_vma (aux
->abfd
, aux
->sec
);
643 (*info
->fprintf_func
) (info
->stream
, "-");
644 objdump_print_value (secaddr
- vma
, info
);
646 else if (vma
> secaddr
)
648 (*info
->fprintf_func
) (info
->stream
, "+");
649 objdump_print_value (vma
- secaddr
, info
);
651 (*info
->fprintf_func
) (info
->stream
, ">");
657 (*info
->fprintf_func
) (info
->stream
, " <%s", sorted_syms
[thisplace
]->name
);
658 if (bfd_asymbol_value (sorted_syms
[thisplace
]) > vma
)
660 (*info
->fprintf_func
) (info
->stream
, "-");
661 objdump_print_value (bfd_asymbol_value (sorted_syms
[thisplace
]) - vma
,
664 else if (vma
> bfd_asymbol_value (sorted_syms
[thisplace
]))
666 (*info
->fprintf_func
) (info
->stream
, "+");
667 objdump_print_value (vma
- bfd_asymbol_value (sorted_syms
[thisplace
]),
670 (*info
->fprintf_func
) (info
->stream
, ">");
673 /* Hold the last function name and the last line number we displayed
676 static char *prev_functionname
;
677 static unsigned int prev_line
;
679 /* We keep a list of all files that we have seen when doing a
680 dissassembly with source, so that we know how much of the file to
681 display. This can be important for inlined functions. */
683 struct print_file_list
685 struct print_file_list
*next
;
691 static struct print_file_list
*print_files
;
693 /* The number of preceding context lines to show when we start
694 displaying a file for the first time. */
696 #define SHOW_PRECEDING_CONTEXT_LINES (5)
698 /* Skip ahead to a given line in a file, optionally printing each
702 skip_to_line
PARAMS ((struct print_file_list
*, unsigned int, boolean
));
705 skip_to_line (p
, line
, show
)
706 struct print_file_list
*p
;
710 while (p
->line
< line
)
714 if (fgets (buf
, sizeof buf
, p
->f
) == NULL
)
724 if (strchr (buf
, '\n') != NULL
)
729 /* Show the line number, or the source line, in a dissassembly
733 show_line (abfd
, section
, off
)
738 CONST
char *filename
;
739 CONST
char *functionname
;
742 if (! with_line_numbers
&& ! with_source_code
)
745 if (! bfd_find_nearest_line (abfd
, section
, syms
, off
, &filename
,
746 &functionname
, &line
))
749 if (filename
!= NULL
&& *filename
== '\0')
751 if (functionname
!= NULL
&& *functionname
== '\0')
754 if (with_line_numbers
)
756 if (functionname
!= NULL
757 && (prev_functionname
== NULL
758 || strcmp (functionname
, prev_functionname
) != 0))
759 printf ("%s():\n", functionname
);
760 if (line
> 0 && line
!= prev_line
)
761 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
768 struct print_file_list
**pp
, *p
;
770 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
771 if (strcmp ((*pp
)->filename
, filename
) == 0)
777 if (p
!= print_files
)
781 /* We have reencountered a file name which we saw
782 earlier. This implies that either we are dumping out
783 code from an included file, or the same file was
784 linked in more than once. There are two common cases
785 of an included file: inline functions in a header
786 file, and a bison or flex skeleton file. In the
787 former case we want to just start printing (but we
788 back up a few lines to give context); in the latter
789 case we want to continue from where we left off. I
790 can't think of a good way to distinguish the cases,
791 so I used a heuristic based on the file name. */
792 if (strcmp (p
->filename
+ strlen (p
->filename
) - 2, ".h") != 0)
796 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
803 p
->f
= fopen (p
->filename
, "r");
807 skip_to_line (p
, l
, false);
809 if (print_files
->f
!= NULL
)
811 fclose (print_files
->f
);
812 print_files
->f
= NULL
;
818 skip_to_line (p
, line
, true);
820 p
->next
= print_files
;
828 f
= fopen (filename
, "r");
833 p
= ((struct print_file_list
*)
834 xmalloc (sizeof (struct print_file_list
)));
835 p
->filename
= xmalloc (strlen (filename
) + 1);
836 strcpy (p
->filename
, filename
);
840 if (print_files
!= NULL
&& print_files
->f
!= NULL
)
842 fclose (print_files
->f
);
843 print_files
->f
= NULL
;
845 p
->next
= print_files
;
848 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
851 skip_to_line (p
, l
, false);
853 skip_to_line (p
, line
, true);
858 if (functionname
!= NULL
859 && (prev_functionname
== NULL
860 || strcmp (functionname
, prev_functionname
) != 0))
862 if (prev_functionname
!= NULL
)
863 free (prev_functionname
);
864 prev_functionname
= xmalloc (strlen (functionname
) + 1);
865 strcpy (prev_functionname
, functionname
);
868 if (line
> 0 && line
!= prev_line
)
872 /* Pseudo FILE object for strings. */
878 /* sprintf to a "stream" */
880 #ifdef ANSI_PROTOTYPES
882 objdump_sprintf (SFILE
*f
, const char *format
, ...)
887 va_start (args
, format
);
888 vsprintf (f
->current
, format
, args
);
889 f
->current
+= n
= strlen (f
->current
);
895 objdump_sprintf (va_alist
)
904 f
= va_arg (args
, SFILE
*);
905 format
= va_arg (args
, const char *);
906 vsprintf (f
->current
, format
, args
);
907 f
->current
+= n
= strlen (f
->current
);
914 disassemble_data (abfd
)
918 disassembler_ftype disassemble_fn
= 0; /* New style */
919 struct disassemble_info disasm_info
;
920 struct objdump_disasm_info aux
;
922 boolean done_dot
= false;
927 prev_functionname
= NULL
;
930 /* We make a copy of syms to sort. We don't want to sort syms
931 because that will screw up the relocs. */
932 sorted_syms
= (asymbol
**) xmalloc (symcount
* sizeof (asymbol
*));
933 memcpy (sorted_syms
, syms
, symcount
* sizeof (asymbol
*));
935 sorted_symcount
= remove_useless_symbols (sorted_syms
, symcount
);
937 /* Sort the symbols into section and symbol order */
938 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
940 INIT_DISASSEMBLE_INFO(disasm_info
, stdout
, fprintf
);
941 disasm_info
.application_data
= (PTR
) &aux
;
943 disasm_info
.print_address_func
= objdump_print_address
;
945 if (machine
!= (char *) NULL
)
947 const bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
950 fprintf (stderr
, "%s: Can't use supplied machine %s\n",
955 abfd
->arch_info
= info
;
958 if (endian
!= BFD_ENDIAN_UNKNOWN
)
960 struct bfd_target
*xvec
;
962 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
963 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
964 xvec
->byteorder
= endian
;
968 disassemble_fn
= disassembler (abfd
);
971 fprintf (stderr
, "%s: Can't disassemble for architecture %s\n",
973 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
977 disasm_info
.arch
= bfd_get_arch (abfd
);
978 disasm_info
.mach
= bfd_get_mach (abfd
);
979 if (bfd_big_endian (abfd
))
980 disasm_info
.endian
= BFD_ENDIAN_BIG
;
981 else if (bfd_little_endian (abfd
))
982 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
984 /* ??? Aborting here seems too drastic. We could default to big or little
986 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
988 for (section
= abfd
->sections
;
989 section
!= (asection
*) NULL
;
990 section
= section
->next
)
992 bfd_byte
*data
= NULL
;
993 bfd_size_type datasize
= 0;
994 arelent
**relbuf
= NULL
;
995 arelent
**relpp
= NULL
;
996 arelent
**relppend
= NULL
;
999 if ((section
->flags
& SEC_LOAD
) == 0
1000 || (! disassemble_all
1002 && (section
->flags
& SEC_CODE
) == 0))
1004 if (only
!= (char *) NULL
&& strcmp (only
, section
->name
) != 0)
1008 && (section
->flags
& SEC_RELOC
) != 0)
1012 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
1014 bfd_fatal (bfd_get_filename (abfd
));
1020 relbuf
= (arelent
**) xmalloc (relsize
);
1021 relcount
= bfd_canonicalize_reloc (abfd
, section
, relbuf
, syms
);
1023 bfd_fatal (bfd_get_filename (abfd
));
1025 /* Sort the relocs by address. */
1026 qsort (relbuf
, relcount
, sizeof (arelent
*), compare_relocs
);
1029 relppend
= relpp
+ relcount
;
1033 printf ("Disassembly of section %s:\n", section
->name
);
1035 datasize
= bfd_get_section_size_before_reloc (section
);
1039 data
= (bfd_byte
*) xmalloc ((size_t) datasize
);
1041 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
1044 disasm_info
.buffer
= data
;
1045 disasm_info
.buffer_vma
= section
->vma
;
1046 disasm_info
.buffer_length
= datasize
;
1047 if (start_address
== (bfd_vma
) -1
1048 || start_address
< disasm_info
.buffer_vma
)
1051 i
= start_address
- disasm_info
.buffer_vma
;
1052 if (stop_address
== (bfd_vma
) -1)
1056 if (stop_address
< disasm_info
.buffer_vma
)
1059 stop
= stop_address
- disasm_info
.buffer_vma
;
1060 if (stop
> disasm_info
.buffer_length
)
1061 stop
= disasm_info
.buffer_length
;
1066 boolean need_nl
= false;
1070 || (data
[i
+ 1] == 0
1072 || (data
[i
+ 2] == 0
1074 || data
[i
+ 3] == 0))))))
1076 if (done_dot
== false)
1086 if (with_line_numbers
|| with_source_code
)
1087 show_line (abfd
, section
, i
);
1088 aux
.require_sec
= true;
1089 objdump_print_address (section
->vma
+ i
, &disasm_info
);
1090 aux
.require_sec
= false;
1093 sfile
.buffer
= sfile
.current
= buf
;
1094 disasm_info
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
1095 disasm_info
.stream
= (FILE *) &sfile
;
1096 bytes
= (*disassemble_fn
) (section
->vma
+ i
, &disasm_info
);
1097 disasm_info
.fprintf_func
= (fprintf_ftype
) fprintf
;
1098 disasm_info
.stream
= stdout
;
1105 for (j
= i
; j
< i
+ bytes
; ++j
)
1107 printf ("%02x", (unsigned) data
[j
]);
1110 /* Separate raw data from instruction by extra space. */
1114 printf ("%s", sfile
.buffer
);
1123 && (section
->flags
& SEC_RELOC
) != 0)
1125 while (relpp
< relppend
1126 && ((*relpp
)->address
>= (bfd_vma
) i
1127 && (*relpp
)->address
< (bfd_vma
) i
+ bytes
))
1130 const char *sym_name
;
1134 printf ("\t\tRELOC: ");
1136 printf_vma (section
->vma
+ q
->address
);
1138 printf (" %s ", q
->howto
->name
);
1140 if (q
->sym_ptr_ptr
!= NULL
1141 && *q
->sym_ptr_ptr
!= NULL
)
1143 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
1144 if (sym_name
== NULL
|| *sym_name
== '\0')
1148 sym_sec
= bfd_get_section (*q
->sym_ptr_ptr
);
1149 sym_name
= bfd_get_section_name (abfd
, sym_sec
);
1150 if (sym_name
== NULL
|| *sym_name
== '\0')
1151 sym_name
= "*unknown*";
1155 sym_name
= "*unknown*";
1157 printf ("%s", sym_name
);
1162 printf_vma (q
->addend
);
1185 /* Define a table of stab values and print-strings. We wish the initializer
1186 could be a direct-mapped table, but instead we build one the first
1189 static void dump_section_stabs
PARAMS ((bfd
*abfd
, char *stabsect_name
,
1190 char *strsect_name
));
1192 /* Dump the stabs sections from an object file that has a section that
1193 uses Sun stabs encoding. */
1199 dump_section_stabs (abfd
, ".stab", ".stabstr");
1200 dump_section_stabs (abfd
, ".stab.excl", ".stab.exclstr");
1201 dump_section_stabs (abfd
, ".stab.index", ".stab.indexstr");
1202 dump_section_stabs (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
1205 static bfd_byte
*stabs
;
1206 static bfd_size_type stab_size
;
1208 static char *strtab
;
1209 static bfd_size_type stabstr_size
;
1211 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
1212 and string table section STRSECT_NAME into `strtab'.
1213 If the section exists and was read, allocate the space and return true.
1214 Otherwise return false. */
1217 read_section_stabs (abfd
, stabsect_name
, strsect_name
)
1219 char *stabsect_name
;
1222 asection
*stabsect
, *stabstrsect
;
1224 stabsect
= bfd_get_section_by_name (abfd
, stabsect_name
);
1227 printf ("No %s section present\n\n", stabsect_name
);
1231 stabstrsect
= bfd_get_section_by_name (abfd
, strsect_name
);
1232 if (0 == stabstrsect
)
1234 fprintf (stderr
, "%s: %s has no %s section\n", program_name
,
1235 bfd_get_filename (abfd
), strsect_name
);
1239 stab_size
= bfd_section_size (abfd
, stabsect
);
1240 stabstr_size
= bfd_section_size (abfd
, stabstrsect
);
1242 stabs
= (bfd_byte
*) xmalloc (stab_size
);
1243 strtab
= (char *) xmalloc (stabstr_size
);
1245 if (! bfd_get_section_contents (abfd
, stabsect
, (PTR
) stabs
, 0, stab_size
))
1247 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
1248 program_name
, stabsect_name
, bfd_get_filename (abfd
),
1249 bfd_errmsg (bfd_get_error ()));
1255 if (! bfd_get_section_contents (abfd
, stabstrsect
, (PTR
) strtab
, 0,
1258 fprintf (stderr
, "%s: Reading %s section of %s failed: %s\n",
1259 program_name
, strsect_name
, bfd_get_filename (abfd
),
1260 bfd_errmsg (bfd_get_error ()));
1269 /* Stabs entries use a 12 byte format:
1270 4 byte string table index
1272 1 byte stab other field
1273 2 byte stab desc field
1275 FIXME: This will have to change for a 64 bit object format. */
1277 #define STRDXOFF (0)
1279 #define OTHEROFF (5)
1282 #define STABSIZE (12)
1284 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1285 using string table section STRSECT_NAME (in `strtab'). */
1288 print_section_stabs (abfd
, stabsect_name
, strsect_name
)
1290 char *stabsect_name
;
1294 unsigned file_string_table_offset
= 0, next_file_string_table_offset
= 0;
1295 bfd_byte
*stabp
, *stabs_end
;
1298 stabs_end
= stabp
+ stab_size
;
1300 printf ("Contents of %s section:\n\n", stabsect_name
);
1301 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
1303 /* Loop through all symbols and print them.
1305 We start the index at -1 because there is a dummy symbol on
1306 the front of stabs-in-{coff,elf} sections that supplies sizes. */
1308 for (i
= -1; stabp
< stabs_end
; stabp
+= STABSIZE
, i
++)
1312 unsigned char type
, other
;
1313 unsigned short desc
;
1316 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
1317 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
1318 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
1319 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
1320 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
1322 printf ("\n%-6d ", i
);
1323 /* Either print the stab name, or, if unnamed, print its number
1324 again (makes consistent formatting for tools like awk). */
1325 name
= bfd_get_stab_name (type
);
1327 printf ("%-6s", name
);
1328 else if (type
== N_UNDF
)
1331 printf ("%-6d", type
);
1332 printf (" %-6d %-6d ", other
, desc
);
1334 printf (" %-6lu", strx
);
1336 /* Symbols with type == 0 (N_UNDF) specify the length of the
1337 string table associated with this file. We use that info
1338 to know how to relocate the *next* file's string table indices. */
1342 file_string_table_offset
= next_file_string_table_offset
;
1343 next_file_string_table_offset
+= value
;
1347 /* Using the (possibly updated) string table offset, print the
1348 string (if any) associated with this symbol. */
1350 if ((strx
+ file_string_table_offset
) < stabstr_size
)
1351 printf (" %s", &strtab
[strx
+ file_string_table_offset
]);
1360 dump_section_stabs (abfd
, stabsect_name
, strsect_name
)
1362 char *stabsect_name
;
1367 /* Check for section names for which stabsect_name is a prefix, to
1368 handle .stab0, etc. */
1369 for (s
= abfd
->sections
;
1375 len
= strlen (stabsect_name
);
1377 /* If the prefix matches, and the files section name ends with a nul or a digit,
1378 then we match. Ie: we want either an exact match or a a section followed by
1380 if (strncmp (stabsect_name
, s
->name
, len
) == 0
1381 && (s
->name
[len
] == '\000' || isdigit (s
->name
[len
])))
1383 if (read_section_stabs (abfd
, s
->name
, strsect_name
))
1385 print_section_stabs (abfd
, s
->name
, strsect_name
);
1394 dump_bfd_header (abfd
)
1399 printf ("architecture: %s, ",
1400 bfd_printable_arch_mach (bfd_get_arch (abfd
),
1401 bfd_get_mach (abfd
)));
1402 printf ("flags 0x%08x:\n", abfd
->flags
);
1404 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
1405 PF (HAS_RELOC
, "HAS_RELOC");
1406 PF (EXEC_P
, "EXEC_P");
1407 PF (HAS_LINENO
, "HAS_LINENO");
1408 PF (HAS_DEBUG
, "HAS_DEBUG");
1409 PF (HAS_SYMS
, "HAS_SYMS");
1410 PF (HAS_LOCALS
, "HAS_LOCALS");
1411 PF (DYNAMIC
, "DYNAMIC");
1412 PF (WP_TEXT
, "WP_TEXT");
1413 PF (D_PAGED
, "D_PAGED");
1414 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
1415 printf ("\nstart address 0x");
1416 printf_vma (abfd
->start_address
);
1421 dump_bfd_private_header (abfd
)
1424 bfd_print_private_bfd_data (abfd
, stdout
);
1433 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
1435 bfd_nonfatal (bfd_get_filename (abfd
));
1436 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
1438 list_matching_formats (matching
);
1444 printf ("\n%s: file format %s\n", bfd_get_filename (abfd
),
1447 print_arelt_descr (stdout
, abfd
, true);
1448 if (dump_file_header
)
1449 dump_bfd_header (abfd
);
1450 if (dump_private_headers
)
1451 dump_bfd_private_header (abfd
);
1453 if (dump_section_headers
)
1454 dump_headers (abfd
);
1455 if (dump_symtab
|| dump_reloc_info
|| disassemble
|| dump_debugging
)
1457 syms
= slurp_symtab (abfd
);
1459 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
)
1461 dynsyms
= slurp_dynamic_symtab (abfd
);
1464 dump_symbols (abfd
, false);
1465 if (dump_dynamic_symtab
)
1466 dump_symbols (abfd
, true);
1467 if (dump_stab_section_info
)
1469 if (dump_reloc_info
&& ! disassemble
)
1471 if (dump_dynamic_reloc_info
)
1472 dump_dynamic_relocs (abfd
);
1473 if (dump_section_contents
)
1476 disassemble_data (abfd
);
1481 dhandle
= read_debugging_info (abfd
, syms
, symcount
);
1482 if (dhandle
!= NULL
)
1484 if (! print_debugging_info (stdout
, dhandle
))
1485 fprintf (stderr
, "%s: printing debugging information failed\n",
1486 bfd_get_filename (abfd
));
1502 display_file (filename
, target
)
1506 bfd
*file
, *arfile
= (bfd
*) NULL
;
1508 file
= bfd_openr (filename
, target
);
1511 bfd_nonfatal (filename
);
1515 if (bfd_check_format (file
, bfd_archive
) == true)
1517 bfd
*last_arfile
= NULL
;
1519 printf ("In archive %s:\n", bfd_get_filename (file
));
1522 bfd_set_error (bfd_error_no_error
);
1524 arfile
= bfd_openr_next_archived_file (file
, arfile
);
1527 if (bfd_get_error () != bfd_error_no_more_archived_files
)
1529 bfd_nonfatal (bfd_get_filename (file
));
1534 display_bfd (arfile
);
1536 if (last_arfile
!= NULL
)
1537 bfd_close (last_arfile
);
1538 last_arfile
= arfile
;
1541 if (last_arfile
!= NULL
)
1542 bfd_close (last_arfile
);
1550 /* Actually display the various requested regions */
1558 bfd_size_type datasize
= 0;
1560 bfd_size_type start
, stop
;
1562 for (section
= abfd
->sections
; section
!= NULL
; section
=
1567 if (only
== (char *) NULL
||
1568 strcmp (only
, section
->name
) == 0)
1570 if (section
->flags
& SEC_HAS_CONTENTS
)
1572 printf ("Contents of section %s:\n", section
->name
);
1574 if (bfd_section_size (abfd
, section
) == 0)
1576 data
= (bfd_byte
*) xmalloc ((size_t) bfd_section_size (abfd
, section
));
1577 datasize
= bfd_section_size (abfd
, section
);
1580 bfd_get_section_contents (abfd
, section
, (PTR
) data
, 0, bfd_section_size (abfd
, section
));
1582 if (start_address
== (bfd_vma
) -1
1583 || start_address
< section
->vma
)
1586 start
= start_address
- section
->vma
;
1587 if (stop_address
== (bfd_vma
) -1)
1588 stop
= bfd_section_size (abfd
, section
);
1591 if (stop_address
< section
->vma
)
1594 stop
= stop_address
- section
->vma
;
1595 if (stop
> bfd_section_size (abfd
, section
))
1596 stop
= bfd_section_size (abfd
, section
);
1598 for (i
= start
; i
< stop
; i
+= onaline
)
1602 printf (" %04lx ", (unsigned long int) (i
+ section
->vma
));
1603 for (j
= i
; j
< i
+ onaline
; j
++)
1606 printf ("%02x", (unsigned) (data
[j
]));
1614 for (j
= i
; j
< i
+ onaline
; j
++)
1619 printf ("%c", isprint (data
[j
]) ? data
[j
] : '.');
1629 /* Should perhaps share code and display with nm? */
1631 dump_symbols (abfd
, dynamic
)
1645 printf ("DYNAMIC SYMBOL TABLE:\n");
1653 printf ("SYMBOL TABLE:\n");
1656 for (count
= 0; count
< max
; count
++)
1660 bfd
*cur_bfd
= bfd_asymbol_bfd(*current
);
1663 bfd_print_symbol (cur_bfd
,
1665 *current
, bfd_print_symbol_all
);
1683 for (a
= abfd
->sections
; a
!= (asection
*) NULL
; a
= a
->next
)
1687 if (bfd_is_abs_section (a
))
1689 if (bfd_is_und_section (a
))
1691 if (bfd_is_com_section (a
))
1696 if (strcmp (only
, a
->name
))
1699 else if ((a
->flags
& SEC_RELOC
) == 0)
1702 relsize
= bfd_get_reloc_upper_bound (abfd
, a
);
1704 bfd_fatal (bfd_get_filename (abfd
));
1706 printf ("RELOCATION RECORDS FOR [%s]:", a
->name
);
1710 printf (" (none)\n\n");
1714 relpp
= (arelent
**) xmalloc (relsize
);
1715 relcount
= bfd_canonicalize_reloc (abfd
, a
, relpp
, syms
);
1717 bfd_fatal (bfd_get_filename (abfd
));
1718 else if (relcount
== 0)
1720 printf (" (none)\n\n");
1725 dump_reloc_set (abfd
, a
, relpp
, relcount
);
1734 dump_dynamic_relocs (abfd
)
1741 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1743 bfd_fatal (bfd_get_filename (abfd
));
1745 printf ("DYNAMIC RELOCATION RECORDS");
1749 printf (" (none)\n\n");
1753 relpp
= (arelent
**) xmalloc (relsize
);
1754 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
1756 bfd_fatal (bfd_get_filename (abfd
));
1757 else if (relcount
== 0)
1759 printf (" (none)\n\n");
1764 dump_reloc_set (abfd
, (asection
*) NULL
, relpp
, relcount
);
1772 dump_reloc_set (abfd
, sec
, relpp
, relcount
)
1779 char *last_filename
, *last_functionname
;
1780 unsigned int last_line
;
1782 /* Get column headers lined up reasonably. */
1788 sprintf_vma (buf
, (bfd_vma
) -1);
1789 width
= strlen (buf
) - 7;
1791 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
1794 last_filename
= NULL
;
1795 last_functionname
= NULL
;
1798 for (p
= relpp
; relcount
&& *p
!= (arelent
*) NULL
; p
++, relcount
--)
1801 const char *filename
, *functionname
;
1803 const char *sym_name
;
1804 const char *section_name
;
1806 if (start_address
!= (bfd_vma
) -1
1807 && q
->address
< start_address
)
1809 if (stop_address
!= (bfd_vma
) -1
1810 && q
->address
> stop_address
)
1813 if (with_line_numbers
1815 && bfd_find_nearest_line (abfd
, sec
, syms
, q
->address
,
1816 &filename
, &functionname
, &line
))
1818 if (functionname
!= NULL
1819 && (last_functionname
== NULL
1820 || strcmp (functionname
, last_functionname
) != 0))
1822 printf ("%s():\n", functionname
);
1823 if (last_functionname
!= NULL
)
1824 free (last_functionname
);
1825 last_functionname
= xstrdup (functionname
);
1828 && (line
!= last_line
1829 || (filename
!= NULL
1830 && last_filename
!= NULL
1831 && strcmp (filename
, last_filename
) != 0)))
1833 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
1835 if (last_filename
!= NULL
)
1836 free (last_filename
);
1837 if (filename
== NULL
)
1838 last_filename
= NULL
;
1840 last_filename
= xstrdup (filename
);
1844 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
1846 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
1847 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
1852 section_name
= NULL
;
1856 printf_vma (q
->address
);
1857 printf (" %-16s %s",
1863 if (section_name
== (CONST
char *) NULL
)
1864 section_name
= "*unknown*";
1865 printf_vma (q
->address
);
1866 printf (" %-16s [%s]",
1873 printf_vma (q
->addend
);
1879 /* The length of the longest architecture name + 1. */
1880 #define LONGEST_ARCH sizeof("rs6000:6000")
1887 endian_string (endian
)
1888 enum bfd_endian endian
;
1890 if (endian
== BFD_ENDIAN_BIG
)
1891 return "big endian";
1892 else if (endian
== BFD_ENDIAN_LITTLE
)
1893 return "little endian";
1895 return "endianness unknown";
1898 /* List the targets that BFD is configured to support, each followed
1899 by its endianness and the architectures it supports. */
1902 display_target_list ()
1904 extern char *tmpnam ();
1905 extern bfd_target
*bfd_target_vector
[];
1906 char tmparg
[L_tmpnam
];
1910 dummy_name
= tmpnam (tmparg
);
1911 for (t
= 0; bfd_target_vector
[t
]; t
++)
1913 bfd_target
*p
= bfd_target_vector
[t
];
1914 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1917 printf ("%s\n (header %s, data %s)\n", p
->name
,
1918 endian_string (p
->header_byteorder
),
1919 endian_string (p
->byteorder
));
1923 bfd_nonfatal (dummy_name
);
1927 if (! bfd_set_format (abfd
, bfd_object
))
1929 if (bfd_get_error () != bfd_error_invalid_operation
)
1930 bfd_nonfatal (p
->name
);
1934 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1935 if (bfd_set_arch_mach (abfd
, (enum bfd_architecture
) a
, 0))
1937 bfd_printable_arch_mach ((enum bfd_architecture
) a
, 0));
1939 unlink (dummy_name
);
1942 /* Print a table showing which architectures are supported for entries
1943 FIRST through LAST-1 of bfd_target_vector (targets across,
1944 architectures down). */
1947 display_info_table (first
, last
)
1951 extern bfd_target
*bfd_target_vector
[];
1952 extern char *tmpnam ();
1953 char tmparg
[L_tmpnam
];
1957 /* Print heading of target names. */
1958 printf ("\n%*s", (int) LONGEST_ARCH
, " ");
1959 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1960 printf ("%s ", bfd_target_vector
[t
]->name
);
1963 dummy_name
= tmpnam (tmparg
);
1964 for (a
= (int) bfd_arch_obscure
+ 1; a
< (int) bfd_arch_last
; a
++)
1965 if (strcmp (bfd_printable_arch_mach (a
, 0), "UNKNOWN!") != 0)
1967 printf ("%*s ", (int) LONGEST_ARCH
- 1,
1968 bfd_printable_arch_mach (a
, 0));
1969 for (t
= first
; t
< last
&& bfd_target_vector
[t
]; t
++)
1971 bfd_target
*p
= bfd_target_vector
[t
];
1973 bfd
*abfd
= bfd_openw (dummy_name
, p
->name
);
1977 bfd_nonfatal (p
->name
);
1983 if (! bfd_set_format (abfd
, bfd_object
))
1985 if (bfd_get_error () != bfd_error_invalid_operation
)
1986 bfd_nonfatal (p
->name
);
1993 if (! bfd_set_arch_mach (abfd
, a
, 0))
1998 printf ("%s ", p
->name
);
2001 int l
= strlen (p
->name
);
2009 unlink (dummy_name
);
2012 /* Print tables of all the target-architecture combinations that
2013 BFD has been configured to support. */
2016 display_target_tables ()
2019 extern bfd_target
*bfd_target_vector
[];
2021 extern char *getenv ();
2024 colum
= getenv ("COLUMNS");
2026 columns
= atoi (colum
);
2031 while (bfd_target_vector
[t
] != NULL
)
2035 wid
= LONGEST_ARCH
+ strlen (bfd_target_vector
[t
]->name
) + 1;
2037 while (wid
< columns
&& bfd_target_vector
[t
] != NULL
)
2041 newwid
= wid
+ strlen (bfd_target_vector
[t
]->name
) + 1;
2042 if (newwid
>= columns
)
2047 display_info_table (oldt
, t
);
2054 printf ("BFD header file version %s\n", BFD_VERSION
);
2055 display_target_list ();
2056 display_target_tables ();
2065 char *target
= default_target
;
2066 boolean seenflag
= false;
2068 program_name
= *argv
;
2069 xmalloc_set_program_name (program_name
);
2071 START_PROGRESS (program_name
, 0);
2075 while ((c
= getopt_long (argc
, argv
, "pib:m:VdDlfahrRtTxsSj:wE:",
2076 long_options
, (int *) 0))
2079 if (c
!= 'l' && c
!= OPTION_START_ADDRESS
&& c
!= OPTION_STOP_ADDRESS
)
2084 break; /* we've been given a long option */
2092 with_line_numbers
= 1;
2098 dump_file_header
= true;
2101 formats_info
= true;
2104 dump_private_headers
= 1;
2107 dump_private_headers
= 1;
2109 dump_reloc_info
= 1;
2110 dump_file_header
= true;
2112 dump_section_headers
= 1;
2118 dump_dynamic_symtab
= 1;
2124 disassemble
= disassemble_all
= true;
2128 with_source_code
= true;
2131 dump_section_contents
= 1;
2134 dump_reloc_info
= 1;
2137 dump_dynamic_reloc_info
= 1;
2143 dump_section_headers
= 1;
2153 case OPTION_START_ADDRESS
:
2154 start_address
= parse_vma (optarg
, "--start-address");
2156 case OPTION_STOP_ADDRESS
:
2157 stop_address
= parse_vma (optarg
, "--stop-address");
2160 if (strcmp (optarg
, "B") == 0)
2161 endian
= BFD_ENDIAN_BIG
;
2162 else if (strcmp (optarg
, "L") == 0)
2163 endian
= BFD_ENDIAN_LITTLE
;
2166 fprintf (stderr
, "%s: unrecognized -E option\n", program_name
);
2171 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
2172 endian
= BFD_ENDIAN_BIG
;
2173 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
2174 endian
= BFD_ENDIAN_LITTLE
;
2177 fprintf (stderr
, "%s: unrecognized --endian type `%s'\n",
2178 program_name
, optarg
);
2189 printf ("GNU %s version %s\n", program_name
, program_version
);
2193 if (seenflag
== false)
2203 display_file ("a.out", target
);
2205 for (; optind
< argc
;)
2206 display_file (argv
[optind
++], target
);
2209 END_PROGRESS (program_name
);