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. */
132 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
134 /* A structure to record the sections mentioned in -j switches. */
137 const char * name
; /* The name of the section. */
138 bfd_boolean seen
; /* A flag to indicate that the section has been found in one or more input files. */
139 struct only
* next
; /* Pointer to the next structure in the list. */
141 /* Pointer to an array of 'only' structures.
142 This pointer is NULL if the -j switch has not been used. */
143 static struct only
* only_list
= NULL
;
145 /* Variables for handling include file path table. */
146 static const char **include_paths
;
147 static int include_path_count
;
149 /* Extra info to pass to the section disassembler and address printing
151 struct objdump_disasm_info
154 bfd_boolean require_sec
;
155 arelent
** dynrelbuf
;
157 disassembler_ftype disassemble_fn
;
162 /* Architecture to disassemble for, or default if NULL. */
163 static char *machine
= NULL
;
165 /* Target specific options to the disassembler. */
166 static char *disassembler_options
= NULL
;
168 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
169 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
171 /* The symbol table. */
172 static asymbol
**syms
;
174 /* Number of symbols in `syms'. */
175 static long symcount
= 0;
177 /* The sorted symbol table. */
178 static asymbol
**sorted_syms
;
180 /* Number of symbols in `sorted_syms'. */
181 static long sorted_symcount
= 0;
183 /* The dynamic symbol table. */
184 static asymbol
**dynsyms
;
186 /* The synthetic symbol table. */
187 static asymbol
*synthsyms
;
188 static long synthcount
= 0;
190 /* Number of symbols in `dynsyms'. */
191 static long dynsymcount
= 0;
193 static bfd_byte
*stabs
;
194 static bfd_size_type stab_size
;
196 static bfd_byte
*strtab
;
197 static bfd_size_type stabstr_size
;
199 /* Handlers for -P/--private. */
200 static const struct objdump_private_desc
* const objdump_private_vectors
[] =
202 OBJDUMP_PRIVATE_VECTORS
206 /* The list of detected jumps inside a function. */
207 static struct jump_info
*detected_jumps
= NULL
;
209 static void usage (FILE *, int) ATTRIBUTE_NORETURN
;
211 usage (FILE *stream
, int status
)
213 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
214 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
215 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
216 fprintf (stream
, _("\
217 -a, --archive-headers Display archive header information\n\
218 -f, --file-headers Display the contents of the overall file header\n\
219 -p, --private-headers Display object format specific file header contents\n\
220 -P, --private=OPT,OPT... Display object format specific contents\n\
221 -h, --[section-]headers Display the contents of the section headers\n\
222 -x, --all-headers Display the contents of all headers\n\
223 -d, --disassemble Display assembler contents of executable sections\n\
224 -D, --disassemble-all Display assembler contents of all sections\n\
225 --disassemble=<sym> Display assembler contents from <sym>\n\
226 -S, --source Intermix source code with disassembly\n\
227 --source-comment[=<txt>] Prefix lines of source code with <txt>\n\
228 -s, --full-contents Display the full contents of all sections requested\n\
229 -g, --debugging Display debug information in object file\n\
230 -e, --debugging-tags Display debug information using ctags style\n\
231 -G, --stabs Display (in raw form) any STABS info in the file\n\
232 -W[lLiaprmfFsoORtUuTgAck] or\n\
233 --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
234 =frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,\n\
235 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
236 =addr,=cu_index,=links]\n\
237 Display DWARF info in the file\n\
239 #if DEFAULT_FOR_FOLLOW_LINKS
240 fprintf (stream
, _("\
241 -WK,--dwarf=follow-links Follow links to separate debug info files (default)\n\
242 -WN,--dwarf=no-follow-links Do not follow links to separate debug info files\n\
245 fprintf (stream
, _("\
246 -WK,--dwarf=follow-links Follow links to separate debug info files\n\
247 -WN,--dwarf=no-follow-links Do not follow links to separate debug info files (default)\n\
251 fprintf (stream
, _("\
252 --ctf=SECTION Display CTF info from SECTION\n\
255 fprintf (stream
, _("\
256 -t, --syms Display the contents of the symbol table(s)\n\
257 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
258 -r, --reloc Display the relocation entries in the file\n\
259 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
260 @<file> Read options from <file>\n\
261 -v, --version Display this program's version number\n\
262 -i, --info List object formats and architectures supported\n\
263 -H, --help Display this information\n\
267 const struct objdump_private_desc
* const *desc
;
269 fprintf (stream
, _("\n The following switches are optional:\n"));
270 fprintf (stream
, _("\
271 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
272 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
273 -j, --section=NAME Only display information for section NAME\n\
274 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
275 -EB --endian=big Assume big endian format when disassembling\n\
276 -EL --endian=little Assume little endian format when disassembling\n\
277 --file-start-context Include context from start of file (with -S)\n\
278 -I, --include=DIR Add DIR to search list for source files\n\
279 -l, --line-numbers Include line numbers and filenames in output\n\
280 -F, --file-offsets Include file offsets when displaying information\n\
281 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
282 The STYLE, if specified, can be `auto', `gnu',\n\
283 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
285 --recurse-limit Enable a limit on recursion whilst demangling. [Default]\n\
286 --no-recurse-limit Disable a limit on recursion whilst demangling\n\
287 -w, --wide Format output for more than 80 columns\n\
288 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
289 --start-address=ADDR Only process data whose address is >= ADDR\n\
290 --stop-address=ADDR Only process data whose address is < ADDR\n\
291 --no-addresses Do not print address alongside disassembly\n\
292 --prefix-addresses Print complete address alongside disassembly\n\
293 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
294 --insn-width=WIDTH Display WIDTH bytes on a single line for -d\n\
295 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
296 --special-syms Include special symbols in symbol dumps\n\
297 --inlines Print all inlines for source line (with -l)\n\
298 --prefix=PREFIX Add PREFIX to absolute paths for -S\n\
299 --prefix-strip=LEVEL Strip initial directory names for -S\n"));
300 fprintf (stream
, _("\
301 --dwarf-depth=N Do not display DIEs at depth N or greater\n\
302 --dwarf-start=N Display DIEs starting with N, at the same depth\n\
304 --dwarf-check Make additional dwarf internal consistency checks.\n"));
306 fprintf (stream
, _("\
307 --ctf-parent=SECTION Use SECTION as the CTF parent\n"));
309 fprintf (stream
, _("\
310 --visualize-jumps Visualize jumps by drawing ASCII art lines\n\
311 --visualize-jumps=color Use colors in the ASCII art\n\
312 --visualize-jumps=extended-color Use extended 8-bit color codes\n\
313 --visualize-jumps=off Disable jump visualization\n\n"));
315 list_supported_targets (program_name
, stream
);
316 list_supported_architectures (program_name
, stream
);
318 disassembler_usage (stream
);
320 if (objdump_private_vectors
[0] != NULL
)
323 _("\nOptions supported for -P/--private switch:\n"));
324 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
325 (*desc
)->help (stream
);
328 if (REPORT_BUGS_TO
[0] && status
== 0)
329 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
333 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
337 OPTION_START_ADDRESS
,
347 OPTION_RECURSE_LIMIT
,
348 OPTION_NO_RECURSE_LIMIT
,
350 OPTION_SOURCE_COMMENT
,
355 OPTION_VISUALIZE_JUMPS
358 static struct option long_options
[]=
360 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
361 {"all-headers", no_argument
, NULL
, 'x'},
362 {"private-headers", no_argument
, NULL
, 'p'},
363 {"private", required_argument
, NULL
, 'P'},
364 {"architecture", required_argument
, NULL
, 'm'},
365 {"archive-headers", no_argument
, NULL
, 'a'},
366 {"debugging", no_argument
, NULL
, 'g'},
367 {"debugging-tags", no_argument
, NULL
, 'e'},
368 {"demangle", optional_argument
, NULL
, 'C'},
369 {"disassemble", optional_argument
, NULL
, 'd'},
370 {"disassemble-all", no_argument
, NULL
, 'D'},
371 {"disassembler-options", required_argument
, NULL
, 'M'},
372 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
373 {"dynamic-reloc", no_argument
, NULL
, 'R'},
374 {"dynamic-syms", no_argument
, NULL
, 'T'},
375 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
376 {"file-headers", no_argument
, NULL
, 'f'},
377 {"file-offsets", no_argument
, NULL
, 'F'},
378 {"file-start-context", no_argument
, &file_start_context
, 1},
379 {"full-contents", no_argument
, NULL
, 's'},
380 {"headers", no_argument
, NULL
, 'h'},
381 {"help", no_argument
, NULL
, 'H'},
382 {"info", no_argument
, NULL
, 'i'},
383 {"line-numbers", no_argument
, NULL
, 'l'},
384 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
385 {"no-addresses", no_argument
, &no_addresses
, 1},
386 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
387 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
388 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
389 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
390 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
391 {"reloc", no_argument
, NULL
, 'r'},
392 {"section", required_argument
, NULL
, 'j'},
393 {"section-headers", no_argument
, NULL
, 'h'},
394 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
395 {"source", no_argument
, NULL
, 'S'},
396 {"source-comment", optional_argument
, NULL
, OPTION_SOURCE_COMMENT
},
397 {"special-syms", no_argument
, &dump_special_syms
, 1},
398 {"include", required_argument
, NULL
, 'I'},
399 {"dwarf", optional_argument
, NULL
, OPTION_DWARF
},
401 {"ctf", required_argument
, NULL
, OPTION_CTF
},
402 {"ctf-parent", required_argument
, NULL
, OPTION_CTF_PARENT
},
404 {"stabs", no_argument
, NULL
, 'G'},
405 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
406 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
407 {"syms", no_argument
, NULL
, 't'},
408 {"target", required_argument
, NULL
, 'b'},
409 {"version", no_argument
, NULL
, 'V'},
410 {"wide", no_argument
, NULL
, 'w'},
411 {"prefix", required_argument
, NULL
, OPTION_PREFIX
},
412 {"prefix-strip", required_argument
, NULL
, OPTION_PREFIX_STRIP
},
413 {"insn-width", required_argument
, NULL
, OPTION_INSN_WIDTH
},
414 {"dwarf-depth", required_argument
, 0, OPTION_DWARF_DEPTH
},
415 {"dwarf-start", required_argument
, 0, OPTION_DWARF_START
},
416 {"dwarf-check", no_argument
, 0, OPTION_DWARF_CHECK
},
417 {"inlines", no_argument
, 0, OPTION_INLINES
},
418 {"visualize-jumps", optional_argument
, 0, OPTION_VISUALIZE_JUMPS
},
419 {0, no_argument
, 0, 0}
423 nonfatal (const char *msg
)
429 /* Returns a version of IN with any control characters
430 replaced by escape sequences. Uses a static buffer
434 sanitize_string (const char * in
)
436 static char * buffer
= NULL
;
437 static size_t buffer_len
= 0;
438 const char * original
= in
;
445 /* See if any conversion is necessary. In the majority
446 of cases it will not be needed. */
459 /* Copy the input, translating as needed. */
461 if (buffer_len
< (strlen (in
) * 2))
463 free ((void *) buffer
);
464 buffer_len
= strlen (in
) * 2;
465 buffer
= xmalloc (buffer_len
+ 1);
491 /* Returns TRUE if the specified section should be dumped. */
494 process_section_p (asection
* section
)
498 if (only_list
== NULL
)
501 for (only
= only_list
; only
; only
= only
->next
)
502 if (strcmp (only
->name
, section
->name
) == 0)
511 /* Add an entry to the 'only' list. */
514 add_only (char * name
)
518 /* First check to make sure that we do not
519 already have an entry for this name. */
520 for (only
= only_list
; only
; only
= only
->next
)
521 if (strcmp (only
->name
, name
) == 0)
524 only
= xmalloc (sizeof * only
);
527 only
->next
= only_list
;
531 /* Release the memory used by the 'only' list.
532 PR 11225: Issue a warning message for unseen sections.
533 Only do this if none of the sections were seen. This is mainly to support
534 tools like the GAS testsuite where an object file is dumped with a list of
535 generic section names known to be present in a range of different file
539 free_only_list (void)
541 bfd_boolean at_least_one_seen
= FALSE
;
545 if (only_list
== NULL
)
548 for (only
= only_list
; only
; only
= only
->next
)
551 at_least_one_seen
= TRUE
;
555 for (only
= only_list
; only
; only
= next
)
557 if (! at_least_one_seen
)
559 non_fatal (_("section '%s' mentioned in a -j option, "
560 "but not found in any input file"),
571 dump_section_header (bfd
*abfd
, asection
*section
, void *data
)
574 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
575 int longest_section_name
= *((int *) data
);
577 /* Ignore linker created section. See elfNN_ia64_object_p in
579 if (section
->flags
& SEC_LINKER_CREATED
)
582 /* PR 10413: Skip sections that we are ignoring. */
583 if (! process_section_p (section
))
586 printf ("%3d %-*s %08lx ", section
->index
, longest_section_name
,
587 sanitize_string (bfd_section_name (section
)),
588 (unsigned long) bfd_section_size (section
) / opb
);
589 bfd_printf_vma (abfd
, bfd_section_vma (section
));
591 bfd_printf_vma (abfd
, section
->lma
);
592 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
593 bfd_section_alignment (section
));
599 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
601 PF (SEC_HAS_CONTENTS
, "CONTENTS");
602 PF (SEC_ALLOC
, "ALLOC");
603 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
604 PF (SEC_LOAD
, "LOAD");
605 PF (SEC_RELOC
, "RELOC");
606 PF (SEC_READONLY
, "READONLY");
607 PF (SEC_CODE
, "CODE");
608 PF (SEC_DATA
, "DATA");
610 PF (SEC_DEBUGGING
, "DEBUGGING");
611 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
612 PF (SEC_EXCLUDE
, "EXCLUDE");
613 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
614 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
616 PF (SEC_TIC54X_BLOCK
, "BLOCK");
617 PF (SEC_TIC54X_CLINK
, "CLINK");
619 PF (SEC_SMALL_DATA
, "SMALL_DATA");
620 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
622 PF (SEC_COFF_SHARED
, "SHARED");
623 PF (SEC_COFF_NOREAD
, "NOREAD");
625 else if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
627 PF (SEC_ELF_OCTETS
, "OCTETS");
628 PF (SEC_ELF_PURECODE
, "PURECODE");
630 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
631 PF (SEC_GROUP
, "GROUP");
632 if (bfd_get_arch (abfd
) == bfd_arch_mep
)
634 PF (SEC_MEP_VLIW
, "VLIW");
637 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
640 struct coff_comdat_info
*comdat
;
642 switch (section
->flags
& SEC_LINK_DUPLICATES
)
646 case SEC_LINK_DUPLICATES_DISCARD
:
647 ls
= "LINK_ONCE_DISCARD";
649 case SEC_LINK_DUPLICATES_ONE_ONLY
:
650 ls
= "LINK_ONCE_ONE_ONLY";
652 case SEC_LINK_DUPLICATES_SAME_SIZE
:
653 ls
= "LINK_ONCE_SAME_SIZE";
655 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
656 ls
= "LINK_ONCE_SAME_CONTENTS";
659 printf ("%s%s", comma
, ls
);
661 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
663 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
672 /* Called on each SECTION in ABFD, update the int variable pointed to by
673 DATA which contains the string length of the longest section name. */
676 find_longest_section_name (bfd
*abfd ATTRIBUTE_UNUSED
,
677 asection
*section
, void *data
)
679 int *longest_so_far
= (int *) data
;
683 /* Ignore linker created section. */
684 if (section
->flags
& SEC_LINKER_CREATED
)
687 /* Skip sections that we are ignoring. */
688 if (! process_section_p (section
))
691 name
= bfd_section_name (section
);
692 len
= (int) strlen (name
);
693 if (len
> *longest_so_far
)
694 *longest_so_far
= len
;
698 dump_headers (bfd
*abfd
)
700 /* The default width of 13 is just an arbitrary choice. */
701 int max_section_name_length
= 13;
707 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
708 if (bfd_get_arch_size (abfd
) == 32)
714 printf (_("Sections:\n"));
717 bfd_map_over_sections (abfd
, find_longest_section_name
,
718 &max_section_name_length
);
720 printf (_("Idx %-*s Size %-*s%-*sFile off Algn"),
721 max_section_name_length
, "Name",
722 bfd_vma_width
, "VMA",
723 bfd_vma_width
, "LMA");
726 printf (_(" Flags"));
729 bfd_map_over_sections (abfd
, dump_section_header
,
730 &max_section_name_length
);
734 slurp_symtab (bfd
*abfd
)
739 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
745 storage
= bfd_get_symtab_upper_bound (abfd
);
748 non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd
));
749 bfd_fatal (_("error message was"));
751 /* Add an extra entry (at the end) with a NULL pointer. */
752 storage
+= sizeof (asymbol
*);
754 off_t filesize
= bfd_get_file_size (abfd
);
758 && filesize
< storage
759 /* The MMO file format supports its own special compression
760 technique, so its sections can be larger than the file size. */
761 && bfd_get_flavour (abfd
) != bfd_target_mmo_flavour
)
763 bfd_nonfatal_message (bfd_get_filename (abfd
), abfd
, NULL
,
764 _("error: symbol table size (%#lx) is larger than filesize (%#lx)"),
765 storage
, (long) filesize
);
771 sy
= (asymbol
**) xmalloc (storage
);
772 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
774 bfd_fatal (bfd_get_filename (abfd
));
775 /* assert (symcount < (storage / sizeof (asymbol *))) */
780 /* Read in the dynamic symbols. */
783 slurp_dynamic_symtab (bfd
*abfd
)
788 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
789 /* Add an extra entry (at the end) with a NULL pointer. */
792 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
794 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
800 bfd_fatal (bfd_get_filename (abfd
));
803 storage
+= sizeof (asymbol
*);
804 sy
= (asymbol
**) xmalloc (storage
);
806 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
808 bfd_fatal (bfd_get_filename (abfd
));
809 /* assert (symcount < (storage / sizeof (asymbol *))) */
810 sy
[dynsymcount
] = NULL
;
814 /* Some symbol names are significant and should be kept in the
815 table of sorted symbol names, even if they are marked as
816 debugging/section symbols. */
819 is_significant_symbol_name (const char * name
)
821 return strncmp (name
, ".plt", 4) == 0 || strcmp (name
, ".got") == 0;
824 /* Filter out (in place) symbols that are useless for disassembly.
825 COUNT is the number of elements in SYMBOLS.
826 Return the number of useful symbols. */
829 remove_useless_symbols (asymbol
**symbols
, long count
)
831 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
835 asymbol
*sym
= *in_ptr
++;
837 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
839 if ((sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
840 && ! is_significant_symbol_name (sym
->name
))
842 if (bfd_is_und_section (sym
->section
)
843 || bfd_is_com_section (sym
->section
))
848 return out_ptr
- symbols
;
851 static const asection
*compare_section
;
853 /* Sort symbols into value order. */
856 compare_symbols (const void *ap
, const void *bp
)
858 const asymbol
*a
= * (const asymbol
**) ap
;
859 const asymbol
*b
= * (const asymbol
**) bp
;
864 bfd_boolean as
, af
, bs
, bf
;
868 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
870 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
873 /* Prefer symbols from the section currently being disassembled.
874 Don't sort symbols from other sections by section, since there
875 isn't much reason to prefer one section over another otherwise.
876 See sym_ok comment for why we compare by section name. */
877 as
= strcmp (compare_section
->name
, a
->section
->name
) == 0;
878 bs
= strcmp (compare_section
->name
, b
->section
->name
) == 0;
884 an
= bfd_asymbol_name (a
);
885 bn
= bfd_asymbol_name (b
);
889 /* The symbols gnu_compiled and gcc2_compiled convey no real
890 information, so put them after other symbols with the same value. */
891 af
= (strstr (an
, "gnu_compiled") != NULL
892 || strstr (an
, "gcc2_compiled") != NULL
);
893 bf
= (strstr (bn
, "gnu_compiled") != NULL
894 || strstr (bn
, "gcc2_compiled") != NULL
);
901 /* We use a heuristic for the file name, to try to sort it after
902 more useful symbols. It may not work on non Unix systems, but it
903 doesn't really matter; the only difference is precisely which
904 symbol names get printed. */
906 #define file_symbol(s, sn, snl) \
907 (((s)->flags & BSF_FILE) != 0 \
909 && (sn)[(snl) - 2] == '.' \
910 && ((sn)[(snl) - 1] == 'o' \
911 || (sn)[(snl) - 1] == 'a')))
913 af
= file_symbol (a
, an
, anl
);
914 bf
= file_symbol (b
, bn
, bnl
);
921 /* Sort function and object symbols before global symbols before
922 local symbols before section symbols before debugging symbols. */
927 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
929 if ((aflags
& BSF_DEBUGGING
) != 0)
934 if ((aflags
& BSF_SECTION_SYM
) != (bflags
& BSF_SECTION_SYM
))
936 if ((aflags
& BSF_SECTION_SYM
) != 0)
941 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
943 if ((aflags
& BSF_FUNCTION
) != 0)
948 if ((aflags
& BSF_OBJECT
) != (bflags
& BSF_OBJECT
))
950 if ((aflags
& BSF_OBJECT
) != 0)
955 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
957 if ((aflags
& BSF_LOCAL
) != 0)
962 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
964 if ((aflags
& BSF_GLOBAL
) != 0)
970 if (bfd_get_flavour (bfd_asymbol_bfd (a
)) == bfd_target_elf_flavour
971 && bfd_get_flavour (bfd_asymbol_bfd (b
)) == bfd_target_elf_flavour
)
976 if ((a
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
977 asz
= ((elf_symbol_type
*) a
)->internal_elf_sym
.st_size
;
979 if ((b
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
980 bsz
= ((elf_symbol_type
*) b
)->internal_elf_sym
.st_size
;
982 return asz
> bsz
? -1 : 1;
985 /* Symbols that start with '.' might be section names, so sort them
986 after symbols that don't start with '.'. */
987 if (an
[0] == '.' && bn
[0] != '.')
989 if (an
[0] != '.' && bn
[0] == '.')
992 /* Finally, if we can't distinguish them in any other way, try to
993 get consistent results by sorting the symbols by name. */
994 return strcmp (an
, bn
);
997 /* Sort relocs into address order. */
1000 compare_relocs (const void *ap
, const void *bp
)
1002 const arelent
*a
= * (const arelent
**) ap
;
1003 const arelent
*b
= * (const arelent
**) bp
;
1005 if (a
->address
> b
->address
)
1007 else if (a
->address
< b
->address
)
1010 /* So that associated relocations tied to the same address show up
1011 in the correct order, we don't do any further sorting. */
1020 /* Print an address (VMA) to the output stream in INFO.
1021 If SKIP_ZEROES is TRUE, omit leading zeroes. */
1024 objdump_print_value (bfd_vma vma
, struct disassemble_info
*inf
,
1025 bfd_boolean skip_zeroes
)
1029 struct objdump_disasm_info
*aux
;
1031 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1032 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
1037 for (p
= buf
; *p
== '0'; ++p
)
1042 (*inf
->fprintf_func
) (inf
->stream
, "%s", p
);
1045 /* Print the name of a symbol. */
1048 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*inf
,
1052 const char *name
, *version_string
= NULL
;
1053 bfd_boolean hidden
= FALSE
;
1056 name
= bfd_asymbol_name (sym
);
1057 if (do_demangle
&& name
[0] != '\0')
1059 /* Demangle the name. */
1060 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
1065 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0)
1066 version_string
= bfd_get_symbol_version_string (abfd
, sym
, TRUE
,
1069 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1072 name
= sanitize_string (name
);
1076 (*inf
->fprintf_func
) (inf
->stream
, "%s", name
);
1077 if (version_string
&& *version_string
!= '\0')
1078 (*inf
->fprintf_func
) (inf
->stream
, hidden
? "@%s" : "@@%s",
1083 printf ("%s", name
);
1084 if (version_string
&& *version_string
!= '\0')
1085 printf (hidden
? "@%s" : "@@%s", version_string
);
1092 static inline bfd_boolean
1093 sym_ok (bfd_boolean want_section
,
1094 bfd
* abfd ATTRIBUTE_UNUSED
,
1097 struct disassemble_info
* inf
)
1101 /* NB: An object file can have different sections with the same
1102 section name. Compare compare section pointers if they have
1104 if (sorted_syms
[place
]->section
->owner
== sec
->owner
1105 && sorted_syms
[place
]->section
!= sec
)
1108 /* Note - we cannot just compare section pointers because they could
1109 be different, but the same... Ie the symbol that we are trying to
1110 find could have come from a separate debug info file. Under such
1111 circumstances the symbol will be associated with a section in the
1112 debug info file, whilst the section we want is in a normal file.
1113 So the section pointers will be different, but the section names
1114 will be the same. */
1115 if (strcmp (bfd_section_name (sorted_syms
[place
]->section
),
1116 bfd_section_name (sec
)) != 0)
1120 return inf
->symbol_is_valid (sorted_syms
[place
], inf
);
1123 /* Locate a symbol given a bfd and a section (from INFO->application_data),
1124 and a VMA. If INFO->application_data->require_sec is TRUE, then always
1125 require the symbol to be in the section. Returns NULL if there is no
1126 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
1127 of the symbol in sorted_syms. */
1130 find_symbol_for_address (bfd_vma vma
,
1131 struct disassemble_info
*inf
,
1134 /* @@ Would it speed things up to cache the last two symbols returned,
1135 and maybe their address ranges? For many processors, only one memory
1136 operand can be present at a time, so the 2-entry cache wouldn't be
1137 constantly churned by code doing heavy memory accesses. */
1139 /* Indices in `sorted_syms'. */
1141 long max_count
= sorted_symcount
;
1143 struct objdump_disasm_info
*aux
;
1147 bfd_boolean want_section
;
1150 if (sorted_symcount
< 1)
1153 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1156 opb
= inf
->octets_per_byte
;
1158 /* Perform a binary search looking for the closest symbol to the
1159 required value. We are searching the range (min, max_count]. */
1160 while (min
+ 1 < max_count
)
1164 thisplace
= (max_count
+ min
) / 2;
1165 sym
= sorted_syms
[thisplace
];
1167 if (bfd_asymbol_value (sym
) > vma
)
1168 max_count
= thisplace
;
1169 else if (bfd_asymbol_value (sym
) < vma
)
1178 /* The symbol we want is now in min, the low end of the range we
1179 were searching. If there are several symbols with the same
1180 value, we want the first one. */
1182 while (thisplace
> 0
1183 && (bfd_asymbol_value (sorted_syms
[thisplace
])
1184 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
1187 /* Prefer a symbol in the current section if we have multple symbols
1188 with the same value, as can occur with overlays or zero size
1191 while (min
< max_count
1192 && (bfd_asymbol_value (sorted_syms
[min
])
1193 == bfd_asymbol_value (sorted_syms
[thisplace
])))
1195 if (sym_ok (TRUE
, abfd
, min
, sec
, inf
))
1202 return sorted_syms
[thisplace
];
1207 /* If the file is relocatable, and the symbol could be from this
1208 section, prefer a symbol from this section over symbols from
1209 others, even if the other symbol's value might be closer.
1211 Note that this may be wrong for some symbol references if the
1212 sections have overlapping memory ranges, but in that case there's
1213 no way to tell what's desired without looking at the relocation
1216 Also give the target a chance to reject symbols. */
1217 want_section
= (aux
->require_sec
1218 || ((abfd
->flags
& HAS_RELOC
) != 0
1219 && vma
>= bfd_section_vma (sec
)
1220 && vma
< (bfd_section_vma (sec
)
1221 + bfd_section_size (sec
) / opb
)));
1223 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1226 long newplace
= sorted_symcount
;
1228 for (i
= min
- 1; i
>= 0; i
--)
1230 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1232 if (newplace
== sorted_symcount
)
1235 if (bfd_asymbol_value (sorted_syms
[i
])
1236 != bfd_asymbol_value (sorted_syms
[newplace
]))
1239 /* Remember this symbol and keep searching until we reach
1240 an earlier address. */
1245 if (newplace
!= sorted_symcount
)
1246 thisplace
= newplace
;
1249 /* We didn't find a good symbol with a smaller value.
1250 Look for one with a larger value. */
1251 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
1253 if (sym_ok (want_section
, abfd
, i
, sec
, inf
))
1261 if (! sym_ok (want_section
, abfd
, thisplace
, sec
, inf
))
1262 /* There is no suitable symbol. */
1266 /* If we have not found an exact match for the specified address
1267 and we have dynamic relocations available, then we can produce
1268 a better result by matching a relocation to the address and
1269 using the symbol associated with that relocation. */
1270 rel_count
= aux
->dynrelcount
;
1272 && sorted_syms
[thisplace
]->value
!= vma
1274 && aux
->dynrelbuf
!= NULL
1275 && aux
->dynrelbuf
[0]->address
<= vma
1276 && aux
->dynrelbuf
[rel_count
- 1]->address
>= vma
1277 /* If we have matched a synthetic symbol, then stick with that. */
1278 && (sorted_syms
[thisplace
]->flags
& BSF_SYNTHETIC
) == 0)
1281 arelent
** rel_high
;
1283 rel_low
= aux
->dynrelbuf
;
1284 rel_high
= rel_low
+ rel_count
- 1;
1285 while (rel_low
<= rel_high
)
1287 arelent
**rel_mid
= &rel_low
[(rel_high
- rel_low
) / 2];
1288 arelent
* rel
= *rel_mid
;
1290 if (rel
->address
== vma
)
1292 /* Absolute relocations do not provide a more helpful
1293 symbolic address. Find a non-absolute relocation
1294 with the same address. */
1295 arelent
**rel_vma
= rel_mid
;
1297 rel_mid
>= rel_low
&& rel_mid
[0]->address
== vma
;
1301 for (; rel_vma
<= rel_high
&& rel_vma
[0]->address
== vma
;
1305 if (rel
->sym_ptr_ptr
!= NULL
1306 && ! bfd_is_abs_section ((* rel
->sym_ptr_ptr
)->section
))
1309 * place
= thisplace
;
1310 return * rel
->sym_ptr_ptr
;
1316 if (vma
< rel
->address
)
1318 else if (vma
>= rel_mid
[1]->address
)
1319 rel_low
= rel_mid
+ 1;
1328 return sorted_syms
[thisplace
];
1331 /* Print an address and the offset to the nearest symbol. */
1334 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
1335 bfd_vma vma
, struct disassemble_info
*inf
,
1336 bfd_boolean skip_zeroes
)
1340 objdump_print_value (vma
, inf
, skip_zeroes
);
1341 (*inf
->fprintf_func
) (inf
->stream
, " ");
1348 (*inf
->fprintf_func
) (inf
->stream
, "<%s",
1349 sanitize_string (bfd_section_name (sec
)));
1350 secaddr
= bfd_section_vma (sec
);
1353 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1354 objdump_print_value (secaddr
- vma
, inf
, TRUE
);
1356 else if (vma
> secaddr
)
1358 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1359 objdump_print_value (vma
- secaddr
, inf
, TRUE
);
1361 (*inf
->fprintf_func
) (inf
->stream
, ">");
1365 (*inf
->fprintf_func
) (inf
->stream
, "<");
1367 objdump_print_symname (abfd
, inf
, sym
);
1369 if (bfd_asymbol_value (sym
) == vma
)
1371 /* Undefined symbols in an executables and dynamic objects do not have
1372 a value associated with them, so it does not make sense to display
1373 an offset relative to them. Normally we would not be provided with
1374 this kind of symbol, but the target backend might choose to do so,
1375 and the code in find_symbol_for_address might return an as yet
1376 unresolved symbol associated with a dynamic reloc. */
1377 else if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
))
1378 && bfd_is_und_section (sym
->section
))
1380 else if (bfd_asymbol_value (sym
) > vma
)
1382 (*inf
->fprintf_func
) (inf
->stream
, "-0x");
1383 objdump_print_value (bfd_asymbol_value (sym
) - vma
, inf
, TRUE
);
1385 else if (vma
> bfd_asymbol_value (sym
))
1387 (*inf
->fprintf_func
) (inf
->stream
, "+0x");
1388 objdump_print_value (vma
- bfd_asymbol_value (sym
), inf
, TRUE
);
1391 (*inf
->fprintf_func
) (inf
->stream
, ">");
1394 if (display_file_offsets
)
1395 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1396 (long int)(sec
->filepos
+ (vma
- sec
->vma
)));
1399 /* Print an address (VMA), symbolically if possible.
1400 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
1403 objdump_print_addr (bfd_vma vma
,
1404 struct disassemble_info
*inf
,
1405 bfd_boolean skip_zeroes
)
1407 struct objdump_disasm_info
*aux
;
1408 asymbol
*sym
= NULL
;
1409 bfd_boolean skip_find
= FALSE
;
1411 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
1413 if (sorted_symcount
< 1)
1417 (*inf
->fprintf_func
) (inf
->stream
, "0x");
1418 objdump_print_value (vma
, inf
, skip_zeroes
);
1421 if (display_file_offsets
)
1422 inf
->fprintf_func (inf
->stream
, _(" (File Offset: 0x%lx)"),
1423 (long int) (inf
->section
->filepos
1424 + (vma
- inf
->section
->vma
)));
1428 if (aux
->reloc
!= NULL
1429 && aux
->reloc
->sym_ptr_ptr
!= NULL
1430 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
1432 sym
= * aux
->reloc
->sym_ptr_ptr
;
1434 /* Adjust the vma to the reloc. */
1435 vma
+= bfd_asymbol_value (sym
);
1437 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1442 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1444 objdump_print_addr_with_sym (aux
->abfd
, inf
->section
, sym
, vma
, inf
,
1448 /* Print VMA to INFO. This function is passed to the disassembler
1452 objdump_print_address (bfd_vma vma
, struct disassemble_info
*inf
)
1454 objdump_print_addr (vma
, inf
, ! prefix_addresses
);
1457 /* Determine if the given address has a symbol associated with it. */
1460 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* inf
)
1464 sym
= find_symbol_for_address (vma
, inf
, NULL
);
1466 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
1469 /* Hold the last function name and the last line number we displayed
1470 in a disassembly. */
1472 static char *prev_functionname
;
1473 static unsigned int prev_line
;
1474 static unsigned int prev_discriminator
;
1476 /* We keep a list of all files that we have seen when doing a
1477 disassembly with source, so that we know how much of the file to
1478 display. This can be important for inlined functions. */
1480 struct print_file_list
1482 struct print_file_list
*next
;
1483 const char *filename
;
1484 const char *modname
;
1487 const char **linemap
;
1490 unsigned max_printed
;
1494 static struct print_file_list
*print_files
;
1496 /* The number of preceding context lines to show when we start
1497 displaying a file for the first time. */
1499 #define SHOW_PRECEDING_CONTEXT_LINES (5)
1501 /* Read a complete file into memory. */
1504 slurp_file (const char *fn
, size_t *size
, struct stat
*fst
)
1507 int ps
= getpagesize ();
1511 int fd
= open (fn
, O_RDONLY
| O_BINARY
);
1515 if (fstat (fd
, fst
) < 0)
1520 *size
= fst
->st_size
;
1522 msize
= (*size
+ ps
- 1) & ~(ps
- 1);
1523 map
= mmap (NULL
, msize
, PROT_READ
, MAP_SHARED
, fd
, 0);
1524 if (map
!= (char *) -1L)
1530 map
= (const char *) malloc (*size
);
1531 if (!map
|| (size_t) read (fd
, (char *) map
, *size
) != *size
)
1533 free ((void *) map
);
1540 #define line_map_decrease 5
1542 /* Precompute array of lines for a mapped file. */
1544 static const char **
1545 index_file (const char *map
, size_t size
, unsigned int *maxline
)
1547 const char *p
, *lstart
, *end
;
1548 int chars_per_line
= 45; /* First iteration will use 40. */
1549 unsigned int lineno
;
1550 const char **linemap
= NULL
;
1551 unsigned long line_map_size
= 0;
1557 for (p
= map
; p
< end
; p
++)
1561 if (p
+ 1 < end
&& p
[1] == '\r')
1564 else if (*p
== '\r')
1566 if (p
+ 1 < end
&& p
[1] == '\n')
1572 /* End of line found. */
1574 if (linemap
== NULL
|| line_map_size
< lineno
+ 1)
1576 unsigned long newsize
;
1578 chars_per_line
-= line_map_decrease
;
1579 if (chars_per_line
<= 1)
1581 line_map_size
= size
/ chars_per_line
+ 1;
1582 if (line_map_size
< lineno
+ 1)
1583 line_map_size
= lineno
+ 1;
1584 newsize
= line_map_size
* sizeof (char *);
1585 linemap
= (const char **) xrealloc (linemap
, newsize
);
1588 linemap
[lineno
++] = lstart
;
1596 /* Tries to open MODNAME, and if successful adds a node to print_files
1597 linked list and returns that node. Returns NULL on failure. */
1599 static struct print_file_list
*
1600 try_print_file_open (const char *origname
, const char *modname
, struct stat
*fst
)
1602 struct print_file_list
*p
;
1604 p
= (struct print_file_list
*) xmalloc (sizeof (struct print_file_list
));
1606 p
->map
= slurp_file (modname
, &p
->mapsize
, fst
);
1613 p
->linemap
= index_file (p
->map
, p
->mapsize
, &p
->maxline
);
1616 p
->filename
= origname
;
1617 p
->modname
= modname
;
1618 p
->next
= print_files
;
1624 /* If the source file, as described in the symtab, is not found
1625 try to locate it in one of the paths specified with -I
1626 If found, add location to print_files linked list. */
1628 static struct print_file_list
*
1629 update_source_path (const char *filename
, bfd
*abfd
)
1631 struct print_file_list
*p
;
1636 p
= try_print_file_open (filename
, filename
, &fst
);
1639 if (include_path_count
== 0)
1642 /* Get the name of the file. */
1643 fname
= lbasename (filename
);
1645 /* If file exists under a new path, we need to add it to the list
1646 so that show_line knows about it. */
1647 for (i
= 0; i
< include_path_count
; i
++)
1649 char *modname
= concat (include_paths
[i
], "/", fname
,
1652 p
= try_print_file_open (filename
, modname
, &fst
);
1662 long mtime
= bfd_get_mtime (abfd
);
1664 if (fst
.st_mtime
> mtime
)
1665 warn (_("source file %s is more recent than object file\n"),
1672 /* Print a source file line. */
1675 print_line (struct print_file_list
*p
, unsigned int linenum
)
1681 if (linenum
>= p
->maxline
)
1683 l
= p
->linemap
[linenum
];
1684 if (source_comment
!= NULL
&& strlen (l
) > 0)
1685 printf ("%s", source_comment
);
1686 len
= strcspn (l
, "\n\r");
1687 /* Test fwrite return value to quiet glibc warning. */
1688 if (len
== 0 || fwrite (l
, len
, 1, stdout
) == 1)
1692 /* Print a range of source code lines. */
1695 dump_lines (struct print_file_list
*p
, unsigned int start
, unsigned int end
)
1699 while (start
<= end
)
1701 print_line (p
, start
);
1706 /* Show the line number, or the source line, in a disassembly
1710 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1712 const char *filename
;
1713 const char *functionname
;
1714 unsigned int linenumber
;
1715 unsigned int discriminator
;
1719 if (! with_line_numbers
&& ! with_source_code
)
1722 if (! bfd_find_nearest_line_discriminator (abfd
, section
, syms
, addr_offset
,
1723 &filename
, &functionname
,
1724 &linenumber
, &discriminator
))
1727 if (filename
!= NULL
&& *filename
== '\0')
1729 if (functionname
!= NULL
&& *functionname
== '\0')
1730 functionname
= NULL
;
1733 && IS_ABSOLUTE_PATH (filename
)
1737 const char *fname
= filename
;
1739 path
= xmalloc (prefix_length
+ PATH_MAX
+ 1);
1742 memcpy (path
, prefix
, prefix_length
);
1743 path_up
= path
+ prefix_length
;
1745 /* Build relocated filename, stripping off leading directories
1746 from the initial filename if requested. */
1747 if (prefix_strip
> 0)
1752 /* Skip selected directory levels. */
1753 for (s
= fname
+ 1; *s
!= '\0' && level
< prefix_strip
; s
++)
1754 if (IS_DIR_SEPARATOR (*s
))
1761 /* Update complete filename. */
1762 strncpy (path_up
, fname
, PATH_MAX
);
1763 path_up
[PATH_MAX
] = '\0';
1771 if (with_line_numbers
)
1773 if (functionname
!= NULL
1774 && (prev_functionname
== NULL
1775 || strcmp (functionname
, prev_functionname
) != 0))
1777 char *demangle_alloc
= NULL
;
1778 if (do_demangle
&& functionname
[0] != '\0')
1780 /* Demangle the name. */
1781 demangle_alloc
= bfd_demangle (abfd
, functionname
,
1785 /* Demangling adds trailing parens, so don't print those. */
1786 if (demangle_alloc
!= NULL
)
1787 printf ("%s:\n", sanitize_string (demangle_alloc
));
1789 printf ("%s():\n", sanitize_string (functionname
));
1792 free (demangle_alloc
);
1795 && (linenumber
!= prev_line
1796 || discriminator
!= prev_discriminator
))
1798 if (discriminator
> 0)
1799 printf ("%s:%u (discriminator %u)\n",
1800 filename
== NULL
? "???" : sanitize_string (filename
),
1801 linenumber
, discriminator
);
1803 printf ("%s:%u\n", filename
== NULL
1804 ? "???" : sanitize_string (filename
),
1809 const char *filename2
;
1810 const char *functionname2
;
1813 while (bfd_find_inliner_info (abfd
, &filename2
, &functionname2
,
1816 printf ("inlined by %s:%u",
1817 sanitize_string (filename2
), line2
);
1818 printf (" (%s)\n", sanitize_string (functionname2
));
1823 if (with_source_code
1827 struct print_file_list
**pp
, *p
;
1830 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1831 if (filename_cmp ((*pp
)->filename
, filename
) == 0)
1838 filename
= xstrdup (filename
);
1839 p
= update_source_path (filename
, abfd
);
1842 if (p
!= NULL
&& linenumber
!= p
->last_line
)
1844 if (file_start_context
&& p
->first
)
1848 l
= linenumber
- SHOW_PRECEDING_CONTEXT_LINES
;
1849 if (l
>= linenumber
)
1851 if (p
->max_printed
>= l
)
1853 if (p
->max_printed
< linenumber
)
1854 l
= p
->max_printed
+ 1;
1859 dump_lines (p
, l
, linenumber
);
1860 if (p
->max_printed
< linenumber
)
1861 p
->max_printed
= linenumber
;
1862 p
->last_line
= linenumber
;
1867 if (functionname
!= NULL
1868 && (prev_functionname
== NULL
1869 || strcmp (functionname
, prev_functionname
) != 0))
1871 if (prev_functionname
!= NULL
)
1872 free (prev_functionname
);
1873 prev_functionname
= (char *) xmalloc (strlen (functionname
) + 1);
1874 strcpy (prev_functionname
, functionname
);
1877 if (linenumber
> 0 && linenumber
!= prev_line
)
1878 prev_line
= linenumber
;
1880 if (discriminator
!= prev_discriminator
)
1881 prev_discriminator
= discriminator
;
1887 /* Pseudo FILE object for strings. */
1895 /* sprintf to a "stream". */
1897 static int ATTRIBUTE_PRINTF_2
1898 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1905 size_t space
= f
->alloc
- f
->pos
;
1907 va_start (args
, format
);
1908 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1914 f
->alloc
= (f
->alloc
+ n
) * 2;
1915 f
->buffer
= (char *) xrealloc (f
->buffer
, f
->alloc
);
1922 /* Code for generating (colored) diagrams of control flow start and end
1925 /* Structure used to store the properties of a jump. */
1929 /* The next jump, or NULL if this is the last object. */
1930 struct jump_info
*next
;
1931 /* The previous jump, or NULL if this is the first object. */
1932 struct jump_info
*prev
;
1933 /* The start addresses of the jump. */
1936 /* The list of start addresses. */
1938 /* The number of elements. */
1940 /* The maximum number of elements that fit into the array. */
1943 /* The end address of the jump. */
1945 /* The drawing level of the jump. */
1949 /* Construct a jump object for a jump from start
1950 to end with the corresponding level. */
1952 static struct jump_info
*
1953 jump_info_new (bfd_vma start
, bfd_vma end
, int level
)
1955 struct jump_info
*result
= xmalloc (sizeof (struct jump_info
));
1957 result
->next
= NULL
;
1958 result
->prev
= NULL
;
1959 result
->start
.addresses
= xmalloc (sizeof (bfd_vma
*) * 2);
1960 result
->start
.addresses
[0] = start
;
1961 result
->start
.count
= 1;
1962 result
->start
.max_count
= 2;
1964 result
->level
= level
;
1969 /* Free a jump object and return the next object
1970 or NULL if this was the last one. */
1972 static struct jump_info
*
1973 jump_info_free (struct jump_info
*ji
)
1975 struct jump_info
*result
= NULL
;
1980 if (ji
->start
.addresses
)
1981 free (ji
->start
.addresses
);
1988 /* Get the smallest value of all start and end addresses. */
1991 jump_info_min_address (const struct jump_info
*ji
)
1993 bfd_vma min_address
= ji
->end
;
1996 for (i
= ji
->start
.count
; i
-- > 0;)
1997 if (ji
->start
.addresses
[i
] < min_address
)
1998 min_address
= ji
->start
.addresses
[i
];
2002 /* Get the largest value of all start and end addresses. */
2005 jump_info_max_address (const struct jump_info
*ji
)
2007 bfd_vma max_address
= ji
->end
;
2010 for (i
= ji
->start
.count
; i
-- > 0;)
2011 if (ji
->start
.addresses
[i
] > max_address
)
2012 max_address
= ji
->start
.addresses
[i
];
2016 /* Get the target address of a jump. */
2019 jump_info_end_address (const struct jump_info
*ji
)
2024 /* Test if an address is one of the start addresses of a jump. */
2027 jump_info_is_start_address (const struct jump_info
*ji
, bfd_vma address
)
2029 bfd_boolean result
= FALSE
;
2032 for (i
= ji
->start
.count
; i
-- > 0;)
2033 if (address
== ji
->start
.addresses
[i
])
2042 /* Test if an address is the target address of a jump. */
2045 jump_info_is_end_address (const struct jump_info
*ji
, bfd_vma address
)
2047 return (address
== ji
->end
);
2050 /* Get the difference between the smallest and largest address of a jump. */
2053 jump_info_size (const struct jump_info
*ji
)
2055 return jump_info_max_address (ji
) - jump_info_min_address (ji
);
2058 /* Unlink a jump object from a list. */
2061 jump_info_unlink (struct jump_info
*node
,
2062 struct jump_info
**base
)
2065 node
->next
->prev
= node
->prev
;
2067 node
->prev
->next
= node
->next
;
2074 /* Insert unlinked jump info node into a list. */
2077 jump_info_insert (struct jump_info
*node
,
2078 struct jump_info
*target
,
2079 struct jump_info
**base
)
2081 node
->next
= target
;
2082 node
->prev
= target
->prev
;
2083 target
->prev
= node
;
2085 node
->prev
->next
= node
;
2090 /* Add unlinked node to the front of a list. */
2093 jump_info_add_front (struct jump_info
*node
,
2094 struct jump_info
**base
)
2098 node
->next
->prev
= node
;
2103 /* Move linked node to target position. */
2106 jump_info_move_linked (struct jump_info
*node
,
2107 struct jump_info
*target
,
2108 struct jump_info
**base
)
2111 jump_info_unlink (node
, base
);
2112 /* Insert node at target position. */
2113 jump_info_insert (node
, target
, base
);
2116 /* Test if two jumps intersect. */
2119 jump_info_intersect (const struct jump_info
*a
,
2120 const struct jump_info
*b
)
2122 return ((jump_info_max_address (a
) >= jump_info_min_address (b
))
2123 && (jump_info_min_address (a
) <= jump_info_max_address (b
)));
2126 /* Merge two compatible jump info objects. */
2129 jump_info_merge (struct jump_info
**base
)
2131 struct jump_info
*a
;
2133 for (a
= *base
; a
; a
= a
->next
)
2135 struct jump_info
*b
;
2137 for (b
= a
->next
; b
; b
= b
->next
)
2139 /* Merge both jumps into one. */
2140 if (a
->end
== b
->end
)
2142 /* Reallocate addresses. */
2143 size_t needed_size
= a
->start
.count
+ b
->start
.count
;
2146 if (needed_size
> a
->start
.max_count
)
2148 a
->start
.max_count
+= b
->start
.max_count
;
2149 a
->start
.addresses
=
2150 xrealloc (a
->start
.addresses
,
2151 a
->start
.max_count
* sizeof (bfd_vma
*));
2154 /* Append start addresses. */
2155 for (i
= 0; i
< b
->start
.count
; ++i
)
2156 a
->start
.addresses
[a
->start
.count
++] =
2157 b
->start
.addresses
[i
];
2159 /* Remove and delete jump. */
2160 struct jump_info
*tmp
= b
->prev
;
2161 jump_info_unlink (b
, base
);
2169 /* Sort jumps by their size and starting point using a stable
2170 minsort. This could be improved if sorting performance is
2171 an issue, for example by using mergesort. */
2174 jump_info_sort (struct jump_info
**base
)
2176 struct jump_info
*current_element
= *base
;
2178 while (current_element
)
2180 struct jump_info
*best_match
= current_element
;
2181 struct jump_info
*runner
= current_element
->next
;
2182 bfd_vma best_size
= jump_info_size (best_match
);
2186 bfd_vma runner_size
= jump_info_size (runner
);
2188 if ((runner_size
< best_size
)
2189 || ((runner_size
== best_size
)
2190 && (jump_info_min_address (runner
)
2191 < jump_info_min_address (best_match
))))
2193 best_match
= runner
;
2194 best_size
= runner_size
;
2197 runner
= runner
->next
;
2200 if (best_match
== current_element
)
2201 current_element
= current_element
->next
;
2203 jump_info_move_linked (best_match
, current_element
, base
);
2207 /* Visualize all jumps at a given address. */
2210 jump_info_visualize_address (bfd_vma address
,
2213 uint8_t *color_buffer
)
2215 struct jump_info
*ji
= detected_jumps
;
2216 size_t len
= (max_level
+ 1) * 3;
2218 /* Clear line buffer. */
2219 memset (line_buffer
, ' ', len
);
2220 memset (color_buffer
, 0, len
);
2222 /* Iterate over jumps and add their ASCII art. */
2225 /* Discard jumps that are never needed again. */
2226 if (jump_info_max_address (ji
) < address
)
2228 struct jump_info
*tmp
= ji
;
2231 jump_info_unlink (tmp
, &detected_jumps
);
2232 jump_info_free (tmp
);
2236 /* This jump intersects with the current address. */
2237 if (jump_info_min_address (ji
) <= address
)
2239 /* Hash target address to get an even
2240 distribution between all values. */
2241 bfd_vma hash_address
= jump_info_end_address (ji
);
2242 uint8_t color
= iterative_hash_object (hash_address
, 0);
2243 /* Fetch line offset. */
2244 int offset
= (max_level
- ji
->level
) * 3;
2246 /* Draw start line. */
2247 if (jump_info_is_start_address (ji
, address
))
2249 size_t i
= offset
+ 1;
2251 for (; i
< len
- 1; ++i
)
2252 if (line_buffer
[i
] == ' ')
2254 line_buffer
[i
] = '-';
2255 color_buffer
[i
] = color
;
2258 if (line_buffer
[i
] == ' ')
2260 line_buffer
[i
] = '-';
2261 color_buffer
[i
] = color
;
2263 else if (line_buffer
[i
] == '>')
2265 line_buffer
[i
] = 'X';
2266 color_buffer
[i
] = color
;
2269 if (line_buffer
[offset
] == ' ')
2271 if (address
<= ji
->end
)
2272 line_buffer
[offset
] =
2273 (jump_info_min_address (ji
) == address
) ? '/': '+';
2275 line_buffer
[offset
] =
2276 (jump_info_max_address (ji
) == address
) ? '\\': '+';
2277 color_buffer
[offset
] = color
;
2280 /* Draw jump target. */
2281 else if (jump_info_is_end_address (ji
, address
))
2283 size_t i
= offset
+ 1;
2285 for (; i
< len
- 1; ++i
)
2286 if (line_buffer
[i
] == ' ')
2288 line_buffer
[i
] = '-';
2289 color_buffer
[i
] = color
;
2292 if (line_buffer
[i
] == ' ')
2294 line_buffer
[i
] = '>';
2295 color_buffer
[i
] = color
;
2297 else if (line_buffer
[i
] == '-')
2299 line_buffer
[i
] = 'X';
2300 color_buffer
[i
] = color
;
2303 if (line_buffer
[offset
] == ' ')
2305 if (jump_info_min_address (ji
) < address
)
2306 line_buffer
[offset
] =
2307 (jump_info_max_address (ji
) > address
) ? '>' : '\\';
2309 line_buffer
[offset
] = '/';
2310 color_buffer
[offset
] = color
;
2313 /* Draw intermediate line segment. */
2314 else if (line_buffer
[offset
] == ' ')
2316 line_buffer
[offset
] = '|';
2317 color_buffer
[offset
] = color
;
2325 /* Clone of disassemble_bytes to detect jumps inside a function. */
2326 /* FIXME: is this correct? Can we strip it down even further? */
2328 static struct jump_info
*
2329 disassemble_jumps (struct disassemble_info
* inf
,
2330 disassembler_ftype disassemble_fn
,
2331 bfd_vma start_offset
,
2332 bfd_vma stop_offset
,
2335 arelent
** relppend
)
2337 struct objdump_disasm_info
*aux
;
2338 struct jump_info
*jumps
= NULL
;
2340 bfd_vma addr_offset
;
2341 unsigned int opb
= inf
->octets_per_byte
;
2345 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2346 section
= inf
->section
;
2349 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2352 inf
->insn_info_valid
= 0;
2353 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2354 inf
->stream
= &sfile
;
2356 addr_offset
= start_offset
;
2357 while (addr_offset
< stop_offset
)
2359 int previous_octets
;
2361 /* Remember the length of the previous instruction. */
2362 previous_octets
= octets
;
2366 inf
->bytes_per_line
= 0;
2367 inf
->bytes_per_chunk
= 0;
2368 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2369 | (wide_output
? WIDE_OUTPUT
: 0));
2371 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2373 if (inf
->disassembler_needs_relocs
2374 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2375 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2376 && *relppp
< relppend
)
2378 bfd_signed_vma distance_to_rel
;
2380 distance_to_rel
= (**relppp
)->address
- (rel_offset
+ addr_offset
);
2382 /* Check to see if the current reloc is associated with
2383 the instruction that we are about to disassemble. */
2384 if (distance_to_rel
== 0
2385 /* FIXME: This is wrong. We are trying to catch
2386 relocs that are addressed part way through the
2387 current instruction, as might happen with a packed
2388 VLIW instruction. Unfortunately we do not know the
2389 length of the current instruction since we have not
2390 disassembled it yet. Instead we take a guess based
2391 upon the length of the previous instruction. The
2392 proper solution is to have a new target-specific
2393 disassembler function which just returns the length
2394 of an instruction at a given address without trying
2395 to display its disassembly. */
2396 || (distance_to_rel
> 0
2397 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
2399 inf
->flags
|= INSN_HAS_RELOC
;
2403 if (! disassemble_all
2404 && (section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2405 == (SEC_CODE
| SEC_HAS_CONTENTS
))
2406 /* Set a stop_vma so that the disassembler will not read
2407 beyond the next symbol. We assume that symbols appear on
2408 the boundaries between instructions. We only do this when
2409 disassembling code of course, and when -D is in effect. */
2410 inf
->stop_vma
= section
->vma
+ stop_offset
;
2412 inf
->stop_offset
= stop_offset
;
2414 /* Extract jump information. */
2415 inf
->insn_info_valid
= 0;
2416 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2417 /* Test if a jump was detected. */
2418 if (inf
->insn_info_valid
2419 && ((inf
->insn_type
== dis_branch
)
2420 || (inf
->insn_type
== dis_condbranch
)
2421 || (inf
->insn_type
== dis_jsr
)
2422 || (inf
->insn_type
== dis_condjsr
))
2423 && (inf
->target
>= section
->vma
+ start_offset
)
2424 && (inf
->target
< section
->vma
+ stop_offset
))
2426 struct jump_info
*ji
=
2427 jump_info_new (section
->vma
+ addr_offset
, inf
->target
, -1);
2428 jump_info_add_front (ji
, &jumps
);
2433 addr_offset
+= octets
/ opb
;
2436 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2437 inf
->stream
= stdout
;
2439 free (sfile
.buffer
);
2442 jump_info_merge (&jumps
);
2443 /* Process jumps. */
2444 jump_info_sort (&jumps
);
2446 /* Group jumps by level. */
2447 struct jump_info
*last_jump
= jumps
;
2452 /* The last jump is part of the next group. */
2453 struct jump_info
*base
= last_jump
;
2454 /* Increment level. */
2455 base
->level
= ++max_level
;
2457 /* Find jumps that can be combined on the same
2458 level, with the largest jumps tested first.
2459 This has the advantage that large jumps are on
2460 lower levels and do not intersect with small
2461 jumps that get grouped on higher levels. */
2462 struct jump_info
*exchange_item
= last_jump
->next
;
2463 struct jump_info
*it
= exchange_item
;
2465 for (; it
; it
= it
->next
)
2467 /* Test if the jump intersects with any
2468 jump from current group. */
2469 bfd_boolean ok
= TRUE
;
2470 struct jump_info
*it_collision
;
2472 for (it_collision
= base
;
2473 it_collision
!= exchange_item
;
2474 it_collision
= it_collision
->next
)
2476 /* This jump intersects so we leave it out. */
2477 if (jump_info_intersect (it_collision
, it
))
2484 /* Add jump to group. */
2487 /* Move current element to the front. */
2488 if (it
!= exchange_item
)
2490 struct jump_info
*save
= it
->prev
;
2491 jump_info_move_linked (it
, exchange_item
, &jumps
);
2497 last_jump
= exchange_item
;
2498 exchange_item
= exchange_item
->next
;
2500 last_jump
->level
= max_level
;
2504 /* Move to next group. */
2505 last_jump
= exchange_item
;
2511 /* The number of zeroes we want to see before we start skipping them.
2512 The number is arbitrarily chosen. */
2514 #define DEFAULT_SKIP_ZEROES 8
2516 /* The number of zeroes to skip at the end of a section. If the
2517 number of zeroes at the end is between SKIP_ZEROES_AT_END and
2518 SKIP_ZEROES, they will be disassembled. If there are fewer than
2519 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
2520 attempt to avoid disassembling zeroes inserted by section
2523 #define DEFAULT_SKIP_ZEROES_AT_END 3
2526 null_print (const void * stream ATTRIBUTE_UNUSED
, const char * format ATTRIBUTE_UNUSED
, ...)
2531 /* Print out jump visualization. */
2534 print_jump_visualisation (bfd_vma addr
, int max_level
, char *line_buffer
,
2535 uint8_t *color_buffer
)
2540 jump_info_visualize_address (addr
, max_level
, line_buffer
, color_buffer
);
2542 size_t line_buffer_size
= strlen (line_buffer
);
2543 char last_color
= 0;
2546 for (i
= 0; i
<= line_buffer_size
; ++i
)
2550 uint8_t color
= (i
< line_buffer_size
) ? color_buffer
[i
]: 0;
2552 if (color
!= last_color
)
2555 if (extended_color_output
)
2556 /* Use extended 8bit color, but
2557 do not choose dark colors. */
2558 printf ("\033[38;5;%dm", 124 + (color
% 108));
2560 /* Use simple terminal colors. */
2561 printf ("\033[%dm", 31 + (color
% 7));
2568 putchar ((i
< line_buffer_size
) ? line_buffer
[i
]: ' ');
2572 /* Disassemble some data in memory between given values. */
2575 disassemble_bytes (struct disassemble_info
* inf
,
2576 disassembler_ftype disassemble_fn
,
2579 bfd_vma start_offset
,
2580 bfd_vma stop_offset
,
2583 arelent
** relppend
)
2585 struct objdump_disasm_info
*aux
;
2587 unsigned int octets_per_line
;
2588 unsigned int skip_addr_chars
;
2589 bfd_vma addr_offset
;
2590 unsigned int opb
= inf
->octets_per_byte
;
2591 unsigned int skip_zeroes
= inf
->skip_zeroes
;
2592 unsigned int skip_zeroes_at_end
= inf
->skip_zeroes_at_end
;
2596 aux
= (struct objdump_disasm_info
*) inf
->application_data
;
2597 section
= inf
->section
;
2600 sfile
.buffer
= (char *) xmalloc (sfile
.alloc
);
2604 octets_per_line
= insn_width
;
2606 octets_per_line
= 4;
2608 octets_per_line
= 16;
2610 /* Figure out how many characters to skip at the start of an
2611 address, to make the disassembly look nicer. We discard leading
2612 zeroes in chunks of 4, ensuring that there is always a leading
2614 skip_addr_chars
= 0;
2615 if (!no_addresses
&& !prefix_addresses
)
2619 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ section
->size
/ opb
);
2621 while (buf
[skip_addr_chars
] == '0')
2624 /* Don't discard zeros on overflow. */
2625 if (buf
[skip_addr_chars
] == '\0' && section
->vma
!= 0)
2626 skip_addr_chars
= 0;
2628 if (skip_addr_chars
!= 0)
2629 skip_addr_chars
= (skip_addr_chars
- 1) & -4;
2632 inf
->insn_info_valid
= 0;
2634 /* Determine maximum level. */
2635 uint8_t *color_buffer
= NULL
;
2636 char *line_buffer
= NULL
;
2639 /* Some jumps were detected. */
2642 struct jump_info
*ji
;
2644 /* Find maximum jump level. */
2645 for (ji
= detected_jumps
; ji
; ji
= ji
->next
)
2647 if (ji
->level
> max_level
)
2648 max_level
= ji
->level
;
2651 /* Allocate buffers. */
2652 size_t len
= (max_level
+ 1) * 3 + 1;
2653 line_buffer
= xmalloc (len
);
2654 line_buffer
[len
- 1] = 0;
2655 color_buffer
= xmalloc (len
);
2656 color_buffer
[len
- 1] = 0;
2659 addr_offset
= start_offset
;
2660 while (addr_offset
< stop_offset
)
2662 bfd_boolean need_nl
= FALSE
;
2666 /* Make sure we don't use relocs from previous instructions. */
2669 /* If we see more than SKIP_ZEROES octets of zeroes, we just
2671 if (! disassemble_zeroes
)
2672 for (; addr_offset
* opb
+ octets
< stop_offset
* opb
; octets
++)
2673 if (data
[addr_offset
* opb
+ octets
] != 0)
2675 if (! disassemble_zeroes
2676 && (inf
->insn_info_valid
== 0
2677 || inf
->branch_delay_insns
== 0)
2678 && (octets
>= skip_zeroes
2679 || (addr_offset
* opb
+ octets
== stop_offset
* opb
2680 && octets
< skip_zeroes_at_end
)))
2682 /* If there are more nonzero octets to follow, we only skip
2683 zeroes in multiples of 4, to try to avoid running over
2684 the start of an instruction which happens to start with
2686 if (addr_offset
* opb
+ octets
!= stop_offset
* opb
)
2689 /* If we are going to display more data, and we are displaying
2690 file offsets, then tell the user how many zeroes we skip
2691 and the file offset from where we resume dumping. */
2692 if (display_file_offsets
2693 && addr_offset
+ octets
/ opb
< stop_offset
)
2694 printf (_("\t... (skipping %lu zeroes, "
2695 "resuming at file offset: 0x%lx)\n"),
2696 (unsigned long) (octets
/ opb
),
2697 (unsigned long) (section
->filepos
2698 + addr_offset
+ octets
/ opb
));
2705 unsigned int bpc
= 0;
2706 unsigned int pb
= 0;
2708 if (with_line_numbers
|| with_source_code
)
2709 show_line (aux
->abfd
, section
, addr_offset
);
2713 else if (!prefix_addresses
)
2717 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
2718 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2722 printf ("%s:\t", buf
+ skip_addr_chars
);
2726 aux
->require_sec
= TRUE
;
2727 objdump_print_address (section
->vma
+ addr_offset
, inf
);
2728 aux
->require_sec
= FALSE
;
2732 print_jump_visualisation (section
->vma
+ addr_offset
,
2733 max_level
, line_buffer
,
2741 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2742 inf
->stream
= &sfile
;
2743 inf
->bytes_per_line
= 0;
2744 inf
->bytes_per_chunk
= 0;
2745 inf
->flags
= ((disassemble_all
? DISASSEMBLE_DATA
: 0)
2746 | (wide_output
? WIDE_OUTPUT
: 0));
2748 inf
->flags
|= USER_SPECIFIED_MACHINE_TYPE
;
2750 if (inf
->disassembler_needs_relocs
2751 && (bfd_get_file_flags (aux
->abfd
) & EXEC_P
) == 0
2752 && (bfd_get_file_flags (aux
->abfd
) & DYNAMIC
) == 0
2753 && *relppp
< relppend
)
2755 bfd_signed_vma distance_to_rel
;
2756 int max_reloc_offset
2757 = aux
->abfd
->arch_info
->max_reloc_offset_into_insn
;
2759 distance_to_rel
= ((**relppp
)->address
- rel_offset
2763 if (distance_to_rel
> 0
2764 && (max_reloc_offset
< 0
2765 || distance_to_rel
<= max_reloc_offset
))
2767 /* This reloc *might* apply to the current insn,
2768 starting somewhere inside it. Discover the length
2769 of the current insn so that the check below will
2772 insn_size
= insn_width
;
2775 /* We find the length by calling the dissassembler
2776 function with a dummy print handler. This should
2777 work unless the disassembler is not expecting to
2778 be called multiple times for the same address.
2780 This does mean disassembling the instruction
2781 twice, but we only do this when there is a high
2782 probability that there is a reloc that will
2783 affect the instruction. */
2784 inf
->fprintf_func
= (fprintf_ftype
) null_print
;
2785 insn_size
= disassemble_fn (section
->vma
2786 + addr_offset
, inf
);
2787 inf
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
2791 /* Check to see if the current reloc is associated with
2792 the instruction that we are about to disassemble. */
2793 if (distance_to_rel
== 0
2794 || (distance_to_rel
> 0
2795 && distance_to_rel
< insn_size
/ (int) opb
))
2797 inf
->flags
|= INSN_HAS_RELOC
;
2798 aux
->reloc
= **relppp
;
2802 if (! disassemble_all
2803 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
2804 == (SEC_CODE
| SEC_HAS_CONTENTS
)))
2805 /* Set a stop_vma so that the disassembler will not read
2806 beyond the next symbol. We assume that symbols appear on
2807 the boundaries between instructions. We only do this when
2808 disassembling code of course, and when -D is in effect. */
2809 inf
->stop_vma
= section
->vma
+ stop_offset
;
2811 inf
->stop_offset
= stop_offset
;
2812 insn_size
= (*disassemble_fn
) (section
->vma
+ addr_offset
, inf
);
2816 inf
->fprintf_func
= (fprintf_ftype
) fprintf
;
2817 inf
->stream
= stdout
;
2818 if (insn_width
== 0 && inf
->bytes_per_line
!= 0)
2819 octets_per_line
= inf
->bytes_per_line
;
2820 if (insn_size
< (int) opb
)
2823 printf ("%s\n", sfile
.buffer
);
2826 non_fatal (_("disassemble_fn returned length %d"),
2837 octets
= octets_per_line
;
2838 if (addr_offset
+ octets
/ opb
> stop_offset
)
2839 octets
= (stop_offset
- addr_offset
) * opb
;
2841 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
2843 if (ISPRINT (data
[j
]))
2844 buf
[j
- addr_offset
* opb
] = data
[j
];
2846 buf
[j
- addr_offset
* opb
] = '.';
2848 buf
[j
- addr_offset
* opb
] = '\0';
2851 if (prefix_addresses
2853 : show_raw_insn
>= 0)
2857 /* If ! prefix_addresses and ! wide_output, we print
2858 octets_per_line octets per line. */
2860 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
2861 pb
= octets_per_line
;
2863 if (inf
->bytes_per_chunk
)
2864 bpc
= inf
->bytes_per_chunk
;
2868 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2870 /* PR 21580: Check for a buffer ending early. */
2871 if (j
+ bpc
<= stop_offset
* opb
)
2875 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2877 for (k
= bpc
; k
-- != 0; )
2878 printf ("%02x", (unsigned) data
[j
+ k
]);
2882 for (k
= 0; k
< bpc
; k
++)
2883 printf ("%02x", (unsigned) data
[j
+ k
]);
2889 for (; pb
< octets_per_line
; pb
+= bpc
)
2893 for (k
= 0; k
< bpc
; k
++)
2898 /* Separate raw data from instruction by extra space. */
2908 printf ("%s", sfile
.buffer
);
2910 if (prefix_addresses
2912 : show_raw_insn
>= 0)
2920 j
= addr_offset
* opb
+ pb
;
2926 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
2927 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
2931 printf ("%s:\t", buf
+ skip_addr_chars
);
2934 print_jump_visualisation (section
->vma
+ j
/ opb
,
2935 max_level
, line_buffer
,
2938 pb
+= octets_per_line
;
2941 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
2943 /* PR 21619: Check for a buffer ending early. */
2944 if (j
+ bpc
<= stop_offset
* opb
)
2948 if (inf
->display_endian
== BFD_ENDIAN_LITTLE
)
2950 for (k
= bpc
; k
-- != 0; )
2951 printf ("%02x", (unsigned) data
[j
+ k
]);
2955 for (k
= 0; k
< bpc
; k
++)
2956 printf ("%02x", (unsigned) data
[j
+ k
]);
2970 while ((*relppp
) < relppend
2971 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
2973 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
2986 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
2991 if (q
->howto
== NULL
)
2992 printf ("*unknown*\t");
2993 else if (q
->howto
->name
)
2994 printf ("%s\t", q
->howto
->name
);
2996 printf ("%d\t", q
->howto
->type
);
2998 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
2999 printf ("*unknown*");
3002 const char *sym_name
;
3004 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
3005 if (sym_name
!= NULL
&& *sym_name
!= '\0')
3006 objdump_print_symname (aux
->abfd
, inf
, *q
->sym_ptr_ptr
);
3011 sym_sec
= bfd_asymbol_section (*q
->sym_ptr_ptr
);
3012 sym_name
= bfd_section_name (sym_sec
);
3013 if (sym_name
== NULL
|| *sym_name
== '\0')
3014 sym_name
= "*unknown*";
3015 printf ("%s", sanitize_string (sym_name
));
3021 bfd_vma addend
= q
->addend
;
3022 if ((bfd_signed_vma
) addend
< 0)
3029 objdump_print_value (addend
, inf
, TRUE
);
3041 addr_offset
+= octets
/ opb
;
3044 free (sfile
.buffer
);
3046 free (color_buffer
);
3050 disassemble_section (bfd
*abfd
, asection
*section
, void *inf
)
3052 const struct elf_backend_data
* bed
;
3053 bfd_vma sign_adjust
= 0;
3054 struct disassemble_info
* pinfo
= (struct disassemble_info
*) inf
;
3055 struct objdump_disasm_info
* paux
;
3056 unsigned int opb
= pinfo
->octets_per_byte
;
3057 bfd_byte
* data
= NULL
;
3058 bfd_size_type datasize
= 0;
3059 arelent
** rel_pp
= NULL
;
3060 arelent
** rel_ppstart
= NULL
;
3061 arelent
** rel_ppend
;
3062 bfd_vma stop_offset
;
3063 asymbol
* sym
= NULL
;
3067 unsigned long addr_offset
;
3068 bfd_boolean do_print
;
3071 stop_offset_reached
,
3076 /* Sections that do not contain machine
3077 code are not normally disassembled. */
3078 if (! disassemble_all
3079 && only_list
== NULL
3080 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
3081 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
3084 if (! process_section_p (section
))
3087 datasize
= bfd_section_size (section
);
3091 if (start_address
== (bfd_vma
) -1
3092 || start_address
< section
->vma
)
3095 addr_offset
= start_address
- section
->vma
;
3097 if (stop_address
== (bfd_vma
) -1)
3098 stop_offset
= datasize
/ opb
;
3101 if (stop_address
< section
->vma
)
3104 stop_offset
= stop_address
- section
->vma
;
3105 if (stop_offset
> datasize
/ opb
)
3106 stop_offset
= datasize
/ opb
;
3109 if (addr_offset
>= stop_offset
)
3112 /* Decide which set of relocs to use. Load them if necessary. */
3113 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
3114 if (paux
->dynrelbuf
&& dump_dynamic_reloc_info
)
3116 rel_pp
= paux
->dynrelbuf
;
3117 rel_count
= paux
->dynrelcount
;
3118 /* Dynamic reloc addresses are absolute, non-dynamic are section
3119 relative. REL_OFFSET specifies the reloc address corresponding
3120 to the start of this section. */
3121 rel_offset
= section
->vma
;
3129 if ((section
->flags
& SEC_RELOC
) != 0
3130 && (dump_reloc_info
|| pinfo
->disassembler_needs_relocs
))
3134 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
3136 bfd_fatal (bfd_get_filename (abfd
));
3140 rel_ppstart
= rel_pp
= (arelent
**) xmalloc (relsize
);
3141 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
3143 bfd_fatal (bfd_get_filename (abfd
));
3145 /* Sort the relocs by address. */
3146 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
3150 rel_ppend
= rel_pp
+ rel_count
;
3152 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
3154 non_fatal (_("Reading section %s failed because: %s"),
3155 section
->name
, bfd_errmsg (bfd_get_error ()));
3159 pinfo
->buffer
= data
;
3160 pinfo
->buffer_vma
= section
->vma
;
3161 pinfo
->buffer_length
= datasize
;
3162 pinfo
->section
= section
;
3164 /* Sort the symbols into value and section order. */
3165 compare_section
= section
;
3166 if (sorted_symcount
> 1)
3167 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
3169 /* Skip over the relocs belonging to addresses below the
3171 while (rel_pp
< rel_ppend
3172 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
3175 printf (_("\nDisassembly of section %s:\n"), sanitize_string (section
->name
));
3177 /* Find the nearest symbol forwards from our current position. */
3178 paux
->require_sec
= TRUE
;
3179 sym
= (asymbol
*) find_symbol_for_address (section
->vma
+ addr_offset
,
3180 (struct disassemble_info
*) inf
,
3182 paux
->require_sec
= FALSE
;
3184 /* PR 9774: If the target used signed addresses then we must make
3185 sure that we sign extend the value that we calculate for 'addr'
3186 in the loop below. */
3187 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3188 && (bed
= get_elf_backend_data (abfd
)) != NULL
3189 && bed
->sign_extend_vma
)
3190 sign_adjust
= (bfd_vma
) 1 << (bed
->s
->arch_size
- 1);
3192 /* Disassemble a block of instructions up to the address associated with
3193 the symbol we have just found. Then print the symbol and find the
3194 next symbol on. Repeat until we have disassembled the entire section
3195 or we have reached the end of the address range we are interested in. */
3196 do_print
= paux
->symbol
== NULL
;
3197 loop_until
= stop_offset_reached
;
3199 while (addr_offset
< stop_offset
)
3203 bfd_vma nextstop_offset
;
3206 addr
= section
->vma
+ addr_offset
;
3207 addr
= ((addr
& ((sign_adjust
<< 1) - 1)) ^ sign_adjust
) - sign_adjust
;
3209 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
3214 (x
< sorted_symcount
3215 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
3219 pinfo
->symbols
= sorted_syms
+ place
;
3220 pinfo
->num_symbols
= x
- place
;
3221 pinfo
->symtab_pos
= place
;
3225 pinfo
->symbols
= NULL
;
3226 pinfo
->num_symbols
= 0;
3227 pinfo
->symtab_pos
= -1;
3230 /* If we are only disassembling from a specific symbol,
3231 check to see if we should start or stop displaying. */
3232 if (sym
&& paux
->symbol
)
3236 /* See if we should stop printing. */
3240 if (sym
->flags
& BSF_FUNCTION
)
3244 case stop_offset_reached
:
3245 /* Handled by the while loop. */
3249 /* FIXME: There is an implicit assumption here
3250 that the name of sym is different from
3252 if (! bfd_is_local_label (abfd
, sym
))
3259 const char * name
= bfd_asymbol_name (sym
);
3260 char * alloc
= NULL
;
3262 if (do_demangle
&& name
[0] != '\0')
3264 /* Demangle the name. */
3265 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
3270 /* We are not currently printing. Check to see
3271 if the current symbol matches the requested symbol. */
3272 if (streq (name
, paux
->symbol
))
3276 if (sym
->flags
& BSF_FUNCTION
)
3278 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
3279 && ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
> 0)
3281 /* Sym is a function symbol with a size associated
3282 with it. Turn on automatic disassembly for the
3283 next VALUE bytes. */
3284 stop_offset
= addr_offset
3285 + ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
3286 loop_until
= stop_offset_reached
;
3290 /* Otherwise we need to tell the loop heuristic to
3291 loop until the next function symbol is encountered. */
3292 loop_until
= function_sym
;
3297 /* Otherwise loop until the next symbol is encountered. */
3298 loop_until
= next_sym
;
3306 if (! prefix_addresses
&& do_print
)
3308 pinfo
->fprintf_func (pinfo
->stream
, "\n");
3309 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
3311 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
3314 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3316 else if (sym
== NULL
)
3320 #define is_valid_next_sym(SYM) \
3321 (strcmp (bfd_section_name ((SYM)->section), bfd_section_name (section)) == 0 \
3322 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
3323 && pinfo->symbol_is_valid (SYM, pinfo))
3325 /* Search forward for the next appropriate symbol in
3326 SECTION. Note that all the symbols are sorted
3327 together into one big array, and that some sections
3328 may have overlapping addresses. */
3329 while (place
< sorted_symcount
3330 && ! is_valid_next_sym (sorted_syms
[place
]))
3333 if (place
>= sorted_symcount
)
3336 nextsym
= sorted_syms
[place
];
3339 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
3340 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
3341 else if (nextsym
== NULL
)
3342 nextstop_offset
= stop_offset
;
3344 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
3346 if (nextstop_offset
> stop_offset
3347 || nextstop_offset
<= addr_offset
)
3348 nextstop_offset
= stop_offset
;
3350 /* If a symbol is explicitly marked as being an object
3351 rather than a function, just dump the bytes without
3352 disassembling them. */
3355 || sym
->section
!= section
3356 || bfd_asymbol_value (sym
) > addr
3357 || ((sym
->flags
& BSF_OBJECT
) == 0
3358 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
3360 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
3362 || (sym
->flags
& BSF_FUNCTION
) != 0)
3369 /* Resolve symbol name. */
3370 if (visualize_jumps
&& abfd
&& sym
&& sym
->name
)
3372 struct disassemble_info di
;
3375 sf
.alloc
= strlen (sym
->name
) + 40;
3376 sf
.buffer
= (char*) xmalloc (sf
.alloc
);
3378 di
.fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
3381 objdump_print_symname (abfd
, &di
, sym
);
3383 /* Fetch jump information. */
3384 detected_jumps
= disassemble_jumps
3385 (pinfo
, paux
->disassemble_fn
,
3386 addr_offset
, nextstop_offset
,
3387 rel_offset
, &rel_pp
, rel_ppend
);
3389 /* Free symbol name. */
3393 /* Add jumps to output. */
3394 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
3395 addr_offset
, nextstop_offset
,
3396 rel_offset
, &rel_pp
, rel_ppend
);
3399 while (detected_jumps
)
3401 detected_jumps
= jump_info_free (detected_jumps
);
3405 addr_offset
= nextstop_offset
;
3411 if (rel_ppstart
!= NULL
)
3415 /* Disassemble the contents of an object file. */
3418 disassemble_data (bfd
*abfd
)
3420 struct disassemble_info disasm_info
;
3421 struct objdump_disasm_info aux
;
3425 prev_functionname
= NULL
;
3427 prev_discriminator
= 0;
3429 /* We make a copy of syms to sort. We don't want to sort syms
3430 because that will screw up the relocs. */
3431 sorted_symcount
= symcount
? symcount
: dynsymcount
;
3432 sorted_syms
= (asymbol
**) xmalloc ((sorted_symcount
+ synthcount
)
3433 * sizeof (asymbol
*));
3434 if (sorted_symcount
!= 0)
3436 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
3437 sorted_symcount
* sizeof (asymbol
*));
3439 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
3442 for (i
= 0; i
< synthcount
; ++i
)
3444 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
3448 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
3450 disasm_info
.application_data
= (void *) &aux
;
3452 aux
.require_sec
= FALSE
;
3453 aux
.dynrelbuf
= NULL
;
3454 aux
.dynrelcount
= 0;
3456 aux
.symbol
= disasm_sym
;
3458 disasm_info
.print_address_func
= objdump_print_address
;
3459 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
3461 if (machine
!= NULL
)
3463 const bfd_arch_info_type
*inf
= bfd_scan_arch (machine
);
3466 fatal (_("can't use supplied machine %s"), machine
);
3468 abfd
->arch_info
= inf
;
3471 if (endian
!= BFD_ENDIAN_UNKNOWN
)
3473 struct bfd_target
*xvec
;
3475 xvec
= (struct bfd_target
*) xmalloc (sizeof (struct bfd_target
));
3476 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
3477 xvec
->byteorder
= endian
;
3481 /* Use libopcodes to locate a suitable disassembler. */
3482 aux
.disassemble_fn
= disassembler (bfd_get_arch (abfd
),
3483 bfd_big_endian (abfd
),
3484 bfd_get_mach (abfd
), abfd
);
3485 if (!aux
.disassemble_fn
)
3487 non_fatal (_("can't disassemble for architecture %s\n"),
3488 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
3493 disasm_info
.flavour
= bfd_get_flavour (abfd
);
3494 disasm_info
.arch
= bfd_get_arch (abfd
);
3495 disasm_info
.mach
= bfd_get_mach (abfd
);
3496 disasm_info
.disassembler_options
= disassembler_options
;
3497 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
, NULL
);
3498 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
3499 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
3500 disasm_info
.disassembler_needs_relocs
= FALSE
;
3502 if (bfd_big_endian (abfd
))
3503 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
3504 else if (bfd_little_endian (abfd
))
3505 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
3507 /* ??? Aborting here seems too drastic. We could default to big or little
3509 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
3511 disasm_info
.endian_code
= disasm_info
.endian
;
3513 /* Allow the target to customize the info structure. */
3514 disassemble_init_for_target (& disasm_info
);
3516 /* Pre-load the dynamic relocs as we may need them during the disassembly. */
3518 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
3520 if (relsize
< 0 && dump_dynamic_reloc_info
)
3521 bfd_fatal (bfd_get_filename (abfd
));
3525 aux
.dynrelbuf
= (arelent
**) xmalloc (relsize
);
3526 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
3529 if (aux
.dynrelcount
< 0)
3530 bfd_fatal (bfd_get_filename (abfd
));
3532 /* Sort the relocs by address. */
3533 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
3537 disasm_info
.symtab
= sorted_syms
;
3538 disasm_info
.symtab_size
= sorted_symcount
;
3540 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
3542 if (aux
.dynrelbuf
!= NULL
)
3543 free (aux
.dynrelbuf
);
3545 disassemble_free_target (&disasm_info
);
3549 load_specific_debug_section (enum dwarf_section_display_enum debug
,
3550 asection
*sec
, void *file
)
3552 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3553 bfd
*abfd
= (bfd
*) file
;
3558 if (section
->start
!= NULL
)
3560 /* If it is already loaded, do nothing. */
3561 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3563 free (section
->start
);
3566 section
->filename
= bfd_get_filename (abfd
);
3567 section
->reloc_info
= NULL
;
3568 section
->num_relocs
= 0;
3569 section
->address
= bfd_section_vma (sec
);
3570 section
->user_data
= sec
;
3571 section
->size
= bfd_section_size (sec
);
3572 /* PR 24360: On 32-bit hosts sizeof (size_t) < sizeof (bfd_size_type). */
3573 alloced
= amt
= section
->size
+ 1;
3574 if (alloced
!= amt
|| alloced
== 0)
3576 section
->start
= NULL
;
3577 free_debug_section (debug
);
3578 printf (_("\nSection '%s' has an invalid size: %#llx.\n"),
3579 sanitize_string (section
->name
),
3580 (unsigned long long) section
->size
);
3583 section
->start
= contents
= malloc (alloced
);
3584 if (section
->start
== NULL
3585 || !bfd_get_full_section_contents (abfd
, sec
, &contents
))
3587 free_debug_section (debug
);
3588 printf (_("\nCan't get contents for section '%s'.\n"),
3589 sanitize_string (section
->name
));
3592 /* Ensure any string section has a terminating NUL. */
3593 section
->start
[section
->size
] = 0;
3595 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0
3596 && debug_displays
[debug
].relocate
)
3601 bfd_cache_section_contents (sec
, section
->start
);
3603 ret
= bfd_simple_get_relocated_section_contents (abfd
,
3610 free_debug_section (debug
);
3611 printf (_("\nCan't get contents for section '%s'.\n"),
3612 sanitize_string (section
->name
));
3616 reloc_size
= bfd_get_reloc_upper_bound (abfd
, sec
);
3619 unsigned long reloc_count
;
3622 relocs
= (arelent
**) xmalloc (reloc_size
);
3624 reloc_count
= bfd_canonicalize_reloc (abfd
, sec
, relocs
, NULL
);
3625 if (reloc_count
== 0)
3629 section
->reloc_info
= relocs
;
3630 section
->num_relocs
= reloc_count
;
3639 reloc_at (struct dwarf_section
* dsec
, dwarf_vma offset
)
3644 if (dsec
== NULL
|| dsec
->reloc_info
== NULL
)
3647 relocs
= (arelent
**) dsec
->reloc_info
;
3649 for (; (rp
= * relocs
) != NULL
; ++ relocs
)
3650 if (rp
->address
== offset
)
3657 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
3659 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3660 bfd
*abfd
= (bfd
*) file
;
3663 /* If it is already loaded, do nothing. */
3664 if (section
->start
!= NULL
)
3666 if (streq (section
->filename
, bfd_get_filename (abfd
)))
3670 /* Locate the debug section. */
3671 sec
= bfd_get_section_by_name (abfd
, section
->uncompressed_name
);
3673 section
->name
= section
->uncompressed_name
;
3676 sec
= bfd_get_section_by_name (abfd
, section
->compressed_name
);
3678 section
->name
= section
->compressed_name
;
3683 return load_specific_debug_section (debug
, sec
, file
);
3687 free_debug_section (enum dwarf_section_display_enum debug
)
3689 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
3691 if (section
->start
== NULL
)
3694 /* PR 17512: file: 0f67f69d. */
3695 if (section
->user_data
!= NULL
)
3697 asection
* sec
= (asection
*) section
->user_data
;
3699 /* If we are freeing contents that are also pointed to by the BFD
3700 library's section structure then make sure to update those pointers
3701 too. Otherwise, the next time we try to load data for this section
3702 we can end up using a stale pointer. */
3703 if (section
->start
== sec
->contents
)
3705 sec
->contents
= NULL
;
3706 sec
->flags
&= ~ SEC_IN_MEMORY
;
3707 sec
->compress_status
= COMPRESS_SECTION_NONE
;
3711 free ((char *) section
->start
);
3712 section
->start
= NULL
;
3713 section
->address
= 0;
3718 close_debug_file (void * file
)
3720 bfd
* abfd
= (bfd
*) file
;
3726 open_debug_file (const char * pathname
)
3730 data
= bfd_openr (pathname
, NULL
);
3734 if (! bfd_check_format (data
, bfd_object
))
3740 #if HAVE_LIBDEBUGINFOD
3741 /* Return a hex string represention of the build-id. */
3744 get_build_id (void * data
)
3747 char * build_id_str
;
3748 bfd
* abfd
= (bfd
*) data
;
3749 const struct bfd_build_id
* build_id
;
3751 build_id
= abfd
->build_id
;
3752 if (build_id
== NULL
)
3755 build_id_str
= malloc (build_id
->size
* 2 + 1);
3756 if (build_id_str
== NULL
)
3759 for (i
= 0; i
< build_id
->size
; i
++)
3760 sprintf (build_id_str
+ (i
* 2), "%02x", build_id
->data
[i
]);
3761 build_id_str
[build_id
->size
* 2] = '\0';
3763 return (unsigned char *)build_id_str
;
3765 #endif /* HAVE_LIBDEBUGINFOD */
3768 dump_dwarf_section (bfd
*abfd
, asection
*section
,
3769 void *arg ATTRIBUTE_UNUSED
)
3771 const char *name
= bfd_section_name (section
);
3775 if (CONST_STRNEQ (name
, ".gnu.linkonce.wi."))
3776 match
= ".debug_info";
3780 for (i
= 0; i
< max
; i
++)
3781 if ((strcmp (debug_displays
[i
].section
.uncompressed_name
, match
) == 0
3782 || strcmp (debug_displays
[i
].section
.compressed_name
, match
) == 0)
3783 && debug_displays
[i
].enabled
!= NULL
3784 && *debug_displays
[i
].enabled
)
3786 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
3788 if (strcmp (sec
->uncompressed_name
, match
) == 0)
3789 sec
->name
= sec
->uncompressed_name
;
3791 sec
->name
= sec
->compressed_name
;
3792 if (load_specific_debug_section ((enum dwarf_section_display_enum
) i
,
3795 debug_displays
[i
].display (sec
, abfd
);
3797 if (i
!= info
&& i
!= abbrev
)
3798 free_debug_section ((enum dwarf_section_display_enum
) i
);
3804 /* Dump the dwarf debugging information. */
3807 dump_dwarf (bfd
*abfd
)
3809 /* The byte_get pointer should have been set at the start of dump_bfd(). */
3810 if (byte_get
== NULL
)
3812 warn (_("File %s does not contain any dwarf debug information\n"),
3813 bfd_get_filename (abfd
));
3817 switch (bfd_get_arch (abfd
))
3820 /* S12Z has a 24 bit address space. But the only known
3821 producer of dwarf_info encodes addresses into 32 bits. */
3826 eh_addr_size
= bfd_arch_bits_per_address (abfd
) / 8;
3830 init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd
),
3831 bfd_get_mach (abfd
));
3833 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
3836 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
3837 it. Return NULL on failure. */
3840 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
,
3841 bfd_size_type
*entsize_ptr
)
3846 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
3847 if (stabsect
== NULL
)
3849 printf (_("No %s section present\n\n"),
3850 sanitize_string (sect_name
));
3854 if (!bfd_malloc_and_get_section (abfd
, stabsect
, &contents
))
3856 non_fatal (_("reading %s section of %s failed: %s"),
3857 sect_name
, bfd_get_filename (abfd
),
3858 bfd_errmsg (bfd_get_error ()));
3864 *size_ptr
= bfd_section_size (stabsect
);
3866 *entsize_ptr
= stabsect
->entsize
;
3871 /* Stabs entries use a 12 byte format:
3872 4 byte string table index
3874 1 byte stab other field
3875 2 byte stab desc field
3877 FIXME: This will have to change for a 64 bit object format. */
3879 #define STRDXOFF (0)
3881 #define OTHEROFF (5)
3884 #define STABSIZE (12)
3886 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
3887 using string table section STRSECT_NAME (in `strtab'). */
3890 print_section_stabs (bfd
*abfd
,
3891 const char *stabsect_name
,
3892 unsigned *string_offset_ptr
)
3895 unsigned file_string_table_offset
= 0;
3896 unsigned next_file_string_table_offset
= *string_offset_ptr
;
3897 bfd_byte
*stabp
, *stabs_end
;
3900 stabs_end
= stabp
+ stab_size
;
3902 printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name
));
3903 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
3905 /* Loop through all symbols and print them.
3907 We start the index at -1 because there is a dummy symbol on
3908 the front of stabs-in-{coff,elf} sections that supplies sizes. */
3909 for (i
= -1; stabp
<= stabs_end
- STABSIZE
; stabp
+= STABSIZE
, i
++)
3913 unsigned char type
, other
;
3914 unsigned short desc
;
3917 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
3918 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
3919 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
3920 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
3921 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
3923 printf ("\n%-6d ", i
);
3924 /* Either print the stab name, or, if unnamed, print its number
3925 again (makes consistent formatting for tools like awk). */
3926 name
= bfd_get_stab_name (type
);
3928 printf ("%-6s", sanitize_string (name
));
3929 else if (type
== N_UNDF
)
3932 printf ("%-6d", type
);
3933 printf (" %-6d %-6d ", other
, desc
);
3934 bfd_printf_vma (abfd
, value
);
3935 printf (" %-6lu", strx
);
3937 /* Symbols with type == 0 (N_UNDF) specify the length of the
3938 string table associated with this file. We use that info
3939 to know how to relocate the *next* file's string table indices. */
3942 file_string_table_offset
= next_file_string_table_offset
;
3943 next_file_string_table_offset
+= value
;
3947 bfd_size_type amt
= strx
+ file_string_table_offset
;
3949 /* Using the (possibly updated) string table offset, print the
3950 string (if any) associated with this symbol. */
3951 if (amt
< stabstr_size
)
3952 /* PR 17512: file: 079-79389-0.001:0.1.
3953 FIXME: May need to sanitize this string before displaying. */
3954 printf (" %.*s", (int)(stabstr_size
- amt
), strtab
+ amt
);
3960 *string_offset_ptr
= next_file_string_table_offset
;
3965 const char * section_name
;
3966 const char * string_section_name
;
3967 unsigned string_offset
;
3972 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
3975 stab_section_names
* sought
= (stab_section_names
*) names
;
3977 /* Check for section names for which stabsect_name is a prefix, to
3978 handle .stab.N, etc. */
3979 len
= strlen (sought
->section_name
);
3981 /* If the prefix matches, and the files section name ends with a
3982 nul or a digit, then we match. I.e., we want either an exact
3983 match or a section followed by a number. */
3984 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
3985 && (section
->name
[len
] == 0
3986 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
3989 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
3990 &stabstr_size
, NULL
);
3994 stabs
= read_section_stabs (abfd
, section
->name
, &stab_size
, NULL
);
3996 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
4002 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
4004 stab_section_names s
;
4006 s
.section_name
= stabsect_name
;
4007 s
.string_section_name
= strsect_name
;
4008 s
.string_offset
= 0;
4010 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
4016 /* Dump the any sections containing stabs debugging information. */
4019 dump_stabs (bfd
*abfd
)
4021 dump_stabs_section (abfd
, ".stab", ".stabstr");
4022 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
4023 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
4026 dump_stabs_section (abfd
, "LC_SYMTAB.stabs", "LC_SYMTAB.stabstr");
4028 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
4032 dump_bfd_header (bfd
*abfd
)
4036 printf (_("architecture: %s, "),
4037 bfd_printable_arch_mach (bfd_get_arch (abfd
),
4038 bfd_get_mach (abfd
)));
4039 printf (_("flags 0x%08x:\n"), abfd
->flags
& ~BFD_FLAGS_FOR_BFD_USE_MASK
);
4041 #define PF(x, y) if (abfd->flags & x) {printf ("%s%s", comma, y); comma=", ";}
4042 PF (HAS_RELOC
, "HAS_RELOC");
4043 PF (EXEC_P
, "EXEC_P");
4044 PF (HAS_LINENO
, "HAS_LINENO");
4045 PF (HAS_DEBUG
, "HAS_DEBUG");
4046 PF (HAS_SYMS
, "HAS_SYMS");
4047 PF (HAS_LOCALS
, "HAS_LOCALS");
4048 PF (DYNAMIC
, "DYNAMIC");
4049 PF (WP_TEXT
, "WP_TEXT");
4050 PF (D_PAGED
, "D_PAGED");
4051 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
4052 printf (_("\nstart address 0x"));
4053 bfd_printf_vma (abfd
, abfd
->start_address
);
4058 #ifdef ENABLE_LIBCTF
4059 /* Formatting callback function passed to ctf_dump. Returns either the pointer
4060 it is passed, or a pointer to newly-allocated storage, in which case
4061 dump_ctf() will free it when it no longer needs it. */
4064 dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED
,
4067 const char *blanks
= arg
;
4070 if (asprintf (&new_s
, "%s%s", blanks
, s
) < 0)
4075 /* Make a ctfsect suitable for ctf_bfdopen_ctfsect(). */
4077 make_ctfsect (const char *name
, bfd_byte
*data
,
4082 ctfsect
.cts_name
= name
;
4083 ctfsect
.cts_entsize
= 1;
4084 ctfsect
.cts_size
= size
;
4085 ctfsect
.cts_data
= data
;
4090 /* Dump CTF errors/warnings. */
4092 dump_ctf_errs (ctf_dict_t
*fp
)
4094 ctf_next_t
*it
= NULL
;
4099 /* Dump accumulated errors and warnings. */
4100 while ((errtext
= ctf_errwarning_next (fp
, &it
, &is_warning
, &err
)) != NULL
)
4102 non_fatal (_("%s: %s"), is_warning
? _("warning"): _("error"),
4106 if (err
!= ECTF_NEXT_END
)
4108 non_fatal (_("CTF error: cannot get CTF errors: `%s'"),
4113 /* Dump one CTF archive member. */
4116 dump_ctf_archive_member (ctf_dict_t
*ctf
, const char *name
, void *arg
)
4118 ctf_dict_t
*parent
= (ctf_dict_t
*) arg
;
4119 const char *things
[] = {"Header", "Labels", "Data objects",
4120 "Function objects", "Variables", "Types", "Strings",
4125 /* Only print out the name of non-default-named archive members.
4126 The name .ctf appears everywhere, even for things that aren't
4127 really archives, so printing it out is liable to be confusing.
4129 The parent, if there is one, is the default-owned archive member:
4130 avoid importing it into itself. (This does no harm, but looks
4133 if (strcmp (name
, ".ctf") != 0)
4135 printf (_("\nCTF archive member: %s:\n"), sanitize_string (name
));
4136 ctf_import (ctf
, parent
);
4139 for (i
= 0, thing
= things
; *thing
[0]; thing
++, i
++)
4141 ctf_dump_state_t
*s
= NULL
;
4144 printf ("\n %s:\n", *thing
);
4145 while ((item
= ctf_dump (ctf
, &s
, i
, dump_ctf_indent_lines
,
4146 (void *) " ")) != NULL
)
4148 printf ("%s\n", item
);
4152 if (ctf_errno (ctf
))
4154 non_fatal (_("Iteration failed: %s, %s"), *thing
,
4155 ctf_errmsg (ctf_errno (ctf
)));
4160 dump_ctf_errs (ctf
);
4165 /* Dump the CTF debugging information. */
4168 dump_ctf (bfd
*abfd
, const char *sect_name
, const char *parent_name
)
4170 ctf_archive_t
*ctfa
, *parenta
= NULL
, *lookparent
;
4171 bfd_byte
*ctfdata
, *parentdata
= NULL
;
4172 bfd_size_type ctfsize
, parentsize
;
4174 ctf_dict_t
*parent
= NULL
;
4177 if ((ctfdata
= read_section_stabs (abfd
, sect_name
, &ctfsize
, NULL
)) == NULL
)
4178 bfd_fatal (bfd_get_filename (abfd
));
4181 && (parentdata
= read_section_stabs (abfd
, parent_name
, &parentsize
,
4183 bfd_fatal (bfd_get_filename (abfd
));
4185 /* Load the CTF file and dump it. */
4187 ctfsect
= make_ctfsect (sect_name
, ctfdata
, ctfsize
);
4188 if ((ctfa
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4190 dump_ctf_errs (NULL
);
4191 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4192 bfd_fatal (bfd_get_filename (abfd
));
4197 ctfsect
= make_ctfsect (parent_name
, parentdata
, parentsize
);
4198 if ((parenta
= ctf_bfdopen_ctfsect (abfd
, &ctfsect
, &err
)) == NULL
)
4200 dump_ctf_errs (NULL
);
4201 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4202 bfd_fatal (bfd_get_filename (abfd
));
4205 lookparent
= parenta
;
4210 /* Assume that the applicable parent archive member is the default one.
4211 (This is what all known implementations are expected to do, if they
4212 put CTFs and their parents in archives together.) */
4213 if ((parent
= ctf_dict_open (lookparent
, NULL
, &err
)) == NULL
)
4215 dump_ctf_errs (NULL
);
4216 non_fatal (_("CTF open failure: %s"), ctf_errmsg (err
));
4217 bfd_fatal (bfd_get_filename (abfd
));
4220 printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name
));
4222 if ((err
= ctf_archive_iter (ctfa
, dump_ctf_archive_member
, parent
)) != 0)
4224 dump_ctf_errs (NULL
);
4225 non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err
));
4226 bfd_fatal (bfd_get_filename (abfd
));
4228 ctf_dict_close (parent
);
4230 ctf_close (parenta
);
4236 dump_ctf (bfd
*abfd ATTRIBUTE_UNUSED
, const char *sect_name ATTRIBUTE_UNUSED
,
4237 const char *parent_name ATTRIBUTE_UNUSED
) {}
4242 dump_bfd_private_header (bfd
*abfd
)
4244 if (!bfd_print_private_bfd_data (abfd
, stdout
))
4245 non_fatal (_("warning: private headers incomplete: %s"),
4246 bfd_errmsg (bfd_get_error ()));
4250 dump_target_specific (bfd
*abfd
)
4252 const struct objdump_private_desc
* const *desc
;
4253 struct objdump_private_option
*opt
;
4256 /* Find the desc. */
4257 for (desc
= objdump_private_vectors
; *desc
!= NULL
; desc
++)
4258 if ((*desc
)->filter (abfd
))
4263 non_fatal (_("option -P/--private not supported by this file"));
4267 /* Clear all options. */
4268 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4269 opt
->selected
= FALSE
;
4271 /* Decode options. */
4272 b
= dump_private_options
;
4275 e
= strchr (b
, ',');
4280 for (opt
= (*desc
)->options
; opt
->name
; opt
++)
4281 if (strcmp (opt
->name
, b
) == 0)
4283 opt
->selected
= TRUE
;
4286 if (opt
->name
== NULL
)
4287 non_fatal (_("target specific dump '%s' not supported"), b
);
4298 (*desc
)->dump (abfd
);
4301 /* Display a section in hexadecimal format with associated characters.
4302 Each line prefixed by the zero padded address. */
4305 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
4307 bfd_byte
*data
= NULL
;
4308 bfd_size_type datasize
;
4309 bfd_vma addr_offset
;
4310 bfd_vma start_offset
;
4311 bfd_vma stop_offset
;
4312 unsigned int opb
= bfd_octets_per_byte (abfd
, section
);
4313 /* Bytes per line. */
4314 const int onaline
= 16;
4319 if (! process_section_p (section
))
4322 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
4325 if ((datasize
= bfd_section_size (section
)) == 0)
4328 /* Compute the address range to display. */
4329 if (start_address
== (bfd_vma
) -1
4330 || start_address
< section
->vma
)
4333 start_offset
= start_address
- section
->vma
;
4335 if (stop_address
== (bfd_vma
) -1)
4336 stop_offset
= datasize
/ opb
;
4339 if (stop_address
< section
->vma
)
4342 stop_offset
= stop_address
- section
->vma
;
4344 if (stop_offset
> datasize
/ opb
)
4345 stop_offset
= datasize
/ opb
;
4348 if (start_offset
>= stop_offset
)
4351 printf (_("Contents of section %s:"), sanitize_string (section
->name
));
4352 if (display_file_offsets
)
4353 printf (_(" (Starting at file offset: 0x%lx)"),
4354 (unsigned long) (section
->filepos
+ start_offset
));
4357 if (!bfd_get_full_section_contents (abfd
, section
, &data
))
4359 non_fatal (_("Reading section %s failed because: %s"),
4360 section
->name
, bfd_errmsg (bfd_get_error ()));
4366 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
4367 if (strlen (buf
) >= sizeof (buf
))
4371 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4373 count
= strlen (buf
) - count
;
4377 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
4378 if (strlen (buf
) >= sizeof (buf
))
4382 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
4384 count
= strlen (buf
) - count
;
4388 for (addr_offset
= start_offset
;
4389 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
4393 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
4394 count
= strlen (buf
);
4395 if ((size_t) count
>= sizeof (buf
))
4399 while (count
< width
)
4404 fputs (buf
+ count
- width
, stdout
);
4407 for (j
= addr_offset
* opb
;
4408 j
< addr_offset
* opb
+ onaline
; j
++)
4410 if (j
< stop_offset
* opb
)
4411 printf ("%02x", (unsigned) (data
[j
]));
4419 for (j
= addr_offset
* opb
;
4420 j
< addr_offset
* opb
+ onaline
; j
++)
4422 if (j
>= stop_offset
* opb
)
4425 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
4432 /* Actually display the various requested regions. */
4435 dump_data (bfd
*abfd
)
4437 bfd_map_over_sections (abfd
, dump_section
, NULL
);
4440 /* Should perhaps share code and display with nm? */
4443 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
4452 max_count
= dynsymcount
;
4453 printf ("DYNAMIC SYMBOL TABLE:\n");
4458 max_count
= symcount
;
4459 printf ("SYMBOL TABLE:\n");
4463 printf (_("no symbols\n"));
4465 for (count
= 0; count
< max_count
; count
++)
4469 if (*current
== NULL
)
4470 printf (_("no information for symbol number %ld\n"), count
);
4472 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
4473 printf (_("could not determine the type of symbol number %ld\n"),
4476 else if (process_section_p ((* current
)->section
)
4477 && (dump_special_syms
4478 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
4480 const char *name
= (*current
)->name
;
4482 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
4486 /* If we want to demangle the name, we demangle it
4487 here, and temporarily clobber it while calling
4488 bfd_print_symbol. FIXME: This is a gross hack. */
4489 alloc
= bfd_demangle (cur_bfd
, name
, demangle_flags
);
4491 (*current
)->name
= alloc
;
4492 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4493 bfd_print_symbol_all
);
4496 (*current
)->name
= name
;
4501 bfd_print_symbol (cur_bfd
, stdout
, *current
,
4502 bfd_print_symbol_all
);
4512 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
4515 char *last_filename
, *last_functionname
;
4516 unsigned int last_line
;
4517 unsigned int last_discriminator
;
4519 /* Get column headers lined up reasonably. */
4527 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
4528 width
= strlen (buf
) - 7;
4530 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
4533 last_filename
= NULL
;
4534 last_functionname
= NULL
;
4536 last_discriminator
= 0;
4538 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
4541 const char *filename
, *functionname
;
4542 unsigned int linenumber
;
4543 unsigned int discriminator
;
4544 const char *sym_name
;
4545 const char *section_name
;
4546 bfd_vma addend2
= 0;
4548 if (start_address
!= (bfd_vma
) -1
4549 && q
->address
< start_address
)
4551 if (stop_address
!= (bfd_vma
) -1
4552 && q
->address
> stop_address
)
4555 if (with_line_numbers
4557 && bfd_find_nearest_line_discriminator (abfd
, sec
, syms
, q
->address
,
4558 &filename
, &functionname
,
4559 &linenumber
, &discriminator
))
4561 if (functionname
!= NULL
4562 && (last_functionname
== NULL
4563 || strcmp (functionname
, last_functionname
) != 0))
4565 printf ("%s():\n", sanitize_string (functionname
));
4566 if (last_functionname
!= NULL
)
4567 free (last_functionname
);
4568 last_functionname
= xstrdup (functionname
);
4572 && (linenumber
!= last_line
4573 || (filename
!= NULL
4574 && last_filename
!= NULL
4575 && filename_cmp (filename
, last_filename
) != 0)
4576 || (discriminator
!= last_discriminator
)))
4578 if (discriminator
> 0)
4579 printf ("%s:%u\n", filename
== NULL
? "???" :
4580 sanitize_string (filename
), linenumber
);
4582 printf ("%s:%u (discriminator %u)\n",
4583 filename
== NULL
? "???" : sanitize_string (filename
),
4584 linenumber
, discriminator
);
4585 last_line
= linenumber
;
4586 last_discriminator
= discriminator
;
4587 if (last_filename
!= NULL
)
4588 free (last_filename
);
4589 if (filename
== NULL
)
4590 last_filename
= NULL
;
4592 last_filename
= xstrdup (filename
);
4596 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
4598 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
4599 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
4604 section_name
= NULL
;
4607 bfd_printf_vma (abfd
, q
->address
);
4608 if (q
->howto
== NULL
)
4609 printf (" *unknown* ");
4610 else if (q
->howto
->name
)
4612 const char *name
= q
->howto
->name
;
4614 /* R_SPARC_OLO10 relocations contain two addends.
4615 But because 'arelent' lacks enough storage to
4616 store them both, the 64-bit ELF Sparc backend
4617 records this as two relocations. One R_SPARC_LO10
4618 and one R_SPARC_13, both pointing to the same
4619 address. This is merely so that we have some
4620 place to store both addend fields.
4622 Undo this transformation, otherwise the output
4623 will be confusing. */
4624 if (abfd
->xvec
->flavour
== bfd_target_elf_flavour
4625 && elf_tdata (abfd
)->elf_header
->e_machine
== EM_SPARCV9
4627 && !strcmp (q
->howto
->name
, "R_SPARC_LO10"))
4629 arelent
*q2
= *(p
+ 1);
4632 && q
->address
== q2
->address
4633 && !strcmp (q2
->howto
->name
, "R_SPARC_13"))
4635 name
= "R_SPARC_OLO10";
4636 addend2
= q2
->addend
;
4640 printf (" %-16s ", name
);
4643 printf (" %-16d ", q
->howto
->type
);
4647 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
4651 if (section_name
== NULL
)
4652 section_name
= "*unknown*";
4653 printf ("[%s]", sanitize_string (section_name
));
4658 bfd_signed_vma addend
= q
->addend
;
4666 bfd_printf_vma (abfd
, addend
);
4671 bfd_printf_vma (abfd
, addend2
);
4677 if (last_filename
!= NULL
)
4678 free (last_filename
);
4679 if (last_functionname
!= NULL
)
4680 free (last_functionname
);
4684 dump_relocs_in_section (bfd
*abfd
,
4686 void *dummy ATTRIBUTE_UNUSED
)
4688 arelent
**relpp
= NULL
;
4692 if ( bfd_is_abs_section (section
)
4693 || bfd_is_und_section (section
)
4694 || bfd_is_com_section (section
)
4695 || (! process_section_p (section
))
4696 || ((section
->flags
& SEC_RELOC
) == 0))
4699 printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section
->name
));
4701 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
4704 printf (" (none)\n\n");
4712 relpp
= (arelent
**) xmalloc (relsize
);
4713 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
4719 non_fatal (_("failed to read relocs in: %s"),
4720 sanitize_string (bfd_get_filename (abfd
)));
4721 bfd_fatal (_("error message was"));
4723 else if (relcount
== 0)
4724 printf (" (none)\n\n");
4728 dump_reloc_set (abfd
, section
, relpp
, relcount
);
4735 dump_relocs (bfd
*abfd
)
4737 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
4741 dump_dynamic_relocs (bfd
*abfd
)
4747 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
4749 bfd_fatal (bfd_get_filename (abfd
));
4751 printf ("DYNAMIC RELOCATION RECORDS");
4754 printf (" (none)\n\n");
4757 relpp
= (arelent
**) xmalloc (relsize
);
4758 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
4761 bfd_fatal (bfd_get_filename (abfd
));
4762 else if (relcount
== 0)
4763 printf (" (none)\n\n");
4767 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
4774 /* Creates a table of paths, to search for source files. */
4777 add_include_path (const char *path
)
4781 include_path_count
++;
4782 include_paths
= (const char **)
4783 xrealloc (include_paths
, include_path_count
* sizeof (*include_paths
));
4784 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4785 if (path
[1] == ':' && path
[2] == 0)
4786 path
= concat (path
, ".", (const char *) 0);
4788 include_paths
[include_path_count
- 1] = path
;
4792 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
4796 if ((section
->flags
& SEC_DEBUGGING
) == 0)
4798 bfd_boolean
*has_reloc_p
= (bfd_boolean
*) arg
;
4799 section
->vma
+= adjust_section_vma
;
4801 section
->lma
+= adjust_section_vma
;
4805 /* Return the sign-extended form of an ARCH_SIZE sized VMA. */
4808 sign_extend_address (bfd
*abfd ATTRIBUTE_UNUSED
,
4813 mask
= (bfd_vma
) 1 << (arch_size
- 1);
4814 return (((vma
& ((mask
<< 1) - 1)) ^ mask
) - mask
);
4817 /* Dump selected contents of ABFD. */
4820 dump_bfd (bfd
*abfd
, bfd_boolean is_mainfile
)
4822 const struct elf_backend_data
* bed
;
4824 if (bfd_big_endian (abfd
))
4825 byte_get
= byte_get_big_endian
;
4826 else if (bfd_little_endian (abfd
))
4827 byte_get
= byte_get_little_endian
;
4831 /* Load any separate debug information files.
4832 We do this now and without checking do_follow_links because separate
4833 debug info files may contain symbol tables that we will need when
4834 displaying information about the main file. Any memory allocated by
4835 load_separate_debug_files will be released when we call
4836 free_debug_memory below.
4838 The test on is_mainfile is there because the chain of separate debug
4839 info files is a global variable shared by all invocations of dump_bfd. */
4842 load_separate_debug_files (abfd
, bfd_get_filename (abfd
));
4844 /* If asked to do so, recursively dump the separate files. */
4845 if (do_follow_links
)
4849 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4850 dump_bfd (i
->handle
, FALSE
);
4854 /* Adjust user-specified start and stop limits for targets that use
4855 signed addresses. */
4856 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4857 && (bed
= get_elf_backend_data (abfd
)) != NULL
4858 && bed
->sign_extend_vma
)
4860 start_address
= sign_extend_address (abfd
, start_address
,
4862 stop_address
= sign_extend_address (abfd
, stop_address
,
4866 /* If we are adjusting section VMA's, change them all now. Changing
4867 the BFD information is a hack. However, we must do it, or
4868 bfd_find_nearest_line will not do the right thing. */
4869 if (adjust_section_vma
!= 0)
4871 bfd_boolean has_reloc
= (abfd
->flags
& HAS_RELOC
);
4872 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
4875 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4876 printf (_("\n%s: file format %s\n"),
4877 sanitize_string (bfd_get_filename (abfd
)),
4880 print_arelt_descr (stdout
, abfd
, TRUE
, FALSE
);
4881 if (dump_file_header
)
4882 dump_bfd_header (abfd
);
4883 if (dump_private_headers
)
4884 dump_bfd_private_header (abfd
);
4885 if (dump_private_options
!= NULL
)
4886 dump_target_specific (abfd
);
4887 if (! dump_debugging_tags
&& ! suppress_bfd_header
)
4894 || dump_dwarf_section_info
)
4896 syms
= slurp_symtab (abfd
);
4898 /* If following links, load any symbol tables from the linked files as well. */
4899 if (do_follow_links
&& is_mainfile
)
4903 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
4905 asymbol
** extra_syms
;
4906 long old_symcount
= symcount
;
4908 extra_syms
= slurp_symtab (i
->handle
);
4912 if (old_symcount
== 0)
4918 syms
= xrealloc (syms
, (symcount
+ old_symcount
+ 1) * sizeof (asymbol
*));
4919 memcpy (syms
+ old_symcount
,
4921 symcount
* sizeof (asymbol
*));
4922 /* Preserve the NULL entry at the end of the symbol table. */
4923 syms
[symcount
+ old_symcount
] = NULL
;
4927 symcount
+= old_symcount
;
4932 if (dump_section_headers
)
4933 dump_headers (abfd
);
4935 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
4936 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
4937 dynsyms
= slurp_dynamic_symtab (abfd
);
4941 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
4942 dynsymcount
, dynsyms
, &synthsyms
);
4948 dump_symbols (abfd
, FALSE
);
4949 if (dump_dynamic_symtab
)
4950 dump_symbols (abfd
, TRUE
);
4951 if (dump_dwarf_section_info
)
4953 if (dump_ctf_section_info
)
4954 dump_ctf (abfd
, dump_ctf_section_name
, dump_ctf_parent_name
);
4955 if (dump_stab_section_info
)
4957 if (dump_reloc_info
&& ! disassemble
)
4959 if (dump_dynamic_reloc_info
&& ! disassemble
)
4960 dump_dynamic_relocs (abfd
);
4961 if (dump_section_contents
)
4964 disassemble_data (abfd
);
4970 dhandle
= read_debugging_info (abfd
, syms
, symcount
, TRUE
);
4971 if (dhandle
!= NULL
)
4973 if (!print_debugging_info (stdout
, dhandle
, abfd
, syms
,
4975 dump_debugging_tags
? TRUE
: FALSE
))
4977 non_fatal (_("%s: printing debugging information failed"),
4978 bfd_get_filename (abfd
));
4984 /* PR 6483: If there was no STABS debug info in the file, try
4986 else if (! dump_dwarf_section_info
)
4988 dwarf_select_sections_all ();
5016 free_debug_memory ();
5020 display_object_bfd (bfd
*abfd
)
5024 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
5026 dump_bfd (abfd
, TRUE
);
5030 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5032 nonfatal (bfd_get_filename (abfd
));
5033 list_matching_formats (matching
);
5038 if (bfd_get_error () != bfd_error_file_not_recognized
)
5040 nonfatal (bfd_get_filename (abfd
));
5044 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
5046 dump_bfd (abfd
, TRUE
);
5050 nonfatal (bfd_get_filename (abfd
));
5052 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
5054 list_matching_formats (matching
);
5060 display_any_bfd (bfd
*file
, int level
)
5062 /* Decompress sections unless dumping the section contents. */
5063 if (!dump_section_contents
)
5064 file
->flags
|= BFD_DECOMPRESS
;
5066 /* If the file is an archive, process all of its elements. */
5067 if (bfd_check_format (file
, bfd_archive
))
5070 bfd
*last_arfile
= NULL
;
5073 printf (_("In archive %s:\n"), sanitize_string (bfd_get_filename (file
)));
5074 else if (level
> 100)
5076 /* Prevent corrupted files from spinning us into an
5077 infinite loop. 100 is an arbitrary heuristic. */
5078 fatal (_("Archive nesting is too deep"));
5082 printf (_("In nested archive %s:\n"),
5083 sanitize_string (bfd_get_filename (file
)));
5087 bfd_set_error (bfd_error_no_error
);
5089 arfile
= bfd_openr_next_archived_file (file
, arfile
);
5092 if (bfd_get_error () != bfd_error_no_more_archived_files
)
5093 nonfatal (bfd_get_filename (file
));
5097 display_any_bfd (arfile
, level
+ 1);
5099 if (last_arfile
!= NULL
)
5101 bfd_close (last_arfile
);
5102 /* PR 17512: file: ac585d01. */
5103 if (arfile
== last_arfile
)
5109 last_arfile
= arfile
;
5112 if (last_arfile
!= NULL
)
5113 bfd_close (last_arfile
);
5116 display_object_bfd (file
);
5120 display_file (char *filename
, char *target
, bfd_boolean last_file
)
5124 if (get_file_size (filename
) < 1)
5130 file
= bfd_openr (filename
, target
);
5133 nonfatal (filename
);
5137 display_any_bfd (file
, 0);
5139 /* This is an optimization to improve the speed of objdump, especially when
5140 dumping a file with lots of associated debug informatiom. Calling
5141 bfd_close on such a file can take a non-trivial amount of time as there
5142 are lots of lists to walk and buffers to free. This is only really
5143 necessary however if we are about to load another file and we need the
5144 memory back. Otherwise, if we are about to exit, then we can save (a lot
5145 of) time by only doing a quick close, and allowing the OS to reclaim the
5150 bfd_close_all_done (file
);
5154 main (int argc
, char **argv
)
5157 char *target
= default_target
;
5158 bfd_boolean seenflag
= FALSE
;
5160 #if defined (HAVE_SETLOCALE)
5161 #if defined (HAVE_LC_MESSAGES)
5162 setlocale (LC_MESSAGES
, "");
5164 setlocale (LC_CTYPE
, "");
5167 bindtextdomain (PACKAGE
, LOCALEDIR
);
5168 textdomain (PACKAGE
);
5170 program_name
= *argv
;
5171 xmalloc_set_program_name (program_name
);
5172 bfd_set_error_program_name (program_name
);
5174 START_PROGRESS (program_name
, 0);
5176 expandargv (&argc
, &argv
);
5178 if (bfd_init () != BFD_INIT_MAGIC
)
5179 fatal (_("fatal error: libbfd ABI mismatch"));
5180 set_default_bfd_target ();
5182 while ((c
= getopt_long (argc
, argv
,
5183 "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
5184 long_options
, (int *) 0))
5190 break; /* We've been given a long option. */
5197 if (disassembler_options
)
5198 /* Ignore potential memory leak for now. */
5199 options
= concat (disassembler_options
, ",",
5200 optarg
, (const char *) NULL
);
5203 disassembler_options
= remove_whitespace_and_extra_commas (options
);
5210 display_file_offsets
= TRUE
;
5213 with_line_numbers
= TRUE
;
5222 enum demangling_styles style
;
5224 style
= cplus_demangle_name_to_style (optarg
);
5225 if (style
== unknown_demangling
)
5226 fatal (_("unknown demangling style `%s'"),
5229 cplus_demangle_set_style (style
);
5232 case OPTION_RECURSE_LIMIT
:
5233 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
5235 case OPTION_NO_RECURSE_LIMIT
:
5236 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
5239 do_wide
= wide_output
= TRUE
;
5241 case OPTION_ADJUST_VMA
:
5242 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
5244 case OPTION_START_ADDRESS
:
5245 start_address
= parse_vma (optarg
, "--start-address");
5246 if ((stop_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5247 fatal (_("error: the start address should be before the end address"));
5249 case OPTION_STOP_ADDRESS
:
5250 stop_address
= parse_vma (optarg
, "--stop-address");
5251 if ((start_address
!= (bfd_vma
) -1) && stop_address
<= start_address
)
5252 fatal (_("error: the stop address should be after the start address"));
5256 prefix_length
= strlen (prefix
);
5257 /* Remove an unnecessary trailing '/' */
5258 while (IS_DIR_SEPARATOR (prefix
[prefix_length
- 1]))
5261 case OPTION_PREFIX_STRIP
:
5262 prefix_strip
= atoi (optarg
);
5263 if (prefix_strip
< 0)
5264 fatal (_("error: prefix strip must be non-negative"));
5266 case OPTION_INSN_WIDTH
:
5267 insn_width
= strtoul (optarg
, NULL
, 0);
5268 if (insn_width
<= 0)
5269 fatal (_("error: instruction width must be positive"));
5271 case OPTION_INLINES
:
5272 unwind_inlines
= TRUE
;
5274 case OPTION_VISUALIZE_JUMPS
:
5275 visualize_jumps
= TRUE
;
5276 color_output
= FALSE
;
5277 extended_color_output
= FALSE
;
5280 if (streq (optarg
, "color"))
5281 color_output
= TRUE
;
5282 else if (streq (optarg
, "extended-color"))
5284 color_output
= TRUE
;
5285 extended_color_output
= TRUE
;
5287 else if (streq (optarg
, "off"))
5288 visualize_jumps
= FALSE
;
5290 nonfatal (_("unrecognized argument to --visualize-option"));
5294 if (strcmp (optarg
, "B") == 0)
5295 endian
= BFD_ENDIAN_BIG
;
5296 else if (strcmp (optarg
, "L") == 0)
5297 endian
= BFD_ENDIAN_LITTLE
;
5300 nonfatal (_("unrecognized -E option"));
5305 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
5306 endian
= BFD_ENDIAN_BIG
;
5307 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
5308 endian
= BFD_ENDIAN_LITTLE
;
5311 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
5318 dump_file_header
= TRUE
;
5322 formats_info
= TRUE
;
5326 add_include_path (optarg
);
5329 dump_private_headers
= TRUE
;
5333 dump_private_options
= optarg
;
5337 dump_private_headers
= TRUE
;
5339 dump_reloc_info
= TRUE
;
5340 dump_file_header
= TRUE
;
5341 dump_ar_hdrs
= TRUE
;
5342 dump_section_headers
= TRUE
;
5350 dump_dynamic_symtab
= TRUE
;
5356 disasm_sym
= optarg
;
5359 disassemble_zeroes
= TRUE
;
5363 disassemble_all
= TRUE
;
5368 with_source_code
= TRUE
;
5371 case OPTION_SOURCE_COMMENT
:
5373 with_source_code
= TRUE
;
5376 source_comment
= xstrdup (sanitize_string (optarg
));
5378 source_comment
= xstrdup ("# ");
5386 dump_debugging_tags
= 1;
5391 dump_dwarf_section_info
= TRUE
;
5394 dwarf_select_sections_by_letters (optarg
);
5396 dwarf_select_sections_all ();
5399 dump_dwarf_section_info
= TRUE
;
5402 dwarf_select_sections_by_names (optarg
);
5404 dwarf_select_sections_all ();
5406 case OPTION_DWARF_DEPTH
:
5409 dwarf_cutoff_level
= strtoul (optarg
, & cp
, 0);
5412 case OPTION_DWARF_START
:
5415 dwarf_start_die
= strtoul (optarg
, & cp
, 0);
5416 suppress_bfd_header
= 1;
5419 case OPTION_DWARF_CHECK
:
5422 #ifdef ENABLE_LIBCTF
5424 dump_ctf_section_info
= TRUE
;
5425 dump_ctf_section_name
= xstrdup (optarg
);
5428 case OPTION_CTF_PARENT
:
5429 dump_ctf_parent_name
= xstrdup (optarg
);
5433 dump_stab_section_info
= TRUE
;
5437 dump_section_contents
= TRUE
;
5441 dump_reloc_info
= TRUE
;
5445 dump_dynamic_reloc_info
= TRUE
;
5449 dump_ar_hdrs
= TRUE
;
5453 dump_section_headers
= TRUE
;
5458 show_version
= TRUE
;
5464 /* No need to set seenflag or to break - usage() does not return. */
5471 print_version ("objdump");
5477 exit_status
= display_info ();
5481 display_file ("a.out", target
, TRUE
);
5483 for (; optind
< argc
;)
5485 display_file (argv
[optind
], target
, optind
== argc
- 1);
5491 free (dump_ctf_section_name
);
5492 free (dump_ctf_parent_name
);
5493 free ((void *) source_comment
);
5495 END_PROGRESS (program_name
);