Commit | Line | Data |
---|---|---|
d20f480f | 1 | /* objdump.c -- dump information about an object file. |
54f74247 | 2 | Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. |
2fa0b342 | 3 | |
b3a2b497 | 4 | This file is part of GNU Binutils. |
2fa0b342 | 5 | |
b3a2b497 | 6 | This program is free software; you can redistribute it and/or modify |
2fa0b342 | 7 | it under the terms of the GNU General Public License as published by |
d20f480f | 8 | the Free Software Foundation; either version 2, or (at your option) |
2fa0b342 DHW |
9 | any later version. |
10 | ||
b3a2b497 | 11 | This program is distributed in the hope that it will be useful, |
2fa0b342 DHW |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
b3a2b497 | 17 | along with this program; if not, write to the Free Software |
a65619c8 | 18 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
2fa0b342 | 19 | |
2fa0b342 DHW |
20 | #include "bfd.h" |
21 | #include "getopt.h" | |
be1d162b | 22 | #include "progress.h" |
e1ec9f07 | 23 | #include "bucomm.h" |
2fa0b342 | 24 | #include <ctype.h> |
2e8adbd7 | 25 | #include "dis-asm.h" |
105da05c | 26 | #include "libiberty.h" |
9793039f | 27 | #include "demangle.h" |
e1c14599 ILT |
28 | #include "debug.h" |
29 | #include "budbg.h" | |
2fa0b342 | 30 | |
7fc01fc9 ILT |
31 | #ifdef ANSI_PROTOTYPES |
32 | #include <stdarg.h> | |
33 | #else | |
34 | #include <varargs.h> | |
35 | #endif | |
36 | ||
73b8f102 JG |
37 | /* Internal headers for the ELF .stab-dump code - sorry. */ |
38 | #define BYTES_IN_WORD 32 | |
39 | #include "aout/aout64.h" | |
bf661056 | 40 | |
746cffcf ILT |
41 | #ifdef NEED_DECLARATION_FPRINTF |
42 | /* This is needed by INIT_DISASSEMBLE_INFO. */ | |
7fc01fc9 | 43 | extern int fprintf PARAMS ((FILE *, const char *, ...)); |
80d19ec1 | 44 | #endif |
2fa0b342 | 45 | |
18f39dfa | 46 | static char *default_target = NULL; /* default at runtime */ |
2fa0b342 | 47 | |
18f39dfa SG |
48 | static int show_version = 0; /* show the version number */ |
49 | static int dump_section_contents; /* -s */ | |
50 | static int dump_section_headers; /* -h */ | |
51 | static boolean dump_file_header; /* -f */ | |
52 | static int dump_symtab; /* -t */ | |
53 | static int dump_dynamic_symtab; /* -T */ | |
54 | static int dump_reloc_info; /* -r */ | |
55 | static int dump_dynamic_reloc_info; /* -R */ | |
56 | static int dump_ar_hdrs; /* -a */ | |
57 | static int dump_private_headers; /* -p */ | |
b4aabb24 | 58 | static int prefix_addresses; /* --prefix-addresses */ |
18f39dfa SG |
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 */ | |
9793039f | 63 | static int do_demangle; /* -C, --demangle */ |
18f39dfa SG |
64 | static boolean disassemble; /* -d */ |
65 | static boolean disassemble_all; /* -D */ | |
51b8c416 | 66 | static int disassemble_zeroes; /* --disassemble-zeroes */ |
18f39dfa SG |
67 | static boolean formats_info; /* -i */ |
68 | static char *only; /* -j secname */ | |
69 | static int wide_output; /* -w */ | |
70 | static bfd_vma start_address = (bfd_vma) -1; /* --start-address */ | |
71 | static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */ | |
72 | static int dump_debugging; /* --debugging */ | |
5c59269f | 73 | static bfd_vma adjust_section_vma = 0; /* --adjust-vma */ |
195d1adf | 74 | |
cef35d48 | 75 | /* Extra info to pass to the disassembler address printing function. */ |
195d1adf KR |
76 | struct objdump_disasm_info { |
77 | bfd *abfd; | |
78 | asection *sec; | |
8b129785 | 79 | boolean require_sec; |
195d1adf | 80 | }; |
2fa0b342 | 81 | |
cef35d48 | 82 | /* Architecture to disassemble for, or default if NULL. */ |
18f39dfa SG |
83 | static char *machine = (char *) NULL; |
84 | ||
85 | /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */ | |
86 | static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN; | |
f7b839f7 DM |
87 | |
88 | /* The symbol table. */ | |
18f39dfa | 89 | static asymbol **syms; |
2fa0b342 | 90 | |
f7b839f7 | 91 | /* Number of symbols in `syms'. */ |
18f39dfa | 92 | static long symcount = 0; |
2fa0b342 | 93 | |
be1d162b | 94 | /* The sorted symbol table. */ |
18f39dfa | 95 | static asymbol **sorted_syms; |
be1d162b ILT |
96 | |
97 | /* Number of symbols in `sorted_syms'. */ | |
18f39dfa | 98 | static long sorted_symcount = 0; |
be1d162b | 99 | |
de3b08ac | 100 | /* The dynamic symbol table. */ |
18f39dfa | 101 | static asymbol **dynsyms; |
de3b08ac ILT |
102 | |
103 | /* Number of symbols in `dynsyms'. */ | |
18f39dfa | 104 | static long dynsymcount = 0; |
de3b08ac | 105 | |
d9971b83 KR |
106 | /* Forward declarations. */ |
107 | ||
108 | static void | |
109 | display_file PARAMS ((char *filename, char *target)); | |
110 | ||
111 | static void | |
112 | dump_data PARAMS ((bfd *abfd)); | |
113 | ||
114 | static void | |
115 | dump_relocs PARAMS ((bfd *abfd)); | |
116 | ||
117 | static void | |
de3b08ac ILT |
118 | dump_dynamic_relocs PARAMS ((bfd * abfd)); |
119 | ||
120 | static void | |
18f39dfa | 121 | dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long)); |
de3b08ac ILT |
122 | |
123 | static void | |
124 | dump_symbols PARAMS ((bfd *abfd, boolean dynamic)); | |
02a68547 ILT |
125 | |
126 | static void | |
127 | display_bfd PARAMS ((bfd *abfd)); | |
8f197c94 | 128 | |
c5ba2759 | 129 | static void |
51b8c416 | 130 | objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean)); |
c5ba2759 | 131 | |
9793039f ILT |
132 | static void |
133 | objdump_print_symname PARAMS ((bfd *, struct disassemble_info *, asymbol *)); | |
134 | ||
b4aabb24 ILT |
135 | static asymbol * |
136 | find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *)); | |
137 | ||
138 | static void | |
139 | objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma, | |
51b8c416 ILT |
140 | struct disassemble_info *, boolean)); |
141 | ||
142 | static void | |
143 | objdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean)); | |
b4aabb24 | 144 | |
8f197c94 ILT |
145 | static void |
146 | objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *)); | |
be1d162b ILT |
147 | |
148 | static void | |
149 | show_line PARAMS ((bfd *, asection *, bfd_vma)); | |
e1c14599 | 150 | |
b4aabb24 ILT |
151 | static void |
152 | disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype, | |
153 | boolean, bfd_byte *, long, long, arelent ***, | |
154 | arelent **)); | |
155 | ||
156 | static void | |
157 | disassemble_data PARAMS ((bfd *)); | |
158 | ||
e1c14599 ILT |
159 | static const char * |
160 | endian_string PARAMS ((enum bfd_endian)); | |
d9971b83 | 161 | \f |
18f39dfa | 162 | static void |
b3a2b497 ILT |
163 | usage (stream, status) |
164 | FILE *stream; | |
165 | int status; | |
2fa0b342 | 166 | { |
b3a2b497 | 167 | fprintf (stream, "\ |
9793039f | 168 | Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\ |
e1c14599 | 169 | [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\ |
51b8c416 ILT |
170 | [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\ |
171 | [--section-headers] [--headers]\n\ | |
13e4db2e SC |
172 | [--info] [--section=section-name] [--line-numbers] [--source]\n", |
173 | program_name); | |
174 | fprintf (stream, "\ | |
d5464baa ILT |
175 | [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\ |
176 | [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\ | |
aa21a2a9 | 177 | [--wide] [--version] [--help] [--private-headers]\n\ |
458bbd1f | 178 | [--start-address=addr] [--stop-address=addr]\n\ |
9793039f ILT |
179 | [--prefix-addresses] [--[no-]show-raw-insn] [--demangle]\n\ |
180 | [--adjust-vma=offset] [-EB|-EL] [--endian={big|little}] objfile...\n\ | |
13e4db2e | 181 | at least one option besides -l (--line-numbers) must be given\n"); |
be1d162b | 182 | list_supported_targets (program_name, stream); |
7f924d55 ILT |
183 | if (status == 0) |
184 | fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n"); | |
b3a2b497 | 185 | exit (status); |
2fa0b342 DHW |
186 | } |
187 | ||
aa21a2a9 ILT |
188 | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ |
189 | ||
18f39dfa SG |
190 | #define OPTION_ENDIAN (150) |
191 | #define OPTION_START_ADDRESS (OPTION_ENDIAN + 1) | |
aa21a2a9 | 192 | #define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1) |
5c59269f | 193 | #define OPTION_ADJUST_VMA (OPTION_STOP_ADDRESS + 1) |
aa21a2a9 | 194 | |
aa0a709a SC |
195 | static struct option long_options[]= |
196 | { | |
5c59269f | 197 | {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA}, |
02a68547 | 198 | {"all-headers", no_argument, NULL, 'x'}, |
a65619c8 | 199 | {"private-headers", no_argument, NULL, 'p'}, |
02a68547 ILT |
200 | {"architecture", required_argument, NULL, 'm'}, |
201 | {"archive-headers", no_argument, NULL, 'a'}, | |
e1c14599 | 202 | {"debugging", no_argument, &dump_debugging, 1}, |
9793039f | 203 | {"demangle", no_argument, &do_demangle, 1}, |
02a68547 | 204 | {"disassemble", no_argument, NULL, 'd'}, |
d5464baa | 205 | {"disassemble-all", no_argument, NULL, 'D'}, |
51b8c416 | 206 | {"disassemble-zeroes", no_argument, &disassemble_zeroes, 1}, |
de3b08ac ILT |
207 | {"dynamic-reloc", no_argument, NULL, 'R'}, |
208 | {"dynamic-syms", no_argument, NULL, 'T'}, | |
18f39dfa | 209 | {"endian", required_argument, NULL, OPTION_ENDIAN}, |
02a68547 ILT |
210 | {"file-headers", no_argument, NULL, 'f'}, |
211 | {"full-contents", no_argument, NULL, 's'}, | |
212 | {"headers", no_argument, NULL, 'h'}, | |
213 | {"help", no_argument, NULL, 'H'}, | |
214 | {"info", no_argument, NULL, 'i'}, | |
215 | {"line-numbers", no_argument, NULL, 'l'}, | |
5c59269f | 216 | {"no-show-raw-insn", no_argument, &show_raw_insn, -1}, |
b4aabb24 | 217 | {"prefix-addresses", no_argument, &prefix_addresses, 1}, |
02a68547 ILT |
218 | {"reloc", no_argument, NULL, 'r'}, |
219 | {"section", required_argument, NULL, 'j'}, | |
220 | {"section-headers", no_argument, NULL, 'h'}, | |
458bbd1f | 221 | {"show-raw-insn", no_argument, &show_raw_insn, 1}, |
be1d162b | 222 | {"source", no_argument, NULL, 'S'}, |
73b8f102 | 223 | {"stabs", no_argument, &dump_stab_section_info, 1}, |
aa21a2a9 ILT |
224 | {"start-address", required_argument, NULL, OPTION_START_ADDRESS}, |
225 | {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS}, | |
02a68547 ILT |
226 | {"syms", no_argument, NULL, 't'}, |
227 | {"target", required_argument, NULL, 'b'}, | |
aa21a2a9 | 228 | {"version", no_argument, &show_version, 1}, |
13e4db2e | 229 | {"wide", no_argument, &wide_output, 'w'}, |
d2442698 DM |
230 | {0, no_argument, 0, 0} |
231 | }; | |
f7b839f7 | 232 | \f |
2fa0b342 | 233 | static void |
f7b839f7 | 234 | dump_section_header (abfd, section, ignored) |
aa0a709a | 235 | bfd *abfd; |
f7b839f7 DM |
236 | asection *section; |
237 | PTR ignored; | |
2fa0b342 | 238 | { |
f7b839f7 | 239 | char *comma = ""; |
aa0a709a | 240 | |
38d7c012 | 241 | printf ("%3d %-13s %08lx ", section->index, |
1efb2ef0 ILT |
242 | bfd_get_section_name (abfd, section), |
243 | (unsigned long) bfd_section_size (abfd, section)); | |
244 | printf_vma (bfd_get_section_vma (abfd, section)); | |
245 | printf (" "); | |
246 | printf_vma (section->lma); | |
247 | printf (" %08lx 2**%u", section->filepos, | |
248 | bfd_get_section_alignment (abfd, section)); | |
249 | if (! wide_output) | |
250 | printf ("\n "); | |
251 | printf (" "); | |
f7b839f7 | 252 | |
1efb2ef0 ILT |
253 | #define PF(x, y) \ |
254 | if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; } | |
f7b839f7 | 255 | |
1efb2ef0 | 256 | PF (SEC_HAS_CONTENTS, "CONTENTS"); |
f7b839f7 DM |
257 | PF (SEC_ALLOC, "ALLOC"); |
258 | PF (SEC_CONSTRUCTOR, "CONSTRUCTOR"); | |
259 | PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT"); | |
260 | PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA"); | |
261 | PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS"); | |
262 | PF (SEC_LOAD, "LOAD"); | |
263 | PF (SEC_RELOC, "RELOC"); | |
195d1adf | 264 | #ifdef SEC_BALIGN |
f7b839f7 | 265 | PF (SEC_BALIGN, "BALIGN"); |
195d1adf | 266 | #endif |
f7b839f7 DM |
267 | PF (SEC_READONLY, "READONLY"); |
268 | PF (SEC_CODE, "CODE"); | |
269 | PF (SEC_DATA, "DATA"); | |
270 | PF (SEC_ROM, "ROM"); | |
271 | PF (SEC_DEBUGGING, "DEBUGGING"); | |
28d1b01e | 272 | PF (SEC_NEVER_LOAD, "NEVER_LOAD"); |
83f4323e | 273 | PF (SEC_EXCLUDE, "EXCLUDE"); |
38d7c012 ILT |
274 | PF (SEC_SORT_ENTRIES, "SORT_ENTRIES"); |
275 | ||
276 | if ((section->flags & SEC_LINK_ONCE) != 0) | |
277 | { | |
278 | const char *ls; | |
279 | ||
280 | switch (section->flags & SEC_LINK_DUPLICATES) | |
281 | { | |
282 | default: | |
283 | abort (); | |
284 | case SEC_LINK_DUPLICATES_DISCARD: | |
285 | ls = "LINK_ONCE_DISCARD"; | |
286 | break; | |
287 | case SEC_LINK_DUPLICATES_ONE_ONLY: | |
288 | ls = "LINK_ONCE_ONE_ONLY"; | |
289 | break; | |
290 | case SEC_LINK_DUPLICATES_SAME_SIZE: | |
291 | ls = "LINK_ONCE_SAME_SIZE"; | |
292 | break; | |
293 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: | |
294 | ls = "LINK_ONCE_SAME_CONTENTS"; | |
295 | break; | |
296 | } | |
297 | printf ("%s%s", comma, ls); | |
298 | comma = ", "; | |
299 | } | |
300 | ||
f7b839f7 | 301 | printf ("\n"); |
2fa0b342 | 302 | #undef PF |
2fa0b342 DHW |
303 | } |
304 | ||
f7b839f7 DM |
305 | static void |
306 | dump_headers (abfd) | |
307 | bfd *abfd; | |
308 | { | |
1efb2ef0 ILT |
309 | printf ("Sections:\n"); |
310 | #ifndef BFD64 | |
311 | printf ("Idx Name Size VMA LMA File off Algn\n"); | |
312 | #else | |
313 | printf ("Idx Name Size VMA LMA File off Algn\n"); | |
314 | #endif | |
f7b839f7 DM |
315 | bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL); |
316 | } | |
317 | \f | |
2fa0b342 | 318 | static asymbol ** |
abdcac0f DM |
319 | slurp_symtab (abfd) |
320 | bfd *abfd; | |
2fa0b342 | 321 | { |
aa0a709a | 322 | asymbol **sy = (asymbol **) NULL; |
ae5d2ff5 | 323 | long storage; |
2fa0b342 | 324 | |
aa0a709a SC |
325 | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
326 | { | |
f7b839f7 | 327 | printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd)); |
c5ba2759 | 328 | symcount = 0; |
f7b839f7 | 329 | return NULL; |
aa0a709a SC |
330 | } |
331 | ||
ae5d2ff5 ILT |
332 | storage = bfd_get_symtab_upper_bound (abfd); |
333 | if (storage < 0) | |
334 | bfd_fatal (bfd_get_filename (abfd)); | |
335 | ||
aa0a709a SC |
336 | if (storage) |
337 | { | |
02a68547 | 338 | sy = (asymbol **) xmalloc (storage); |
aa0a709a SC |
339 | } |
340 | symcount = bfd_canonicalize_symtab (abfd, sy); | |
ae5d2ff5 ILT |
341 | if (symcount < 0) |
342 | bfd_fatal (bfd_get_filename (abfd)); | |
343 | if (symcount == 0) | |
de3b08ac ILT |
344 | fprintf (stderr, "%s: %s: No symbols\n", |
345 | program_name, bfd_get_filename (abfd)); | |
346 | return sy; | |
347 | } | |
348 | ||
349 | /* Read in the dynamic symbols. */ | |
350 | ||
351 | static asymbol ** | |
352 | slurp_dynamic_symtab (abfd) | |
353 | bfd *abfd; | |
354 | { | |
355 | asymbol **sy = (asymbol **) NULL; | |
356 | long storage; | |
357 | ||
de3b08ac ILT |
358 | storage = bfd_get_dynamic_symtab_upper_bound (abfd); |
359 | if (storage < 0) | |
28d1b01e ILT |
360 | { |
361 | if (!(bfd_get_file_flags (abfd) & DYNAMIC)) | |
362 | { | |
363 | fprintf (stderr, "%s: %s: not a dynamic object\n", | |
364 | program_name, bfd_get_filename (abfd)); | |
c5ba2759 | 365 | dynsymcount = 0; |
28d1b01e ILT |
366 | return NULL; |
367 | } | |
368 | ||
369 | bfd_fatal (bfd_get_filename (abfd)); | |
370 | } | |
de3b08ac ILT |
371 | |
372 | if (storage) | |
373 | { | |
374 | sy = (asymbol **) xmalloc (storage); | |
375 | } | |
376 | dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); | |
377 | if (dynsymcount < 0) | |
378 | bfd_fatal (bfd_get_filename (abfd)); | |
379 | if (dynsymcount == 0) | |
380 | fprintf (stderr, "%s: %s: No dynamic symbols\n", | |
381 | program_name, bfd_get_filename (abfd)); | |
aa0a709a | 382 | return sy; |
2fa0b342 | 383 | } |
aa0a709a | 384 | |
f7b839f7 DM |
385 | /* Filter out (in place) symbols that are useless for disassembly. |
386 | COUNT is the number of elements in SYMBOLS. | |
387 | Return the number of useful symbols. */ | |
3ae36cb6 | 388 | |
18f39dfa | 389 | static long |
f7b839f7 DM |
390 | remove_useless_symbols (symbols, count) |
391 | asymbol **symbols; | |
ae5d2ff5 | 392 | long count; |
3ae36cb6 | 393 | { |
f7b839f7 | 394 | register asymbol **in_ptr = symbols, **out_ptr = symbols; |
3ae36cb6 | 395 | |
f7b839f7 | 396 | while (--count >= 0) |
3ae36cb6 PB |
397 | { |
398 | asymbol *sym = *in_ptr++; | |
399 | ||
400 | if (sym->name == NULL || sym->name[0] == '\0') | |
401 | continue; | |
402 | if (sym->flags & (BSF_DEBUGGING)) | |
403 | continue; | |
28d1b01e | 404 | if (bfd_is_und_section (sym->section) |
3ae36cb6 PB |
405 | || bfd_is_com_section (sym->section)) |
406 | continue; | |
407 | ||
408 | *out_ptr++ = sym; | |
409 | } | |
f7b839f7 | 410 | return out_ptr - symbols; |
3ae36cb6 PB |
411 | } |
412 | ||
e1c14599 | 413 | /* Sort symbols into value order. */ |
37853673 | 414 | |
aa0a709a | 415 | static int |
37853673 | 416 | compare_symbols (ap, bp) |
d5464baa ILT |
417 | const PTR ap; |
418 | const PTR bp; | |
2fa0b342 | 419 | { |
d5464baa ILT |
420 | const asymbol *a = *(const asymbol **)ap; |
421 | const asymbol *b = *(const asymbol **)bp; | |
db552bda ILT |
422 | const char *an, *bn; |
423 | size_t anl, bnl; | |
424 | boolean af, bf; | |
e1c14599 | 425 | flagword aflags, bflags; |
2fa0b342 | 426 | |
be1d162b | 427 | if (bfd_asymbol_value (a) > bfd_asymbol_value (b)) |
3ae36cb6 | 428 | return 1; |
be1d162b | 429 | else if (bfd_asymbol_value (a) < bfd_asymbol_value (b)) |
3ae36cb6 | 430 | return -1; |
2fa0b342 | 431 | |
3ae36cb6 PB |
432 | if (a->section > b->section) |
433 | return 1; | |
434 | else if (a->section < b->section) | |
435 | return -1; | |
db552bda ILT |
436 | |
437 | an = bfd_asymbol_name (a); | |
438 | bn = bfd_asymbol_name (b); | |
439 | anl = strlen (an); | |
440 | bnl = strlen (bn); | |
441 | ||
442 | /* The symbols gnu_compiled and gcc2_compiled convey no real | |
443 | information, so put them after other symbols with the same value. */ | |
444 | ||
445 | af = (strstr (an, "gnu_compiled") != NULL | |
446 | || strstr (an, "gcc2_compiled") != NULL); | |
447 | bf = (strstr (bn, "gnu_compiled") != NULL | |
448 | || strstr (bn, "gcc2_compiled") != NULL); | |
449 | ||
450 | if (af && ! bf) | |
451 | return 1; | |
452 | if (! af && bf) | |
453 | return -1; | |
454 | ||
455 | /* We use a heuristic for the file name, to try to sort it after | |
456 | more useful symbols. It may not work on non Unix systems, but it | |
457 | doesn't really matter; the only difference is precisely which | |
458 | symbol names get printed. */ | |
459 | ||
460 | #define file_symbol(s, sn, snl) \ | |
461 | (((s)->flags & BSF_FILE) != 0 \ | |
462 | || ((sn)[(snl) - 2] == '.' \ | |
463 | && ((sn)[(snl) - 1] == 'o' \ | |
464 | || (sn)[(snl) - 1] == 'a'))) | |
465 | ||
466 | af = file_symbol (a, an, anl); | |
467 | bf = file_symbol (b, bn, bnl); | |
468 | ||
469 | if (af && ! bf) | |
470 | return 1; | |
471 | if (! af && bf) | |
472 | return -1; | |
473 | ||
b4aabb24 ILT |
474 | /* Try to sort global symbols before local symbols before function |
475 | symbols before debugging symbols. */ | |
e1c14599 ILT |
476 | |
477 | aflags = a->flags; | |
478 | bflags = b->flags; | |
479 | ||
480 | if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING)) | |
481 | { | |
482 | if ((aflags & BSF_DEBUGGING) != 0) | |
483 | return 1; | |
484 | else | |
485 | return -1; | |
486 | } | |
b4aabb24 ILT |
487 | if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION)) |
488 | { | |
489 | if ((aflags & BSF_FUNCTION) != 0) | |
490 | return -1; | |
491 | else | |
492 | return 1; | |
493 | } | |
e1c14599 ILT |
494 | if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL)) |
495 | { | |
496 | if ((aflags & BSF_LOCAL) != 0) | |
497 | return 1; | |
498 | else | |
499 | return -1; | |
500 | } | |
17aa8284 ILT |
501 | if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL)) |
502 | { | |
503 | if ((aflags & BSF_GLOBAL) != 0) | |
504 | return -1; | |
505 | else | |
506 | return 1; | |
507 | } | |
508 | ||
509 | /* Symbols that start with '.' might be section names, so sort them | |
510 | after symbols that don't start with '.'. */ | |
511 | if (an[0] == '.' && bn[0] != '.') | |
512 | return 1; | |
513 | if (an[0] != '.' && bn[0] == '.') | |
514 | return -1; | |
e1c14599 | 515 | |
17aa8284 ILT |
516 | /* Finally, if we can't distinguish them in any other way, try to |
517 | get consistent results by sorting the symbols by name. */ | |
518 | return strcmp (an, bn); | |
2fa0b342 DHW |
519 | } |
520 | ||
d5464baa ILT |
521 | /* Sort relocs into address order. */ |
522 | ||
523 | static int | |
524 | compare_relocs (ap, bp) | |
525 | const PTR ap; | |
526 | const PTR bp; | |
527 | { | |
528 | const arelent *a = *(const arelent **)ap; | |
529 | const arelent *b = *(const arelent **)bp; | |
530 | ||
531 | if (a->address > b->address) | |
532 | return 1; | |
533 | else if (a->address < b->address) | |
534 | return -1; | |
535 | ||
a65619c8 SC |
536 | /* So that associated relocations tied to the same address show up |
537 | in the correct order, we don't do any further sorting. */ | |
538 | if (a > b) | |
539 | return 1; | |
540 | else if (a < b) | |
541 | return -1; | |
542 | else | |
543 | return 0; | |
d5464baa ILT |
544 | } |
545 | ||
51b8c416 | 546 | /* Print VMA to STREAM. If SKIP_ZEROES is true, omit leading zeroes. */ |
c5ba2759 ILT |
547 | |
548 | static void | |
51b8c416 | 549 | objdump_print_value (vma, info, skip_zeroes) |
c5ba2759 | 550 | bfd_vma vma; |
7fc01fc9 | 551 | struct disassemble_info *info; |
51b8c416 | 552 | boolean skip_zeroes; |
c5ba2759 ILT |
553 | { |
554 | char buf[30]; | |
555 | char *p; | |
556 | ||
557 | sprintf_vma (buf, vma); | |
51b8c416 ILT |
558 | if (! skip_zeroes) |
559 | p = buf; | |
560 | else | |
561 | { | |
562 | for (p = buf; *p == '0'; ++p) | |
563 | ; | |
564 | if (*p == '\0') | |
565 | --p; | |
566 | } | |
7fc01fc9 | 567 | (*info->fprintf_func) (info->stream, "%s", p); |
c5ba2759 ILT |
568 | } |
569 | ||
9793039f ILT |
570 | /* Print the name of a symbol. */ |
571 | ||
572 | static void | |
573 | objdump_print_symname (abfd, info, sym) | |
574 | bfd *abfd; | |
575 | struct disassemble_info *info; | |
576 | asymbol *sym; | |
577 | { | |
578 | char *alloc; | |
579 | const char *name; | |
580 | const char *print; | |
581 | ||
582 | alloc = NULL; | |
583 | name = bfd_asymbol_name (sym); | |
584 | if (! do_demangle || name[0] == '\0') | |
585 | print = name; | |
586 | else | |
587 | { | |
588 | /* Demangle the name. */ | |
589 | if (bfd_get_symbol_leading_char (abfd) == name[0]) | |
590 | ++name; | |
591 | ||
592 | alloc = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS); | |
593 | if (alloc == NULL) | |
594 | print = name; | |
595 | else | |
596 | print = alloc; | |
597 | } | |
598 | ||
599 | if (info != NULL) | |
600 | (*info->fprintf_func) (info->stream, "%s", print); | |
601 | else | |
602 | printf ("%s", print); | |
603 | ||
604 | if (alloc != NULL) | |
605 | free (alloc); | |
606 | } | |
607 | ||
b4aabb24 ILT |
608 | /* Locate a symbol given a bfd, a section, and a VMA. If REQUIRE_SEC |
609 | is true, then always require the symbol to be in the section. This | |
610 | returns NULL if there is no suitable symbol. If PLACE is not NULL, | |
611 | then *PLACE is set to the index of the symbol in sorted_syms. */ | |
f7b839f7 | 612 | |
b4aabb24 ILT |
613 | static asymbol * |
614 | find_symbol_for_address (abfd, sec, vma, require_sec, place) | |
615 | bfd *abfd; | |
616 | asection *sec; | |
aa0a709a | 617 | bfd_vma vma; |
b4aabb24 ILT |
618 | boolean require_sec; |
619 | long *place; | |
2fa0b342 | 620 | { |
195d1adf KR |
621 | /* @@ Would it speed things up to cache the last two symbols returned, |
622 | and maybe their address ranges? For many processors, only one memory | |
623 | operand can be present at a time, so the 2-entry cache wouldn't be | |
624 | constantly churned by code doing heavy memory accesses. */ | |
2fa0b342 | 625 | |
be1d162b | 626 | /* Indices in `sorted_syms'. */ |
ae5d2ff5 | 627 | long min = 0; |
be1d162b | 628 | long max = sorted_symcount; |
ae5d2ff5 | 629 | long thisplace; |
2fa0b342 | 630 | |
be1d162b | 631 | if (sorted_symcount < 1) |
b4aabb24 | 632 | return NULL; |
f7b839f7 | 633 | |
8f197c94 ILT |
634 | /* Perform a binary search looking for the closest symbol to the |
635 | required value. We are searching the range (min, max]. */ | |
636 | while (min + 1 < max) | |
aa0a709a | 637 | { |
f7b839f7 | 638 | asymbol *sym; |
8f197c94 | 639 | |
f7b839f7 | 640 | thisplace = (max + min) / 2; |
be1d162b | 641 | sym = sorted_syms[thisplace]; |
8f197c94 | 642 | |
13e4db2e | 643 | if (bfd_asymbol_value (sym) > vma) |
f7b839f7 | 644 | max = thisplace; |
13e4db2e | 645 | else if (bfd_asymbol_value (sym) < vma) |
f7b839f7 DM |
646 | min = thisplace; |
647 | else | |
aa0a709a | 648 | { |
8f197c94 ILT |
649 | min = thisplace; |
650 | break; | |
aa0a709a | 651 | } |
f7b839f7 | 652 | } |
fc5d6074 | 653 | |
8f197c94 | 654 | /* The symbol we want is now in min, the low end of the range we |
e1c14599 ILT |
655 | were searching. If there are several symbols with the same |
656 | value, we want the first one. */ | |
8f197c94 | 657 | thisplace = min; |
db552bda ILT |
658 | while (thisplace > 0 |
659 | && (bfd_asymbol_value (sorted_syms[thisplace]) | |
660 | == bfd_asymbol_value (sorted_syms[thisplace - 1]))) | |
661 | --thisplace; | |
8f197c94 | 662 | |
b4aabb24 ILT |
663 | /* If the file is relocateable, and the symbol could be from this |
664 | section, prefer a symbol from this section over symbols from | |
665 | others, even if the other symbol's value might be closer. | |
f7b839f7 | 666 | |
b4aabb24 ILT |
667 | Note that this may be wrong for some symbol references if the |
668 | sections have overlapping memory ranges, but in that case there's | |
669 | no way to tell what's desired without looking at the relocation | |
670 | table. */ | |
671 | ||
672 | if (sorted_syms[thisplace]->section != sec | |
673 | && (require_sec | |
674 | || ((abfd->flags & HAS_RELOC) != 0 | |
675 | && vma >= bfd_get_section_vma (abfd, sec) | |
676 | && vma < (bfd_get_section_vma (abfd, sec) | |
677 | + bfd_section_size (abfd, sec))))) | |
678 | { | |
679 | long i; | |
680 | ||
681 | for (i = thisplace + 1; i < sorted_symcount; i++) | |
682 | { | |
683 | if (bfd_asymbol_value (sorted_syms[i]) | |
684 | != bfd_asymbol_value (sorted_syms[thisplace])) | |
685 | break; | |
686 | } | |
687 | --i; | |
688 | for (; i >= 0; i--) | |
689 | { | |
690 | if (sorted_syms[i]->section == sec | |
691 | && (i == 0 | |
692 | || sorted_syms[i - 1]->section != sec | |
693 | || (bfd_asymbol_value (sorted_syms[i]) | |
694 | != bfd_asymbol_value (sorted_syms[i - 1])))) | |
695 | { | |
696 | thisplace = i; | |
28d1b01e | 697 | break; |
b4aabb24 ILT |
698 | } |
699 | } | |
700 | ||
701 | if (sorted_syms[thisplace]->section != sec) | |
702 | { | |
703 | /* We didn't find a good symbol with a smaller value. | |
704 | Look for one with a larger value. */ | |
705 | for (i = thisplace + 1; i < sorted_symcount; i++) | |
706 | { | |
707 | if (sorted_syms[i]->section == sec) | |
708 | { | |
709 | thisplace = i; | |
710 | break; | |
711 | } | |
712 | } | |
713 | } | |
714 | ||
715 | if (sorted_syms[thisplace]->section != sec | |
716 | && (require_sec | |
717 | || ((abfd->flags & HAS_RELOC) != 0 | |
718 | && vma >= bfd_get_section_vma (abfd, sec) | |
719 | && vma < (bfd_get_section_vma (abfd, sec) | |
720 | + bfd_section_size (abfd, sec))))) | |
721 | { | |
722 | /* There is no suitable symbol. */ | |
723 | return NULL; | |
724 | } | |
725 | } | |
726 | ||
727 | if (place != NULL) | |
728 | *place = thisplace; | |
729 | ||
730 | return sorted_syms[thisplace]; | |
731 | } | |
732 | ||
733 | /* Print an address to INFO symbolically. */ | |
734 | ||
735 | static void | |
51b8c416 | 736 | objdump_print_addr_with_sym (abfd, sec, sym, vma, info, skip_zeroes) |
b4aabb24 ILT |
737 | bfd *abfd; |
738 | asection *sec; | |
739 | asymbol *sym; | |
740 | bfd_vma vma; | |
741 | struct disassemble_info *info; | |
51b8c416 | 742 | boolean skip_zeroes; |
b4aabb24 | 743 | { |
51b8c416 | 744 | objdump_print_value (vma, info, skip_zeroes); |
b4aabb24 ILT |
745 | |
746 | if (sym == NULL) | |
f7b839f7 | 747 | { |
b4aabb24 ILT |
748 | bfd_vma secaddr; |
749 | ||
750 | (*info->fprintf_func) (info->stream, " <%s", | |
751 | bfd_get_section_name (abfd, sec)); | |
752 | secaddr = bfd_get_section_vma (abfd, sec); | |
753 | if (vma < secaddr) | |
754 | { | |
755 | (*info->fprintf_func) (info->stream, "-"); | |
51b8c416 | 756 | objdump_print_value (secaddr - vma, info, true); |
b4aabb24 ILT |
757 | } |
758 | else if (vma > secaddr) | |
759 | { | |
760 | (*info->fprintf_func) (info->stream, "+"); | |
51b8c416 | 761 | objdump_print_value (vma - secaddr, info, true); |
b4aabb24 ILT |
762 | } |
763 | (*info->fprintf_func) (info->stream, ">"); | |
f7b839f7 | 764 | } |
b4aabb24 | 765 | else |
f7b839f7 | 766 | { |
9793039f ILT |
767 | (*info->fprintf_func) (info->stream, " <"); |
768 | objdump_print_symname (abfd, info, sym); | |
b4aabb24 ILT |
769 | if (bfd_asymbol_value (sym) > vma) |
770 | { | |
771 | (*info->fprintf_func) (info->stream, "-"); | |
51b8c416 | 772 | objdump_print_value (bfd_asymbol_value (sym) - vma, info, true); |
b4aabb24 ILT |
773 | } |
774 | else if (vma > bfd_asymbol_value (sym)) | |
775 | { | |
776 | (*info->fprintf_func) (info->stream, "+"); | |
51b8c416 | 777 | objdump_print_value (vma - bfd_asymbol_value (sym), info, true); |
b4aabb24 ILT |
778 | } |
779 | (*info->fprintf_func) (info->stream, ">"); | |
2fa0b342 | 780 | } |
b4aabb24 ILT |
781 | } |
782 | ||
51b8c416 ILT |
783 | /* Print VMA to INFO, symbolically if possible. If SKIP_ZEROES is |
784 | true, don't output leading zeroes. */ | |
b4aabb24 ILT |
785 | |
786 | static void | |
51b8c416 | 787 | objdump_print_addr (vma, info, skip_zeroes) |
b4aabb24 ILT |
788 | bfd_vma vma; |
789 | struct disassemble_info *info; | |
51b8c416 | 790 | boolean skip_zeroes; |
b4aabb24 ILT |
791 | { |
792 | struct objdump_disasm_info *aux; | |
793 | asymbol *sym; | |
794 | ||
795 | if (sorted_symcount < 1) | |
796 | { | |
51b8c416 | 797 | objdump_print_value (vma, info, skip_zeroes); |
b4aabb24 ILT |
798 | return; |
799 | } | |
800 | ||
801 | aux = (struct objdump_disasm_info *) info->application_data; | |
802 | sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec, | |
803 | (long *) NULL); | |
51b8c416 ILT |
804 | objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info, |
805 | skip_zeroes); | |
806 | } | |
807 | ||
808 | /* Print VMA to INFO. This function is passed to the disassembler | |
809 | routine. */ | |
810 | ||
811 | static void | |
812 | objdump_print_address (vma, info) | |
813 | bfd_vma vma; | |
814 | struct disassemble_info *info; | |
815 | { | |
816 | objdump_print_addr (vma, info, ! prefix_addresses); | |
2fa0b342 DHW |
817 | } |
818 | ||
be1d162b ILT |
819 | /* Hold the last function name and the last line number we displayed |
820 | in a disassembly. */ | |
821 | ||
822 | static char *prev_functionname; | |
823 | static unsigned int prev_line; | |
824 | ||
825 | /* We keep a list of all files that we have seen when doing a | |
826 | dissassembly with source, so that we know how much of the file to | |
827 | display. This can be important for inlined functions. */ | |
828 | ||
829 | struct print_file_list | |
830 | { | |
831 | struct print_file_list *next; | |
832 | char *filename; | |
833 | unsigned int line; | |
834 | FILE *f; | |
835 | }; | |
836 | ||
837 | static struct print_file_list *print_files; | |
838 | ||
839 | /* The number of preceding context lines to show when we start | |
840 | displaying a file for the first time. */ | |
841 | ||
842 | #define SHOW_PRECEDING_CONTEXT_LINES (5) | |
843 | ||
844 | /* Skip ahead to a given line in a file, optionally printing each | |
845 | line. */ | |
846 | ||
847 | static void | |
848 | skip_to_line PARAMS ((struct print_file_list *, unsigned int, boolean)); | |
849 | ||
850 | static void | |
851 | skip_to_line (p, line, show) | |
852 | struct print_file_list *p; | |
853 | unsigned int line; | |
854 | boolean show; | |
855 | { | |
856 | while (p->line < line) | |
857 | { | |
858 | char buf[100]; | |
859 | ||
860 | if (fgets (buf, sizeof buf, p->f) == NULL) | |
861 | { | |
862 | fclose (p->f); | |
863 | p->f = NULL; | |
864 | break; | |
865 | } | |
866 | ||
867 | if (show) | |
868 | printf ("%s", buf); | |
869 | ||
870 | if (strchr (buf, '\n') != NULL) | |
871 | ++p->line; | |
872 | } | |
873 | } | |
874 | ||
875 | /* Show the line number, or the source line, in a dissassembly | |
876 | listing. */ | |
877 | ||
878 | static void | |
879 | show_line (abfd, section, off) | |
aa0a709a | 880 | bfd *abfd; |
be1d162b ILT |
881 | asection *section; |
882 | bfd_vma off; | |
2fa0b342 | 883 | { |
be1d162b ILT |
884 | CONST char *filename; |
885 | CONST char *functionname; | |
886 | unsigned int line; | |
2e8adbd7 | 887 | |
be1d162b ILT |
888 | if (! with_line_numbers && ! with_source_code) |
889 | return; | |
d20f480f | 890 | |
be1d162b ILT |
891 | if (! bfd_find_nearest_line (abfd, section, syms, off, &filename, |
892 | &functionname, &line)) | |
893 | return; | |
aa0a709a | 894 | |
be1d162b ILT |
895 | if (filename != NULL && *filename == '\0') |
896 | filename = NULL; | |
897 | if (functionname != NULL && *functionname == '\0') | |
898 | functionname = NULL; | |
aa0a709a | 899 | |
be1d162b | 900 | if (with_line_numbers) |
d5464baa | 901 | { |
be1d162b ILT |
902 | if (functionname != NULL |
903 | && (prev_functionname == NULL | |
904 | || strcmp (functionname, prev_functionname) != 0)) | |
905 | printf ("%s():\n", functionname); | |
906 | if (line > 0 && line != prev_line) | |
907 | printf ("%s:%u\n", filename == NULL ? "???" : filename, line); | |
908 | } | |
909 | ||
910 | if (with_source_code | |
911 | && filename != NULL | |
912 | && line > 0) | |
913 | { | |
914 | struct print_file_list **pp, *p; | |
915 | ||
916 | for (pp = &print_files; *pp != NULL; pp = &(*pp)->next) | |
917 | if (strcmp ((*pp)->filename, filename) == 0) | |
918 | break; | |
919 | p = *pp; | |
920 | ||
921 | if (p != NULL) | |
d5464baa | 922 | { |
be1d162b ILT |
923 | if (p != print_files) |
924 | { | |
925 | int l; | |
926 | ||
927 | /* We have reencountered a file name which we saw | |
928 | earlier. This implies that either we are dumping out | |
929 | code from an included file, or the same file was | |
930 | linked in more than once. There are two common cases | |
931 | of an included file: inline functions in a header | |
932 | file, and a bison or flex skeleton file. In the | |
933 | former case we want to just start printing (but we | |
934 | back up a few lines to give context); in the latter | |
935 | case we want to continue from where we left off. I | |
936 | can't think of a good way to distinguish the cases, | |
937 | so I used a heuristic based on the file name. */ | |
938 | if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0) | |
939 | l = p->line; | |
940 | else | |
941 | { | |
942 | l = line - SHOW_PRECEDING_CONTEXT_LINES; | |
943 | if (l <= 0) | |
944 | l = 1; | |
945 | } | |
d5464baa | 946 | |
be1d162b ILT |
947 | if (p->f == NULL) |
948 | { | |
949 | p->f = fopen (p->filename, "r"); | |
950 | p->line = 0; | |
951 | } | |
952 | if (p->f != NULL) | |
953 | skip_to_line (p, l, false); | |
d5464baa | 954 | |
be1d162b ILT |
955 | if (print_files->f != NULL) |
956 | { | |
957 | fclose (print_files->f); | |
958 | print_files->f = NULL; | |
959 | } | |
960 | } | |
d5464baa | 961 | |
be1d162b ILT |
962 | if (p->f != NULL) |
963 | { | |
964 | skip_to_line (p, line, true); | |
965 | *pp = p->next; | |
966 | p->next = print_files; | |
967 | print_files = p; | |
968 | } | |
969 | } | |
970 | else | |
971 | { | |
972 | FILE *f; | |
d5464baa | 973 | |
be1d162b ILT |
974 | f = fopen (filename, "r"); |
975 | if (f != NULL) | |
d5464baa | 976 | { |
be1d162b | 977 | int l; |
d5464baa | 978 | |
be1d162b ILT |
979 | p = ((struct print_file_list *) |
980 | xmalloc (sizeof (struct print_file_list))); | |
981 | p->filename = xmalloc (strlen (filename) + 1); | |
982 | strcpy (p->filename, filename); | |
983 | p->line = 0; | |
984 | p->f = f; | |
985 | ||
986 | if (print_files != NULL && print_files->f != NULL) | |
987 | { | |
988 | fclose (print_files->f); | |
989 | print_files->f = NULL; | |
990 | } | |
991 | p->next = print_files; | |
992 | print_files = p; | |
993 | ||
994 | l = line - SHOW_PRECEDING_CONTEXT_LINES; | |
995 | if (l <= 0) | |
996 | l = 1; | |
997 | skip_to_line (p, l, false); | |
998 | if (p->f != NULL) | |
999 | skip_to_line (p, line, true); | |
d5464baa ILT |
1000 | } |
1001 | } | |
1002 | } | |
1003 | ||
be1d162b ILT |
1004 | if (functionname != NULL |
1005 | && (prev_functionname == NULL | |
1006 | || strcmp (functionname, prev_functionname) != 0)) | |
aa0a709a | 1007 | { |
be1d162b ILT |
1008 | if (prev_functionname != NULL) |
1009 | free (prev_functionname); | |
1010 | prev_functionname = xmalloc (strlen (functionname) + 1); | |
1011 | strcpy (prev_functionname, functionname); | |
aa0a709a | 1012 | } |
2fa0b342 | 1013 | |
be1d162b ILT |
1014 | if (line > 0 && line != prev_line) |
1015 | prev_line = line; | |
1016 | } | |
1017 | ||
7fc01fc9 ILT |
1018 | /* Pseudo FILE object for strings. */ |
1019 | typedef struct { | |
1020 | char *buffer; | |
1021 | char *current; | |
1022 | } SFILE; | |
1023 | ||
1024 | /* sprintf to a "stream" */ | |
1025 | ||
1026 | #ifdef ANSI_PROTOTYPES | |
1027 | static int | |
1028 | objdump_sprintf (SFILE *f, const char *format, ...) | |
1029 | { | |
1030 | int n; | |
1031 | va_list args; | |
1032 | ||
1033 | va_start (args, format); | |
1034 | vsprintf (f->current, format, args); | |
1035 | f->current += n = strlen (f->current); | |
1036 | va_end (args); | |
1037 | return n; | |
1038 | } | |
1039 | #else | |
1040 | static int | |
1041 | objdump_sprintf (va_alist) | |
1042 | va_dcl | |
1043 | { | |
1044 | int n; | |
1045 | SFILE *f; | |
1046 | const char *format; | |
1047 | va_list args; | |
1048 | ||
1049 | va_start (args); | |
1050 | f = va_arg (args, SFILE *); | |
1051 | format = va_arg (args, const char *); | |
1052 | vsprintf (f->current, format, args); | |
1053 | f->current += n = strlen (f->current); | |
1054 | va_end (args); | |
1055 | return n; | |
1056 | } | |
1057 | #endif | |
1058 | ||
b4aabb24 ILT |
1059 | /* The number of zeroes we want to see before we start skipping them. |
1060 | The number is arbitrarily chosen. */ | |
1061 | ||
1062 | #define SKIP_ZEROES (8) | |
1063 | ||
1064 | /* The number of zeroes to skip at the end of a section. If the | |
1065 | number of zeroes at the end is between SKIP_ZEROES_AT_END and | |
1066 | SKIP_ZEROES, they will be disassembled. If there are fewer than | |
1067 | SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic | |
1068 | attempt to avoid disassembling zeroes inserted by section | |
1069 | alignment. */ | |
1070 | ||
1071 | #define SKIP_ZEROES_AT_END (3) | |
1072 | ||
1073 | /* Disassemble some data in memory between given values. */ | |
1074 | ||
1075 | static void | |
1076 | disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp, | |
1077 | relppend) | |
1078 | struct disassemble_info *info; | |
1079 | disassembler_ftype disassemble_fn; | |
1080 | boolean insns; | |
1081 | bfd_byte *data; | |
1082 | long start; | |
1083 | long stop; | |
1084 | arelent ***relppp; | |
1085 | arelent **relppend; | |
1086 | { | |
1087 | struct objdump_disasm_info *aux; | |
1088 | asection *section; | |
1089 | int bytes_per_line; | |
1090 | boolean done_dot; | |
51b8c416 | 1091 | int skip_addr_chars; |
b4aabb24 ILT |
1092 | long i; |
1093 | ||
1094 | aux = (struct objdump_disasm_info *) info->application_data; | |
1095 | section = aux->sec; | |
1096 | ||
1097 | if (insns) | |
1098 | bytes_per_line = 4; | |
1099 | else | |
1100 | bytes_per_line = 16; | |
1101 | ||
51b8c416 ILT |
1102 | /* Figure out how many characters to skip at the start of an |
1103 | address, to make the disassembly look nicer. We discard leading | |
1104 | zeroes in chunks of 4, ensuring that there is always a leading | |
1105 | zero remaining. */ | |
1106 | skip_addr_chars = 0; | |
1107 | if (! prefix_addresses) | |
1108 | { | |
1109 | char buf[30]; | |
1110 | char *s; | |
1111 | ||
1112 | sprintf_vma (buf, | |
1113 | section->vma + bfd_section_size (section->owner, section)); | |
1114 | s = buf; | |
1115 | while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0' | |
1116 | && s[4] == '0') | |
1117 | { | |
1118 | skip_addr_chars += 4; | |
1119 | s += 4; | |
1120 | } | |
1121 | } | |
1122 | ||
b4aabb24 ILT |
1123 | info->insn_info_valid = 0; |
1124 | ||
1125 | done_dot = false; | |
1126 | i = start; | |
1127 | while (i < stop) | |
1128 | { | |
1129 | long z; | |
1130 | int bytes; | |
1131 | boolean need_nl = false; | |
1132 | ||
1133 | /* If we see more than SKIP_ZEROES bytes of zeroes, we just | |
1134 | print `...'. */ | |
1135 | for (z = i; z < stop; z++) | |
1136 | if (data[z] != 0) | |
1137 | break; | |
51b8c416 ILT |
1138 | if (! disassemble_zeroes |
1139 | && (info->insn_info_valid == 0 | |
1140 | || info->branch_delay_insns == 0) | |
b4aabb24 ILT |
1141 | && (z - i >= SKIP_ZEROES |
1142 | || (z == stop && z - i < SKIP_ZEROES_AT_END))) | |
1143 | { | |
1144 | printf ("\t...\n"); | |
1145 | ||
1146 | /* If there are more nonzero bytes to follow, we only skip | |
1147 | zeroes in multiples of 4, to try to avoid running over | |
1148 | the start of an instruction which happens to start with | |
1149 | zero. */ | |
1150 | if (z != stop) | |
1151 | z = i + ((z - i) &~ 3); | |
1152 | ||
1153 | bytes = z - i; | |
1154 | } | |
1155 | else | |
1156 | { | |
1157 | char buf[1000]; | |
1158 | SFILE sfile; | |
33a795dd | 1159 | int bpc, pb = 0; |
b4aabb24 ILT |
1160 | |
1161 | done_dot = false; | |
1162 | ||
1163 | if (with_line_numbers || with_source_code) | |
1164 | show_line (aux->abfd, section, i); | |
1165 | ||
1166 | if (! prefix_addresses) | |
51b8c416 ILT |
1167 | { |
1168 | char *s; | |
1169 | ||
1170 | sprintf_vma (buf, section->vma + i); | |
1171 | for (s = buf + skip_addr_chars; *s == '0'; s++) | |
1172 | *s = ' '; | |
1173 | if (*s == '\0') | |
1174 | *--s = '0'; | |
1175 | printf ("%s:\t", buf + skip_addr_chars); | |
1176 | } | |
b4aabb24 ILT |
1177 | else |
1178 | { | |
1179 | aux->require_sec = true; | |
1180 | objdump_print_address (section->vma + i, info); | |
1181 | aux->require_sec = false; | |
1182 | putchar (' '); | |
1183 | } | |
1184 | ||
1185 | if (insns) | |
1186 | { | |
1187 | sfile.buffer = sfile.current = buf; | |
1188 | info->fprintf_func = (fprintf_ftype) objdump_sprintf; | |
1189 | info->stream = (FILE *) &sfile; | |
1190 | info->bytes_per_line = 0; | |
33a795dd | 1191 | info->bytes_per_chunk = 0; |
b4aabb24 ILT |
1192 | bytes = (*disassemble_fn) (section->vma + i, info); |
1193 | info->fprintf_func = (fprintf_ftype) fprintf; | |
1194 | info->stream = stdout; | |
1195 | if (info->bytes_per_line != 0) | |
1196 | bytes_per_line = info->bytes_per_line; | |
1197 | if (bytes < 0) | |
1198 | break; | |
1199 | } | |
1200 | else | |
1201 | { | |
1202 | long j; | |
1203 | ||
1204 | bytes = bytes_per_line; | |
1205 | if (i + bytes > stop) | |
1206 | bytes = stop - i; | |
1207 | ||
1208 | for (j = i; j < i + bytes; ++j) | |
1209 | { | |
1210 | if (isprint (data[j])) | |
1211 | buf[j - i] = data[j]; | |
1212 | else | |
1213 | buf[j - i] = '.'; | |
1214 | } | |
1215 | buf[j - i] = '\0'; | |
1216 | } | |
1217 | ||
5c59269f ILT |
1218 | if (prefix_addresses |
1219 | ? show_raw_insn > 0 | |
1220 | : show_raw_insn >= 0) | |
b4aabb24 ILT |
1221 | { |
1222 | long j; | |
1223 | ||
1224 | /* If ! prefix_addresses and ! wide_output, we print | |
33a795dd | 1225 | bytes_per_line bytes per line. */ |
b4aabb24 ILT |
1226 | pb = bytes; |
1227 | if (pb > bytes_per_line && ! prefix_addresses && ! wide_output) | |
1228 | pb = bytes_per_line; | |
1229 | ||
33a795dd MH |
1230 | if (info->bytes_per_chunk) |
1231 | bpc = info->bytes_per_chunk; | |
1232 | else | |
1233 | bpc = 1; | |
1234 | ||
1235 | for (j = i; j < i + pb; j += bpc) | |
b4aabb24 | 1236 | { |
33a795dd MH |
1237 | int k; |
1238 | if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE) | |
1239 | { | |
0988ea9f ILT |
1240 | for (k = bpc - 1; k >= 0; k--) |
1241 | printf ("%02x", (unsigned) data[j + k]); | |
33a795dd MH |
1242 | putchar (' '); |
1243 | } | |
1244 | else | |
1245 | { | |
0988ea9f ILT |
1246 | for (k = 0; k < bpc; k++) |
1247 | printf ("%02x", (unsigned) data[j + k]); | |
33a795dd MH |
1248 | putchar (' '); |
1249 | } | |
b4aabb24 ILT |
1250 | } |
1251 | ||
0988ea9f ILT |
1252 | for (; pb < bytes_per_line; pb += bpc) |
1253 | { | |
1254 | int k; | |
1255 | ||
1256 | for (k = 0; k < bpc; k++) | |
1257 | printf (" "); | |
1258 | putchar (' '); | |
1259 | } | |
b4aabb24 ILT |
1260 | |
1261 | /* Separate raw data from instruction by extra space. */ | |
1262 | if (insns) | |
1263 | putchar ('\t'); | |
1264 | else | |
1265 | printf (" "); | |
1266 | } | |
1267 | ||
1268 | printf ("%s", buf); | |
1269 | ||
5c59269f ILT |
1270 | if (prefix_addresses |
1271 | ? show_raw_insn > 0 | |
1272 | : show_raw_insn >= 0) | |
b4aabb24 ILT |
1273 | { |
1274 | while (pb < bytes) | |
1275 | { | |
1276 | long j; | |
0948199a | 1277 | char *s; |
b4aabb24 ILT |
1278 | |
1279 | putchar ('\n'); | |
1280 | j = i + pb; | |
0948199a ILT |
1281 | |
1282 | sprintf_vma (buf, section->vma + j); | |
1283 | for (s = buf + skip_addr_chars; *s == '0'; s++) | |
1284 | *s = ' '; | |
1285 | if (*s == '\0') | |
1286 | *--s = '0'; | |
1287 | printf ("%s:\t", buf + skip_addr_chars); | |
1288 | ||
b4aabb24 ILT |
1289 | pb += bytes_per_line; |
1290 | if (pb > bytes) | |
1291 | pb = bytes; | |
0988ea9f | 1292 | for (; j < i + pb; j += bpc) |
b4aabb24 | 1293 | { |
0988ea9f ILT |
1294 | int k; |
1295 | ||
1296 | if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE) | |
1297 | { | |
1298 | for (k = bpc - 1; k >= 0; k--) | |
1299 | printf ("%02x", (unsigned) data[j + k]); | |
1300 | putchar (' '); | |
1301 | } | |
1302 | else | |
1303 | { | |
1304 | for (k = 0; k < bpc; k++) | |
1305 | printf ("%02x", (unsigned) data[j + k]); | |
1306 | putchar (' '); | |
1307 | } | |
b4aabb24 ILT |
1308 | } |
1309 | } | |
1310 | } | |
1311 | ||
1312 | if (!wide_output) | |
1313 | putchar ('\n'); | |
1314 | else | |
1315 | need_nl = true; | |
1316 | } | |
1317 | ||
1318 | if (dump_reloc_info | |
1319 | && (section->flags & SEC_RELOC) != 0) | |
1320 | { | |
1321 | while ((*relppp) < relppend | |
1322 | && ((**relppp)->address >= (bfd_vma) i | |
1323 | && (**relppp)->address < (bfd_vma) i + bytes)) | |
1324 | { | |
1325 | arelent *q; | |
b4aabb24 ILT |
1326 | |
1327 | q = **relppp; | |
1328 | ||
1329 | if (wide_output) | |
1330 | putchar ('\t'); | |
1331 | else | |
1332 | printf ("\t\t\t"); | |
1333 | ||
51b8c416 | 1334 | objdump_print_value (section->vma + q->address, info, true); |
b4aabb24 ILT |
1335 | |
1336 | printf (": %s\t", q->howto->name); | |
1337 | ||
9793039f ILT |
1338 | if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL) |
1339 | printf ("*unknown*"); | |
1340 | else | |
b4aabb24 | 1341 | { |
9793039f ILT |
1342 | const char *sym_name; |
1343 | ||
b4aabb24 | 1344 | sym_name = bfd_asymbol_name (*q->sym_ptr_ptr); |
9793039f ILT |
1345 | if (sym_name != NULL && *sym_name != '\0') |
1346 | objdump_print_symname (aux->abfd, info, *q->sym_ptr_ptr); | |
1347 | else | |
b4aabb24 ILT |
1348 | { |
1349 | asection *sym_sec; | |
1350 | ||
1351 | sym_sec = bfd_get_section (*q->sym_ptr_ptr); | |
9793039f | 1352 | sym_name = bfd_get_section_name (aux->abfd, sym_sec); |
b4aabb24 ILT |
1353 | if (sym_name == NULL || *sym_name == '\0') |
1354 | sym_name = "*unknown*"; | |
9793039f | 1355 | printf ("%s", sym_name); |
b4aabb24 ILT |
1356 | } |
1357 | } | |
b4aabb24 ILT |
1358 | |
1359 | if (q->addend) | |
1360 | { | |
1361 | printf ("+0x"); | |
51b8c416 | 1362 | objdump_print_value (q->addend, info, true); |
b4aabb24 ILT |
1363 | } |
1364 | ||
1365 | printf ("\n"); | |
1366 | need_nl = false; | |
1367 | ++(*relppp); | |
1368 | } | |
1369 | } | |
1370 | ||
1371 | if (need_nl) | |
1372 | printf ("\n"); | |
1373 | ||
1374 | i += bytes; | |
1375 | } | |
1376 | } | |
1377 | ||
1378 | /* Disassemble the contents of an object file. */ | |
1379 | ||
18f39dfa | 1380 | static void |
be1d162b ILT |
1381 | disassemble_data (abfd) |
1382 | bfd *abfd; | |
1383 | { | |
1384 | long i; | |
b4aabb24 | 1385 | disassembler_ftype disassemble_fn; |
be1d162b ILT |
1386 | struct disassemble_info disasm_info; |
1387 | struct objdump_disasm_info aux; | |
1388 | asection *section; | |
be1d162b ILT |
1389 | |
1390 | print_files = NULL; | |
1391 | prev_functionname = NULL; | |
1392 | prev_line = -1; | |
1393 | ||
1394 | /* We make a copy of syms to sort. We don't want to sort syms | |
1395 | because that will screw up the relocs. */ | |
1396 | sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *)); | |
1397 | memcpy (sorted_syms, syms, symcount * sizeof (asymbol *)); | |
1398 | ||
1399 | sorted_symcount = remove_useless_symbols (sorted_syms, symcount); | |
2fa0b342 DHW |
1400 | |
1401 | /* Sort the symbols into section and symbol order */ | |
be1d162b | 1402 | qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols); |
2fa0b342 | 1403 | |
4e050e3b | 1404 | INIT_DISASSEMBLE_INFO(disasm_info, stdout, fprintf); |
cef35d48 DM |
1405 | disasm_info.application_data = (PTR) &aux; |
1406 | aux.abfd = abfd; | |
8275482c | 1407 | aux.require_sec = false; |
cef35d48 DM |
1408 | disasm_info.print_address_func = objdump_print_address; |
1409 | ||
aa0a709a SC |
1410 | if (machine != (char *) NULL) |
1411 | { | |
db552bda | 1412 | const bfd_arch_info_type *info = bfd_scan_arch (machine); |
cef35d48 | 1413 | if (info == NULL) |
aa0a709a SC |
1414 | { |
1415 | fprintf (stderr, "%s: Can't use supplied machine %s\n", | |
1416 | program_name, | |
1417 | machine); | |
1418 | exit (1); | |
1419 | } | |
1420 | abfd->arch_info = info; | |
2fa0b342 | 1421 | } |
e779a58c | 1422 | |
18f39dfa SG |
1423 | if (endian != BFD_ENDIAN_UNKNOWN) |
1424 | { | |
1425 | struct bfd_target *xvec; | |
1426 | ||
1427 | xvec = (struct bfd_target *) xmalloc (sizeof (struct bfd_target)); | |
1428 | memcpy (xvec, abfd->xvec, sizeof (struct bfd_target)); | |
1429 | xvec->byteorder = endian; | |
1430 | abfd->xvec = xvec; | |
1431 | } | |
1432 | ||
db552bda ILT |
1433 | disassemble_fn = disassembler (abfd); |
1434 | if (!disassemble_fn) | |
aa0a709a | 1435 | { |
db552bda ILT |
1436 | fprintf (stderr, "%s: Can't disassemble for architecture %s\n", |
1437 | program_name, | |
1438 | bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); | |
1439 | exit (1); | |
aa0a709a | 1440 | } |
2fa0b342 | 1441 | |
7f924d55 | 1442 | disasm_info.flavour = bfd_get_flavour (abfd); |
458bbd1f DE |
1443 | disasm_info.arch = bfd_get_arch (abfd); |
1444 | disasm_info.mach = bfd_get_mach (abfd); | |
1445 | if (bfd_big_endian (abfd)) | |
1446 | disasm_info.endian = BFD_ENDIAN_BIG; | |
38aa863c | 1447 | else if (bfd_little_endian (abfd)) |
458bbd1f | 1448 | disasm_info.endian = BFD_ENDIAN_LITTLE; |
38aa863c DE |
1449 | else |
1450 | /* ??? Aborting here seems too drastic. We could default to big or little | |
1451 | instead. */ | |
1452 | disasm_info.endian = BFD_ENDIAN_UNKNOWN; | |
458bbd1f | 1453 | |
2fa0b342 | 1454 | for (section = abfd->sections; |
aa0a709a SC |
1455 | section != (asection *) NULL; |
1456 | section = section->next) | |
65cceb78 | 1457 | { |
cef35d48 DM |
1458 | bfd_byte *data = NULL; |
1459 | bfd_size_type datasize = 0; | |
be1d162b | 1460 | arelent **relbuf = NULL; |
d5464baa ILT |
1461 | arelent **relpp = NULL; |
1462 | arelent **relppend = NULL; | |
aa21a2a9 | 1463 | long stop; |
2fa0b342 | 1464 | |
d5464baa ILT |
1465 | if ((section->flags & SEC_LOAD) == 0 |
1466 | || (! disassemble_all | |
1467 | && only == NULL | |
1468 | && (section->flags & SEC_CODE) == 0)) | |
cef35d48 DM |
1469 | continue; |
1470 | if (only != (char *) NULL && strcmp (only, section->name) != 0) | |
1471 | continue; | |
2fa0b342 | 1472 | |
d5464baa ILT |
1473 | if (dump_reloc_info |
1474 | && (section->flags & SEC_RELOC) != 0) | |
1475 | { | |
be1d162b ILT |
1476 | long relsize; |
1477 | ||
1478 | relsize = bfd_get_reloc_upper_bound (abfd, section); | |
1479 | if (relsize < 0) | |
1480 | bfd_fatal (bfd_get_filename (abfd)); | |
1481 | ||
1482 | if (relsize > 0) | |
1483 | { | |
1484 | long relcount; | |
1485 | ||
1486 | relbuf = (arelent **) xmalloc (relsize); | |
1487 | relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms); | |
1488 | if (relcount < 0) | |
1489 | bfd_fatal (bfd_get_filename (abfd)); | |
1490 | ||
1491 | /* Sort the relocs by address. */ | |
1492 | qsort (relbuf, relcount, sizeof (arelent *), compare_relocs); | |
1493 | ||
1494 | relpp = relbuf; | |
1495 | relppend = relpp + relcount; | |
1496 | } | |
d5464baa ILT |
1497 | } |
1498 | ||
cef35d48 | 1499 | printf ("Disassembly of section %s:\n", section->name); |
2fa0b342 | 1500 | |
cef35d48 DM |
1501 | datasize = bfd_get_section_size_before_reloc (section); |
1502 | if (datasize == 0) | |
1503 | continue; | |
2fa0b342 | 1504 | |
cef35d48 | 1505 | data = (bfd_byte *) xmalloc ((size_t) datasize); |
2fa0b342 | 1506 | |
cef35d48 | 1507 | bfd_get_section_contents (abfd, section, data, 0, datasize); |
2fa0b342 | 1508 | |
cef35d48 DM |
1509 | aux.sec = section; |
1510 | disasm_info.buffer = data; | |
1511 | disasm_info.buffer_vma = section->vma; | |
1512 | disasm_info.buffer_length = datasize; | |
aa21a2a9 ILT |
1513 | if (start_address == (bfd_vma) -1 |
1514 | || start_address < disasm_info.buffer_vma) | |
1515 | i = 0; | |
1516 | else | |
1517 | i = start_address - disasm_info.buffer_vma; | |
1518 | if (stop_address == (bfd_vma) -1) | |
1519 | stop = datasize; | |
1520 | else | |
1521 | { | |
1522 | if (stop_address < disasm_info.buffer_vma) | |
1523 | stop = 0; | |
1524 | else | |
1525 | stop = stop_address - disasm_info.buffer_vma; | |
1526 | if (stop > disasm_info.buffer_length) | |
1527 | stop = disasm_info.buffer_length; | |
1528 | } | |
b4aabb24 ILT |
1529 | |
1530 | if (prefix_addresses) | |
1531 | disassemble_bytes (&disasm_info, disassemble_fn, true, data, i, stop, | |
1532 | &relpp, relppend); | |
1533 | else | |
cef35d48 | 1534 | { |
b4aabb24 ILT |
1535 | asymbol *sym; |
1536 | long place; | |
1537 | ||
5c59269f ILT |
1538 | sym = find_symbol_for_address (abfd, section, section->vma + i, |
1539 | true, &place); | |
b4aabb24 ILT |
1540 | ++place; |
1541 | while (i < stop) | |
cef35d48 | 1542 | { |
b4aabb24 ILT |
1543 | asymbol *nextsym; |
1544 | long nextstop; | |
1545 | boolean insns; | |
65cceb78 | 1546 | |
5c59269f ILT |
1547 | if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + i) |
1548 | disasm_info.symbol = sym; | |
1549 | else | |
1550 | disasm_info.symbol = NULL; | |
b4aabb24 ILT |
1551 | |
1552 | printf ("\n"); | |
1553 | objdump_print_addr_with_sym (abfd, section, sym, | |
1554 | section->vma + i, | |
51b8c416 ILT |
1555 | &disasm_info, |
1556 | false); | |
b4aabb24 | 1557 | printf (":\n"); |
db552bda | 1558 | |
5c59269f ILT |
1559 | if (sym != NULL && bfd_asymbol_value (sym) > section->vma + i) |
1560 | nextsym = sym; | |
1561 | else if (sym == NULL) | |
b4aabb24 ILT |
1562 | nextsym = NULL; |
1563 | else | |
7fc01fc9 | 1564 | { |
b4aabb24 ILT |
1565 | while (place < sorted_symcount |
1566 | && (sorted_syms[place]->section != section | |
1567 | || (bfd_asymbol_value (sorted_syms[place]) | |
1568 | <= bfd_asymbol_value (sym)))) | |
1569 | ++place; | |
1570 | if (place >= sorted_symcount) | |
1571 | nextsym = NULL; | |
1572 | else | |
1573 | nextsym = sorted_syms[place]; | |
7fc01fc9 ILT |
1574 | } |
1575 | ||
5c59269f ILT |
1576 | if (sym != NULL && bfd_asymbol_value (sym) > section->vma + i) |
1577 | { | |
1578 | nextstop = bfd_asymbol_value (sym) - section->vma; | |
1579 | if (nextstop > stop) | |
1580 | nextstop = stop; | |
1581 | } | |
1582 | else if (nextsym == NULL) | |
b4aabb24 | 1583 | nextstop = stop; |
13e4db2e | 1584 | else |
d5464baa | 1585 | { |
b4aabb24 ILT |
1586 | nextstop = bfd_asymbol_value (nextsym) - section->vma; |
1587 | if (nextstop > stop) | |
1588 | nextstop = stop; | |
1589 | } | |
d5464baa | 1590 | |
b4aabb24 ILT |
1591 | /* If a symbol is explicitly marked as being an object |
1592 | rather than a function, just dump the bytes without | |
1593 | disassembling them. */ | |
1594 | if (disassemble_all | |
1595 | || sym == NULL | |
5c59269f | 1596 | || bfd_asymbol_value (sym) > section->vma + i |
b4aabb24 ILT |
1597 | || ((sym->flags & BSF_OBJECT) == 0 |
1598 | && (strstr (bfd_asymbol_name (sym), "gnu_compiled") | |
1599 | == NULL) | |
1600 | && (strstr (bfd_asymbol_name (sym), "gcc2_compiled") | |
1601 | == NULL)) | |
1602 | || (sym->flags & BSF_FUNCTION) != 0) | |
1603 | insns = true; | |
1604 | else | |
1605 | insns = false; | |
d5464baa | 1606 | |
b4aabb24 ILT |
1607 | disassemble_bytes (&disasm_info, disassemble_fn, insns, data, i, |
1608 | nextstop, &relpp, relppend); | |
d5464baa | 1609 | |
b4aabb24 ILT |
1610 | i = nextstop; |
1611 | sym = nextsym; | |
d5464baa | 1612 | } |
96d7950b | 1613 | } |
be1d162b | 1614 | |
cef35d48 | 1615 | free (data); |
be1d162b ILT |
1616 | if (relbuf != NULL) |
1617 | free (relbuf); | |
2fa0b342 | 1618 | } |
c5ba2759 | 1619 | free (sorted_syms); |
2fa0b342 | 1620 | } |
73b8f102 | 1621 | \f |
73b8f102 JG |
1622 | |
1623 | /* Define a table of stab values and print-strings. We wish the initializer | |
1624 | could be a direct-mapped table, but instead we build one the first | |
1625 | time we need it. */ | |
1626 | ||
18f39dfa SG |
1627 | static void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name, |
1628 | char *strsect_name)); | |
249c6fc0 | 1629 | |
250e36fe | 1630 | /* Dump the stabs sections from an object file that has a section that |
18f39dfa | 1631 | uses Sun stabs encoding. */ |
73b8f102 | 1632 | |
18f39dfa | 1633 | static void |
9b018ecd | 1634 | dump_stabs (abfd) |
73b8f102 JG |
1635 | bfd *abfd; |
1636 | { | |
250e36fe DM |
1637 | dump_section_stabs (abfd, ".stab", ".stabstr"); |
1638 | dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr"); | |
1639 | dump_section_stabs (abfd, ".stab.index", ".stab.indexstr"); | |
1640 | dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$"); | |
249c6fc0 RS |
1641 | } |
1642 | ||
18f39dfa | 1643 | static bfd_byte *stabs; |
250e36fe DM |
1644 | static bfd_size_type stab_size; |
1645 | ||
1646 | static char *strtab; | |
1647 | static bfd_size_type stabstr_size; | |
1648 | ||
1649 | /* Read ABFD's stabs section STABSECT_NAME into `stabs' | |
1650 | and string table section STRSECT_NAME into `strtab'. | |
1651 | If the section exists and was read, allocate the space and return true. | |
1652 | Otherwise return false. */ | |
1653 | ||
18f39dfa | 1654 | static boolean |
250e36fe | 1655 | read_section_stabs (abfd, stabsect_name, strsect_name) |
249c6fc0 | 1656 | bfd *abfd; |
250e36fe DM |
1657 | char *stabsect_name; |
1658 | char *strsect_name; | |
249c6fc0 | 1659 | { |
9b018ecd | 1660 | asection *stabsect, *stabstrsect; |
9b018ecd | 1661 | |
d5671c53 ILT |
1662 | stabsect = bfd_get_section_by_name (abfd, stabsect_name); |
1663 | if (0 == stabsect) | |
73b8f102 | 1664 | { |
250e36fe DM |
1665 | printf ("No %s section present\n\n", stabsect_name); |
1666 | return false; | |
73b8f102 JG |
1667 | } |
1668 | ||
d5671c53 ILT |
1669 | stabstrsect = bfd_get_section_by_name (abfd, strsect_name); |
1670 | if (0 == stabstrsect) | |
73b8f102 | 1671 | { |
eae82145 | 1672 | fprintf (stderr, "%s: %s has no %s section\n", program_name, |
250e36fe DM |
1673 | bfd_get_filename (abfd), strsect_name); |
1674 | return false; | |
73b8f102 | 1675 | } |
9b018ecd | 1676 | |
d5671c53 ILT |
1677 | stab_size = bfd_section_size (abfd, stabsect); |
1678 | stabstr_size = bfd_section_size (abfd, stabstrsect); | |
73b8f102 | 1679 | |
18f39dfa | 1680 | stabs = (bfd_byte *) xmalloc (stab_size); |
9b018ecd | 1681 | strtab = (char *) xmalloc (stabstr_size); |
73b8f102 | 1682 | |
d5671c53 | 1683 | if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size)) |
9b018ecd | 1684 | { |
d5671c53 ILT |
1685 | fprintf (stderr, "%s: Reading %s section of %s failed: %s\n", |
1686 | program_name, stabsect_name, bfd_get_filename (abfd), | |
1687 | bfd_errmsg (bfd_get_error ())); | |
1688 | free (stabs); | |
1689 | free (strtab); | |
1690 | return false; | |
73b8f102 | 1691 | } |
2fa0b342 | 1692 | |
d5671c53 ILT |
1693 | if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0, |
1694 | stabstr_size)) | |
9b018ecd | 1695 | { |
d5671c53 ILT |
1696 | fprintf (stderr, "%s: Reading %s section of %s failed: %s\n", |
1697 | program_name, strsect_name, bfd_get_filename (abfd), | |
1698 | bfd_errmsg (bfd_get_error ())); | |
1699 | free (stabs); | |
1700 | free (strtab); | |
1701 | return false; | |
73b8f102 | 1702 | } |
d5671c53 | 1703 | |
250e36fe DM |
1704 | return true; |
1705 | } | |
73b8f102 | 1706 | |
18f39dfa SG |
1707 | /* Stabs entries use a 12 byte format: |
1708 | 4 byte string table index | |
1709 | 1 byte stab type | |
1710 | 1 byte stab other field | |
1711 | 2 byte stab desc field | |
1712 | 4 byte stab value | |
1713 | FIXME: This will have to change for a 64 bit object format. */ | |
1714 | ||
1715 | #define STRDXOFF (0) | |
1716 | #define TYPEOFF (4) | |
1717 | #define OTHEROFF (5) | |
1718 | #define DESCOFF (6) | |
1719 | #define VALOFF (8) | |
1720 | #define STABSIZE (12) | |
73b8f102 | 1721 | |
250e36fe DM |
1722 | /* Print ABFD's stabs section STABSECT_NAME (in `stabs'), |
1723 | using string table section STRSECT_NAME (in `strtab'). */ | |
1724 | ||
18f39dfa | 1725 | static void |
250e36fe DM |
1726 | print_section_stabs (abfd, stabsect_name, strsect_name) |
1727 | bfd *abfd; | |
1728 | char *stabsect_name; | |
1729 | char *strsect_name; | |
1730 | { | |
1731 | int i; | |
1732 | unsigned file_string_table_offset = 0, next_file_string_table_offset = 0; | |
18f39dfa SG |
1733 | bfd_byte *stabp, *stabs_end; |
1734 | ||
1735 | stabp = stabs; | |
1736 | stabs_end = stabp + stab_size; | |
73b8f102 | 1737 | |
250e36fe DM |
1738 | printf ("Contents of %s section:\n\n", stabsect_name); |
1739 | printf ("Symnum n_type n_othr n_desc n_value n_strx String\n"); | |
249c6fc0 RS |
1740 | |
1741 | /* Loop through all symbols and print them. | |
1742 | ||
1743 | We start the index at -1 because there is a dummy symbol on | |
250e36fe | 1744 | the front of stabs-in-{coff,elf} sections that supplies sizes. */ |
249c6fc0 | 1745 | |
18f39dfa | 1746 | for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++) |
73b8f102 | 1747 | { |
7fc01fc9 | 1748 | const char *name; |
18f39dfa SG |
1749 | unsigned long strx; |
1750 | unsigned char type, other; | |
1751 | unsigned short desc; | |
1752 | bfd_vma value; | |
1753 | ||
1754 | strx = bfd_h_get_32 (abfd, stabp + STRDXOFF); | |
1755 | type = bfd_h_get_8 (abfd, stabp + TYPEOFF); | |
1756 | other = bfd_h_get_8 (abfd, stabp + OTHEROFF); | |
1757 | desc = bfd_h_get_16 (abfd, stabp + DESCOFF); | |
1758 | value = bfd_h_get_32 (abfd, stabp + VALOFF); | |
7fc01fc9 | 1759 | |
fe2750e1 | 1760 | printf ("\n%-6d ", i); |
250e36fe | 1761 | /* Either print the stab name, or, if unnamed, print its number |
fe2750e1 | 1762 | again (makes consistent formatting for tools like awk). */ |
18f39dfa | 1763 | name = bfd_get_stab_name (type); |
7fc01fc9 ILT |
1764 | if (name != NULL) |
1765 | printf ("%-6s", name); | |
18f39dfa | 1766 | else if (type == N_UNDF) |
105da05c | 1767 | printf ("HdrSym"); |
fe2750e1 | 1768 | else |
18f39dfa SG |
1769 | printf ("%-6d", type); |
1770 | printf (" %-6d %-6d ", other, desc); | |
1771 | printf_vma (value); | |
1772 | printf (" %-6lu", strx); | |
249c6fc0 RS |
1773 | |
1774 | /* Symbols with type == 0 (N_UNDF) specify the length of the | |
1775 | string table associated with this file. We use that info | |
1776 | to know how to relocate the *next* file's string table indices. */ | |
1777 | ||
18f39dfa | 1778 | if (type == N_UNDF) |
249c6fc0 RS |
1779 | { |
1780 | file_string_table_offset = next_file_string_table_offset; | |
18f39dfa | 1781 | next_file_string_table_offset += value; |
249c6fc0 | 1782 | } |
249c6fc0 | 1783 | else |
e1ec9f07 | 1784 | { |
250e36fe | 1785 | /* Using the (possibly updated) string table offset, print the |
e1ec9f07 SS |
1786 | string (if any) associated with this symbol. */ |
1787 | ||
18f39dfa SG |
1788 | if ((strx + file_string_table_offset) < stabstr_size) |
1789 | printf (" %s", &strtab[strx + file_string_table_offset]); | |
e1ec9f07 SS |
1790 | else |
1791 | printf (" *"); | |
1792 | } | |
73b8f102 JG |
1793 | } |
1794 | printf ("\n\n"); | |
1795 | } | |
249c6fc0 | 1796 | |
18f39dfa | 1797 | static void |
250e36fe DM |
1798 | dump_section_stabs (abfd, stabsect_name, strsect_name) |
1799 | bfd *abfd; | |
1800 | char *stabsect_name; | |
1801 | char *strsect_name; | |
1802 | { | |
13e4db2e | 1803 | asection *s; |
13e4db2e | 1804 | |
a65619c8 SC |
1805 | /* Check for section names for which stabsect_name is a prefix, to |
1806 | handle .stab0, etc. */ | |
13e4db2e | 1807 | for (s = abfd->sections; |
a65619c8 | 1808 | s != NULL; |
13e4db2e SC |
1809 | s = s->next) |
1810 | { | |
18f39dfa SG |
1811 | int len; |
1812 | ||
1813 | len = strlen (stabsect_name); | |
1814 | ||
1815 | /* If the prefix matches, and the files section name ends with a nul or a digit, | |
1816 | then we match. Ie: we want either an exact match or a a section followed by | |
1817 | a number. */ | |
1818 | if (strncmp (stabsect_name, s->name, len) == 0 | |
1819 | && (s->name[len] == '\000' || isdigit (s->name[len]))) | |
13e4db2e | 1820 | { |
a65619c8 SC |
1821 | if (read_section_stabs (abfd, s->name, strsect_name)) |
1822 | { | |
1823 | print_section_stabs (abfd, s->name, strsect_name); | |
1824 | free (stabs); | |
1825 | free (strtab); | |
1826 | } | |
13e4db2e SC |
1827 | } |
1828 | } | |
250e36fe DM |
1829 | } |
1830 | \f | |
eae82145 | 1831 | static void |
f7b839f7 DM |
1832 | dump_bfd_header (abfd) |
1833 | bfd *abfd; | |
1834 | { | |
1835 | char *comma = ""; | |
1836 | ||
1837 | printf ("architecture: %s, ", | |
1838 | bfd_printable_arch_mach (bfd_get_arch (abfd), | |
1839 | bfd_get_mach (abfd))); | |
1840 | printf ("flags 0x%08x:\n", abfd->flags); | |
1841 | ||
1842 | #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";} | |
1843 | PF (HAS_RELOC, "HAS_RELOC"); | |
1844 | PF (EXEC_P, "EXEC_P"); | |
1845 | PF (HAS_LINENO, "HAS_LINENO"); | |
1846 | PF (HAS_DEBUG, "HAS_DEBUG"); | |
1847 | PF (HAS_SYMS, "HAS_SYMS"); | |
1848 | PF (HAS_LOCALS, "HAS_LOCALS"); | |
1849 | PF (DYNAMIC, "DYNAMIC"); | |
1850 | PF (WP_TEXT, "WP_TEXT"); | |
1851 | PF (D_PAGED, "D_PAGED"); | |
1852 | PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE"); | |
1853 | printf ("\nstart address 0x"); | |
1854 | printf_vma (abfd->start_address); | |
38d7c012 | 1855 | printf ("\n"); |
f7b839f7 | 1856 | } |
a65619c8 SC |
1857 | \f |
1858 | static void | |
1859 | dump_bfd_private_header (abfd) | |
1860 | bfd *abfd; | |
1861 | { | |
1862 | bfd_print_private_bfd_data (abfd, stdout); | |
1863 | } | |
18f39dfa | 1864 | |
02a68547 | 1865 | static void |
2fa0b342 DHW |
1866 | display_bfd (abfd) |
1867 | bfd *abfd; | |
1868 | { | |
209e5610 DM |
1869 | char **matching; |
1870 | ||
1871 | if (!bfd_check_format_matches (abfd, bfd_object, &matching)) | |
aa0a709a | 1872 | { |
cef35d48 | 1873 | bfd_nonfatal (bfd_get_filename (abfd)); |
8f197c94 | 1874 | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
209e5610 DM |
1875 | { |
1876 | list_matching_formats (matching); | |
1877 | free (matching); | |
1878 | } | |
aa0a709a SC |
1879 | return; |
1880 | } | |
f7b839f7 | 1881 | |
5c59269f ILT |
1882 | /* If we are adjusting section VMA's, change them all now. Changing |
1883 | the BFD information is a hack. However, we must do it, or | |
1884 | bfd_find_nearest_line will not do the right thing. */ | |
1885 | if (adjust_section_vma != 0) | |
1886 | { | |
1887 | asection *s; | |
1888 | ||
1889 | for (s = abfd->sections; s != NULL; s = s->next) | |
1890 | { | |
1891 | s->vma += adjust_section_vma; | |
1892 | s->lma += adjust_section_vma; | |
1893 | } | |
1894 | } | |
1895 | ||
cef35d48 DM |
1896 | printf ("\n%s: file format %s\n", bfd_get_filename (abfd), |
1897 | abfd->xvec->name); | |
aa0a709a SC |
1898 | if (dump_ar_hdrs) |
1899 | print_arelt_descr (stdout, abfd, true); | |
aa0a709a | 1900 | if (dump_file_header) |
f7b839f7 | 1901 | dump_bfd_header (abfd); |
a65619c8 SC |
1902 | if (dump_private_headers) |
1903 | dump_bfd_private_header (abfd); | |
f7b839f7 | 1904 | putchar ('\n'); |
2fa0b342 | 1905 | if (dump_section_headers) |
aa0a709a | 1906 | dump_headers (abfd); |
83f4323e | 1907 | if (dump_symtab || dump_reloc_info || disassemble || dump_debugging) |
aa0a709a SC |
1908 | { |
1909 | syms = slurp_symtab (abfd); | |
1910 | } | |
de3b08ac ILT |
1911 | if (dump_dynamic_symtab || dump_dynamic_reloc_info) |
1912 | { | |
1913 | dynsyms = slurp_dynamic_symtab (abfd); | |
1914 | } | |
aa0a709a | 1915 | if (dump_symtab) |
de3b08ac ILT |
1916 | dump_symbols (abfd, false); |
1917 | if (dump_dynamic_symtab) | |
1918 | dump_symbols (abfd, true); | |
73b8f102 | 1919 | if (dump_stab_section_info) |
9b018ecd | 1920 | dump_stabs (abfd); |
d5464baa | 1921 | if (dump_reloc_info && ! disassemble) |
aa0a709a | 1922 | dump_relocs (abfd); |
de3b08ac ILT |
1923 | if (dump_dynamic_reloc_info) |
1924 | dump_dynamic_relocs (abfd); | |
aa0a709a SC |
1925 | if (dump_section_contents) |
1926 | dump_data (abfd); | |
1927 | if (disassemble) | |
1928 | disassemble_data (abfd); | |
e1c14599 ILT |
1929 | if (dump_debugging) |
1930 | { | |
1931 | PTR dhandle; | |
1932 | ||
83f4323e | 1933 | dhandle = read_debugging_info (abfd, syms, symcount); |
e1c14599 ILT |
1934 | if (dhandle != NULL) |
1935 | { | |
1936 | if (! print_debugging_info (stdout, dhandle)) | |
1937 | fprintf (stderr, "%s: printing debugging information failed\n", | |
1938 | bfd_get_filename (abfd)); | |
1939 | } | |
1940 | } | |
c5ba2759 ILT |
1941 | if (syms) |
1942 | { | |
1943 | free (syms); | |
1944 | syms = NULL; | |
1945 | } | |
1946 | if (dynsyms) | |
1947 | { | |
1948 | free (dynsyms); | |
1949 | dynsyms = NULL; | |
1950 | } | |
2fa0b342 DHW |
1951 | } |
1952 | ||
d9971b83 | 1953 | static void |
2fa0b342 DHW |
1954 | display_file (filename, target) |
1955 | char *filename; | |
1956 | char *target; | |
1957 | { | |
1958 | bfd *file, *arfile = (bfd *) NULL; | |
1959 | ||
1960 | file = bfd_openr (filename, target); | |
aa0a709a SC |
1961 | if (file == NULL) |
1962 | { | |
cef35d48 | 1963 | bfd_nonfatal (filename); |
aa0a709a SC |
1964 | return; |
1965 | } | |
2fa0b342 | 1966 | |
aa0a709a SC |
1967 | if (bfd_check_format (file, bfd_archive) == true) |
1968 | { | |
8f197c94 ILT |
1969 | bfd *last_arfile = NULL; |
1970 | ||
aa0a709a SC |
1971 | printf ("In archive %s:\n", bfd_get_filename (file)); |
1972 | for (;;) | |
1973 | { | |
8f197c94 | 1974 | bfd_set_error (bfd_error_no_error); |
aa0a709a SC |
1975 | |
1976 | arfile = bfd_openr_next_archived_file (file, arfile); | |
1977 | if (arfile == NULL) | |
1978 | { | |
8f197c94 | 1979 | if (bfd_get_error () != bfd_error_no_more_archived_files) |
d2442698 | 1980 | { |
cef35d48 | 1981 | bfd_nonfatal (bfd_get_filename (file)); |
d2442698 | 1982 | } |
8f197c94 | 1983 | break; |
aa0a709a | 1984 | } |
2fa0b342 | 1985 | |
aa0a709a | 1986 | display_bfd (arfile); |
8f197c94 ILT |
1987 | |
1988 | if (last_arfile != NULL) | |
1989 | bfd_close (last_arfile); | |
1990 | last_arfile = arfile; | |
aa0a709a | 1991 | } |
8f197c94 ILT |
1992 | |
1993 | if (last_arfile != NULL) | |
1994 | bfd_close (last_arfile); | |
2fa0b342 | 1995 | } |
2fa0b342 | 1996 | else |
aa0a709a | 1997 | display_bfd (file); |
2fa0b342 | 1998 | |
aa0a709a | 1999 | bfd_close (file); |
2fa0b342 DHW |
2000 | } |
2001 | \f | |
2002 | /* Actually display the various requested regions */ | |
2003 | ||
d9971b83 | 2004 | static void |
2fa0b342 DHW |
2005 | dump_data (abfd) |
2006 | bfd *abfd; | |
2007 | { | |
2008 | asection *section; | |
aa0a709a | 2009 | bfd_byte *data = 0; |
fc5d6074 SC |
2010 | bfd_size_type datasize = 0; |
2011 | bfd_size_type i; | |
aa21a2a9 | 2012 | bfd_size_type start, stop; |
2fa0b342 DHW |
2013 | |
2014 | for (section = abfd->sections; section != NULL; section = | |
aa0a709a SC |
2015 | section->next) |
2016 | { | |
2017 | int onaline = 16; | |
2fa0b342 | 2018 | |
aa0a709a SC |
2019 | if (only == (char *) NULL || |
2020 | strcmp (only, section->name) == 0) | |
60c80016 | 2021 | { |
aa0a709a SC |
2022 | if (section->flags & SEC_HAS_CONTENTS) |
2023 | { | |
2024 | printf ("Contents of section %s:\n", section->name); | |
2025 | ||
9b018ecd | 2026 | if (bfd_section_size (abfd, section) == 0) |
aa0a709a | 2027 | continue; |
02a68547 | 2028 | data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section)); |
9b018ecd | 2029 | datasize = bfd_section_size (abfd, section); |
2fa0b342 | 2030 | |
2fa0b342 | 2031 | |
9b018ecd | 2032 | bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section)); |
2fa0b342 | 2033 | |
aa21a2a9 ILT |
2034 | if (start_address == (bfd_vma) -1 |
2035 | || start_address < section->vma) | |
2036 | start = 0; | |
2037 | else | |
2038 | start = start_address - section->vma; | |
2039 | if (stop_address == (bfd_vma) -1) | |
2040 | stop = bfd_section_size (abfd, section); | |
2041 | else | |
2042 | { | |
2043 | if (stop_address < section->vma) | |
2044 | stop = 0; | |
2045 | else | |
2046 | stop = stop_address - section->vma; | |
2047 | if (stop > bfd_section_size (abfd, section)) | |
2048 | stop = bfd_section_size (abfd, section); | |
2049 | } | |
2050 | for (i = start; i < stop; i += onaline) | |
aa0a709a SC |
2051 | { |
2052 | bfd_size_type j; | |
2053 | ||
2054 | printf (" %04lx ", (unsigned long int) (i + section->vma)); | |
2055 | for (j = i; j < i + onaline; j++) | |
2056 | { | |
aa21a2a9 | 2057 | if (j < stop) |
aa0a709a SC |
2058 | printf ("%02x", (unsigned) (data[j])); |
2059 | else | |
2060 | printf (" "); | |
2061 | if ((j & 3) == 3) | |
2062 | printf (" "); | |
2063 | } | |
2fa0b342 | 2064 | |
aa0a709a SC |
2065 | printf (" "); |
2066 | for (j = i; j < i + onaline; j++) | |
2067 | { | |
aa21a2a9 | 2068 | if (j >= stop) |
aa0a709a SC |
2069 | printf (" "); |
2070 | else | |
2071 | printf ("%c", isprint (data[j]) ? data[j] : '.'); | |
2072 | } | |
2073 | putchar ('\n'); | |
2074 | } | |
d9971b83 | 2075 | free (data); |
60c80016 | 2076 | } |
2fa0b342 | 2077 | } |
2fa0b342 | 2078 | } |
2fa0b342 DHW |
2079 | } |
2080 | ||
2fa0b342 | 2081 | /* Should perhaps share code and display with nm? */ |
d9971b83 | 2082 | static void |
de3b08ac | 2083 | dump_symbols (abfd, dynamic) |
2fa0b342 | 2084 | bfd *abfd; |
de3b08ac | 2085 | boolean dynamic; |
2fa0b342 | 2086 | { |
de3b08ac ILT |
2087 | asymbol **current; |
2088 | long max; | |
ae5d2ff5 | 2089 | long count; |
2fa0b342 | 2090 | |
de3b08ac | 2091 | if (dynamic) |
aa0a709a | 2092 | { |
de3b08ac ILT |
2093 | current = dynsyms; |
2094 | max = dynsymcount; | |
2095 | if (max == 0) | |
2096 | return; | |
2097 | printf ("DYNAMIC SYMBOL TABLE:\n"); | |
2098 | } | |
2099 | else | |
2100 | { | |
2101 | current = syms; | |
2102 | max = symcount; | |
2103 | if (max == 0) | |
2104 | return; | |
2105 | printf ("SYMBOL TABLE:\n"); | |
2106 | } | |
2fa0b342 | 2107 | |
de3b08ac ILT |
2108 | for (count = 0; count < max; count++) |
2109 | { | |
d9971b83 | 2110 | if (*current) |
aa0a709a | 2111 | { |
9793039f ILT |
2112 | bfd *cur_bfd = bfd_asymbol_bfd (*current); |
2113 | ||
2114 | if (cur_bfd != NULL) | |
d9971b83 | 2115 | { |
9793039f ILT |
2116 | const char *name; |
2117 | char *alloc; | |
2118 | ||
2119 | name = bfd_asymbol_name (*current); | |
2120 | alloc = NULL; | |
2121 | if (do_demangle && name != NULL && *name != '\0') | |
2122 | { | |
2123 | const char *n; | |
2124 | ||
2125 | /* If we want to demangle the name, we demangle it | |
2126 | here, and temporarily clobber it while calling | |
2127 | bfd_print_symbol. FIXME: This is a gross hack. */ | |
2128 | ||
2129 | n = name; | |
2130 | if (bfd_get_symbol_leading_char (cur_bfd) == *n) | |
2131 | ++n; | |
2132 | alloc = cplus_demangle (n, DMGL_ANSI | DMGL_PARAMS); | |
2133 | if (alloc != NULL) | |
2134 | (*current)->name = alloc; | |
2135 | else | |
2136 | (*current)->name = n; | |
2137 | } | |
2138 | ||
2139 | bfd_print_symbol (cur_bfd, stdout, *current, | |
2140 | bfd_print_symbol_all); | |
2141 | ||
2142 | (*current)->name = name; | |
2143 | if (alloc != NULL) | |
2144 | free (alloc); | |
2145 | ||
d9971b83 KR |
2146 | printf ("\n"); |
2147 | } | |
aa0a709a SC |
2148 | } |
2149 | current++; | |
2fa0b342 | 2150 | } |
aa0a709a SC |
2151 | printf ("\n"); |
2152 | printf ("\n"); | |
2fa0b342 DHW |
2153 | } |
2154 | ||
d9971b83 | 2155 | static void |
aa0a709a SC |
2156 | dump_relocs (abfd) |
2157 | bfd *abfd; | |
2fa0b342 DHW |
2158 | { |
2159 | arelent **relpp; | |
ae5d2ff5 | 2160 | long relcount; |
2fa0b342 | 2161 | asection *a; |
aa0a709a SC |
2162 | |
2163 | for (a = abfd->sections; a != (asection *) NULL; a = a->next) | |
2164 | { | |
ae5d2ff5 ILT |
2165 | long relsize; |
2166 | ||
28d1b01e | 2167 | if (bfd_is_abs_section (a)) |
aa0a709a | 2168 | continue; |
28d1b01e | 2169 | if (bfd_is_und_section (a)) |
aa0a709a | 2170 | continue; |
d9971b83 | 2171 | if (bfd_is_com_section (a)) |
aa0a709a SC |
2172 | continue; |
2173 | ||
195d1adf KR |
2174 | if (only) |
2175 | { | |
2176 | if (strcmp (only, a->name)) | |
2177 | continue; | |
2178 | } | |
2179 | else if ((a->flags & SEC_RELOC) == 0) | |
2180 | continue; | |
2181 | ||
ae5d2ff5 ILT |
2182 | relsize = bfd_get_reloc_upper_bound (abfd, a); |
2183 | if (relsize < 0) | |
2184 | bfd_fatal (bfd_get_filename (abfd)); | |
2185 | ||
c5ba2759 ILT |
2186 | printf ("RELOCATION RECORDS FOR [%s]:", a->name); |
2187 | ||
ae5d2ff5 | 2188 | if (relsize == 0) |
aa0a709a SC |
2189 | { |
2190 | printf (" (none)\n\n"); | |
d20f480f | 2191 | } |
aa0a709a SC |
2192 | else |
2193 | { | |
ae5d2ff5 | 2194 | relpp = (arelent **) xmalloc (relsize); |
aa0a709a | 2195 | relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms); |
ae5d2ff5 ILT |
2196 | if (relcount < 0) |
2197 | bfd_fatal (bfd_get_filename (abfd)); | |
2198 | else if (relcount == 0) | |
aa0a709a SC |
2199 | { |
2200 | printf (" (none)\n\n"); | |
d20f480f | 2201 | } |
aa0a709a SC |
2202 | else |
2203 | { | |
2204 | printf ("\n"); | |
18f39dfa | 2205 | dump_reloc_set (abfd, a, relpp, relcount); |
aa0a709a | 2206 | printf ("\n\n"); |
d20f480f | 2207 | } |
de3b08ac | 2208 | free (relpp); |
2fa0b342 | 2209 | } |
de3b08ac ILT |
2210 | } |
2211 | } | |
2fa0b342 | 2212 | |
de3b08ac ILT |
2213 | static void |
2214 | dump_dynamic_relocs (abfd) | |
2215 | bfd *abfd; | |
2216 | { | |
2217 | long relsize; | |
2218 | arelent **relpp; | |
2219 | long relcount; | |
2220 | ||
de3b08ac ILT |
2221 | relsize = bfd_get_dynamic_reloc_upper_bound (abfd); |
2222 | if (relsize < 0) | |
2223 | bfd_fatal (bfd_get_filename (abfd)); | |
2224 | ||
c5ba2759 ILT |
2225 | printf ("DYNAMIC RELOCATION RECORDS"); |
2226 | ||
de3b08ac ILT |
2227 | if (relsize == 0) |
2228 | { | |
2229 | printf (" (none)\n\n"); | |
2230 | } | |
2231 | else | |
2232 | { | |
2233 | relpp = (arelent **) xmalloc (relsize); | |
2234 | relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms); | |
2235 | if (relcount < 0) | |
2236 | bfd_fatal (bfd_get_filename (abfd)); | |
2237 | else if (relcount == 0) | |
2238 | { | |
2239 | printf (" (none)\n\n"); | |
2240 | } | |
2241 | else | |
2242 | { | |
2243 | printf ("\n"); | |
18f39dfa | 2244 | dump_reloc_set (abfd, (asection *) NULL, relpp, relcount); |
de3b08ac ILT |
2245 | printf ("\n\n"); |
2246 | } | |
2247 | free (relpp); | |
2248 | } | |
2249 | } | |
2250 | ||
2251 | static void | |
18f39dfa | 2252 | dump_reloc_set (abfd, sec, relpp, relcount) |
de3b08ac | 2253 | bfd *abfd; |
18f39dfa | 2254 | asection *sec; |
de3b08ac ILT |
2255 | arelent **relpp; |
2256 | long relcount; | |
2257 | { | |
2258 | arelent **p; | |
18f39dfa SG |
2259 | char *last_filename, *last_functionname; |
2260 | unsigned int last_line; | |
de3b08ac ILT |
2261 | |
2262 | /* Get column headers lined up reasonably. */ | |
2263 | { | |
2264 | static int width; | |
2265 | if (width == 0) | |
2266 | { | |
2267 | char buf[30]; | |
2268 | sprintf_vma (buf, (bfd_vma) -1); | |
2269 | width = strlen (buf) - 7; | |
2270 | } | |
2271 | printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, ""); | |
2272 | } | |
2273 | ||
18f39dfa SG |
2274 | last_filename = NULL; |
2275 | last_functionname = NULL; | |
2276 | last_line = 0; | |
2277 | ||
de3b08ac ILT |
2278 | for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--) |
2279 | { | |
2280 | arelent *q = *p; | |
18f39dfa SG |
2281 | const char *filename, *functionname; |
2282 | unsigned int line; | |
2283 | const char *sym_name; | |
2284 | const char *section_name; | |
de3b08ac | 2285 | |
aa21a2a9 ILT |
2286 | if (start_address != (bfd_vma) -1 |
2287 | && q->address < start_address) | |
2288 | continue; | |
2289 | if (stop_address != (bfd_vma) -1 | |
2290 | && q->address > stop_address) | |
2291 | continue; | |
2292 | ||
18f39dfa SG |
2293 | if (with_line_numbers |
2294 | && sec != NULL | |
2295 | && bfd_find_nearest_line (abfd, sec, syms, q->address, | |
2296 | &filename, &functionname, &line)) | |
2297 | { | |
2298 | if (functionname != NULL | |
2299 | && (last_functionname == NULL | |
2300 | || strcmp (functionname, last_functionname) != 0)) | |
2301 | { | |
2302 | printf ("%s():\n", functionname); | |
2303 | if (last_functionname != NULL) | |
2304 | free (last_functionname); | |
2305 | last_functionname = xstrdup (functionname); | |
2306 | } | |
2307 | if (line > 0 | |
2308 | && (line != last_line | |
2309 | || (filename != NULL | |
2310 | && last_filename != NULL | |
2311 | && strcmp (filename, last_filename) != 0))) | |
2312 | { | |
2313 | printf ("%s:%u\n", filename == NULL ? "???" : filename, line); | |
2314 | last_line = line; | |
2315 | if (last_filename != NULL) | |
2316 | free (last_filename); | |
2317 | if (filename == NULL) | |
2318 | last_filename = NULL; | |
2319 | else | |
2320 | last_filename = xstrdup (filename); | |
2321 | } | |
2322 | } | |
2323 | ||
de3b08ac ILT |
2324 | if (q->sym_ptr_ptr && *q->sym_ptr_ptr) |
2325 | { | |
2326 | sym_name = (*(q->sym_ptr_ptr))->name; | |
2327 | section_name = (*(q->sym_ptr_ptr))->section->name; | |
2328 | } | |
2329 | else | |
2330 | { | |
2331 | sym_name = NULL; | |
2332 | section_name = NULL; | |
2333 | } | |
2334 | if (sym_name) | |
2335 | { | |
2336 | printf_vma (q->address); | |
9793039f ILT |
2337 | printf (" %-16s ", q->howto->name); |
2338 | objdump_print_symname (abfd, (struct disassemble_info *) NULL, | |
2339 | *q->sym_ptr_ptr); | |
de3b08ac ILT |
2340 | } |
2341 | else | |
2342 | { | |
2343 | if (section_name == (CONST char *) NULL) | |
2344 | section_name = "*unknown*"; | |
2345 | printf_vma (q->address); | |
2346 | printf (" %-16s [%s]", | |
2347 | q->howto->name, | |
2348 | section_name); | |
2349 | } | |
2350 | if (q->addend) | |
2351 | { | |
2352 | printf ("+0x"); | |
2353 | printf_vma (q->addend); | |
2354 | } | |
2355 | printf ("\n"); | |
d20f480f | 2356 | } |
2fa0b342 | 2357 | } |
f7b839f7 | 2358 | \f |
f7b839f7 DM |
2359 | /* The length of the longest architecture name + 1. */ |
2360 | #define LONGEST_ARCH sizeof("rs6000:6000") | |
2361 | ||
e1c14599 ILT |
2362 | static const char * |
2363 | endian_string (endian) | |
2364 | enum bfd_endian endian; | |
2365 | { | |
2366 | if (endian == BFD_ENDIAN_BIG) | |
2367 | return "big endian"; | |
2368 | else if (endian == BFD_ENDIAN_LITTLE) | |
2369 | return "little endian"; | |
2370 | else | |
2371 | return "endianness unknown"; | |
2372 | } | |
2373 | ||
f7b839f7 DM |
2374 | /* List the targets that BFD is configured to support, each followed |
2375 | by its endianness and the architectures it supports. */ | |
2376 | ||
2377 | static void | |
2378 | display_target_list () | |
2379 | { | |
2380 | extern bfd_target *bfd_target_vector[]; | |
de04bceb | 2381 | char *dummy_name; |
f7b839f7 DM |
2382 | int t; |
2383 | ||
7f924d55 | 2384 | dummy_name = choose_temp_base (); |
f7b839f7 DM |
2385 | for (t = 0; bfd_target_vector[t]; t++) |
2386 | { | |
f7b839f7 | 2387 | bfd_target *p = bfd_target_vector[t]; |
de04bceb | 2388 | bfd *abfd = bfd_openw (dummy_name, p->name); |
105da05c ILT |
2389 | int a; |
2390 | ||
2391 | printf ("%s\n (header %s, data %s)\n", p->name, | |
e1c14599 ILT |
2392 | endian_string (p->header_byteorder), |
2393 | endian_string (p->byteorder)); | |
f7b839f7 | 2394 | |
334d6e76 SS |
2395 | if (abfd == NULL) |
2396 | { | |
de04bceb | 2397 | bfd_nonfatal (dummy_name); |
105da05c | 2398 | continue; |
334d6e76 | 2399 | } |
105da05c ILT |
2400 | |
2401 | if (! bfd_set_format (abfd, bfd_object)) | |
2402 | { | |
2403 | if (bfd_get_error () != bfd_error_invalid_operation) | |
2404 | bfd_nonfatal (p->name); | |
2405 | continue; | |
2406 | } | |
2407 | ||
f7b839f7 DM |
2408 | for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++) |
2409 | if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0)) | |
2410 | printf (" %s\n", | |
2411 | bfd_printable_arch_mach ((enum bfd_architecture) a, 0)); | |
2412 | } | |
de04bceb | 2413 | unlink (dummy_name); |
7f924d55 | 2414 | free (dummy_name); |
f7b839f7 DM |
2415 | } |
2416 | ||
2417 | /* Print a table showing which architectures are supported for entries | |
2418 | FIRST through LAST-1 of bfd_target_vector (targets across, | |
2419 | architectures down). */ | |
2420 | ||
9872a49c | 2421 | static void |
abdcac0f DM |
2422 | display_info_table (first, last) |
2423 | int first; | |
2424 | int last; | |
9872a49c | 2425 | { |
abdcac0f | 2426 | extern bfd_target *bfd_target_vector[]; |
de04bceb ILT |
2427 | int t, a; |
2428 | char *dummy_name; | |
9872a49c | 2429 | |
f7b839f7 | 2430 | /* Print heading of target names. */ |
ae5d2ff5 | 2431 | printf ("\n%*s", (int) LONGEST_ARCH, " "); |
105da05c | 2432 | for (t = first; t < last && bfd_target_vector[t]; t++) |
f7b839f7 DM |
2433 | printf ("%s ", bfd_target_vector[t]->name); |
2434 | putchar ('\n'); | |
9872a49c | 2435 | |
7f924d55 | 2436 | dummy_name = choose_temp_base (); |
f7b839f7 DM |
2437 | for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++) |
2438 | if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0) | |
e779a58c | 2439 | { |
ae5d2ff5 ILT |
2440 | printf ("%*s ", (int) LONGEST_ARCH - 1, |
2441 | bfd_printable_arch_mach (a, 0)); | |
105da05c | 2442 | for (t = first; t < last && bfd_target_vector[t]; t++) |
aa0a709a | 2443 | { |
f7b839f7 | 2444 | bfd_target *p = bfd_target_vector[t]; |
105da05c | 2445 | boolean ok = true; |
de04bceb | 2446 | bfd *abfd = bfd_openw (dummy_name, p->name); |
aa0a709a | 2447 | |
334d6e76 SS |
2448 | if (abfd == NULL) |
2449 | { | |
105da05c ILT |
2450 | bfd_nonfatal (p->name); |
2451 | ok = false; | |
2452 | } | |
2453 | ||
2454 | if (ok) | |
2455 | { | |
2456 | if (! bfd_set_format (abfd, bfd_object)) | |
2457 | { | |
2458 | if (bfd_get_error () != bfd_error_invalid_operation) | |
2459 | bfd_nonfatal (p->name); | |
2460 | ok = false; | |
2461 | } | |
334d6e76 | 2462 | } |
105da05c ILT |
2463 | |
2464 | if (ok) | |
2465 | { | |
2466 | if (! bfd_set_arch_mach (abfd, a, 0)) | |
2467 | ok = false; | |
2468 | } | |
2469 | ||
2470 | if (ok) | |
aa0a709a SC |
2471 | printf ("%s ", p->name); |
2472 | else | |
e779a58c | 2473 | { |
f7b839f7 | 2474 | int l = strlen (p->name); |
aa0a709a | 2475 | while (l--) |
f7b839f7 DM |
2476 | putchar ('-'); |
2477 | putchar (' '); | |
e779a58c | 2478 | } |
e779a58c | 2479 | } |
f7b839f7 | 2480 | putchar ('\n'); |
e779a58c | 2481 | } |
de04bceb | 2482 | unlink (dummy_name); |
7f924d55 | 2483 | free (dummy_name); |
9872a49c | 2484 | } |
aa0a709a | 2485 | |
f7b839f7 DM |
2486 | /* Print tables of all the target-architecture combinations that |
2487 | BFD has been configured to support. */ | |
2488 | ||
aa0a709a | 2489 | static void |
f7b839f7 | 2490 | display_target_tables () |
aa0a709a | 2491 | { |
f7b839f7 | 2492 | int t, columns; |
abdcac0f | 2493 | extern bfd_target *bfd_target_vector[]; |
f7b839f7 | 2494 | char *colum; |
aa0a709a SC |
2495 | extern char *getenv (); |
2496 | ||
aa0a709a | 2497 | columns = 0; |
f7b839f7 DM |
2498 | colum = getenv ("COLUMNS"); |
2499 | if (colum != NULL) | |
aa0a709a | 2500 | columns = atoi (colum); |
f7b839f7 | 2501 | if (columns == 0) |
aa0a709a | 2502 | columns = 80; |
f7b839f7 | 2503 | |
105da05c ILT |
2504 | t = 0; |
2505 | while (bfd_target_vector[t] != NULL) | |
aa0a709a | 2506 | { |
f7b839f7 DM |
2507 | int oldt = t, wid; |
2508 | ||
105da05c ILT |
2509 | wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1; |
2510 | ++t; | |
2511 | while (wid < columns && bfd_target_vector[t] != NULL) | |
2512 | { | |
2513 | int newwid; | |
2514 | ||
2515 | newwid = wid + strlen (bfd_target_vector[t]->name) + 1; | |
2516 | if (newwid >= columns) | |
2517 | break; | |
2518 | wid = newwid; | |
2519 | ++t; | |
2520 | } | |
f7b839f7 | 2521 | display_info_table (oldt, t); |
aa0a709a SC |
2522 | } |
2523 | } | |
2524 | ||
f7b839f7 DM |
2525 | static void |
2526 | display_info () | |
2527 | { | |
2528 | printf ("BFD header file version %s\n", BFD_VERSION); | |
2529 | display_target_list (); | |
2530 | display_target_tables (); | |
2531 | } | |
2532 | ||
2fa0b342 DHW |
2533 | int |
2534 | main (argc, argv) | |
2535 | int argc; | |
2536 | char **argv; | |
2537 | { | |
2538 | int c; | |
2fa0b342 DHW |
2539 | char *target = default_target; |
2540 | boolean seenflag = false; | |
2fa0b342 DHW |
2541 | |
2542 | program_name = *argv; | |
8f197c94 ILT |
2543 | xmalloc_set_program_name (program_name); |
2544 | ||
be1d162b ILT |
2545 | START_PROGRESS (program_name, 0); |
2546 | ||
8f197c94 | 2547 | bfd_init (); |
5c59269f | 2548 | set_default_bfd_target (); |
2fa0b342 | 2549 | |
9793039f | 2550 | while ((c = getopt_long (argc, argv, "pib:m:VCdDlfahrRtTxsSj:wE:", |
18f39dfa | 2551 | long_options, (int *) 0)) |
aa0a709a SC |
2552 | != EOF) |
2553 | { | |
aa21a2a9 ILT |
2554 | if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS) |
2555 | seenflag = true; | |
aa0a709a SC |
2556 | switch (c) |
2557 | { | |
b3a2b497 ILT |
2558 | case 0: |
2559 | break; /* we've been given a long option */ | |
aa0a709a SC |
2560 | case 'm': |
2561 | machine = optarg; | |
2562 | break; | |
2563 | case 'j': | |
2564 | only = optarg; | |
2565 | break; | |
2566 | case 'l': | |
2567 | with_line_numbers = 1; | |
2568 | break; | |
2569 | case 'b': | |
2570 | target = optarg; | |
2571 | break; | |
2572 | case 'f': | |
2573 | dump_file_header = true; | |
2574 | break; | |
2575 | case 'i': | |
e1ec9f07 | 2576 | formats_info = true; |
aa0a709a | 2577 | break; |
a65619c8 SC |
2578 | case 'p': |
2579 | dump_private_headers = 1; | |
2580 | break; | |
aa0a709a | 2581 | case 'x': |
a65619c8 | 2582 | dump_private_headers = 1; |
aa0a709a SC |
2583 | dump_symtab = 1; |
2584 | dump_reloc_info = 1; | |
2585 | dump_file_header = true; | |
2586 | dump_ar_hdrs = 1; | |
2587 | dump_section_headers = 1; | |
2588 | break; | |
aa0a709a SC |
2589 | case 't': |
2590 | dump_symtab = 1; | |
2591 | break; | |
de3b08ac ILT |
2592 | case 'T': |
2593 | dump_dynamic_symtab = 1; | |
2594 | break; | |
9793039f ILT |
2595 | case 'C': |
2596 | do_demangle = 1; | |
2597 | break; | |
aa0a709a SC |
2598 | case 'd': |
2599 | disassemble = true; | |
2600 | break; | |
d5464baa ILT |
2601 | case 'D': |
2602 | disassemble = disassemble_all = true; | |
2603 | break; | |
be1d162b ILT |
2604 | case 'S': |
2605 | disassemble = true; | |
2606 | with_source_code = true; | |
2607 | break; | |
aa0a709a SC |
2608 | case 's': |
2609 | dump_section_contents = 1; | |
2610 | break; | |
2611 | case 'r': | |
2612 | dump_reloc_info = 1; | |
2613 | break; | |
de3b08ac ILT |
2614 | case 'R': |
2615 | dump_dynamic_reloc_info = 1; | |
2616 | break; | |
aa0a709a SC |
2617 | case 'a': |
2618 | dump_ar_hdrs = 1; | |
2619 | break; | |
2620 | case 'h': | |
2621 | dump_section_headers = 1; | |
2622 | break; | |
b3a2b497 ILT |
2623 | case 'H': |
2624 | usage (stdout, 0); | |
249c6fc0 RS |
2625 | case 'V': |
2626 | show_version = 1; | |
2627 | break; | |
13e4db2e SC |
2628 | case 'w': |
2629 | wide_output = 1; | |
2630 | break; | |
5c59269f ILT |
2631 | case OPTION_ADJUST_VMA: |
2632 | adjust_section_vma = parse_vma (optarg, "--adjust-vma"); | |
2633 | break; | |
aa21a2a9 ILT |
2634 | case OPTION_START_ADDRESS: |
2635 | start_address = parse_vma (optarg, "--start-address"); | |
2636 | break; | |
2637 | case OPTION_STOP_ADDRESS: | |
2638 | stop_address = parse_vma (optarg, "--stop-address"); | |
2639 | break; | |
18f39dfa SG |
2640 | case 'E': |
2641 | if (strcmp (optarg, "B") == 0) | |
2642 | endian = BFD_ENDIAN_BIG; | |
2643 | else if (strcmp (optarg, "L") == 0) | |
2644 | endian = BFD_ENDIAN_LITTLE; | |
2645 | else | |
2646 | { | |
2647 | fprintf (stderr, "%s: unrecognized -E option\n", program_name); | |
2648 | usage (stderr, 1); | |
2649 | } | |
2650 | break; | |
2651 | case OPTION_ENDIAN: | |
2652 | if (strncmp (optarg, "big", strlen (optarg)) == 0) | |
2653 | endian = BFD_ENDIAN_BIG; | |
2654 | else if (strncmp (optarg, "little", strlen (optarg)) == 0) | |
2655 | endian = BFD_ENDIAN_LITTLE; | |
2656 | else | |
2657 | { | |
2658 | fprintf (stderr, "%s: unrecognized --endian type `%s'\n", | |
2659 | program_name, optarg); | |
2660 | usage (stderr, 1); | |
2661 | } | |
2662 | break; | |
aa0a709a | 2663 | default: |
b3a2b497 | 2664 | usage (stderr, 1); |
aa0a709a | 2665 | } |
2fa0b342 | 2666 | } |
2fa0b342 | 2667 | |
249c6fc0 | 2668 | if (show_version) |
7f924d55 | 2669 | print_version ("objdump"); |
249c6fc0 | 2670 | |
2fa0b342 | 2671 | if (seenflag == false) |
b3a2b497 | 2672 | usage (stderr, 1); |
2fa0b342 | 2673 | |
e1ec9f07 | 2674 | if (formats_info) |
aa0a709a SC |
2675 | { |
2676 | display_info (); | |
2677 | } | |
2678 | else | |
2679 | { | |
2680 | if (optind == argc) | |
2681 | display_file ("a.out", target); | |
2682 | else | |
2683 | for (; optind < argc;) | |
2684 | display_file (argv[optind++], target); | |
2685 | } | |
be1d162b ILT |
2686 | |
2687 | END_PROGRESS (program_name); | |
2688 | ||
2fa0b342 DHW |
2689 | return 0; |
2690 | } |