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
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
57 #include "safe-ctype.h"
59 #include "libiberty.h"
64 /* Internal headers for the ELF .stab-dump code - sorry. */
65 #define BYTES_IN_WORD 32
66 #include "aout/aout64.h"
68 #ifdef NEED_DECLARATION_FPRINTF
69 /* This is needed by init_disassemble_info(). */
70 extern int fprintf (FILE *, const char *, ...);
74 static int exit_status
= 0;
76 static char *default_target
= NULL
; /* Default at runtime. */
78 /* The following variables are set based on arguments passed on the
80 static int show_version
= 0; /* Show the version number. */
81 static int dump_section_contents
; /* -s */
82 static int dump_section_headers
; /* -h */
83 static bfd_boolean dump_file_header
; /* -f */
84 static int dump_symtab
; /* -t */
85 static int dump_dynamic_symtab
; /* -T */
86 static int dump_reloc_info
; /* -r */
87 static int dump_dynamic_reloc_info
; /* -R */
88 static int dump_ar_hdrs
; /* -a */
89 static int dump_private_headers
; /* -p */
90 static int prefix_addresses
; /* --prefix-addresses */
91 static int with_line_numbers
; /* -l */
92 static bfd_boolean with_source_code
; /* -S */
93 static int show_raw_insn
; /* --show-raw-insn */
94 static int dump_stab_section_info
; /* --stabs */
95 static int do_demangle
; /* -C, --demangle */
96 static bfd_boolean disassemble
; /* -d */
97 static bfd_boolean disassemble_all
; /* -D */
98 static int disassemble_zeroes
; /* --disassemble-zeroes */
99 static bfd_boolean formats_info
; /* -i */
100 static int wide_output
; /* -w */
101 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
102 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
103 static int dump_debugging
; /* --debugging */
104 static int dump_debugging_tags
; /* --debugging-tags */
105 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
106 static int file_start_context
= 0; /* --file-start-context */
108 /* Pointer to an array of section names provided by
109 one or more "-j secname" command line options. */
111 /* The total number of slots in the only[] array. */
112 static size_t only_size
= 0;
113 /* The number of occupied slots in the only[] array. */
114 static size_t only_used
= 0;
116 /* Variables for handling include file path table. */
117 static const char **include_paths
;
118 static int include_path_count
;
120 /* Extra info to pass to the section disassembler and address printing
122 struct objdump_disasm_info
126 bfd_boolean require_sec
;
127 arelent
** dynrelbuf
;
129 disassembler_ftype disassemble_fn
;
132 /* Architecture to disassemble for, or default if NULL. */
133 static char *machine
= NULL
;
135 /* Target specific options to the disassembler. */
136 static char *disassembler_options
= NULL
;
138 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
139 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
141 /* The symbol table. */
142 static asymbol
**syms
;
144 /* Number of symbols in `syms'. */
145 static long symcount
= 0;
147 /* The sorted symbol table. */
148 static asymbol
**sorted_syms
;
150 /* Number of symbols in `sorted_syms'. */
151 static long sorted_symcount
= 0;
153 /* The dynamic symbol table. */
154 static asymbol
**dynsyms
;
156 /* The synthetic symbol table. */
157 static asymbol
*synthsyms
;
158 static long synthcount
= 0;
160 /* Number of symbols in `dynsyms'. */
161 static long dynsymcount
= 0;
163 static bfd_byte
*stabs
;
164 static bfd_size_type stab_size
;
167 static bfd_size_type stabstr_size
;
170 usage (FILE *stream
, int status
)
172 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
173 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
174 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
175 fprintf (stream
, _("\
176 -a, --archive-headers Display archive header information\n\
177 -f, --file-headers Display the contents of the overall file header\n\
178 -p, --private-headers Display object format specific file header contents\n\
179 -h, --[section-]headers Display the contents of the section headers\n\
180 -x, --all-headers Display the contents of all headers\n\
181 -d, --disassemble Display assembler contents of executable sections\n\
182 -D, --disassemble-all Display assembler contents of all sections\n\
183 -S, --source Intermix source code with disassembly\n\
184 -s, --full-contents Display the full contents of all sections requested\n\
185 -g, --debugging Display debug information in object file\n\
186 -e, --debugging-tags Display debug information using ctags style\n\
187 -G, --stabs Display (in raw form) any STABS info in the file\n\
188 -t, --syms Display the contents of the symbol table(s)\n\
189 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
190 -r, --reloc Display the relocation entries in the file\n\
191 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
192 -v, --version Display this program's version number\n\
193 -i, --info List object formats and architectures supported\n\
194 -H, --help Display this information\n\
198 fprintf (stream
, _("\n The following switches are optional:\n"));
199 fprintf (stream
, _("\
200 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
201 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
202 -j, --section=NAME Only display information for section NAME\n\
203 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
204 -EB --endian=big Assume big endian format when disassembling\n\
205 -EL --endian=little Assume little endian format when disassembling\n\
206 --file-start-context Include context from start of file (with -S)\n\
207 -I, --include=DIR Add DIR to search list for source files\n\
208 -l, --line-numbers Include line numbers and filenames in output\n\
209 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
210 The STYLE, if specified, can be `auto', `gnu',\n\
211 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
213 -w, --wide Format output for more than 80 columns\n\
214 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
215 --start-address=ADDR Only process data whose address is >= ADDR\n\
216 --stop-address=ADDR Only process data whose address is <= ADDR\n\
217 --prefix-addresses Print complete address alongside disassembly\n\
218 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
219 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
221 list_supported_targets (program_name
, stream
);
222 list_supported_architectures (program_name
, stream
);
224 disassembler_usage (stream
);
227 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
231 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
235 OPTION_START_ADDRESS
,
240 static struct option long_options
[]=
242 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
243 {"all-headers", no_argument
, NULL
, 'x'},
244 {"private-headers", no_argument
, NULL
, 'p'},
245 {"architecture", required_argument
, NULL
, 'm'},
246 {"archive-headers", no_argument
, NULL
, 'a'},
247 {"debugging", no_argument
, NULL
, 'g'},
248 {"debugging-tags", no_argument
, NULL
, 'e'},
249 {"demangle", optional_argument
, NULL
, 'C'},
250 {"disassemble", no_argument
, NULL
, 'd'},
251 {"disassemble-all", no_argument
, NULL
, 'D'},
252 {"disassembler-options", required_argument
, NULL
, 'M'},
253 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
254 {"dynamic-reloc", no_argument
, NULL
, 'R'},
255 {"dynamic-syms", no_argument
, NULL
, 'T'},
256 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
257 {"file-headers", no_argument
, NULL
, 'f'},
258 {"file-start-context", no_argument
, &file_start_context
, 1},
259 {"full-contents", no_argument
, NULL
, 's'},
260 {"headers", no_argument
, NULL
, 'h'},
261 {"help", no_argument
, NULL
, 'H'},
262 {"info", no_argument
, NULL
, 'i'},
263 {"line-numbers", no_argument
, NULL
, 'l'},
264 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
265 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
266 {"reloc", no_argument
, NULL
, 'r'},
267 {"section", required_argument
, NULL
, 'j'},
268 {"section-headers", no_argument
, NULL
, 'h'},
269 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
270 {"source", no_argument
, NULL
, 'S'},
271 {"include", required_argument
, NULL
, 'I'},
272 {"stabs", no_argument
, NULL
, 'G'},
273 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
274 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
275 {"syms", no_argument
, NULL
, 't'},
276 {"target", required_argument
, NULL
, 'b'},
277 {"version", no_argument
, NULL
, 'V'},
278 {"wide", no_argument
, NULL
, 'w'},
279 {0, no_argument
, 0, 0}
283 nonfatal (const char *msg
)
290 dump_section_header (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
291 void *ignored ATTRIBUTE_UNUSED
)
294 unsigned int opb
= bfd_octets_per_byte (abfd
);
296 printf ("%3d %-13s %08lx ", section
->index
,
297 bfd_get_section_name (abfd
, section
),
298 (unsigned long) bfd_section_size (abfd
, section
) / opb
);
299 bfd_printf_vma (abfd
, bfd_get_section_vma (abfd
, section
));
301 bfd_printf_vma (abfd
, section
->lma
);
302 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
303 bfd_get_section_alignment (abfd
, section
));
309 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
311 PF (SEC_HAS_CONTENTS
, "CONTENTS");
312 PF (SEC_ALLOC
, "ALLOC");
313 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
314 PF (SEC_LOAD
, "LOAD");
315 PF (SEC_RELOC
, "RELOC");
316 PF (SEC_READONLY
, "READONLY");
317 PF (SEC_CODE
, "CODE");
318 PF (SEC_DATA
, "DATA");
320 PF (SEC_DEBUGGING
, "DEBUGGING");
321 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
322 PF (SEC_EXCLUDE
, "EXCLUDE");
323 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
324 PF (SEC_BLOCK
, "BLOCK");
325 PF (SEC_CLINK
, "CLINK");
326 PF (SEC_SMALL_DATA
, "SMALL_DATA");
327 PF (SEC_SHARED
, "SHARED");
328 PF (SEC_ARCH_BIT_0
, "ARCH_BIT_0");
329 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
331 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
334 struct coff_comdat_info
*comdat
;
336 switch (section
->flags
& SEC_LINK_DUPLICATES
)
340 case SEC_LINK_DUPLICATES_DISCARD
:
341 ls
= "LINK_ONCE_DISCARD";
343 case SEC_LINK_DUPLICATES_ONE_ONLY
:
344 ls
= "LINK_ONCE_ONE_ONLY";
346 case SEC_LINK_DUPLICATES_SAME_SIZE
:
347 ls
= "LINK_ONCE_SAME_SIZE";
349 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
350 ls
= "LINK_ONCE_SAME_CONTENTS";
353 printf ("%s%s", comma
, ls
);
355 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
357 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
367 dump_headers (bfd
*abfd
)
369 printf (_("Sections:\n"));
372 printf (_("Idx Name Size VMA LMA File off Algn"));
374 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
375 if (bfd_get_arch_size (abfd
) == 32)
376 printf (_("Idx Name Size VMA LMA File off Algn"));
378 printf (_("Idx Name Size VMA LMA File off Algn"));
382 printf (_(" Flags"));
383 if (abfd
->flags
& HAS_LOAD_PAGE
)
387 bfd_map_over_sections (abfd
, dump_section_header
, NULL
);
391 slurp_symtab (bfd
*abfd
)
396 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
402 storage
= bfd_get_symtab_upper_bound (abfd
);
404 bfd_fatal (bfd_get_filename (abfd
));
406 sy
= xmalloc (storage
);
408 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
410 bfd_fatal (bfd_get_filename (abfd
));
414 /* Read in the dynamic symbols. */
417 slurp_dynamic_symtab (bfd
*abfd
)
422 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
425 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
427 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
432 bfd_fatal (bfd_get_filename (abfd
));
435 sy
= xmalloc (storage
);
437 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
439 bfd_fatal (bfd_get_filename (abfd
));
443 /* Filter out (in place) symbols that are useless for disassembly.
444 COUNT is the number of elements in SYMBOLS.
445 Return the number of useful symbols. */
448 remove_useless_symbols (asymbol
**symbols
, long count
)
450 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
454 asymbol
*sym
= *in_ptr
++;
456 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
458 if (sym
->flags
& (BSF_DEBUGGING
))
460 if (bfd_is_und_section (sym
->section
)
461 || bfd_is_com_section (sym
->section
))
466 return out_ptr
- symbols
;
469 /* Sort symbols into value order. */
472 compare_symbols (const void *ap
, const void *bp
)
474 const asymbol
*a
= * (const asymbol
**) ap
;
475 const asymbol
*b
= * (const asymbol
**) bp
;
485 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
487 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
490 if (a
->section
> b
->section
)
492 else if (a
->section
< b
->section
)
495 an
= bfd_asymbol_name (a
);
496 bn
= bfd_asymbol_name (b
);
500 /* The symbols gnu_compiled and gcc2_compiled convey no real
501 information, so put them after other symbols with the same value. */
502 af
= (strstr (an
, "gnu_compiled") != NULL
503 || strstr (an
, "gcc2_compiled") != NULL
);
504 bf
= (strstr (bn
, "gnu_compiled") != NULL
505 || strstr (bn
, "gcc2_compiled") != NULL
);
512 /* We use a heuristic for the file name, to try to sort it after
513 more useful symbols. It may not work on non Unix systems, but it
514 doesn't really matter; the only difference is precisely which
515 symbol names get printed. */
517 #define file_symbol(s, sn, snl) \
518 (((s)->flags & BSF_FILE) != 0 \
519 || ((sn)[(snl) - 2] == '.' \
520 && ((sn)[(snl) - 1] == 'o' \
521 || (sn)[(snl) - 1] == 'a')))
523 af
= file_symbol (a
, an
, anl
);
524 bf
= file_symbol (b
, bn
, bnl
);
531 /* Try to sort global symbols before local symbols before function
532 symbols before debugging symbols. */
537 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
539 if ((aflags
& BSF_DEBUGGING
) != 0)
544 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
546 if ((aflags
& BSF_FUNCTION
) != 0)
551 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
553 if ((aflags
& BSF_LOCAL
) != 0)
558 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
560 if ((aflags
& BSF_GLOBAL
) != 0)
566 /* Symbols that start with '.' might be section names, so sort them
567 after symbols that don't start with '.'. */
568 if (an
[0] == '.' && bn
[0] != '.')
570 if (an
[0] != '.' && bn
[0] == '.')
573 /* Finally, if we can't distinguish them in any other way, try to
574 get consistent results by sorting the symbols by name. */
575 return strcmp (an
, bn
);
578 /* Sort relocs into address order. */
581 compare_relocs (const void *ap
, const void *bp
)
583 const arelent
*a
= * (const arelent
**) ap
;
584 const arelent
*b
= * (const arelent
**) bp
;
586 if (a
->address
> b
->address
)
588 else if (a
->address
< b
->address
)
591 /* So that associated relocations tied to the same address show up
592 in the correct order, we don't do any further sorting. */
601 /* Print an address (VMA) to the output stream in INFO.
602 If SKIP_ZEROES is TRUE, omit leading zeroes. */
605 objdump_print_value (bfd_vma vma
, struct disassemble_info
*info
,
606 bfd_boolean skip_zeroes
)
610 struct objdump_disasm_info
*aux
;
612 aux
= (struct objdump_disasm_info
*) info
->application_data
;
613 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
618 for (p
= buf
; *p
== '0'; ++p
)
623 (*info
->fprintf_func
) (info
->stream
, "%s", p
);
626 /* Print the name of a symbol. */
629 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*info
,
636 name
= bfd_asymbol_name (sym
);
637 if (do_demangle
&& name
[0] != '\0')
639 /* Demangle the name. */
640 alloc
= demangle (abfd
, name
);
645 (*info
->fprintf_func
) (info
->stream
, "%s", name
);
653 /* Locate a symbol given a bfd and a section (from INFO->application_data),
654 and a VMA. If INFO->application_data->require_sec is TRUE, then always
655 require the symbol to be in the section. Returns NULL if there is no
656 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
657 of the symbol in sorted_syms. */
660 find_symbol_for_address (bfd_vma vma
,
661 struct disassemble_info
*info
,
664 /* @@ Would it speed things up to cache the last two symbols returned,
665 and maybe their address ranges? For many processors, only one memory
666 operand can be present at a time, so the 2-entry cache wouldn't be
667 constantly churned by code doing heavy memory accesses. */
669 /* Indices in `sorted_syms'. */
671 long max
= sorted_symcount
;
673 struct objdump_disasm_info
*aux
;
678 if (sorted_symcount
< 1)
681 aux
= (struct objdump_disasm_info
*) info
->application_data
;
684 opb
= bfd_octets_per_byte (abfd
);
686 /* Perform a binary search looking for the closest symbol to the
687 required value. We are searching the range (min, max]. */
688 while (min
+ 1 < max
)
692 thisplace
= (max
+ min
) / 2;
693 sym
= sorted_syms
[thisplace
];
695 if (bfd_asymbol_value (sym
) > vma
)
697 else if (bfd_asymbol_value (sym
) < vma
)
706 /* The symbol we want is now in min, the low end of the range we
707 were searching. If there are several symbols with the same
708 value, we want the first one. */
711 && (bfd_asymbol_value (sorted_syms
[thisplace
])
712 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
715 /* If the file is relocatable, and the symbol could be from this
716 section, prefer a symbol from this section over symbols from
717 others, even if the other symbol's value might be closer.
719 Note that this may be wrong for some symbol references if the
720 sections have overlapping memory ranges, but in that case there's
721 no way to tell what's desired without looking at the relocation
723 if (sorted_syms
[thisplace
]->section
!= sec
725 || ((abfd
->flags
& HAS_RELOC
) != 0
726 && vma
>= bfd_get_section_vma (abfd
, sec
)
727 && vma
< (bfd_get_section_vma (abfd
, sec
)
728 + bfd_section_size (abfd
, sec
) / opb
))))
732 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
734 if (bfd_asymbol_value (sorted_syms
[i
])
735 != bfd_asymbol_value (sorted_syms
[thisplace
]))
743 if (sorted_syms
[i
]->section
== sec
745 || sorted_syms
[i
- 1]->section
!= sec
746 || (bfd_asymbol_value (sorted_syms
[i
])
747 != bfd_asymbol_value (sorted_syms
[i
- 1]))))
754 if (sorted_syms
[thisplace
]->section
!= sec
)
756 /* We didn't find a good symbol with a smaller value.
757 Look for one with a larger value. */
758 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
760 if (sorted_syms
[i
]->section
== sec
)
768 if (sorted_syms
[thisplace
]->section
!= sec
770 || ((abfd
->flags
& HAS_RELOC
) != 0
771 && vma
>= bfd_get_section_vma (abfd
, sec
)
772 && vma
< (bfd_get_section_vma (abfd
, sec
)
773 + bfd_section_size (abfd
, sec
)))))
774 /* There is no suitable symbol. */
778 /* Give the target a chance to reject the symbol. */
779 while (! info
->symbol_is_valid (sorted_syms
[thisplace
], info
))
782 if (thisplace
>= sorted_symcount
783 || bfd_asymbol_value (sorted_syms
[thisplace
]) > vma
)
790 return sorted_syms
[thisplace
];
793 /* Print an address and the offset to the nearest symbol. */
796 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
797 bfd_vma vma
, struct disassemble_info
*info
,
798 bfd_boolean skip_zeroes
)
800 objdump_print_value (vma
, info
, skip_zeroes
);
806 (*info
->fprintf_func
) (info
->stream
, " <%s",
807 bfd_get_section_name (abfd
, sec
));
808 secaddr
= bfd_get_section_vma (abfd
, sec
);
811 (*info
->fprintf_func
) (info
->stream
, "-0x");
812 objdump_print_value (secaddr
- vma
, info
, TRUE
);
814 else if (vma
> secaddr
)
816 (*info
->fprintf_func
) (info
->stream
, "+0x");
817 objdump_print_value (vma
- secaddr
, info
, TRUE
);
819 (*info
->fprintf_func
) (info
->stream
, ">");
823 (*info
->fprintf_func
) (info
->stream
, " <");
824 objdump_print_symname (abfd
, info
, sym
);
825 if (bfd_asymbol_value (sym
) > vma
)
827 (*info
->fprintf_func
) (info
->stream
, "-0x");
828 objdump_print_value (bfd_asymbol_value (sym
) - vma
, info
, TRUE
);
830 else if (vma
> bfd_asymbol_value (sym
))
832 (*info
->fprintf_func
) (info
->stream
, "+0x");
833 objdump_print_value (vma
- bfd_asymbol_value (sym
), info
, TRUE
);
835 (*info
->fprintf_func
) (info
->stream
, ">");
839 /* Print an address (VMA), symbolically if possible.
840 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
843 objdump_print_addr (bfd_vma vma
,
844 struct disassemble_info
*info
,
845 bfd_boolean skip_zeroes
)
847 struct objdump_disasm_info
*aux
;
850 if (sorted_symcount
< 1)
852 (*info
->fprintf_func
) (info
->stream
, "0x");
853 objdump_print_value (vma
, info
, skip_zeroes
);
857 aux
= (struct objdump_disasm_info
*) info
->application_data
;
858 sym
= find_symbol_for_address (vma
, info
, NULL
);
859 objdump_print_addr_with_sym (aux
->abfd
, aux
->sec
, sym
, vma
, info
,
863 /* Print VMA to INFO. This function is passed to the disassembler
867 objdump_print_address (bfd_vma vma
, struct disassemble_info
*info
)
869 objdump_print_addr (vma
, info
, ! prefix_addresses
);
872 /* Determine of the given address has a symbol associated with it. */
875 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* info
)
879 sym
= find_symbol_for_address (vma
, info
, NULL
);
881 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
884 /* Hold the last function name and the last line number we displayed
887 static char *prev_functionname
;
888 static unsigned int prev_line
;
890 /* We keep a list of all files that we have seen when doing a
891 disassembly with source, so that we know how much of the file to
892 display. This can be important for inlined functions. */
894 struct print_file_list
896 struct print_file_list
*next
;
897 const char *filename
;
903 static struct print_file_list
*print_files
;
905 /* The number of preceding context lines to show when we start
906 displaying a file for the first time. */
908 #define SHOW_PRECEDING_CONTEXT_LINES (5)
910 /* Tries to open MODNAME, and if successful adds a node to print_files
911 linked list and returns that node. Returns NULL on failure. */
913 static struct print_file_list
*
914 try_print_file_open (const char *origname
, const char *modname
)
916 struct print_file_list
*p
;
919 f
= fopen (modname
, "r");
923 if (print_files
!= NULL
&& print_files
->f
!= NULL
)
925 fclose (print_files
->f
);
926 print_files
->f
= NULL
;
929 p
= xmalloc (sizeof (struct print_file_list
));
930 p
->filename
= origname
;
931 p
->modname
= modname
;
934 p
->next
= print_files
;
939 /* If the the source file, as described in the symtab, is not found
940 try to locate it in one of the paths specified with -I
941 If found, add location to print_files linked list. */
943 static struct print_file_list
*
944 update_source_path (const char *filename
)
946 struct print_file_list
*p
;
950 if (filename
== NULL
)
953 p
= try_print_file_open (filename
, filename
);
957 if (include_path_count
== 0)
960 /* Get the name of the file. */
961 fname
= strrchr (filename
, '/');
962 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
964 /* We could have a mixed forward/back slash case. */
965 char *backslash
= strrchr (filename
, '\\');
966 if (fname
== NULL
|| (backslash
!= NULL
&& backslash
> fname
))
968 if (fname
== NULL
&& filename
[0] != '\0' && filename
[1] == ':')
969 fname
= filename
+ 1;
977 /* If file exists under a new path, we need to add it to the list
978 so that show_line knows about it. */
979 for (i
= 0; i
< include_path_count
; i
++)
981 char *modname
= concat (include_paths
[i
], "/", fname
, (const char *) 0);
983 p
= try_print_file_open (filename
, modname
);
993 /* Skip ahead to a given line in a file, optionally printing each
997 skip_to_line (struct print_file_list
*p
, unsigned int line
,
1000 while (p
->line
< line
)
1004 if (fgets (buf
, sizeof buf
, p
->f
) == NULL
)
1014 if (strchr (buf
, '\n') != NULL
)
1019 /* Show the line number, or the source line, in a disassembly
1023 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1025 const char *filename
;
1026 const char *functionname
;
1029 if (! with_line_numbers
&& ! with_source_code
)
1032 if (! bfd_find_nearest_line (abfd
, section
, syms
, addr_offset
, &filename
,
1033 &functionname
, &line
))
1036 if (filename
!= NULL
&& *filename
== '\0')
1038 if (functionname
!= NULL
&& *functionname
== '\0')
1039 functionname
= NULL
;
1041 if (with_line_numbers
)
1043 if (functionname
!= NULL
1044 && (prev_functionname
== NULL
1045 || strcmp (functionname
, prev_functionname
) != 0))
1046 printf ("%s():\n", functionname
);
1047 if (line
> 0 && line
!= prev_line
)
1048 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
1051 if (with_source_code
1055 struct print_file_list
**pp
, *p
;
1057 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1058 if (strcmp ((*pp
)->filename
, filename
) == 0)
1064 if (p
!= print_files
)
1068 /* We have reencountered a file name which we saw
1069 earlier. This implies that either we are dumping out
1070 code from an included file, or the same file was
1071 linked in more than once. There are two common cases
1072 of an included file: inline functions in a header
1073 file, and a bison or flex skeleton file. In the
1074 former case we want to just start printing (but we
1075 back up a few lines to give context); in the latter
1076 case we want to continue from where we left off. I
1077 can't think of a good way to distinguish the cases,
1078 so I used a heuristic based on the file name. */
1079 if (strcmp (p
->filename
+ strlen (p
->filename
) - 2, ".h") != 0)
1083 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
1090 p
->f
= fopen (p
->modname
, "r");
1094 skip_to_line (p
, l
, FALSE
);
1096 if (print_files
->f
!= NULL
)
1098 fclose (print_files
->f
);
1099 print_files
->f
= NULL
;
1105 skip_to_line (p
, line
, TRUE
);
1107 p
->next
= print_files
;
1113 p
= update_source_path (filename
);
1119 if (file_start_context
)
1122 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
1125 skip_to_line (p
, l
, FALSE
);
1127 skip_to_line (p
, line
, TRUE
);
1132 if (functionname
!= NULL
1133 && (prev_functionname
== NULL
1134 || strcmp (functionname
, prev_functionname
) != 0))
1136 if (prev_functionname
!= NULL
)
1137 free (prev_functionname
);
1138 prev_functionname
= xmalloc (strlen (functionname
) + 1);
1139 strcpy (prev_functionname
, functionname
);
1142 if (line
> 0 && line
!= prev_line
)
1146 /* Pseudo FILE object for strings. */
1154 /* sprintf to a "stream". */
1157 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1164 size_t space
= f
->alloc
- f
->pos
;
1166 va_start (args
, format
);
1167 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1173 f
->alloc
= (f
->alloc
+ n
) * 2;
1174 f
->buffer
= xrealloc (f
->buffer
, f
->alloc
);
1181 /* Returns TRUE if the specified section should be dumped. */
1184 process_section_p (asection
* section
)
1191 for (i
= 0; i
< only_used
; i
++)
1192 if (strcmp (only
[i
], section
->name
) == 0)
1199 /* The number of zeroes we want to see before we start skipping them.
1200 The number is arbitrarily chosen. */
1203 #define SKIP_ZEROES (8)
1206 /* The number of zeroes to skip at the end of a section. If the
1207 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1208 SKIP_ZEROES, they will be disassembled. If there are fewer than
1209 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1210 attempt to avoid disassembling zeroes inserted by section
1213 #ifndef SKIP_ZEROES_AT_END
1214 #define SKIP_ZEROES_AT_END (3)
1217 /* Disassemble some data in memory between given values. */
1220 disassemble_bytes (struct disassemble_info
* info
,
1221 disassembler_ftype disassemble_fn
,
1224 bfd_vma start_offset
,
1225 bfd_vma stop_offset
,
1228 arelent
** relppend
)
1230 struct objdump_disasm_info
*aux
;
1232 int octets_per_line
;
1233 bfd_boolean done_dot
;
1234 int skip_addr_chars
;
1235 bfd_vma addr_offset
;
1236 int opb
= info
->octets_per_byte
;
1239 aux
= (struct objdump_disasm_info
*) info
->application_data
;
1243 sfile
.buffer
= xmalloc (sfile
.alloc
);
1247 octets_per_line
= 4;
1249 octets_per_line
= 16;
1251 /* Figure out how many characters to skip at the start of an
1252 address, to make the disassembly look nicer. We discard leading
1253 zeroes in chunks of 4, ensuring that there is always a leading
1255 skip_addr_chars
= 0;
1256 if (! prefix_addresses
)
1264 + bfd_section_size (section
->owner
, section
) / opb
));
1266 while (s
[0] == '0' && s
[1] == '0' && s
[2] == '0' && s
[3] == '0'
1269 skip_addr_chars
+= 4;
1274 info
->insn_info_valid
= 0;
1277 addr_offset
= start_offset
;
1278 while (addr_offset
< stop_offset
)
1282 bfd_boolean need_nl
= FALSE
;
1284 /* If we see more than SKIP_ZEROES octets of zeroes, we just
1286 for (z
= addr_offset
* opb
; z
< stop_offset
* opb
; z
++)
1289 if (! disassemble_zeroes
1290 && (info
->insn_info_valid
== 0
1291 || info
->branch_delay_insns
== 0)
1292 && (z
- addr_offset
* opb
>= SKIP_ZEROES
1293 || (z
== stop_offset
* opb
&&
1294 z
- addr_offset
* opb
< SKIP_ZEROES_AT_END
)))
1298 /* If there are more nonzero octets to follow, we only skip
1299 zeroes in multiples of 4, to try to avoid running over
1300 the start of an instruction which happens to start with
1302 if (z
!= stop_offset
* opb
)
1303 z
= addr_offset
* opb
+ ((z
- addr_offset
* opb
) &~ 3);
1305 octets
= z
- addr_offset
* opb
;
1315 if (with_line_numbers
|| with_source_code
)
1316 /* The line number tables will refer to unadjusted
1317 section VMAs, so we must undo any VMA modifications
1318 when calling show_line. */
1319 show_line (aux
->abfd
, section
, addr_offset
- adjust_section_vma
);
1321 if (! prefix_addresses
)
1325 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
1326 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
1330 printf ("%s:\t", buf
+ skip_addr_chars
);
1334 aux
->require_sec
= TRUE
;
1335 objdump_print_address (section
->vma
+ addr_offset
, info
);
1336 aux
->require_sec
= FALSE
;
1343 info
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
1344 info
->stream
= (FILE *) &sfile
;
1345 info
->bytes_per_line
= 0;
1346 info
->bytes_per_chunk
= 0;
1348 #ifdef DISASSEMBLER_NEEDS_RELOCS
1349 /* FIXME: This is wrong. It tests the number of octets
1350 in the last instruction, not the current one. */
1351 if (*relppp
< relppend
1352 && (**relppp
)->address
>= rel_offset
+ addr_offset
1353 && ((**relppp
)->address
1354 < rel_offset
+ addr_offset
+ octets
/ opb
))
1355 info
->flags
= INSN_HAS_RELOC
;
1360 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, info
);
1361 info
->fprintf_func
= (fprintf_ftype
) fprintf
;
1362 info
->stream
= stdout
;
1363 if (info
->bytes_per_line
!= 0)
1364 octets_per_line
= info
->bytes_per_line
;
1368 printf ("%s\n", sfile
.buffer
);
1376 octets
= octets_per_line
;
1377 if (addr_offset
+ octets
/ opb
> stop_offset
)
1378 octets
= (stop_offset
- addr_offset
) * opb
;
1380 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
1382 if (ISPRINT (data
[j
]))
1383 buf
[j
- addr_offset
* opb
] = data
[j
];
1385 buf
[j
- addr_offset
* opb
] = '.';
1387 buf
[j
- addr_offset
* opb
] = '\0';
1390 if (prefix_addresses
1392 : show_raw_insn
>= 0)
1396 /* If ! prefix_addresses and ! wide_output, we print
1397 octets_per_line octets per line. */
1399 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
1400 pb
= octets_per_line
;
1402 if (info
->bytes_per_chunk
)
1403 bpc
= info
->bytes_per_chunk
;
1407 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
1410 if (bpc
> 1 && info
->display_endian
== BFD_ENDIAN_LITTLE
)
1412 for (k
= bpc
- 1; k
>= 0; k
--)
1413 printf ("%02x", (unsigned) data
[j
+ k
]);
1418 for (k
= 0; k
< bpc
; k
++)
1419 printf ("%02x", (unsigned) data
[j
+ k
]);
1424 for (; pb
< octets_per_line
; pb
+= bpc
)
1428 for (k
= 0; k
< bpc
; k
++)
1433 /* Separate raw data from instruction by extra space. */
1443 printf ("%s", sfile
.buffer
);
1445 if (prefix_addresses
1447 : show_raw_insn
>= 0)
1455 j
= addr_offset
* opb
+ pb
;
1457 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
1458 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
1462 printf ("%s:\t", buf
+ skip_addr_chars
);
1464 pb
+= octets_per_line
;
1467 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
1471 if (bpc
> 1 && info
->display_endian
== BFD_ENDIAN_LITTLE
)
1473 for (k
= bpc
- 1; k
>= 0; k
--)
1474 printf ("%02x", (unsigned) data
[j
+ k
]);
1479 for (k
= 0; k
< bpc
; k
++)
1480 printf ("%02x", (unsigned) data
[j
+ k
]);
1493 while ((*relppp
) < relppend
1494 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
1496 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
1507 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
1510 printf (": %s\t", q
->howto
->name
);
1512 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
1513 printf ("*unknown*");
1516 const char *sym_name
;
1518 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
1519 if (sym_name
!= NULL
&& *sym_name
!= '\0')
1520 objdump_print_symname (aux
->abfd
, info
, *q
->sym_ptr_ptr
);
1525 sym_sec
= bfd_get_section (*q
->sym_ptr_ptr
);
1526 sym_name
= bfd_get_section_name (aux
->abfd
, sym_sec
);
1527 if (sym_name
== NULL
|| *sym_name
== '\0')
1528 sym_name
= "*unknown*";
1529 printf ("%s", sym_name
);
1536 objdump_print_value (q
->addend
, info
, TRUE
);
1548 addr_offset
+= octets
/ opb
;
1551 free (sfile
.buffer
);
1555 disassemble_section (bfd
*abfd
, asection
*section
, void *info
)
1557 struct disassemble_info
* pinfo
= (struct disassemble_info
*) info
;
1558 struct objdump_disasm_info
* paux
;
1559 unsigned int opb
= pinfo
->octets_per_byte
;
1560 bfd_byte
* data
= NULL
;
1561 bfd_size_type datasize
= 0;
1562 arelent
** rel_pp
= NULL
;
1563 arelent
** rel_ppstart
= NULL
;
1564 arelent
** rel_ppend
;
1565 unsigned long stop_offset
;
1566 asymbol
* sym
= NULL
;
1570 unsigned long addr_offset
;
1572 /* Sections that do not contain machine
1573 code are not normally disassembled. */
1574 if (! disassemble_all
1576 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
1577 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
1580 if (! process_section_p (section
))
1583 datasize
= bfd_get_section_size (section
);
1587 /* Decide which set of relocs to use. Load them if necessary. */
1588 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
1589 if (paux
->dynrelbuf
)
1591 rel_pp
= paux
->dynrelbuf
;
1592 rel_count
= paux
->dynrelcount
;
1593 /* Dynamic reloc addresses are absolute, non-dynamic are section
1594 relative. REL_OFFSET specifies the reloc address corresponding
1595 to the start of this section. */
1596 rel_offset
= section
->vma
;
1604 if ((section
->flags
& SEC_RELOC
) != 0
1605 #ifndef DISASSEMBLER_NEEDS_RELOCS
1612 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
1614 bfd_fatal (bfd_get_filename (abfd
));
1618 rel_ppstart
= rel_pp
= xmalloc (relsize
);
1619 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
1621 bfd_fatal (bfd_get_filename (abfd
));
1623 /* Sort the relocs by address. */
1624 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
1629 rel_ppend
= rel_pp
+ rel_count
;
1631 data
= xmalloc (datasize
);
1633 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
1635 paux
->sec
= section
;
1636 pinfo
->buffer
= data
;
1637 pinfo
->buffer_vma
= section
->vma
;
1638 pinfo
->buffer_length
= datasize
;
1639 pinfo
->section
= section
;
1641 if (start_address
== (bfd_vma
) -1
1642 || start_address
< pinfo
->buffer_vma
)
1645 addr_offset
= start_address
- pinfo
->buffer_vma
;
1647 if (stop_address
== (bfd_vma
) -1)
1648 stop_offset
= datasize
/ opb
;
1651 if (stop_address
< pinfo
->buffer_vma
)
1654 stop_offset
= stop_address
- pinfo
->buffer_vma
;
1655 if (stop_offset
> pinfo
->buffer_length
/ opb
)
1656 stop_offset
= pinfo
->buffer_length
/ opb
;
1659 /* Skip over the relocs belonging to addresses below the
1661 while (rel_pp
< rel_ppend
1662 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
1665 printf (_("Disassembly of section %s:\n"), section
->name
);
1667 /* Find the nearest symbol forwards from our current position. */
1668 paux
->require_sec
= TRUE
;
1669 sym
= find_symbol_for_address (section
->vma
+ addr_offset
, info
, &place
);
1670 paux
->require_sec
= FALSE
;
1672 /* Disassemble a block of instructions up to the address associated with
1673 the symbol we have just found. Then print the symbol and find the
1674 next symbol on. Repeat until we have disassembled the entire section
1675 or we have reached the end of the address range we are interested in. */
1676 while (addr_offset
< stop_offset
)
1680 unsigned long nextstop_offset
;
1683 addr
= section
->vma
+ addr_offset
;
1685 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
1690 (x
< sorted_symcount
1691 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
1695 pinfo
->symbols
= sorted_syms
+ place
;
1696 pinfo
->num_symbols
= x
- place
;
1700 pinfo
->symbols
= NULL
;
1701 pinfo
->num_symbols
= 0;
1704 if (! prefix_addresses
)
1706 pinfo
->fprintf_func (pinfo
->stream
, "\n");
1707 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
1709 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
1712 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
1714 else if (sym
== NULL
)
1718 #define is_valid_next_sym(SYM) \
1719 ((SYM)->section == section \
1720 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
1721 && pinfo->symbol_is_valid (SYM, pinfo))
1723 /* Search forward for the next appropriate symbol in
1724 SECTION. Note that all the symbols are sorted
1725 together into one big array, and that some sections
1726 may have overlapping addresses. */
1727 while (place
< sorted_symcount
1728 && ! is_valid_next_sym (sorted_syms
[place
]))
1731 if (place
>= sorted_symcount
)
1734 nextsym
= sorted_syms
[place
];
1737 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
1738 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
1739 else if (nextsym
== NULL
)
1740 nextstop_offset
= stop_offset
;
1742 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
1744 if (nextstop_offset
> stop_offset
)
1745 nextstop_offset
= stop_offset
;
1747 /* If a symbol is explicitly marked as being an object
1748 rather than a function, just dump the bytes without
1749 disassembling them. */
1752 || bfd_asymbol_value (sym
) > addr
1753 || ((sym
->flags
& BSF_OBJECT
) == 0
1754 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
1756 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
1758 || (sym
->flags
& BSF_FUNCTION
) != 0)
1763 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
1764 addr_offset
, nextstop_offset
,
1765 rel_offset
, &rel_pp
, rel_ppend
);
1767 addr_offset
= nextstop_offset
;
1773 if (rel_ppstart
!= NULL
)
1777 /* Disassemble the contents of an object file. */
1780 disassemble_data (bfd
*abfd
)
1782 struct disassemble_info disasm_info
;
1783 struct objdump_disasm_info aux
;
1787 prev_functionname
= NULL
;
1790 /* We make a copy of syms to sort. We don't want to sort syms
1791 because that will screw up the relocs. */
1792 sorted_symcount
= symcount
? symcount
: dynsymcount
;
1793 sorted_syms
= xmalloc ((sorted_symcount
+ synthcount
) * sizeof (asymbol
*));
1794 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
1795 sorted_symcount
* sizeof (asymbol
*));
1797 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
1799 for (i
= 0; i
< synthcount
; ++i
)
1801 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
1805 /* Sort the symbols into section and symbol order. */
1806 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
1808 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
1810 disasm_info
.application_data
= (void *) &aux
;
1812 aux
.require_sec
= FALSE
;
1813 aux
.dynrelbuf
= NULL
;
1814 aux
.dynrelcount
= 0;
1816 disasm_info
.print_address_func
= objdump_print_address
;
1817 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
1819 if (machine
!= NULL
)
1821 const bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
1824 fatal (_("Can't use supplied machine %s"), machine
);
1826 abfd
->arch_info
= info
;
1829 if (endian
!= BFD_ENDIAN_UNKNOWN
)
1831 struct bfd_target
*xvec
;
1833 xvec
= xmalloc (sizeof (struct bfd_target
));
1834 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
1835 xvec
->byteorder
= endian
;
1839 /* Use libopcodes to locate a suitable disassembler. */
1840 aux
.disassemble_fn
= disassembler (abfd
);
1841 if (!aux
.disassemble_fn
)
1843 non_fatal (_("Can't disassemble for architecture %s\n"),
1844 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
1849 disasm_info
.flavour
= bfd_get_flavour (abfd
);
1850 disasm_info
.arch
= bfd_get_arch (abfd
);
1851 disasm_info
.mach
= bfd_get_mach (abfd
);
1852 disasm_info
.disassembler_options
= disassembler_options
;
1853 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
);
1855 if (bfd_big_endian (abfd
))
1856 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
1857 else if (bfd_little_endian (abfd
))
1858 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
1860 /* ??? Aborting here seems too drastic. We could default to big or little
1862 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
1864 /* Allow the target to customize the info structure. */
1865 disassemble_init_for_target (& disasm_info
);
1867 /* Pre-load the dynamic relocs if we are going
1868 to be dumping them along with the disassembly. */
1869 if (dump_dynamic_reloc_info
)
1871 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1874 bfd_fatal (bfd_get_filename (abfd
));
1878 aux
.dynrelbuf
= xmalloc (relsize
);
1879 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
1882 if (aux
.dynrelcount
< 0)
1883 bfd_fatal (bfd_get_filename (abfd
));
1885 /* Sort the relocs by address. */
1886 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
1891 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
1893 if (aux
.dynrelbuf
!= NULL
)
1894 free (aux
.dynrelbuf
);
1898 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
1899 it. Return NULL on failure. */
1902 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
)
1908 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
1909 if (stabsect
== NULL
)
1911 printf (_("No %s section present\n\n"), sect_name
);
1915 size
= bfd_section_size (abfd
, stabsect
);
1916 contents
= xmalloc (size
);
1918 if (! bfd_get_section_contents (abfd
, stabsect
, contents
, 0, size
))
1920 non_fatal (_("Reading %s section of %s failed: %s"),
1921 sect_name
, bfd_get_filename (abfd
),
1922 bfd_errmsg (bfd_get_error ()));
1933 /* Stabs entries use a 12 byte format:
1934 4 byte string table index
1936 1 byte stab other field
1937 2 byte stab desc field
1939 FIXME: This will have to change for a 64 bit object format. */
1941 #define STRDXOFF (0)
1943 #define OTHEROFF (5)
1946 #define STABSIZE (12)
1948 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1949 using string table section STRSECT_NAME (in `strtab'). */
1952 print_section_stabs (bfd
*abfd
,
1953 const char *stabsect_name
,
1954 unsigned *string_offset_ptr
)
1957 unsigned file_string_table_offset
= 0;
1958 unsigned next_file_string_table_offset
= *string_offset_ptr
;
1959 bfd_byte
*stabp
, *stabs_end
;
1962 stabs_end
= stabp
+ stab_size
;
1964 printf (_("Contents of %s section:\n\n"), stabsect_name
);
1965 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
1967 /* Loop through all symbols and print them.
1969 We start the index at -1 because there is a dummy symbol on
1970 the front of stabs-in-{coff,elf} sections that supplies sizes. */
1971 for (i
= -1; stabp
< stabs_end
; stabp
+= STABSIZE
, i
++)
1975 unsigned char type
, other
;
1976 unsigned short desc
;
1979 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
1980 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
1981 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
1982 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
1983 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
1985 printf ("\n%-6d ", i
);
1986 /* Either print the stab name, or, if unnamed, print its number
1987 again (makes consistent formatting for tools like awk). */
1988 name
= bfd_get_stab_name (type
);
1990 printf ("%-6s", name
);
1991 else if (type
== N_UNDF
)
1994 printf ("%-6d", type
);
1995 printf (" %-6d %-6d ", other
, desc
);
1996 bfd_printf_vma (abfd
, value
);
1997 printf (" %-6lu", strx
);
1999 /* Symbols with type == 0 (N_UNDF) specify the length of the
2000 string table associated with this file. We use that info
2001 to know how to relocate the *next* file's string table indices. */
2004 file_string_table_offset
= next_file_string_table_offset
;
2005 next_file_string_table_offset
+= value
;
2009 /* Using the (possibly updated) string table offset, print the
2010 string (if any) associated with this symbol. */
2011 if ((strx
+ file_string_table_offset
) < stabstr_size
)
2012 printf (" %s", &strtab
[strx
+ file_string_table_offset
]);
2018 *string_offset_ptr
= next_file_string_table_offset
;
2023 const char * section_name
;
2024 const char * string_section_name
;
2025 unsigned string_offset
;
2030 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
2033 stab_section_names
* sought
= (stab_section_names
*) names
;
2035 /* Check for section names for which stabsect_name is a prefix, to
2036 handle .stab.N, etc. */
2037 len
= strlen (sought
->section_name
);
2039 /* If the prefix matches, and the files section name ends with a
2040 nul or a digit, then we match. I.e., we want either an exact
2041 match or a section followed by a number. */
2042 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
2043 && (section
->name
[len
] == 0
2044 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
2047 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
2052 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
);
2054 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
2060 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
2062 stab_section_names s
;
2064 s
.section_name
= stabsect_name
;
2065 s
.string_section_name
= strsect_name
;
2066 s
.string_offset
= 0;
2068 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
2074 /* Dump the any sections containing stabs debugging information. */
2077 dump_stabs (bfd
*abfd
)
2079 dump_stabs_section (abfd
, ".stab", ".stabstr");
2080 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
2081 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
2082 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
2086 dump_bfd_header (bfd
*abfd
)
2090 printf (_("architecture: %s, "),
2091 bfd_printable_arch_mach (bfd_get_arch (abfd
),
2092 bfd_get_mach (abfd
)));
2093 printf (_("flags 0x%08x:\n"), abfd
->flags
);
2095 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
2096 PF (HAS_RELOC
, "HAS_RELOC");
2097 PF (EXEC_P
, "EXEC_P");
2098 PF (HAS_LINENO
, "HAS_LINENO");
2099 PF (HAS_DEBUG
, "HAS_DEBUG");
2100 PF (HAS_SYMS
, "HAS_SYMS");
2101 PF (HAS_LOCALS
, "HAS_LOCALS");
2102 PF (DYNAMIC
, "DYNAMIC");
2103 PF (WP_TEXT
, "WP_TEXT");
2104 PF (D_PAGED
, "D_PAGED");
2105 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
2106 PF (HAS_LOAD_PAGE
, "HAS_LOAD_PAGE");
2107 printf (_("\nstart address 0x"));
2108 bfd_printf_vma (abfd
, abfd
->start_address
);
2114 dump_bfd_private_header (bfd
*abfd
)
2116 bfd_print_private_bfd_data (abfd
, stdout
);
2120 /* Display a section in hexadecimal format with associated characters.
2121 Each line prefixed by the zero padded address. */
2124 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
2127 bfd_size_type datasize
;
2128 bfd_size_type addr_offset
;
2129 bfd_size_type start_offset
;
2130 bfd_size_type stop_offset
;
2131 unsigned int opb
= bfd_octets_per_byte (abfd
);
2132 /* Bytes per line. */
2133 const int onaline
= 16;
2138 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2141 if (! process_section_p (section
))
2144 if ((datasize
= bfd_section_size (abfd
, section
)) == 0)
2147 printf (_("Contents of section %s:\n"), section
->name
);
2149 data
= xmalloc (datasize
);
2151 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
2153 /* Compute the address range to display. */
2154 if (start_address
== (bfd_vma
) -1
2155 || start_address
< section
->vma
)
2158 start_offset
= start_address
- section
->vma
;
2160 if (stop_address
== (bfd_vma
) -1)
2161 stop_offset
= datasize
/ opb
;
2164 if (stop_address
< section
->vma
)
2167 stop_offset
= stop_address
- section
->vma
;
2169 if (stop_offset
> datasize
/ opb
)
2170 stop_offset
= datasize
/ opb
;
2175 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
2176 if (strlen (buf
) >= sizeof (buf
))
2180 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
2182 count
= strlen (buf
) - count
;
2186 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
2187 if (strlen (buf
) >= sizeof (buf
))
2191 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
2193 count
= strlen (buf
) - count
;
2197 for (addr_offset
= start_offset
;
2198 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
2202 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
2203 count
= strlen (buf
);
2204 if ((size_t) count
>= sizeof (buf
))
2208 while (count
< width
)
2213 fputs (buf
+ count
- width
, stdout
);
2216 for (j
= addr_offset
* opb
;
2217 j
< addr_offset
* opb
+ onaline
; j
++)
2219 if (j
< stop_offset
* opb
)
2220 printf ("%02x", (unsigned) (data
[j
]));
2228 for (j
= addr_offset
* opb
;
2229 j
< addr_offset
* opb
+ onaline
; j
++)
2231 if (j
>= stop_offset
* opb
)
2234 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
2241 /* Actually display the various requested regions. */
2244 dump_data (bfd
*abfd
)
2246 bfd_map_over_sections (abfd
, dump_section
, NULL
);
2249 /* Should perhaps share code and display with nm? */
2252 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
2262 printf ("DYNAMIC SYMBOL TABLE:\n");
2268 printf ("SYMBOL TABLE:\n");
2272 printf (_("no symbols\n"));
2274 for (count
= 0; count
< max
; count
++)
2278 if (*current
== NULL
)
2279 printf (_("no information for the %ld'th symbol"), count
);
2281 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
2282 printf (_("could not determine the type of the %ld'th symbol"),
2287 const char *name
= (*current
)->name
;
2289 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
2293 /* If we want to demangle the name, we demangle it
2294 here, and temporarily clobber it while calling
2295 bfd_print_symbol. FIXME: This is a gross hack. */
2296 alloc
= demangle (cur_bfd
, name
);
2297 (*current
)->name
= alloc
;
2298 bfd_print_symbol (cur_bfd
, stdout
, *current
,
2299 bfd_print_symbol_all
);
2300 (*current
)->name
= name
;
2304 bfd_print_symbol (cur_bfd
, stdout
, *current
,
2305 bfd_print_symbol_all
);
2315 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
2318 char *last_filename
, *last_functionname
;
2319 unsigned int last_line
;
2321 /* Get column headers lined up reasonably. */
2329 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
2330 width
= strlen (buf
) - 7;
2332 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
2335 last_filename
= NULL
;
2336 last_functionname
= NULL
;
2339 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
2342 const char *filename
, *functionname
;
2344 const char *sym_name
;
2345 const char *section_name
;
2347 if (start_address
!= (bfd_vma
) -1
2348 && q
->address
< start_address
)
2350 if (stop_address
!= (bfd_vma
) -1
2351 && q
->address
> stop_address
)
2354 if (with_line_numbers
2356 && bfd_find_nearest_line (abfd
, sec
, syms
, q
->address
,
2357 &filename
, &functionname
, &line
))
2359 if (functionname
!= NULL
2360 && (last_functionname
== NULL
2361 || strcmp (functionname
, last_functionname
) != 0))
2363 printf ("%s():\n", functionname
);
2364 if (last_functionname
!= NULL
)
2365 free (last_functionname
);
2366 last_functionname
= xstrdup (functionname
);
2370 && (line
!= last_line
2371 || (filename
!= NULL
2372 && last_filename
!= NULL
2373 && strcmp (filename
, last_filename
) != 0)))
2375 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
2377 if (last_filename
!= NULL
)
2378 free (last_filename
);
2379 if (filename
== NULL
)
2380 last_filename
= NULL
;
2382 last_filename
= xstrdup (filename
);
2386 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
2388 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
2389 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
2394 section_name
= NULL
;
2399 bfd_printf_vma (abfd
, q
->address
);
2401 printf (" %-16s ", q
->howto
->name
);
2403 printf (" %-16d ", q
->howto
->type
);
2404 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
2408 if (section_name
== NULL
)
2409 section_name
= "*unknown*";
2410 bfd_printf_vma (abfd
, q
->address
);
2411 printf (" %-16s [%s]",
2419 bfd_printf_vma (abfd
, q
->addend
);
2427 dump_relocs_in_section (bfd
*abfd
,
2429 void *dummy ATTRIBUTE_UNUSED
)
2435 if ( bfd_is_abs_section (section
)
2436 || bfd_is_und_section (section
)
2437 || bfd_is_com_section (section
)
2438 || (! process_section_p (section
))
2439 || ((section
->flags
& SEC_RELOC
) == 0))
2442 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
2444 bfd_fatal (bfd_get_filename (abfd
));
2446 printf ("RELOCATION RECORDS FOR [%s]:", section
->name
);
2450 printf (" (none)\n\n");
2454 relpp
= xmalloc (relsize
);
2455 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
2458 bfd_fatal (bfd_get_filename (abfd
));
2459 else if (relcount
== 0)
2460 printf (" (none)\n\n");
2464 dump_reloc_set (abfd
, section
, relpp
, relcount
);
2471 dump_relocs (bfd
*abfd
)
2473 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
2477 dump_dynamic_relocs (bfd
*abfd
)
2483 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
2485 bfd_fatal (bfd_get_filename (abfd
));
2487 printf ("DYNAMIC RELOCATION RECORDS");
2490 printf (" (none)\n\n");
2493 relpp
= xmalloc (relsize
);
2494 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
2497 bfd_fatal (bfd_get_filename (abfd
));
2498 else if (relcount
== 0)
2499 printf (" (none)\n\n");
2503 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
2510 /* Creates a table of paths, to search for source files. */
2513 add_include_path (const char *path
)
2517 include_path_count
++;
2518 include_paths
= xrealloc (include_paths
,
2519 include_path_count
* sizeof (*include_paths
));
2520 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2521 if (path
[1] == ':' && path
[2] == 0)
2522 path
= concat (path
, ".", (const char *) 0);
2524 include_paths
[include_path_count
- 1] = path
;
2528 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
2530 void *dummy ATTRIBUTE_UNUSED
)
2532 section
->vma
+= adjust_section_vma
;
2533 section
->lma
+= adjust_section_vma
;
2536 /* Dump selected contents of ABFD. */
2539 dump_bfd (bfd
*abfd
)
2541 /* If we are adjusting section VMA's, change them all now. Changing
2542 the BFD information is a hack. However, we must do it, or
2543 bfd_find_nearest_line will not do the right thing. */
2544 if (adjust_section_vma
!= 0)
2545 bfd_map_over_sections (abfd
, adjust_addresses
, NULL
);
2547 if (! dump_debugging_tags
)
2548 printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd
),
2551 print_arelt_descr (stdout
, abfd
, TRUE
);
2552 if (dump_file_header
)
2553 dump_bfd_header (abfd
);
2554 if (dump_private_headers
)
2555 dump_bfd_private_header (abfd
);
2556 if (! dump_debugging_tags
)
2558 if (dump_section_headers
)
2559 dump_headers (abfd
);
2561 if (dump_symtab
|| dump_reloc_info
|| disassemble
|| dump_debugging
)
2562 syms
= slurp_symtab (abfd
);
2563 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
2564 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
2565 dynsyms
= slurp_dynamic_symtab (abfd
);
2566 if (disassemble
&& dynsymcount
> 0)
2568 synthcount
= bfd_get_synthetic_symtab (abfd
, dynsyms
, &synthsyms
);
2569 if (synthcount
< 0) synthcount
= 0;
2573 dump_symbols (abfd
, FALSE
);
2574 if (dump_dynamic_symtab
)
2575 dump_symbols (abfd
, TRUE
);
2576 if (dump_stab_section_info
)
2578 if (dump_reloc_info
&& ! disassemble
)
2580 if (dump_dynamic_reloc_info
&& ! disassemble
)
2581 dump_dynamic_relocs (abfd
);
2582 if (dump_section_contents
)
2585 disassemble_data (abfd
);
2591 dhandle
= read_debugging_info (abfd
, syms
, symcount
);
2592 if (dhandle
!= NULL
)
2594 if (! print_debugging_info (stdout
, dhandle
, abfd
, syms
, demangle
,
2595 dump_debugging_tags
? TRUE
: FALSE
))
2597 non_fatal (_("%s: printing debugging information failed"),
2598 bfd_get_filename (abfd
));
2628 display_bfd (bfd
*abfd
)
2632 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
2638 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
2640 nonfatal (bfd_get_filename (abfd
));
2641 list_matching_formats (matching
);
2646 if (bfd_get_error () != bfd_error_file_not_recognized
)
2648 nonfatal (bfd_get_filename (abfd
));
2652 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
2658 nonfatal (bfd_get_filename (abfd
));
2660 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
2662 list_matching_formats (matching
);
2668 display_file (char *filename
, char *target
)
2673 if (get_file_size (filename
) < 1)
2676 file
= bfd_openr (filename
, target
);
2679 nonfatal (filename
);
2683 /* If the file is an archive, process all of its elements. */
2684 if (bfd_check_format (file
, bfd_archive
))
2686 bfd
*last_arfile
= NULL
;
2688 printf (_("In archive %s:\n"), bfd_get_filename (file
));
2691 bfd_set_error (bfd_error_no_error
);
2693 arfile
= bfd_openr_next_archived_file (file
, arfile
);
2696 if (bfd_get_error () != bfd_error_no_more_archived_files
)
2697 nonfatal (bfd_get_filename (file
));
2701 display_bfd (arfile
);
2703 if (last_arfile
!= NULL
)
2704 bfd_close (last_arfile
);
2705 last_arfile
= arfile
;
2708 if (last_arfile
!= NULL
)
2709 bfd_close (last_arfile
);
2718 main (int argc
, char **argv
)
2721 char *target
= default_target
;
2722 bfd_boolean seenflag
= FALSE
;
2724 #if defined (HAVE_SETLOCALE)
2725 #if defined (HAVE_LC_MESSAGES)
2726 setlocale (LC_MESSAGES
, "");
2728 setlocale (LC_CTYPE
, "");
2731 bindtextdomain (PACKAGE
, LOCALEDIR
);
2732 textdomain (PACKAGE
);
2734 program_name
= *argv
;
2735 xmalloc_set_program_name (program_name
);
2737 START_PROGRESS (program_name
, 0);
2740 set_default_bfd_target ();
2742 while ((c
= getopt_long (argc
, argv
, "pib:m:M:VvCdDlfaHhrRtTxsSI:j:wE:zgeG",
2743 long_options
, (int *) 0))
2749 break; /* We've been given a long option. */
2754 if (disassembler_options
)
2755 /* Ignore potential memory leak for now. */
2756 disassembler_options
= concat (disassembler_options
, ",",
2759 disassembler_options
= optarg
;
2762 if (only_used
== only_size
)
2765 only
= xrealloc (only
, only_size
* sizeof (char *));
2767 only
[only_used
++] = optarg
;
2770 with_line_numbers
= TRUE
;
2779 enum demangling_styles style
;
2781 style
= cplus_demangle_name_to_style (optarg
);
2782 if (style
== unknown_demangling
)
2783 fatal (_("unknown demangling style `%s'"),
2786 cplus_demangle_set_style (style
);
2792 case OPTION_ADJUST_VMA
:
2793 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
2795 case OPTION_START_ADDRESS
:
2796 start_address
= parse_vma (optarg
, "--start-address");
2798 case OPTION_STOP_ADDRESS
:
2799 stop_address
= parse_vma (optarg
, "--stop-address");
2802 if (strcmp (optarg
, "B") == 0)
2803 endian
= BFD_ENDIAN_BIG
;
2804 else if (strcmp (optarg
, "L") == 0)
2805 endian
= BFD_ENDIAN_LITTLE
;
2808 non_fatal (_("unrecognized -E option"));
2813 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
2814 endian
= BFD_ENDIAN_BIG
;
2815 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
2816 endian
= BFD_ENDIAN_LITTLE
;
2819 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
2825 dump_file_header
= TRUE
;
2829 formats_info
= TRUE
;
2833 add_include_path (optarg
);
2836 dump_private_headers
= TRUE
;
2840 dump_private_headers
= TRUE
;
2842 dump_reloc_info
= TRUE
;
2843 dump_file_header
= TRUE
;
2844 dump_ar_hdrs
= TRUE
;
2845 dump_section_headers
= TRUE
;
2853 dump_dynamic_symtab
= TRUE
;
2861 disassemble_zeroes
= TRUE
;
2865 disassemble_all
= TRUE
;
2870 with_source_code
= TRUE
;
2879 dump_debugging_tags
= 1;
2884 dump_stab_section_info
= TRUE
;
2888 dump_section_contents
= TRUE
;
2892 dump_reloc_info
= TRUE
;
2896 dump_dynamic_reloc_info
= TRUE
;
2900 dump_ar_hdrs
= TRUE
;
2904 dump_section_headers
= TRUE
;
2912 show_version
= TRUE
;
2922 print_version ("objdump");
2928 exit_status
= display_info ();
2932 display_file ("a.out", target
);
2934 for (; optind
< argc
;)
2935 display_file (argv
[optind
++], target
);
2938 END_PROGRESS (program_name
);