1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "libiberty.h"
30 #ifdef ANSI_PROTOTYPES
36 /* Internal headers for the ELF .stab-dump code - sorry. */
37 #define BYTES_IN_WORD 32
38 #include "aout/aout64.h"
40 #ifdef NEED_DECLARATION_FPRINTF
41 /* This is needed by INIT_DISASSEMBLE_INFO. */
42 extern int fprintf PARAMS ((FILE *, const char *, ...));
45 static char *default_target = NULL; /* default at runtime */
47 static int show_version = 0; /* show the version number */
48 static int dump_section_contents; /* -s */
49 static int dump_section_headers; /* -h */
50 static boolean dump_file_header; /* -f */
51 static int dump_symtab; /* -t */
52 static int dump_dynamic_symtab; /* -T */
53 static int dump_reloc_info; /* -r */
54 static int dump_dynamic_reloc_info; /* -R */
55 static int dump_ar_hdrs; /* -a */
56 static int dump_private_headers; /* -p */
57 static int prefix_addresses; /* --prefix-addresses */
58 static int with_line_numbers; /* -l */
59 static boolean with_source_code; /* -S */
60 static int show_raw_insn; /* --show-raw-insn */
61 static int dump_stab_section_info; /* --stabs */
62 static boolean disassemble; /* -d */
63 static boolean disassemble_all; /* -D */
64 static boolean formats_info; /* -i */
65 static char *only; /* -j secname */
66 static int wide_output; /* -w */
67 static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
68 static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
69 static int dump_debugging; /* --debugging */
71 /* Extra info to pass to the disassembler address printing function. */
72 struct objdump_disasm_info {
78 /* Architecture to disassemble for, or default if NULL. */
79 static char *machine = (char *) NULL;
81 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
82 static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
84 /* The symbol table. */
85 static asymbol **syms;
87 /* Number of symbols in `syms'. */
88 static long symcount = 0;
90 /* The sorted symbol table. */
91 static asymbol **sorted_syms;
93 /* Number of symbols in `sorted_syms'. */
94 static long sorted_symcount = 0;
96 /* The dynamic symbol table. */
97 static asymbol **dynsyms;
99 /* Number of symbols in `dynsyms'. */
100 static long dynsymcount = 0;
102 /* Forward declarations. */
105 display_file PARAMS ((char *filename, char *target));
108 dump_data PARAMS ((bfd *abfd));
111 dump_relocs PARAMS ((bfd *abfd));
114 dump_dynamic_relocs PARAMS ((bfd * abfd));
117 dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long));
120 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
123 display_bfd PARAMS ((bfd *abfd));
126 objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *));
129 find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));
132 objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
133 struct disassemble_info *));
136 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
139 show_line PARAMS ((bfd *, asection *, bfd_vma));
142 disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype,
143 boolean, bfd_byte *, long, long, arelent ***,
147 disassemble_data PARAMS ((bfd *));
150 endian_string PARAMS ((enum bfd_endian));
153 usage (stream, status)
158 Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
159 [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
160 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
161 [--info] [--section=section-name] [--line-numbers] [--source]\n",
164 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
165 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
166 [--wide] [--version] [--help] [--private-headers]\n\
167 [--start-address=addr] [--stop-address=addr]\n\
168 [--prefix-addresses] [--show-raw-insn]\n\
169 [-EB|-EL] [--endian={big|little}] objfile...\n\
170 at least one option besides -l (--line-numbers) must be given\n");
171 list_supported_targets (program_name, stream);
173 fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
177 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
179 #define OPTION_ENDIAN (150)
180 #define OPTION_START_ADDRESS (OPTION_ENDIAN + 1)
181 #define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
183 static struct option long_options[]=
185 {"all-headers", no_argument, NULL, 'x'},
186 {"private-headers", no_argument, NULL, 'p'},
187 {"architecture", required_argument, NULL, 'm'},
188 {"archive-headers", no_argument, NULL, 'a'},
189 {"debugging", no_argument, &dump_debugging, 1},
190 {"disassemble", no_argument, NULL, 'd'},
191 {"disassemble-all", no_argument, NULL, 'D'},
192 {"dynamic-reloc", no_argument, NULL, 'R'},
193 {"dynamic-syms", no_argument, NULL, 'T'},
194 {"endian", required_argument, NULL, OPTION_ENDIAN},
195 {"file-headers", no_argument, NULL, 'f'},
196 {"full-contents", no_argument, NULL, 's'},
197 {"headers", no_argument, NULL, 'h'},
198 {"help", no_argument, NULL, 'H'},
199 {"info", no_argument, NULL, 'i'},
200 {"line-numbers", no_argument, NULL, 'l'},
201 {"prefix-addresses", no_argument, &prefix_addresses, 1},
202 {"reloc", no_argument, NULL, 'r'},
203 {"section", required_argument, NULL, 'j'},
204 {"section-headers", no_argument, NULL, 'h'},
205 {"show-raw-insn", no_argument, &show_raw_insn, 1},
206 {"source", no_argument, NULL, 'S'},
207 {"stabs", no_argument, &dump_stab_section_info, 1},
208 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
209 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
210 {"syms", no_argument, NULL, 't'},
211 {"target", required_argument, NULL, 'b'},
212 {"version", no_argument, &show_version, 1},
213 {"wide", no_argument, &wide_output, 'w'},
214 {0, no_argument, 0, 0}
218 dump_section_header (abfd, section, ignored)
225 printf ("%3d %-13s %08lx ", section->index,
226 bfd_get_section_name (abfd, section),
227 (unsigned long) bfd_section_size (abfd, section));
228 printf_vma (bfd_get_section_vma (abfd, section));
230 printf_vma (section->lma);
231 printf (" %08lx 2**%u", section->filepos,
232 bfd_get_section_alignment (abfd, section));
238 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
240 PF (SEC_HAS_CONTENTS, "CONTENTS");
241 PF (SEC_ALLOC, "ALLOC");
242 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
243 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
244 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
245 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
246 PF (SEC_LOAD, "LOAD");
247 PF (SEC_RELOC, "RELOC");
249 PF (SEC_BALIGN, "BALIGN");
251 PF (SEC_READONLY, "READONLY");
252 PF (SEC_CODE, "CODE");
253 PF (SEC_DATA, "DATA");
255 PF (SEC_DEBUGGING, "DEBUGGING");
256 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
257 PF (SEC_EXCLUDE, "EXCLUDE");
258 PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
260 if ((section->flags & SEC_LINK_ONCE) != 0)
264 switch (section->flags & SEC_LINK_DUPLICATES)
268 case SEC_LINK_DUPLICATES_DISCARD:
269 ls = "LINK_ONCE_DISCARD";
271 case SEC_LINK_DUPLICATES_ONE_ONLY:
272 ls = "LINK_ONCE_ONE_ONLY";
274 case SEC_LINK_DUPLICATES_SAME_SIZE:
275 ls = "LINK_ONCE_SAME_SIZE";
277 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
278 ls = "LINK_ONCE_SAME_CONTENTS";
281 printf ("%s%s", comma, ls);
293 printf ("Sections:\n");
295 printf ("Idx Name Size VMA LMA File off Algn\n");
297 printf ("Idx Name Size VMA LMA File off Algn\n");
299 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
306 asymbol **sy = (asymbol **) NULL;
309 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
311 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
316 storage = bfd_get_symtab_upper_bound (abfd);
318 bfd_fatal (bfd_get_filename (abfd));
322 sy = (asymbol **) xmalloc (storage);
324 symcount = bfd_canonicalize_symtab (abfd, sy);
326 bfd_fatal (bfd_get_filename (abfd));
328 fprintf (stderr, "%s: %s: No symbols\n",
329 program_name, bfd_get_filename (abfd));
333 /* Read in the dynamic symbols. */
336 slurp_dynamic_symtab (abfd)
339 asymbol **sy = (asymbol **) NULL;
342 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
345 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
347 fprintf (stderr, "%s: %s: not a dynamic object\n",
348 program_name, bfd_get_filename (abfd));
353 bfd_fatal (bfd_get_filename (abfd));
358 sy = (asymbol **) xmalloc (storage);
360 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
362 bfd_fatal (bfd_get_filename (abfd));
363 if (dynsymcount == 0)
364 fprintf (stderr, "%s: %s: No dynamic symbols\n",
365 program_name, bfd_get_filename (abfd));
369 /* Filter out (in place) symbols that are useless for disassembly.
370 COUNT is the number of elements in SYMBOLS.
371 Return the number of useful symbols. */
374 remove_useless_symbols (symbols, count)
378 register asymbol **in_ptr = symbols, **out_ptr = symbols;
382 asymbol *sym = *in_ptr++;
384 if (sym->name == NULL || sym->name[0] == '\0')
386 if (sym->flags & (BSF_DEBUGGING))
388 if (bfd_is_und_section (sym->section)
389 || bfd_is_com_section (sym->section))
394 return out_ptr - symbols;
397 /* Sort symbols into value order. */
400 compare_symbols (ap, bp)
404 const asymbol *a = *(const asymbol **)ap;
405 const asymbol *b = *(const asymbol **)bp;
409 flagword aflags, bflags;
411 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
413 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
416 if (a->section > b->section)
418 else if (a->section < b->section)
421 an = bfd_asymbol_name (a);
422 bn = bfd_asymbol_name (b);
426 /* The symbols gnu_compiled and gcc2_compiled convey no real
427 information, so put them after other symbols with the same value. */
429 af = (strstr (an, "gnu_compiled") != NULL
430 || strstr (an, "gcc2_compiled") != NULL);
431 bf = (strstr (bn, "gnu_compiled") != NULL
432 || strstr (bn, "gcc2_compiled") != NULL);
439 /* We use a heuristic for the file name, to try to sort it after
440 more useful symbols. It may not work on non Unix systems, but it
441 doesn't really matter; the only difference is precisely which
442 symbol names get printed. */
444 #define file_symbol(s, sn, snl) \
445 (((s)->flags & BSF_FILE) != 0 \
446 || ((sn)[(snl) - 2] == '.' \
447 && ((sn)[(snl) - 1] == 'o' \
448 || (sn)[(snl) - 1] == 'a')))
450 af = file_symbol (a, an, anl);
451 bf = file_symbol (b, bn, bnl);
458 /* Try to sort global symbols before local symbols before function
459 symbols before debugging symbols. */
464 if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
466 if ((aflags & BSF_DEBUGGING) != 0)
471 if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
473 if ((aflags & BSF_FUNCTION) != 0)
478 if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
480 if ((aflags & BSF_LOCAL) != 0)
485 if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
487 if ((aflags & BSF_GLOBAL) != 0)
493 /* Symbols that start with '.' might be section names, so sort them
494 after symbols that don't start with '.'. */
495 if (an[0] == '.' && bn[0] != '.')
497 if (an[0] != '.' && bn[0] == '.')
500 /* Finally, if we can't distinguish them in any other way, try to
501 get consistent results by sorting the symbols by name. */
502 return strcmp (an, bn);
505 /* Sort relocs into address order. */
508 compare_relocs (ap, bp)
512 const arelent *a = *(const arelent **)ap;
513 const arelent *b = *(const arelent **)bp;
515 if (a->address > b->address)
517 else if (a->address < b->address)
520 /* So that associated relocations tied to the same address show up
521 in the correct order, we don't do any further sorting. */
530 /* Print VMA to STREAM with no leading zeroes. */
533 objdump_print_value (vma, info)
535 struct disassemble_info *info;
540 sprintf_vma (buf, vma);
541 for (p = buf; *p == '0'; ++p)
545 (*info->fprintf_func) (info->stream, "%s", p);
548 /* Locate a symbol given a bfd, a section, and a VMA. If REQUIRE_SEC
549 is true, then always require the symbol to be in the section. This
550 returns NULL if there is no suitable symbol. If PLACE is not NULL,
551 then *PLACE is set to the index of the symbol in sorted_syms. */
554 find_symbol_for_address (abfd, sec, vma, require_sec, place)
561 /* @@ Would it speed things up to cache the last two symbols returned,
562 and maybe their address ranges? For many processors, only one memory
563 operand can be present at a time, so the 2-entry cache wouldn't be
564 constantly churned by code doing heavy memory accesses. */
566 /* Indices in `sorted_syms'. */
568 long max = sorted_symcount;
571 if (sorted_symcount < 1)
574 /* Perform a binary search looking for the closest symbol to the
575 required value. We are searching the range (min, max]. */
576 while (min + 1 < max)
580 thisplace = (max + min) / 2;
581 sym = sorted_syms[thisplace];
583 if (bfd_asymbol_value (sym) > vma)
585 else if (bfd_asymbol_value (sym) < vma)
594 /* The symbol we want is now in min, the low end of the range we
595 were searching. If there are several symbols with the same
596 value, we want the first one. */
599 && (bfd_asymbol_value (sorted_syms[thisplace])
600 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
603 /* If the file is relocateable, and the symbol could be from this
604 section, prefer a symbol from this section over symbols from
605 others, even if the other symbol's value might be closer.
607 Note that this may be wrong for some symbol references if the
608 sections have overlapping memory ranges, but in that case there's
609 no way to tell what's desired without looking at the relocation
612 if (sorted_syms[thisplace]->section != sec
614 || ((abfd->flags & HAS_RELOC) != 0
615 && vma >= bfd_get_section_vma (abfd, sec)
616 && vma < (bfd_get_section_vma (abfd, sec)
617 + bfd_section_size (abfd, sec)))))
621 for (i = thisplace + 1; i < sorted_symcount; i++)
623 if (bfd_asymbol_value (sorted_syms[i])
624 != bfd_asymbol_value (sorted_syms[thisplace]))
630 if (sorted_syms[i]->section == sec
632 || sorted_syms[i - 1]->section != sec
633 || (bfd_asymbol_value (sorted_syms[i])
634 != bfd_asymbol_value (sorted_syms[i - 1]))))
641 if (sorted_syms[thisplace]->section != sec)
643 /* We didn't find a good symbol with a smaller value.
644 Look for one with a larger value. */
645 for (i = thisplace + 1; i < sorted_symcount; i++)
647 if (sorted_syms[i]->section == sec)
655 if (sorted_syms[thisplace]->section != sec
657 || ((abfd->flags & HAS_RELOC) != 0
658 && vma >= bfd_get_section_vma (abfd, sec)
659 && vma < (bfd_get_section_vma (abfd, sec)
660 + bfd_section_size (abfd, sec)))))
662 /* There is no suitable symbol. */
670 return sorted_syms[thisplace];
673 /* Print an address to INFO symbolically. */
676 objdump_print_addr_with_sym (abfd, sec, sym, vma, info)
681 struct disassemble_info *info;
685 sprintf_vma (buf, vma);
686 (*info->fprintf_func) (info->stream, "%s", buf);
692 (*info->fprintf_func) (info->stream, " <%s",
693 bfd_get_section_name (abfd, sec));
694 secaddr = bfd_get_section_vma (abfd, sec);
697 (*info->fprintf_func) (info->stream, "-");
698 objdump_print_value (secaddr - vma, info);
700 else if (vma > secaddr)
702 (*info->fprintf_func) (info->stream, "+");
703 objdump_print_value (vma - secaddr, info);
705 (*info->fprintf_func) (info->stream, ">");
709 (*info->fprintf_func) (info->stream, " <%s", sym->name);
710 if (bfd_asymbol_value (sym) > vma)
712 (*info->fprintf_func) (info->stream, "-");
713 objdump_print_value (bfd_asymbol_value (sym) - vma, info);
715 else if (vma > bfd_asymbol_value (sym))
717 (*info->fprintf_func) (info->stream, "+");
718 objdump_print_value (vma - bfd_asymbol_value (sym), info);
720 (*info->fprintf_func) (info->stream, ">");
724 /* Print VMA symbolically to INFO if possible. */
727 objdump_print_address (vma, info)
729 struct disassemble_info *info;
731 struct objdump_disasm_info *aux;
734 if (sorted_symcount < 1)
738 sprintf_vma (buf, vma);
739 (*info->fprintf_func) (info->stream, "%s", buf);
743 aux = (struct objdump_disasm_info *) info->application_data;
744 sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec,
746 objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info);
749 /* Hold the last function name and the last line number we displayed
752 static char *prev_functionname;
753 static unsigned int prev_line;
755 /* We keep a list of all files that we have seen when doing a
756 dissassembly with source, so that we know how much of the file to
757 display. This can be important for inlined functions. */
759 struct print_file_list
761 struct print_file_list *next;
767 static struct print_file_list *print_files;
769 /* The number of preceding context lines to show when we start
770 displaying a file for the first time. */
772 #define SHOW_PRECEDING_CONTEXT_LINES (5)
774 /* Skip ahead to a given line in a file, optionally printing each
778 skip_to_line PARAMS ((struct print_file_list *, unsigned int, boolean));
781 skip_to_line (p, line, show)
782 struct print_file_list *p;
786 while (p->line < line)
790 if (fgets (buf, sizeof buf, p->f) == NULL)
800 if (strchr (buf, '\n') != NULL)
805 /* Show the line number, or the source line, in a dissassembly
809 show_line (abfd, section, off)
814 CONST char *filename;
815 CONST char *functionname;
818 if (! with_line_numbers && ! with_source_code)
821 if (! bfd_find_nearest_line (abfd, section, syms, off, &filename,
822 &functionname, &line))
825 if (filename != NULL && *filename == '\0')
827 if (functionname != NULL && *functionname == '\0')
830 if (with_line_numbers)
832 if (functionname != NULL
833 && (prev_functionname == NULL
834 || strcmp (functionname, prev_functionname) != 0))
835 printf ("%s():\n", functionname);
836 if (line > 0 && line != prev_line)
837 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
844 struct print_file_list **pp, *p;
846 for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
847 if (strcmp ((*pp)->filename, filename) == 0)
853 if (p != print_files)
857 /* We have reencountered a file name which we saw
858 earlier. This implies that either we are dumping out
859 code from an included file, or the same file was
860 linked in more than once. There are two common cases
861 of an included file: inline functions in a header
862 file, and a bison or flex skeleton file. In the
863 former case we want to just start printing (but we
864 back up a few lines to give context); in the latter
865 case we want to continue from where we left off. I
866 can't think of a good way to distinguish the cases,
867 so I used a heuristic based on the file name. */
868 if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0)
872 l = line - SHOW_PRECEDING_CONTEXT_LINES;
879 p->f = fopen (p->filename, "r");
883 skip_to_line (p, l, false);
885 if (print_files->f != NULL)
887 fclose (print_files->f);
888 print_files->f = NULL;
894 skip_to_line (p, line, true);
896 p->next = print_files;
904 f = fopen (filename, "r");
909 p = ((struct print_file_list *)
910 xmalloc (sizeof (struct print_file_list)));
911 p->filename = xmalloc (strlen (filename) + 1);
912 strcpy (p->filename, filename);
916 if (print_files != NULL && print_files->f != NULL)
918 fclose (print_files->f);
919 print_files->f = NULL;
921 p->next = print_files;
924 l = line - SHOW_PRECEDING_CONTEXT_LINES;
927 skip_to_line (p, l, false);
929 skip_to_line (p, line, true);
934 if (functionname != NULL
935 && (prev_functionname == NULL
936 || strcmp (functionname, prev_functionname) != 0))
938 if (prev_functionname != NULL)
939 free (prev_functionname);
940 prev_functionname = xmalloc (strlen (functionname) + 1);
941 strcpy (prev_functionname, functionname);
944 if (line > 0 && line != prev_line)
948 /* Pseudo FILE object for strings. */
954 /* sprintf to a "stream" */
956 #ifdef ANSI_PROTOTYPES
958 objdump_sprintf (SFILE *f, const char *format, ...)
963 va_start (args, format);
964 vsprintf (f->current, format, args);
965 f->current += n = strlen (f->current);
971 objdump_sprintf (va_alist)
980 f = va_arg (args, SFILE *);
981 format = va_arg (args, const char *);
982 vsprintf (f->current, format, args);
983 f->current += n = strlen (f->current);
989 /* The number of zeroes we want to see before we start skipping them.
990 The number is arbitrarily chosen. */
992 #define SKIP_ZEROES (8)
994 /* The number of zeroes to skip at the end of a section. If the
995 number of zeroes at the end is between SKIP_ZEROES_AT_END and
996 SKIP_ZEROES, they will be disassembled. If there are fewer than
997 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
998 attempt to avoid disassembling zeroes inserted by section
1001 #define SKIP_ZEROES_AT_END (3)
1003 /* Disassemble some data in memory between given values. */
1006 disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
1008 struct disassemble_info *info;
1009 disassembler_ftype disassemble_fn;
1017 struct objdump_disasm_info *aux;
1023 aux = (struct objdump_disasm_info *) info->application_data;
1029 bytes_per_line = 16;
1031 info->insn_info_valid = 0;
1039 boolean need_nl = false;
1041 /* If we see more than SKIP_ZEROES bytes of zeroes, we just
1043 for (z = i; z < stop; z++)
1046 if ((info->insn_info_valid == 0
1047 || info->branch_delay_insns == 0)
1048 && (z - i >= SKIP_ZEROES
1049 || (z == stop && z - i < SKIP_ZEROES_AT_END)))
1053 /* If there are more nonzero bytes to follow, we only skip
1054 zeroes in multiples of 4, to try to avoid running over
1055 the start of an instruction which happens to start with
1058 z = i + ((z - i) &~ 3);
1070 if (with_line_numbers || with_source_code)
1071 show_line (aux->abfd, section, i);
1073 if (! prefix_addresses)
1074 printf ("%6lx:\t", (unsigned long) (i - start));
1077 aux->require_sec = true;
1078 objdump_print_address (section->vma + i, info);
1079 aux->require_sec = false;
1085 sfile.buffer = sfile.current = buf;
1086 info->fprintf_func = (fprintf_ftype) objdump_sprintf;
1087 info->stream = (FILE *) &sfile;
1088 info->bytes_per_line = 0;
1089 bytes = (*disassemble_fn) (section->vma + i, info);
1090 info->fprintf_func = (fprintf_ftype) fprintf;
1091 info->stream = stdout;
1092 if (info->bytes_per_line != 0)
1093 bytes_per_line = info->bytes_per_line;
1101 bytes = bytes_per_line;
1102 if (i + bytes > stop)
1105 for (j = i; j < i + bytes; ++j)
1107 if (isprint (data[j]))
1108 buf[j - i] = data[j];
1115 if (! prefix_addresses || show_raw_insn)
1119 /* If ! prefix_addresses and ! wide_output, we print
1120 four bytes per line. */
1122 if (pb > bytes_per_line && ! prefix_addresses && ! wide_output)
1123 pb = bytes_per_line;
1125 for (j = i; j < i + pb; ++j)
1127 printf ("%02x", (unsigned) data[j]);
1131 for (; pb < bytes_per_line; ++pb)
1134 /* Separate raw data from instruction by extra space. */
1143 if (! prefix_addresses || show_raw_insn)
1151 printf ("%6lx:\t", (unsigned long) (j - start));
1152 pb += bytes_per_line;
1155 for (; j < i + pb; ++j)
1157 printf ("%02x", (unsigned) data[j]);
1170 && (section->flags & SEC_RELOC) != 0)
1172 while ((*relppp) < relppend
1173 && ((**relppp)->address >= (bfd_vma) i
1174 && (**relppp)->address < (bfd_vma) i + bytes))
1177 const char *sym_name;
1186 objdump_print_value (section->vma + q->address - start, info);
1188 printf (": %s\t", q->howto->name);
1190 if (q->sym_ptr_ptr != NULL
1191 && *q->sym_ptr_ptr != NULL)
1193 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
1194 if (sym_name == NULL || *sym_name == '\0')
1198 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
1199 sym_name = bfd_get_section_name (abfd, sym_sec);
1200 if (sym_name == NULL || *sym_name == '\0')
1201 sym_name = "*unknown*";
1205 sym_name = "*unknown*";
1207 printf ("%s", sym_name);
1212 objdump_print_value (q->addend, info);
1228 /* Disassemble the contents of an object file. */
1231 disassemble_data (abfd)
1235 disassembler_ftype disassemble_fn;
1236 struct disassemble_info disasm_info;
1237 struct objdump_disasm_info aux;
1241 prev_functionname = NULL;
1244 /* We make a copy of syms to sort. We don't want to sort syms
1245 because that will screw up the relocs. */
1246 sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
1247 memcpy (sorted_syms, syms, symcount * sizeof (asymbol *));
1249 sorted_symcount = remove_useless_symbols (sorted_syms, symcount);
1251 /* Sort the symbols into section and symbol order */
1252 qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
1254 INIT_DISASSEMBLE_INFO(disasm_info, stdout, fprintf);
1255 disasm_info.application_data = (PTR) &aux;
1257 disasm_info.print_address_func = objdump_print_address;
1259 if (machine != (char *) NULL)
1261 const bfd_arch_info_type *info = bfd_scan_arch (machine);
1264 fprintf (stderr, "%s: Can't use supplied machine %s\n",
1269 abfd->arch_info = info;
1272 if (endian != BFD_ENDIAN_UNKNOWN)
1274 struct bfd_target *xvec;
1276 xvec = (struct bfd_target *) xmalloc (sizeof (struct bfd_target));
1277 memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
1278 xvec->byteorder = endian;
1282 disassemble_fn = disassembler (abfd);
1283 if (!disassemble_fn)
1285 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
1287 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
1291 disasm_info.flavour = bfd_get_flavour (abfd);
1292 disasm_info.arch = bfd_get_arch (abfd);
1293 disasm_info.mach = bfd_get_mach (abfd);
1294 if (bfd_big_endian (abfd))
1295 disasm_info.endian = BFD_ENDIAN_BIG;
1296 else if (bfd_little_endian (abfd))
1297 disasm_info.endian = BFD_ENDIAN_LITTLE;
1299 /* ??? Aborting here seems too drastic. We could default to big or little
1301 disasm_info.endian = BFD_ENDIAN_UNKNOWN;
1303 for (section = abfd->sections;
1304 section != (asection *) NULL;
1305 section = section->next)
1307 bfd_byte *data = NULL;
1308 bfd_size_type datasize = 0;
1309 arelent **relbuf = NULL;
1310 arelent **relpp = NULL;
1311 arelent **relppend = NULL;
1314 if ((section->flags & SEC_LOAD) == 0
1315 || (! disassemble_all
1317 && (section->flags & SEC_CODE) == 0))
1319 if (only != (char *) NULL && strcmp (only, section->name) != 0)
1323 && (section->flags & SEC_RELOC) != 0)
1327 relsize = bfd_get_reloc_upper_bound (abfd, section);
1329 bfd_fatal (bfd_get_filename (abfd));
1335 relbuf = (arelent **) xmalloc (relsize);
1336 relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
1338 bfd_fatal (bfd_get_filename (abfd));
1340 /* Sort the relocs by address. */
1341 qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
1344 relppend = relpp + relcount;
1348 printf ("Disassembly of section %s:\n", section->name);
1350 datasize = bfd_get_section_size_before_reloc (section);
1354 data = (bfd_byte *) xmalloc ((size_t) datasize);
1356 bfd_get_section_contents (abfd, section, data, 0, datasize);
1359 disasm_info.buffer = data;
1360 disasm_info.buffer_vma = section->vma;
1361 disasm_info.buffer_length = datasize;
1362 if (start_address == (bfd_vma) -1
1363 || start_address < disasm_info.buffer_vma)
1366 i = start_address - disasm_info.buffer_vma;
1367 if (stop_address == (bfd_vma) -1)
1371 if (stop_address < disasm_info.buffer_vma)
1374 stop = stop_address - disasm_info.buffer_vma;
1375 if (stop > disasm_info.buffer_length)
1376 stop = disasm_info.buffer_length;
1379 if (prefix_addresses)
1380 disassemble_bytes (&disasm_info, disassemble_fn, true, data, i, stop,
1387 sym = find_symbol_for_address (abfd, section, i, true, &place);
1395 disasm_info.symbol = sym;
1398 objdump_print_addr_with_sym (abfd, section, sym,
1407 while (place < sorted_symcount
1408 && (sorted_syms[place]->section != section
1409 || (bfd_asymbol_value (sorted_syms[place])
1410 <= bfd_asymbol_value (sym))))
1412 if (place >= sorted_symcount)
1415 nextsym = sorted_syms[place];
1418 if (nextsym == NULL)
1422 nextstop = bfd_asymbol_value (nextsym) - section->vma;
1423 if (nextstop > stop)
1427 /* If a symbol is explicitly marked as being an object
1428 rather than a function, just dump the bytes without
1429 disassembling them. */
1432 || ((sym->flags & BSF_OBJECT) == 0
1433 && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
1435 && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
1437 || (sym->flags & BSF_FUNCTION) != 0)
1442 disassemble_bytes (&disasm_info, disassemble_fn, insns, data, i,
1443 nextstop, &relpp, relppend);
1458 /* Define a table of stab values and print-strings. We wish the initializer
1459 could be a direct-mapped table, but instead we build one the first
1462 static void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
1463 char *strsect_name));
1465 /* Dump the stabs sections from an object file that has a section that
1466 uses Sun stabs encoding. */
1472 dump_section_stabs (abfd, ".stab", ".stabstr");
1473 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
1474 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
1475 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
1478 static bfd_byte *stabs;
1479 static bfd_size_type stab_size;
1481 static char *strtab;
1482 static bfd_size_type stabstr_size;
1484 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
1485 and string table section STRSECT_NAME into `strtab'.
1486 If the section exists and was read, allocate the space and return true.
1487 Otherwise return false. */
1490 read_section_stabs (abfd, stabsect_name, strsect_name)
1492 char *stabsect_name;
1495 asection *stabsect, *stabstrsect;
1497 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
1500 printf ("No %s section present\n\n", stabsect_name);
1504 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
1505 if (0 == stabstrsect)
1507 fprintf (stderr, "%s: %s has no %s section\n", program_name,
1508 bfd_get_filename (abfd), strsect_name);
1512 stab_size = bfd_section_size (abfd, stabsect);
1513 stabstr_size = bfd_section_size (abfd, stabstrsect);
1515 stabs = (bfd_byte *) xmalloc (stab_size);
1516 strtab = (char *) xmalloc (stabstr_size);
1518 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
1520 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1521 program_name, stabsect_name, bfd_get_filename (abfd),
1522 bfd_errmsg (bfd_get_error ()));
1528 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
1531 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1532 program_name, strsect_name, bfd_get_filename (abfd),
1533 bfd_errmsg (bfd_get_error ()));
1542 /* Stabs entries use a 12 byte format:
1543 4 byte string table index
1545 1 byte stab other field
1546 2 byte stab desc field
1548 FIXME: This will have to change for a 64 bit object format. */
1550 #define STRDXOFF (0)
1552 #define OTHEROFF (5)
1555 #define STABSIZE (12)
1557 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1558 using string table section STRSECT_NAME (in `strtab'). */
1561 print_section_stabs (abfd, stabsect_name, strsect_name)
1563 char *stabsect_name;
1567 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
1568 bfd_byte *stabp, *stabs_end;
1571 stabs_end = stabp + stab_size;
1573 printf ("Contents of %s section:\n\n", stabsect_name);
1574 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
1576 /* Loop through all symbols and print them.
1578 We start the index at -1 because there is a dummy symbol on
1579 the front of stabs-in-{coff,elf} sections that supplies sizes. */
1581 for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++)
1585 unsigned char type, other;
1586 unsigned short desc;
1589 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
1590 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
1591 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
1592 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
1593 value = bfd_h_get_32 (abfd, stabp + VALOFF);
1595 printf ("\n%-6d ", i);
1596 /* Either print the stab name, or, if unnamed, print its number
1597 again (makes consistent formatting for tools like awk). */
1598 name = bfd_get_stab_name (type);
1600 printf ("%-6s", name);
1601 else if (type == N_UNDF)
1604 printf ("%-6d", type);
1605 printf (" %-6d %-6d ", other, desc);
1607 printf (" %-6lu", strx);
1609 /* Symbols with type == 0 (N_UNDF) specify the length of the
1610 string table associated with this file. We use that info
1611 to know how to relocate the *next* file's string table indices. */
1615 file_string_table_offset = next_file_string_table_offset;
1616 next_file_string_table_offset += value;
1620 /* Using the (possibly updated) string table offset, print the
1621 string (if any) associated with this symbol. */
1623 if ((strx + file_string_table_offset) < stabstr_size)
1624 printf (" %s", &strtab[strx + file_string_table_offset]);
1633 dump_section_stabs (abfd, stabsect_name, strsect_name)
1635 char *stabsect_name;
1640 /* Check for section names for which stabsect_name is a prefix, to
1641 handle .stab0, etc. */
1642 for (s = abfd->sections;
1648 len = strlen (stabsect_name);
1650 /* If the prefix matches, and the files section name ends with a nul or a digit,
1651 then we match. Ie: we want either an exact match or a a section followed by
1653 if (strncmp (stabsect_name, s->name, len) == 0
1654 && (s->name[len] == '\000' || isdigit (s->name[len])))
1656 if (read_section_stabs (abfd, s->name, strsect_name))
1658 print_section_stabs (abfd, s->name, strsect_name);
1667 dump_bfd_header (abfd)
1672 printf ("architecture: %s, ",
1673 bfd_printable_arch_mach (bfd_get_arch (abfd),
1674 bfd_get_mach (abfd)));
1675 printf ("flags 0x%08x:\n", abfd->flags);
1677 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
1678 PF (HAS_RELOC, "HAS_RELOC");
1679 PF (EXEC_P, "EXEC_P");
1680 PF (HAS_LINENO, "HAS_LINENO");
1681 PF (HAS_DEBUG, "HAS_DEBUG");
1682 PF (HAS_SYMS, "HAS_SYMS");
1683 PF (HAS_LOCALS, "HAS_LOCALS");
1684 PF (DYNAMIC, "DYNAMIC");
1685 PF (WP_TEXT, "WP_TEXT");
1686 PF (D_PAGED, "D_PAGED");
1687 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
1688 printf ("\nstart address 0x");
1689 printf_vma (abfd->start_address);
1694 dump_bfd_private_header (abfd)
1697 bfd_print_private_bfd_data (abfd, stdout);
1706 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
1708 bfd_nonfatal (bfd_get_filename (abfd));
1709 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
1711 list_matching_formats (matching);
1717 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
1720 print_arelt_descr (stdout, abfd, true);
1721 if (dump_file_header)
1722 dump_bfd_header (abfd);
1723 if (dump_private_headers)
1724 dump_bfd_private_header (abfd);
1726 if (dump_section_headers)
1727 dump_headers (abfd);
1728 if (dump_symtab || dump_reloc_info || disassemble || dump_debugging)
1730 syms = slurp_symtab (abfd);
1732 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
1734 dynsyms = slurp_dynamic_symtab (abfd);
1737 dump_symbols (abfd, false);
1738 if (dump_dynamic_symtab)
1739 dump_symbols (abfd, true);
1740 if (dump_stab_section_info)
1742 if (dump_reloc_info && ! disassemble)
1744 if (dump_dynamic_reloc_info)
1745 dump_dynamic_relocs (abfd);
1746 if (dump_section_contents)
1749 disassemble_data (abfd);
1754 dhandle = read_debugging_info (abfd, syms, symcount);
1755 if (dhandle != NULL)
1757 if (! print_debugging_info (stdout, dhandle))
1758 fprintf (stderr, "%s: printing debugging information failed\n",
1759 bfd_get_filename (abfd));
1775 display_file (filename, target)
1779 bfd *file, *arfile = (bfd *) NULL;
1781 file = bfd_openr (filename, target);
1784 bfd_nonfatal (filename);
1788 if (bfd_check_format (file, bfd_archive) == true)
1790 bfd *last_arfile = NULL;
1792 printf ("In archive %s:\n", bfd_get_filename (file));
1795 bfd_set_error (bfd_error_no_error);
1797 arfile = bfd_openr_next_archived_file (file, arfile);
1800 if (bfd_get_error () != bfd_error_no_more_archived_files)
1802 bfd_nonfatal (bfd_get_filename (file));
1807 display_bfd (arfile);
1809 if (last_arfile != NULL)
1810 bfd_close (last_arfile);
1811 last_arfile = arfile;
1814 if (last_arfile != NULL)
1815 bfd_close (last_arfile);
1823 /* Actually display the various requested regions */
1831 bfd_size_type datasize = 0;
1833 bfd_size_type start, stop;
1835 for (section = abfd->sections; section != NULL; section =
1840 if (only == (char *) NULL ||
1841 strcmp (only, section->name) == 0)
1843 if (section->flags & SEC_HAS_CONTENTS)
1845 printf ("Contents of section %s:\n", section->name);
1847 if (bfd_section_size (abfd, section) == 0)
1849 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
1850 datasize = bfd_section_size (abfd, section);
1853 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
1855 if (start_address == (bfd_vma) -1
1856 || start_address < section->vma)
1859 start = start_address - section->vma;
1860 if (stop_address == (bfd_vma) -1)
1861 stop = bfd_section_size (abfd, section);
1864 if (stop_address < section->vma)
1867 stop = stop_address - section->vma;
1868 if (stop > bfd_section_size (abfd, section))
1869 stop = bfd_section_size (abfd, section);
1871 for (i = start; i < stop; i += onaline)
1875 printf (" %04lx ", (unsigned long int) (i + section->vma));
1876 for (j = i; j < i + onaline; j++)
1879 printf ("%02x", (unsigned) (data[j]));
1887 for (j = i; j < i + onaline; j++)
1892 printf ("%c", isprint (data[j]) ? data[j] : '.');
1902 /* Should perhaps share code and display with nm? */
1904 dump_symbols (abfd, dynamic)
1918 printf ("DYNAMIC SYMBOL TABLE:\n");
1926 printf ("SYMBOL TABLE:\n");
1929 for (count = 0; count < max; count++)
1933 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1936 bfd_print_symbol (cur_bfd,
1938 *current, bfd_print_symbol_all);
1956 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1960 if (bfd_is_abs_section (a))
1962 if (bfd_is_und_section (a))
1964 if (bfd_is_com_section (a))
1969 if (strcmp (only, a->name))
1972 else if ((a->flags & SEC_RELOC) == 0)
1975 relsize = bfd_get_reloc_upper_bound (abfd, a);
1977 bfd_fatal (bfd_get_filename (abfd));
1979 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1983 printf (" (none)\n\n");
1987 relpp = (arelent **) xmalloc (relsize);
1988 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1990 bfd_fatal (bfd_get_filename (abfd));
1991 else if (relcount == 0)
1993 printf (" (none)\n\n");
1998 dump_reloc_set (abfd, a, relpp, relcount);
2007 dump_dynamic_relocs (abfd)
2014 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
2016 bfd_fatal (bfd_get_filename (abfd));
2018 printf ("DYNAMIC RELOCATION RECORDS");
2022 printf (" (none)\n\n");
2026 relpp = (arelent **) xmalloc (relsize);
2027 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
2029 bfd_fatal (bfd_get_filename (abfd));
2030 else if (relcount == 0)
2032 printf (" (none)\n\n");
2037 dump_reloc_set (abfd, (asection *) NULL, relpp, relcount);
2045 dump_reloc_set (abfd, sec, relpp, relcount)
2052 char *last_filename, *last_functionname;
2053 unsigned int last_line;
2055 /* Get column headers lined up reasonably. */
2061 sprintf_vma (buf, (bfd_vma) -1);
2062 width = strlen (buf) - 7;
2064 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
2067 last_filename = NULL;
2068 last_functionname = NULL;
2071 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
2074 const char *filename, *functionname;
2076 const char *sym_name;
2077 const char *section_name;
2079 if (start_address != (bfd_vma) -1
2080 && q->address < start_address)
2082 if (stop_address != (bfd_vma) -1
2083 && q->address > stop_address)
2086 if (with_line_numbers
2088 && bfd_find_nearest_line (abfd, sec, syms, q->address,
2089 &filename, &functionname, &line))
2091 if (functionname != NULL
2092 && (last_functionname == NULL
2093 || strcmp (functionname, last_functionname) != 0))
2095 printf ("%s():\n", functionname);
2096 if (last_functionname != NULL)
2097 free (last_functionname);
2098 last_functionname = xstrdup (functionname);
2101 && (line != last_line
2102 || (filename != NULL
2103 && last_filename != NULL
2104 && strcmp (filename, last_filename) != 0)))
2106 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
2108 if (last_filename != NULL)
2109 free (last_filename);
2110 if (filename == NULL)
2111 last_filename = NULL;
2113 last_filename = xstrdup (filename);
2117 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
2119 sym_name = (*(q->sym_ptr_ptr))->name;
2120 section_name = (*(q->sym_ptr_ptr))->section->name;
2125 section_name = NULL;
2129 printf_vma (q->address);
2130 printf (" %-16s %s",
2136 if (section_name == (CONST char *) NULL)
2137 section_name = "*unknown*";
2138 printf_vma (q->address);
2139 printf (" %-16s [%s]",
2146 printf_vma (q->addend);
2152 /* The length of the longest architecture name + 1. */
2153 #define LONGEST_ARCH sizeof("rs6000:6000")
2156 endian_string (endian)
2157 enum bfd_endian endian;
2159 if (endian == BFD_ENDIAN_BIG)
2160 return "big endian";
2161 else if (endian == BFD_ENDIAN_LITTLE)
2162 return "little endian";
2164 return "endianness unknown";
2167 /* List the targets that BFD is configured to support, each followed
2168 by its endianness and the architectures it supports. */
2171 display_target_list ()
2173 extern bfd_target *bfd_target_vector[];
2177 dummy_name = choose_temp_base ();
2178 for (t = 0; bfd_target_vector[t]; t++)
2180 bfd_target *p = bfd_target_vector[t];
2181 bfd *abfd = bfd_openw (dummy_name, p->name);
2184 printf ("%s\n (header %s, data %s)\n", p->name,
2185 endian_string (p->header_byteorder),
2186 endian_string (p->byteorder));
2190 bfd_nonfatal (dummy_name);
2194 if (! bfd_set_format (abfd, bfd_object))
2196 if (bfd_get_error () != bfd_error_invalid_operation)
2197 bfd_nonfatal (p->name);
2201 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
2202 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
2204 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
2206 unlink (dummy_name);
2210 /* Print a table showing which architectures are supported for entries
2211 FIRST through LAST-1 of bfd_target_vector (targets across,
2212 architectures down). */
2215 display_info_table (first, last)
2219 extern bfd_target *bfd_target_vector[];
2223 /* Print heading of target names. */
2224 printf ("\n%*s", (int) LONGEST_ARCH, " ");
2225 for (t = first; t < last && bfd_target_vector[t]; t++)
2226 printf ("%s ", bfd_target_vector[t]->name);
2229 dummy_name = choose_temp_base ();
2230 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
2231 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
2233 printf ("%*s ", (int) LONGEST_ARCH - 1,
2234 bfd_printable_arch_mach (a, 0));
2235 for (t = first; t < last && bfd_target_vector[t]; t++)
2237 bfd_target *p = bfd_target_vector[t];
2239 bfd *abfd = bfd_openw (dummy_name, p->name);
2243 bfd_nonfatal (p->name);
2249 if (! bfd_set_format (abfd, bfd_object))
2251 if (bfd_get_error () != bfd_error_invalid_operation)
2252 bfd_nonfatal (p->name);
2259 if (! bfd_set_arch_mach (abfd, a, 0))
2264 printf ("%s ", p->name);
2267 int l = strlen (p->name);
2275 unlink (dummy_name);
2279 /* Print tables of all the target-architecture combinations that
2280 BFD has been configured to support. */
2283 display_target_tables ()
2286 extern bfd_target *bfd_target_vector[];
2288 extern char *getenv ();
2291 colum = getenv ("COLUMNS");
2293 columns = atoi (colum);
2298 while (bfd_target_vector[t] != NULL)
2302 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
2304 while (wid < columns && bfd_target_vector[t] != NULL)
2308 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
2309 if (newwid >= columns)
2314 display_info_table (oldt, t);
2321 printf ("BFD header file version %s\n", BFD_VERSION);
2322 display_target_list ();
2323 display_target_tables ();
2332 char *target = default_target;
2333 boolean seenflag = false;
2335 program_name = *argv;
2336 xmalloc_set_program_name (program_name);
2338 START_PROGRESS (program_name, 0);
2342 while ((c = getopt_long (argc, argv, "pib:m:VdDlfahrRtTxsSj:wE:",
2343 long_options, (int *) 0))
2346 if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS)
2351 break; /* we've been given a long option */
2359 with_line_numbers = 1;
2365 dump_file_header = true;
2368 formats_info = true;
2371 dump_private_headers = 1;
2374 dump_private_headers = 1;
2376 dump_reloc_info = 1;
2377 dump_file_header = true;
2379 dump_section_headers = 1;
2385 dump_dynamic_symtab = 1;
2391 disassemble = disassemble_all = true;
2395 with_source_code = true;
2398 dump_section_contents = 1;
2401 dump_reloc_info = 1;
2404 dump_dynamic_reloc_info = 1;
2410 dump_section_headers = 1;
2420 case OPTION_START_ADDRESS:
2421 start_address = parse_vma (optarg, "--start-address");
2423 case OPTION_STOP_ADDRESS:
2424 stop_address = parse_vma (optarg, "--stop-address");
2427 if (strcmp (optarg, "B") == 0)
2428 endian = BFD_ENDIAN_BIG;
2429 else if (strcmp (optarg, "L") == 0)
2430 endian = BFD_ENDIAN_LITTLE;
2433 fprintf (stderr, "%s: unrecognized -E option\n", program_name);
2438 if (strncmp (optarg, "big", strlen (optarg)) == 0)
2439 endian = BFD_ENDIAN_BIG;
2440 else if (strncmp (optarg, "little", strlen (optarg)) == 0)
2441 endian = BFD_ENDIAN_LITTLE;
2444 fprintf (stderr, "%s: unrecognized --endian type `%s'\n",
2445 program_name, optarg);
2455 print_version ("objdump");
2457 if (seenflag == false)
2467 display_file ("a.out", target);
2469 for (; optind < argc;)
2470 display_file (argv[optind++], target);
2473 END_PROGRESS (program_name);