1 /* objdump.c -- dump information about an object file.
2 Copyright (C) 1990-2021 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 3, 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, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 Objdump displays information about one or more object files, either on
25 their own, or inside libraries. It is commonly used as a disassembler,
26 but it can also display information about file headers, symbol tables,
27 relocations, debugging directives and more.
29 The flow of execution is as follows:
31 1. Command line arguments are checked for control switches and the
32 information to be displayed is selected.
34 2. Any remaining arguments are assumed to be object files, and they are
35 processed in order by display_bfd(). If the file is an archive each
36 of its elements is processed in turn.
38 3. The file's target architecture and binary file format are determined
39 by bfd_check_format(). If they are recognised, then dump_bfd() is
42 4. dump_bfd() in turn calls separate functions to display the requested
43 item(s) of information(s). For example disassemble_data() is called if
44 a disassembly has been requested.
46 When disassembling the code loops through blocks of instructions bounded
47 by symbols, calling disassemble_bytes() on each block. The actual
48 disassembling is done by the libopcodes library, via a function pointer
49 supplied by the disassembler() function. */
61 #include "safe-ctype.h"
63 #include "libiberty.h"
65 #include "filenames.h"
74 /* Internal headers for the ELF .stab-dump code - sorry. */
75 #define BYTES_IN_WORD 32
76 #include "aout/aout64.h"
79 static int exit_status
= 0;
81 static char *default_target
= NULL
; /* Default at runtime. */
83 /* The following variables are set based on arguments passed on the
85 static int show_version
= 0; /* Show the version number. */
86 static int dump_section_contents
; /* -s */
87 static int dump_section_headers
; /* -h */
88 static bfd_boolean dump_file_header
; /* -f */
89 static int dump_symtab
; /* -t */
90 static int dump_dynamic_symtab
; /* -T */
91 static int dump_reloc_info
; /* -r */
92 static int dump_dynamic_reloc_info
; /* -R */
93 static int dump_ar_hdrs
; /* -a */
94 static int dump_private_headers
; /* -p */
95 static char *dump_private_options
; /* -P */
96 static int no_addresses
; /* --no-addresses */
97 static int prefix_addresses
; /* --prefix-addresses */
98 static int with_line_numbers
; /* -l */
99 static bfd_boolean with_source_code
; /* -S */
100 static int show_raw_insn
; /* --show-raw-insn */
101 static int dump_dwarf_section_info
; /* --dwarf */
102 static int dump_stab_section_info
; /* --stabs */
103 static int dump_ctf_section_info
; /* --ctf */
104 static char *dump_ctf_section_name
;
105 static char *dump_ctf_parent_name
; /* --ctf-parent */
106 static int do_demangle
; /* -C, --demangle */
107 static bfd_boolean disassemble
; /* -d */
108 static bfd_boolean disassemble_all
; /* -D */
109 static int disassemble_zeroes
; /* --disassemble-zeroes */
110 static bfd_boolean formats_info
; /* -i */
111 static int wide_output
; /* -w */
112 static int insn_width
; /* --insn-width */
113 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
114 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
115 static int dump_debugging
; /* --debugging */
116 static int dump_debugging_tags
; /* --debugging-tags */
117 static int suppress_bfd_header
;
118 static int dump_special_syms
= 0; /* --special-syms */
119 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
120 static int file_start_context
= 0; /* --file-start-context */
121 static bfd_boolean display_file_offsets
;/* -F */
122 static const char *prefix
; /* --prefix */
123 static int prefix_strip
; /* --prefix-strip */
124 static size_t prefix_length
;
125 static bfd_boolean unwind_inlines
; /* --inlines. */
126 static const char * disasm_sym
; /* Disassembly start symbol. */
127 static const char * source_comment
; /* --source_comment. */
128 static bfd_boolean visualize_jumps
= FALSE
; /* --visualize-jumps. */
129 static bfd_boolean color_output
= FALSE
; /* --visualize-jumps=color. */
130 static bfd_boolean extended_color_output
= FALSE
; /* --visualize-jumps=extended-color. */
131 static bfd_boolean process_links
= FALSE
; /* --process-links. */
133 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
135 /* A structure to record the sections mentioned in -j switches. */
138 const char * name
; /* The name of the section. */
139 bfd_boolean seen
; /* A flag to indicate that the section has been found in one or more input files. */
140 struct only
* next
; /* Pointer to the next structure in the list. */
142 /* Pointer to an array of 'only' structures.
143 This pointer is NULL if the -j switch has not been used. */
144 static struct only
* only_list
= NULL
;
146 /* Variables for handling include file path table. */
147 static const char **include_paths
;
148 static int include_path_count
;
150 /* Extra info to pass to the section disassembler and address printing
152 struct objdump_disasm_info
155 bfd_boolean require_sec
;
156 arelent
** dynrelbuf
;
158 disassembler_ftype disassemble_fn
;
163 /* Architecture to disassemble for, or default if NULL. */
164 static char *machine
= NULL
;
166 /* Target specific options to the disassembler. */
167 static char *disassembler_options
= NULL
;
169 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
170 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
172 /* The symbol table. */
173 static asymbol
**syms
;
175 /* Number of symbols in `syms'. */
176 static long symcount
= 0;
178 /* The sorted symbol table. */
179 static asymbol
**sorted_syms
;
181 /* Number of symbols in `sorted_syms'. */
182 static long sorted_symcount
= 0;
184 /* The dynamic symbol table. */
185 static asymbol
**dynsyms
;
187 /* The synthetic symbol table. */
188 static asymbol
*synthsyms
;
189 static long synthcount
= 0;
191 /* Number of symbols in `dynsyms'. */
192 static long dynsymcount
= 0;
194 static bfd_byte
*stabs
;
195 static bfd_size_type stab_size
;
197 static bfd_byte
*strtab
;
198 static bfd_size_type stabstr_size
;
200 /* Handlers for -P/--private. */
201 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
203 OBJDUMP_PRIVATE_VECTORS
207 /* The list of detected jumps inside a function. */
208 static struct jump_info
*detected_jumps
= NULL
;
210 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
212 usage (FILE *stream
, int status
)
214 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
215 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
216 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
217 fprintf (stream
, _("\
218 -a, --archive-headers Display archive header information\n\
219 -f, --file-headers Display the contents of the overall file header\n\
220 -p, --private-headers Display object format specific file header contents\n\
221 -P, --private=OPT,OPT... Display object format specific contents\n\
222 -h, --[section-]headers Display the contents of the section headers\n\
223 -x, --all-headers Display the contents of all headers\n\
224 -d, --disassemble Display assembler contents of executable sections\n\
225 -D, --disassemble-all Display assembler contents of all sections\n\
226 --disassemble=<sym> Display assembler contents from <sym>\n\
227 -S, --source Intermix source code with disassembly\n\
228 --source-comment[=<txt>] Prefix lines of source code with <txt>\n\
229 -s, --full-contents Display the full contents of all sections requested\n\
230 -g, --debugging Display debug information in object file\n\
231 -e, --debugging-tags Display debug information using ctags style\n\
232 -G, --stabs Display (in raw form) any STABS info in the file\n\
233 -W[lLiaprmfFsoORtUuTgAck] or\n\
234 --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
235 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
236 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
237 =addr,=cu_index,=links]\n\
238 Display DWARF info in the file\n\
240 #if DEFAULT_FOR_FOLLOW_LINKS
241 fprintf (stream
, _("\
242 -WK,--dwarf=follow-links Follow links to separate debug info files (default)\n\
243 -WN,--dwarf=no-follow-links Do not follow links to separate debug info files\n\
246 fprintf (stream
, _("\
247 -WK,--dwarf=follow-links Follow links to separate debug info files\n\
248 -WN,--dwarf=no-follow-links Do not follow links to separate debug info files (default)\n\
251 fprintf (stream
, _("\
252 -L, --process-links Display the contents of non-debug sections in separate debuginfo files.\n\
255 fprintf (stream
, _("\
256 --ctf=SECTION Display CTF info from SECTION\n\
259 fprintf (stream
, _("\
260 -t, --syms Display the contents of the symbol table(s)\n\
261 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
262 -r, --reloc Display the relocation entries in the file\n\
263 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
264 @<file> Read options from <file>\n\
265 -v, --version Display this program's version number\n\
266 -i, --info List object formats and architectures supported\n\
267 -H, --help Display this information\n\
271 const struct objdump_private_desc
* const *desc
;
273 fprintf (stream
, _("\n The following switches are optional:\n"));
274 fprintf (stream
, _("\
275 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
276 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
277 -j, --section=NAME Only display information for section NAME\n\
278 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
279 -EB --endian=big Assume big endian format when disassembling\n\
280 -EL --endian=little Assume little endian format when disassembling\n\
281 --file-start-context Include context from start of file (with -S)\n\
282 -I, --include=DIR Add DIR to search list for source files\n\
283 -l, --line-numbers Include line numbers and filenames in output\n\
284 -F, --file-offsets Include file offsets when displaying information\n\
285 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
286 The STYLE, if specified, can be `auto', `gnu',\n\
287 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
289 --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
290 --no-recurse-limit Disable a limit on recursion whilst demangling\n\
291 -w, --wide Format output for more than 80 columns\n\
292 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
293 --start-address=ADDR Only process data whose address is >= ADDR\n\
294 --stop-address=ADDR Only process data whose address is < ADDR\n\
295 --no-addresses Do not print address alongside disassembly\n\
296 --prefix-addresses Print complete address alongside disassembly\n\
297 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
298 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n\
299 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
300 --special-syms Include special symbols in symbol dumps\n\
301 --inlines Print all inlines for source line (with -l)\n\
302 --prefix=PREFIX Add PREFIX to absolute paths for -S\n\
303 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
304 fprintf (stream
, _("\
305 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
306 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
308 --dwarf-check Make additional dwarf internal consistency checks.\n"));
310 fprintf (stream
, _("\
311 --ctf-parent=SECTION Use SECTION as the CTF parent\n"));
313 fprintf (stream
, _("\
314 --visualize-jumps Visualize jumps by drawing ASCII art lines\n\
315 --visualize-jumps=color Use colors in the ASCII art\n\
316 --visualize-jumps=extended-color Use extended 8-bit color codes\n\
317 --visualize-jumps=off Disable jump visualization\n\n"));
319 list_supported_targets (program_name
, stream
);
320 list_supported_architectures (program_name
, stream
);
322 disassembler_usage (stream
);
324 if (objdump_private_vectors
[0] != NULL
)
327 _("\nOptions supported for -P/--private switch:\n"));
328 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
329 (*desc
)->help (stream
);
332 if (REPORT_BUGS_TO
[0] && status
== 0)
333 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
337 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
341 OPTION_START_ADDRESS
,
351 OPTION_RECURSE_LIMIT
,
352 OPTION_NO_RECURSE_LIMIT
,
354 OPTION_SOURCE_COMMENT
,
359 OPTION_VISUALIZE_JUMPS
362 static struct option long_options
[]=
364 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
365 {"all-headers", no_argument
, NULL
, 'x'},
366 {"private-headers", no_argument
, NULL
, 'p'},
367 {"private", required_argument
, NULL
, 'P'},
368 {"architecture", required_argument
, NULL
, 'm'},
369 {"archive-headers", no_argument
, NULL
, 'a'},
370 {"debugging", no_argument
, NULL
, 'g'},
371 {"debugging-tags", no_argument
, NULL
, 'e'},
372 {"demangle", optional_argument
, NULL
, 'C'},
373 {"disassemble", optional_argument
, NULL
, 'd'},
374 {"disassemble-all", no_argument
, NULL
, 'D'},
375 {"disassembler-options", required_argument
, NULL
, 'M'},
376 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
377 {"dynamic-reloc", no_argument
, NULL
, 'R'},
378 {"dynamic-syms", no_argument
, NULL
, 'T'},
379 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
380 {"file-headers", no_argument
, NULL
, 'f'},
381 {"file-offsets", no_argument
, NULL
, 'F'},
382 {"file-start-context", no_argument
, &file_start_context
, 1},
383 {"full-contents", no_argument
, NULL
, 's'},
384 {"headers", no_argument
, NULL
, 'h'},
385 {"help", no_argument
, NULL
, 'H'},
386 {"info", no_argument
, NULL
, 'i'},
387 {"line-numbers", no_argument
, NULL
, 'l'},
388 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
389 {"no-addresses", no_argument
, &no_addresses
, 1},
390 {"process-links", no_argument
, &process_links
, TRUE
},
391 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
392 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
393 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
394 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
395 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
396 {"reloc", no_argument
, NULL
, 'r'},
397 {"section", required_argument
, NULL
, 'j'},
398 {"section-headers", no_argument
, NULL
, 'h'},
399 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
400 {"source", no_argument
, NULL
, 'S'},
401 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
402 {"special-syms", no_argument
, &dump_special_syms
, 1},
403 {"include", required_argument
, NULL
, 'I'},
404 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
406 {"ctf", required_argument
, NULL
, OPTION_CTF
},
407 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
409 {"stabs", no_argument
, NULL
, 'G'},
410 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
411 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
412 {"syms", no_argument
, NULL
, 't'},
413 {"target", required_argument
, NULL
, 'b'},
414 {"version", no_argument
, NULL
, 'V'},
415 {"wide", no_argument
, NULL
, 'w'},
416 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
417 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
418 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
419 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
420 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
421 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
422 {"inlines", no_argument
, 0, OPTION_INLINES
},
423 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
424 {0, no_argument
, 0, 0}
428 nonfatal (const char *msg
)
434 /* Returns a version of IN with any control characters
435 replaced by escape sequences. Uses a static buffer
439 sanitize_string (const char * in
)
441 static char * buffer
= NULL
;
442 static size_t buffer_len
= 0;
443 const char * original
= in
;
450 /* See if any conversion is necessary. In the majority
451 of cases it will not be needed. */
464 /* Copy the input, translating as needed. */
466 if (buffer_len
< (strlen (in
) * 2))
468 free ((void *) buffer
);
469 buffer_len
= strlen (in
) * 2;
470 buffer
= xmalloc (buffer_len
+ 1);
496 /* Returns TRUE if the specified section should be dumped. */
499 process_section_p (asection
* section
)
503 if (only_list
== NULL
)
506 for (only
= only_list
; only
; only
= only
->next
)
507 if (strcmp (only
->name
, section
->name
) == 0)
516 /* Add an entry to the 'only' list. */
519 add_only (char * name
)
523 /* First check to make sure that we do not
524 already have an entry for this name. */
525 for (only
= only_list
; only
; only
= only
->next
)
526 if (strcmp (only
->name
, name
) == 0)
529 only
= xmalloc (sizeof * only
);
532 only
->next
= only_list
;
536 /* Release the memory used by the 'only' list.
537 PR 11225: Issue a warning message for unseen sections.
538 Only do this if none of the sections were seen. This is mainly to support
539 tools like the GAS testsuite where an object file is dumped with a list of
540 generic section names known to be present in a range of different file
544 free_only_list (void)
546 bfd_boolean at_least_one_seen
= FALSE
;
550 if (only_list
== NULL
)
553 for (only
= only_list
; only
; only
= only
->next
)
556 at_least_one_seen
= TRUE
;
560 for (only
= only_list
; only
; only
= next
)
562 if (! at_least_one_seen
)
564 non_fatal (_("section '%s' mentioned in a -j option, "
565 "but not found in any input file"),
576 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
579 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
580 int longest_section_name
= *((int *) data
);
582 /* Ignore linker created section. See elfNN_ia64_object_p in
584 if (section
->flags
& SEC_LINKER_CREATED
)
587 /* PR 10413: Skip sections that we are ignoring. */
588 if (! process_section_p (section
))
591 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
592 sanitize_string (bfd_section_name (section
)),
593 (unsigned long) bfd_section_size (section
) / opb
);
594 bfd_printf_vma (abfd
, bfd_section_vma (section
));
596 bfd_printf_vma (abfd
, section
->lma
);
597 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
598 bfd_section_alignment (section
));
604 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
606 PF (SEC_HAS_CONTENTS
, "CONTENTS");
607 PF (SEC_ALLOC
, "ALLOC");
608 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
609 PF (SEC_LOAD
, "LOAD");
610 PF (SEC_RELOC
, "RELOC");
611 PF (SEC_READONLY
, "READONLY");
612 PF (SEC_CODE
, "CODE");
613 PF (SEC_DATA
, "DATA");
615 PF (SEC_DEBUGGING
, "DEBUGGING");
616 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
617 PF (SEC_EXCLUDE
, "EXCLUDE");
618 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
619 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
621 PF (SEC_TIC54X_BLOCK
, "BLOCK");
622 PF (SEC_TIC54X_CLINK
, "CLINK");
624 PF (SEC_SMALL_DATA
, "SMALL_DATA");
625 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
627 PF (SEC_COFF_SHARED
, "SHARED");
628 PF (SEC_COFF_NOREAD
, "NOREAD");
630 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
632 PF (SEC_ELF_OCTETS
, "OCTETS");
633 PF (SEC_ELF_PURECODE
, "PURECODE");
635 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
636 PF (SEC_GROUP
, "GROUP");
637 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
639 PF (SEC_MEP_VLIW
, "VLIW");
642 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
645 struct coff_comdat_info
*comdat
;
647 switch (section
->flags
& SEC_LINK_DUPLICATES
)
651 case SEC_LINK_DUPLICATES_DISCARD
:
652 ls
= "LINK_ONCE_DISCARD";
654 case SEC_LINK_DUPLICATES_ONE_ONLY
:
655 ls
= "LINK_ONCE_ONE_ONLY";
657 case SEC_LINK_DUPLICATES_SAME_SIZE
:
658 ls
= "LINK_ONCE_SAME_SIZE";
660 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
661 ls
= "LINK_ONCE_SAME_CONTENTS";
664 printf ("%s%s", comma
, ls
);
666 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
668 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
677 /* Called on each SECTION in ABFD, update the int variable pointed to by
678 DATA which contains the string length of the longest section name. */
681 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
682 asection
*section
, void *data
)
684 int *longest_so_far
= (int *) data
;
688 /* Ignore linker created section. */
689 if (section
->flags
& SEC_LINKER_CREATED
)
692 /* Skip sections that we are ignoring. */
693 if (! process_section_p (section
))
696 name
= bfd_section_name (section
);
697 len
= (int) strlen (name
);
698 if (len
> *longest_so_far
)
699 *longest_so_far
= len
;
703 dump_headers (bfd
*abfd
)
705 /* The default width of 13 is just an arbitrary choice. */
706 int max_section_name_length
= 13;
712 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
713 if (bfd_get_arch_size (abfd
) == 32)
719 printf (_("Sections:\n"));
722 bfd_map_over_sections (abfd
, find_longest_section_name
,
723 &max_section_name_length
);
725 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
726 max_section_name_length
, "Name",
727 bfd_vma_width
, "VMA",
728 bfd_vma_width
, "LMA");
731 printf (_(" Flags"));
734 bfd_map_over_sections (abfd
, dump_section_header
,
735 &max_section_name_length
);
739 slurp_symtab (bfd
*abfd
)
744 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
750 storage
= bfd_get_symtab_upper_bound (abfd
);
753 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
754 bfd_fatal (_("error message was"));
759 off_t filesize
= bfd_get_file_size (abfd
);
763 && filesize
< storage
764 /* The MMO file format supports its own special compression
765 technique, so its sections can be larger than the file size. */
766 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
768 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
769 _("error: symbol table size (%#lx) "
770 "is larger than filesize (%#lx)"),
771 storage
, (long) filesize
);
777 sy
= (asymbol
**) xmalloc (storage
);
780 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
782 bfd_fatal (bfd_get_filename (abfd
));
786 /* Read in the dynamic symbols. */
789 slurp_dynamic_symtab (bfd
*abfd
)
794 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
797 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
799 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
805 bfd_fatal (bfd_get_filename (abfd
));
809 sy
= (asymbol
**) xmalloc (storage
);
811 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
813 bfd_fatal (bfd_get_filename (abfd
));
817 /* Some symbol names are significant and should be kept in the
818 table of sorted symbol names, even if they are marked as
819 debugging/section symbols. */
822 is_significant_symbol_name (const char * name
)
824 return strncmp (name
, ".plt", 4) == 0 || strcmp (name
, ".got") == 0;
827 /* Filter out (in place) symbols that are useless for disassembly.
828 COUNT is the number of elements in SYMBOLS.
829 Return the number of useful symbols. */
832 remove_useless_symbols (asymbol
**symbols
, long count
)
834 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
838 asymbol
*sym
= *in_ptr
++;
840 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
842 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
843 && ! is_significant_symbol_name (sym
->name
))
845 if (bfd_is_und_section (sym
->section
)
846 || bfd_is_com_section (sym
->section
))
851 return out_ptr
- symbols
;
854 static const asection
*compare_section
;
856 /* Sort symbols into value order. */
859 compare_symbols (const void *ap
, const void *bp
)
861 const asymbol
*a
= * (const asymbol
**) ap
;
862 const asymbol
*b
= * (const asymbol
**) bp
;
867 bfd_boolean as
, af
, bs
, bf
;
871 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
873 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
876 /* Prefer symbols from the section currently being disassembled.
877 Don't sort symbols from other sections by section, since there
878 isn't much reason to prefer one section over another otherwise.
879 See sym_ok comment for why we compare by section name. */
880 as
= strcmp (compare_section
->name
, a
->section
->name
) == 0;
881 bs
= strcmp (compare_section
->name
, b
->section
->name
) == 0;
887 an
= bfd_asymbol_name (a
);
888 bn
= bfd_asymbol_name (b
);
892 /* The symbols gnu_compiled and gcc2_compiled convey no real
893 information, so put them after other symbols with the same value. */
894 af
= (strstr (an
, "gnu_compiled") != NULL
895 || strstr (an
, "gcc2_compiled") != NULL
);
896 bf
= (strstr (bn
, "gnu_compiled") != NULL
897 || strstr (bn
, "gcc2_compiled") != NULL
);
904 /* We use a heuristic for the file name, to try to sort it after
905 more useful symbols. It may not work on non Unix systems, but it
906 doesn't really matter; the only difference is precisely which
907 symbol names get printed. */
909 #define file_symbol(s, sn, snl) \
910 (((s)->flags & BSF_FILE) != 0 \
912 && (sn)[(snl) - 2] == '.' \
913 && ((sn)[(snl) - 1] == 'o' \
914 || (sn)[(snl) - 1] == 'a')))
916 af
= file_symbol (a
, an
, anl
);
917 bf
= file_symbol (b
, bn
, bnl
);
924 /* Sort function and object symbols before global symbols before
925 local symbols before section symbols before debugging symbols. */
930 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
932 if ((aflags
& BSF_DEBUGGING
) != 0)
937 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
939 if ((aflags
& BSF_SECTION_SYM
) != 0)
944 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
946 if ((aflags
& BSF_FUNCTION
) != 0)
951 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
953 if ((aflags
& BSF_OBJECT
) != 0)
958 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
960 if ((aflags
& BSF_LOCAL
) != 0)
965 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
967 if ((aflags
& BSF_GLOBAL
) != 0)
973 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
974 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
979 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
980 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
982 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
983 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
985 return asz
> bsz
? -1 : 1;
988 /* Symbols that start with '.' might be section names, so sort them
989 after symbols that don't start with '.'. */
990 if (an
[0] == '.' && bn
[0] != '.')
992 if (an
[0] != '.' && bn
[0] == '.')
995 /* Finally, if we can't distinguish them in any other way, try to
996 get consistent results by sorting the symbols by name. */
997 return strcmp (an
, bn
);
1000 /* Sort relocs into address order. */
1003 compare_relocs (const void *ap
, const void *bp
)
1005 const arelent
*a
= * (const arelent
**) ap
;
1006 const arelent
*b
= * (const arelent
**) bp
;
1008 if (a
->address
> b
->address
)
1010 else if (a
->address
< b
->address
)
1013 /* So that associated relocations tied to the same address show up
1014 in the correct order, we don't do any further sorting. */
1023 /* Print an address (VMA) to the output stream in INFO.
1024 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1027 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1028 bfd_boolean skip_zeroes
)
1032 struct objdump_disasm_info
*aux
;
1034 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1035 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1040 for (p
= buf
; *p
== '0'; ++p
)
1045 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
1048 /* Print the name of a symbol. */
1051 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1055 const char *name
, *version_string
= NULL
;
1056 bfd_boolean hidden
= FALSE
;
1059 name
= bfd_asymbol_name (sym
);
1060 if (do_demangle
&& name
[0] != '\0')
1062 /* Demangle the name. */
1063 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1068 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1069 version_string
= bfd_get_symbol_version_string (abfd
, sym
, TRUE
,
1072 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1075 name
= sanitize_string (name
);
1079 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1080 if (version_string
&& *version_string
!= '\0')
1081 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1086 printf ("%s", name
);
1087 if (version_string
&& *version_string
!= '\0')
1088 printf (hidden
? "@%s" : "@@%s", version_string
);
1095 static inline bfd_boolean
1096 sym_ok (bfd_boolean want_section
,
1097 bfd
* abfd ATTRIBUTE_UNUSED
,
1100 struct disassemble_info
* inf
)
1104 /* NB: An object file can have different sections with the same
1105 section name. Compare compare section pointers if they have
1107 if (sorted_syms
[place
]->section
->owner
== sec
->owner
1108 && sorted_syms
[place
]->section
!= sec
)
1111 /* Note - we cannot just compare section pointers because they could
1112 be different, but the same... Ie the symbol that we are trying to
1113 find could have come from a separate debug info file. Under such
1114 circumstances the symbol will be associated with a section in the
1115 debug info file, whilst the section we want is in a normal file.
1116 So the section pointers will be different, but the section names
1117 will be the same. */
1118 if (strcmp (bfd_section_name (sorted_syms
[place
]->section
),
1119 bfd_section_name (sec
)) != 0)
1123 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1126 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1127 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1128 require the symbol to be in the section. Returns NULL if there is no
1129 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1130 of the symbol in sorted_syms. */
1133 find_symbol_for_address (bfd_vma vma
,
1134 struct disassemble_info
*inf
,
1137 /* @@ Would it speed things up to cache the last two symbols returned,
1138 and maybe their address ranges? For many processors, only one memory
1139 operand can be present at a time, so the 2-entry cache wouldn't be
1140 constantly churned by code doing heavy memory accesses. */
1142 /* Indices in `sorted_syms'. */
1144 long max_count
= sorted_symcount
;
1146 struct objdump_disasm_info
*aux
;
1150 bfd_boolean want_section
;
1153 if (sorted_symcount
< 1)
1156 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1159 opb
= inf
->octets_per_byte
;
1161 /* Perform a binary search looking for the closest symbol to the
1162 required value. We are searching the range (min, max_count]. */
1163 while (min
+ 1 < max_count
)
1167 thisplace
= (max_count
+ min
) / 2;
1168 sym
= sorted_syms
[thisplace
];
1170 if (bfd_asymbol_value (sym
) > vma
)
1171 max_count
= thisplace
;
1172 else if (bfd_asymbol_value (sym
) < vma
)
1181 /* The symbol we want is now in min, the low end of the range we
1182 were searching. If there are several symbols with the same
1183 value, we want the first one. */
1185 while (thisplace
> 0
1186 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1187 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1190 /* Prefer a symbol in the current section if we have multple symbols
1191 with the same value, as can occur with overlays or zero size
1194 while (min
< max_count
1195 && (bfd_asymbol_value (sorted_syms
[min
])
1196 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1198 if (sym_ok (TRUE
, abfd
, min
, sec
, inf
))
1205 return sorted_syms
[thisplace
];
1210 /* If the file is relocatable, and the symbol could be from this
1211 section, prefer a symbol from this section over symbols from
1212 others, even if the other symbol's value might be closer.
1214 Note that this may be wrong for some symbol references if the
1215 sections have overlapping memory ranges, but in that case there's
1216 no way to tell what's desired without looking at the relocation
1219 Also give the target a chance to reject symbols. */
1220 want_section
= (aux
->require_sec
1221 || ((abfd
->flags
& HAS_RELOC
) != 0
1222 && vma
>= bfd_section_vma (sec
)
1223 && vma
< (bfd_section_vma (sec
)
1224 + bfd_section_size (sec
) / opb
)));
1226 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1229 long newplace
= sorted_symcount
;
1231 for (i
= min
- 1; i
>= 0; i
--)
1233 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1235 if (newplace
== sorted_symcount
)
1238 if (bfd_asymbol_value (sorted_syms
[i
])
1239 != bfd_asymbol_value (sorted_syms
[newplace
]))
1242 /* Remember this symbol and keep searching until we reach
1243 an earlier address. */
1248 if (newplace
!= sorted_symcount
)
1249 thisplace
= newplace
;
1252 /* We didn't find a good symbol with a smaller value.
1253 Look for one with a larger value. */
1254 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1256 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1264 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1265 /* There is no suitable symbol. */
1269 /* If we have not found an exact match for the specified address
1270 and we have dynamic relocations available, then we can produce
1271 a better result by matching a relocation to the address and
1272 using the symbol associated with that relocation. */
1273 rel_count
= aux
->dynrelcount
;
1275 && sorted_syms
[thisplace
]->value
!= vma
1277 && aux
->dynrelbuf
!= NULL
1278 && aux
->dynrelbuf
[0]->address
<= vma
1279 && aux
->dynrelbuf
[rel_count
- 1]->address
>= vma
1280 /* If we have matched a synthetic symbol, then stick with that. */
1281 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1284 arelent
** rel_high
;
1286 rel_low
= aux
->dynrelbuf
;
1287 rel_high
= rel_low
+ rel_count
- 1;
1288 while (rel_low
<= rel_high
)
1290 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1291 arelent
* rel
= *rel_mid
;
1293 if (rel
->address
== vma
)
1295 /* Absolute relocations do not provide a more helpful
1296 symbolic address. Find a non-absolute relocation
1297 with the same address. */
1298 arelent
**rel_vma
= rel_mid
;
1300 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1304 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1308 if (rel
->sym_ptr_ptr
!= NULL
1309 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1312 * place
= thisplace
;
1313 return * rel
->sym_ptr_ptr
;
1319 if (vma
< rel
->address
)
1321 else if (vma
>= rel_mid
[1]->address
)
1322 rel_low
= rel_mid
+ 1;
1331 return sorted_syms
[thisplace
];
1334 /* Print an address and the offset to the nearest symbol. */
1337 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1338 bfd_vma vma
, struct disassemble_info
*inf
,
1339 bfd_boolean skip_zeroes
)
1343 objdump_print_value (vma
, inf
, skip_zeroes
);
1344 (*inf
->fprintf_func
) (inf
->stream
, " ");
1351 (*inf
->fprintf_func
) (inf
->stream
, "<%s",
1352 sanitize_string (bfd_section_name (sec
)));
1353 secaddr
= bfd_section_vma (sec
);
1356 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1357 objdump_print_value (secaddr
- vma
, inf
, TRUE
);
1359 else if (vma
> secaddr
)
1361 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1362 objdump_print_value (vma
- secaddr
, inf
, TRUE
);
1364 (*inf
->fprintf_func
) (inf
->stream
, ">");
1368 (*inf
->fprintf_func
) (inf
->stream
, "<");
1370 objdump_print_symname (abfd
, inf
, sym
);
1372 if (bfd_asymbol_value (sym
) == vma
)
1374 /* Undefined symbols in an executables and dynamic objects do not have
1375 a value associated with them, so it does not make sense to display
1376 an offset relative to them. Normally we would not be provided with
1377 this kind of symbol, but the target backend might choose to do so,
1378 and the code in find_symbol_for_address might return an as yet
1379 unresolved symbol associated with a dynamic reloc. */
1380 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1381 && bfd_is_und_section (sym
->section
))
1383 else if (bfd_asymbol_value (sym
) > vma
)
1385 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1386 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, TRUE
);
1388 else if (vma
> bfd_asymbol_value (sym
))
1390 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1391 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, TRUE
);
1394 (*inf
->fprintf_func
) (inf
->stream
, ">");
1397 if (display_file_offsets
)
1398 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1399 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1402 /* Print an address (VMA), symbolically if possible.
1403 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1406 objdump_print_addr (bfd_vma vma
,
1407 struct disassemble_info
*inf
,
1408 bfd_boolean skip_zeroes
)
1410 struct objdump_disasm_info
*aux
;
1411 asymbol
*sym
= NULL
;
1412 bfd_boolean skip_find
= FALSE
;
1414 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1416 if (sorted_symcount
< 1)
1420 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1421 objdump_print_value (vma
, inf
, skip_zeroes
);
1424 if (display_file_offsets
)
1425 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1426 (long int) (inf
->section
->filepos
1427 + (vma
- inf
->section
->vma
)));
1431 if (aux
->reloc
!= NULL
1432 && aux
->reloc
->sym_ptr_ptr
!= NULL
1433 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1435 sym
= * aux
->reloc
->sym_ptr_ptr
;
1437 /* Adjust the vma to the reloc. */
1438 vma
+= bfd_asymbol_value (sym
);
1440 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1445 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1447 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1451 /* Print VMA to INFO. This function is passed to the disassembler
1455 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1457 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1460 /* Determine if the given address has a symbol associated with it. */
1463 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1467 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1469 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
1472 /* Hold the last function name and the last line number we displayed
1473 in a disassembly. */
1475 static char *prev_functionname
;
1476 static unsigned int prev_line
;
1477 static unsigned int prev_discriminator
;
1479 /* We keep a list of all files that we have seen when doing a
1480 disassembly with source, so that we know how much of the file to
1481 display. This can be important for inlined functions. */
1483 struct print_file_list
1485 struct print_file_list
*next
;
1486 const char *filename
;
1487 const char *modname
;
1490 const char **linemap
;
1493 unsigned max_printed
;
1497 static struct print_file_list
*print_files
;
1499 /* The number of preceding context lines to show when we start
1500 displaying a file for the first time. */
1502 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1504 /* Read a complete file into memory. */
1507 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1510 int ps
= getpagesize ();
1514 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1518 if (fstat (fd
, fst
) < 0)
1523 *size
= fst
->st_size
;
1525 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1526 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1527 if (map
!= (char *) -1L)
1533 map
= (const char *) malloc (*size
);
1534 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1536 free ((void *) map
);
1543 #define line_map_decrease 5
1545 /* Precompute array of lines for a mapped file. */
1547 static const char **
1548 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1550 const char *p
, *lstart
, *end
;
1551 int chars_per_line
= 45; /* First iteration will use 40. */
1552 unsigned int lineno
;
1553 const char **linemap
= NULL
;
1554 unsigned long line_map_size
= 0;
1560 for (p
= map
; p
< end
; p
++)
1564 if (p
+ 1 < end
&& p
[1] == '\r')
1567 else if (*p
== '\r')
1569 if (p
+ 1 < end
&& p
[1] == '\n')
1575 /* End of line found. */
1577 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1579 unsigned long newsize
;
1581 chars_per_line
-= line_map_decrease
;
1582 if (chars_per_line
<= 1)
1584 line_map_size
= size
/ chars_per_line
+ 1;
1585 if (line_map_size
< lineno
+ 1)
1586 line_map_size
= lineno
+ 1;
1587 newsize
= line_map_size
* sizeof (char *);
1588 linemap
= (const char **) xrealloc (linemap
, newsize
);
1591 linemap
[lineno
++] = lstart
;
1599 /* Tries to open MODNAME, and if successful adds a node to print_files
1600 linked list and returns that node. Returns NULL on failure. */
1602 static struct print_file_list
*
1603 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1605 struct print_file_list
*p
;
1607 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1609 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1616 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1619 p
->filename
= origname
;
1620 p
->modname
= modname
;
1621 p
->next
= print_files
;
1627 /* If the source file, as described in the symtab, is not found
1628 try to locate it in one of the paths specified with -I
1629 If found, add location to print_files linked list. */
1631 static struct print_file_list
*
1632 update_source_path (const char *filename
, bfd
*abfd
)
1634 struct print_file_list
*p
;
1639 p
= try_print_file_open (filename
, filename
, &fst
);
1642 if (include_path_count
== 0)
1645 /* Get the name of the file. */
1646 fname
= lbasename (filename
);
1648 /* If file exists under a new path, we need to add it to the list
1649 so that show_line knows about it. */
1650 for (i
= 0; i
< include_path_count
; i
++)
1652 char *modname
= concat (include_paths
[i
], "/", fname
,
1655 p
= try_print_file_open (filename
, modname
, &fst
);
1665 long mtime
= bfd_get_mtime (abfd
);
1667 if (fst
.st_mtime
> mtime
)
1668 warn (_("source file %s is more recent than object file\n"),
1675 /* Print a source file line. */
1678 print_line (struct print_file_list
*p
, unsigned int linenum
)
1684 if (linenum
>= p
->maxline
)
1686 l
= p
->linemap
[linenum
];
1687 if (source_comment
!= NULL
&& strlen (l
) > 0)
1688 printf ("%s", source_comment
);
1689 len
= strcspn (l
, "\n\r");
1690 /* Test fwrite return value to quiet glibc warning. */
1691 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1695 /* Print a range of source code lines. */
1698 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1702 while (start
<= end
)
1704 print_line (p
, start
);
1709 /* Show the line number, or the source line, in a disassembly
1713 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1715 const char *filename
;
1716 const char *functionname
;
1717 unsigned int linenumber
;
1718 unsigned int discriminator
;
1722 if (! with_line_numbers
&& ! with_source_code
)
1725 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1726 &filename
, &functionname
,
1727 &linenumber
, &discriminator
))
1730 if (filename
!= NULL
&& *filename
== '\0')
1732 if (functionname
!= NULL
&& *functionname
== '\0')
1733 functionname
= NULL
;
1736 && IS_ABSOLUTE_PATH (filename
)
1740 const char *fname
= filename
;
1742 path
= xmalloc (prefix_length
+ PATH_MAX
+ 1);
1745 memcpy (path
, prefix
, prefix_length
);
1746 path_up
= path
+ prefix_length
;
1748 /* Build relocated filename, stripping off leading directories
1749 from the initial filename if requested. */
1750 if (prefix_strip
> 0)
1755 /* Skip selected directory levels. */
1756 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1757 if (IS_DIR_SEPARATOR (*s
))
1764 /* Update complete filename. */
1765 strncpy (path_up
, fname
, PATH_MAX
);
1766 path_up
[PATH_MAX
] = '\0';
1774 if (with_line_numbers
)
1776 if (functionname
!= NULL
1777 && (prev_functionname
== NULL
1778 || strcmp (functionname
, prev_functionname
) != 0))
1780 char *demangle_alloc
= NULL
;
1781 if (do_demangle
&& functionname
[0] != '\0')
1783 /* Demangle the name. */
1784 demangle_alloc
= bfd_demangle (abfd
, functionname
,
1788 /* Demangling adds trailing parens, so don't print those. */
1789 if (demangle_alloc
!= NULL
)
1790 printf ("%s:\n", sanitize_string (demangle_alloc
));
1792 printf ("%s():\n", sanitize_string (functionname
));
1795 free (demangle_alloc
);
1798 && (linenumber
!= prev_line
1799 || discriminator
!= prev_discriminator
))
1801 if (discriminator
> 0)
1802 printf ("%s:%u (discriminator %u)\n",
1803 filename
== NULL
? "???" : sanitize_string (filename
),
1804 linenumber
, discriminator
);
1806 printf ("%s:%u\n", filename
== NULL
1807 ? "???" : sanitize_string (filename
),
1812 const char *filename2
;
1813 const char *functionname2
;
1816 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
1819 printf ("inlined by %s:%u",
1820 sanitize_string (filename2
), line2
);
1821 printf (" (%s)\n", sanitize_string (functionname2
));
1826 if (with_source_code
1830 struct print_file_list
**pp
, *p
;
1833 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1834 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
1841 filename
= xstrdup (filename
);
1842 p
= update_source_path (filename
, abfd
);
1845 if (p
!= NULL
&& linenumber
!= p
->last_line
)
1847 if (file_start_context
&& p
->first
)
1851 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
1852 if (l
>= linenumber
)
1854 if (p
->max_printed
>= l
)
1856 if (p
->max_printed
< linenumber
)
1857 l
= p
->max_printed
+ 1;
1862 dump_lines (p
, l
, linenumber
);
1863 if (p
->max_printed
< linenumber
)
1864 p
->max_printed
= linenumber
;
1865 p
->last_line
= linenumber
;
1870 if (functionname
!= NULL
1871 && (prev_functionname
== NULL
1872 || strcmp (functionname
, prev_functionname
) != 0))
1874 if (prev_functionname
!= NULL
)
1875 free (prev_functionname
);
1876 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
1877 strcpy (prev_functionname
, functionname
);
1880 if (linenumber
> 0 && linenumber
!= prev_line
)
1881 prev_line
= linenumber
;
1883 if (discriminator
!= prev_discriminator
)
1884 prev_discriminator
= discriminator
;
1890 /* Pseudo FILE object for strings. */
1898 /* sprintf to a "stream". */
1900 static int ATTRIBUTE_PRINTF_2
1901 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1908 size_t space
= f
->alloc
- f
->pos
;
1910 va_start (args
, format
);
1911 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1917 f
->alloc
= (f
->alloc
+ n
) * 2;
1918 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
1925 /* Code for generating (colored) diagrams of control flow start and end
1928 /* Structure used to store the properties of a jump. */
1932 /* The next jump, or NULL if this is the last object. */
1933 struct jump_info
*next
;
1934 /* The previous jump, or NULL if this is the first object. */
1935 struct jump_info
*prev
;
1936 /* The start addresses of the jump. */
1939 /* The list of start addresses. */
1941 /* The number of elements. */
1943 /* The maximum number of elements that fit into the array. */
1946 /* The end address of the jump. */
1948 /* The drawing level of the jump. */
1952 /* Construct a jump object for a jump from start
1953 to end with the corresponding level. */
1955 static struct jump_info
*
1956 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
1958 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
1960 result
->next
= NULL
;
1961 result
->prev
= NULL
;
1962 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
1963 result
->start
.addresses
[0] = start
;
1964 result
->start
.count
= 1;
1965 result
->start
.max_count
= 2;
1967 result
->level
= level
;
1972 /* Free a jump object and return the next object
1973 or NULL if this was the last one. */
1975 static struct jump_info
*
1976 jump_info_free (struct jump_info
*ji
)
1978 struct jump_info
*result
= NULL
;
1983 if (ji
->start
.addresses
)
1984 free (ji
->start
.addresses
);
1991 /* Get the smallest value of all start and end addresses. */
1994 jump_info_min_address (const struct jump_info
*ji
)
1996 bfd_vma min_address
= ji
->end
;
1999 for (i
= ji
->start
.count
; i
-- > 0;)
2000 if (ji
->start
.addresses
[i
] < min_address
)
2001 min_address
= ji
->start
.addresses
[i
];
2005 /* Get the largest value of all start and end addresses. */
2008 jump_info_max_address (const struct jump_info
*ji
)
2010 bfd_vma max_address
= ji
->end
;
2013 for (i
= ji
->start
.count
; i
-- > 0;)
2014 if (ji
->start
.addresses
[i
] > max_address
)
2015 max_address
= ji
->start
.addresses
[i
];
2019 /* Get the target address of a jump. */
2022 jump_info_end_address (const struct jump_info
*ji
)
2027 /* Test if an address is one of the start addresses of a jump. */
2030 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2032 bfd_boolean result
= FALSE
;
2035 for (i
= ji
->start
.count
; i
-- > 0;)
2036 if (address
== ji
->start
.addresses
[i
])
2045 /* Test if an address is the target address of a jump. */
2048 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2050 return (address
== ji
->end
);
2053 /* Get the difference between the smallest and largest address of a jump. */
2056 jump_info_size (const struct jump_info
*ji
)
2058 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2061 /* Unlink a jump object from a list. */
2064 jump_info_unlink (struct jump_info
*node
,
2065 struct jump_info
**base
)
2068 node
->next
->prev
= node
->prev
;
2070 node
->prev
->next
= node
->next
;
2077 /* Insert unlinked jump info node into a list. */
2080 jump_info_insert (struct jump_info
*node
,
2081 struct jump_info
*target
,
2082 struct jump_info
**base
)
2084 node
->next
= target
;
2085 node
->prev
= target
->prev
;
2086 target
->prev
= node
;
2088 node
->prev
->next
= node
;
2093 /* Add unlinked node to the front of a list. */
2096 jump_info_add_front (struct jump_info
*node
,
2097 struct jump_info
**base
)
2101 node
->next
->prev
= node
;
2106 /* Move linked node to target position. */
2109 jump_info_move_linked (struct jump_info
*node
,
2110 struct jump_info
*target
,
2111 struct jump_info
**base
)
2114 jump_info_unlink (node
, base
);
2115 /* Insert node at target position. */
2116 jump_info_insert (node
, target
, base
);
2119 /* Test if two jumps intersect. */
2122 jump_info_intersect (const struct jump_info
*a
,
2123 const struct jump_info
*b
)
2125 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2126 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2129 /* Merge two compatible jump info objects. */
2132 jump_info_merge (struct jump_info
**base
)
2134 struct jump_info
*a
;
2136 for (a
= *base
; a
; a
= a
->next
)
2138 struct jump_info
*b
;
2140 for (b
= a
->next
; b
; b
= b
->next
)
2142 /* Merge both jumps into one. */
2143 if (a
->end
== b
->end
)
2145 /* Reallocate addresses. */
2146 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2149 if (needed_size
> a
->start
.max_count
)
2151 a
->start
.max_count
+= b
->start
.max_count
;
2152 a
->start
.addresses
=
2153 xrealloc (a
->start
.addresses
,
2154 a
->start
.max_count
* sizeof (bfd_vma
*));
2157 /* Append start addresses. */
2158 for (i
= 0; i
< b
->start
.count
; ++i
)
2159 a
->start
.addresses
[a
->start
.count
++] =
2160 b
->start
.addresses
[i
];
2162 /* Remove and delete jump. */
2163 struct jump_info
*tmp
= b
->prev
;
2164 jump_info_unlink (b
, base
);
2172 /* Sort jumps by their size and starting point using a stable
2173 minsort. This could be improved if sorting performance is
2174 an issue, for example by using mergesort. */
2177 jump_info_sort (struct jump_info
**base
)
2179 struct jump_info
*current_element
= *base
;
2181 while (current_element
)
2183 struct jump_info
*best_match
= current_element
;
2184 struct jump_info
*runner
= current_element
->next
;
2185 bfd_vma best_size
= jump_info_size (best_match
);
2189 bfd_vma runner_size
= jump_info_size (runner
);
2191 if ((runner_size
< best_size
)
2192 || ((runner_size
== best_size
)
2193 && (jump_info_min_address (runner
)
2194 < jump_info_min_address (best_match
))))
2196 best_match
= runner
;
2197 best_size
= runner_size
;
2200 runner
= runner
->next
;
2203 if (best_match
== current_element
)
2204 current_element
= current_element
->next
;
2206 jump_info_move_linked (best_match
, current_element
, base
);
2210 /* Visualize all jumps at a given address. */
2213 jump_info_visualize_address (bfd_vma address
,
2216 uint8_t *color_buffer
)
2218 struct jump_info
*ji
= detected_jumps
;
2219 size_t len
= (max_level
+ 1) * 3;
2221 /* Clear line buffer. */
2222 memset (line_buffer
, ' ', len
);
2223 memset (color_buffer
, 0, len
);
2225 /* Iterate over jumps and add their ASCII art. */
2228 /* Discard jumps that are never needed again. */
2229 if (jump_info_max_address (ji
) < address
)
2231 struct jump_info
*tmp
= ji
;
2234 jump_info_unlink (tmp
, &detected_jumps
);
2235 jump_info_free (tmp
);
2239 /* This jump intersects with the current address. */
2240 if (jump_info_min_address (ji
) <= address
)
2242 /* Hash target address to get an even
2243 distribution between all values. */
2244 bfd_vma hash_address
= jump_info_end_address (ji
);
2245 uint8_t color
= iterative_hash_object (hash_address
, 0);
2246 /* Fetch line offset. */
2247 int offset
= (max_level
- ji
->level
) * 3;
2249 /* Draw start line. */
2250 if (jump_info_is_start_address (ji
, address
))
2252 size_t i
= offset
+ 1;
2254 for (; i
< len
- 1; ++i
)
2255 if (line_buffer
[i
] == ' ')
2257 line_buffer
[i
] = '-';
2258 color_buffer
[i
] = color
;
2261 if (line_buffer
[i
] == ' ')
2263 line_buffer
[i
] = '-';
2264 color_buffer
[i
] = color
;
2266 else if (line_buffer
[i
] == '>')
2268 line_buffer
[i
] = 'X';
2269 color_buffer
[i
] = color
;
2272 if (line_buffer
[offset
] == ' ')
2274 if (address
<= ji
->end
)
2275 line_buffer
[offset
] =
2276 (jump_info_min_address (ji
) == address
) ? '/': '+';
2278 line_buffer
[offset
] =
2279 (jump_info_max_address (ji
) == address
) ? '\\': '+';
2280 color_buffer
[offset
] = color
;
2283 /* Draw jump target. */
2284 else if (jump_info_is_end_address (ji
, address
))
2286 size_t i
= offset
+ 1;
2288 for (; i
< len
- 1; ++i
)
2289 if (line_buffer
[i
] == ' ')
2291 line_buffer
[i
] = '-';
2292 color_buffer
[i
] = color
;
2295 if (line_buffer
[i
] == ' ')
2297 line_buffer
[i
] = '>';
2298 color_buffer
[i
] = color
;
2300 else if (line_buffer
[i
] == '-')
2302 line_buffer
[i
] = 'X';
2303 color_buffer
[i
] = color
;
2306 if (line_buffer
[offset
] == ' ')
2308 if (jump_info_min_address (ji
) < address
)
2309 line_buffer
[offset
] =
2310 (jump_info_max_address (ji
) > address
) ? '>' : '\\';
2312 line_buffer
[offset
] = '/';
2313 color_buffer
[offset
] = color
;
2316 /* Draw intermediate line segment. */
2317 else if (line_buffer
[offset
] == ' ')
2319 line_buffer
[offset
] = '|';
2320 color_buffer
[offset
] = color
;
2328 /* Clone of disassemble_bytes to detect jumps inside a function. */
2329 /* FIXME: is this correct? Can we strip it down even further? */
2331 static struct jump_info
*
2332 disassemble_jumps (struct disassemble_info
* inf
,
2333 disassembler_ftype disassemble_fn
,
2334 bfd_vma start_offset
,
2335 bfd_vma stop_offset
,
2338 arelent
** relppend
)
2340 struct objdump_disasm_info
*aux
;
2341 struct jump_info
*jumps
= NULL
;
2343 bfd_vma addr_offset
;
2344 unsigned int opb
= inf
->octets_per_byte
;
2348 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2349 section
= inf
->section
;
2352 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2355 inf
->insn_info_valid
= 0;
2356 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2357 inf
->stream
= &sfile
;
2359 addr_offset
= start_offset
;
2360 while (addr_offset
< stop_offset
)
2362 int previous_octets
;
2364 /* Remember the length of the previous instruction. */
2365 previous_octets
= octets
;
2369 inf
->bytes_per_line
= 0;
2370 inf
->bytes_per_chunk
= 0;
2371 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2372 | (wide_output
? WIDE_OUTPUT
: 0));
2374 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2376 if (inf
->disassembler_needs_relocs
2377 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2378 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2379 && *relppp
< relppend
)
2381 bfd_signed_vma distance_to_rel
;
2383 distance_to_rel
= (**relppp
)->address
- (rel_offset
+ addr_offset
);
2385 /* Check to see if the current reloc is associated with
2386 the instruction that we are about to disassemble. */
2387 if (distance_to_rel
== 0
2388 /* FIXME: This is wrong. We are trying to catch
2389 relocs that are addressed part way through the
2390 current instruction, as might happen with a packed
2391 VLIW instruction. Unfortunately we do not know the
2392 length of the current instruction since we have not
2393 disassembled it yet. Instead we take a guess based
2394 upon the length of the previous instruction. The
2395 proper solution is to have a new target-specific
2396 disassembler function which just returns the length
2397 of an instruction at a given address without trying
2398 to display its disassembly. */
2399 || (distance_to_rel
> 0
2400 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2402 inf
->flags
|= INSN_HAS_RELOC
;
2406 if (! disassemble_all
2407 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2408 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2409 /* Set a stop_vma so that the disassembler will not read
2410 beyond the next symbol. We assume that symbols appear on
2411 the boundaries between instructions. We only do this when
2412 disassembling code of course, and when -D is in effect. */
2413 inf
->stop_vma
= section
->vma
+ stop_offset
;
2415 inf
->stop_offset
= stop_offset
;
2417 /* Extract jump information. */
2418 inf
->insn_info_valid
= 0;
2419 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2420 /* Test if a jump was detected. */
2421 if (inf
->insn_info_valid
2422 && ((inf
->insn_type
== dis_branch
)
2423 || (inf
->insn_type
== dis_condbranch
)
2424 || (inf
->insn_type
== dis_jsr
)
2425 || (inf
->insn_type
== dis_condjsr
))
2426 && (inf
->target
>= section
->vma
+ start_offset
)
2427 && (inf
->target
< section
->vma
+ stop_offset
))
2429 struct jump_info
*ji
=
2430 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
2431 jump_info_add_front (ji
, &jumps
);
2436 addr_offset
+= octets
/ opb
;
2439 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2440 inf
->stream
= stdout
;
2442 free (sfile
.buffer
);
2445 jump_info_merge (&jumps
);
2446 /* Process jumps. */
2447 jump_info_sort (&jumps
);
2449 /* Group jumps by level. */
2450 struct jump_info
*last_jump
= jumps
;
2455 /* The last jump is part of the next group. */
2456 struct jump_info
*base
= last_jump
;
2457 /* Increment level. */
2458 base
->level
= ++max_level
;
2460 /* Find jumps that can be combined on the same
2461 level, with the largest jumps tested first.
2462 This has the advantage that large jumps are on
2463 lower levels and do not intersect with small
2464 jumps that get grouped on higher levels. */
2465 struct jump_info
*exchange_item
= last_jump
->next
;
2466 struct jump_info
*it
= exchange_item
;
2468 for (; it
; it
= it
->next
)
2470 /* Test if the jump intersects with any
2471 jump from current group. */
2472 bfd_boolean ok
= TRUE
;
2473 struct jump_info
*it_collision
;
2475 for (it_collision
= base
;
2476 it_collision
!= exchange_item
;
2477 it_collision
= it_collision
->next
)
2479 /* This jump intersects so we leave it out. */
2480 if (jump_info_intersect (it_collision
, it
))
2487 /* Add jump to group. */
2490 /* Move current element to the front. */
2491 if (it
!= exchange_item
)
2493 struct jump_info
*save
= it
->prev
;
2494 jump_info_move_linked (it
, exchange_item
, &jumps
);
2500 last_jump
= exchange_item
;
2501 exchange_item
= exchange_item
->next
;
2503 last_jump
->level
= max_level
;
2507 /* Move to next group. */
2508 last_jump
= exchange_item
;
2514 /* The number of zeroes we want to see before we start skipping them.
2515 The number is arbitrarily chosen. */
2517 #define DEFAULT_SKIP_ZEROES 8
2519 /* The number of zeroes to skip at the end of a section. If the
2520 number of zeroes at the end is between SKIP_ZEROES_AT_END and
2521 SKIP_ZEROES, they will be disassembled. If there are fewer than
2522 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
2523 attempt to avoid disassembling zeroes inserted by section
2526 #define DEFAULT_SKIP_ZEROES_AT_END 3
2529 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
2534 /* Print out jump visualization. */
2537 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
2538 uint8_t *color_buffer
)
2543 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
2545 size_t line_buffer_size
= strlen (line_buffer
);
2546 char last_color
= 0;
2549 for (i
= 0; i
<= line_buffer_size
; ++i
)
2553 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
2555 if (color
!= last_color
)
2558 if (extended_color_output
)
2559 /* Use extended 8bit color, but
2560 do not choose dark colors. */
2561 printf ("\033[38;5;%dm", 124 + (color
% 108));
2563 /* Use simple terminal colors. */
2564 printf ("\033[%dm", 31 + (color
% 7));
2571 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
2575 /* Disassemble some data in memory between given values. */
2578 disassemble_bytes (struct disassemble_info
* inf
,
2579 disassembler_ftype disassemble_fn
,
2582 bfd_vma start_offset
,
2583 bfd_vma stop_offset
,
2586 arelent
** relppend
)
2588 struct objdump_disasm_info
*aux
;
2590 unsigned int octets_per_line
;
2591 unsigned int skip_addr_chars
;
2592 bfd_vma addr_offset
;
2593 unsigned int opb
= inf
->octets_per_byte
;
2594 unsigned int skip_zeroes
= inf
->skip_zeroes
;
2595 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
2599 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2600 section
= inf
->section
;
2603 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2607 octets_per_line
= insn_width
;
2609 octets_per_line
= 4;
2611 octets_per_line
= 16;
2613 /* Figure out how many characters to skip at the start of an
2614 address, to make the disassembly look nicer. We discard leading
2615 zeroes in chunks of 4, ensuring that there is always a leading
2617 skip_addr_chars
= 0;
2618 if (!no_addresses
&& !prefix_addresses
)
2622 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
2624 while (buf
[skip_addr_chars
] == '0')
2627 /* Don't discard zeros on overflow. */
2628 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
2629 skip_addr_chars
= 0;
2631 if (skip_addr_chars
!= 0)
2632 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
2635 inf
->insn_info_valid
= 0;
2637 /* Determine maximum level. */
2638 uint8_t *color_buffer
= NULL
;
2639 char *line_buffer
= NULL
;
2642 /* Some jumps were detected. */
2645 struct jump_info
*ji
;
2647 /* Find maximum jump level. */
2648 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
2650 if (ji
->level
> max_level
)
2651 max_level
= ji
->level
;
2654 /* Allocate buffers. */
2655 size_t len
= (max_level
+ 1) * 3 + 1;
2656 line_buffer
= xmalloc (len
);
2657 line_buffer
[len
- 1] = 0;
2658 color_buffer
= xmalloc (len
);
2659 color_buffer
[len
- 1] = 0;
2662 addr_offset
= start_offset
;
2663 while (addr_offset
< stop_offset
)
2665 bfd_boolean need_nl
= FALSE
;
2669 /* Make sure we don't use relocs from previous instructions. */
2672 /* If we see more than SKIP_ZEROES octets of zeroes, we just
2674 if (! disassemble_zeroes
)
2675 for (; addr_offset
* opb
+ octets
< stop_offset
* opb
; octets
++)
2676 if (data
[addr_offset
* opb
+ octets
] != 0)
2678 if (! disassemble_zeroes
2679 && (inf
->insn_info_valid
== 0
2680 || inf
->branch_delay_insns
== 0)
2681 && (octets
>= skip_zeroes
2682 || (addr_offset
* opb
+ octets
== stop_offset
* opb
2683 && octets
< skip_zeroes_at_end
)))
2685 /* If there are more nonzero octets to follow, we only skip
2686 zeroes in multiples of 4, to try to avoid running over
2687 the start of an instruction which happens to start with
2689 if (addr_offset
* opb
+ octets
!= stop_offset
* opb
)
2692 /* If we are going to display more data, and we are displaying
2693 file offsets, then tell the user how many zeroes we skip
2694 and the file offset from where we resume dumping. */
2695 if (display_file_offsets
2696 && addr_offset
+ octets
/ opb
< stop_offset
)
2697 printf (_("\t... (skipping %lu zeroes, "
2698 "resuming at file offset: 0x%lx)\n"),
2699 (unsigned long) (octets
/ opb
),
2700 (unsigned long) (section
->filepos
2701 + addr_offset
+ octets
/ opb
));
2708 unsigned int bpc
= 0;
2709 unsigned int pb
= 0;
2711 if (with_line_numbers
|| with_source_code
)
2712 show_line (aux
->abfd
, section
, addr_offset
);
2716 else if (!prefix_addresses
)
2720 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
2721 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2725 printf ("%s:\t", buf
+ skip_addr_chars
);
2729 aux
->require_sec
= TRUE
;
2730 objdump_print_address (section
->vma
+ addr_offset
, inf
);
2731 aux
->require_sec
= FALSE
;
2735 print_jump_visualisation (section
->vma
+ addr_offset
,
2736 max_level
, line_buffer
,
2744 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2745 inf
->stream
= &sfile
;
2746 inf
->bytes_per_line
= 0;
2747 inf
->bytes_per_chunk
= 0;
2748 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2749 | (wide_output
? WIDE_OUTPUT
: 0));
2751 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2753 if (inf
->disassembler_needs_relocs
2754 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2755 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2756 && *relppp
< relppend
)
2758 bfd_signed_vma distance_to_rel
;
2759 int max_reloc_offset
2760 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
2762 distance_to_rel
= ((**relppp
)->address
- rel_offset
2766 if (distance_to_rel
> 0
2767 && (max_reloc_offset
< 0
2768 || distance_to_rel
<= max_reloc_offset
))
2770 /* This reloc *might* apply to the current insn,
2771 starting somewhere inside it. Discover the length
2772 of the current insn so that the check below will
2775 insn_size
= insn_width
;
2778 /* We find the length by calling the dissassembler
2779 function with a dummy print handler. This should
2780 work unless the disassembler is not expecting to
2781 be called multiple times for the same address.
2783 This does mean disassembling the instruction
2784 twice, but we only do this when there is a high
2785 probability that there is a reloc that will
2786 affect the instruction. */
2787 inf
->fprintf_func
= (fprintf_ftype
) null_print
;
2788 insn_size
= disassemble_fn (section
->vma
2789 + addr_offset
, inf
);
2790 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2794 /* Check to see if the current reloc is associated with
2795 the instruction that we are about to disassemble. */
2796 if (distance_to_rel
== 0
2797 || (distance_to_rel
> 0
2798 && distance_to_rel
< insn_size
/ (int) opb
))
2800 inf
->flags
|= INSN_HAS_RELOC
;
2801 aux
->reloc
= **relppp
;
2805 if (! disassemble_all
2806 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2807 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
2808 /* Set a stop_vma so that the disassembler will not read
2809 beyond the next symbol. We assume that symbols appear on
2810 the boundaries between instructions. We only do this when
2811 disassembling code of course, and when -D is in effect. */
2812 inf
->stop_vma
= section
->vma
+ stop_offset
;
2814 inf
->stop_offset
= stop_offset
;
2815 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2819 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2820 inf
->stream
= stdout
;
2821 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
2822 octets_per_line
= inf
->bytes_per_line
;
2823 if (insn_size
< (int) opb
)
2826 printf ("%s\n", sfile
.buffer
);
2829 non_fatal (_("disassemble_fn returned length %d"),
2840 octets
= octets_per_line
;
2841 if (addr_offset
+ octets
/ opb
> stop_offset
)
2842 octets
= (stop_offset
- addr_offset
) * opb
;
2844 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
2846 if (ISPRINT (data
[j
]))
2847 buf
[j
- addr_offset
* opb
] = data
[j
];
2849 buf
[j
- addr_offset
* opb
] = '.';
2851 buf
[j
- addr_offset
* opb
] = '\0';
2854 if (prefix_addresses
2856 : show_raw_insn
>= 0)
2860 /* If ! prefix_addresses and ! wide_output, we print
2861 octets_per_line octets per line. */
2863 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
2864 pb
= octets_per_line
;
2866 if (inf
->bytes_per_chunk
)
2867 bpc
= inf
->bytes_per_chunk
;
2871 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2873 /* PR 21580: Check for a buffer ending early. */
2874 if (j
+ bpc
<= stop_offset
* opb
)
2878 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2880 for (k
= bpc
; k
-- != 0; )
2881 printf ("%02x", (unsigned) data
[j
+ k
]);
2885 for (k
= 0; k
< bpc
; k
++)
2886 printf ("%02x", (unsigned) data
[j
+ k
]);
2892 for (; pb
< octets_per_line
; pb
+= bpc
)
2896 for (k
= 0; k
< bpc
; k
++)
2901 /* Separate raw data from instruction by extra space. */
2911 printf ("%s", sfile
.buffer
);
2913 if (prefix_addresses
2915 : show_raw_insn
>= 0)
2923 j
= addr_offset
* opb
+ pb
;
2929 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
2930 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2934 printf ("%s:\t", buf
+ skip_addr_chars
);
2937 print_jump_visualisation (section
->vma
+ j
/ opb
,
2938 max_level
, line_buffer
,
2941 pb
+= octets_per_line
;
2944 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2946 /* PR 21619: Check for a buffer ending early. */
2947 if (j
+ bpc
<= stop_offset
* opb
)
2951 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2953 for (k
= bpc
; k
-- != 0; )
2954 printf ("%02x", (unsigned) data
[j
+ k
]);
2958 for (k
= 0; k
< bpc
; k
++)
2959 printf ("%02x", (unsigned) data
[j
+ k
]);
2973 while ((*relppp
) < relppend
2974 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
2976 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
2989 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
2994 if (q
->howto
== NULL
)
2995 printf ("*unknown*\t");
2996 else if (q
->howto
->name
)
2997 printf ("%s\t", q
->howto
->name
);
2999 printf ("%d\t", q
->howto
->type
);
3001 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
3002 printf ("*unknown*");
3005 const char *sym_name
;
3007 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
3008 if (sym_name
!= NULL
&& *sym_name
!= '\0')
3009 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
3014 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
3015 sym_name
= bfd_section_name (sym_sec
);
3016 if (sym_name
== NULL
|| *sym_name
== '\0')
3017 sym_name
= "*unknown*";
3018 printf ("%s", sanitize_string (sym_name
));
3024 bfd_vma addend
= q
->addend
;
3025 if ((bfd_signed_vma
) addend
< 0)
3032 objdump_print_value (addend
, inf
, TRUE
);
3044 addr_offset
+= octets
/ opb
;
3047 free (sfile
.buffer
);
3049 free (color_buffer
);
3053 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3055 const struct elf_backend_data
* bed
;
3056 bfd_vma sign_adjust
= 0;
3057 struct disassemble_info
* pinfo
= (struct disassemble_info
*) inf
;
3058 struct objdump_disasm_info
* paux
;
3059 unsigned int opb
= pinfo
->octets_per_byte
;
3060 bfd_byte
* data
= NULL
;
3061 bfd_size_type datasize
= 0;
3062 arelent
** rel_pp
= NULL
;
3063 arelent
** rel_ppstart
= NULL
;
3064 arelent
** rel_ppend
;
3065 bfd_vma stop_offset
;
3066 asymbol
* sym
= NULL
;
3070 unsigned long addr_offset
;
3071 bfd_boolean do_print
;
3074 stop_offset_reached
,
3079 /* Sections that do not contain machine
3080 code are not normally disassembled. */
3081 if (! disassemble_all
3082 && only_list
== NULL
3083 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3084 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
3087 if (! process_section_p (section
))
3090 datasize
= bfd_section_size (section
);
3094 if (start_address
== (bfd_vma
) -1
3095 || start_address
< section
->vma
)
3098 addr_offset
= start_address
- section
->vma
;
3100 if (stop_address
== (bfd_vma
) -1)
3101 stop_offset
= datasize
/ opb
;
3104 if (stop_address
< section
->vma
)
3107 stop_offset
= stop_address
- section
->vma
;
3108 if (stop_offset
> datasize
/ opb
)
3109 stop_offset
= datasize
/ opb
;
3112 if (addr_offset
>= stop_offset
)
3115 /* Decide which set of relocs to use. Load them if necessary. */
3116 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3117 if (paux
->dynrelbuf
&& dump_dynamic_reloc_info
)
3119 rel_pp
= paux
->dynrelbuf
;
3120 rel_count
= paux
->dynrelcount
;
3121 /* Dynamic reloc addresses are absolute, non-dynamic are section
3122 relative. REL_OFFSET specifies the reloc address corresponding
3123 to the start of this section. */
3124 rel_offset
= section
->vma
;
3132 if ((section
->flags
& SEC_RELOC
) != 0
3133 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3137 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3139 bfd_fatal (bfd_get_filename (abfd
));
3143 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
3144 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3146 bfd_fatal (bfd_get_filename (abfd
));
3148 /* Sort the relocs by address. */
3149 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3153 rel_ppend
= rel_pp
+ rel_count
;
3155 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3157 non_fatal (_("Reading section %s failed because: %s"),
3158 section
->name
, bfd_errmsg (bfd_get_error ()));
3162 pinfo
->buffer
= data
;
3163 pinfo
->buffer_vma
= section
->vma
;
3164 pinfo
->buffer_length
= datasize
;
3165 pinfo
->section
= section
;
3167 /* Sort the symbols into value and section order. */
3168 compare_section
= section
;
3169 if (sorted_symcount
> 1)
3170 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3172 /* Skip over the relocs belonging to addresses below the
3174 while (rel_pp
< rel_ppend
3175 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3178 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3180 /* Find the nearest symbol forwards from our current position. */
3181 paux
->require_sec
= TRUE
;
3182 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3183 (struct disassemble_info
*) inf
,
3185 paux
->require_sec
= FALSE
;
3187 /* PR 9774: If the target used signed addresses then we must make
3188 sure that we sign extend the value that we calculate for 'addr'
3189 in the loop below. */
3190 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3191 && (bed
= get_elf_backend_data (abfd
)) != NULL
3192 && bed
->sign_extend_vma
)
3193 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3195 /* Disassemble a block of instructions up to the address associated with
3196 the symbol we have just found. Then print the symbol and find the
3197 next symbol on. Repeat until we have disassembled the entire section
3198 or we have reached the end of the address range we are interested in. */
3199 do_print
= paux
->symbol
== NULL
;
3200 loop_until
= stop_offset_reached
;
3202 while (addr_offset
< stop_offset
)
3206 bfd_vma nextstop_offset
;
3209 addr
= section
->vma
+ addr_offset
;
3210 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3212 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3217 (x
< sorted_symcount
3218 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3222 pinfo
->symbols
= sorted_syms
+ place
;
3223 pinfo
->num_symbols
= x
- place
;
3224 pinfo
->symtab_pos
= place
;
3228 pinfo
->symbols
= NULL
;
3229 pinfo
->num_symbols
= 0;
3230 pinfo
->symtab_pos
= -1;
3233 /* If we are only disassembling from a specific symbol,
3234 check to see if we should start or stop displaying. */
3235 if (sym
&& paux
->symbol
)
3239 /* See if we should stop printing. */
3243 if (sym
->flags
& BSF_FUNCTION
)
3247 case stop_offset_reached
:
3248 /* Handled by the while loop. */
3252 /* FIXME: There is an implicit assumption here
3253 that the name of sym is different from
3255 if (! bfd_is_local_label (abfd
, sym
))
3262 const char * name
= bfd_asymbol_name (sym
);
3263 char * alloc
= NULL
;
3265 if (do_demangle
&& name
[0] != '\0')
3267 /* Demangle the name. */
3268 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3273 /* We are not currently printing. Check to see
3274 if the current symbol matches the requested symbol. */
3275 if (streq (name
, paux
->symbol
))
3279 if (sym
->flags
& BSF_FUNCTION
)
3281 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3282 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
3284 /* Sym is a function symbol with a size associated
3285 with it. Turn on automatic disassembly for the
3286 next VALUE bytes. */
3287 stop_offset
= addr_offset
3288 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
3289 loop_until
= stop_offset_reached
;
3293 /* Otherwise we need to tell the loop heuristic to
3294 loop until the next function symbol is encountered. */
3295 loop_until
= function_sym
;
3300 /* Otherwise loop until the next symbol is encountered. */
3301 loop_until
= next_sym
;
3309 if (! prefix_addresses
&& do_print
)
3311 pinfo
->fprintf_func (pinfo
->stream
, "\n");
3312 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
3314 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
3317 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3319 else if (sym
== NULL
)
3323 #define is_valid_next_sym(SYM) \
3324 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
3325 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
3326 && pinfo->symbol_is_valid (SYM, pinfo))
3328 /* Search forward for the next appropriate symbol in
3329 SECTION. Note that all the symbols are sorted
3330 together into one big array, and that some sections
3331 may have overlapping addresses. */
3332 while (place
< sorted_symcount
3333 && ! is_valid_next_sym (sorted_syms
[place
]))
3336 if (place
>= sorted_symcount
)
3339 nextsym
= sorted_syms
[place
];
3342 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3343 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
3344 else if (nextsym
== NULL
)
3345 nextstop_offset
= stop_offset
;
3347 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
3349 if (nextstop_offset
> stop_offset
3350 || nextstop_offset
<= addr_offset
)
3351 nextstop_offset
= stop_offset
;
3353 /* If a symbol is explicitly marked as being an object
3354 rather than a function, just dump the bytes without
3355 disassembling them. */
3358 || sym
->section
!= section
3359 || bfd_asymbol_value (sym
) > addr
3360 || ((sym
->flags
& BSF_OBJECT
) == 0
3361 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
3363 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
3365 || (sym
->flags
& BSF_FUNCTION
) != 0)
3372 /* Resolve symbol name. */
3373 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
3375 struct disassemble_info di
;
3378 sf
.alloc
= strlen (sym
->name
) + 40;
3379 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
3381 di
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
3384 objdump_print_symname (abfd
, &di
, sym
);
3386 /* Fetch jump information. */
3387 detected_jumps
= disassemble_jumps
3388 (pinfo
, paux
->disassemble_fn
,
3389 addr_offset
, nextstop_offset
,
3390 rel_offset
, &rel_pp
, rel_ppend
);
3392 /* Free symbol name. */
3396 /* Add jumps to output. */
3397 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
3398 addr_offset
, nextstop_offset
,
3399 rel_offset
, &rel_pp
, rel_ppend
);
3402 while (detected_jumps
)
3404 detected_jumps
= jump_info_free (detected_jumps
);
3408 addr_offset
= nextstop_offset
;
3414 if (rel_ppstart
!= NULL
)
3418 /* Disassemble the contents of an object file. */
3421 disassemble_data (bfd
*abfd
)
3423 struct disassemble_info disasm_info
;
3424 struct objdump_disasm_info aux
;
3428 prev_functionname
= NULL
;
3430 prev_discriminator
= 0;
3432 /* We make a copy of syms to sort. We don't want to sort syms
3433 because that will screw up the relocs. */
3434 sorted_symcount
= symcount
? symcount
: dynsymcount
;
3435 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
3436 * sizeof (asymbol
*));
3437 if (sorted_symcount
!= 0)
3439 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
3440 sorted_symcount
* sizeof (asymbol
*));
3442 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
3445 for (i
= 0; i
< synthcount
; ++i
)
3447 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
3451 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
3453 disasm_info
.application_data
= (void *) &aux
;
3455 aux
.require_sec
= FALSE
;
3456 aux
.dynrelbuf
= NULL
;
3457 aux
.dynrelcount
= 0;
3459 aux
.symbol
= disasm_sym
;
3461 disasm_info
.print_address_func
= objdump_print_address
;
3462 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
3464 if (machine
!= NULL
)
3466 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
3469 fatal (_("can't use supplied machine %s"), machine
);
3471 abfd
->arch_info
= inf
;
3474 if (endian
!= BFD_ENDIAN_UNKNOWN
)
3476 struct bfd_target
*xvec
;
3478 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
3479 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
3480 xvec
->byteorder
= endian
;
3484 /* Use libopcodes to locate a suitable disassembler. */
3485 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
3486 bfd_big_endian (abfd
),
3487 bfd_get_mach (abfd
), abfd
);
3488 if (!aux
.disassemble_fn
)
3490 non_fatal (_("can't disassemble for architecture %s\n"),
3491 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
3496 disasm_info
.flavour
= bfd_get_flavour (abfd
);
3497 disasm_info
.arch
= bfd_get_arch (abfd
);
3498 disasm_info
.mach
= bfd_get_mach (abfd
);
3499 disasm_info
.disassembler_options
= disassembler_options
;
3500 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
3501 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
3502 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
3503 disasm_info
.disassembler_needs_relocs
= FALSE
;
3505 if (bfd_big_endian (abfd
))
3506 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
3507 else if (bfd_little_endian (abfd
))
3508 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
3510 /* ??? Aborting here seems too drastic. We could default to big or little
3512 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
3514 disasm_info
.endian_code
= disasm_info
.endian
;
3516 /* Allow the target to customize the info structure. */
3517 disassemble_init_for_target (& disasm_info
);
3519 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
3521 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3523 if (relsize
< 0 && dump_dynamic_reloc_info
)
3524 bfd_fatal (bfd_get_filename (abfd
));
3528 aux
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
3529 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
3532 if (aux
.dynrelcount
< 0)
3533 bfd_fatal (bfd_get_filename (abfd
));
3535 /* Sort the relocs by address. */
3536 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
3540 disasm_info
.symtab
= sorted_syms
;
3541 disasm_info
.symtab_size
= sorted_symcount
;
3543 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
3545 if (aux
.dynrelbuf
!= NULL
)
3546 free (aux
.dynrelbuf
);
3548 disassemble_free_target (&disasm_info
);
3552 load_specific_debug_section (enum dwarf_section_display_enum debug
,
3553 asection
*sec
, void *file
)
3555 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3556 bfd
*abfd
= (bfd
*) file
;
3562 if (section
->start
!= NULL
)
3564 /* If it is already loaded, do nothing. */
3565 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3567 free (section
->start
);
3570 section
->filename
= bfd_get_filename (abfd
);
3571 section
->reloc_info
= NULL
;
3572 section
->num_relocs
= 0;
3573 section
->address
= bfd_section_vma (sec
);
3574 section
->size
= bfd_section_size (sec
);
3575 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
3576 alloced
= amt
= section
->size
+ 1;
3577 if (alloced
!= amt
|| alloced
== 0)
3579 section
->start
= NULL
;
3580 free_debug_section (debug
);
3581 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
3582 sanitize_string (section
->name
),
3583 (unsigned long long) section
->size
);
3587 section
->start
= contents
= xmalloc (alloced
);
3588 /* Ensure any string section has a terminating NUL. */
3589 section
->start
[section
->size
] = 0;
3591 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
3592 && debug_displays
[debug
].relocate
)
3594 ret
= bfd_simple_get_relocated_section_contents (abfd
,
3600 long reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
3604 unsigned long reloc_count
;
3607 relocs
= (arelent
**) xmalloc (reloc_size
);
3609 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
3610 if (reloc_count
== 0)
3614 section
->reloc_info
= relocs
;
3615 section
->num_relocs
= reloc_count
;
3621 ret
= bfd_get_full_section_contents (abfd
, sec
, &contents
);
3625 free_debug_section (debug
);
3626 printf (_("\nCan't get contents for section '%s'.\n"),
3627 sanitize_string (section
->name
));
3635 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
3640 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
3643 relocs
= (arelent
**) dsec
->reloc_info
;
3645 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
3646 if (rp
->address
== offset
)
3653 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
3655 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3656 bfd
*abfd
= (bfd
*) file
;
3659 /* If it is already loaded, do nothing. */
3660 if (section
->start
!= NULL
)
3662 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3666 /* Locate the debug section. */
3667 sec
= bfd_get_section_by_name (abfd
, section
->uncompressed_name
);
3669 section
->name
= section
->uncompressed_name
;
3672 sec
= bfd_get_section_by_name (abfd
, section
->compressed_name
);
3674 section
->name
= section
->compressed_name
;
3679 return load_specific_debug_section (debug
, sec
, file
);
3683 free_debug_section (enum dwarf_section_display_enum debug
)
3685 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3687 free ((char *) section
->start
);
3688 section
->start
= NULL
;
3689 section
->address
= 0;
3694 close_debug_file (void * file
)
3696 bfd
* abfd
= (bfd
*) file
;
3702 open_debug_file (const char * pathname
)
3706 data
= bfd_openr (pathname
, NULL
);
3710 if (! bfd_check_format (data
, bfd_object
))
3716 #if HAVE_LIBDEBUGINFOD
3717 /* Return a hex string represention of the build-id. */
3720 get_build_id (void * data
)
3723 char * build_id_str
;
3724 bfd
* abfd
= (bfd
*) data
;
3725 const struct bfd_build_id
* build_id
;
3727 build_id
= abfd
->build_id
;
3728 if (build_id
== NULL
)
3731 build_id_str
= malloc (build_id
->size
* 2 + 1);
3732 if (build_id_str
== NULL
)
3735 for (i
= 0; i
< build_id
->size
; i
++)
3736 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
3737 build_id_str
[build_id
->size
* 2] = '\0';
3739 return (unsigned char *)build_id_str
;
3741 #endif /* HAVE_LIBDEBUGINFOD */
3744 dump_dwarf_section (bfd
*abfd
, asection
*section
,
3745 void *arg ATTRIBUTE_UNUSED
)
3747 const char *name
= bfd_section_name (section
);
3751 if (startswith (name
, ".gnu.linkonce.wi."))
3752 match
= ".debug_info";
3756 for (i
= 0; i
< max
; i
++)
3757 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
3758 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0)
3759 && debug_displays
[i
].enabled
!= NULL
3760 && *debug_displays
[i
].enabled
)
3762 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
3764 if (strcmp (sec
->uncompressed_name
, match
) == 0)
3765 sec
->name
= sec
->uncompressed_name
;
3767 sec
->name
= sec
->compressed_name
;
3768 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
3771 debug_displays
[i
].display (sec
, abfd
);
3773 if (i
!= info
&& i
!= abbrev
)
3774 free_debug_section ((enum dwarf_section_display_enum
) i
);
3780 /* Dump the dwarf debugging information. */
3783 dump_dwarf (bfd
*abfd
)
3785 /* The byte_get pointer should have been set at the start of dump_bfd(). */
3786 if (byte_get
== NULL
)
3788 warn (_("File %s does not contain any dwarf debug information\n"),
3789 bfd_get_filename (abfd
));
3793 switch (bfd_get_arch (abfd
))
3796 /* S12Z has a 24 bit address space. But the only known
3797 producer of dwarf_info encodes addresses into 32 bits. */
3802 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
3806 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
3807 bfd_get_mach (abfd
));
3809 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
3812 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
3813 it. Return NULL on failure. */
3816 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
3817 bfd_size_type
*entsize_ptr
)
3822 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
3823 if (stabsect
== NULL
)
3825 printf (_("No %s section present\n\n"),
3826 sanitize_string (sect_name
));
3830 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
3832 non_fatal (_("reading %s section of %s failed: %s"),
3833 sect_name
, bfd_get_filename (abfd
),
3834 bfd_errmsg (bfd_get_error ()));
3840 *size_ptr
= bfd_section_size (stabsect
);
3842 *entsize_ptr
= stabsect
->entsize
;
3847 /* Stabs entries use a 12 byte format:
3848 4 byte string table index
3850 1 byte stab other field
3851 2 byte stab desc field
3853 FIXME: This will have to change for a 64 bit object format. */
3855 #define STRDXOFF (0)
3857 #define OTHEROFF (5)
3860 #define STABSIZE (12)
3862 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
3863 using string table section STRSECT_NAME (in `strtab'). */
3866 print_section_stabs (bfd
*abfd
,
3867 const char *stabsect_name
,
3868 unsigned *string_offset_ptr
)
3871 unsigned file_string_table_offset
= 0;
3872 unsigned next_file_string_table_offset
= *string_offset_ptr
;
3873 bfd_byte
*stabp
, *stabs_end
;
3876 stabs_end
= stabp
+ stab_size
;
3878 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
3879 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
3881 /* Loop through all symbols and print them.
3883 We start the index at -1 because there is a dummy symbol on
3884 the front of stabs-in-{coff,elf} sections that supplies sizes. */
3885 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
3889 unsigned char type
, other
;
3890 unsigned short desc
;
3893 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
3894 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
3895 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
3896 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
3897 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
3899 printf ("\n%-6d ", i
);
3900 /* Either print the stab name, or, if unnamed, print its number
3901 again (makes consistent formatting for tools like awk). */
3902 name
= bfd_get_stab_name (type
);
3904 printf ("%-6s", sanitize_string (name
));
3905 else if (type
== N_UNDF
)
3908 printf ("%-6d", type
);
3909 printf (" %-6d %-6d ", other
, desc
);
3910 bfd_printf_vma (abfd
, value
);
3911 printf (" %-6lu", strx
);
3913 /* Symbols with type == 0 (N_UNDF) specify the length of the
3914 string table associated with this file. We use that info
3915 to know how to relocate the *next* file's string table indices. */
3918 file_string_table_offset
= next_file_string_table_offset
;
3919 next_file_string_table_offset
+= value
;
3923 bfd_size_type amt
= strx
+ file_string_table_offset
;
3925 /* Using the (possibly updated) string table offset, print the
3926 string (if any) associated with this symbol. */
3927 if (amt
< stabstr_size
)
3928 /* PR 17512: file: 079-79389-0.001:0.1.
3929 FIXME: May need to sanitize this string before displaying. */
3930 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
3936 *string_offset_ptr
= next_file_string_table_offset
;
3941 const char * section_name
;
3942 const char * string_section_name
;
3943 unsigned string_offset
;
3948 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
3951 stab_section_names
* sought
= (stab_section_names
*) names
;
3953 /* Check for section names for which stabsect_name is a prefix, to
3954 handle .stab.N, etc. */
3955 len
= strlen (sought
->section_name
);
3957 /* If the prefix matches, and the files section name ends with a
3958 nul or a digit, then we match. I.e., we want either an exact
3959 match or a section followed by a number. */
3960 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
3961 && (section
->name
[len
] == 0
3962 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
3965 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
3966 &stabstr_size
, NULL
);
3970 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
3972 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
3978 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
3980 stab_section_names s
;
3982 s
.section_name
= stabsect_name
;
3983 s
.string_section_name
= strsect_name
;
3984 s
.string_offset
= 0;
3986 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
3992 /* Dump the any sections containing stabs debugging information. */
3995 dump_stabs (bfd
*abfd
)
3997 dump_stabs_section (abfd
, ".stab", ".stabstr");
3998 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
3999 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4002 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4004 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4008 dump_bfd_header (bfd
*abfd
)
4012 printf (_("architecture: %s, "),
4013 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4014 bfd_get_mach (abfd
)));
4015 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4017 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4018 PF (HAS_RELOC
, "HAS_RELOC");
4019 PF (EXEC_P
, "EXEC_P");
4020 PF (HAS_LINENO
, "HAS_LINENO");
4021 PF (HAS_DEBUG
, "HAS_DEBUG");
4022 PF (HAS_SYMS
, "HAS_SYMS");
4023 PF (HAS_LOCALS
, "HAS_LOCALS");
4024 PF (DYNAMIC
, "DYNAMIC");
4025 PF (WP_TEXT
, "WP_TEXT");
4026 PF (D_PAGED
, "D_PAGED");
4027 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4028 printf (_("\nstart address 0x"));
4029 bfd_printf_vma (abfd
, abfd
->start_address
);
4034 #ifdef ENABLE_LIBCTF
4035 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4036 it is passed, or a pointer to newly-allocated storage, in which case
4037 dump_ctf() will free it when it no longer needs it. */
4040 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4043 const char *blanks
= arg
;
4046 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
4051 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4053 make_ctfsect (const char *name
, bfd_byte
*data
,
4058 ctfsect
.cts_name
= name
;
4059 ctfsect
.cts_entsize
= 1;
4060 ctfsect
.cts_size
= size
;
4061 ctfsect
.cts_data
= data
;
4066 /* Dump CTF errors/warnings. */
4068 dump_ctf_errs (ctf_dict_t
*fp
)
4070 ctf_next_t
*it
= NULL
;
4075 /* Dump accumulated errors and warnings. */
4076 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
4078 non_fatal (_("%s: %s"), is_warning
? _("warning"): _("error"),
4082 if (err
!= ECTF_NEXT_END
)
4084 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4089 /* Dump one CTF archive member. */
4092 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, void *arg
)
4094 ctf_dict_t
*parent
= (ctf_dict_t
*) arg
;
4095 const char *things
[] = {"Header", "Labels", "Data objects",
4096 "Function objects", "Variables", "Types", "Strings",
4101 /* Only print out the name of non-default-named archive members.
4102 The name .ctf appears everywhere, even for things that aren't
4103 really archives, so printing it out is liable to be confusing.
4105 The parent, if there is one, is the default-owned archive member:
4106 avoid importing it into itself. (This does no harm, but looks
4109 if (strcmp (name
, ".ctf") != 0)
4111 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4112 ctf_import (ctf
, parent
);
4115 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4117 ctf_dump_state_t
*s
= NULL
;
4120 printf ("\n %s:\n", *thing
);
4121 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4122 (void *) " ")) != NULL
)
4124 printf ("%s\n", item
);
4128 if (ctf_errno (ctf
))
4130 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4131 ctf_errmsg (ctf_errno (ctf
)));
4136 dump_ctf_errs (ctf
);
4141 /* Dump the CTF debugging information. */
4144 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
4146 ctf_archive_t
*ctfa
, *parenta
= NULL
, *lookparent
;
4147 bfd_byte
*ctfdata
, *parentdata
= NULL
;
4148 bfd_size_type ctfsize
, parentsize
;
4150 ctf_dict_t
*parent
= NULL
;
4153 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
4154 bfd_fatal (bfd_get_filename (abfd
));
4157 && (parentdata
= read_section_stabs (abfd
, parent_name
, &parentsize
,
4159 bfd_fatal (bfd_get_filename (abfd
));
4161 /* Load the CTF file and dump it. */
4163 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
4164 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4166 dump_ctf_errs (NULL
);
4167 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4168 bfd_fatal (bfd_get_filename (abfd
));
4173 ctfsect
= make_ctfsect (parent_name
, parentdata
, parentsize
);
4174 if ((parenta
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4176 dump_ctf_errs (NULL
);
4177 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4178 bfd_fatal (bfd_get_filename (abfd
));
4181 lookparent
= parenta
;
4186 /* Assume that the applicable parent archive member is the default one.
4187 (This is what all known implementations are expected to do, if they
4188 put CTFs and their parents in archives together.) */
4189 if ((parent
= ctf_dict_open (lookparent
, NULL
, &err
)) == NULL
)
4191 dump_ctf_errs (NULL
);
4192 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4193 bfd_fatal (bfd_get_filename (abfd
));
4196 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4198 if ((err
= ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
)) != 0)
4200 dump_ctf_errs (NULL
);
4201 non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err
));
4202 bfd_fatal (bfd_get_filename (abfd
));
4204 ctf_dict_close (parent
);
4206 ctf_close (parenta
);
4212 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4213 const char *parent_name ATTRIBUTE_UNUSED
) {}
4218 dump_bfd_private_header (bfd
*abfd
)
4220 if (!bfd_print_private_bfd_data (abfd
, stdout
))
4221 non_fatal (_("warning: private headers incomplete: %s"),
4222 bfd_errmsg (bfd_get_error ()));
4226 dump_target_specific (bfd
*abfd
)
4228 const struct objdump_private_desc
* const *desc
;
4229 struct objdump_private_option
*opt
;
4232 /* Find the desc. */
4233 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
4234 if ((*desc
)->filter (abfd
))
4239 non_fatal (_("option -P/--private not supported by this file"));
4243 /* Clear all options. */
4244 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4245 opt
->selected
= FALSE
;
4247 /* Decode options. */
4248 b
= dump_private_options
;
4251 e
= strchr (b
, ',');
4256 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4257 if (strcmp (opt
->name
, b
) == 0)
4259 opt
->selected
= TRUE
;
4262 if (opt
->name
== NULL
)
4263 non_fatal (_("target specific dump '%s' not supported"), b
);
4274 (*desc
)->dump (abfd
);
4277 /* Display a section in hexadecimal format with associated characters.
4278 Each line prefixed by the zero padded address. */
4281 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
4283 bfd_byte
*data
= NULL
;
4284 bfd_size_type datasize
;
4285 bfd_vma addr_offset
;
4286 bfd_vma start_offset
;
4287 bfd_vma stop_offset
;
4288 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
4289 /* Bytes per line. */
4290 const int onaline
= 16;
4295 if (! process_section_p (section
))
4298 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
4301 if ((datasize
= bfd_section_size (section
)) == 0)
4304 /* Compute the address range to display. */
4305 if (start_address
== (bfd_vma
) -1
4306 || start_address
< section
->vma
)
4309 start_offset
= start_address
- section
->vma
;
4311 if (stop_address
== (bfd_vma
) -1)
4312 stop_offset
= datasize
/ opb
;
4315 if (stop_address
< section
->vma
)
4318 stop_offset
= stop_address
- section
->vma
;
4320 if (stop_offset
> datasize
/ opb
)
4321 stop_offset
= datasize
/ opb
;
4324 if (start_offset
>= stop_offset
)
4327 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
4328 if (display_file_offsets
)
4329 printf (_(" (Starting at file offset: 0x%lx)"),
4330 (unsigned long) (section
->filepos
+ start_offset
));
4333 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
4335 non_fatal (_("Reading section %s failed because: %s"),
4336 section
->name
, bfd_errmsg (bfd_get_error ()));
4342 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
4343 if (strlen (buf
) >= sizeof (buf
))
4347 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4349 count
= strlen (buf
) - count
;
4353 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
4354 if (strlen (buf
) >= sizeof (buf
))
4358 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4360 count
= strlen (buf
) - count
;
4364 for (addr_offset
= start_offset
;
4365 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
4369 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
4370 count
= strlen (buf
);
4371 if ((size_t) count
>= sizeof (buf
))
4375 while (count
< width
)
4380 fputs (buf
+ count
- width
, stdout
);
4383 for (j
= addr_offset
* opb
;
4384 j
< addr_offset
* opb
+ onaline
; j
++)
4386 if (j
< stop_offset
* opb
)
4387 printf ("%02x", (unsigned) (data
[j
]));
4395 for (j
= addr_offset
* opb
;
4396 j
< addr_offset
* opb
+ onaline
; j
++)
4398 if (j
>= stop_offset
* opb
)
4401 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
4408 /* Actually display the various requested regions. */
4411 dump_data (bfd
*abfd
)
4413 bfd_map_over_sections (abfd
, dump_section
, NULL
);
4416 /* Should perhaps share code and display with nm? */
4419 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
4428 max_count
= dynsymcount
;
4429 printf ("DYNAMIC SYMBOL TABLE:\n");
4434 max_count
= symcount
;
4435 printf ("SYMBOL TABLE:\n");
4439 printf (_("no symbols\n"));
4441 for (count
= 0; count
< max_count
; count
++)
4445 if (*current
== NULL
)
4446 printf (_("no information for symbol number %ld\n"), count
);
4448 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
4449 printf (_("could not determine the type of symbol number %ld\n"),
4452 else if (process_section_p ((* current
)->section
)
4453 && (dump_special_syms
4454 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
4456 const char *name
= (*current
)->name
;
4458 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
4462 /* If we want to demangle the name, we demangle it
4463 here, and temporarily clobber it while calling
4464 bfd_print_symbol. FIXME: This is a gross hack. */
4465 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
4467 (*current
)->name
= alloc
;
4468 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4469 bfd_print_symbol_all
);
4472 (*current
)->name
= name
;
4477 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4478 bfd_print_symbol_all
);
4488 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
4491 char *last_filename
, *last_functionname
;
4492 unsigned int last_line
;
4493 unsigned int last_discriminator
;
4495 /* Get column headers lined up reasonably. */
4503 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
4504 width
= strlen (buf
) - 7;
4506 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
4509 last_filename
= NULL
;
4510 last_functionname
= NULL
;
4512 last_discriminator
= 0;
4514 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
4517 const char *filename
, *functionname
;
4518 unsigned int linenumber
;
4519 unsigned int discriminator
;
4520 const char *sym_name
;
4521 const char *section_name
;
4522 bfd_vma addend2
= 0;
4524 if (start_address
!= (bfd_vma
) -1
4525 && q
->address
< start_address
)
4527 if (stop_address
!= (bfd_vma
) -1
4528 && q
->address
> stop_address
)
4531 if (with_line_numbers
4533 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
4534 &filename
, &functionname
,
4535 &linenumber
, &discriminator
))
4537 if (functionname
!= NULL
4538 && (last_functionname
== NULL
4539 || strcmp (functionname
, last_functionname
) != 0))
4541 printf ("%s():\n", sanitize_string (functionname
));
4542 if (last_functionname
!= NULL
)
4543 free (last_functionname
);
4544 last_functionname
= xstrdup (functionname
);
4548 && (linenumber
!= last_line
4549 || (filename
!= NULL
4550 && last_filename
!= NULL
4551 && filename_cmp (filename
, last_filename
) != 0)
4552 || (discriminator
!= last_discriminator
)))
4554 if (discriminator
> 0)
4555 printf ("%s:%u\n", filename
== NULL
? "???" :
4556 sanitize_string (filename
), linenumber
);
4558 printf ("%s:%u (discriminator %u)\n",
4559 filename
== NULL
? "???" : sanitize_string (filename
),
4560 linenumber
, discriminator
);
4561 last_line
= linenumber
;
4562 last_discriminator
= discriminator
;
4563 if (last_filename
!= NULL
)
4564 free (last_filename
);
4565 if (filename
== NULL
)
4566 last_filename
= NULL
;
4568 last_filename
= xstrdup (filename
);
4572 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
4574 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
4575 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
4580 section_name
= NULL
;
4583 bfd_printf_vma (abfd
, q
->address
);
4584 if (q
->howto
== NULL
)
4585 printf (" *unknown* ");
4586 else if (q
->howto
->name
)
4588 const char *name
= q
->howto
->name
;
4590 /* R_SPARC_OLO10 relocations contain two addends.
4591 But because 'arelent' lacks enough storage to
4592 store them both, the 64-bit ELF Sparc backend
4593 records this as two relocations. One R_SPARC_LO10
4594 and one R_SPARC_13, both pointing to the same
4595 address. This is merely so that we have some
4596 place to store both addend fields.
4598 Undo this transformation, otherwise the output
4599 will be confusing. */
4600 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
4601 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
4603 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
4605 arelent
*q2
= *(p
+ 1);
4608 && q
->address
== q2
->address
4609 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
4611 name
= "R_SPARC_OLO10";
4612 addend2
= q2
->addend
;
4616 printf (" %-16s ", name
);
4619 printf (" %-16d ", q
->howto
->type
);
4623 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
4627 if (section_name
== NULL
)
4628 section_name
= "*unknown*";
4629 printf ("[%s]", sanitize_string (section_name
));
4634 bfd_signed_vma addend
= q
->addend
;
4642 bfd_printf_vma (abfd
, addend
);
4647 bfd_printf_vma (abfd
, addend2
);
4653 if (last_filename
!= NULL
)
4654 free (last_filename
);
4655 if (last_functionname
!= NULL
)
4656 free (last_functionname
);
4660 dump_relocs_in_section (bfd
*abfd
,
4662 void *dummy ATTRIBUTE_UNUSED
)
4664 arelent
**relpp
= NULL
;
4668 if ( bfd_is_abs_section (section
)
4669 || bfd_is_und_section (section
)
4670 || bfd_is_com_section (section
)
4671 || (! process_section_p (section
))
4672 || ((section
->flags
& SEC_RELOC
) == 0))
4675 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
4677 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
4680 printf (" (none)\n\n");
4688 relpp
= (arelent
**) xmalloc (relsize
);
4689 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
4695 non_fatal (_("failed to read relocs in: %s"),
4696 sanitize_string (bfd_get_filename (abfd
)));
4697 bfd_fatal (_("error message was"));
4699 else if (relcount
== 0)
4700 printf (" (none)\n\n");
4704 dump_reloc_set (abfd
, section
, relpp
, relcount
);
4711 dump_relocs (bfd
*abfd
)
4713 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
4717 dump_dynamic_relocs (bfd
*abfd
)
4723 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4725 bfd_fatal (bfd_get_filename (abfd
));
4727 printf ("DYNAMIC RELOCATION RECORDS");
4730 printf (" (none)\n\n");
4733 relpp
= (arelent
**) xmalloc (relsize
);
4734 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
4737 bfd_fatal (bfd_get_filename (abfd
));
4738 else if (relcount
== 0)
4739 printf (" (none)\n\n");
4743 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
4750 /* Creates a table of paths, to search for source files. */
4753 add_include_path (const char *path
)
4757 include_path_count
++;
4758 include_paths
= (const char **)
4759 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
4760 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4761 if (path
[1] == ':' && path
[2] == 0)
4762 path
= concat (path
, ".", (const char *) 0);
4764 include_paths
[include_path_count
- 1] = path
;
4768 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
4772 if ((section
->flags
& SEC_DEBUGGING
) == 0)
4774 bfd_boolean
*has_reloc_p
= (bfd_boolean
*) arg
;
4775 section
->vma
+= adjust_section_vma
;
4777 section
->lma
+= adjust_section_vma
;
4781 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
4784 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
4789 mask
= (bfd_vma
) 1 << (arch_size
- 1);
4790 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
4793 /* Dump selected contents of ABFD. */
4796 dump_bfd (bfd
*abfd
, bfd_boolean is_mainfile
)
4798 const struct elf_backend_data
* bed
;
4800 if (bfd_big_endian (abfd
))
4801 byte_get
= byte_get_big_endian
;
4802 else if (bfd_little_endian (abfd
))
4803 byte_get
= byte_get_little_endian
;
4807 /* Load any separate debug information files.
4808 We do this now and without checking do_follow_links because separate
4809 debug info files may contain symbol tables that we will need when
4810 displaying information about the main file. Any memory allocated by
4811 load_separate_debug_files will be released when we call
4812 free_debug_memory below.
4814 The test on is_mainfile is there because the chain of separate debug
4815 info files is a global variable shared by all invocations of dump_bfd. */
4818 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
4820 /* If asked to do so, recursively dump the separate files. */
4821 if (do_follow_links
)
4825 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4826 dump_bfd (i
->handle
, FALSE
);
4830 /* Adjust user-specified start and stop limits for targets that use
4831 signed addresses. */
4832 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4833 && (bed
= get_elf_backend_data (abfd
)) != NULL
4834 && bed
->sign_extend_vma
)
4836 start_address
= sign_extend_address (abfd
, start_address
,
4838 stop_address
= sign_extend_address (abfd
, stop_address
,
4842 /* If we are adjusting section VMA's, change them all now. Changing
4843 the BFD information is a hack. However, we must do it, or
4844 bfd_find_nearest_line will not do the right thing. */
4845 if (adjust_section_vma
!= 0)
4847 bfd_boolean has_reloc
= (abfd
->flags
& HAS_RELOC
);
4848 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
4851 if (! is_mainfile
&& ! process_links
)
4854 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4855 printf (_("\n%s: file format %s\n"),
4856 sanitize_string (bfd_get_filename (abfd
)),
4859 print_arelt_descr (stdout
, abfd
, TRUE
, FALSE
);
4860 if (dump_file_header
)
4861 dump_bfd_header (abfd
);
4862 if (dump_private_headers
)
4863 dump_bfd_private_header (abfd
);
4864 if (dump_private_options
!= NULL
)
4865 dump_target_specific (abfd
);
4866 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4873 || dump_dwarf_section_info
)
4875 syms
= slurp_symtab (abfd
);
4877 /* If following links, load any symbol tables from the linked files as well. */
4878 if (do_follow_links
&& is_mainfile
)
4882 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4884 asymbol
** extra_syms
;
4885 long old_symcount
= symcount
;
4887 extra_syms
= slurp_symtab (i
->handle
);
4891 if (old_symcount
== 0)
4897 syms
= xrealloc (syms
, ((symcount
+ old_symcount
+ 1)
4898 * sizeof (asymbol
*)));
4899 memcpy (syms
+ old_symcount
,
4901 (symcount
+ 1) * sizeof (asymbol
*));
4905 symcount
+= old_symcount
;
4910 if (dump_section_headers
)
4911 dump_headers (abfd
);
4913 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
4914 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
4915 dynsyms
= slurp_dynamic_symtab (abfd
);
4919 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
4920 dynsymcount
, dynsyms
, &synthsyms
);
4926 dump_symbols (abfd
, FALSE
);
4927 if (dump_dynamic_symtab
)
4928 dump_symbols (abfd
, TRUE
);
4929 if (dump_dwarf_section_info
)
4931 if (dump_ctf_section_info
)
4932 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
4933 if (dump_stab_section_info
)
4935 if (dump_reloc_info
&& ! disassemble
)
4937 if (dump_dynamic_reloc_info
&& ! disassemble
)
4938 dump_dynamic_relocs (abfd
);
4939 if (dump_section_contents
)
4942 disassemble_data (abfd
);
4948 dhandle
= read_debugging_info (abfd
, syms
, symcount
, TRUE
);
4949 if (dhandle
!= NULL
)
4951 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
4953 dump_debugging_tags
? TRUE
: FALSE
))
4955 non_fatal (_("%s: printing debugging information failed"),
4956 bfd_get_filename (abfd
));
4962 /* PR 6483: If there was no STABS debug info in the file, try
4964 else if (! dump_dwarf_section_info
)
4966 dwarf_select_sections_all ();
4994 free_debug_memory ();
4998 display_object_bfd (bfd
*abfd
)
5002 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
5004 dump_bfd (abfd
, TRUE
);
5008 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5010 nonfatal (bfd_get_filename (abfd
));
5011 list_matching_formats (matching
);
5016 if (bfd_get_error () != bfd_error_file_not_recognized
)
5018 nonfatal (bfd_get_filename (abfd
));
5022 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5024 dump_bfd (abfd
, TRUE
);
5028 nonfatal (bfd_get_filename (abfd
));
5030 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5032 list_matching_formats (matching
);
5038 display_any_bfd (bfd
*file
, int level
)
5040 /* Decompress sections unless dumping the section contents. */
5041 if (!dump_section_contents
)
5042 file
->flags
|= BFD_DECOMPRESS
;
5044 /* If the file is an archive, process all of its elements. */
5045 if (bfd_check_format (file
, bfd_archive
))
5048 bfd
*last_arfile
= NULL
;
5051 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5052 else if (level
> 100)
5054 /* Prevent corrupted files from spinning us into an
5055 infinite loop. 100 is an arbitrary heuristic. */
5056 fatal (_("Archive nesting is too deep"));
5060 printf (_("In nested archive %s:\n"),
5061 sanitize_string (bfd_get_filename (file
)));
5065 bfd_set_error (bfd_error_no_error
);
5067 arfile
= bfd_openr_next_archived_file (file
, arfile
);
5070 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5071 nonfatal (bfd_get_filename (file
));
5075 display_any_bfd (arfile
, level
+ 1);
5077 if (last_arfile
!= NULL
)
5079 bfd_close (last_arfile
);
5080 /* PR 17512: file: ac585d01. */
5081 if (arfile
== last_arfile
)
5087 last_arfile
= arfile
;
5090 if (last_arfile
!= NULL
)
5091 bfd_close (last_arfile
);
5094 display_object_bfd (file
);
5098 display_file (char *filename
, char *target
, bfd_boolean last_file
)
5102 if (get_file_size (filename
) < 1)
5108 file
= bfd_openr (filename
, target
);
5111 nonfatal (filename
);
5115 display_any_bfd (file
, 0);
5117 /* This is an optimization to improve the speed of objdump, especially when
5118 dumping a file with lots of associated debug informatiom. Calling
5119 bfd_close on such a file can take a non-trivial amount of time as there
5120 are lots of lists to walk and buffers to free. This is only really
5121 necessary however if we are about to load another file and we need the
5122 memory back. Otherwise, if we are about to exit, then we can save (a lot
5123 of) time by only doing a quick close, and allowing the OS to reclaim the
5128 bfd_close_all_done (file
);
5132 main (int argc
, char **argv
)
5135 char *target
= default_target
;
5136 bfd_boolean seenflag
= FALSE
;
5138 #if defined (HAVE_SETLOCALE)
5139 #if defined (HAVE_LC_MESSAGES)
5140 setlocale (LC_MESSAGES
, "");
5142 setlocale (LC_CTYPE
, "");
5145 bindtextdomain (PACKAGE
, LOCALEDIR
);
5146 textdomain (PACKAGE
);
5148 program_name
= *argv
;
5149 xmalloc_set_program_name (program_name
);
5150 bfd_set_error_program_name (program_name
);
5152 START_PROGRESS (program_name
, 0);
5154 expandargv (&argc
, &argv
);
5156 if (bfd_init () != BFD_INIT_MAGIC
)
5157 fatal (_("fatal error: libbfd ABI mismatch"));
5158 set_default_bfd_target ();
5160 while ((c
= getopt_long (argc
, argv
,
5161 "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
5162 long_options
, (int *) 0))
5168 break; /* We've been given a long option. */
5175 if (disassembler_options
)
5176 /* Ignore potential memory leak for now. */
5177 options
= concat (disassembler_options
, ",",
5178 optarg
, (const char *) NULL
);
5181 disassembler_options
= remove_whitespace_and_extra_commas (options
);
5188 display_file_offsets
= TRUE
;
5191 with_line_numbers
= TRUE
;
5200 enum demangling_styles style
;
5202 style
= cplus_demangle_name_to_style (optarg
);
5203 if (style
== unknown_demangling
)
5204 fatal (_("unknown demangling style `%s'"),
5207 cplus_demangle_set_style (style
);
5210 case OPTION_RECURSE_LIMIT
:
5211 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5213 case OPTION_NO_RECURSE_LIMIT
:
5214 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5217 do_wide
= wide_output
= TRUE
;
5219 case OPTION_ADJUST_VMA
:
5220 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
5222 case OPTION_START_ADDRESS
:
5223 start_address
= parse_vma (optarg
, "--start-address");
5224 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5225 fatal (_("error: the start address should be before the end address"));
5227 case OPTION_STOP_ADDRESS
:
5228 stop_address
= parse_vma (optarg
, "--stop-address");
5229 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5230 fatal (_("error: the stop address should be after the start address"));
5234 prefix_length
= strlen (prefix
);
5235 /* Remove an unnecessary trailing '/' */
5236 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
5239 case OPTION_PREFIX_STRIP
:
5240 prefix_strip
= atoi (optarg
);
5241 if (prefix_strip
< 0)
5242 fatal (_("error: prefix strip must be non-negative"));
5244 case OPTION_INSN_WIDTH
:
5245 insn_width
= strtoul (optarg
, NULL
, 0);
5246 if (insn_width
<= 0)
5247 fatal (_("error: instruction width must be positive"));
5249 case OPTION_INLINES
:
5250 unwind_inlines
= TRUE
;
5252 case OPTION_VISUALIZE_JUMPS
:
5253 visualize_jumps
= TRUE
;
5254 color_output
= FALSE
;
5255 extended_color_output
= FALSE
;
5258 if (streq (optarg
, "color"))
5259 color_output
= TRUE
;
5260 else if (streq (optarg
, "extended-color"))
5262 color_output
= TRUE
;
5263 extended_color_output
= TRUE
;
5265 else if (streq (optarg
, "off"))
5266 visualize_jumps
= FALSE
;
5268 nonfatal (_("unrecognized argument to --visualize-option"));
5272 if (strcmp (optarg
, "B") == 0)
5273 endian
= BFD_ENDIAN_BIG
;
5274 else if (strcmp (optarg
, "L") == 0)
5275 endian
= BFD_ENDIAN_LITTLE
;
5278 nonfatal (_("unrecognized -E option"));
5283 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
5284 endian
= BFD_ENDIAN_BIG
;
5285 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
5286 endian
= BFD_ENDIAN_LITTLE
;
5289 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
5296 dump_file_header
= TRUE
;
5300 formats_info
= TRUE
;
5304 add_include_path (optarg
);
5307 dump_private_headers
= TRUE
;
5311 dump_private_options
= optarg
;
5315 dump_private_headers
= TRUE
;
5317 dump_reloc_info
= TRUE
;
5318 dump_file_header
= TRUE
;
5319 dump_ar_hdrs
= TRUE
;
5320 dump_section_headers
= TRUE
;
5328 dump_dynamic_symtab
= TRUE
;
5334 disasm_sym
= optarg
;
5337 disassemble_zeroes
= TRUE
;
5341 disassemble_all
= TRUE
;
5346 with_source_code
= TRUE
;
5349 case OPTION_SOURCE_COMMENT
:
5351 with_source_code
= TRUE
;
5354 source_comment
= xstrdup (sanitize_string (optarg
));
5356 source_comment
= xstrdup ("# ");
5364 dump_debugging_tags
= 1;
5369 process_links
= TRUE
;
5370 do_follow_links
= TRUE
;
5373 dump_dwarf_section_info
= TRUE
;
5376 dwarf_select_sections_by_letters (optarg
);
5378 dwarf_select_sections_all ();
5381 dump_dwarf_section_info
= TRUE
;
5384 dwarf_select_sections_by_names (optarg
);
5386 dwarf_select_sections_all ();
5388 case OPTION_DWARF_DEPTH
:
5391 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5394 case OPTION_DWARF_START
:
5397 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5398 suppress_bfd_header
= 1;
5401 case OPTION_DWARF_CHECK
:
5404 #ifdef ENABLE_LIBCTF
5406 dump_ctf_section_info
= TRUE
;
5407 dump_ctf_section_name
= xstrdup (optarg
);
5410 case OPTION_CTF_PARENT
:
5411 dump_ctf_parent_name
= xstrdup (optarg
);
5415 dump_stab_section_info
= TRUE
;
5419 dump_section_contents
= TRUE
;
5423 dump_reloc_info
= TRUE
;
5427 dump_dynamic_reloc_info
= TRUE
;
5431 dump_ar_hdrs
= TRUE
;
5435 dump_section_headers
= TRUE
;
5440 show_version
= TRUE
;
5446 /* No need to set seenflag or to break - usage() does not return. */
5453 print_version ("objdump");
5459 exit_status
= display_info ();
5463 display_file ("a.out", target
, TRUE
);
5465 for (; optind
< argc
;)
5467 display_file (argv
[optind
], target
, optind
== argc
- 1);
5473 free (dump_ctf_section_name
);
5474 free (dump_ctf_parent_name
);
5475 free ((void *) source_comment
);
5477 END_PROGRESS (program_name
);