1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 Objdump displays information about one or more object files, either on
25 their own, or inside libraries. It is commonly used as a disassembler,
26 but it can also display information about file headers, symbol tables,
27 relocations, debugging directives and more.
29 The flow of execution is as follows:
31 1. Command line arguments are checked for control switches and the
32 information to be displayed is selected.
34 2. Any remaining arguments are assumed to be object files, and they are
35 processed in order by display_bfd(). If the file is an archive each
36 of its elements is processed in turn.
38 3. The file's target architecture and binary file format are determined
39 by bfd_check_format(). If they are recognised, then dump_bfd() is
42 4. dump_bfd() in turn calls separate functions to display the requested
43 item(s) of information(s). For example disassemble_data() is called if
44 a disassembly has been requested.
46 When disassembling the code loops through blocks of instructions bounded
47 by symbols, calling disassemble_bytes() on each block. The actual
48 disassembling is done by the libopcodes library, via a function pointer
49 supplied by the disassembler() function. */
58 #include "safe-ctype.h"
60 #include "libiberty.h"
65 /* Internal headers for the ELF .stab-dump code - sorry. */
66 #define BYTES_IN_WORD 32
67 #include "aout/aout64.h"
69 #if !HAVE_DECL_FPRINTF
70 /* This is needed by init_disassemble_info(). */
71 extern int fprintf (FILE *, const char *, ...);
75 static int exit_status
= 0;
77 static char *default_target
= NULL
; /* Default at runtime. */
79 /* The following variables are set based on arguments passed on the
81 static int show_version
= 0; /* Show the version number. */
82 static int dump_section_contents
; /* -s */
83 static int dump_section_headers
; /* -h */
84 static bfd_boolean dump_file_header
; /* -f */
85 static int dump_symtab
; /* -t */
86 static int dump_dynamic_symtab
; /* -T */
87 static int dump_reloc_info
; /* -r */
88 static int dump_dynamic_reloc_info
; /* -R */
89 static int dump_ar_hdrs
; /* -a */
90 static int dump_private_headers
; /* -p */
91 static int prefix_addresses
; /* --prefix-addresses */
92 static int with_line_numbers
; /* -l */
93 static bfd_boolean with_source_code
; /* -S */
94 static int show_raw_insn
; /* --show-raw-insn */
95 static int dump_dwarf_section_info
; /* --dwarf */
96 static int dump_stab_section_info
; /* --stabs */
97 static int do_demangle
; /* -C, --demangle */
98 static bfd_boolean disassemble
; /* -d */
99 static bfd_boolean disassemble_all
; /* -D */
100 static int disassemble_zeroes
; /* --disassemble-zeroes */
101 static bfd_boolean formats_info
; /* -i */
102 static int wide_output
; /* -w */
103 static bfd_vma start_address
= (bfd_vma
) -1; /* --start-address */
104 static bfd_vma stop_address
= (bfd_vma
) -1; /* --stop-address */
105 static int dump_debugging
; /* --debugging */
106 static int dump_debugging_tags
; /* --debugging-tags */
107 static int dump_special_syms
= 0; /* --special-syms */
108 static bfd_vma adjust_section_vma
= 0; /* --adjust-vma */
109 static int file_start_context
= 0; /* --file-start-context */
111 /* Pointer to an array of section names provided by
112 one or more "-j secname" command line options. */
114 /* The total number of slots in the only[] array. */
115 static size_t only_size
= 0;
116 /* The number of occupied slots in the only[] array. */
117 static size_t only_used
= 0;
119 /* Variables for handling include file path table. */
120 static const char **include_paths
;
121 static int include_path_count
;
123 /* Extra info to pass to the section disassembler and address printing
125 struct objdump_disasm_info
129 bfd_boolean require_sec
;
130 arelent
** dynrelbuf
;
132 disassembler_ftype disassemble_fn
;
133 #ifdef DISASSEMBLER_NEEDS_RELOCS
138 /* Architecture to disassemble for, or default if NULL. */
139 static char *machine
= NULL
;
141 /* Target specific options to the disassembler. */
142 static char *disassembler_options
= NULL
;
144 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
145 static enum bfd_endian endian
= BFD_ENDIAN_UNKNOWN
;
147 /* The symbol table. */
148 static asymbol
**syms
;
150 /* Number of symbols in `syms'. */
151 static long symcount
= 0;
153 /* The sorted symbol table. */
154 static asymbol
**sorted_syms
;
156 /* Number of symbols in `sorted_syms'. */
157 static long sorted_symcount
= 0;
159 /* The dynamic symbol table. */
160 static asymbol
**dynsyms
;
162 /* The synthetic symbol table. */
163 static asymbol
*synthsyms
;
164 static long synthcount
= 0;
166 /* Number of symbols in `dynsyms'. */
167 static long dynsymcount
= 0;
169 static bfd_byte
*stabs
;
170 static bfd_size_type stab_size
;
173 static bfd_size_type stabstr_size
;
176 usage (FILE *stream
, int status
)
178 fprintf (stream
, _("Usage: %s <option(s)> <file(s)>\n"), program_name
);
179 fprintf (stream
, _(" Display information from object <file(s)>.\n"));
180 fprintf (stream
, _(" At least one of the following switches must be given:\n"));
181 fprintf (stream
, _("\
182 -a, --archive-headers Display archive header information\n\
183 -f, --file-headers Display the contents of the overall file header\n\
184 -p, --private-headers Display object format specific file header contents\n\
185 -h, --[section-]headers Display the contents of the section headers\n\
186 -x, --all-headers Display the contents of all headers\n\
187 -d, --disassemble Display assembler contents of executable sections\n\
188 -D, --disassemble-all Display assembler contents of all sections\n\
189 -S, --source Intermix source code with disassembly\n\
190 -s, --full-contents Display the full contents of all sections requested\n\
191 -g, --debugging Display debug information in object file\n\
192 -e, --debugging-tags Display debug information using ctags style\n\
193 -G, --stabs Display (in raw form) any STABS info in the file\n\
194 -W, --dwarf Display DWARF info in the file\n\
195 -t, --syms Display the contents of the symbol table(s)\n\
196 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
197 -r, --reloc Display the relocation entries in the file\n\
198 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
199 @<file> Read options from <file>\n\
200 -v, --version Display this program's version number\n\
201 -i, --info List object formats and architectures supported\n\
202 -H, --help Display this information\n\
206 fprintf (stream
, _("\n The following switches are optional:\n"));
207 fprintf (stream
, _("\
208 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
209 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
210 -j, --section=NAME Only display information for section NAME\n\
211 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
212 -EB --endian=big Assume big endian format when disassembling\n\
213 -EL --endian=little Assume little endian format when disassembling\n\
214 --file-start-context Include context from start of file (with -S)\n\
215 -I, --include=DIR Add DIR to search list for source files\n\
216 -l, --line-numbers Include line numbers and filenames in output\n\
217 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
218 The STYLE, if specified, can be `auto', `gnu',\n\
219 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
221 -w, --wide Format output for more than 80 columns\n\
222 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
223 --start-address=ADDR Only process data whose address is >= ADDR\n\
224 --stop-address=ADDR Only process data whose address is <= ADDR\n\
225 --prefix-addresses Print complete address alongside disassembly\n\
226 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
227 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
228 --special-syms Include special symbols in symbol dumps\n\
230 list_supported_targets (program_name
, stream
);
231 list_supported_architectures (program_name
, stream
);
233 disassembler_usage (stream
);
236 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
240 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
244 OPTION_START_ADDRESS
,
249 static struct option long_options
[]=
251 {"adjust-vma", required_argument
, NULL
, OPTION_ADJUST_VMA
},
252 {"all-headers", no_argument
, NULL
, 'x'},
253 {"private-headers", no_argument
, NULL
, 'p'},
254 {"architecture", required_argument
, NULL
, 'm'},
255 {"archive-headers", no_argument
, NULL
, 'a'},
256 {"debugging", no_argument
, NULL
, 'g'},
257 {"debugging-tags", no_argument
, NULL
, 'e'},
258 {"demangle", optional_argument
, NULL
, 'C'},
259 {"disassemble", no_argument
, NULL
, 'd'},
260 {"disassemble-all", no_argument
, NULL
, 'D'},
261 {"disassembler-options", required_argument
, NULL
, 'M'},
262 {"disassemble-zeroes", no_argument
, NULL
, 'z'},
263 {"dynamic-reloc", no_argument
, NULL
, 'R'},
264 {"dynamic-syms", no_argument
, NULL
, 'T'},
265 {"endian", required_argument
, NULL
, OPTION_ENDIAN
},
266 {"file-headers", no_argument
, NULL
, 'f'},
267 {"file-start-context", no_argument
, &file_start_context
, 1},
268 {"full-contents", no_argument
, NULL
, 's'},
269 {"headers", no_argument
, NULL
, 'h'},
270 {"help", no_argument
, NULL
, 'H'},
271 {"info", no_argument
, NULL
, 'i'},
272 {"line-numbers", no_argument
, NULL
, 'l'},
273 {"no-show-raw-insn", no_argument
, &show_raw_insn
, -1},
274 {"prefix-addresses", no_argument
, &prefix_addresses
, 1},
275 {"reloc", no_argument
, NULL
, 'r'},
276 {"section", required_argument
, NULL
, 'j'},
277 {"section-headers", no_argument
, NULL
, 'h'},
278 {"show-raw-insn", no_argument
, &show_raw_insn
, 1},
279 {"source", no_argument
, NULL
, 'S'},
280 {"special-syms", no_argument
, &dump_special_syms
, 1},
281 {"include", required_argument
, NULL
, 'I'},
282 {"dwarf", no_argument
, NULL
, 'W'},
283 {"stabs", no_argument
, NULL
, 'G'},
284 {"start-address", required_argument
, NULL
, OPTION_START_ADDRESS
},
285 {"stop-address", required_argument
, NULL
, OPTION_STOP_ADDRESS
},
286 {"syms", no_argument
, NULL
, 't'},
287 {"target", required_argument
, NULL
, 'b'},
288 {"version", no_argument
, NULL
, 'V'},
289 {"wide", no_argument
, NULL
, 'w'},
290 {0, no_argument
, 0, 0}
294 nonfatal (const char *msg
)
301 dump_section_header (bfd
*abfd
, asection
*section
,
302 void *ignored ATTRIBUTE_UNUSED
)
305 unsigned int opb
= bfd_octets_per_byte (abfd
);
307 /* Ignore linker created section. See elfNN_ia64_object_p in
309 if (section
->flags
& SEC_LINKER_CREATED
)
312 printf ("%3d %-13s %08lx ", section
->index
,
313 bfd_get_section_name (abfd
, section
),
314 (unsigned long) bfd_section_size (abfd
, section
) / opb
);
315 bfd_printf_vma (abfd
, bfd_get_section_vma (abfd
, section
));
317 bfd_printf_vma (abfd
, section
->lma
);
318 printf (" %08lx 2**%u", (unsigned long) section
->filepos
,
319 bfd_get_section_alignment (abfd
, section
));
325 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
327 PF (SEC_HAS_CONTENTS
, "CONTENTS");
328 PF (SEC_ALLOC
, "ALLOC");
329 PF (SEC_CONSTRUCTOR
, "CONSTRUCTOR");
330 PF (SEC_LOAD
, "LOAD");
331 PF (SEC_RELOC
, "RELOC");
332 PF (SEC_READONLY
, "READONLY");
333 PF (SEC_CODE
, "CODE");
334 PF (SEC_DATA
, "DATA");
336 PF (SEC_DEBUGGING
, "DEBUGGING");
337 PF (SEC_NEVER_LOAD
, "NEVER_LOAD");
338 PF (SEC_EXCLUDE
, "EXCLUDE");
339 PF (SEC_SORT_ENTRIES
, "SORT_ENTRIES");
340 if (bfd_get_arch (abfd
) == bfd_arch_tic54x
)
342 PF (SEC_TIC54X_BLOCK
, "BLOCK");
343 PF (SEC_TIC54X_CLINK
, "CLINK");
345 PF (SEC_SMALL_DATA
, "SMALL_DATA");
346 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
347 PF (SEC_COFF_SHARED
, "SHARED");
348 PF (SEC_THREAD_LOCAL
, "THREAD_LOCAL");
349 PF (SEC_GROUP
, "GROUP");
351 if ((section
->flags
& SEC_LINK_ONCE
) != 0)
354 struct coff_comdat_info
*comdat
;
356 switch (section
->flags
& SEC_LINK_DUPLICATES
)
360 case SEC_LINK_DUPLICATES_DISCARD
:
361 ls
= "LINK_ONCE_DISCARD";
363 case SEC_LINK_DUPLICATES_ONE_ONLY
:
364 ls
= "LINK_ONCE_ONE_ONLY";
366 case SEC_LINK_DUPLICATES_SAME_SIZE
:
367 ls
= "LINK_ONCE_SAME_SIZE";
369 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
370 ls
= "LINK_ONCE_SAME_CONTENTS";
373 printf ("%s%s", comma
, ls
);
375 comdat
= bfd_coff_get_comdat_section (abfd
, section
);
377 printf (" (COMDAT %s %ld)", comdat
->name
, comdat
->symbol
);
387 dump_headers (bfd
*abfd
)
389 printf (_("Sections:\n"));
392 printf (_("Idx Name Size VMA LMA File off Algn"));
394 /* With BFD64, non-ELF returns -1 and wants always 64 bit addresses. */
395 if (bfd_get_arch_size (abfd
) == 32)
396 printf (_("Idx Name Size VMA LMA File off Algn"));
398 printf (_("Idx Name Size VMA LMA File off Algn"));
402 printf (_(" Flags"));
403 if (abfd
->flags
& HAS_LOAD_PAGE
)
407 bfd_map_over_sections (abfd
, dump_section_header
, NULL
);
411 slurp_symtab (bfd
*abfd
)
416 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
422 storage
= bfd_get_symtab_upper_bound (abfd
);
424 bfd_fatal (bfd_get_filename (abfd
));
426 sy
= xmalloc (storage
);
428 symcount
= bfd_canonicalize_symtab (abfd
, sy
);
430 bfd_fatal (bfd_get_filename (abfd
));
434 /* Read in the dynamic symbols. */
437 slurp_dynamic_symtab (bfd
*abfd
)
442 storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
445 if (!(bfd_get_file_flags (abfd
) & DYNAMIC
))
447 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd
));
452 bfd_fatal (bfd_get_filename (abfd
));
455 sy
= xmalloc (storage
);
457 dynsymcount
= bfd_canonicalize_dynamic_symtab (abfd
, sy
);
459 bfd_fatal (bfd_get_filename (abfd
));
463 /* Filter out (in place) symbols that are useless for disassembly.
464 COUNT is the number of elements in SYMBOLS.
465 Return the number of useful symbols. */
468 remove_useless_symbols (asymbol
**symbols
, long count
)
470 asymbol
**in_ptr
= symbols
, **out_ptr
= symbols
;
474 asymbol
*sym
= *in_ptr
++;
476 if (sym
->name
== NULL
|| sym
->name
[0] == '\0')
478 if (sym
->flags
& (BSF_DEBUGGING
| BSF_SECTION_SYM
))
480 if (bfd_is_und_section (sym
->section
)
481 || bfd_is_com_section (sym
->section
))
486 return out_ptr
- symbols
;
489 /* Sort symbols into value order. */
492 compare_symbols (const void *ap
, const void *bp
)
494 const asymbol
*a
= * (const asymbol
**) ap
;
495 const asymbol
*b
= * (const asymbol
**) bp
;
505 if (bfd_asymbol_value (a
) > bfd_asymbol_value (b
))
507 else if (bfd_asymbol_value (a
) < bfd_asymbol_value (b
))
510 if (a
->section
> b
->section
)
512 else if (a
->section
< b
->section
)
515 an
= bfd_asymbol_name (a
);
516 bn
= bfd_asymbol_name (b
);
520 /* The symbols gnu_compiled and gcc2_compiled convey no real
521 information, so put them after other symbols with the same value. */
522 af
= (strstr (an
, "gnu_compiled") != NULL
523 || strstr (an
, "gcc2_compiled") != NULL
);
524 bf
= (strstr (bn
, "gnu_compiled") != NULL
525 || strstr (bn
, "gcc2_compiled") != NULL
);
532 /* We use a heuristic for the file name, to try to sort it after
533 more useful symbols. It may not work on non Unix systems, but it
534 doesn't really matter; the only difference is precisely which
535 symbol names get printed. */
537 #define file_symbol(s, sn, snl) \
538 (((s)->flags & BSF_FILE) != 0 \
539 || ((sn)[(snl) - 2] == '.' \
540 && ((sn)[(snl) - 1] == 'o' \
541 || (sn)[(snl) - 1] == 'a')))
543 af
= file_symbol (a
, an
, anl
);
544 bf
= file_symbol (b
, bn
, bnl
);
551 /* Try to sort global symbols before local symbols before function
552 symbols before debugging symbols. */
557 if ((aflags
& BSF_DEBUGGING
) != (bflags
& BSF_DEBUGGING
))
559 if ((aflags
& BSF_DEBUGGING
) != 0)
564 if ((aflags
& BSF_FUNCTION
) != (bflags
& BSF_FUNCTION
))
566 if ((aflags
& BSF_FUNCTION
) != 0)
571 if ((aflags
& BSF_LOCAL
) != (bflags
& BSF_LOCAL
))
573 if ((aflags
& BSF_LOCAL
) != 0)
578 if ((aflags
& BSF_GLOBAL
) != (bflags
& BSF_GLOBAL
))
580 if ((aflags
& BSF_GLOBAL
) != 0)
586 /* Symbols that start with '.' might be section names, so sort them
587 after symbols that don't start with '.'. */
588 if (an
[0] == '.' && bn
[0] != '.')
590 if (an
[0] != '.' && bn
[0] == '.')
593 /* Finally, if we can't distinguish them in any other way, try to
594 get consistent results by sorting the symbols by name. */
595 return strcmp (an
, bn
);
598 /* Sort relocs into address order. */
601 compare_relocs (const void *ap
, const void *bp
)
603 const arelent
*a
= * (const arelent
**) ap
;
604 const arelent
*b
= * (const arelent
**) bp
;
606 if (a
->address
> b
->address
)
608 else if (a
->address
< b
->address
)
611 /* So that associated relocations tied to the same address show up
612 in the correct order, we don't do any further sorting. */
621 /* Print an address (VMA) to the output stream in INFO.
622 If SKIP_ZEROES is TRUE, omit leading zeroes. */
625 objdump_print_value (bfd_vma vma
, struct disassemble_info
*info
,
626 bfd_boolean skip_zeroes
)
630 struct objdump_disasm_info
*aux
;
632 aux
= (struct objdump_disasm_info
*) info
->application_data
;
633 bfd_sprintf_vma (aux
->abfd
, buf
, vma
);
638 for (p
= buf
; *p
== '0'; ++p
)
643 (*info
->fprintf_func
) (info
->stream
, "%s", p
);
646 /* Print the name of a symbol. */
649 objdump_print_symname (bfd
*abfd
, struct disassemble_info
*info
,
656 name
= bfd_asymbol_name (sym
);
657 if (do_demangle
&& name
[0] != '\0')
659 /* Demangle the name. */
660 alloc
= demangle (abfd
, name
);
665 (*info
->fprintf_func
) (info
->stream
, "%s", name
);
673 /* Locate a symbol given a bfd and a section (from INFO->application_data),
674 and a VMA. If INFO->application_data->require_sec is TRUE, then always
675 require the symbol to be in the section. Returns NULL if there is no
676 suitable symbol. If PLACE is not NULL, then *PLACE is set to the index
677 of the symbol in sorted_syms. */
680 find_symbol_for_address (bfd_vma vma
,
681 struct disassemble_info
*info
,
684 /* @@ Would it speed things up to cache the last two symbols returned,
685 and maybe their address ranges? For many processors, only one memory
686 operand can be present at a time, so the 2-entry cache wouldn't be
687 constantly churned by code doing heavy memory accesses. */
689 /* Indices in `sorted_syms'. */
691 long max
= sorted_symcount
;
693 struct objdump_disasm_info
*aux
;
698 if (sorted_symcount
< 1)
701 aux
= (struct objdump_disasm_info
*) info
->application_data
;
704 opb
= bfd_octets_per_byte (abfd
);
706 /* Perform a binary search looking for the closest symbol to the
707 required value. We are searching the range (min, max]. */
708 while (min
+ 1 < max
)
712 thisplace
= (max
+ min
) / 2;
713 sym
= sorted_syms
[thisplace
];
715 if (bfd_asymbol_value (sym
) > vma
)
717 else if (bfd_asymbol_value (sym
) < vma
)
726 /* The symbol we want is now in min, the low end of the range we
727 were searching. If there are several symbols with the same
728 value, we want the first one. */
731 && (bfd_asymbol_value (sorted_syms
[thisplace
])
732 == bfd_asymbol_value (sorted_syms
[thisplace
- 1])))
735 /* If the file is relocatable, and the symbol could be from this
736 section, prefer a symbol from this section over symbols from
737 others, even if the other symbol's value might be closer.
739 Note that this may be wrong for some symbol references if the
740 sections have overlapping memory ranges, but in that case there's
741 no way to tell what's desired without looking at the relocation
743 if (sorted_syms
[thisplace
]->section
!= sec
745 || ((abfd
->flags
& HAS_RELOC
) != 0
746 && vma
>= bfd_get_section_vma (abfd
, sec
)
747 && vma
< (bfd_get_section_vma (abfd
, sec
)
748 + bfd_section_size (abfd
, sec
) / opb
))))
752 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
754 if (bfd_asymbol_value (sorted_syms
[i
])
755 != bfd_asymbol_value (sorted_syms
[thisplace
]))
763 if (sorted_syms
[i
]->section
== sec
765 || sorted_syms
[i
- 1]->section
!= sec
766 || (bfd_asymbol_value (sorted_syms
[i
])
767 != bfd_asymbol_value (sorted_syms
[i
- 1]))))
774 if (sorted_syms
[thisplace
]->section
!= sec
)
776 /* We didn't find a good symbol with a smaller value.
777 Look for one with a larger value. */
778 for (i
= thisplace
+ 1; i
< sorted_symcount
; i
++)
780 if (sorted_syms
[i
]->section
== sec
)
788 if (sorted_syms
[thisplace
]->section
!= sec
790 || ((abfd
->flags
& HAS_RELOC
) != 0
791 && vma
>= bfd_get_section_vma (abfd
, sec
)
792 && vma
< (bfd_get_section_vma (abfd
, sec
)
793 + bfd_section_size (abfd
, sec
)))))
794 /* There is no suitable symbol. */
798 /* Give the target a chance to reject the symbol. */
799 while (! info
->symbol_is_valid (sorted_syms
[thisplace
], info
))
802 if (thisplace
>= sorted_symcount
803 || bfd_asymbol_value (sorted_syms
[thisplace
]) > vma
)
810 return sorted_syms
[thisplace
];
813 /* Print an address and the offset to the nearest symbol. */
816 objdump_print_addr_with_sym (bfd
*abfd
, asection
*sec
, asymbol
*sym
,
817 bfd_vma vma
, struct disassemble_info
*info
,
818 bfd_boolean skip_zeroes
)
820 objdump_print_value (vma
, info
, skip_zeroes
);
826 (*info
->fprintf_func
) (info
->stream
, " <%s",
827 bfd_get_section_name (abfd
, sec
));
828 secaddr
= bfd_get_section_vma (abfd
, sec
);
831 (*info
->fprintf_func
) (info
->stream
, "-0x");
832 objdump_print_value (secaddr
- vma
, info
, TRUE
);
834 else if (vma
> secaddr
)
836 (*info
->fprintf_func
) (info
->stream
, "+0x");
837 objdump_print_value (vma
- secaddr
, info
, TRUE
);
839 (*info
->fprintf_func
) (info
->stream
, ">");
843 (*info
->fprintf_func
) (info
->stream
, " <");
844 objdump_print_symname (abfd
, info
, sym
);
845 if (bfd_asymbol_value (sym
) > vma
)
847 (*info
->fprintf_func
) (info
->stream
, "-0x");
848 objdump_print_value (bfd_asymbol_value (sym
) - vma
, info
, TRUE
);
850 else if (vma
> bfd_asymbol_value (sym
))
852 (*info
->fprintf_func
) (info
->stream
, "+0x");
853 objdump_print_value (vma
- bfd_asymbol_value (sym
), info
, TRUE
);
855 (*info
->fprintf_func
) (info
->stream
, ">");
859 /* Print an address (VMA), symbolically if possible.
860 If SKIP_ZEROES is TRUE, don't output leading zeroes. */
863 objdump_print_addr (bfd_vma vma
,
864 struct disassemble_info
*info
,
865 bfd_boolean skip_zeroes
)
867 struct objdump_disasm_info
*aux
;
868 asymbol
*sym
= NULL
; /* Initialize to avoid compiler warning. */
869 #ifdef DISASSEMBLER_NEEDS_RELOCS
870 bfd_boolean skip_find
= FALSE
;
873 if (sorted_symcount
< 1)
875 (*info
->fprintf_func
) (info
->stream
, "0x");
876 objdump_print_value (vma
, info
, skip_zeroes
);
880 aux
= (struct objdump_disasm_info
*) info
->application_data
;
882 #ifdef DISASSEMBLER_NEEDS_RELOCS
883 if (aux
->reloc
!= NULL
884 && aux
->reloc
->sym_ptr_ptr
!= NULL
885 && * aux
->reloc
->sym_ptr_ptr
!= NULL
)
887 sym
= * aux
->reloc
->sym_ptr_ptr
;
889 /* Adjust the vma to the reloc. */
890 vma
+= bfd_asymbol_value (sym
);
892 if (bfd_is_und_section (bfd_get_section (sym
)))
898 sym
= find_symbol_for_address (vma
, info
, NULL
);
900 objdump_print_addr_with_sym (aux
->abfd
, aux
->sec
, sym
, vma
, info
,
904 /* Print VMA to INFO. This function is passed to the disassembler
908 objdump_print_address (bfd_vma vma
, struct disassemble_info
*info
)
910 objdump_print_addr (vma
, info
, ! prefix_addresses
);
913 /* Determine of the given address has a symbol associated with it. */
916 objdump_symbol_at_address (bfd_vma vma
, struct disassemble_info
* info
)
920 sym
= find_symbol_for_address (vma
, info
, NULL
);
922 return (sym
!= NULL
&& (bfd_asymbol_value (sym
) == vma
));
925 /* Hold the last function name and the last line number we displayed
928 static char *prev_functionname
;
929 static unsigned int prev_line
;
931 /* We keep a list of all files that we have seen when doing a
932 disassembly with source, so that we know how much of the file to
933 display. This can be important for inlined functions. */
935 struct print_file_list
937 struct print_file_list
*next
;
938 const char *filename
;
944 static struct print_file_list
*print_files
;
946 /* The number of preceding context lines to show when we start
947 displaying a file for the first time. */
949 #define SHOW_PRECEDING_CONTEXT_LINES (5)
951 /* Tries to open MODNAME, and if successful adds a node to print_files
952 linked list and returns that node. Returns NULL on failure. */
954 static struct print_file_list
*
955 try_print_file_open (const char *origname
, const char *modname
)
957 struct print_file_list
*p
;
960 f
= fopen (modname
, "r");
964 if (print_files
!= NULL
&& print_files
->f
!= NULL
)
966 fclose (print_files
->f
);
967 print_files
->f
= NULL
;
970 p
= xmalloc (sizeof (struct print_file_list
));
971 p
->filename
= origname
;
972 p
->modname
= modname
;
975 p
->next
= print_files
;
980 /* If the the source file, as described in the symtab, is not found
981 try to locate it in one of the paths specified with -I
982 If found, add location to print_files linked list. */
984 static struct print_file_list
*
985 update_source_path (const char *filename
)
987 struct print_file_list
*p
;
991 if (filename
== NULL
)
994 p
= try_print_file_open (filename
, filename
);
998 if (include_path_count
== 0)
1001 /* Get the name of the file. */
1002 fname
= strrchr (filename
, '/');
1003 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
1005 /* We could have a mixed forward/back slash case. */
1006 char *backslash
= strrchr (filename
, '\\');
1007 if (fname
== NULL
|| (backslash
!= NULL
&& backslash
> fname
))
1009 if (fname
== NULL
&& filename
[0] != '\0' && filename
[1] == ':')
1010 fname
= filename
+ 1;
1018 /* If file exists under a new path, we need to add it to the list
1019 so that show_line knows about it. */
1020 for (i
= 0; i
< include_path_count
; i
++)
1022 char *modname
= concat (include_paths
[i
], "/", fname
, (const char *) 0);
1024 p
= try_print_file_open (filename
, modname
);
1034 /* Skip ahead to a given line in a file, optionally printing each
1038 skip_to_line (struct print_file_list
*p
, unsigned int line
,
1041 while (p
->line
< line
)
1045 if (fgets (buf
, sizeof buf
, p
->f
) == NULL
)
1055 if (strchr (buf
, '\n') != NULL
)
1060 /* Show the line number, or the source line, in a disassembly
1064 show_line (bfd
*abfd
, asection
*section
, bfd_vma addr_offset
)
1066 const char *filename
;
1067 const char *functionname
;
1070 if (! with_line_numbers
&& ! with_source_code
)
1073 if (! bfd_find_nearest_line (abfd
, section
, syms
, addr_offset
, &filename
,
1074 &functionname
, &line
))
1077 if (filename
!= NULL
&& *filename
== '\0')
1079 if (functionname
!= NULL
&& *functionname
== '\0')
1080 functionname
= NULL
;
1082 if (with_line_numbers
)
1084 if (functionname
!= NULL
1085 && (prev_functionname
== NULL
1086 || strcmp (functionname
, prev_functionname
) != 0))
1087 printf ("%s():\n", functionname
);
1088 if (line
> 0 && line
!= prev_line
)
1089 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
1092 if (with_source_code
1096 struct print_file_list
**pp
, *p
;
1098 for (pp
= &print_files
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1099 if (strcmp ((*pp
)->filename
, filename
) == 0)
1105 if (p
!= print_files
)
1109 /* We have reencountered a file name which we saw
1110 earlier. This implies that either we are dumping out
1111 code from an included file, or the same file was
1112 linked in more than once. There are two common cases
1113 of an included file: inline functions in a header
1114 file, and a bison or flex skeleton file. In the
1115 former case we want to just start printing (but we
1116 back up a few lines to give context); in the latter
1117 case we want to continue from where we left off. I
1118 can't think of a good way to distinguish the cases,
1119 so I used a heuristic based on the file name. */
1120 if (strcmp (p
->filename
+ strlen (p
->filename
) - 2, ".h") != 0)
1124 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
1131 p
->f
= fopen (p
->modname
, "r");
1135 skip_to_line (p
, l
, FALSE
);
1137 if (print_files
->f
!= NULL
)
1139 fclose (print_files
->f
);
1140 print_files
->f
= NULL
;
1146 skip_to_line (p
, line
, TRUE
);
1148 p
->next
= print_files
;
1154 p
= update_source_path (filename
);
1160 if (file_start_context
)
1163 l
= line
- SHOW_PRECEDING_CONTEXT_LINES
;
1166 skip_to_line (p
, l
, FALSE
);
1168 skip_to_line (p
, line
, TRUE
);
1173 if (functionname
!= NULL
1174 && (prev_functionname
== NULL
1175 || strcmp (functionname
, prev_functionname
) != 0))
1177 if (prev_functionname
!= NULL
)
1178 free (prev_functionname
);
1179 prev_functionname
= xmalloc (strlen (functionname
) + 1);
1180 strcpy (prev_functionname
, functionname
);
1183 if (line
> 0 && line
!= prev_line
)
1187 /* Pseudo FILE object for strings. */
1195 /* sprintf to a "stream". */
1197 static int ATTRIBUTE_PRINTF_2
1198 objdump_sprintf (SFILE
*f
, const char *format
, ...)
1205 size_t space
= f
->alloc
- f
->pos
;
1207 va_start (args
, format
);
1208 n
= vsnprintf (f
->buffer
+ f
->pos
, space
, format
, args
);
1214 f
->alloc
= (f
->alloc
+ n
) * 2;
1215 f
->buffer
= xrealloc (f
->buffer
, f
->alloc
);
1222 /* Returns TRUE if the specified section should be dumped. */
1225 process_section_p (asection
* section
)
1232 for (i
= 0; i
< only_used
; i
++)
1233 if (strcmp (only
[i
], section
->name
) == 0)
1240 /* The number of zeroes we want to see before we start skipping them.
1241 The number is arbitrarily chosen. */
1243 #define DEFAULT_SKIP_ZEROES 8
1245 /* The number of zeroes to skip at the end of a section. If the
1246 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1247 SKIP_ZEROES, they will be disassembled. If there are fewer than
1248 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1249 attempt to avoid disassembling zeroes inserted by section
1252 #define DEFAULT_SKIP_ZEROES_AT_END 3
1254 /* Disassemble some data in memory between given values. */
1257 disassemble_bytes (struct disassemble_info
* info
,
1258 disassembler_ftype disassemble_fn
,
1261 bfd_vma start_offset
,
1262 bfd_vma stop_offset
,
1265 arelent
** relppend
)
1267 struct objdump_disasm_info
*aux
;
1269 int octets_per_line
;
1270 bfd_boolean done_dot
;
1271 int skip_addr_chars
;
1272 bfd_vma addr_offset
;
1273 unsigned int opb
= info
->octets_per_byte
;
1274 unsigned int skip_zeroes
= info
->skip_zeroes
;
1275 unsigned int skip_zeroes_at_end
= info
->skip_zeroes_at_end
;
1279 aux
= (struct objdump_disasm_info
*) info
->application_data
;
1283 sfile
.buffer
= xmalloc (sfile
.alloc
);
1287 octets_per_line
= 4;
1289 octets_per_line
= 16;
1291 /* Figure out how many characters to skip at the start of an
1292 address, to make the disassembly look nicer. We discard leading
1293 zeroes in chunks of 4, ensuring that there is always a leading
1295 skip_addr_chars
= 0;
1296 if (! prefix_addresses
)
1304 + bfd_section_size (section
->owner
, section
) / opb
));
1306 while (s
[0] == '0' && s
[1] == '0' && s
[2] == '0' && s
[3] == '0'
1309 skip_addr_chars
+= 4;
1314 info
->insn_info_valid
= 0;
1317 addr_offset
= start_offset
;
1318 while (addr_offset
< stop_offset
)
1321 bfd_boolean need_nl
= FALSE
;
1322 #ifdef DISASSEMBLER_NEEDS_RELOCS
1323 int previous_octets
;
1325 /* Remember the length of the previous instruction. */
1326 previous_octets
= octets
;
1330 /* If we see more than SKIP_ZEROES octets of zeroes, we just
1332 for (z
= addr_offset
* opb
; z
< stop_offset
* opb
; z
++)
1335 if (! disassemble_zeroes
1336 && (info
->insn_info_valid
== 0
1337 || info
->branch_delay_insns
== 0)
1338 && (z
- addr_offset
* opb
>= skip_zeroes
1339 || (z
== stop_offset
* opb
&&
1340 z
- addr_offset
* opb
< skip_zeroes_at_end
)))
1344 /* If there are more nonzero octets to follow, we only skip
1345 zeroes in multiples of 4, to try to avoid running over
1346 the start of an instruction which happens to start with
1348 if (z
!= stop_offset
* opb
)
1349 z
= addr_offset
* opb
+ ((z
- addr_offset
* opb
) &~ 3);
1351 octets
= z
- addr_offset
* opb
;
1361 if (with_line_numbers
|| with_source_code
)
1362 show_line (aux
->abfd
, section
, addr_offset
);
1364 if (! prefix_addresses
)
1368 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ addr_offset
);
1369 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
1373 printf ("%s:\t", buf
+ skip_addr_chars
);
1377 aux
->require_sec
= TRUE
;
1378 objdump_print_address (section
->vma
+ addr_offset
, info
);
1379 aux
->require_sec
= FALSE
;
1386 info
->fprintf_func
= (fprintf_ftype
) objdump_sprintf
;
1387 info
->stream
= &sfile
;
1388 info
->bytes_per_line
= 0;
1389 info
->bytes_per_chunk
= 0;
1392 #ifdef DISASSEMBLER_NEEDS_RELOCS
1393 if (*relppp
< relppend
)
1395 bfd_signed_vma distance_to_rel
;
1397 distance_to_rel
= (**relppp
)->address
1398 - (rel_offset
+ addr_offset
);
1400 /* Check to see if the current reloc is associated with
1401 the instruction that we are about to disassemble. */
1402 if (distance_to_rel
== 0
1403 /* FIXME: This is wrong. We are trying to catch
1404 relocs that are addressed part way through the
1405 current instruction, as might happen with a packed
1406 VLIW instruction. Unfortunately we do not know the
1407 length of the current instruction since we have not
1408 disassembled it yet. Instead we take a guess based
1409 upon the length of the previous instruction. The
1410 proper solution is to have a new target-specific
1411 disassembler function which just returns the length
1412 of an instruction at a given address without trying
1413 to display its disassembly. */
1414 || (distance_to_rel
> 0
1415 && distance_to_rel
< (bfd_signed_vma
) (previous_octets
/ opb
)))
1417 info
->flags
= INSN_HAS_RELOC
;
1418 aux
->reloc
= **relppp
;
1424 octets
= (*disassemble_fn
) (section
->vma
+ addr_offset
, info
);
1425 info
->fprintf_func
= (fprintf_ftype
) fprintf
;
1426 info
->stream
= stdout
;
1427 if (info
->bytes_per_line
!= 0)
1428 octets_per_line
= info
->bytes_per_line
;
1432 printf ("%s\n", sfile
.buffer
);
1440 octets
= octets_per_line
;
1441 if (addr_offset
+ octets
/ opb
> stop_offset
)
1442 octets
= (stop_offset
- addr_offset
) * opb
;
1444 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ octets
; ++j
)
1446 if (ISPRINT (data
[j
]))
1447 buf
[j
- addr_offset
* opb
] = data
[j
];
1449 buf
[j
- addr_offset
* opb
] = '.';
1451 buf
[j
- addr_offset
* opb
] = '\0';
1454 if (prefix_addresses
1456 : show_raw_insn
>= 0)
1460 /* If ! prefix_addresses and ! wide_output, we print
1461 octets_per_line octets per line. */
1463 if (pb
> octets_per_line
&& ! prefix_addresses
&& ! wide_output
)
1464 pb
= octets_per_line
;
1466 if (info
->bytes_per_chunk
)
1467 bpc
= info
->bytes_per_chunk
;
1471 for (j
= addr_offset
* opb
; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
1475 if (bpc
> 1 && info
->display_endian
== BFD_ENDIAN_LITTLE
)
1477 for (k
= bpc
- 1; k
>= 0; k
--)
1478 printf ("%02x", (unsigned) data
[j
+ k
]);
1483 for (k
= 0; k
< bpc
; k
++)
1484 printf ("%02x", (unsigned) data
[j
+ k
]);
1489 for (; pb
< octets_per_line
; pb
+= bpc
)
1493 for (k
= 0; k
< bpc
; k
++)
1498 /* Separate raw data from instruction by extra space. */
1508 printf ("%s", sfile
.buffer
);
1510 if (prefix_addresses
1512 : show_raw_insn
>= 0)
1520 j
= addr_offset
* opb
+ pb
;
1522 bfd_sprintf_vma (aux
->abfd
, buf
, section
->vma
+ j
/ opb
);
1523 for (s
= buf
+ skip_addr_chars
; *s
== '0'; s
++)
1527 printf ("%s:\t", buf
+ skip_addr_chars
);
1529 pb
+= octets_per_line
;
1532 for (; j
< addr_offset
* opb
+ pb
; j
+= bpc
)
1536 if (bpc
> 1 && info
->display_endian
== BFD_ENDIAN_LITTLE
)
1538 for (k
= bpc
- 1; k
>= 0; k
--)
1539 printf ("%02x", (unsigned) data
[j
+ k
]);
1544 for (k
= 0; k
< bpc
; k
++)
1545 printf ("%02x", (unsigned) data
[j
+ k
]);
1558 while ((*relppp
) < relppend
1559 && (**relppp
)->address
< rel_offset
+ addr_offset
+ octets
/ opb
)
1561 if (dump_reloc_info
|| dump_dynamic_reloc_info
)
1572 objdump_print_value (section
->vma
- rel_offset
+ q
->address
,
1575 if (q
->howto
== NULL
)
1576 printf (": *unknown*\t");
1577 else if (q
->howto
->name
)
1578 printf (": %s\t", q
->howto
->name
);
1580 printf (": %d\t", q
->howto
->type
);
1582 if (q
->sym_ptr_ptr
== NULL
|| *q
->sym_ptr_ptr
== NULL
)
1583 printf ("*unknown*");
1586 const char *sym_name
;
1588 sym_name
= bfd_asymbol_name (*q
->sym_ptr_ptr
);
1589 if (sym_name
!= NULL
&& *sym_name
!= '\0')
1590 objdump_print_symname (aux
->abfd
, info
, *q
->sym_ptr_ptr
);
1595 sym_sec
= bfd_get_section (*q
->sym_ptr_ptr
);
1596 sym_name
= bfd_get_section_name (aux
->abfd
, sym_sec
);
1597 if (sym_name
== NULL
|| *sym_name
== '\0')
1598 sym_name
= "*unknown*";
1599 printf ("%s", sym_name
);
1606 objdump_print_value (q
->addend
, info
, TRUE
);
1618 addr_offset
+= octets
/ opb
;
1621 free (sfile
.buffer
);
1625 disassemble_section (bfd
*abfd
, asection
*section
, void *info
)
1627 struct disassemble_info
* pinfo
= (struct disassemble_info
*) info
;
1628 struct objdump_disasm_info
* paux
;
1629 unsigned int opb
= pinfo
->octets_per_byte
;
1630 bfd_byte
* data
= NULL
;
1631 bfd_size_type datasize
= 0;
1632 arelent
** rel_pp
= NULL
;
1633 arelent
** rel_ppstart
= NULL
;
1634 arelent
** rel_ppend
;
1635 unsigned long stop_offset
;
1636 asymbol
* sym
= NULL
;
1640 unsigned long addr_offset
;
1642 /* Sections that do not contain machine
1643 code are not normally disassembled. */
1644 if (! disassemble_all
1646 && ((section
->flags
& (SEC_CODE
| SEC_HAS_CONTENTS
))
1647 != (SEC_CODE
| SEC_HAS_CONTENTS
)))
1650 if (! process_section_p (section
))
1653 datasize
= bfd_get_section_size (section
);
1657 /* Decide which set of relocs to use. Load them if necessary. */
1658 paux
= (struct objdump_disasm_info
*) pinfo
->application_data
;
1659 if (paux
->dynrelbuf
)
1661 rel_pp
= paux
->dynrelbuf
;
1662 rel_count
= paux
->dynrelcount
;
1663 /* Dynamic reloc addresses are absolute, non-dynamic are section
1664 relative. REL_OFFSET specifies the reloc address corresponding
1665 to the start of this section. */
1666 rel_offset
= section
->vma
;
1674 if ((section
->flags
& SEC_RELOC
) != 0
1675 #ifndef DISASSEMBLER_NEEDS_RELOCS
1682 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
1684 bfd_fatal (bfd_get_filename (abfd
));
1688 rel_ppstart
= rel_pp
= xmalloc (relsize
);
1689 rel_count
= bfd_canonicalize_reloc (abfd
, section
, rel_pp
, syms
);
1691 bfd_fatal (bfd_get_filename (abfd
));
1693 /* Sort the relocs by address. */
1694 qsort (rel_pp
, rel_count
, sizeof (arelent
*), compare_relocs
);
1699 rel_ppend
= rel_pp
+ rel_count
;
1701 data
= xmalloc (datasize
);
1703 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
1705 paux
->sec
= section
;
1706 pinfo
->buffer
= data
;
1707 pinfo
->buffer_vma
= section
->vma
;
1708 pinfo
->buffer_length
= datasize
;
1709 pinfo
->section
= section
;
1711 if (start_address
== (bfd_vma
) -1
1712 || start_address
< pinfo
->buffer_vma
)
1715 addr_offset
= start_address
- pinfo
->buffer_vma
;
1717 if (stop_address
== (bfd_vma
) -1)
1718 stop_offset
= datasize
/ opb
;
1721 if (stop_address
< pinfo
->buffer_vma
)
1724 stop_offset
= stop_address
- pinfo
->buffer_vma
;
1725 if (stop_offset
> pinfo
->buffer_length
/ opb
)
1726 stop_offset
= pinfo
->buffer_length
/ opb
;
1729 /* Skip over the relocs belonging to addresses below the
1731 while (rel_pp
< rel_ppend
1732 && (*rel_pp
)->address
< rel_offset
+ addr_offset
)
1735 printf (_("Disassembly of section %s:\n"), section
->name
);
1737 /* Find the nearest symbol forwards from our current position. */
1738 paux
->require_sec
= TRUE
;
1739 sym
= find_symbol_for_address (section
->vma
+ addr_offset
, info
, &place
);
1740 paux
->require_sec
= FALSE
;
1742 /* Disassemble a block of instructions up to the address associated with
1743 the symbol we have just found. Then print the symbol and find the
1744 next symbol on. Repeat until we have disassembled the entire section
1745 or we have reached the end of the address range we are interested in. */
1746 while (addr_offset
< stop_offset
)
1750 unsigned long nextstop_offset
;
1753 addr
= section
->vma
+ addr_offset
;
1755 if (sym
!= NULL
&& bfd_asymbol_value (sym
) <= addr
)
1760 (x
< sorted_symcount
1761 && (bfd_asymbol_value (sorted_syms
[x
]) <= addr
));
1765 pinfo
->symbols
= sorted_syms
+ place
;
1766 pinfo
->num_symbols
= x
- place
;
1770 pinfo
->symbols
= NULL
;
1771 pinfo
->num_symbols
= 0;
1774 if (! prefix_addresses
)
1776 pinfo
->fprintf_func (pinfo
->stream
, "\n");
1777 objdump_print_addr_with_sym (abfd
, section
, sym
, addr
,
1779 pinfo
->fprintf_func (pinfo
->stream
, ":\n");
1782 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
1784 else if (sym
== NULL
)
1788 #define is_valid_next_sym(SYM) \
1789 ((SYM)->section == section \
1790 && (bfd_asymbol_value (SYM) > bfd_asymbol_value (sym)) \
1791 && pinfo->symbol_is_valid (SYM, pinfo))
1793 /* Search forward for the next appropriate symbol in
1794 SECTION. Note that all the symbols are sorted
1795 together into one big array, and that some sections
1796 may have overlapping addresses. */
1797 while (place
< sorted_symcount
1798 && ! is_valid_next_sym (sorted_syms
[place
]))
1801 if (place
>= sorted_symcount
)
1804 nextsym
= sorted_syms
[place
];
1807 if (sym
!= NULL
&& bfd_asymbol_value (sym
) > addr
)
1808 nextstop_offset
= bfd_asymbol_value (sym
) - section
->vma
;
1809 else if (nextsym
== NULL
)
1810 nextstop_offset
= stop_offset
;
1812 nextstop_offset
= bfd_asymbol_value (nextsym
) - section
->vma
;
1814 if (nextstop_offset
> stop_offset
)
1815 nextstop_offset
= stop_offset
;
1817 /* If a symbol is explicitly marked as being an object
1818 rather than a function, just dump the bytes without
1819 disassembling them. */
1822 || bfd_asymbol_value (sym
) > addr
1823 || ((sym
->flags
& BSF_OBJECT
) == 0
1824 && (strstr (bfd_asymbol_name (sym
), "gnu_compiled")
1826 && (strstr (bfd_asymbol_name (sym
), "gcc2_compiled")
1828 || (sym
->flags
& BSF_FUNCTION
) != 0)
1833 disassemble_bytes (pinfo
, paux
->disassemble_fn
, insns
, data
,
1834 addr_offset
, nextstop_offset
,
1835 rel_offset
, &rel_pp
, rel_ppend
);
1837 addr_offset
= nextstop_offset
;
1843 if (rel_ppstart
!= NULL
)
1847 /* Disassemble the contents of an object file. */
1850 disassemble_data (bfd
*abfd
)
1852 struct disassemble_info disasm_info
;
1853 struct objdump_disasm_info aux
;
1857 prev_functionname
= NULL
;
1860 /* We make a copy of syms to sort. We don't want to sort syms
1861 because that will screw up the relocs. */
1862 sorted_symcount
= symcount
? symcount
: dynsymcount
;
1863 sorted_syms
= xmalloc ((sorted_symcount
+ synthcount
) * sizeof (asymbol
*));
1864 memcpy (sorted_syms
, symcount
? syms
: dynsyms
,
1865 sorted_symcount
* sizeof (asymbol
*));
1867 sorted_symcount
= remove_useless_symbols (sorted_syms
, sorted_symcount
);
1869 for (i
= 0; i
< synthcount
; ++i
)
1871 sorted_syms
[sorted_symcount
] = synthsyms
+ i
;
1875 /* Sort the symbols into section and symbol order. */
1876 qsort (sorted_syms
, sorted_symcount
, sizeof (asymbol
*), compare_symbols
);
1878 init_disassemble_info (&disasm_info
, stdout
, (fprintf_ftype
) fprintf
);
1880 disasm_info
.application_data
= (void *) &aux
;
1882 aux
.require_sec
= FALSE
;
1883 aux
.dynrelbuf
= NULL
;
1884 aux
.dynrelcount
= 0;
1885 #ifdef DISASSEMBLER_NEEDS_RELOCS
1889 disasm_info
.print_address_func
= objdump_print_address
;
1890 disasm_info
.symbol_at_address_func
= objdump_symbol_at_address
;
1892 if (machine
!= NULL
)
1894 const bfd_arch_info_type
*info
= bfd_scan_arch (machine
);
1897 fatal (_("Can't use supplied machine %s"), machine
);
1899 abfd
->arch_info
= info
;
1902 if (endian
!= BFD_ENDIAN_UNKNOWN
)
1904 struct bfd_target
*xvec
;
1906 xvec
= xmalloc (sizeof (struct bfd_target
));
1907 memcpy (xvec
, abfd
->xvec
, sizeof (struct bfd_target
));
1908 xvec
->byteorder
= endian
;
1912 /* Use libopcodes to locate a suitable disassembler. */
1913 aux
.disassemble_fn
= disassembler (abfd
);
1914 if (!aux
.disassemble_fn
)
1916 non_fatal (_("Can't disassemble for architecture %s\n"),
1917 bfd_printable_arch_mach (bfd_get_arch (abfd
), 0));
1922 disasm_info
.flavour
= bfd_get_flavour (abfd
);
1923 disasm_info
.arch
= bfd_get_arch (abfd
);
1924 disasm_info
.mach
= bfd_get_mach (abfd
);
1925 disasm_info
.disassembler_options
= disassembler_options
;
1926 disasm_info
.octets_per_byte
= bfd_octets_per_byte (abfd
);
1927 disasm_info
.skip_zeroes
= DEFAULT_SKIP_ZEROES
;
1928 disasm_info
.skip_zeroes_at_end
= DEFAULT_SKIP_ZEROES_AT_END
;
1930 if (bfd_big_endian (abfd
))
1931 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_BIG
;
1932 else if (bfd_little_endian (abfd
))
1933 disasm_info
.display_endian
= disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
1935 /* ??? Aborting here seems too drastic. We could default to big or little
1937 disasm_info
.endian
= BFD_ENDIAN_UNKNOWN
;
1939 /* Allow the target to customize the info structure. */
1940 disassemble_init_for_target (& disasm_info
);
1942 /* Pre-load the dynamic relocs if we are going
1943 to be dumping them along with the disassembly. */
1944 if (dump_dynamic_reloc_info
)
1946 long relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
1949 bfd_fatal (bfd_get_filename (abfd
));
1953 aux
.dynrelbuf
= xmalloc (relsize
);
1954 aux
.dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
,
1957 if (aux
.dynrelcount
< 0)
1958 bfd_fatal (bfd_get_filename (abfd
));
1960 /* Sort the relocs by address. */
1961 qsort (aux
.dynrelbuf
, aux
.dynrelcount
, sizeof (arelent
*),
1966 bfd_map_over_sections (abfd
, disassemble_section
, & disasm_info
);
1968 if (aux
.dynrelbuf
!= NULL
)
1969 free (aux
.dynrelbuf
);
1974 load_debug_section (enum dwarf_section_display_enum debug
, void *file
)
1976 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
1981 /* If it is already loaded, do nothing. */
1982 if (section
->start
!= NULL
)
1985 /* Locate the debug section. */
1986 sec
= bfd_get_section_by_name (abfd
, section
->name
);
1990 section
->address
= bfd_get_section_vma (abfd
, sec
);
1991 section
->size
= bfd_get_section_size (sec
);
1992 section
->start
= xmalloc (section
->size
);
1994 if (is_relocatable
&& debug_displays
[debug
].relocate
)
1995 ret
= bfd_simple_get_relocated_section_contents (abfd
,
2000 ret
= bfd_get_section_contents (abfd
, sec
, section
->start
, 0,
2005 free_debug_section (debug
);
2006 printf (_("\nCan't get contents for section '%s'.\n"),
2014 free_debug_section (enum dwarf_section_display_enum debug
)
2016 struct dwarf_section
*section
= &debug_displays
[debug
].section
;
2018 if (section
->start
== NULL
)
2021 free ((char *) section
->start
);
2022 section
->start
= NULL
;
2023 section
->address
= 0;
2028 dump_dwarf_section (bfd
*abfd
, asection
*section
,
2029 void *arg ATTRIBUTE_UNUSED
)
2031 const char *name
= bfd_get_section_name (abfd
, section
);
2033 enum dwarf_section_display_enum i
;
2035 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
2036 match
= ".debug_info";
2040 for (i
= 0; i
< max
; i
++)
2041 if (strcmp (debug_displays
[i
].section
.name
, match
) == 0)
2043 if (!debug_displays
[i
].eh_frame
)
2045 struct dwarf_section
*sec
= &debug_displays
[i
].section
;
2047 if (load_debug_section (i
, abfd
))
2049 debug_displays
[i
].display (sec
, abfd
);
2051 if (i
!= info
&& i
!= abbrev
)
2052 free_debug_section (i
);
2059 static const char *mach_o_dwarf_sections
[] = {
2060 "LC_SEGMENT.__DWARFA.__debug_abbrev", /* .debug_abbrev */
2061 "LC_SEGMENT.__DWARFA.__debug_aranges", /* .debug_aranges */
2062 "LC_SEGMENT.__DWARFA.__debug_frame", /* .debug_frame */
2063 "LC_SEGMENT.__DWARFA.__debug_info", /* .debug_info */
2064 "LC_SEGMENT.__DWARFA.__debug_line", /* .debug_line */
2065 "LC_SEGMENT.__DWARFA.__debug_pubnames", /* .debug_pubnames */
2066 ".eh_frame", /* .eh_frame */
2067 "LC_SEGMENT.__DWARFA.__debug_macinfo", /* .debug_macinfo */
2068 "LC_SEGMENT.__DWARFA.__debug_str", /* .debug_str */
2069 "LC_SEGMENT.__DWARFA.__debug_loc", /* .debug_loc */
2070 "LC_SEGMENT.__DWARFA.__debug_pubtypes", /* .debug_pubtypes */
2071 "LC_SEGMENT.__DWARFA.__debug_ranges", /* .debug_ranges */
2072 "LC_SEGMENT.__DWARFA.__debug_static_func", /* .debug_static_func */
2073 "LC_SEGMENT.__DWARFA.__debug_static_vars", /* .debug_static_vars */
2074 "LC_SEGMENT.__DWARFA.__debug_types", /* .debug_types */
2075 "LC_SEGMENT.__DWARFA.__debug_weaknames" /* .debug_weaknames */
2078 static const char *generic_dwarf_sections
[max
];
2081 check_mach_o_dwarf (bfd
*abfd
)
2083 static enum bfd_flavour old_flavour
= bfd_target_unknown_flavour
;
2084 enum bfd_flavour current_flavour
= bfd_get_flavour (abfd
);
2085 enum dwarf_section_display_enum i
;
2087 if (generic_dwarf_sections
[0] == NULL
)
2088 for (i
= 0; i
< max
; i
++)
2089 generic_dwarf_sections
[i
] = debug_displays
[i
].section
.name
;
2091 if (old_flavour
!= current_flavour
)
2093 if (current_flavour
== bfd_target_mach_o_flavour
)
2094 for (i
= 0; i
< max
; i
++)
2095 debug_displays
[i
].section
.name
= mach_o_dwarf_sections
[i
];
2096 else if (old_flavour
== bfd_target_mach_o_flavour
)
2097 for (i
= 0; i
< max
; i
++)
2098 debug_displays
[i
].section
.name
= generic_dwarf_sections
[i
];
2100 old_flavour
= current_flavour
;
2104 /* Dump the dwarf debugging information. */
2107 dump_dwarf (bfd
*abfd
)
2109 is_relocatable
= ((abfd
->flags
& (HAS_RELOC
| EXEC_P
| DYNAMIC
))
2112 /* FIXME: bfd_get_arch_size may return -1. We assume that 64bit
2113 targets will return 64. */
2114 eh_addr_size
= bfd_get_arch_size (abfd
) == 64 ? 8 : 4;
2116 if (bfd_big_endian (abfd
))
2117 byte_get
= byte_get_big_endian
;
2118 else if (bfd_little_endian (abfd
))
2119 byte_get
= byte_get_little_endian
;
2123 check_mach_o_dwarf (abfd
);
2125 bfd_map_over_sections (abfd
, dump_dwarf_section
, NULL
);
2127 free_debug_memory ();
2130 /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to
2131 it. Return NULL on failure. */
2134 read_section_stabs (bfd
*abfd
, const char *sect_name
, bfd_size_type
*size_ptr
)
2140 stabsect
= bfd_get_section_by_name (abfd
, sect_name
);
2141 if (stabsect
== NULL
)
2143 printf (_("No %s section present\n\n"), sect_name
);
2147 size
= bfd_section_size (abfd
, stabsect
);
2148 contents
= xmalloc (size
);
2150 if (! bfd_get_section_contents (abfd
, stabsect
, contents
, 0, size
))
2152 non_fatal (_("Reading %s section of %s failed: %s"),
2153 sect_name
, bfd_get_filename (abfd
),
2154 bfd_errmsg (bfd_get_error ()));
2165 /* Stabs entries use a 12 byte format:
2166 4 byte string table index
2168 1 byte stab other field
2169 2 byte stab desc field
2171 FIXME: This will have to change for a 64 bit object format. */
2173 #define STRDXOFF (0)
2175 #define OTHEROFF (5)
2178 #define STABSIZE (12)
2180 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
2181 using string table section STRSECT_NAME (in `strtab'). */
2184 print_section_stabs (bfd
*abfd
,
2185 const char *stabsect_name
,
2186 unsigned *string_offset_ptr
)
2189 unsigned file_string_table_offset
= 0;
2190 unsigned next_file_string_table_offset
= *string_offset_ptr
;
2191 bfd_byte
*stabp
, *stabs_end
;
2194 stabs_end
= stabp
+ stab_size
;
2196 printf (_("Contents of %s section:\n\n"), stabsect_name
);
2197 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
2199 /* Loop through all symbols and print them.
2201 We start the index at -1 because there is a dummy symbol on
2202 the front of stabs-in-{coff,elf} sections that supplies sizes. */
2203 for (i
= -1; stabp
< stabs_end
; stabp
+= STABSIZE
, i
++)
2207 unsigned char type
, other
;
2208 unsigned short desc
;
2211 strx
= bfd_h_get_32 (abfd
, stabp
+ STRDXOFF
);
2212 type
= bfd_h_get_8 (abfd
, stabp
+ TYPEOFF
);
2213 other
= bfd_h_get_8 (abfd
, stabp
+ OTHEROFF
);
2214 desc
= bfd_h_get_16 (abfd
, stabp
+ DESCOFF
);
2215 value
= bfd_h_get_32 (abfd
, stabp
+ VALOFF
);
2217 printf ("\n%-6d ", i
);
2218 /* Either print the stab name, or, if unnamed, print its number
2219 again (makes consistent formatting for tools like awk). */
2220 name
= bfd_get_stab_name (type
);
2222 printf ("%-6s", name
);
2223 else if (type
== N_UNDF
)
2226 printf ("%-6d", type
);
2227 printf (" %-6d %-6d ", other
, desc
);
2228 bfd_printf_vma (abfd
, value
);
2229 printf (" %-6lu", strx
);
2231 /* Symbols with type == 0 (N_UNDF) specify the length of the
2232 string table associated with this file. We use that info
2233 to know how to relocate the *next* file's string table indices. */
2236 file_string_table_offset
= next_file_string_table_offset
;
2237 next_file_string_table_offset
+= value
;
2241 /* Using the (possibly updated) string table offset, print the
2242 string (if any) associated with this symbol. */
2243 if ((strx
+ file_string_table_offset
) < stabstr_size
)
2244 printf (" %s", &strtab
[strx
+ file_string_table_offset
]);
2250 *string_offset_ptr
= next_file_string_table_offset
;
2255 const char * section_name
;
2256 const char * string_section_name
;
2257 unsigned string_offset
;
2262 find_stabs_section (bfd
*abfd
, asection
*section
, void *names
)
2265 stab_section_names
* sought
= (stab_section_names
*) names
;
2267 /* Check for section names for which stabsect_name is a prefix, to
2268 handle .stab.N, etc. */
2269 len
= strlen (sought
->section_name
);
2271 /* If the prefix matches, and the files section name ends with a
2272 nul or a digit, then we match. I.e., we want either an exact
2273 match or a section followed by a number. */
2274 if (strncmp (sought
->section_name
, section
->name
, len
) == 0
2275 && (section
->name
[len
] == 0
2276 || (section
->name
[len
] == '.' && ISDIGIT (section
->name
[len
+ 1]))))
2279 strtab
= read_section_stabs (abfd
, sought
->string_section_name
,
2284 stabs
= (bfd_byte
*) read_section_stabs (abfd
, section
->name
,
2287 print_section_stabs (abfd
, section
->name
, &sought
->string_offset
);
2293 dump_stabs_section (bfd
*abfd
, char *stabsect_name
, char *strsect_name
)
2295 stab_section_names s
;
2297 s
.section_name
= stabsect_name
;
2298 s
.string_section_name
= strsect_name
;
2299 s
.string_offset
= 0;
2301 bfd_map_over_sections (abfd
, find_stabs_section
, & s
);
2307 /* Dump the any sections containing stabs debugging information. */
2310 dump_stabs (bfd
*abfd
)
2312 dump_stabs_section (abfd
, ".stab", ".stabstr");
2313 dump_stabs_section (abfd
, ".stab.excl", ".stab.exclstr");
2314 dump_stabs_section (abfd
, ".stab.index", ".stab.indexstr");
2315 dump_stabs_section (abfd
, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
2319 dump_bfd_header (bfd
*abfd
)
2323 printf (_("architecture: %s, "),
2324 bfd_printable_arch_mach (bfd_get_arch (abfd
),
2325 bfd_get_mach (abfd
)));
2326 printf (_("flags 0x%08x:\n"), abfd
->flags
);
2328 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
2329 PF (HAS_RELOC
, "HAS_RELOC");
2330 PF (EXEC_P
, "EXEC_P");
2331 PF (HAS_LINENO
, "HAS_LINENO");
2332 PF (HAS_DEBUG
, "HAS_DEBUG");
2333 PF (HAS_SYMS
, "HAS_SYMS");
2334 PF (HAS_LOCALS
, "HAS_LOCALS");
2335 PF (DYNAMIC
, "DYNAMIC");
2336 PF (WP_TEXT
, "WP_TEXT");
2337 PF (D_PAGED
, "D_PAGED");
2338 PF (BFD_IS_RELAXABLE
, "BFD_IS_RELAXABLE");
2339 PF (HAS_LOAD_PAGE
, "HAS_LOAD_PAGE");
2340 printf (_("\nstart address 0x"));
2341 bfd_printf_vma (abfd
, abfd
->start_address
);
2347 dump_bfd_private_header (bfd
*abfd
)
2349 bfd_print_private_bfd_data (abfd
, stdout
);
2353 /* Display a section in hexadecimal format with associated characters.
2354 Each line prefixed by the zero padded address. */
2357 dump_section (bfd
*abfd
, asection
*section
, void *dummy ATTRIBUTE_UNUSED
)
2360 bfd_size_type datasize
;
2361 bfd_size_type addr_offset
;
2362 bfd_size_type start_offset
;
2363 bfd_size_type stop_offset
;
2364 unsigned int opb
= bfd_octets_per_byte (abfd
);
2365 /* Bytes per line. */
2366 const int onaline
= 16;
2371 if ((section
->flags
& SEC_HAS_CONTENTS
) == 0)
2374 if (! process_section_p (section
))
2377 if ((datasize
= bfd_section_size (abfd
, section
)) == 0)
2380 printf (_("Contents of section %s:\n"), section
->name
);
2382 data
= xmalloc (datasize
);
2384 bfd_get_section_contents (abfd
, section
, data
, 0, datasize
);
2386 /* Compute the address range to display. */
2387 if (start_address
== (bfd_vma
) -1
2388 || start_address
< section
->vma
)
2391 start_offset
= start_address
- section
->vma
;
2393 if (stop_address
== (bfd_vma
) -1)
2394 stop_offset
= datasize
/ opb
;
2397 if (stop_address
< section
->vma
)
2400 stop_offset
= stop_address
- section
->vma
;
2402 if (stop_offset
> datasize
/ opb
)
2403 stop_offset
= datasize
/ opb
;
2408 bfd_sprintf_vma (abfd
, buf
, start_offset
+ section
->vma
);
2409 if (strlen (buf
) >= sizeof (buf
))
2413 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
2415 count
= strlen (buf
) - count
;
2419 bfd_sprintf_vma (abfd
, buf
, stop_offset
+ section
->vma
- 1);
2420 if (strlen (buf
) >= sizeof (buf
))
2424 while (buf
[count
] == '0' && buf
[count
+1] != '\0')
2426 count
= strlen (buf
) - count
;
2430 for (addr_offset
= start_offset
;
2431 addr_offset
< stop_offset
; addr_offset
+= onaline
/ opb
)
2435 bfd_sprintf_vma (abfd
, buf
, (addr_offset
+ section
->vma
));
2436 count
= strlen (buf
);
2437 if ((size_t) count
>= sizeof (buf
))
2441 while (count
< width
)
2446 fputs (buf
+ count
- width
, stdout
);
2449 for (j
= addr_offset
* opb
;
2450 j
< addr_offset
* opb
+ onaline
; j
++)
2452 if (j
< stop_offset
* opb
)
2453 printf ("%02x", (unsigned) (data
[j
]));
2461 for (j
= addr_offset
* opb
;
2462 j
< addr_offset
* opb
+ onaline
; j
++)
2464 if (j
>= stop_offset
* opb
)
2467 printf ("%c", ISPRINT (data
[j
]) ? data
[j
] : '.');
2474 /* Actually display the various requested regions. */
2477 dump_data (bfd
*abfd
)
2479 bfd_map_over_sections (abfd
, dump_section
, NULL
);
2482 /* Should perhaps share code and display with nm? */
2485 dump_symbols (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_boolean dynamic
)
2495 printf ("DYNAMIC SYMBOL TABLE:\n");
2501 printf ("SYMBOL TABLE:\n");
2505 printf (_("no symbols\n"));
2507 for (count
= 0; count
< max
; count
++)
2511 if (*current
== NULL
)
2512 printf (_("no information for symbol number %ld\n"), count
);
2514 else if ((cur_bfd
= bfd_asymbol_bfd (*current
)) == NULL
)
2515 printf (_("could not determine the type of symbol number %ld\n"),
2518 else if (process_section_p ((* current
)->section
)
2519 && (dump_special_syms
2520 || !bfd_is_target_special_symbol (cur_bfd
, *current
)))
2522 const char *name
= (*current
)->name
;
2524 if (do_demangle
&& name
!= NULL
&& *name
!= '\0')
2528 /* If we want to demangle the name, we demangle it
2529 here, and temporarily clobber it while calling
2530 bfd_print_symbol. FIXME: This is a gross hack. */
2531 alloc
= demangle (cur_bfd
, name
);
2532 (*current
)->name
= alloc
;
2533 bfd_print_symbol (cur_bfd
, stdout
, *current
,
2534 bfd_print_symbol_all
);
2535 (*current
)->name
= name
;
2539 bfd_print_symbol (cur_bfd
, stdout
, *current
,
2540 bfd_print_symbol_all
);
2550 dump_reloc_set (bfd
*abfd
, asection
*sec
, arelent
**relpp
, long relcount
)
2553 char *last_filename
, *last_functionname
;
2554 unsigned int last_line
;
2556 /* Get column headers lined up reasonably. */
2564 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
2565 width
= strlen (buf
) - 7;
2567 printf ("OFFSET %*s TYPE %*s VALUE \n", width
, "", 12, "");
2570 last_filename
= NULL
;
2571 last_functionname
= NULL
;
2574 for (p
= relpp
; relcount
&& *p
!= NULL
; p
++, relcount
--)
2577 const char *filename
, *functionname
;
2579 const char *sym_name
;
2580 const char *section_name
;
2582 if (start_address
!= (bfd_vma
) -1
2583 && q
->address
< start_address
)
2585 if (stop_address
!= (bfd_vma
) -1
2586 && q
->address
> stop_address
)
2589 if (with_line_numbers
2591 && bfd_find_nearest_line (abfd
, sec
, syms
, q
->address
,
2592 &filename
, &functionname
, &line
))
2594 if (functionname
!= NULL
2595 && (last_functionname
== NULL
2596 || strcmp (functionname
, last_functionname
) != 0))
2598 printf ("%s():\n", functionname
);
2599 if (last_functionname
!= NULL
)
2600 free (last_functionname
);
2601 last_functionname
= xstrdup (functionname
);
2605 && (line
!= last_line
2606 || (filename
!= NULL
2607 && last_filename
!= NULL
2608 && strcmp (filename
, last_filename
) != 0)))
2610 printf ("%s:%u\n", filename
== NULL
? "???" : filename
, line
);
2612 if (last_filename
!= NULL
)
2613 free (last_filename
);
2614 if (filename
== NULL
)
2615 last_filename
= NULL
;
2617 last_filename
= xstrdup (filename
);
2621 if (q
->sym_ptr_ptr
&& *q
->sym_ptr_ptr
)
2623 sym_name
= (*(q
->sym_ptr_ptr
))->name
;
2624 section_name
= (*(q
->sym_ptr_ptr
))->section
->name
;
2629 section_name
= NULL
;
2632 bfd_printf_vma (abfd
, q
->address
);
2633 if (q
->howto
== NULL
)
2634 printf (" *unknown* ");
2635 else if (q
->howto
->name
)
2636 printf (" %-16s ", q
->howto
->name
);
2638 printf (" %-16d ", q
->howto
->type
);
2640 objdump_print_symname (abfd
, NULL
, *q
->sym_ptr_ptr
);
2643 if (section_name
== NULL
)
2644 section_name
= "*unknown*";
2645 printf ("[%s]", section_name
);
2651 bfd_printf_vma (abfd
, q
->addend
);
2659 dump_relocs_in_section (bfd
*abfd
,
2661 void *dummy ATTRIBUTE_UNUSED
)
2667 if ( bfd_is_abs_section (section
)
2668 || bfd_is_und_section (section
)
2669 || bfd_is_com_section (section
)
2670 || (! process_section_p (section
))
2671 || ((section
->flags
& SEC_RELOC
) == 0))
2674 relsize
= bfd_get_reloc_upper_bound (abfd
, section
);
2676 bfd_fatal (bfd_get_filename (abfd
));
2678 printf ("RELOCATION RECORDS FOR [%s]:", section
->name
);
2682 printf (" (none)\n\n");
2686 relpp
= xmalloc (relsize
);
2687 relcount
= bfd_canonicalize_reloc (abfd
, section
, relpp
, syms
);
2690 bfd_fatal (bfd_get_filename (abfd
));
2691 else if (relcount
== 0)
2692 printf (" (none)\n\n");
2696 dump_reloc_set (abfd
, section
, relpp
, relcount
);
2703 dump_relocs (bfd
*abfd
)
2705 bfd_map_over_sections (abfd
, dump_relocs_in_section
, NULL
);
2709 dump_dynamic_relocs (bfd
*abfd
)
2715 relsize
= bfd_get_dynamic_reloc_upper_bound (abfd
);
2717 bfd_fatal (bfd_get_filename (abfd
));
2719 printf ("DYNAMIC RELOCATION RECORDS");
2722 printf (" (none)\n\n");
2725 relpp
= xmalloc (relsize
);
2726 relcount
= bfd_canonicalize_dynamic_reloc (abfd
, relpp
, dynsyms
);
2729 bfd_fatal (bfd_get_filename (abfd
));
2730 else if (relcount
== 0)
2731 printf (" (none)\n\n");
2735 dump_reloc_set (abfd
, NULL
, relpp
, relcount
);
2742 /* Creates a table of paths, to search for source files. */
2745 add_include_path (const char *path
)
2749 include_path_count
++;
2750 include_paths
= xrealloc (include_paths
,
2751 include_path_count
* sizeof (*include_paths
));
2752 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2753 if (path
[1] == ':' && path
[2] == 0)
2754 path
= concat (path
, ".", (const char *) 0);
2756 include_paths
[include_path_count
- 1] = path
;
2760 adjust_addresses (bfd
*abfd ATTRIBUTE_UNUSED
,
2764 if ((section
->flags
& SEC_DEBUGGING
) == 0)
2766 bfd_boolean
*has_reloc_p
= (bfd_boolean
*) arg
;
2767 section
->vma
+= adjust_section_vma
;
2769 section
->lma
+= adjust_section_vma
;
2773 /* Dump selected contents of ABFD. */
2776 dump_bfd (bfd
*abfd
)
2778 /* If we are adjusting section VMA's, change them all now. Changing
2779 the BFD information is a hack. However, we must do it, or
2780 bfd_find_nearest_line will not do the right thing. */
2781 if (adjust_section_vma
!= 0)
2783 bfd_boolean has_reloc
= (abfd
->flags
& HAS_RELOC
);
2784 bfd_map_over_sections (abfd
, adjust_addresses
, &has_reloc
);
2787 if (! dump_debugging_tags
)
2788 printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd
),
2791 print_arelt_descr (stdout
, abfd
, TRUE
);
2792 if (dump_file_header
)
2793 dump_bfd_header (abfd
);
2794 if (dump_private_headers
)
2795 dump_bfd_private_header (abfd
);
2796 if (! dump_debugging_tags
)
2798 if (dump_section_headers
)
2799 dump_headers (abfd
);
2805 || dump_dwarf_section_info
)
2806 syms
= slurp_symtab (abfd
);
2807 if (dump_dynamic_symtab
|| dump_dynamic_reloc_info
2808 || (disassemble
&& bfd_get_dynamic_symtab_upper_bound (abfd
) > 0))
2809 dynsyms
= slurp_dynamic_symtab (abfd
);
2812 synthcount
= bfd_get_synthetic_symtab (abfd
, symcount
, syms
,
2813 dynsymcount
, dynsyms
, &synthsyms
);
2819 dump_symbols (abfd
, FALSE
);
2820 if (dump_dynamic_symtab
)
2821 dump_symbols (abfd
, TRUE
);
2822 if (dump_dwarf_section_info
)
2824 if (dump_stab_section_info
)
2826 if (dump_reloc_info
&& ! disassemble
)
2828 if (dump_dynamic_reloc_info
&& ! disassemble
)
2829 dump_dynamic_relocs (abfd
);
2830 if (dump_section_contents
)
2833 disassemble_data (abfd
);
2839 dhandle
= read_debugging_info (abfd
, syms
, symcount
);
2840 if (dhandle
!= NULL
)
2842 if (! print_debugging_info (stdout
, dhandle
, abfd
, syms
, demangle
,
2843 dump_debugging_tags
? TRUE
: FALSE
))
2845 non_fatal (_("%s: printing debugging information failed"),
2846 bfd_get_filename (abfd
));
2876 display_bfd (bfd
*abfd
)
2880 if (bfd_check_format_matches (abfd
, bfd_object
, &matching
))
2886 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
2888 nonfatal (bfd_get_filename (abfd
));
2889 list_matching_formats (matching
);
2894 if (bfd_get_error () != bfd_error_file_not_recognized
)
2896 nonfatal (bfd_get_filename (abfd
));
2900 if (bfd_check_format_matches (abfd
, bfd_core
, &matching
))
2906 nonfatal (bfd_get_filename (abfd
));
2908 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
2910 list_matching_formats (matching
);
2916 display_file (char *filename
, char *target
)
2921 if (get_file_size (filename
) < 1)
2924 file
= bfd_openr (filename
, target
);
2927 nonfatal (filename
);
2931 /* If the file is an archive, process all of its elements. */
2932 if (bfd_check_format (file
, bfd_archive
))
2934 bfd
*last_arfile
= NULL
;
2936 printf (_("In archive %s:\n"), bfd_get_filename (file
));
2939 bfd_set_error (bfd_error_no_error
);
2941 arfile
= bfd_openr_next_archived_file (file
, arfile
);
2944 if (bfd_get_error () != bfd_error_no_more_archived_files
)
2945 nonfatal (bfd_get_filename (file
));
2949 display_bfd (arfile
);
2951 if (last_arfile
!= NULL
)
2952 bfd_close (last_arfile
);
2953 last_arfile
= arfile
;
2956 if (last_arfile
!= NULL
)
2957 bfd_close (last_arfile
);
2966 main (int argc
, char **argv
)
2969 char *target
= default_target
;
2970 bfd_boolean seenflag
= FALSE
;
2972 #if defined (HAVE_SETLOCALE)
2973 #if defined (HAVE_LC_MESSAGES)
2974 setlocale (LC_MESSAGES
, "");
2976 setlocale (LC_CTYPE
, "");
2979 bindtextdomain (PACKAGE
, LOCALEDIR
);
2980 textdomain (PACKAGE
);
2982 program_name
= *argv
;
2983 xmalloc_set_program_name (program_name
);
2985 START_PROGRESS (program_name
, 0);
2987 expandargv (&argc
, &argv
);
2990 set_default_bfd_target ();
2992 while ((c
= getopt_long (argc
, argv
, "pib:m:M:VvCdDlfaHhrRtTxsSI:j:wE:zgeGW",
2993 long_options
, (int *) 0))
2999 break; /* We've been given a long option. */
3004 if (disassembler_options
)
3005 /* Ignore potential memory leak for now. */
3006 disassembler_options
= concat (disassembler_options
, ",",
3009 disassembler_options
= optarg
;
3012 if (only_used
== only_size
)
3015 only
= xrealloc (only
, only_size
* sizeof (char *));
3017 only
[only_used
++] = optarg
;
3020 with_line_numbers
= TRUE
;
3029 enum demangling_styles style
;
3031 style
= cplus_demangle_name_to_style (optarg
);
3032 if (style
== unknown_demangling
)
3033 fatal (_("unknown demangling style `%s'"),
3036 cplus_demangle_set_style (style
);
3042 case OPTION_ADJUST_VMA
:
3043 adjust_section_vma
= parse_vma (optarg
, "--adjust-vma");
3045 case OPTION_START_ADDRESS
:
3046 start_address
= parse_vma (optarg
, "--start-address");
3048 case OPTION_STOP_ADDRESS
:
3049 stop_address
= parse_vma (optarg
, "--stop-address");
3052 if (strcmp (optarg
, "B") == 0)
3053 endian
= BFD_ENDIAN_BIG
;
3054 else if (strcmp (optarg
, "L") == 0)
3055 endian
= BFD_ENDIAN_LITTLE
;
3058 non_fatal (_("unrecognized -E option"));
3063 if (strncmp (optarg
, "big", strlen (optarg
)) == 0)
3064 endian
= BFD_ENDIAN_BIG
;
3065 else if (strncmp (optarg
, "little", strlen (optarg
)) == 0)
3066 endian
= BFD_ENDIAN_LITTLE
;
3069 non_fatal (_("unrecognized --endian type `%s'"), optarg
);
3075 dump_file_header
= TRUE
;
3079 formats_info
= TRUE
;
3083 add_include_path (optarg
);
3086 dump_private_headers
= TRUE
;
3090 dump_private_headers
= TRUE
;
3092 dump_reloc_info
= TRUE
;
3093 dump_file_header
= TRUE
;
3094 dump_ar_hdrs
= TRUE
;
3095 dump_section_headers
= TRUE
;
3103 dump_dynamic_symtab
= TRUE
;
3111 disassemble_zeroes
= TRUE
;
3115 disassemble_all
= TRUE
;
3120 with_source_code
= TRUE
;
3129 dump_debugging_tags
= 1;
3134 dump_dwarf_section_info
= TRUE
;
3137 do_debug_abbrevs
= 1;
3139 do_debug_pubnames
= 1;
3140 do_debug_aranges
= 1;
3141 do_debug_ranges
= 1;
3142 do_debug_frames
= 1;
3143 do_debug_macinfo
= 1;
3148 dump_stab_section_info
= TRUE
;
3152 dump_section_contents
= TRUE
;
3156 dump_reloc_info
= TRUE
;
3160 dump_dynamic_reloc_info
= TRUE
;
3164 dump_ar_hdrs
= TRUE
;
3168 dump_section_headers
= TRUE
;
3176 show_version
= TRUE
;
3186 print_version ("objdump");
3192 exit_status
= display_info ();
3196 display_file ("a.out", target
);
3198 for (; optind
< argc
;)
3199 display_file (argv
[optind
++], target
);
3202 END_PROGRESS (program_name
);