1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 Objdump displays information about one or more object files, either on
25 their own, or inside libraries. It is commonly used as a disassembler,
26 but it can also display information about file headers, symbol tables,
27 relocations, debugging directives and more.
29 The flow of execution is as follows:
31 1. Command line arguments are checked for control switches and the
32 information to be displayed is selected.
34 2. Any remaining arguments are assumed to be object files, and they are
35 processed in order by display_bfd(). If the file is an archive each
36 of its elements is processed in turn.
38 3. The file's target architecture and binary file format are determined
39 by bfd_check_format(). If they are recognised, then dump_bfd() is
42 4. dump_bfd() in turn calls separate functions to display the requested
43 item(s) of information(s). For example disassemble_data() is called if
44 a disassembly has been requested.
46 When disassembling the code loops through blocks of instructions bounded
47 by symbols, calling disassemble_bytes() on each block. The actual
48 disassembling is done by the libopcodes library, via a function pointer
49 supplied by the disassembler() function. */
58 #include "safe-ctype.h"
60 #include "libiberty.h"
65 /* Internal headers for the ELF .stab-dump code - sorry. */
66 #define BYTES_IN_WORD 32
67 #include "aout/aout64.h"
69 #if !HAVE_DECL_FPRINTF
70 /* This is needed by init_disassemble_info(). */
71 extern int fprintf (FILE *, const char *, ...);
75 static int exit_status = 0;
77 static char *default_target = NULL; /* Default at runtime. */
79 /* The following variables are set based on arguments passed on the
81 static int show_version = 0; /* Show the version number. */
82 static int dump_section_contents; /* -s */
83 static int dump_section_headers; /* -h */
84 static bfd_boolean dump_file_header; /* -f */
85 static int dump_symtab; /* -t */
86 static int dump_dynamic_symtab; /* -T */
87 static int dump_reloc_info; /* -r */
88 static int dump_dynamic_reloc_info; /* -R */
89 static int dump_ar_hdrs; /* -a */
90 static int dump_private_headers; /* -p */
91 static int prefix_addresses; /* --prefix-addresses */
92 static int with_line_numbers; /* -l */
93 static bfd_boolean with_source_code; /* -S */
94 static int show_raw_insn; /* --show-raw-insn */
95 static int dump_dwarf_section_info; /* --dwarf */
96 static int dump_stab_section_info; /* --stabs */
97 static int do_demangle; /* -C, --demangle */
98 static bfd_boolean disassemble; /* -d */
99 static bfd_boolean disassemble_all; /* -D */
100 static int disassemble_zeroes; /* --disassemble-zeroes */
101 static bfd_boolean formats_info; /* -i */
102 static int wide_output; /* -w */
103 static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
104 static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
105 static int dump_debugging; /* --debugging */
106 static int dump_debugging_tags; /* --debugging-tags */
107 static int dump_special_syms = 0; /* --special-syms */
108 static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
109 static int file_start_context = 0; /* --file-start-context */
111 /* Pointer to an array of section names provided by
112 one or more "-j secname" command line options. */
114 /* The total number of slots in the only[] array. */
115 static size_t only_size = 0;
116 /* The number of occupied slots in the only[] array. */
117 static size_t only_used = 0;
119 /* Variables for handling include file path table. */
120 static const char **include_paths;
121 static int include_path_count;
123 /* Extra info to pass to the section disassembler and address printing
125 struct objdump_disasm_info
129 bfd_boolean require_sec;
130 arelent ** dynrelbuf;
132 disassembler_ftype disassemble_fn;
133 #ifdef DISASSEMBLER_NEEDS_RELOCS
138 /* Architecture to disassemble for, or default if NULL. */
139 static char *machine = NULL;
141 /* Target specific options to the disassembler. */
142 static char *disassembler_options = NULL;
144 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
145 static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
147 /* The symbol table. */
148 static asymbol **syms;
150 /* Number of symbols in `syms'. */
151 static long symcount = 0;
153 /* The sorted symbol table. */
154 static asymbol **sorted_syms;
156 /* Number of symbols in `sorted_syms'. */
157 static long sorted_symcount = 0;
159 /* The dynamic symbol table. */
160 static asymbol **dynsyms;
162 /* The synthetic symbol table. */
163 static asymbol *synthsyms;
164 static long synthcount = 0;
166 /* Number of symbols in `dynsyms'. */
167 static long dynsymcount = 0;
169 static bfd_byte *stabs;
170 static bfd_size_type stab_size;
173 static bfd_size_type stabstr_size;
176 usage (FILE *stream, int status)
178 fprintf (stream, _("Usage: %s <option(s)> <file(s)>\n"), program_name);
179 fprintf (stream, _(" Display information from object <file(s)>.\n"));
180 fprintf (stream, _(" At least one of the following switches must be given:\n"));
181 fprintf (stream, _("\
182 -a, --archive-headers Display archive header information\n\
183 -f, --file-headers Display the contents of the overall file header\n\
184 -p, --private-headers Display object format specific file header contents\n\
185 -h, --[section-]headers Display the contents of the section headers\n\
186 -x, --all-headers Display the contents of all headers\n\
187 -d, --disassemble Display assembler contents of executable sections\n\
188 -D, --disassemble-all Display assembler contents of all sections\n\
189 -S, --source Intermix source code with disassembly\n\
190 -s, --full-contents Display the full contents of all sections requested\n\
191 -g, --debugging Display debug information in object file\n\
192 -e, --debugging-tags Display debug information using ctags style\n\
193 -G, --stabs Display (in raw form) any STABS info in the file\n\
194 -W, --dwarf Display DWARF info in the file\n\
195 -t, --syms Display the contents of the symbol table(s)\n\
196 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
197 -r, --reloc Display the relocation entries in the file\n\
198 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
199 -v, --version Display this program's version number\n\
200 -i, --info List object formats and architectures supported\n\
201 -H, --help Display this information\n\
205 fprintf (stream, _("\n The following switches are optional:\n"));
206 fprintf (stream, _("\
207 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
208 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
209 -j, --section=NAME Only display information for section NAME\n\
210 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
211 -EB --endian=big Assume big endian format when disassembling\n\
212 -EL --endian=little Assume little endian format when disassembling\n\
213 --file-start-context Include context from start of file (with -S)\n\
214 -I, --include=DIR Add DIR to search list for source files\n\
215 -l, --line-numbers Include line numbers and filenames in output\n\
216 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
217 The STYLE, if specified, can be `auto', `gnu',\n\
218 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
220 -w, --wide Format output for more than 80 columns\n\
221 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
222 --start-address=ADDR Only process data whose address is >= ADDR\n\
223 --stop-address=ADDR Only process data whose address is <= ADDR\n\
224 --prefix-addresses Print complete address alongside disassembly\n\
225 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
226 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
227 --special-syms Include special symbols in symbol dumps\n\
229 list_supported_targets (program_name, stream);
230 list_supported_architectures (program_name, stream);
232 disassembler_usage (stream);
235 fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
239 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
243 OPTION_START_ADDRESS,
248 static struct option long_options[]=
250 {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
251 {"all-headers", no_argument, NULL, 'x'},
252 {"private-headers", no_argument, NULL, 'p'},
253 {"architecture", required_argument, NULL, 'm'},
254 {"archive-headers", no_argument, NULL, 'a'},
255 {"debugging", no_argument, NULL, 'g'},
256 {"debugging-tags", no_argument, NULL, 'e'},
257 {"demangle", optional_argument, NULL, 'C'},
258 {"disassemble", no_argument, NULL, 'd'},
259 {"disassemble-all", no_argument, NULL, 'D'},
260 {"disassembler-options", required_argument, NULL, 'M'},
261 {"disassemble-zeroes", no_argument, NULL, 'z'},
262 {"dynamic-reloc", no_argument, NULL, 'R'},
263 {"dynamic-syms", no_argument, NULL, 'T'},
264 {"endian", required_argument, NULL, OPTION_ENDIAN},
265 {"file-headers", no_argument, NULL, 'f'},
266 {"file-start-context", no_argument, &file_start_context, 1},
267 {"full-contents", no_argument, NULL, 's'},
268 {"headers", no_argument, NULL, 'h'},
269 {"help", no_argument, NULL, 'H'},
270 {"info", no_argument, NULL, 'i'},
271 {"line-numbers", no_argument, NULL, 'l'},
272 {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
273 {"prefix-addresses", no_argument, &prefix_addresses, 1},
274 {"reloc", no_argument, NULL, 'r'},
275 {"section", required_argument, NULL, 'j'},
276 {"section-headers", no_argument, NULL, 'h'},
277 {"show-raw-insn", no_argument, &show_raw_insn, 1},
278 {"source", no_argument, NULL, 'S'},
279 {"special-syms", no_argument, &dump_special_syms, 1},
280 {"include", required_argument, NULL, 'I'},
281 {"dwarf", no_argument, NULL, 'W'},
282 {"stabs", no_argument, NULL, 'G'},
283 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
284 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
285 {"syms", no_argument, NULL, 't'},
286 {"target", required_argument, NULL, 'b'},
287 {"version", no_argument, NULL, 'V'},
288 {"wide", no_argument, NULL, 'w'},
289 {0, no_argument, 0, 0}
293 nonfatal (const char *msg)
300 dump_section_header (bfd *abfd, asection *section,
301 void *ignored ATTRIBUTE_UNUSED)
304 unsigned int opb = bfd_octets_per_byte (abfd);
306 /* Ignore linker created section. See elfNN_ia64_object_p in
308 if (section->flags & SEC_LINKER_CREATED)
311 printf ("%3d %-13s %08lx ", section->index,
312 bfd_get_section_name (abfd, section),
313 (unsigned long) bfd_section_size (abfd, section) / opb);
314 bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section));
316 bfd_printf_vma (abfd, section->lma);
317 printf (" %08lx 2**%u", (unsigned long) section->filepos,
318 bfd_get_section_alignment (abfd, section));
324 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
326 PF (SEC_HAS_CONTENTS, "CONTENTS");
327 PF (SEC_ALLOC, "ALLOC");
328 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
329 PF (SEC_LOAD, "LOAD");
330 PF (SEC_RELOC, "RELOC");
331 PF (SEC_READONLY, "READONLY");
332 PF (SEC_CODE, "CODE");
333 PF (SEC_DATA, "DATA");
335 PF (SEC_DEBUGGING, "DEBUGGING");
336 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
337 PF (SEC_EXCLUDE, "EXCLUDE");
338 PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
339 if (bfd_get_arch (abfd) == bfd_arch_tic54x)
341 PF (SEC_TIC54X_BLOCK, "BLOCK");
342 PF (SEC_TIC54X_CLINK, "CLINK");
344 PF (SEC_SMALL_DATA, "SMALL_DATA");
345 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
346 PF (SEC_COFF_SHARED, "SHARED");
347 PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
348 PF (SEC_GROUP, "GROUP");
350 if ((section->flags & SEC_LINK_ONCE) != 0)
353 struct coff_comdat_info *comdat;
355 switch (section->flags & SEC_LINK_DUPLICATES)
359 case SEC_LINK_DUPLICATES_DISCARD:
360 ls = "LINK_ONCE_DISCARD";
362 case SEC_LINK_DUPLICATES_ONE_ONLY:
363 ls = "LINK_ONCE_ONE_ONLY";
365 case SEC_LINK_DUPLICATES_SAME_SIZE:
366 ls = "LINK_ONCE_SAME_SIZE";
368 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
369 ls = "LINK_ONCE_SAME_CONTENTS";
372 printf ("%s%s", comma, ls);
374 comdat = bfd_coff_get_comdat_section (abfd, section);
376 printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol);
386 dump_headers (bfd *abfd)
388 printf (_("Sections:\n"));
391 printf (_("Idx Name Size VMA LMA File off Algn"));
393 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
394 if (bfd_get_arch_size (abfd) == 32)
395 printf (_("Idx Name Size VMA LMA File off Algn"));
397 printf (_("Idx Name Size VMA LMA File off Algn"));
401 printf (_(" Flags"));
402 if (abfd->flags & HAS_LOAD_PAGE)
406 bfd_map_over_sections (abfd, dump_section_header, NULL);
410 slurp_symtab (bfd *abfd)
415 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
421 storage = bfd_get_symtab_upper_bound (abfd);
423 bfd_fatal (bfd_get_filename (abfd));
425 sy = xmalloc (storage);
427 symcount = bfd_canonicalize_symtab (abfd, sy);
429 bfd_fatal (bfd_get_filename (abfd));
433 /* Read in the dynamic symbols. */
436 slurp_dynamic_symtab (bfd *abfd)
441 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
444 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
446 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
451 bfd_fatal (bfd_get_filename (abfd));
454 sy = xmalloc (storage);
456 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
458 bfd_fatal (bfd_get_filename (abfd));
462 /* Filter out (in place) symbols that are useless for disassembly.
463 COUNT is the number of elements in SYMBOLS.
464 Return the number of useful symbols. */
467 remove_useless_symbols (asymbol **symbols, long count)
469 asymbol **in_ptr = symbols, **out_ptr = symbols;
473 asymbol *sym = *in_ptr++;
475 if (sym->name == NULL || sym->name[0] == '\0')
477 if (sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM))
479 if (bfd_is_und_section (sym->section)
480 || bfd_is_com_section (sym->section))
485 return out_ptr - symbols;
488 /* Sort symbols into value order. */
491 compare_symbols (const void *ap, const void *bp)
493 const asymbol *a = * (const asymbol **) ap;
494 const asymbol *b = * (const asymbol **) bp;
504 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
506 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
509 if (a->section > b->section)
511 else if (a->section < b->section)
514 an = bfd_asymbol_name (a);
515 bn = bfd_asymbol_name (b);
519 /* The symbols gnu_compiled and gcc2_compiled convey no real
520 information, so put them after other symbols with the same value. */
521 af = (strstr (an, "gnu_compiled") != NULL
522 || strstr (an, "gcc2_compiled") != NULL);
523 bf = (strstr (bn, "gnu_compiled") != NULL
524 || strstr (bn, "gcc2_compiled") != NULL);
531 /* We use a heuristic for the file name, to try to sort it after
532 more useful symbols. It may not work on non Unix systems, but it
533 doesn't really matter; the only difference is precisely which
534 symbol names get printed. */
536 #define file_symbol(s, sn, snl) \
537 (((s)->flags & BSF_FILE) != 0 \
538 || ((sn)[(snl) - 2] == '.' \
539 && ((sn)[(snl) - 1] == 'o' \
540 || (sn)[(snl) - 1] == 'a')))
542 af = file_symbol (a, an, anl);
543 bf = file_symbol (b, bn, bnl);
550 /* Try to sort global symbols before local symbols before function
551 symbols before debugging symbols. */
556 if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
558 if ((aflags & BSF_DEBUGGING) != 0)
563 if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
565 if ((aflags & BSF_FUNCTION) != 0)
570 if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
572 if ((aflags & BSF_LOCAL) != 0)
577 if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
579 if ((aflags & BSF_GLOBAL) != 0)
585 /* Symbols that start with '.' might be section names, so sort them
586 after symbols that don't start with '.'. */
587 if (an[0] == '.' && bn[0] != '.')
589 if (an[0] != '.' && bn[0] == '.')
592 /* Finally, if we can't distinguish them in any other way, try to
593 get consistent results by sorting the symbols by name. */
594 return strcmp (an, bn);
597 /* Sort relocs into address order. */
600 compare_relocs (const void *ap, const void *bp)
602 const arelent *a = * (const arelent **) ap;
603 const arelent *b = * (const arelent **) bp;
605 if (a->address > b->address)
607 else if (a->address < b->address)
610 /* So that associated relocations tied to the same address show up
611 in the correct order, we don't do any further sorting. */
620 /* Print an address (VMA) to the output stream in INFO.
621 If SKIP_ZEROES is TRUE, omit leading zeroes. */
624 objdump_print_value (bfd_vma vma, struct disassemble_info *info,
625 bfd_boolean skip_zeroes)
629 struct objdump_disasm_info *aux;
631 aux = (struct objdump_disasm_info *) info->application_data;
632 bfd_sprintf_vma (aux->abfd, buf, vma);
637 for (p = buf; *p == '0'; ++p)
642 (*info->fprintf_func) (info->stream, "%s", p);
645 /* Print the name of a symbol. */
648 objdump_print_symname (bfd *abfd, struct disassemble_info *info,
655 name = bfd_asymbol_name (sym);
656 if (do_demangle && name[0] != '\0')
658 /* Demangle the name. */
659 alloc = demangle (abfd, name);
664 (*info->fprintf_func) (info->stream, "%s", name);
672 /* Locate a symbol given a bfd and a section (from INFO->application_data),
673 and a VMA. If INFO->application_data->require_sec is TRUE, then always
674 require the symbol to be in the section. Returns NULL if there is no
675 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
676 of the symbol in sorted_syms. */
679 find_symbol_for_address (bfd_vma vma,
680 struct disassemble_info *info,
683 /* @@ Would it speed things up to cache the last two symbols returned,
684 and maybe their address ranges? For many processors, only one memory
685 operand can be present at a time, so the 2-entry cache wouldn't be
686 constantly churned by code doing heavy memory accesses. */
688 /* Indices in `sorted_syms'. */
690 long max = sorted_symcount;
692 struct objdump_disasm_info *aux;
697 if (sorted_symcount < 1)
700 aux = (struct objdump_disasm_info *) info->application_data;
703 opb = bfd_octets_per_byte (abfd);
705 /* Perform a binary search looking for the closest symbol to the
706 required value. We are searching the range (min, max]. */
707 while (min + 1 < max)
711 thisplace = (max + min) / 2;
712 sym = sorted_syms[thisplace];
714 if (bfd_asymbol_value (sym) > vma)
716 else if (bfd_asymbol_value (sym) < vma)
725 /* The symbol we want is now in min, the low end of the range we
726 were searching. If there are several symbols with the same
727 value, we want the first one. */
730 && (bfd_asymbol_value (sorted_syms[thisplace])
731 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
734 /* If the file is relocatable, and the symbol could be from this
735 section, prefer a symbol from this section over symbols from
736 others, even if the other symbol's value might be closer.
738 Note that this may be wrong for some symbol references if the
739 sections have overlapping memory ranges, but in that case there's
740 no way to tell what's desired without looking at the relocation
742 if (sorted_syms[thisplace]->section != sec
744 || ((abfd->flags & HAS_RELOC) != 0
745 && vma >= bfd_get_section_vma (abfd, sec)
746 && vma < (bfd_get_section_vma (abfd, sec)
747 + bfd_section_size (abfd, sec) / opb))))
751 for (i = thisplace + 1; i < sorted_symcount; i++)
753 if (bfd_asymbol_value (sorted_syms[i])
754 != bfd_asymbol_value (sorted_syms[thisplace]))
762 if (sorted_syms[i]->section == sec
764 || sorted_syms[i - 1]->section != sec
765 || (bfd_asymbol_value (sorted_syms[i])
766 != bfd_asymbol_value (sorted_syms[i - 1]))))
773 if (sorted_syms[thisplace]->section != sec)
775 /* We didn't find a good symbol with a smaller value.
776 Look for one with a larger value. */
777 for (i = thisplace + 1; i < sorted_symcount; i++)
779 if (sorted_syms[i]->section == sec)
787 if (sorted_syms[thisplace]->section != sec
789 || ((abfd->flags & HAS_RELOC) != 0
790 && vma >= bfd_get_section_vma (abfd, sec)
791 && vma < (bfd_get_section_vma (abfd, sec)
792 + bfd_section_size (abfd, sec)))))
793 /* There is no suitable symbol. */
797 /* Give the target a chance to reject the symbol. */
798 while (! info->symbol_is_valid (sorted_syms [thisplace], info))
801 if (thisplace >= sorted_symcount
802 || bfd_asymbol_value (sorted_syms [thisplace]) > vma)
809 return sorted_syms[thisplace];
812 /* Print an address and the offset to the nearest symbol. */
815 objdump_print_addr_with_sym (bfd *abfd, asection *sec, asymbol *sym,
816 bfd_vma vma, struct disassemble_info *info,
817 bfd_boolean skip_zeroes)
819 objdump_print_value (vma, info, skip_zeroes);
825 (*info->fprintf_func) (info->stream, " <%s",
826 bfd_get_section_name (abfd, sec));
827 secaddr = bfd_get_section_vma (abfd, sec);
830 (*info->fprintf_func) (info->stream, "-0x");
831 objdump_print_value (secaddr - vma, info, TRUE);
833 else if (vma > secaddr)
835 (*info->fprintf_func) (info->stream, "+0x");
836 objdump_print_value (vma - secaddr, info, TRUE);
838 (*info->fprintf_func) (info->stream, ">");
842 (*info->fprintf_func) (info->stream, " <");
843 objdump_print_symname (abfd, info, sym);
844 if (bfd_asymbol_value (sym) > vma)
846 (*info->fprintf_func) (info->stream, "-0x");
847 objdump_print_value (bfd_asymbol_value (sym) - vma, info, TRUE);
849 else if (vma > bfd_asymbol_value (sym))
851 (*info->fprintf_func) (info->stream, "+0x");
852 objdump_print_value (vma - bfd_asymbol_value (sym), info, TRUE);
854 (*info->fprintf_func) (info->stream, ">");
858 /* Print an address (VMA), symbolically if possible.
859 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
862 objdump_print_addr (bfd_vma vma,
863 struct disassemble_info *info,
864 bfd_boolean skip_zeroes)
866 struct objdump_disasm_info *aux;
867 asymbol *sym = NULL; /* Initialize to avoid compiler warning. */
868 #ifdef DISASSEMBLER_NEEDS_RELOCS
869 bfd_boolean skip_find = FALSE;
872 if (sorted_symcount < 1)
874 (*info->fprintf_func) (info->stream, "0x");
875 objdump_print_value (vma, info, skip_zeroes);
879 aux = (struct objdump_disasm_info *) info->application_data;
881 #ifdef DISASSEMBLER_NEEDS_RELOCS
882 if (aux->reloc != NULL
883 && aux->reloc->sym_ptr_ptr != NULL
884 && * aux->reloc->sym_ptr_ptr != NULL)
886 sym = * aux->reloc->sym_ptr_ptr;
888 /* Adjust the vma to the reloc. */
889 vma += bfd_asymbol_value (sym);
891 if (bfd_is_und_section (bfd_get_section (sym)))
897 sym = find_symbol_for_address (vma, info, NULL);
899 objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
903 /* Print VMA to INFO. This function is passed to the disassembler
907 objdump_print_address (bfd_vma vma, struct disassemble_info *info)
909 objdump_print_addr (vma, info, ! prefix_addresses);
912 /* Determine of the given address has a symbol associated with it. */
915 objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * info)
919 sym = find_symbol_for_address (vma, info, NULL);
921 return (sym != NULL && (bfd_asymbol_value (sym) == vma));
924 /* Hold the last function name and the last line number we displayed
927 static char *prev_functionname;
928 static unsigned int prev_line;
930 /* We keep a list of all files that we have seen when doing a
931 disassembly with source, so that we know how much of the file to
932 display. This can be important for inlined functions. */
934 struct print_file_list
936 struct print_file_list *next;
937 const char *filename;
943 static struct print_file_list *print_files;
945 /* The number of preceding context lines to show when we start
946 displaying a file for the first time. */
948 #define SHOW_PRECEDING_CONTEXT_LINES (5)
950 /* Tries to open MODNAME, and if successful adds a node to print_files
951 linked list and returns that node. Returns NULL on failure. */
953 static struct print_file_list *
954 try_print_file_open (const char *origname, const char *modname)
956 struct print_file_list *p;
959 f = fopen (modname, "r");
963 if (print_files != NULL && print_files->f != NULL)
965 fclose (print_files->f);
966 print_files->f = NULL;
969 p = xmalloc (sizeof (struct print_file_list));
970 p->filename = origname;
971 p->modname = modname;
974 p->next = print_files;
979 /* If the the source file, as described in the symtab, is not found
980 try to locate it in one of the paths specified with -I
981 If found, add location to print_files linked list. */
983 static struct print_file_list *
984 update_source_path (const char *filename)
986 struct print_file_list *p;
990 if (filename == NULL)
993 p = try_print_file_open (filename, filename);
997 if (include_path_count == 0)
1000 /* Get the name of the file. */
1001 fname = strrchr (filename, '/');
1002 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
1004 /* We could have a mixed forward/back slash case. */
1005 char *backslash = strrchr (filename, '\\');
1006 if (fname == NULL || (backslash != NULL && backslash > fname))
1008 if (fname == NULL && filename[0] != '\0' && filename[1] == ':')
1009 fname = filename + 1;
1017 /* If file exists under a new path, we need to add it to the list
1018 so that show_line knows about it. */
1019 for (i = 0; i < include_path_count; i++)
1021 char *modname = concat (include_paths[i], "/", fname, (const char *) 0);
1023 p = try_print_file_open (filename, modname);
1033 /* Skip ahead to a given line in a file, optionally printing each
1037 skip_to_line (struct print_file_list *p, unsigned int line,
1040 while (p->line < line)
1044 if (fgets (buf, sizeof buf, p->f) == NULL)
1054 if (strchr (buf, '\n') != NULL)
1059 /* Show the line number, or the source line, in a disassembly
1063 show_line (bfd *abfd, asection *section, bfd_vma addr_offset)
1065 const char *filename;
1066 const char *functionname;
1069 if (! with_line_numbers && ! with_source_code)
1072 if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename,
1073 &functionname, &line))
1076 if (filename != NULL && *filename == '\0')
1078 if (functionname != NULL && *functionname == '\0')
1079 functionname = NULL;
1081 if (with_line_numbers)
1083 if (functionname != NULL
1084 && (prev_functionname == NULL
1085 || strcmp (functionname, prev_functionname) != 0))
1086 printf ("%s():\n", functionname);
1087 if (line > 0 && line != prev_line)
1088 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
1091 if (with_source_code
1095 struct print_file_list **pp, *p;
1097 for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
1098 if (strcmp ((*pp)->filename, filename) == 0)
1104 if (p != print_files)
1108 /* We have reencountered a file name which we saw
1109 earlier. This implies that either we are dumping out
1110 code from an included file, or the same file was
1111 linked in more than once. There are two common cases
1112 of an included file: inline functions in a header
1113 file, and a bison or flex skeleton file. In the
1114 former case we want to just start printing (but we
1115 back up a few lines to give context); in the latter
1116 case we want to continue from where we left off. I
1117 can't think of a good way to distinguish the cases,
1118 so I used a heuristic based on the file name. */
1119 if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0)
1123 l = line - SHOW_PRECEDING_CONTEXT_LINES;
1130 p->f = fopen (p->modname, "r");
1134 skip_to_line (p, l, FALSE);
1136 if (print_files->f != NULL)
1138 fclose (print_files->f);
1139 print_files->f = NULL;
1145 skip_to_line (p, line, TRUE);
1147 p->next = print_files;
1153 p = update_source_path (filename);
1159 if (file_start_context)
1162 l = line - SHOW_PRECEDING_CONTEXT_LINES;
1165 skip_to_line (p, l, FALSE);
1167 skip_to_line (p, line, TRUE);
1172 if (functionname != NULL
1173 && (prev_functionname == NULL
1174 || strcmp (functionname, prev_functionname) != 0))
1176 if (prev_functionname != NULL)
1177 free (prev_functionname);
1178 prev_functionname = xmalloc (strlen (functionname) + 1);
1179 strcpy (prev_functionname, functionname);
1182 if (line > 0 && line != prev_line)
1186 /* Pseudo FILE object for strings. */
1194 /* sprintf to a "stream". */
1196 static int ATTRIBUTE_PRINTF_2
1197 objdump_sprintf (SFILE *f, const char *format, ...)
1204 size_t space = f->alloc - f->pos;
1206 va_start (args, format);
1207 n = vsnprintf (f->buffer + f->pos, space, format, args);
1213 f->alloc = (f->alloc + n) * 2;
1214 f->buffer = xrealloc (f->buffer, f->alloc);
1221 /* Returns TRUE if the specified section should be dumped. */
1224 process_section_p (asection * section)
1231 for (i = 0; i < only_used; i++)
1232 if (strcmp (only [i], section->name) == 0)
1239 /* The number of zeroes we want to see before we start skipping them.
1240 The number is arbitrarily chosen. */
1242 #define DEFAULT_SKIP_ZEROES 8
1244 /* The number of zeroes to skip at the end of a section. If the
1245 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1246 SKIP_ZEROES, they will be disassembled. If there are fewer than
1247 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1248 attempt to avoid disassembling zeroes inserted by section
1251 #define DEFAULT_SKIP_ZEROES_AT_END 3
1253 /* Disassemble some data in memory between given values. */
1256 disassemble_bytes (struct disassemble_info * info,
1257 disassembler_ftype disassemble_fn,
1260 bfd_vma start_offset,
1261 bfd_vma stop_offset,
1264 arelent ** relppend)
1266 struct objdump_disasm_info *aux;
1268 int octets_per_line;
1269 bfd_boolean done_dot;
1270 int skip_addr_chars;
1271 bfd_vma addr_offset;
1272 unsigned int opb = info->octets_per_byte;
1273 unsigned int skip_zeroes = info->skip_zeroes;
1274 unsigned int skip_zeroes_at_end = info->skip_zeroes_at_end;
1278 aux = (struct objdump_disasm_info *) info->application_data;
1282 sfile.buffer = xmalloc (sfile.alloc);
1286 octets_per_line = 4;
1288 octets_per_line = 16;
1290 /* Figure out how many characters to skip at the start of an
1291 address, to make the disassembly look nicer. We discard leading
1292 zeroes in chunks of 4, ensuring that there is always a leading
1294 skip_addr_chars = 0;
1295 if (! prefix_addresses)
1303 + bfd_section_size (section->owner, section) / opb));
1305 while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
1308 skip_addr_chars += 4;
1313 info->insn_info_valid = 0;
1316 addr_offset = start_offset;
1317 while (addr_offset < stop_offset)
1320 bfd_boolean need_nl = FALSE;
1321 #ifdef DISASSEMBLER_NEEDS_RELOCS
1322 int previous_octets;
1324 /* Remember the length of the previous instruction. */
1325 previous_octets = octets;
1329 /* If we see more than SKIP_ZEROES octets of zeroes, we just
1331 for (z = addr_offset * opb; z < stop_offset * opb; z++)
1334 if (! disassemble_zeroes
1335 && (info->insn_info_valid == 0
1336 || info->branch_delay_insns == 0)
1337 && (z - addr_offset * opb >= skip_zeroes
1338 || (z == stop_offset * opb &&
1339 z - addr_offset * opb < skip_zeroes_at_end)))
1343 /* If there are more nonzero octets to follow, we only skip
1344 zeroes in multiples of 4, to try to avoid running over
1345 the start of an instruction which happens to start with
1347 if (z != stop_offset * opb)
1348 z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
1350 octets = z - addr_offset * opb;
1360 if (with_line_numbers || with_source_code)
1361 show_line (aux->abfd, section, addr_offset);
1363 if (! prefix_addresses)
1367 bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
1368 for (s = buf + skip_addr_chars; *s == '0'; s++)
1372 printf ("%s:\t", buf + skip_addr_chars);
1376 aux->require_sec = TRUE;
1377 objdump_print_address (section->vma + addr_offset, info);
1378 aux->require_sec = FALSE;
1385 info->fprintf_func = (fprintf_ftype) objdump_sprintf;
1386 info->stream = &sfile;
1387 info->bytes_per_line = 0;
1388 info->bytes_per_chunk = 0;
1391 #ifdef DISASSEMBLER_NEEDS_RELOCS
1392 if (*relppp < relppend)
1394 bfd_signed_vma distance_to_rel;
1396 distance_to_rel = (**relppp)->address
1397 - (rel_offset + addr_offset);
1399 /* Check to see if the current reloc is associated with
1400 the instruction that we are about to disassemble. */
1401 if (distance_to_rel == 0
1402 /* FIXME: This is wrong. We are trying to catch
1403 relocs that are addressed part way through the
1404 current instruction, as might happen with a packed
1405 VLIW instruction. Unfortunately we do not know the
1406 length of the current instruction since we have not
1407 disassembled it yet. Instead we take a guess based
1408 upon the length of the previous instruction. The
1409 proper solution is to have a new target-specific
1410 disassembler function which just returns the length
1411 of an instruction at a given address without trying
1412 to display its disassembly. */
1413 || (distance_to_rel > 0
1414 && distance_to_rel < (bfd_signed_vma) (previous_octets/ opb)))
1416 info->flags = INSN_HAS_RELOC;
1417 aux->reloc = **relppp;
1423 octets = (*disassemble_fn) (section->vma + addr_offset, info);
1424 info->fprintf_func = (fprintf_ftype) fprintf;
1425 info->stream = stdout;
1426 if (info->bytes_per_line != 0)
1427 octets_per_line = info->bytes_per_line;
1431 printf ("%s\n", sfile.buffer);
1439 octets = octets_per_line;
1440 if (addr_offset + octets / opb > stop_offset)
1441 octets = (stop_offset - addr_offset) * opb;
1443 for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
1445 if (ISPRINT (data[j]))
1446 buf[j - addr_offset * opb] = data[j];
1448 buf[j - addr_offset * opb] = '.';
1450 buf[j - addr_offset * opb] = '\0';
1453 if (prefix_addresses
1455 : show_raw_insn >= 0)
1459 /* If ! prefix_addresses and ! wide_output, we print
1460 octets_per_line octets per line. */
1462 if (pb > octets_per_line && ! prefix_addresses && ! wide_output)
1463 pb = octets_per_line;
1465 if (info->bytes_per_chunk)
1466 bpc = info->bytes_per_chunk;
1470 for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
1474 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1476 for (k = bpc - 1; k >= 0; k--)
1477 printf ("%02x", (unsigned) data[j + k]);
1482 for (k = 0; k < bpc; k++)
1483 printf ("%02x", (unsigned) data[j + k]);
1488 for (; pb < octets_per_line; pb += bpc)
1492 for (k = 0; k < bpc; k++)
1497 /* Separate raw data from instruction by extra space. */
1507 printf ("%s", sfile.buffer);
1509 if (prefix_addresses
1511 : show_raw_insn >= 0)
1519 j = addr_offset * opb + pb;
1521 bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
1522 for (s = buf + skip_addr_chars; *s == '0'; s++)
1526 printf ("%s:\t", buf + skip_addr_chars);
1528 pb += octets_per_line;
1531 for (; j < addr_offset * opb + pb; j += bpc)
1535 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1537 for (k = bpc - 1; k >= 0; k--)
1538 printf ("%02x", (unsigned) data[j + k]);
1543 for (k = 0; k < bpc; k++)
1544 printf ("%02x", (unsigned) data[j + k]);
1557 while ((*relppp) < relppend
1558 && (**relppp)->address < rel_offset + addr_offset + octets / opb)
1560 if (dump_reloc_info || dump_dynamic_reloc_info)
1571 objdump_print_value (section->vma - rel_offset + q->address,
1574 if (q->howto == NULL)
1575 printf (": *unknown*\t");
1576 else if (q->howto->name)
1577 printf (": %s\t", q->howto->name);
1579 printf (": %d\t", q->howto->type);
1581 if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
1582 printf ("*unknown*");
1585 const char *sym_name;
1587 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
1588 if (sym_name != NULL && *sym_name != '\0')
1589 objdump_print_symname (aux->abfd, info, *q->sym_ptr_ptr);
1594 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
1595 sym_name = bfd_get_section_name (aux->abfd, sym_sec);
1596 if (sym_name == NULL || *sym_name == '\0')
1597 sym_name = "*unknown*";
1598 printf ("%s", sym_name);
1605 objdump_print_value (q->addend, info, TRUE);
1617 addr_offset += octets / opb;
1620 free (sfile.buffer);
1624 disassemble_section (bfd *abfd, asection *section, void *info)
1626 struct disassemble_info * pinfo = (struct disassemble_info *) info;
1627 struct objdump_disasm_info * paux;
1628 unsigned int opb = pinfo->octets_per_byte;
1629 bfd_byte * data = NULL;
1630 bfd_size_type datasize = 0;
1631 arelent ** rel_pp = NULL;
1632 arelent ** rel_ppstart = NULL;
1633 arelent ** rel_ppend;
1634 unsigned long stop_offset;
1635 asymbol * sym = NULL;
1639 unsigned long addr_offset;
1641 /* Sections that do not contain machine
1642 code are not normally disassembled. */
1643 if (! disassemble_all
1645 && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS))
1646 != (SEC_CODE | SEC_HAS_CONTENTS)))
1649 if (! process_section_p (section))
1652 datasize = bfd_get_section_size (section);
1656 /* Decide which set of relocs to use. Load them if necessary. */
1657 paux = (struct objdump_disasm_info *) pinfo->application_data;
1658 if (paux->dynrelbuf)
1660 rel_pp = paux->dynrelbuf;
1661 rel_count = paux->dynrelcount;
1662 /* Dynamic reloc addresses are absolute, non-dynamic are section
1663 relative. REL_OFFSET specifies the reloc address corresponding
1664 to the start of this section. */
1665 rel_offset = section->vma;
1673 if ((section->flags & SEC_RELOC) != 0
1674 #ifndef DISASSEMBLER_NEEDS_RELOCS
1681 relsize = bfd_get_reloc_upper_bound (abfd, section);
1683 bfd_fatal (bfd_get_filename (abfd));
1687 rel_ppstart = rel_pp = xmalloc (relsize);
1688 rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms);
1690 bfd_fatal (bfd_get_filename (abfd));
1692 /* Sort the relocs by address. */
1693 qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs);
1698 rel_ppend = rel_pp + rel_count;
1700 data = xmalloc (datasize);
1702 bfd_get_section_contents (abfd, section, data, 0, datasize);
1704 paux->sec = section;
1705 pinfo->buffer = data;
1706 pinfo->buffer_vma = section->vma;
1707 pinfo->buffer_length = datasize;
1708 pinfo->section = section;
1710 if (start_address == (bfd_vma) -1
1711 || start_address < pinfo->buffer_vma)
1714 addr_offset = start_address - pinfo->buffer_vma;
1716 if (stop_address == (bfd_vma) -1)
1717 stop_offset = datasize / opb;
1720 if (stop_address < pinfo->buffer_vma)
1723 stop_offset = stop_address - pinfo->buffer_vma;
1724 if (stop_offset > pinfo->buffer_length / opb)
1725 stop_offset = pinfo->buffer_length / opb;
1728 /* Skip over the relocs belonging to addresses below the
1730 while (rel_pp < rel_ppend
1731 && (*rel_pp)->address < rel_offset + addr_offset)
1734 printf (_("Disassembly of section %s:\n"), section->name);
1736 /* Find the nearest symbol forwards from our current position. */
1737 paux->require_sec = TRUE;
1738 sym = find_symbol_for_address (section->vma + addr_offset, info, &place);
1739 paux->require_sec = FALSE;
1741 /* Disassemble a block of instructions up to the address associated with
1742 the symbol we have just found. Then print the symbol and find the
1743 next symbol on. Repeat until we have disassembled the entire section
1744 or we have reached the end of the address range we are interested in. */
1745 while (addr_offset < stop_offset)
1749 unsigned long nextstop_offset;
1752 addr = section->vma + addr_offset;
1754 if (sym != NULL && bfd_asymbol_value (sym) <= addr)
1759 (x < sorted_symcount
1760 && (bfd_asymbol_value (sorted_syms[x]) <= addr));
1764 pinfo->symbols = sorted_syms + place;
1765 pinfo->num_symbols = x - place;
1769 pinfo->symbols = NULL;
1770 pinfo->num_symbols = 0;
1773 if (! prefix_addresses)
1775 pinfo->fprintf_func (pinfo->stream, "\n");
1776 objdump_print_addr_with_sym (abfd, section, sym, addr,
1778 pinfo->fprintf_func (pinfo->stream, ":\n");
1781 if (sym != NULL && bfd_asymbol_value (sym) > addr)
1783 else if (sym == NULL)
1787 #define is_valid_next_sym(SYM) \
1788 ((SYM)->section == section \
1789 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
1790 && pinfo->symbol_is_valid (SYM, pinfo))
1792 /* Search forward for the next appropriate symbol in
1793 SECTION. Note that all the symbols are sorted
1794 together into one big array, and that some sections
1795 may have overlapping addresses. */
1796 while (place < sorted_symcount
1797 && ! is_valid_next_sym (sorted_syms [place]))
1800 if (place >= sorted_symcount)
1803 nextsym = sorted_syms[place];
1806 if (sym != NULL && bfd_asymbol_value (sym) > addr)
1807 nextstop_offset = bfd_asymbol_value (sym) - section->vma;
1808 else if (nextsym == NULL)
1809 nextstop_offset = stop_offset;
1811 nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
1813 if (nextstop_offset > stop_offset)
1814 nextstop_offset = stop_offset;
1816 /* If a symbol is explicitly marked as being an object
1817 rather than a function, just dump the bytes without
1818 disassembling them. */
1821 || bfd_asymbol_value (sym) > addr
1822 || ((sym->flags & BSF_OBJECT) == 0
1823 && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
1825 && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
1827 || (sym->flags & BSF_FUNCTION) != 0)
1832 disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
1833 addr_offset, nextstop_offset,
1834 rel_offset, &rel_pp, rel_ppend);
1836 addr_offset = nextstop_offset;
1842 if (rel_ppstart != NULL)
1846 /* Disassemble the contents of an object file. */
1849 disassemble_data (bfd *abfd)
1851 struct disassemble_info disasm_info;
1852 struct objdump_disasm_info aux;
1856 prev_functionname = NULL;
1859 /* We make a copy of syms to sort. We don't want to sort syms
1860 because that will screw up the relocs. */
1861 sorted_symcount = symcount ? symcount : dynsymcount;
1862 sorted_syms = xmalloc ((sorted_symcount + synthcount) * sizeof (asymbol *));
1863 memcpy (sorted_syms, symcount ? syms : dynsyms,
1864 sorted_symcount * sizeof (asymbol *));
1866 sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
1868 for (i = 0; i < synthcount; ++i)
1870 sorted_syms[sorted_symcount] = synthsyms + i;
1874 /* Sort the symbols into section and symbol order. */
1875 qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
1877 init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
1879 disasm_info.application_data = (void *) &aux;
1881 aux.require_sec = FALSE;
1882 aux.dynrelbuf = NULL;
1883 aux.dynrelcount = 0;
1884 #ifdef DISASSEMBLER_NEEDS_RELOCS
1888 disasm_info.print_address_func = objdump_print_address;
1889 disasm_info.symbol_at_address_func = objdump_symbol_at_address;
1891 if (machine != NULL)
1893 const bfd_arch_info_type *info = bfd_scan_arch (machine);
1896 fatal (_("Can't use supplied machine %s"), machine);
1898 abfd->arch_info = info;
1901 if (endian != BFD_ENDIAN_UNKNOWN)
1903 struct bfd_target *xvec;
1905 xvec = xmalloc (sizeof (struct bfd_target));
1906 memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
1907 xvec->byteorder = endian;
1911 /* Use libopcodes to locate a suitable disassembler. */
1912 aux.disassemble_fn = disassembler (abfd);
1913 if (!aux.disassemble_fn)
1915 non_fatal (_("Can't disassemble for architecture %s\n"),
1916 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
1921 disasm_info.flavour = bfd_get_flavour (abfd);
1922 disasm_info.arch = bfd_get_arch (abfd);
1923 disasm_info.mach = bfd_get_mach (abfd);
1924 disasm_info.disassembler_options = disassembler_options;
1925 disasm_info.octets_per_byte = bfd_octets_per_byte (abfd);
1926 disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
1927 disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
1929 if (bfd_big_endian (abfd))
1930 disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
1931 else if (bfd_little_endian (abfd))
1932 disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
1934 /* ??? Aborting here seems too drastic. We could default to big or little
1936 disasm_info.endian = BFD_ENDIAN_UNKNOWN;
1938 /* Allow the target to customize the info structure. */
1939 disassemble_init_for_target (& disasm_info);
1941 /* Pre-load the dynamic relocs if we are going
1942 to be dumping them along with the disassembly. */
1943 if (dump_dynamic_reloc_info)
1945 long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1948 bfd_fatal (bfd_get_filename (abfd));
1952 aux.dynrelbuf = xmalloc (relsize);
1953 aux.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd,
1956 if (aux.dynrelcount < 0)
1957 bfd_fatal (bfd_get_filename (abfd));
1959 /* Sort the relocs by address. */
1960 qsort (aux.dynrelbuf, aux.dynrelcount, sizeof (arelent *),
1965 bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
1967 if (aux.dynrelbuf != NULL)
1968 free (aux.dynrelbuf);
1973 load_debug_section (enum dwarf_section_display_enum debug, void *file)
1975 struct dwarf_section *section = &debug_displays [debug].section;
1980 /* If it is already loaded, do nothing. */
1981 if (section->start != NULL)
1984 /* Locate the debug section. */
1985 sec = bfd_get_section_by_name (abfd, section->name);
1989 section->address = bfd_get_section_vma (abfd, sec);
1990 section->size = bfd_get_section_size (sec);
1991 section->start = xmalloc (section->size);
1993 if (is_relocatable && debug_displays [debug].relocate)
1994 ret = bfd_simple_get_relocated_section_contents (abfd,
1999 ret = bfd_get_section_contents (abfd, sec, section->start, 0,
2004 free_debug_section (debug);
2005 printf (_("\nCan't get contents for section '%s'.\n"),
2013 free_debug_section (enum dwarf_section_display_enum debug)
2015 struct dwarf_section *section = &debug_displays [debug].section;
2017 if (section->start == NULL)
2020 free ((char *) section->start);
2021 section->start = NULL;
2022 section->address = 0;
2027 dump_dwarf_section (bfd *abfd, asection *section,
2028 void *arg ATTRIBUTE_UNUSED)
2030 const char *name = bfd_get_section_name (abfd, section);
2032 enum dwarf_section_display_enum i;
2034 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2035 match = ".debug_info";
2039 for (i = 0; i < max; i++)
2040 if (strcmp (debug_displays[i].section.name, match) == 0)
2042 if (!debug_displays[i].eh_frame)
2044 struct dwarf_section *sec = &debug_displays [i].section;
2046 if (load_debug_section (i, abfd))
2048 debug_displays[i].display (sec, abfd);
2050 if (i != info && i != abbrev)
2051 free_debug_section (i);
2058 static const char *mach_o_dwarf_sections [] = {
2059 "LC_SEGMENT.__DWARFA.__debug_abbrev", /* .debug_abbrev */
2060 "LC_SEGMENT.__DWARFA.__debug_aranges", /* .debug_aranges */
2061 "LC_SEGMENT.__DWARFA.__debug_frame", /* .debug_frame */
2062 "LC_SEGMENT.__DWARFA.__debug_info", /* .debug_info */
2063 "LC_SEGMENT.__DWARFA.__debug_line", /* .debug_line */
2064 "LC_SEGMENT.__DWARFA.__debug_pubnames", /* .debug_pubnames */
2065 ".eh_frame", /* .eh_frame */
2066 "LC_SEGMENT.__DWARFA.__debug_macinfo", /* .debug_macinfo */
2067 "LC_SEGMENT.__DWARFA.__debug_str", /* .debug_str */
2068 "LC_SEGMENT.__DWARFA.__debug_loc", /* .debug_loc */
2069 "LC_SEGMENT.__DWARFA.__debug_pubtypes", /* .debug_pubtypes */
2070 "LC_SEGMENT.__DWARFA.__debug_ranges", /* .debug_ranges */
2071 "LC_SEGMENT.__DWARFA.__debug_static_func", /* .debug_static_func */
2072 "LC_SEGMENT.__DWARFA.__debug_static_vars", /* .debug_static_vars */
2073 "LC_SEGMENT.__DWARFA.__debug_types", /* .debug_types */
2074 "LC_SEGMENT.__DWARFA.__debug_weaknames" /* .debug_weaknames */
2077 static const char *generic_dwarf_sections [max];
2080 check_mach_o_dwarf (bfd *abfd)
2082 static enum bfd_flavour old_flavour = bfd_target_unknown_flavour;
2083 enum bfd_flavour current_flavour = bfd_get_flavour (abfd);
2084 enum dwarf_section_display_enum i;
2086 if (generic_dwarf_sections [0] == NULL)
2087 for (i = 0; i < max; i++)
2088 generic_dwarf_sections [i] = debug_displays[i].section.name;
2090 if (old_flavour != current_flavour)
2092 if (current_flavour == bfd_target_mach_o_flavour)
2093 for (i = 0; i < max; i++)
2094 debug_displays[i].section.name = mach_o_dwarf_sections [i];
2095 else if (old_flavour == bfd_target_mach_o_flavour)
2096 for (i = 0; i < max; i++)
2097 debug_displays[i].section.name = generic_dwarf_sections [i];
2099 old_flavour = current_flavour;
2103 /* Dump the dwarf debugging information. */
2106 dump_dwarf (bfd *abfd)
2108 is_relocatable = ((abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC))
2111 /* FIXME: bfd_get_arch_size may return -1. We assume that 64bit
2112 targets will return 64. */
2113 eh_addr_size = bfd_get_arch_size (abfd) == 64 ? 8 : 4;
2115 if (bfd_big_endian (abfd))
2116 byte_get = byte_get_big_endian;
2117 else if (bfd_little_endian (abfd))
2118 byte_get = byte_get_little_endian;
2122 check_mach_o_dwarf (abfd);
2124 bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
2126 free_debug_memory ();
2129 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
2130 it. Return NULL on failure. */
2133 read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr)
2139 stabsect = bfd_get_section_by_name (abfd, sect_name);
2140 if (stabsect == NULL)
2142 printf (_("No %s section present\n\n"), sect_name);
2146 size = bfd_section_size (abfd, stabsect);
2147 contents = xmalloc (size);
2149 if (! bfd_get_section_contents (abfd, stabsect, contents, 0, size))
2151 non_fatal (_("Reading %s section of %s failed: %s"),
2152 sect_name, bfd_get_filename (abfd),
2153 bfd_errmsg (bfd_get_error ()));
2164 /* Stabs entries use a 12 byte format:
2165 4 byte string table index
2167 1 byte stab other field
2168 2 byte stab desc field
2170 FIXME: This will have to change for a 64 bit object format. */
2172 #define STRDXOFF (0)
2174 #define OTHEROFF (5)
2177 #define STABSIZE (12)
2179 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
2180 using string table section STRSECT_NAME (in `strtab'). */
2183 print_section_stabs (bfd *abfd,
2184 const char *stabsect_name,
2185 unsigned *string_offset_ptr)
2188 unsigned file_string_table_offset = 0;
2189 unsigned next_file_string_table_offset = *string_offset_ptr;
2190 bfd_byte *stabp, *stabs_end;
2193 stabs_end = stabp + stab_size;
2195 printf (_("Contents of %s section:\n\n"), stabsect_name);
2196 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
2198 /* Loop through all symbols and print them.
2200 We start the index at -1 because there is a dummy symbol on
2201 the front of stabs-in-{coff,elf} sections that supplies sizes. */
2202 for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++)
2206 unsigned char type, other;
2207 unsigned short desc;
2210 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
2211 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
2212 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
2213 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
2214 value = bfd_h_get_32 (abfd, stabp + VALOFF);
2216 printf ("\n%-6d ", i);
2217 /* Either print the stab name, or, if unnamed, print its number
2218 again (makes consistent formatting for tools like awk). */
2219 name = bfd_get_stab_name (type);
2221 printf ("%-6s", name);
2222 else if (type == N_UNDF)
2225 printf ("%-6d", type);
2226 printf (" %-6d %-6d ", other, desc);
2227 bfd_printf_vma (abfd, value);
2228 printf (" %-6lu", strx);
2230 /* Symbols with type == 0 (N_UNDF) specify the length of the
2231 string table associated with this file. We use that info
2232 to know how to relocate the *next* file's string table indices. */
2235 file_string_table_offset = next_file_string_table_offset;
2236 next_file_string_table_offset += value;
2240 /* Using the (possibly updated) string table offset, print the
2241 string (if any) associated with this symbol. */
2242 if ((strx + file_string_table_offset) < stabstr_size)
2243 printf (" %s", &strtab[strx + file_string_table_offset]);
2249 *string_offset_ptr = next_file_string_table_offset;
2254 const char * section_name;
2255 const char * string_section_name;
2256 unsigned string_offset;
2261 find_stabs_section (bfd *abfd, asection *section, void *names)
2264 stab_section_names * sought = (stab_section_names *) names;
2266 /* Check for section names for which stabsect_name is a prefix, to
2267 handle .stab.N, etc. */
2268 len = strlen (sought->section_name);
2270 /* If the prefix matches, and the files section name ends with a
2271 nul or a digit, then we match. I.e., we want either an exact
2272 match or a section followed by a number. */
2273 if (strncmp (sought->section_name, section->name, len) == 0
2274 && (section->name[len] == 0
2275 || (section->name[len] == '.' && ISDIGIT (section->name[len + 1]))))
2278 strtab = read_section_stabs (abfd, sought->string_section_name,
2283 stabs = (bfd_byte *) read_section_stabs (abfd, section->name,
2286 print_section_stabs (abfd, section->name, &sought->string_offset);
2292 dump_stabs_section (bfd *abfd, char *stabsect_name, char *strsect_name)
2294 stab_section_names s;
2296 s.section_name = stabsect_name;
2297 s.string_section_name = strsect_name;
2298 s.string_offset = 0;
2300 bfd_map_over_sections (abfd, find_stabs_section, & s);
2306 /* Dump the any sections containing stabs debugging information. */
2309 dump_stabs (bfd *abfd)
2311 dump_stabs_section (abfd, ".stab", ".stabstr");
2312 dump_stabs_section (abfd, ".stab.excl", ".stab.exclstr");
2313 dump_stabs_section (abfd, ".stab.index", ".stab.indexstr");
2314 dump_stabs_section (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
2318 dump_bfd_header (bfd *abfd)
2322 printf (_("architecture: %s, "),
2323 bfd_printable_arch_mach (bfd_get_arch (abfd),
2324 bfd_get_mach (abfd)));
2325 printf (_("flags 0x%08x:\n"), abfd->flags);
2327 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
2328 PF (HAS_RELOC, "HAS_RELOC");
2329 PF (EXEC_P, "EXEC_P");
2330 PF (HAS_LINENO, "HAS_LINENO");
2331 PF (HAS_DEBUG, "HAS_DEBUG");
2332 PF (HAS_SYMS, "HAS_SYMS");
2333 PF (HAS_LOCALS, "HAS_LOCALS");
2334 PF (DYNAMIC, "DYNAMIC");
2335 PF (WP_TEXT, "WP_TEXT");
2336 PF (D_PAGED, "D_PAGED");
2337 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
2338 PF (HAS_LOAD_PAGE, "HAS_LOAD_PAGE");
2339 printf (_("\nstart address 0x"));
2340 bfd_printf_vma (abfd, abfd->start_address);
2346 dump_bfd_private_header (bfd *abfd)
2348 bfd_print_private_bfd_data (abfd, stdout);
2352 /* Display a section in hexadecimal format with associated characters.
2353 Each line prefixed by the zero padded address. */
2356 dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED)
2359 bfd_size_type datasize;
2360 bfd_size_type addr_offset;
2361 bfd_size_type start_offset;
2362 bfd_size_type stop_offset;
2363 unsigned int opb = bfd_octets_per_byte (abfd);
2364 /* Bytes per line. */
2365 const int onaline = 16;
2370 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2373 if (! process_section_p (section))
2376 if ((datasize = bfd_section_size (abfd, section)) == 0)
2379 printf (_("Contents of section %s:\n"), section->name);
2381 data = xmalloc (datasize);
2383 bfd_get_section_contents (abfd, section, data, 0, datasize);
2385 /* Compute the address range to display. */
2386 if (start_address == (bfd_vma) -1
2387 || start_address < section->vma)
2390 start_offset = start_address - section->vma;
2392 if (stop_address == (bfd_vma) -1)
2393 stop_offset = datasize / opb;
2396 if (stop_address < section->vma)
2399 stop_offset = stop_address - section->vma;
2401 if (stop_offset > datasize / opb)
2402 stop_offset = datasize / opb;
2407 bfd_sprintf_vma (abfd, buf, start_offset + section->vma);
2408 if (strlen (buf) >= sizeof (buf))
2412 while (buf[count] == '0' && buf[count+1] != '\0')
2414 count = strlen (buf) - count;
2418 bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1);
2419 if (strlen (buf) >= sizeof (buf))
2423 while (buf[count] == '0' && buf[count+1] != '\0')
2425 count = strlen (buf) - count;
2429 for (addr_offset = start_offset;
2430 addr_offset < stop_offset; addr_offset += onaline / opb)
2434 bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma));
2435 count = strlen (buf);
2436 if ((size_t) count >= sizeof (buf))
2440 while (count < width)
2445 fputs (buf + count - width, stdout);
2448 for (j = addr_offset * opb;
2449 j < addr_offset * opb + onaline; j++)
2451 if (j < stop_offset * opb)
2452 printf ("%02x", (unsigned) (data[j]));
2460 for (j = addr_offset * opb;
2461 j < addr_offset * opb + onaline; j++)
2463 if (j >= stop_offset * opb)
2466 printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
2473 /* Actually display the various requested regions. */
2476 dump_data (bfd *abfd)
2478 bfd_map_over_sections (abfd, dump_section, NULL);
2481 /* Should perhaps share code and display with nm? */
2484 dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic)
2494 printf ("DYNAMIC SYMBOL TABLE:\n");
2500 printf ("SYMBOL TABLE:\n");
2504 printf (_("no symbols\n"));
2506 for (count = 0; count < max; count++)
2510 if (*current == NULL)
2511 printf (_("no information for symbol number %ld\n"), count);
2513 else if ((cur_bfd = bfd_asymbol_bfd (*current)) == NULL)
2514 printf (_("could not determine the type of symbol number %ld\n"),
2517 else if (process_section_p ((* current)->section)
2518 && (dump_special_syms
2519 || !bfd_is_target_special_symbol (cur_bfd, *current)))
2521 const char *name = (*current)->name;
2523 if (do_demangle && name != NULL && *name != '\0')
2527 /* If we want to demangle the name, we demangle it
2528 here, and temporarily clobber it while calling
2529 bfd_print_symbol. FIXME: This is a gross hack. */
2530 alloc = demangle (cur_bfd, name);
2531 (*current)->name = alloc;
2532 bfd_print_symbol (cur_bfd, stdout, *current,
2533 bfd_print_symbol_all);
2534 (*current)->name = name;
2538 bfd_print_symbol (cur_bfd, stdout, *current,
2539 bfd_print_symbol_all);
2549 dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount)
2552 char *last_filename, *last_functionname;
2553 unsigned int last_line;
2555 /* Get column headers lined up reasonably. */
2563 bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
2564 width = strlen (buf) - 7;
2566 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
2569 last_filename = NULL;
2570 last_functionname = NULL;
2573 for (p = relpp; relcount && *p != NULL; p++, relcount--)
2576 const char *filename, *functionname;
2578 const char *sym_name;
2579 const char *section_name;
2581 if (start_address != (bfd_vma) -1
2582 && q->address < start_address)
2584 if (stop_address != (bfd_vma) -1
2585 && q->address > stop_address)
2588 if (with_line_numbers
2590 && bfd_find_nearest_line (abfd, sec, syms, q->address,
2591 &filename, &functionname, &line))
2593 if (functionname != NULL
2594 && (last_functionname == NULL
2595 || strcmp (functionname, last_functionname) != 0))
2597 printf ("%s():\n", functionname);
2598 if (last_functionname != NULL)
2599 free (last_functionname);
2600 last_functionname = xstrdup (functionname);
2604 && (line != last_line
2605 || (filename != NULL
2606 && last_filename != NULL
2607 && strcmp (filename, last_filename) != 0)))
2609 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
2611 if (last_filename != NULL)
2612 free (last_filename);
2613 if (filename == NULL)
2614 last_filename = NULL;
2616 last_filename = xstrdup (filename);
2620 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
2622 sym_name = (*(q->sym_ptr_ptr))->name;
2623 section_name = (*(q->sym_ptr_ptr))->section->name;
2628 section_name = NULL;
2631 bfd_printf_vma (abfd, q->address);
2632 if (q->howto == NULL)
2633 printf (" *unknown* ");
2634 else if (q->howto->name)
2635 printf (" %-16s ", q->howto->name);
2637 printf (" %-16d ", q->howto->type);
2639 objdump_print_symname (abfd, NULL, *q->sym_ptr_ptr);
2642 if (section_name == NULL)
2643 section_name = "*unknown*";
2644 printf ("[%s]", section_name);
2650 bfd_printf_vma (abfd, q->addend);
2658 dump_relocs_in_section (bfd *abfd,
2660 void *dummy ATTRIBUTE_UNUSED)
2666 if ( bfd_is_abs_section (section)
2667 || bfd_is_und_section (section)
2668 || bfd_is_com_section (section)
2669 || (! process_section_p (section))
2670 || ((section->flags & SEC_RELOC) == 0))
2673 relsize = bfd_get_reloc_upper_bound (abfd, section);
2675 bfd_fatal (bfd_get_filename (abfd));
2677 printf ("RELOCATION RECORDS FOR [%s]:", section->name);
2681 printf (" (none)\n\n");
2685 relpp = xmalloc (relsize);
2686 relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
2689 bfd_fatal (bfd_get_filename (abfd));
2690 else if (relcount == 0)
2691 printf (" (none)\n\n");
2695 dump_reloc_set (abfd, section, relpp, relcount);
2702 dump_relocs (bfd *abfd)
2704 bfd_map_over_sections (abfd, dump_relocs_in_section, NULL);
2708 dump_dynamic_relocs (bfd *abfd)
2714 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
2716 bfd_fatal (bfd_get_filename (abfd));
2718 printf ("DYNAMIC RELOCATION RECORDS");
2721 printf (" (none)\n\n");
2724 relpp = xmalloc (relsize);
2725 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
2728 bfd_fatal (bfd_get_filename (abfd));
2729 else if (relcount == 0)
2730 printf (" (none)\n\n");
2734 dump_reloc_set (abfd, NULL, relpp, relcount);
2741 /* Creates a table of paths, to search for source files. */
2744 add_include_path (const char *path)
2748 include_path_count++;
2749 include_paths = xrealloc (include_paths,
2750 include_path_count * sizeof (*include_paths));
2751 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2752 if (path[1] == ':' && path[2] == 0)
2753 path = concat (path, ".", (const char *) 0);
2755 include_paths[include_path_count - 1] = path;
2759 adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
2763 if ((section->flags & SEC_DEBUGGING) == 0)
2765 bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
2766 section->vma += adjust_section_vma;
2768 section->lma += adjust_section_vma;
2772 /* Dump selected contents of ABFD. */
2775 dump_bfd (bfd *abfd)
2777 /* If we are adjusting section VMA's, change them all now. Changing
2778 the BFD information is a hack. However, we must do it, or
2779 bfd_find_nearest_line will not do the right thing. */
2780 if (adjust_section_vma != 0)
2782 bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
2783 bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
2786 if (! dump_debugging_tags)
2787 printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd),
2790 print_arelt_descr (stdout, abfd, TRUE);
2791 if (dump_file_header)
2792 dump_bfd_header (abfd);
2793 if (dump_private_headers)
2794 dump_bfd_private_header (abfd);
2795 if (! dump_debugging_tags)
2797 if (dump_section_headers)
2798 dump_headers (abfd);
2804 || dump_dwarf_section_info)
2805 syms = slurp_symtab (abfd);
2806 if (dump_dynamic_symtab || dump_dynamic_reloc_info
2807 || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0))
2808 dynsyms = slurp_dynamic_symtab (abfd);
2811 synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms,
2812 dynsymcount, dynsyms, &synthsyms);
2818 dump_symbols (abfd, FALSE);
2819 if (dump_dynamic_symtab)
2820 dump_symbols (abfd, TRUE);
2821 if (dump_dwarf_section_info)
2823 if (dump_stab_section_info)
2825 if (dump_reloc_info && ! disassemble)
2827 if (dump_dynamic_reloc_info && ! disassemble)
2828 dump_dynamic_relocs (abfd);
2829 if (dump_section_contents)
2832 disassemble_data (abfd);
2838 dhandle = read_debugging_info (abfd, syms, symcount);
2839 if (dhandle != NULL)
2841 if (! print_debugging_info (stdout, dhandle, abfd, syms, demangle,
2842 dump_debugging_tags ? TRUE : FALSE))
2844 non_fatal (_("%s: printing debugging information failed"),
2845 bfd_get_filename (abfd));
2875 display_bfd (bfd *abfd)
2879 if (bfd_check_format_matches (abfd, bfd_object, &matching))
2885 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
2887 nonfatal (bfd_get_filename (abfd));
2888 list_matching_formats (matching);
2893 if (bfd_get_error () != bfd_error_file_not_recognized)
2895 nonfatal (bfd_get_filename (abfd));
2899 if (bfd_check_format_matches (abfd, bfd_core, &matching))
2905 nonfatal (bfd_get_filename (abfd));
2907 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
2909 list_matching_formats (matching);
2915 display_file (char *filename, char *target)
2920 if (get_file_size (filename) < 1)
2923 file = bfd_openr (filename, target);
2926 nonfatal (filename);
2930 /* If the file is an archive, process all of its elements. */
2931 if (bfd_check_format (file, bfd_archive))
2933 bfd *last_arfile = NULL;
2935 printf (_("In archive %s:\n"), bfd_get_filename (file));
2938 bfd_set_error (bfd_error_no_error);
2940 arfile = bfd_openr_next_archived_file (file, arfile);
2943 if (bfd_get_error () != bfd_error_no_more_archived_files)
2944 nonfatal (bfd_get_filename (file));
2948 display_bfd (arfile);
2950 if (last_arfile != NULL)
2951 bfd_close (last_arfile);
2952 last_arfile = arfile;
2955 if (last_arfile != NULL)
2956 bfd_close (last_arfile);
2965 main (int argc, char **argv)
2968 char *target = default_target;
2969 bfd_boolean seenflag = FALSE;
2971 #if defined (HAVE_SETLOCALE)
2972 #if defined (HAVE_LC_MESSAGES)
2973 setlocale (LC_MESSAGES, "");
2975 setlocale (LC_CTYPE, "");
2978 bindtextdomain (PACKAGE, LOCALEDIR);
2979 textdomain (PACKAGE);
2981 program_name = *argv;
2982 xmalloc_set_program_name (program_name);
2984 START_PROGRESS (program_name, 0);
2986 expandargv (&argc, &argv);
2989 set_default_bfd_target ();
2991 while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfaHhrRtTxsSI:j:wE:zgeGW",
2992 long_options, (int *) 0))
2998 break; /* We've been given a long option. */
3003 if (disassembler_options)
3004 /* Ignore potential memory leak for now. */
3005 disassembler_options = concat (disassembler_options, ",",
3008 disassembler_options = optarg;
3011 if (only_used == only_size)
3014 only = xrealloc (only, only_size * sizeof (char *));
3016 only [only_used++] = optarg;
3019 with_line_numbers = TRUE;
3028 enum demangling_styles style;
3030 style = cplus_demangle_name_to_style (optarg);
3031 if (style == unknown_demangling)
3032 fatal (_("unknown demangling style `%s'"),
3035 cplus_demangle_set_style (style);
3041 case OPTION_ADJUST_VMA:
3042 adjust_section_vma = parse_vma (optarg, "--adjust-vma");
3044 case OPTION_START_ADDRESS:
3045 start_address = parse_vma (optarg, "--start-address");
3047 case OPTION_STOP_ADDRESS:
3048 stop_address = parse_vma (optarg, "--stop-address");
3051 if (strcmp (optarg, "B") == 0)
3052 endian = BFD_ENDIAN_BIG;
3053 else if (strcmp (optarg, "L") == 0)
3054 endian = BFD_ENDIAN_LITTLE;
3057 non_fatal (_("unrecognized -E option"));
3062 if (strncmp (optarg, "big", strlen (optarg)) == 0)
3063 endian = BFD_ENDIAN_BIG;
3064 else if (strncmp (optarg, "little", strlen (optarg)) == 0)
3065 endian = BFD_ENDIAN_LITTLE;
3068 non_fatal (_("unrecognized --endian type `%s'"), optarg);
3074 dump_file_header = TRUE;
3078 formats_info = TRUE;
3082 add_include_path (optarg);
3085 dump_private_headers = TRUE;
3089 dump_private_headers = TRUE;
3091 dump_reloc_info = TRUE;
3092 dump_file_header = TRUE;
3093 dump_ar_hdrs = TRUE;
3094 dump_section_headers = TRUE;
3102 dump_dynamic_symtab = TRUE;
3110 disassemble_zeroes = TRUE;
3114 disassemble_all = TRUE;
3119 with_source_code = TRUE;
3128 dump_debugging_tags = 1;
3133 dump_dwarf_section_info = TRUE;
3136 do_debug_abbrevs = 1;
3138 do_debug_pubnames = 1;
3139 do_debug_aranges = 1;
3140 do_debug_ranges = 1;
3141 do_debug_frames = 1;
3142 do_debug_macinfo = 1;
3147 dump_stab_section_info = TRUE;
3151 dump_section_contents = TRUE;
3155 dump_reloc_info = TRUE;
3159 dump_dynamic_reloc_info = TRUE;
3163 dump_ar_hdrs = TRUE;
3167 dump_section_headers = TRUE;
3175 show_version = TRUE;
3185 print_version ("objdump");
3191 exit_status = display_info ();
3195 display_file ("a.out", target);
3197 for (; optind < argc;)
3198 display_file (argv[optind++], target);
3201 END_PROGRESS (program_name);