]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* objdump.c -- dump information about an object file. |
8c2bc687 | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
9210d879 | 3 | 2000, 2001, 2002, 2003, 2004, 2005 |
252b5132 RH |
4 | Free Software Foundation, Inc. |
5 | ||
b5e2a4f3 | 6 | This file is part of GNU Binutils. |
252b5132 | 7 | |
b5e2a4f3 NC |
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) | |
11 | any later version. | |
252b5132 | 12 | |
b5e2a4f3 NC |
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. | |
252b5132 | 17 | |
b5e2a4f3 NC |
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 | |
b43b5d5f | 20 | Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 | 21 | |
155e0d23 NC |
22 | /* Objdump overview. |
23 | ||
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. | |
28 | ||
29 | The flow of execution is as follows: | |
30 | ||
31 | 1. Command line arguments are checked for control switches and the | |
32 | information to be displayed is selected. | |
33 | ||
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. | |
37 | ||
50c2245b | 38 | 3. The file's target architecture and binary file format are determined |
155e0d23 NC |
39 | by bfd_check_format(). If they are recognised, then dump_bfd() is |
40 | called. | |
41 | ||
50c2245b KH |
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 | |
aaad4cf3 | 44 | a disassembly has been requested. |
155e0d23 NC |
45 | |
46 | When disassembling the code loops through blocks of instructions bounded | |
50c2245b | 47 | by symbols, calling disassemble_bytes() on each block. The actual |
155e0d23 NC |
48 | disassembling is done by the libopcodes library, via a function pointer |
49 | supplied by the disassembler() function. */ | |
50 | ||
252b5132 | 51 | #include "bfd.h" |
6e1a7e9a | 52 | #include "bfdver.h" |
252b5132 RH |
53 | #include "progress.h" |
54 | #include "bucomm.h" | |
365544c3 | 55 | #include "dwarf.h" |
a6637ec0 | 56 | #include "budemang.h" |
d7a283d4 | 57 | #include "getopt.h" |
3882b010 | 58 | #include "safe-ctype.h" |
252b5132 RH |
59 | #include "dis-asm.h" |
60 | #include "libiberty.h" | |
61 | #include "demangle.h" | |
62 | #include "debug.h" | |
63 | #include "budbg.h" | |
64 | ||
252b5132 RH |
65 | /* Internal headers for the ELF .stab-dump code - sorry. */ |
66 | #define BYTES_IN_WORD 32 | |
67 | #include "aout/aout64.h" | |
68 | ||
398ee8f1 | 69 | #if !HAVE_DECL_FPRINTF |
92c2346c | 70 | /* This is needed by init_disassemble_info(). */ |
fd7bb956 | 71 | extern int fprintf (FILE *, const char *, ...); |
252b5132 RH |
72 | #endif |
73 | ||
75cd796a ILT |
74 | /* Exit status. */ |
75 | static int exit_status = 0; | |
76 | ||
98a91d6a | 77 | static char *default_target = NULL; /* Default at runtime. */ |
252b5132 | 78 | |
3b9ad1cc AM |
79 | /* The following variables are set based on arguments passed on the |
80 | command line. */ | |
98a91d6a | 81 | static int show_version = 0; /* Show the version number. */ |
252b5132 RH |
82 | static int dump_section_contents; /* -s */ |
83 | static int dump_section_headers; /* -h */ | |
b34976b6 | 84 | static bfd_boolean dump_file_header; /* -f */ |
252b5132 RH |
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 */ | |
b34976b6 | 93 | static bfd_boolean with_source_code; /* -S */ |
252b5132 | 94 | static int show_raw_insn; /* --show-raw-insn */ |
365544c3 | 95 | static int dump_dwarf_section_info; /* --dwarf */ |
252b5132 RH |
96 | static int dump_stab_section_info; /* --stabs */ |
97 | static int do_demangle; /* -C, --demangle */ | |
b34976b6 AM |
98 | static bfd_boolean disassemble; /* -d */ |
99 | static bfd_boolean disassemble_all; /* -D */ | |
252b5132 | 100 | static int disassemble_zeroes; /* --disassemble-zeroes */ |
b34976b6 | 101 | static bfd_boolean formats_info; /* -i */ |
252b5132 RH |
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 */ | |
51cdc6e0 | 106 | static int dump_debugging_tags; /* --debugging-tags */ |
3c9458e9 | 107 | static int dump_special_syms = 0; /* --special-syms */ |
252b5132 | 108 | static bfd_vma adjust_section_vma = 0; /* --adjust-vma */ |
f1563258 | 109 | static int file_start_context = 0; /* --file-start-context */ |
252b5132 | 110 | |
155e0d23 NC |
111 | /* Pointer to an array of section names provided by |
112 | one or more "-j secname" command line options. */ | |
113 | static char **only; | |
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; | |
118 | ||
43ac9881 AM |
119 | /* Variables for handling include file path table. */ |
120 | static const char **include_paths; | |
121 | static int include_path_count; | |
122 | ||
3b9ad1cc AM |
123 | /* Extra info to pass to the section disassembler and address printing |
124 | function. */ | |
026df7c5 NC |
125 | struct objdump_disasm_info |
126 | { | |
155e0d23 NC |
127 | bfd * abfd; |
128 | asection * sec; | |
129 | bfd_boolean require_sec; | |
130 | arelent ** dynrelbuf; | |
131 | long dynrelcount; | |
132 | disassembler_ftype disassemble_fn; | |
ce04548a NC |
133 | #ifdef DISASSEMBLER_NEEDS_RELOCS |
134 | arelent * reloc; | |
135 | #endif | |
252b5132 RH |
136 | }; |
137 | ||
138 | /* Architecture to disassemble for, or default if NULL. */ | |
d3ba0551 | 139 | static char *machine = NULL; |
252b5132 | 140 | |
dd92f639 | 141 | /* Target specific options to the disassembler. */ |
d3ba0551 | 142 | static char *disassembler_options = NULL; |
dd92f639 | 143 | |
252b5132 RH |
144 | /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */ |
145 | static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN; | |
146 | ||
147 | /* The symbol table. */ | |
148 | static asymbol **syms; | |
149 | ||
150 | /* Number of symbols in `syms'. */ | |
151 | static long symcount = 0; | |
152 | ||
153 | /* The sorted symbol table. */ | |
154 | static asymbol **sorted_syms; | |
155 | ||
156 | /* Number of symbols in `sorted_syms'. */ | |
157 | static long sorted_symcount = 0; | |
158 | ||
159 | /* The dynamic symbol table. */ | |
160 | static asymbol **dynsyms; | |
161 | ||
4c45e5c9 JJ |
162 | /* The synthetic symbol table. */ |
163 | static asymbol *synthsyms; | |
164 | static long synthcount = 0; | |
165 | ||
252b5132 RH |
166 | /* Number of symbols in `dynsyms'. */ |
167 | static long dynsymcount = 0; | |
168 | ||
98a91d6a NC |
169 | static bfd_byte *stabs; |
170 | static bfd_size_type stab_size; | |
171 | ||
172 | static char *strtab; | |
173 | static bfd_size_type stabstr_size; | |
252b5132 RH |
174 | \f |
175 | static void | |
46dca2e0 | 176 | usage (FILE *stream, int status) |
252b5132 | 177 | { |
8b53311e NC |
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")); | |
252b5132 | 181 | fprintf (stream, _("\ |
86d65c94 MK |
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\ | |
51cdc6e0 | 192 | -e, --debugging-tags Display debug information using ctags style\n\ |
86d65c94 | 193 | -G, --stabs Display (in raw form) any STABS info in the file\n\ |
365544c3 | 194 | -W, --dwarf Display DWARF info in the file\n\ |
86d65c94 MK |
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\ | |
07012eee | 199 | @<file> Read options from <file>\n\ |
8b53311e | 200 | -v, --version Display this program's version number\n\ |
86d65c94 MK |
201 | -i, --info List object formats and architectures supported\n\ |
202 | -H, --help Display this information\n\ | |
1dada9c5 NC |
203 | ")); |
204 | if (status != 2) | |
205 | { | |
206 | fprintf (stream, _("\n The following switches are optional:\n")); | |
207 | fprintf (stream, _("\ | |
86d65c94 MK |
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\ | |
1dada9c5 NC |
212 | -EB --endian=big Assume big endian format when disassembling\n\ |
213 | -EL --endian=little Assume little endian format when disassembling\n\ | |
f1563258 | 214 | --file-start-context Include context from start of file (with -S)\n\ |
43ac9881 | 215 | -I, --include=DIR Add DIR to search list for source files\n\ |
86d65c94 | 216 | -l, --line-numbers Include line numbers and filenames in output\n\ |
28c309a2 | 217 | -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\ |
f0c8c24a NC |
218 | The STYLE, if specified, can be `auto', `gnu',\n\ |
219 | `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ | |
220 | or `gnat'\n\ | |
86d65c94 MK |
221 | -w, --wide Format output for more than 80 columns\n\ |
222 | -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\ | |
f0c8c24a NC |
223 | --start-address=ADDR Only process data whose address is >= ADDR\n\ |
224 | --stop-address=ADDR Only process data whose address is <= ADDR\n\ | |
1dada9c5 NC |
225 | --prefix-addresses Print complete address alongside disassembly\n\ |
226 | --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\ | |
86d65c94 | 227 | --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\ |
3c9458e9 | 228 | --special-syms Include special symbols in symbol dumps\n\ |
1dada9c5 NC |
229 | \n")); |
230 | list_supported_targets (program_name, stream); | |
2f83960e | 231 | list_supported_architectures (program_name, stream); |
86d65c94 | 232 | |
94470b23 | 233 | disassembler_usage (stream); |
1dada9c5 | 234 | } |
252b5132 | 235 | if (status == 0) |
86d65c94 | 236 | fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO); |
252b5132 RH |
237 | exit (status); |
238 | } | |
239 | ||
240 | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ | |
46dca2e0 NC |
241 | enum option_values |
242 | { | |
243 | OPTION_ENDIAN=150, | |
244 | OPTION_START_ADDRESS, | |
245 | OPTION_STOP_ADDRESS, | |
246 | OPTION_ADJUST_VMA | |
247 | }; | |
252b5132 RH |
248 | |
249 | static struct option long_options[]= | |
250 | { | |
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'}, | |
1dada9c5 | 256 | {"debugging", no_argument, NULL, 'g'}, |
51cdc6e0 | 257 | {"debugging-tags", no_argument, NULL, 'e'}, |
28c309a2 | 258 | {"demangle", optional_argument, NULL, 'C'}, |
252b5132 RH |
259 | {"disassemble", no_argument, NULL, 'd'}, |
260 | {"disassemble-all", no_argument, NULL, 'D'}, | |
dd92f639 | 261 | {"disassembler-options", required_argument, NULL, 'M'}, |
1dada9c5 | 262 | {"disassemble-zeroes", no_argument, NULL, 'z'}, |
252b5132 RH |
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'}, | |
f1563258 | 267 | {"file-start-context", no_argument, &file_start_context, 1}, |
252b5132 RH |
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'}, | |
3c9458e9 | 280 | {"special-syms", no_argument, &dump_special_syms, 1}, |
43ac9881 | 281 | {"include", required_argument, NULL, 'I'}, |
365544c3 | 282 | {"dwarf", no_argument, NULL, 'W'}, |
1dada9c5 | 283 | {"stabs", no_argument, NULL, 'G'}, |
252b5132 RH |
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'}, | |
1dada9c5 NC |
288 | {"version", no_argument, NULL, 'V'}, |
289 | {"wide", no_argument, NULL, 'w'}, | |
252b5132 RH |
290 | {0, no_argument, 0, 0} |
291 | }; | |
292 | \f | |
293 | static void | |
46dca2e0 | 294 | nonfatal (const char *msg) |
75cd796a ILT |
295 | { |
296 | bfd_nonfatal (msg); | |
297 | exit_status = 1; | |
298 | } | |
299 | \f | |
300 | static void | |
ebe372c1 | 301 | dump_section_header (bfd *abfd, asection *section, |
46dca2e0 | 302 | void *ignored ATTRIBUTE_UNUSED) |
252b5132 RH |
303 | { |
304 | char *comma = ""; | |
f6af82bd | 305 | unsigned int opb = bfd_octets_per_byte (abfd); |
252b5132 | 306 | |
3bee8bcd L |
307 | /* Ignore linker created section. See elfNN_ia64_object_p in |
308 | bfd/elfxx-ia64.c. */ | |
309 | if (section->flags & SEC_LINKER_CREATED) | |
310 | return; | |
311 | ||
252b5132 RH |
312 | printf ("%3d %-13s %08lx ", section->index, |
313 | bfd_get_section_name (abfd, section), | |
940b2b78 | 314 | (unsigned long) bfd_section_size (abfd, section) / opb); |
d8180c76 | 315 | bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section)); |
252b5132 | 316 | printf (" "); |
d8180c76 | 317 | bfd_printf_vma (abfd, section->lma); |
e59b4dfb | 318 | printf (" %08lx 2**%u", (unsigned long) section->filepos, |
252b5132 RH |
319 | bfd_get_section_alignment (abfd, section)); |
320 | if (! wide_output) | |
321 | printf ("\n "); | |
322 | printf (" "); | |
323 | ||
324 | #define PF(x, y) \ | |
325 | if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; } | |
326 | ||
327 | PF (SEC_HAS_CONTENTS, "CONTENTS"); | |
328 | PF (SEC_ALLOC, "ALLOC"); | |
329 | PF (SEC_CONSTRUCTOR, "CONSTRUCTOR"); | |
252b5132 RH |
330 | PF (SEC_LOAD, "LOAD"); |
331 | PF (SEC_RELOC, "RELOC"); | |
252b5132 RH |
332 | PF (SEC_READONLY, "READONLY"); |
333 | PF (SEC_CODE, "CODE"); | |
334 | PF (SEC_DATA, "DATA"); | |
335 | PF (SEC_ROM, "ROM"); | |
336 | PF (SEC_DEBUGGING, "DEBUGGING"); | |
337 | PF (SEC_NEVER_LOAD, "NEVER_LOAD"); | |
338 | PF (SEC_EXCLUDE, "EXCLUDE"); | |
339 | PF (SEC_SORT_ENTRIES, "SORT_ENTRIES"); | |
ebe372c1 L |
340 | if (bfd_get_arch (abfd) == bfd_arch_tic54x) |
341 | { | |
342 | PF (SEC_TIC54X_BLOCK, "BLOCK"); | |
343 | PF (SEC_TIC54X_CLINK, "CLINK"); | |
344 | } | |
24c411ed | 345 | PF (SEC_SMALL_DATA, "SMALL_DATA"); |
ebe372c1 L |
346 | if (bfd_get_flavour (abfd) == bfd_target_coff_flavour) |
347 | PF (SEC_COFF_SHARED, "SHARED"); | |
13ae64f3 | 348 | PF (SEC_THREAD_LOCAL, "THREAD_LOCAL"); |
64c1196b | 349 | PF (SEC_GROUP, "GROUP"); |
252b5132 RH |
350 | |
351 | if ((section->flags & SEC_LINK_ONCE) != 0) | |
352 | { | |
353 | const char *ls; | |
082b7297 | 354 | struct coff_comdat_info *comdat; |
252b5132 RH |
355 | |
356 | switch (section->flags & SEC_LINK_DUPLICATES) | |
357 | { | |
358 | default: | |
359 | abort (); | |
360 | case SEC_LINK_DUPLICATES_DISCARD: | |
361 | ls = "LINK_ONCE_DISCARD"; | |
362 | break; | |
363 | case SEC_LINK_DUPLICATES_ONE_ONLY: | |
364 | ls = "LINK_ONCE_ONE_ONLY"; | |
365 | break; | |
366 | case SEC_LINK_DUPLICATES_SAME_SIZE: | |
367 | ls = "LINK_ONCE_SAME_SIZE"; | |
368 | break; | |
369 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: | |
370 | ls = "LINK_ONCE_SAME_CONTENTS"; | |
371 | break; | |
372 | } | |
373 | printf ("%s%s", comma, ls); | |
deecf979 | 374 | |
082b7297 L |
375 | comdat = bfd_coff_get_comdat_section (abfd, section); |
376 | if (comdat != NULL) | |
377 | printf (" (COMDAT %s %ld)", comdat->name, comdat->symbol); | |
deecf979 | 378 | |
252b5132 RH |
379 | comma = ", "; |
380 | } | |
381 | ||
382 | printf ("\n"); | |
383 | #undef PF | |
384 | } | |
385 | ||
386 | static void | |
46dca2e0 | 387 | dump_headers (bfd *abfd) |
252b5132 RH |
388 | { |
389 | printf (_("Sections:\n")); | |
8bea4d5c | 390 | |
252b5132 | 391 | #ifndef BFD64 |
8bea4d5c | 392 | printf (_("Idx Name Size VMA LMA File off Algn")); |
252b5132 | 393 | #else |
21611032 TS |
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")); | |
397 | else | |
398 | printf (_("Idx Name Size VMA LMA File off Algn")); | |
252b5132 | 399 | #endif |
8bea4d5c ILT |
400 | |
401 | if (wide_output) | |
402 | printf (_(" Flags")); | |
026df7c5 NC |
403 | if (abfd->flags & HAS_LOAD_PAGE) |
404 | printf (_(" Pg")); | |
8bea4d5c ILT |
405 | printf ("\n"); |
406 | ||
46dca2e0 | 407 | bfd_map_over_sections (abfd, dump_section_header, NULL); |
252b5132 RH |
408 | } |
409 | \f | |
410 | static asymbol ** | |
46dca2e0 | 411 | slurp_symtab (bfd *abfd) |
252b5132 | 412 | { |
d3ba0551 | 413 | asymbol **sy = NULL; |
252b5132 RH |
414 | long storage; |
415 | ||
416 | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) | |
417 | { | |
252b5132 RH |
418 | symcount = 0; |
419 | return NULL; | |
420 | } | |
421 | ||
422 | storage = bfd_get_symtab_upper_bound (abfd); | |
423 | if (storage < 0) | |
424 | bfd_fatal (bfd_get_filename (abfd)); | |
252b5132 | 425 | if (storage) |
d3ba0551 | 426 | sy = xmalloc (storage); |
28b18af1 | 427 | |
252b5132 RH |
428 | symcount = bfd_canonicalize_symtab (abfd, sy); |
429 | if (symcount < 0) | |
430 | bfd_fatal (bfd_get_filename (abfd)); | |
252b5132 RH |
431 | return sy; |
432 | } | |
433 | ||
434 | /* Read in the dynamic symbols. */ | |
435 | ||
436 | static asymbol ** | |
46dca2e0 | 437 | slurp_dynamic_symtab (bfd *abfd) |
252b5132 | 438 | { |
d3ba0551 | 439 | asymbol **sy = NULL; |
252b5132 RH |
440 | long storage; |
441 | ||
442 | storage = bfd_get_dynamic_symtab_upper_bound (abfd); | |
443 | if (storage < 0) | |
444 | { | |
445 | if (!(bfd_get_file_flags (abfd) & DYNAMIC)) | |
446 | { | |
37cc8ec1 | 447 | non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd)); |
252b5132 RH |
448 | dynsymcount = 0; |
449 | return NULL; | |
450 | } | |
451 | ||
452 | bfd_fatal (bfd_get_filename (abfd)); | |
453 | } | |
252b5132 | 454 | if (storage) |
d3ba0551 | 455 | sy = xmalloc (storage); |
28b18af1 | 456 | |
252b5132 RH |
457 | dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); |
458 | if (dynsymcount < 0) | |
459 | bfd_fatal (bfd_get_filename (abfd)); | |
252b5132 RH |
460 | return sy; |
461 | } | |
462 | ||
463 | /* Filter out (in place) symbols that are useless for disassembly. | |
464 | COUNT is the number of elements in SYMBOLS. | |
0af11b59 | 465 | Return the number of useful symbols. */ |
252b5132 RH |
466 | |
467 | static long | |
46dca2e0 | 468 | remove_useless_symbols (asymbol **symbols, long count) |
252b5132 | 469 | { |
46dca2e0 | 470 | asymbol **in_ptr = symbols, **out_ptr = symbols; |
252b5132 RH |
471 | |
472 | while (--count >= 0) | |
473 | { | |
474 | asymbol *sym = *in_ptr++; | |
475 | ||
476 | if (sym->name == NULL || sym->name[0] == '\0') | |
477 | continue; | |
180e47e2 | 478 | if (sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) |
252b5132 RH |
479 | continue; |
480 | if (bfd_is_und_section (sym->section) | |
481 | || bfd_is_com_section (sym->section)) | |
482 | continue; | |
483 | ||
484 | *out_ptr++ = sym; | |
485 | } | |
486 | return out_ptr - symbols; | |
487 | } | |
488 | ||
489 | /* Sort symbols into value order. */ | |
490 | ||
0af11b59 | 491 | static int |
46dca2e0 | 492 | compare_symbols (const void *ap, const void *bp) |
252b5132 | 493 | { |
46dca2e0 NC |
494 | const asymbol *a = * (const asymbol **) ap; |
495 | const asymbol *b = * (const asymbol **) bp; | |
496 | const char *an; | |
497 | const char *bn; | |
498 | size_t anl; | |
499 | size_t bnl; | |
500 | bfd_boolean af; | |
501 | bfd_boolean bf; | |
502 | flagword aflags; | |
503 | flagword bflags; | |
252b5132 RH |
504 | |
505 | if (bfd_asymbol_value (a) > bfd_asymbol_value (b)) | |
506 | return 1; | |
507 | else if (bfd_asymbol_value (a) < bfd_asymbol_value (b)) | |
508 | return -1; | |
509 | ||
510 | if (a->section > b->section) | |
511 | return 1; | |
512 | else if (a->section < b->section) | |
513 | return -1; | |
514 | ||
515 | an = bfd_asymbol_name (a); | |
516 | bn = bfd_asymbol_name (b); | |
517 | anl = strlen (an); | |
518 | bnl = strlen (bn); | |
519 | ||
520 | /* The symbols gnu_compiled and gcc2_compiled convey no real | |
521 | information, so put them after other symbols with the same value. */ | |
252b5132 RH |
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); | |
526 | ||
527 | if (af && ! bf) | |
528 | return 1; | |
529 | if (! af && bf) | |
530 | return -1; | |
531 | ||
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. */ | |
536 | ||
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'))) | |
542 | ||
543 | af = file_symbol (a, an, anl); | |
544 | bf = file_symbol (b, bn, bnl); | |
545 | ||
546 | if (af && ! bf) | |
547 | return 1; | |
548 | if (! af && bf) | |
549 | return -1; | |
550 | ||
551 | /* Try to sort global symbols before local symbols before function | |
552 | symbols before debugging symbols. */ | |
553 | ||
554 | aflags = a->flags; | |
555 | bflags = b->flags; | |
556 | ||
557 | if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING)) | |
558 | { | |
559 | if ((aflags & BSF_DEBUGGING) != 0) | |
560 | return 1; | |
561 | else | |
562 | return -1; | |
563 | } | |
564 | if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION)) | |
565 | { | |
566 | if ((aflags & BSF_FUNCTION) != 0) | |
567 | return -1; | |
568 | else | |
569 | return 1; | |
570 | } | |
571 | if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL)) | |
572 | { | |
573 | if ((aflags & BSF_LOCAL) != 0) | |
574 | return 1; | |
575 | else | |
576 | return -1; | |
577 | } | |
578 | if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL)) | |
579 | { | |
580 | if ((aflags & BSF_GLOBAL) != 0) | |
581 | return -1; | |
582 | else | |
583 | return 1; | |
584 | } | |
585 | ||
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] != '.') | |
589 | return 1; | |
590 | if (an[0] != '.' && bn[0] == '.') | |
591 | return -1; | |
592 | ||
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); | |
596 | } | |
597 | ||
598 | /* Sort relocs into address order. */ | |
599 | ||
600 | static int | |
46dca2e0 | 601 | compare_relocs (const void *ap, const void *bp) |
252b5132 | 602 | { |
46dca2e0 NC |
603 | const arelent *a = * (const arelent **) ap; |
604 | const arelent *b = * (const arelent **) bp; | |
252b5132 RH |
605 | |
606 | if (a->address > b->address) | |
607 | return 1; | |
608 | else if (a->address < b->address) | |
609 | return -1; | |
610 | ||
611 | /* So that associated relocations tied to the same address show up | |
612 | in the correct order, we don't do any further sorting. */ | |
613 | if (a > b) | |
614 | return 1; | |
615 | else if (a < b) | |
616 | return -1; | |
617 | else | |
618 | return 0; | |
619 | } | |
620 | ||
155e0d23 NC |
621 | /* Print an address (VMA) to the output stream in INFO. |
622 | If SKIP_ZEROES is TRUE, omit leading zeroes. */ | |
252b5132 RH |
623 | |
624 | static void | |
46dca2e0 NC |
625 | objdump_print_value (bfd_vma vma, struct disassemble_info *info, |
626 | bfd_boolean skip_zeroes) | |
252b5132 RH |
627 | { |
628 | char buf[30]; | |
629 | char *p; | |
3b9ad1cc | 630 | struct objdump_disasm_info *aux; |
252b5132 | 631 | |
3b9ad1cc | 632 | aux = (struct objdump_disasm_info *) info->application_data; |
d8180c76 | 633 | bfd_sprintf_vma (aux->abfd, buf, vma); |
252b5132 RH |
634 | if (! skip_zeroes) |
635 | p = buf; | |
636 | else | |
637 | { | |
638 | for (p = buf; *p == '0'; ++p) | |
639 | ; | |
640 | if (*p == '\0') | |
641 | --p; | |
642 | } | |
643 | (*info->fprintf_func) (info->stream, "%s", p); | |
644 | } | |
645 | ||
646 | /* Print the name of a symbol. */ | |
647 | ||
648 | static void | |
46dca2e0 NC |
649 | objdump_print_symname (bfd *abfd, struct disassemble_info *info, |
650 | asymbol *sym) | |
252b5132 RH |
651 | { |
652 | char *alloc; | |
653 | const char *name; | |
252b5132 RH |
654 | |
655 | alloc = NULL; | |
656 | name = bfd_asymbol_name (sym); | |
a6637ec0 | 657 | if (do_demangle && name[0] != '\0') |
252b5132 RH |
658 | { |
659 | /* Demangle the name. */ | |
a6637ec0 AM |
660 | alloc = demangle (abfd, name); |
661 | name = alloc; | |
252b5132 RH |
662 | } |
663 | ||
664 | if (info != NULL) | |
a6637ec0 | 665 | (*info->fprintf_func) (info->stream, "%s", name); |
252b5132 | 666 | else |
a6637ec0 | 667 | printf ("%s", name); |
252b5132 RH |
668 | |
669 | if (alloc != NULL) | |
670 | free (alloc); | |
671 | } | |
672 | ||
22a398e1 NC |
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. */ | |
252b5132 RH |
678 | |
679 | static asymbol * | |
3b9ad1cc AM |
680 | find_symbol_for_address (bfd_vma vma, |
681 | struct disassemble_info *info, | |
682 | long *place) | |
252b5132 RH |
683 | { |
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. */ | |
688 | ||
689 | /* Indices in `sorted_syms'. */ | |
690 | long min = 0; | |
691 | long max = sorted_symcount; | |
692 | long thisplace; | |
3b9ad1cc AM |
693 | struct objdump_disasm_info *aux; |
694 | bfd *abfd; | |
695 | asection *sec; | |
696 | unsigned int opb; | |
252b5132 RH |
697 | |
698 | if (sorted_symcount < 1) | |
699 | return NULL; | |
700 | ||
3b9ad1cc AM |
701 | aux = (struct objdump_disasm_info *) info->application_data; |
702 | abfd = aux->abfd; | |
703 | sec = aux->sec; | |
704 | opb = bfd_octets_per_byte (abfd); | |
705 | ||
252b5132 RH |
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) | |
709 | { | |
710 | asymbol *sym; | |
711 | ||
712 | thisplace = (max + min) / 2; | |
713 | sym = sorted_syms[thisplace]; | |
714 | ||
715 | if (bfd_asymbol_value (sym) > vma) | |
716 | max = thisplace; | |
717 | else if (bfd_asymbol_value (sym) < vma) | |
718 | min = thisplace; | |
719 | else | |
720 | { | |
721 | min = thisplace; | |
722 | break; | |
723 | } | |
724 | } | |
725 | ||
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. */ | |
729 | thisplace = min; | |
730 | while (thisplace > 0 | |
731 | && (bfd_asymbol_value (sorted_syms[thisplace]) | |
732 | == bfd_asymbol_value (sorted_syms[thisplace - 1]))) | |
733 | --thisplace; | |
734 | ||
1049f94e | 735 | /* If the file is relocatable, and the symbol could be from this |
252b5132 RH |
736 | section, prefer a symbol from this section over symbols from |
737 | others, even if the other symbol's value might be closer. | |
0af11b59 | 738 | |
252b5132 RH |
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 | |
742 | table. */ | |
252b5132 | 743 | if (sorted_syms[thisplace]->section != sec |
22a398e1 | 744 | && (aux->require_sec |
252b5132 RH |
745 | || ((abfd->flags & HAS_RELOC) != 0 |
746 | && vma >= bfd_get_section_vma (abfd, sec) | |
747 | && vma < (bfd_get_section_vma (abfd, sec) | |
940b2b78 | 748 | + bfd_section_size (abfd, sec) / opb)))) |
252b5132 RH |
749 | { |
750 | long i; | |
751 | ||
752 | for (i = thisplace + 1; i < sorted_symcount; i++) | |
753 | { | |
754 | if (bfd_asymbol_value (sorted_syms[i]) | |
755 | != bfd_asymbol_value (sorted_syms[thisplace])) | |
756 | break; | |
757 | } | |
98a91d6a | 758 | |
252b5132 | 759 | --i; |
98a91d6a | 760 | |
252b5132 RH |
761 | for (; i >= 0; i--) |
762 | { | |
763 | if (sorted_syms[i]->section == sec | |
764 | && (i == 0 | |
765 | || sorted_syms[i - 1]->section != sec | |
766 | || (bfd_asymbol_value (sorted_syms[i]) | |
767 | != bfd_asymbol_value (sorted_syms[i - 1])))) | |
768 | { | |
769 | thisplace = i; | |
770 | break; | |
771 | } | |
772 | } | |
773 | ||
774 | if (sorted_syms[thisplace]->section != sec) | |
775 | { | |
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++) | |
779 | { | |
780 | if (sorted_syms[i]->section == sec) | |
781 | { | |
782 | thisplace = i; | |
783 | break; | |
784 | } | |
785 | } | |
786 | } | |
787 | ||
788 | if (sorted_syms[thisplace]->section != sec | |
22a398e1 | 789 | && (aux->require_sec |
252b5132 RH |
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))))) | |
22a398e1 NC |
794 | /* There is no suitable symbol. */ |
795 | return NULL; | |
796 | } | |
797 | ||
798 | /* Give the target a chance to reject the symbol. */ | |
799 | while (! info->symbol_is_valid (sorted_syms [thisplace], info)) | |
800 | { | |
801 | ++ thisplace; | |
802 | if (thisplace >= sorted_symcount | |
803 | || bfd_asymbol_value (sorted_syms [thisplace]) > vma) | |
804 | return NULL; | |
252b5132 RH |
805 | } |
806 | ||
807 | if (place != NULL) | |
808 | *place = thisplace; | |
809 | ||
810 | return sorted_syms[thisplace]; | |
811 | } | |
812 | ||
155e0d23 | 813 | /* Print an address and the offset to the nearest symbol. */ |
252b5132 RH |
814 | |
815 | static void | |
46dca2e0 NC |
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) | |
252b5132 RH |
819 | { |
820 | objdump_print_value (vma, info, skip_zeroes); | |
821 | ||
822 | if (sym == NULL) | |
823 | { | |
824 | bfd_vma secaddr; | |
825 | ||
826 | (*info->fprintf_func) (info->stream, " <%s", | |
827 | bfd_get_section_name (abfd, sec)); | |
828 | secaddr = bfd_get_section_vma (abfd, sec); | |
829 | if (vma < secaddr) | |
830 | { | |
831 | (*info->fprintf_func) (info->stream, "-0x"); | |
b34976b6 | 832 | objdump_print_value (secaddr - vma, info, TRUE); |
252b5132 RH |
833 | } |
834 | else if (vma > secaddr) | |
835 | { | |
836 | (*info->fprintf_func) (info->stream, "+0x"); | |
b34976b6 | 837 | objdump_print_value (vma - secaddr, info, TRUE); |
252b5132 RH |
838 | } |
839 | (*info->fprintf_func) (info->stream, ">"); | |
840 | } | |
841 | else | |
842 | { | |
843 | (*info->fprintf_func) (info->stream, " <"); | |
844 | objdump_print_symname (abfd, info, sym); | |
845 | if (bfd_asymbol_value (sym) > vma) | |
846 | { | |
847 | (*info->fprintf_func) (info->stream, "-0x"); | |
b34976b6 | 848 | objdump_print_value (bfd_asymbol_value (sym) - vma, info, TRUE); |
252b5132 RH |
849 | } |
850 | else if (vma > bfd_asymbol_value (sym)) | |
851 | { | |
852 | (*info->fprintf_func) (info->stream, "+0x"); | |
b34976b6 | 853 | objdump_print_value (vma - bfd_asymbol_value (sym), info, TRUE); |
252b5132 RH |
854 | } |
855 | (*info->fprintf_func) (info->stream, ">"); | |
856 | } | |
857 | } | |
858 | ||
155e0d23 NC |
859 | /* Print an address (VMA), symbolically if possible. |
860 | If SKIP_ZEROES is TRUE, don't output leading zeroes. */ | |
252b5132 RH |
861 | |
862 | static void | |
3b9ad1cc AM |
863 | objdump_print_addr (bfd_vma vma, |
864 | struct disassemble_info *info, | |
46dca2e0 | 865 | bfd_boolean skip_zeroes) |
252b5132 | 866 | { |
3b9ad1cc | 867 | struct objdump_disasm_info *aux; |
58450b3b | 868 | asymbol *sym = NULL; /* Initialize to avoid compiler warning. */ |
ce04548a NC |
869 | #ifdef DISASSEMBLER_NEEDS_RELOCS |
870 | bfd_boolean skip_find = FALSE; | |
871 | #endif | |
252b5132 RH |
872 | |
873 | if (sorted_symcount < 1) | |
874 | { | |
875 | (*info->fprintf_func) (info->stream, "0x"); | |
876 | objdump_print_value (vma, info, skip_zeroes); | |
877 | return; | |
878 | } | |
879 | ||
3b9ad1cc | 880 | aux = (struct objdump_disasm_info *) info->application_data; |
ce04548a NC |
881 | |
882 | #ifdef DISASSEMBLER_NEEDS_RELOCS | |
883 | if (aux->reloc != NULL | |
884 | && aux->reloc->sym_ptr_ptr != NULL | |
885 | && * aux->reloc->sym_ptr_ptr != NULL) | |
886 | { | |
887 | sym = * aux->reloc->sym_ptr_ptr; | |
888 | ||
889 | /* Adjust the vma to the reloc. */ | |
890 | vma += bfd_asymbol_value (sym); | |
891 | ||
892 | if (bfd_is_und_section (bfd_get_section (sym))) | |
893 | skip_find = TRUE; | |
894 | } | |
895 | ||
896 | if (!skip_find) | |
897 | #endif | |
898 | sym = find_symbol_for_address (vma, info, NULL); | |
899 | ||
252b5132 RH |
900 | objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info, |
901 | skip_zeroes); | |
902 | } | |
903 | ||
904 | /* Print VMA to INFO. This function is passed to the disassembler | |
905 | routine. */ | |
906 | ||
907 | static void | |
46dca2e0 | 908 | objdump_print_address (bfd_vma vma, struct disassemble_info *info) |
252b5132 RH |
909 | { |
910 | objdump_print_addr (vma, info, ! prefix_addresses); | |
911 | } | |
912 | ||
913 | /* Determine of the given address has a symbol associated with it. */ | |
914 | ||
915 | static int | |
46dca2e0 | 916 | objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * info) |
252b5132 | 917 | { |
252b5132 RH |
918 | asymbol * sym; |
919 | ||
22a398e1 | 920 | sym = find_symbol_for_address (vma, info, NULL); |
252b5132 RH |
921 | |
922 | return (sym != NULL && (bfd_asymbol_value (sym) == vma)); | |
923 | } | |
924 | ||
925 | /* Hold the last function name and the last line number we displayed | |
926 | in a disassembly. */ | |
927 | ||
928 | static char *prev_functionname; | |
929 | static unsigned int prev_line; | |
930 | ||
931 | /* We keep a list of all files that we have seen when doing a | |
50c2245b | 932 | disassembly with source, so that we know how much of the file to |
252b5132 RH |
933 | display. This can be important for inlined functions. */ |
934 | ||
935 | struct print_file_list | |
936 | { | |
937 | struct print_file_list *next; | |
43ac9881 AM |
938 | const char *filename; |
939 | const char *modname; | |
252b5132 RH |
940 | unsigned int line; |
941 | FILE *f; | |
942 | }; | |
943 | ||
944 | static struct print_file_list *print_files; | |
945 | ||
946 | /* The number of preceding context lines to show when we start | |
947 | displaying a file for the first time. */ | |
948 | ||
949 | #define SHOW_PRECEDING_CONTEXT_LINES (5) | |
950 | ||
43ac9881 AM |
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. */ | |
953 | ||
954 | static struct print_file_list * | |
955 | try_print_file_open (const char *origname, const char *modname) | |
956 | { | |
957 | struct print_file_list *p; | |
958 | FILE *f; | |
959 | ||
960 | f = fopen (modname, "r"); | |
961 | if (f == NULL) | |
962 | return NULL; | |
963 | ||
964 | if (print_files != NULL && print_files->f != NULL) | |
965 | { | |
966 | fclose (print_files->f); | |
967 | print_files->f = NULL; | |
968 | } | |
969 | ||
970 | p = xmalloc (sizeof (struct print_file_list)); | |
971 | p->filename = origname; | |
972 | p->modname = modname; | |
973 | p->line = 0; | |
974 | p->f = f; | |
975 | p->next = print_files; | |
976 | print_files = p; | |
977 | return p; | |
978 | } | |
979 | ||
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. */ | |
983 | ||
984 | static struct print_file_list * | |
985 | update_source_path (const char *filename) | |
986 | { | |
987 | struct print_file_list *p; | |
988 | const char *fname; | |
989 | int i; | |
990 | ||
991 | if (filename == NULL) | |
992 | return NULL; | |
993 | ||
994 | p = try_print_file_open (filename, filename); | |
995 | if (p != NULL) | |
996 | return p; | |
997 | ||
998 | if (include_path_count == 0) | |
999 | return NULL; | |
1000 | ||
1001 | /* Get the name of the file. */ | |
1002 | fname = strrchr (filename, '/'); | |
1003 | #ifdef HAVE_DOS_BASED_FILE_SYSTEM | |
1004 | { | |
1005 | /* We could have a mixed forward/back slash case. */ | |
1006 | char *backslash = strrchr (filename, '\\'); | |
1007 | if (fname == NULL || (backslash != NULL && backslash > fname)) | |
1008 | fname = backslash; | |
1009 | if (fname == NULL && filename[0] != '\0' && filename[1] == ':') | |
1010 | fname = filename + 1; | |
1011 | } | |
1012 | #endif | |
1013 | if (fname == NULL) | |
1014 | fname = filename; | |
1015 | else | |
1016 | ++fname; | |
1017 | ||
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++) | |
1021 | { | |
1022 | char *modname = concat (include_paths[i], "/", fname, (const char *) 0); | |
1023 | ||
1024 | p = try_print_file_open (filename, modname); | |
1025 | if (p) | |
1026 | return p; | |
1027 | ||
1028 | free (modname); | |
1029 | } | |
1030 | ||
1031 | return NULL; | |
1032 | } | |
1033 | ||
252b5132 RH |
1034 | /* Skip ahead to a given line in a file, optionally printing each |
1035 | line. */ | |
1036 | ||
252b5132 | 1037 | static void |
46dca2e0 NC |
1038 | skip_to_line (struct print_file_list *p, unsigned int line, |
1039 | bfd_boolean show) | |
252b5132 RH |
1040 | { |
1041 | while (p->line < line) | |
1042 | { | |
1043 | char buf[100]; | |
1044 | ||
1045 | if (fgets (buf, sizeof buf, p->f) == NULL) | |
1046 | { | |
1047 | fclose (p->f); | |
1048 | p->f = NULL; | |
1049 | break; | |
1050 | } | |
1051 | ||
1052 | if (show) | |
1053 | printf ("%s", buf); | |
1054 | ||
1055 | if (strchr (buf, '\n') != NULL) | |
1056 | ++p->line; | |
1057 | } | |
0af11b59 | 1058 | } |
252b5132 | 1059 | |
50c2245b | 1060 | /* Show the line number, or the source line, in a disassembly |
252b5132 RH |
1061 | listing. */ |
1062 | ||
1063 | static void | |
46dca2e0 | 1064 | show_line (bfd *abfd, asection *section, bfd_vma addr_offset) |
252b5132 | 1065 | { |
b1f88ebe AM |
1066 | const char *filename; |
1067 | const char *functionname; | |
252b5132 RH |
1068 | unsigned int line; |
1069 | ||
1070 | if (! with_line_numbers && ! with_source_code) | |
1071 | return; | |
1072 | ||
940b2b78 | 1073 | if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename, |
252b5132 RH |
1074 | &functionname, &line)) |
1075 | return; | |
1076 | ||
1077 | if (filename != NULL && *filename == '\0') | |
1078 | filename = NULL; | |
1079 | if (functionname != NULL && *functionname == '\0') | |
1080 | functionname = NULL; | |
1081 | ||
1082 | if (with_line_numbers) | |
1083 | { | |
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); | |
1090 | } | |
1091 | ||
1092 | if (with_source_code | |
1093 | && filename != NULL | |
1094 | && line > 0) | |
1095 | { | |
1096 | struct print_file_list **pp, *p; | |
1097 | ||
1098 | for (pp = &print_files; *pp != NULL; pp = &(*pp)->next) | |
1099 | if (strcmp ((*pp)->filename, filename) == 0) | |
1100 | break; | |
1101 | p = *pp; | |
1102 | ||
1103 | if (p != NULL) | |
1104 | { | |
1105 | if (p != print_files) | |
1106 | { | |
1107 | int l; | |
1108 | ||
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) | |
1121 | l = p->line; | |
1122 | else | |
1123 | { | |
1124 | l = line - SHOW_PRECEDING_CONTEXT_LINES; | |
f1563258 TW |
1125 | if (l < 0) |
1126 | l = 0; | |
252b5132 RH |
1127 | } |
1128 | ||
1129 | if (p->f == NULL) | |
1130 | { | |
43ac9881 | 1131 | p->f = fopen (p->modname, "r"); |
252b5132 RH |
1132 | p->line = 0; |
1133 | } | |
1134 | if (p->f != NULL) | |
b34976b6 | 1135 | skip_to_line (p, l, FALSE); |
252b5132 RH |
1136 | |
1137 | if (print_files->f != NULL) | |
1138 | { | |
1139 | fclose (print_files->f); | |
1140 | print_files->f = NULL; | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | if (p->f != NULL) | |
1145 | { | |
b34976b6 | 1146 | skip_to_line (p, line, TRUE); |
252b5132 RH |
1147 | *pp = p->next; |
1148 | p->next = print_files; | |
1149 | print_files = p; | |
1150 | } | |
1151 | } | |
1152 | else | |
1153 | { | |
43ac9881 | 1154 | p = update_source_path (filename); |
252b5132 | 1155 | |
43ac9881 | 1156 | if (p != NULL) |
252b5132 RH |
1157 | { |
1158 | int l; | |
1159 | ||
0af11b59 KH |
1160 | if (file_start_context) |
1161 | l = 0; | |
1162 | else | |
1163 | l = line - SHOW_PRECEDING_CONTEXT_LINES; | |
f1563258 TW |
1164 | if (l < 0) |
1165 | l = 0; | |
b34976b6 | 1166 | skip_to_line (p, l, FALSE); |
252b5132 | 1167 | if (p->f != NULL) |
b34976b6 | 1168 | skip_to_line (p, line, TRUE); |
252b5132 RH |
1169 | } |
1170 | } | |
1171 | } | |
1172 | ||
1173 | if (functionname != NULL | |
1174 | && (prev_functionname == NULL | |
1175 | || strcmp (functionname, prev_functionname) != 0)) | |
1176 | { | |
1177 | if (prev_functionname != NULL) | |
1178 | free (prev_functionname); | |
1179 | prev_functionname = xmalloc (strlen (functionname) + 1); | |
1180 | strcpy (prev_functionname, functionname); | |
1181 | } | |
1182 | ||
1183 | if (line > 0 && line != prev_line) | |
1184 | prev_line = line; | |
1185 | } | |
1186 | ||
1187 | /* Pseudo FILE object for strings. */ | |
1188 | typedef struct | |
1189 | { | |
1190 | char *buffer; | |
6f104306 NS |
1191 | size_t pos; |
1192 | size_t alloc; | |
252b5132 RH |
1193 | } SFILE; |
1194 | ||
46dca2e0 | 1195 | /* sprintf to a "stream". */ |
252b5132 | 1196 | |
0fd3a477 | 1197 | static int ATTRIBUTE_PRINTF_2 |
46dca2e0 | 1198 | objdump_sprintf (SFILE *f, const char *format, ...) |
252b5132 | 1199 | { |
252b5132 | 1200 | size_t n; |
46dca2e0 | 1201 | va_list args; |
252b5132 | 1202 | |
6f104306 | 1203 | while (1) |
252b5132 | 1204 | { |
6f104306 NS |
1205 | size_t space = f->alloc - f->pos; |
1206 | ||
1207 | va_start (args, format); | |
1208 | n = vsnprintf (f->buffer + f->pos, space, format, args); | |
451dad9c | 1209 | va_end (args); |
252b5132 | 1210 | |
6f104306 NS |
1211 | if (space > n) |
1212 | break; | |
1213 | ||
1214 | f->alloc = (f->alloc + n) * 2; | |
1215 | f->buffer = xrealloc (f->buffer, f->alloc); | |
252b5132 | 1216 | } |
6f104306 NS |
1217 | f->pos += n; |
1218 | ||
252b5132 RH |
1219 | return n; |
1220 | } | |
1221 | ||
155e0d23 NC |
1222 | /* Returns TRUE if the specified section should be dumped. */ |
1223 | ||
1224 | static bfd_boolean | |
1225 | process_section_p (asection * section) | |
1226 | { | |
1227 | size_t i; | |
1228 | ||
1229 | if (only == NULL) | |
1230 | return TRUE; | |
1231 | ||
1232 | for (i = 0; i < only_used; i++) | |
1233 | if (strcmp (only [i], section->name) == 0) | |
1234 | return TRUE; | |
1235 | ||
1236 | return FALSE; | |
1237 | } | |
1238 | ||
1239 | ||
252b5132 RH |
1240 | /* The number of zeroes we want to see before we start skipping them. |
1241 | The number is arbitrarily chosen. */ | |
1242 | ||
0bcb06d2 | 1243 | #define DEFAULT_SKIP_ZEROES 8 |
252b5132 RH |
1244 | |
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 | |
1250 | alignment. */ | |
1251 | ||
0bcb06d2 | 1252 | #define DEFAULT_SKIP_ZEROES_AT_END 3 |
252b5132 RH |
1253 | |
1254 | /* Disassemble some data in memory between given values. */ | |
1255 | ||
1256 | static void | |
46dca2e0 NC |
1257 | disassemble_bytes (struct disassemble_info * info, |
1258 | disassembler_ftype disassemble_fn, | |
1259 | bfd_boolean insns, | |
1260 | bfd_byte * data, | |
1261 | bfd_vma start_offset, | |
1262 | bfd_vma stop_offset, | |
fd7bb956 | 1263 | bfd_vma rel_offset, |
46dca2e0 NC |
1264 | arelent *** relppp, |
1265 | arelent ** relppend) | |
252b5132 RH |
1266 | { |
1267 | struct objdump_disasm_info *aux; | |
1268 | asection *section; | |
940b2b78 | 1269 | int octets_per_line; |
b34976b6 | 1270 | bfd_boolean done_dot; |
252b5132 | 1271 | int skip_addr_chars; |
940b2b78 | 1272 | bfd_vma addr_offset; |
0bcb06d2 AS |
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; | |
ce04548a | 1276 | int octets = opb; |
6f104306 | 1277 | SFILE sfile; |
252b5132 RH |
1278 | |
1279 | aux = (struct objdump_disasm_info *) info->application_data; | |
1280 | section = aux->sec; | |
1281 | ||
6f104306 NS |
1282 | sfile.alloc = 120; |
1283 | sfile.buffer = xmalloc (sfile.alloc); | |
1284 | sfile.pos = 0; | |
1285 | ||
252b5132 | 1286 | if (insns) |
940b2b78 | 1287 | octets_per_line = 4; |
252b5132 | 1288 | else |
940b2b78 | 1289 | octets_per_line = 16; |
252b5132 RH |
1290 | |
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 | |
1294 | zero remaining. */ | |
1295 | skip_addr_chars = 0; | |
1296 | if (! prefix_addresses) | |
1297 | { | |
1298 | char buf[30]; | |
1299 | char *s; | |
1300 | ||
d8180c76 L |
1301 | bfd_sprintf_vma |
1302 | (aux->abfd, buf, | |
1303 | (section->vma | |
1304 | + bfd_section_size (section->owner, section) / opb)); | |
252b5132 RH |
1305 | s = buf; |
1306 | while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0' | |
1307 | && s[4] == '0') | |
1308 | { | |
1309 | skip_addr_chars += 4; | |
1310 | s += 4; | |
1311 | } | |
1312 | } | |
1313 | ||
1314 | info->insn_info_valid = 0; | |
1315 | ||
b34976b6 | 1316 | done_dot = FALSE; |
940b2b78 TW |
1317 | addr_offset = start_offset; |
1318 | while (addr_offset < stop_offset) | |
252b5132 RH |
1319 | { |
1320 | bfd_vma z; | |
b34976b6 | 1321 | bfd_boolean need_nl = FALSE; |
ce04548a NC |
1322 | #ifdef DISASSEMBLER_NEEDS_RELOCS |
1323 | int previous_octets; | |
1324 | ||
1325 | /* Remember the length of the previous instruction. */ | |
1326 | previous_octets = octets; | |
1327 | #endif | |
1328 | octets = 0; | |
252b5132 | 1329 | |
940b2b78 | 1330 | /* If we see more than SKIP_ZEROES octets of zeroes, we just |
43ac9881 | 1331 | print `...'. */ |
940b2b78 | 1332 | for (z = addr_offset * opb; z < stop_offset * opb; z++) |
252b5132 RH |
1333 | if (data[z] != 0) |
1334 | break; | |
1335 | if (! disassemble_zeroes | |
1336 | && (info->insn_info_valid == 0 | |
1337 | || info->branch_delay_insns == 0) | |
0bcb06d2 | 1338 | && (z - addr_offset * opb >= skip_zeroes |
0af11b59 | 1339 | || (z == stop_offset * opb && |
0bcb06d2 | 1340 | z - addr_offset * opb < skip_zeroes_at_end))) |
252b5132 RH |
1341 | { |
1342 | printf ("\t...\n"); | |
1343 | ||
940b2b78 | 1344 | /* If there are more nonzero octets to follow, we only skip |
43ac9881 AM |
1345 | zeroes in multiples of 4, to try to avoid running over |
1346 | the start of an instruction which happens to start with | |
1347 | zero. */ | |
940b2b78 TW |
1348 | if (z != stop_offset * opb) |
1349 | z = addr_offset * opb + ((z - addr_offset * opb) &~ 3); | |
252b5132 | 1350 | |
940b2b78 | 1351 | octets = z - addr_offset * opb; |
252b5132 RH |
1352 | } |
1353 | else | |
1354 | { | |
1355 | char buf[50]; | |
252b5132 RH |
1356 | int bpc = 0; |
1357 | int pb = 0; | |
1358 | ||
b34976b6 | 1359 | done_dot = FALSE; |
252b5132 RH |
1360 | |
1361 | if (with_line_numbers || with_source_code) | |
bc79cded | 1362 | show_line (aux->abfd, section, addr_offset); |
252b5132 RH |
1363 | |
1364 | if (! prefix_addresses) | |
1365 | { | |
1366 | char *s; | |
1367 | ||
d8180c76 | 1368 | bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset); |
252b5132 RH |
1369 | for (s = buf + skip_addr_chars; *s == '0'; s++) |
1370 | *s = ' '; | |
1371 | if (*s == '\0') | |
1372 | *--s = '0'; | |
1373 | printf ("%s:\t", buf + skip_addr_chars); | |
1374 | } | |
1375 | else | |
1376 | { | |
b34976b6 | 1377 | aux->require_sec = TRUE; |
940b2b78 | 1378 | objdump_print_address (section->vma + addr_offset, info); |
b34976b6 | 1379 | aux->require_sec = FALSE; |
252b5132 RH |
1380 | putchar (' '); |
1381 | } | |
1382 | ||
1383 | if (insns) | |
1384 | { | |
6f104306 | 1385 | sfile.pos = 0; |
252b5132 | 1386 | info->fprintf_func = (fprintf_ftype) objdump_sprintf; |
5810296b | 1387 | info->stream = &sfile; |
252b5132 RH |
1388 | info->bytes_per_line = 0; |
1389 | info->bytes_per_chunk = 0; | |
ce04548a | 1390 | info->flags = 0; |
252b5132 | 1391 | |
8b1e6df3 | 1392 | #ifdef DISASSEMBLER_NEEDS_RELOCS |
ce04548a NC |
1393 | if (*relppp < relppend) |
1394 | { | |
1395 | bfd_signed_vma distance_to_rel; | |
1396 | ||
1397 | distance_to_rel = (**relppp)->address | |
1398 | - (rel_offset + addr_offset); | |
1399 | ||
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))) | |
1416 | { | |
1417 | info->flags = INSN_HAS_RELOC; | |
1418 | aux->reloc = **relppp; | |
1419 | } | |
1420 | else | |
1421 | aux->reloc = NULL; | |
1422 | } | |
8b1e6df3 | 1423 | #endif |
940b2b78 | 1424 | octets = (*disassemble_fn) (section->vma + addr_offset, info); |
252b5132 RH |
1425 | info->fprintf_func = (fprintf_ftype) fprintf; |
1426 | info->stream = stdout; | |
1427 | if (info->bytes_per_line != 0) | |
940b2b78 TW |
1428 | octets_per_line = info->bytes_per_line; |
1429 | if (octets < 0) | |
e07bf1ac | 1430 | { |
6f104306 | 1431 | if (sfile.pos) |
e07bf1ac | 1432 | printf ("%s\n", sfile.buffer); |
e07bf1ac ILT |
1433 | break; |
1434 | } | |
252b5132 RH |
1435 | } |
1436 | else | |
1437 | { | |
b4c96d0d | 1438 | bfd_vma j; |
252b5132 | 1439 | |
940b2b78 TW |
1440 | octets = octets_per_line; |
1441 | if (addr_offset + octets / opb > stop_offset) | |
1442 | octets = (stop_offset - addr_offset) * opb; | |
252b5132 | 1443 | |
940b2b78 | 1444 | for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j) |
252b5132 | 1445 | { |
3882b010 | 1446 | if (ISPRINT (data[j])) |
940b2b78 | 1447 | buf[j - addr_offset * opb] = data[j]; |
252b5132 | 1448 | else |
940b2b78 | 1449 | buf[j - addr_offset * opb] = '.'; |
252b5132 | 1450 | } |
940b2b78 | 1451 | buf[j - addr_offset * opb] = '\0'; |
252b5132 RH |
1452 | } |
1453 | ||
1454 | if (prefix_addresses | |
1455 | ? show_raw_insn > 0 | |
1456 | : show_raw_insn >= 0) | |
1457 | { | |
b4c96d0d | 1458 | bfd_vma j; |
252b5132 RH |
1459 | |
1460 | /* If ! prefix_addresses and ! wide_output, we print | |
43ac9881 | 1461 | octets_per_line octets per line. */ |
940b2b78 TW |
1462 | pb = octets; |
1463 | if (pb > octets_per_line && ! prefix_addresses && ! wide_output) | |
1464 | pb = octets_per_line; | |
252b5132 RH |
1465 | |
1466 | if (info->bytes_per_chunk) | |
1467 | bpc = info->bytes_per_chunk; | |
1468 | else | |
1469 | bpc = 1; | |
1470 | ||
940b2b78 | 1471 | for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc) |
252b5132 RH |
1472 | { |
1473 | int k; | |
ed049af3 | 1474 | |
252b5132 RH |
1475 | if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE) |
1476 | { | |
1477 | for (k = bpc - 1; k >= 0; k--) | |
1478 | printf ("%02x", (unsigned) data[j + k]); | |
1479 | putchar (' '); | |
1480 | } | |
1481 | else | |
1482 | { | |
1483 | for (k = 0; k < bpc; k++) | |
1484 | printf ("%02x", (unsigned) data[j + k]); | |
1485 | putchar (' '); | |
1486 | } | |
1487 | } | |
1488 | ||
940b2b78 | 1489 | for (; pb < octets_per_line; pb += bpc) |
252b5132 RH |
1490 | { |
1491 | int k; | |
1492 | ||
1493 | for (k = 0; k < bpc; k++) | |
1494 | printf (" "); | |
1495 | putchar (' '); | |
1496 | } | |
1497 | ||
1498 | /* Separate raw data from instruction by extra space. */ | |
1499 | if (insns) | |
1500 | putchar ('\t'); | |
1501 | else | |
1502 | printf (" "); | |
1503 | } | |
1504 | ||
1505 | if (! insns) | |
1506 | printf ("%s", buf); | |
6f104306 NS |
1507 | else if (sfile.pos) |
1508 | printf ("%s", sfile.buffer); | |
252b5132 RH |
1509 | |
1510 | if (prefix_addresses | |
1511 | ? show_raw_insn > 0 | |
1512 | : show_raw_insn >= 0) | |
1513 | { | |
940b2b78 | 1514 | while (pb < octets) |
252b5132 | 1515 | { |
b4c96d0d | 1516 | bfd_vma j; |
252b5132 RH |
1517 | char *s; |
1518 | ||
1519 | putchar ('\n'); | |
940b2b78 | 1520 | j = addr_offset * opb + pb; |
252b5132 | 1521 | |
d8180c76 | 1522 | bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb); |
252b5132 RH |
1523 | for (s = buf + skip_addr_chars; *s == '0'; s++) |
1524 | *s = ' '; | |
1525 | if (*s == '\0') | |
1526 | *--s = '0'; | |
1527 | printf ("%s:\t", buf + skip_addr_chars); | |
1528 | ||
940b2b78 TW |
1529 | pb += octets_per_line; |
1530 | if (pb > octets) | |
1531 | pb = octets; | |
1532 | for (; j < addr_offset * opb + pb; j += bpc) | |
252b5132 RH |
1533 | { |
1534 | int k; | |
1535 | ||
1536 | if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE) | |
1537 | { | |
1538 | for (k = bpc - 1; k >= 0; k--) | |
1539 | printf ("%02x", (unsigned) data[j + k]); | |
1540 | putchar (' '); | |
1541 | } | |
1542 | else | |
1543 | { | |
1544 | for (k = 0; k < bpc; k++) | |
1545 | printf ("%02x", (unsigned) data[j + k]); | |
1546 | putchar (' '); | |
1547 | } | |
1548 | } | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | if (!wide_output) | |
1553 | putchar ('\n'); | |
1554 | else | |
b34976b6 | 1555 | need_nl = TRUE; |
252b5132 RH |
1556 | } |
1557 | ||
fd7bb956 AM |
1558 | while ((*relppp) < relppend |
1559 | && (**relppp)->address < rel_offset + addr_offset + octets / opb) | |
252b5132 | 1560 | { |
fd7bb956 | 1561 | if (dump_reloc_info || dump_dynamic_reloc_info) |
252b5132 RH |
1562 | { |
1563 | arelent *q; | |
1564 | ||
1565 | q = **relppp; | |
1566 | ||
1567 | if (wide_output) | |
1568 | putchar ('\t'); | |
1569 | else | |
1570 | printf ("\t\t\t"); | |
1571 | ||
68b3b8dc JJ |
1572 | objdump_print_value (section->vma - rel_offset + q->address, |
1573 | info, TRUE); | |
252b5132 | 1574 | |
f9ecb0a4 JJ |
1575 | if (q->howto == NULL) |
1576 | printf (": *unknown*\t"); | |
1577 | else if (q->howto->name) | |
1578 | printf (": %s\t", q->howto->name); | |
1579 | else | |
1580 | printf (": %d\t", q->howto->type); | |
252b5132 RH |
1581 | |
1582 | if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL) | |
1583 | printf ("*unknown*"); | |
1584 | else | |
1585 | { | |
1586 | const char *sym_name; | |
1587 | ||
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); | |
1591 | else | |
1592 | { | |
1593 | asection *sym_sec; | |
1594 | ||
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); | |
1600 | } | |
1601 | } | |
1602 | ||
1603 | if (q->addend) | |
1604 | { | |
1605 | printf ("+0x"); | |
b34976b6 | 1606 | objdump_print_value (q->addend, info, TRUE); |
252b5132 RH |
1607 | } |
1608 | ||
1609 | printf ("\n"); | |
b34976b6 | 1610 | need_nl = FALSE; |
252b5132 | 1611 | } |
fd7bb956 | 1612 | ++(*relppp); |
252b5132 RH |
1613 | } |
1614 | ||
1615 | if (need_nl) | |
1616 | printf ("\n"); | |
1617 | ||
940b2b78 | 1618 | addr_offset += octets / opb; |
252b5132 | 1619 | } |
6f104306 NS |
1620 | |
1621 | free (sfile.buffer); | |
252b5132 RH |
1622 | } |
1623 | ||
155e0d23 NC |
1624 | static void |
1625 | disassemble_section (bfd *abfd, asection *section, void *info) | |
1626 | { | |
1627 | struct disassemble_info * pinfo = (struct disassemble_info *) info; | |
3b9ad1cc | 1628 | struct objdump_disasm_info * paux; |
155e0d23 NC |
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; | |
1637 | long place = 0; | |
1638 | long rel_count; | |
1639 | bfd_vma rel_offset; | |
1640 | unsigned long addr_offset; | |
1641 | ||
1642 | /* Sections that do not contain machine | |
1643 | code are not normally disassembled. */ | |
1644 | if (! disassemble_all | |
1645 | && only == NULL | |
46212538 AM |
1646 | && ((section->flags & (SEC_CODE | SEC_HAS_CONTENTS)) |
1647 | != (SEC_CODE | SEC_HAS_CONTENTS))) | |
155e0d23 NC |
1648 | return; |
1649 | ||
1650 | if (! process_section_p (section)) | |
1651 | return; | |
1652 | ||
135dfb4a | 1653 | datasize = bfd_get_section_size (section); |
155e0d23 NC |
1654 | if (datasize == 0) |
1655 | return; | |
1656 | ||
1657 | /* Decide which set of relocs to use. Load them if necessary. */ | |
3b9ad1cc | 1658 | paux = (struct objdump_disasm_info *) pinfo->application_data; |
155e0d23 NC |
1659 | if (paux->dynrelbuf) |
1660 | { | |
1661 | rel_pp = paux->dynrelbuf; | |
1662 | rel_count = paux->dynrelcount; | |
1663 | /* Dynamic reloc addresses are absolute, non-dynamic are section | |
50c2245b | 1664 | relative. REL_OFFSET specifies the reloc address corresponding |
155e0d23 | 1665 | to the start of this section. */ |
68b3b8dc | 1666 | rel_offset = section->vma; |
155e0d23 NC |
1667 | } |
1668 | else | |
1669 | { | |
1670 | rel_count = 0; | |
1671 | rel_pp = NULL; | |
1672 | rel_offset = 0; | |
1673 | ||
1674 | if ((section->flags & SEC_RELOC) != 0 | |
1675 | #ifndef DISASSEMBLER_NEEDS_RELOCS | |
1676 | && dump_reloc_info | |
1677 | #endif | |
1678 | ) | |
1679 | { | |
1680 | long relsize; | |
1681 | ||
1682 | relsize = bfd_get_reloc_upper_bound (abfd, section); | |
1683 | if (relsize < 0) | |
1684 | bfd_fatal (bfd_get_filename (abfd)); | |
1685 | ||
1686 | if (relsize > 0) | |
1687 | { | |
1688 | rel_ppstart = rel_pp = xmalloc (relsize); | |
1689 | rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms); | |
1690 | if (rel_count < 0) | |
1691 | bfd_fatal (bfd_get_filename (abfd)); | |
1692 | ||
1693 | /* Sort the relocs by address. */ | |
1694 | qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs); | |
1695 | } | |
1696 | } | |
1697 | ||
1698 | } | |
1699 | rel_ppend = rel_pp + rel_count; | |
1700 | ||
1701 | data = xmalloc (datasize); | |
1702 | ||
1703 | bfd_get_section_contents (abfd, section, data, 0, datasize); | |
1704 | ||
1705 | paux->sec = section; | |
1706 | pinfo->buffer = data; | |
1707 | pinfo->buffer_vma = section->vma; | |
1708 | pinfo->buffer_length = datasize; | |
1709 | pinfo->section = section; | |
1710 | ||
1711 | if (start_address == (bfd_vma) -1 | |
1712 | || start_address < pinfo->buffer_vma) | |
1713 | addr_offset = 0; | |
1714 | else | |
1715 | addr_offset = start_address - pinfo->buffer_vma; | |
1716 | ||
1717 | if (stop_address == (bfd_vma) -1) | |
1718 | stop_offset = datasize / opb; | |
1719 | else | |
1720 | { | |
1721 | if (stop_address < pinfo->buffer_vma) | |
1722 | stop_offset = 0; | |
1723 | else | |
1724 | stop_offset = stop_address - pinfo->buffer_vma; | |
1725 | if (stop_offset > pinfo->buffer_length / opb) | |
1726 | stop_offset = pinfo->buffer_length / opb; | |
1727 | } | |
1728 | ||
1729 | /* Skip over the relocs belonging to addresses below the | |
1730 | start address. */ | |
1731 | while (rel_pp < rel_ppend | |
1732 | && (*rel_pp)->address < rel_offset + addr_offset) | |
1733 | ++rel_pp; | |
1734 | ||
1735 | printf (_("Disassembly of section %s:\n"), section->name); | |
1736 | ||
1737 | /* Find the nearest symbol forwards from our current position. */ | |
3b9ad1cc | 1738 | paux->require_sec = TRUE; |
22a398e1 | 1739 | sym = find_symbol_for_address (section->vma + addr_offset, info, &place); |
3b9ad1cc | 1740 | paux->require_sec = FALSE; |
155e0d23 NC |
1741 | |
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) | |
1747 | { | |
22a398e1 | 1748 | bfd_vma addr; |
155e0d23 NC |
1749 | asymbol *nextsym; |
1750 | unsigned long nextstop_offset; | |
1751 | bfd_boolean insns; | |
1752 | ||
22a398e1 NC |
1753 | addr = section->vma + addr_offset; |
1754 | ||
1755 | if (sym != NULL && bfd_asymbol_value (sym) <= addr) | |
155e0d23 NC |
1756 | { |
1757 | int x; | |
1758 | ||
1759 | for (x = place; | |
1760 | (x < sorted_symcount | |
22a398e1 | 1761 | && (bfd_asymbol_value (sorted_syms[x]) <= addr)); |
155e0d23 NC |
1762 | ++x) |
1763 | continue; | |
1764 | ||
22a398e1 | 1765 | pinfo->symbols = sorted_syms + place; |
155e0d23 NC |
1766 | pinfo->num_symbols = x - place; |
1767 | } | |
1768 | else | |
22a398e1 NC |
1769 | { |
1770 | pinfo->symbols = NULL; | |
1771 | pinfo->num_symbols = 0; | |
1772 | } | |
155e0d23 NC |
1773 | |
1774 | if (! prefix_addresses) | |
1775 | { | |
1776 | pinfo->fprintf_func (pinfo->stream, "\n"); | |
22a398e1 | 1777 | objdump_print_addr_with_sym (abfd, section, sym, addr, |
155e0d23 NC |
1778 | pinfo, FALSE); |
1779 | pinfo->fprintf_func (pinfo->stream, ":\n"); | |
1780 | } | |
1781 | ||
22a398e1 | 1782 | if (sym != NULL && bfd_asymbol_value (sym) > addr) |
155e0d23 NC |
1783 | nextsym = sym; |
1784 | else if (sym == NULL) | |
1785 | nextsym = NULL; | |
1786 | else | |
1787 | { | |
22a398e1 NC |
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)) | |
1792 | ||
155e0d23 NC |
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 | |
22a398e1 | 1798 | && ! is_valid_next_sym (sorted_syms [place])) |
155e0d23 | 1799 | ++place; |
22a398e1 | 1800 | |
155e0d23 NC |
1801 | if (place >= sorted_symcount) |
1802 | nextsym = NULL; | |
1803 | else | |
1804 | nextsym = sorted_syms[place]; | |
1805 | } | |
1806 | ||
22a398e1 NC |
1807 | if (sym != NULL && bfd_asymbol_value (sym) > addr) |
1808 | nextstop_offset = bfd_asymbol_value (sym) - section->vma; | |
155e0d23 NC |
1809 | else if (nextsym == NULL) |
1810 | nextstop_offset = stop_offset; | |
1811 | else | |
22a398e1 NC |
1812 | nextstop_offset = bfd_asymbol_value (nextsym) - section->vma; |
1813 | ||
1814 | if (nextstop_offset > stop_offset) | |
1815 | nextstop_offset = stop_offset; | |
155e0d23 NC |
1816 | |
1817 | /* If a symbol is explicitly marked as being an object | |
1818 | rather than a function, just dump the bytes without | |
1819 | disassembling them. */ | |
1820 | if (disassemble_all | |
1821 | || sym == NULL | |
22a398e1 | 1822 | || bfd_asymbol_value (sym) > addr |
155e0d23 NC |
1823 | || ((sym->flags & BSF_OBJECT) == 0 |
1824 | && (strstr (bfd_asymbol_name (sym), "gnu_compiled") | |
1825 | == NULL) | |
1826 | && (strstr (bfd_asymbol_name (sym), "gcc2_compiled") | |
1827 | == NULL)) | |
1828 | || (sym->flags & BSF_FUNCTION) != 0) | |
1829 | insns = TRUE; | |
1830 | else | |
1831 | insns = FALSE; | |
1832 | ||
1833 | disassemble_bytes (pinfo, paux->disassemble_fn, insns, data, | |
1834 | addr_offset, nextstop_offset, | |
1835 | rel_offset, &rel_pp, rel_ppend); | |
1836 | ||
1837 | addr_offset = nextstop_offset; | |
1838 | sym = nextsym; | |
1839 | } | |
1840 | ||
1841 | free (data); | |
1842 | ||
1843 | if (rel_ppstart != NULL) | |
1844 | free (rel_ppstart); | |
1845 | } | |
1846 | ||
252b5132 RH |
1847 | /* Disassemble the contents of an object file. */ |
1848 | ||
1849 | static void | |
46dca2e0 | 1850 | disassemble_data (bfd *abfd) |
252b5132 | 1851 | { |
252b5132 RH |
1852 | struct disassemble_info disasm_info; |
1853 | struct objdump_disasm_info aux; | |
4c45e5c9 | 1854 | long i; |
252b5132 RH |
1855 | |
1856 | print_files = NULL; | |
1857 | prev_functionname = NULL; | |
1858 | prev_line = -1; | |
1859 | ||
1860 | /* We make a copy of syms to sort. We don't want to sort syms | |
1861 | because that will screw up the relocs. */ | |
4c45e5c9 JJ |
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 *)); | |
252b5132 | 1866 | |
4c45e5c9 JJ |
1867 | sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount); |
1868 | ||
1869 | for (i = 0; i < synthcount; ++i) | |
1870 | { | |
1871 | sorted_syms[sorted_symcount] = synthsyms + i; | |
1872 | ++sorted_symcount; | |
1873 | } | |
252b5132 | 1874 | |
98a91d6a | 1875 | /* Sort the symbols into section and symbol order. */ |
252b5132 RH |
1876 | qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols); |
1877 | ||
22a398e1 | 1878 | init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf); |
98a91d6a | 1879 | |
46dca2e0 | 1880 | disasm_info.application_data = (void *) &aux; |
252b5132 | 1881 | aux.abfd = abfd; |
b34976b6 | 1882 | aux.require_sec = FALSE; |
155e0d23 NC |
1883 | aux.dynrelbuf = NULL; |
1884 | aux.dynrelcount = 0; | |
ce04548a NC |
1885 | #ifdef DISASSEMBLER_NEEDS_RELOCS |
1886 | aux.reloc = NULL; | |
1887 | #endif | |
155e0d23 | 1888 | |
252b5132 RH |
1889 | disasm_info.print_address_func = objdump_print_address; |
1890 | disasm_info.symbol_at_address_func = objdump_symbol_at_address; | |
1891 | ||
d3ba0551 | 1892 | if (machine != NULL) |
252b5132 RH |
1893 | { |
1894 | const bfd_arch_info_type *info = bfd_scan_arch (machine); | |
98a91d6a | 1895 | |
252b5132 | 1896 | if (info == NULL) |
98a91d6a NC |
1897 | fatal (_("Can't use supplied machine %s"), machine); |
1898 | ||
252b5132 RH |
1899 | abfd->arch_info = info; |
1900 | } | |
1901 | ||
1902 | if (endian != BFD_ENDIAN_UNKNOWN) | |
1903 | { | |
1904 | struct bfd_target *xvec; | |
1905 | ||
d3ba0551 | 1906 | xvec = xmalloc (sizeof (struct bfd_target)); |
252b5132 RH |
1907 | memcpy (xvec, abfd->xvec, sizeof (struct bfd_target)); |
1908 | xvec->byteorder = endian; | |
1909 | abfd->xvec = xvec; | |
1910 | } | |
1911 | ||
155e0d23 NC |
1912 | /* Use libopcodes to locate a suitable disassembler. */ |
1913 | aux.disassemble_fn = disassembler (abfd); | |
1914 | if (!aux.disassemble_fn) | |
252b5132 | 1915 | { |
37cc8ec1 AM |
1916 | non_fatal (_("Can't disassemble for architecture %s\n"), |
1917 | bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); | |
75cd796a | 1918 | exit_status = 1; |
252b5132 RH |
1919 | return; |
1920 | } | |
1921 | ||
1922 | disasm_info.flavour = bfd_get_flavour (abfd); | |
1923 | disasm_info.arch = bfd_get_arch (abfd); | |
1924 | disasm_info.mach = bfd_get_mach (abfd); | |
dd92f639 | 1925 | disasm_info.disassembler_options = disassembler_options; |
155e0d23 | 1926 | disasm_info.octets_per_byte = bfd_octets_per_byte (abfd); |
0bcb06d2 AS |
1927 | disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES; |
1928 | disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END; | |
0af11b59 | 1929 | |
252b5132 | 1930 | if (bfd_big_endian (abfd)) |
a8a9050d | 1931 | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG; |
252b5132 | 1932 | else if (bfd_little_endian (abfd)) |
a8a9050d | 1933 | disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE; |
252b5132 RH |
1934 | else |
1935 | /* ??? Aborting here seems too drastic. We could default to big or little | |
1936 | instead. */ | |
1937 | disasm_info.endian = BFD_ENDIAN_UNKNOWN; | |
1938 | ||
22a398e1 NC |
1939 | /* Allow the target to customize the info structure. */ |
1940 | disassemble_init_for_target (& disasm_info); | |
1941 | ||
155e0d23 NC |
1942 | /* Pre-load the dynamic relocs if we are going |
1943 | to be dumping them along with the disassembly. */ | |
fd7bb956 AM |
1944 | if (dump_dynamic_reloc_info) |
1945 | { | |
1946 | long relsize = bfd_get_dynamic_reloc_upper_bound (abfd); | |
155e0d23 | 1947 | |
fd7bb956 AM |
1948 | if (relsize < 0) |
1949 | bfd_fatal (bfd_get_filename (abfd)); | |
1950 | ||
1951 | if (relsize > 0) | |
1952 | { | |
155e0d23 | 1953 | aux.dynrelbuf = xmalloc (relsize); |
3b9ad1cc AM |
1954 | aux.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, |
1955 | aux.dynrelbuf, | |
1956 | dynsyms); | |
155e0d23 | 1957 | if (aux.dynrelcount < 0) |
fd7bb956 AM |
1958 | bfd_fatal (bfd_get_filename (abfd)); |
1959 | ||
1960 | /* Sort the relocs by address. */ | |
3b9ad1cc AM |
1961 | qsort (aux.dynrelbuf, aux.dynrelcount, sizeof (arelent *), |
1962 | compare_relocs); | |
fd7bb956 AM |
1963 | } |
1964 | } | |
1965 | ||
155e0d23 | 1966 | bfd_map_over_sections (abfd, disassemble_section, & disasm_info); |
98a91d6a | 1967 | |
155e0d23 NC |
1968 | if (aux.dynrelbuf != NULL) |
1969 | free (aux.dynrelbuf); | |
252b5132 RH |
1970 | free (sorted_syms); |
1971 | } | |
1972 | \f | |
365544c3 L |
1973 | int |
1974 | load_debug_section (enum dwarf_section_display_enum debug, void *file) | |
1975 | { | |
1976 | struct dwarf_section *section = &debug_displays [debug].section; | |
1977 | bfd *abfd = file; | |
1978 | asection *sec; | |
1979 | bfd_boolean ret; | |
1980 | ||
1981 | /* If it is already loaded, do nothing. */ | |
1982 | if (section->start != NULL) | |
1983 | return 1; | |
1984 | ||
1985 | /* Locate the debug section. */ | |
1986 | sec = bfd_get_section_by_name (abfd, section->name); | |
1987 | if (sec == NULL) | |
1988 | return 0; | |
1989 | ||
1990 | section->address = bfd_get_section_vma (abfd, sec); | |
1991 | section->size = bfd_get_section_size (sec); | |
1992 | section->start = xmalloc (section->size); | |
1993 | ||
1994 | if (is_relocatable && debug_displays [debug].relocate) | |
1995 | ret = bfd_simple_get_relocated_section_contents (abfd, | |
1996 | sec, | |
1997 | section->start, | |
1998 | syms) != NULL; | |
1999 | else | |
2000 | ret = bfd_get_section_contents (abfd, sec, section->start, 0, | |
2001 | section->size); | |
2002 | ||
2003 | if (!ret) | |
2004 | { | |
2005 | free_debug_section (debug); | |
2006 | printf (_("\nCan't get contents for section '%s'.\n"), | |
2007 | section->name); | |
2008 | } | |
2009 | ||
2010 | return ret; | |
2011 | } | |
2012 | ||
2013 | void | |
2014 | free_debug_section (enum dwarf_section_display_enum debug) | |
2015 | { | |
2016 | struct dwarf_section *section = &debug_displays [debug].section; | |
2017 | ||
2018 | if (section->start == NULL) | |
2019 | return; | |
2020 | ||
2021 | free ((char *) section->start); | |
2022 | section->start = NULL; | |
2023 | section->address = 0; | |
2024 | section->size = 0; | |
2025 | } | |
2026 | ||
2027 | static void | |
2028 | dump_dwarf_section (bfd *abfd, asection *section, | |
2029 | void *arg ATTRIBUTE_UNUSED) | |
2030 | { | |
2031 | const char *name = bfd_get_section_name (abfd, section); | |
2032 | const char *match; | |
2033 | enum dwarf_section_display_enum i; | |
2034 | ||
2035 | if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0) | |
2036 | match = ".debug_info"; | |
2037 | else | |
2038 | match = name; | |
2039 | ||
2040 | for (i = 0; i < max; i++) | |
2041 | if (strcmp (debug_displays[i].section.name, match) == 0) | |
2042 | { | |
2043 | if (!debug_displays[i].eh_frame) | |
2044 | { | |
2045 | struct dwarf_section *sec = &debug_displays [i].section; | |
2046 | ||
2047 | if (load_debug_section (i, abfd)) | |
2048 | { | |
2049 | debug_displays[i].display (sec, abfd); | |
2050 | ||
2051 | if (i != info && i != abbrev) | |
2052 | free_debug_section (i); | |
2053 | } | |
2054 | } | |
2055 | break; | |
2056 | } | |
2057 | } | |
2058 | ||
bfe2612a L |
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 */ | |
2076 | }; | |
2077 | ||
2078 | static const char *generic_dwarf_sections [max]; | |
2079 | ||
2080 | static void | |
2081 | check_mach_o_dwarf (bfd *abfd) | |
2082 | { | |
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; | |
2086 | ||
2087 | if (generic_dwarf_sections [0] == NULL) | |
2088 | for (i = 0; i < max; i++) | |
2089 | generic_dwarf_sections [i] = debug_displays[i].section.name; | |
2090 | ||
2091 | if (old_flavour != current_flavour) | |
2092 | { | |
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]; | |
2099 | ||
2100 | old_flavour = current_flavour; | |
2101 | } | |
2102 | } | |
2103 | ||
365544c3 L |
2104 | /* Dump the dwarf debugging information. */ |
2105 | ||
2106 | static void | |
2107 | dump_dwarf (bfd *abfd) | |
2108 | { | |
2109 | is_relocatable = ((abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC)) | |
2110 | == HAS_RELOC); | |
2111 | ||
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; | |
2115 | ||
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; | |
2120 | else | |
2121 | abort (); | |
2122 | ||
bfe2612a L |
2123 | check_mach_o_dwarf (abfd); |
2124 | ||
365544c3 L |
2125 | bfd_map_over_sections (abfd, dump_dwarf_section, NULL); |
2126 | ||
2127 | free_debug_memory (); | |
2128 | } | |
2129 | \f | |
29ca8dc5 NS |
2130 | /* Read ABFD's stabs section STABSECT_NAME, and return a pointer to |
2131 | it. Return NULL on failure. */ | |
252b5132 | 2132 | |
29ca8dc5 NS |
2133 | static char * |
2134 | read_section_stabs (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr) | |
252b5132 | 2135 | { |
29ca8dc5 NS |
2136 | asection *stabsect; |
2137 | bfd_size_type size; | |
2138 | char *contents; | |
252b5132 | 2139 | |
29ca8dc5 | 2140 | stabsect = bfd_get_section_by_name (abfd, sect_name); |
155e0d23 | 2141 | if (stabsect == NULL) |
252b5132 | 2142 | { |
29ca8dc5 | 2143 | printf (_("No %s section present\n\n"), sect_name); |
b34976b6 | 2144 | return FALSE; |
252b5132 RH |
2145 | } |
2146 | ||
29ca8dc5 NS |
2147 | size = bfd_section_size (abfd, stabsect); |
2148 | contents = xmalloc (size); | |
0af11b59 | 2149 | |
29ca8dc5 | 2150 | if (! bfd_get_section_contents (abfd, stabsect, contents, 0, size)) |
252b5132 | 2151 | { |
37cc8ec1 | 2152 | non_fatal (_("Reading %s section of %s failed: %s"), |
29ca8dc5 | 2153 | sect_name, bfd_get_filename (abfd), |
37cc8ec1 | 2154 | bfd_errmsg (bfd_get_error ())); |
29ca8dc5 | 2155 | free (contents); |
75cd796a | 2156 | exit_status = 1; |
29ca8dc5 | 2157 | return NULL; |
252b5132 RH |
2158 | } |
2159 | ||
29ca8dc5 | 2160 | *size_ptr = size; |
252b5132 | 2161 | |
29ca8dc5 | 2162 | return contents; |
252b5132 RH |
2163 | } |
2164 | ||
2165 | /* Stabs entries use a 12 byte format: | |
2166 | 4 byte string table index | |
2167 | 1 byte stab type | |
2168 | 1 byte stab other field | |
2169 | 2 byte stab desc field | |
2170 | 4 byte stab value | |
2171 | FIXME: This will have to change for a 64 bit object format. */ | |
2172 | ||
46dca2e0 NC |
2173 | #define STRDXOFF (0) |
2174 | #define TYPEOFF (4) | |
2175 | #define OTHEROFF (5) | |
2176 | #define DESCOFF (6) | |
2177 | #define VALOFF (8) | |
252b5132 RH |
2178 | #define STABSIZE (12) |
2179 | ||
2180 | /* Print ABFD's stabs section STABSECT_NAME (in `stabs'), | |
2181 | using string table section STRSECT_NAME (in `strtab'). */ | |
2182 | ||
2183 | static void | |
3b9ad1cc AM |
2184 | print_section_stabs (bfd *abfd, |
2185 | const char *stabsect_name, | |
2186 | unsigned *string_offset_ptr) | |
252b5132 RH |
2187 | { |
2188 | int i; | |
46dca2e0 | 2189 | unsigned file_string_table_offset = 0; |
29ca8dc5 | 2190 | unsigned next_file_string_table_offset = *string_offset_ptr; |
252b5132 RH |
2191 | bfd_byte *stabp, *stabs_end; |
2192 | ||
2193 | stabp = stabs; | |
2194 | stabs_end = stabp + stab_size; | |
2195 | ||
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"); | |
2198 | ||
2199 | /* Loop through all symbols and print them. | |
2200 | ||
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. */ | |
252b5132 RH |
2203 | for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++) |
2204 | { | |
2205 | const char *name; | |
2206 | unsigned long strx; | |
2207 | unsigned char type, other; | |
2208 | unsigned short desc; | |
2209 | bfd_vma value; | |
2210 | ||
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); | |
2216 | ||
2217 | printf ("\n%-6d ", i); | |
2218 | /* Either print the stab name, or, if unnamed, print its number | |
0af11b59 | 2219 | again (makes consistent formatting for tools like awk). */ |
252b5132 RH |
2220 | name = bfd_get_stab_name (type); |
2221 | if (name != NULL) | |
2222 | printf ("%-6s", name); | |
2223 | else if (type == N_UNDF) | |
2224 | printf ("HdrSym"); | |
2225 | else | |
2226 | printf ("%-6d", type); | |
2227 | printf (" %-6d %-6d ", other, desc); | |
d8180c76 | 2228 | bfd_printf_vma (abfd, value); |
252b5132 RH |
2229 | printf (" %-6lu", strx); |
2230 | ||
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. */ | |
252b5132 RH |
2234 | if (type == N_UNDF) |
2235 | { | |
2236 | file_string_table_offset = next_file_string_table_offset; | |
2237 | next_file_string_table_offset += value; | |
2238 | } | |
2239 | else | |
2240 | { | |
2241 | /* Using the (possibly updated) string table offset, print the | |
2242 | string (if any) associated with this symbol. */ | |
252b5132 RH |
2243 | if ((strx + file_string_table_offset) < stabstr_size) |
2244 | printf (" %s", &strtab[strx + file_string_table_offset]); | |
2245 | else | |
2246 | printf (" *"); | |
2247 | } | |
2248 | } | |
2249 | printf ("\n\n"); | |
29ca8dc5 | 2250 | *string_offset_ptr = next_file_string_table_offset; |
252b5132 RH |
2251 | } |
2252 | ||
155e0d23 NC |
2253 | typedef struct |
2254 | { | |
2255 | const char * section_name; | |
2256 | const char * string_section_name; | |
29ca8dc5 | 2257 | unsigned string_offset; |
155e0d23 NC |
2258 | } |
2259 | stab_section_names; | |
2260 | ||
252b5132 | 2261 | static void |
155e0d23 | 2262 | find_stabs_section (bfd *abfd, asection *section, void *names) |
252b5132 | 2263 | { |
155e0d23 NC |
2264 | int len; |
2265 | stab_section_names * sought = (stab_section_names *) names; | |
252b5132 RH |
2266 | |
2267 | /* Check for section names for which stabsect_name is a prefix, to | |
29ca8dc5 | 2268 | handle .stab.N, etc. */ |
155e0d23 NC |
2269 | len = strlen (sought->section_name); |
2270 | ||
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 | |
29ca8dc5 | 2276 | || (section->name[len] == '.' && ISDIGIT (section->name[len + 1])))) |
252b5132 | 2277 | { |
29ca8dc5 NS |
2278 | if (strtab == NULL) |
2279 | strtab = read_section_stabs (abfd, sought->string_section_name, | |
2280 | &stabstr_size); | |
2281 | ||
2282 | if (strtab) | |
252b5132 | 2283 | { |
9210d879 AM |
2284 | stabs = (bfd_byte *) read_section_stabs (abfd, section->name, |
2285 | &stab_size); | |
29ca8dc5 NS |
2286 | if (stabs) |
2287 | print_section_stabs (abfd, section->name, &sought->string_offset); | |
252b5132 RH |
2288 | } |
2289 | } | |
2290 | } | |
98a91d6a | 2291 | |
155e0d23 NC |
2292 | static void |
2293 | dump_stabs_section (bfd *abfd, char *stabsect_name, char *strsect_name) | |
2294 | { | |
2295 | stab_section_names s; | |
2296 | ||
2297 | s.section_name = stabsect_name; | |
2298 | s.string_section_name = strsect_name; | |
29ca8dc5 NS |
2299 | s.string_offset = 0; |
2300 | ||
155e0d23 | 2301 | bfd_map_over_sections (abfd, find_stabs_section, & s); |
29ca8dc5 NS |
2302 | |
2303 | free (strtab); | |
2304 | strtab = NULL; | |
155e0d23 NC |
2305 | } |
2306 | ||
2307 | /* Dump the any sections containing stabs debugging information. */ | |
2308 | ||
2309 | static void | |
2310 | dump_stabs (bfd *abfd) | |
2311 | { | |
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$"); | |
2316 | } | |
252b5132 RH |
2317 | \f |
2318 | static void | |
46dca2e0 | 2319 | dump_bfd_header (bfd *abfd) |
252b5132 RH |
2320 | { |
2321 | char *comma = ""; | |
2322 | ||
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); | |
2327 | ||
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"); | |
026df7c5 | 2339 | PF (HAS_LOAD_PAGE, "HAS_LOAD_PAGE"); |
252b5132 | 2340 | printf (_("\nstart address 0x")); |
d8180c76 | 2341 | bfd_printf_vma (abfd, abfd->start_address); |
252b5132 RH |
2342 | printf ("\n"); |
2343 | } | |
98a91d6a | 2344 | |
252b5132 RH |
2345 | \f |
2346 | static void | |
46dca2e0 | 2347 | dump_bfd_private_header (bfd *abfd) |
252b5132 RH |
2348 | { |
2349 | bfd_print_private_bfd_data (abfd, stdout); | |
2350 | } | |
2351 | ||
155e0d23 NC |
2352 | \f |
2353 | /* Display a section in hexadecimal format with associated characters. | |
2354 | Each line prefixed by the zero padded address. */ | |
d24de309 | 2355 | |
252b5132 | 2356 | static void |
155e0d23 | 2357 | dump_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED) |
252b5132 | 2358 | { |
155e0d23 NC |
2359 | bfd_byte *data = 0; |
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; | |
2367 | char buf[64]; | |
2368 | int count; | |
2369 | int width; | |
2370 | ||
2371 | if ((section->flags & SEC_HAS_CONTENTS) == 0) | |
2372 | return; | |
2373 | ||
2374 | if (! process_section_p (section)) | |
2375 | return; | |
2376 | ||
2377 | if ((datasize = bfd_section_size (abfd, section)) == 0) | |
2378 | return; | |
2379 | ||
2380 | printf (_("Contents of section %s:\n"), section->name); | |
2381 | ||
2382 | data = xmalloc (datasize); | |
2383 | ||
2384 | bfd_get_section_contents (abfd, section, data, 0, datasize); | |
2385 | ||
2386 | /* Compute the address range to display. */ | |
2387 | if (start_address == (bfd_vma) -1 | |
2388 | || start_address < section->vma) | |
2389 | start_offset = 0; | |
2390 | else | |
2391 | start_offset = start_address - section->vma; | |
2392 | ||
2393 | if (stop_address == (bfd_vma) -1) | |
2394 | stop_offset = datasize / opb; | |
2395 | else | |
252b5132 | 2396 | { |
155e0d23 NC |
2397 | if (stop_address < section->vma) |
2398 | stop_offset = 0; | |
2399 | else | |
2400 | stop_offset = stop_address - section->vma; | |
252b5132 | 2401 | |
155e0d23 NC |
2402 | if (stop_offset > datasize / opb) |
2403 | stop_offset = datasize / opb; | |
252b5132 RH |
2404 | } |
2405 | ||
155e0d23 | 2406 | width = 4; |
026df7c5 | 2407 | |
155e0d23 NC |
2408 | bfd_sprintf_vma (abfd, buf, start_offset + section->vma); |
2409 | if (strlen (buf) >= sizeof (buf)) | |
2410 | abort (); | |
026df7c5 | 2411 | |
155e0d23 NC |
2412 | count = 0; |
2413 | while (buf[count] == '0' && buf[count+1] != '\0') | |
2414 | count++; | |
2415 | count = strlen (buf) - count; | |
2416 | if (count > width) | |
2417 | width = count; | |
252b5132 | 2418 | |
155e0d23 NC |
2419 | bfd_sprintf_vma (abfd, buf, stop_offset + section->vma - 1); |
2420 | if (strlen (buf) >= sizeof (buf)) | |
2421 | abort (); | |
026df7c5 | 2422 | |
155e0d23 NC |
2423 | count = 0; |
2424 | while (buf[count] == '0' && buf[count+1] != '\0') | |
2425 | count++; | |
2426 | count = strlen (buf) - count; | |
2427 | if (count > width) | |
2428 | width = count; | |
026df7c5 | 2429 | |
155e0d23 NC |
2430 | for (addr_offset = start_offset; |
2431 | addr_offset < stop_offset; addr_offset += onaline / opb) | |
d24de309 | 2432 | { |
155e0d23 | 2433 | bfd_size_type j; |
d24de309 | 2434 | |
155e0d23 NC |
2435 | bfd_sprintf_vma (abfd, buf, (addr_offset + section->vma)); |
2436 | count = strlen (buf); | |
2437 | if ((size_t) count >= sizeof (buf)) | |
2438 | abort (); | |
d24de309 | 2439 | |
155e0d23 NC |
2440 | putchar (' '); |
2441 | while (count < width) | |
252b5132 | 2442 | { |
155e0d23 NC |
2443 | putchar ('0'); |
2444 | count++; | |
2445 | } | |
2446 | fputs (buf + count - width, stdout); | |
2447 | putchar (' '); | |
252b5132 | 2448 | |
155e0d23 NC |
2449 | for (j = addr_offset * opb; |
2450 | j < addr_offset * opb + onaline; j++) | |
2451 | { | |
2452 | if (j < stop_offset * opb) | |
2453 | printf ("%02x", (unsigned) (data[j])); | |
2454 | else | |
2455 | printf (" "); | |
2456 | if ((j & 3) == 3) | |
2457 | printf (" "); | |
252b5132 RH |
2458 | } |
2459 | ||
155e0d23 NC |
2460 | printf (" "); |
2461 | for (j = addr_offset * opb; | |
2462 | j < addr_offset * opb + onaline; j++) | |
2463 | { | |
2464 | if (j >= stop_offset * opb) | |
2465 | printf (" "); | |
2466 | else | |
2467 | printf ("%c", ISPRINT (data[j]) ? data[j] : '.'); | |
2468 | } | |
2469 | putchar ('\n'); | |
252b5132 | 2470 | } |
155e0d23 | 2471 | free (data); |
252b5132 | 2472 | } |
155e0d23 | 2473 | |
98a91d6a | 2474 | /* Actually display the various requested regions. */ |
252b5132 RH |
2475 | |
2476 | static void | |
46dca2e0 | 2477 | dump_data (bfd *abfd) |
252b5132 | 2478 | { |
155e0d23 | 2479 | bfd_map_over_sections (abfd, dump_section, NULL); |
252b5132 RH |
2480 | } |
2481 | ||
98a91d6a NC |
2482 | /* Should perhaps share code and display with nm? */ |
2483 | ||
252b5132 | 2484 | static void |
46dca2e0 | 2485 | dump_symbols (bfd *abfd ATTRIBUTE_UNUSED, bfd_boolean dynamic) |
252b5132 RH |
2486 | { |
2487 | asymbol **current; | |
2488 | long max; | |
2489 | long count; | |
2490 | ||
2491 | if (dynamic) | |
2492 | { | |
2493 | current = dynsyms; | |
2494 | max = dynsymcount; | |
252b5132 RH |
2495 | printf ("DYNAMIC SYMBOL TABLE:\n"); |
2496 | } | |
2497 | else | |
2498 | { | |
2499 | current = syms; | |
2500 | max = symcount; | |
252b5132 RH |
2501 | printf ("SYMBOL TABLE:\n"); |
2502 | } | |
2503 | ||
a1df01d1 AM |
2504 | if (max == 0) |
2505 | printf (_("no symbols\n")); | |
2506 | ||
252b5132 RH |
2507 | for (count = 0; count < max; count++) |
2508 | { | |
155e0d23 NC |
2509 | bfd *cur_bfd; |
2510 | ||
2511 | if (*current == NULL) | |
83ef0798 | 2512 | printf (_("no information for symbol number %ld\n"), count); |
155e0d23 NC |
2513 | |
2514 | else if ((cur_bfd = bfd_asymbol_bfd (*current)) == NULL) | |
83ef0798 | 2515 | printf (_("could not determine the type of symbol number %ld\n"), |
155e0d23 NC |
2516 | count); |
2517 | ||
661f7c35 NC |
2518 | else if (process_section_p ((* current)->section) |
2519 | && (dump_special_syms | |
2520 | || !bfd_is_target_special_symbol (cur_bfd, *current))) | |
252b5132 | 2521 | { |
155e0d23 | 2522 | const char *name = (*current)->name; |
252b5132 | 2523 | |
155e0d23 | 2524 | if (do_demangle && name != NULL && *name != '\0') |
252b5132 | 2525 | { |
252b5132 RH |
2526 | char *alloc; |
2527 | ||
155e0d23 NC |
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; | |
252b5132 RH |
2533 | bfd_print_symbol (cur_bfd, stdout, *current, |
2534 | bfd_print_symbol_all); | |
252b5132 | 2535 | (*current)->name = name; |
155e0d23 | 2536 | free (alloc); |
252b5132 | 2537 | } |
252b5132 | 2538 | else |
155e0d23 NC |
2539 | bfd_print_symbol (cur_bfd, stdout, *current, |
2540 | bfd_print_symbol_all); | |
83ef0798 | 2541 | printf ("\n"); |
252b5132 | 2542 | } |
661f7c35 | 2543 | |
155e0d23 | 2544 | current++; |
252b5132 | 2545 | } |
155e0d23 | 2546 | printf ("\n\n"); |
252b5132 | 2547 | } |
155e0d23 | 2548 | \f |
252b5132 | 2549 | static void |
46dca2e0 | 2550 | dump_reloc_set (bfd *abfd, asection *sec, arelent **relpp, long relcount) |
252b5132 RH |
2551 | { |
2552 | arelent **p; | |
2553 | char *last_filename, *last_functionname; | |
2554 | unsigned int last_line; | |
2555 | ||
2556 | /* Get column headers lined up reasonably. */ | |
2557 | { | |
2558 | static int width; | |
98a91d6a | 2559 | |
252b5132 RH |
2560 | if (width == 0) |
2561 | { | |
2562 | char buf[30]; | |
155e0d23 | 2563 | |
d8180c76 | 2564 | bfd_sprintf_vma (abfd, buf, (bfd_vma) -1); |
252b5132 RH |
2565 | width = strlen (buf) - 7; |
2566 | } | |
2567 | printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, ""); | |
2568 | } | |
2569 | ||
2570 | last_filename = NULL; | |
2571 | last_functionname = NULL; | |
2572 | last_line = 0; | |
2573 | ||
d3ba0551 | 2574 | for (p = relpp; relcount && *p != NULL; p++, relcount--) |
252b5132 RH |
2575 | { |
2576 | arelent *q = *p; | |
2577 | const char *filename, *functionname; | |
2578 | unsigned int line; | |
2579 | const char *sym_name; | |
2580 | const char *section_name; | |
2581 | ||
2582 | if (start_address != (bfd_vma) -1 | |
2583 | && q->address < start_address) | |
2584 | continue; | |
2585 | if (stop_address != (bfd_vma) -1 | |
2586 | && q->address > stop_address) | |
2587 | continue; | |
2588 | ||
2589 | if (with_line_numbers | |
2590 | && sec != NULL | |
2591 | && bfd_find_nearest_line (abfd, sec, syms, q->address, | |
2592 | &filename, &functionname, &line)) | |
2593 | { | |
2594 | if (functionname != NULL | |
2595 | && (last_functionname == NULL | |
2596 | || strcmp (functionname, last_functionname) != 0)) | |
2597 | { | |
2598 | printf ("%s():\n", functionname); | |
2599 | if (last_functionname != NULL) | |
2600 | free (last_functionname); | |
2601 | last_functionname = xstrdup (functionname); | |
2602 | } | |
98a91d6a | 2603 | |
252b5132 RH |
2604 | if (line > 0 |
2605 | && (line != last_line | |
2606 | || (filename != NULL | |
2607 | && last_filename != NULL | |
2608 | && strcmp (filename, last_filename) != 0))) | |
2609 | { | |
2610 | printf ("%s:%u\n", filename == NULL ? "???" : filename, line); | |
2611 | last_line = line; | |
2612 | if (last_filename != NULL) | |
2613 | free (last_filename); | |
2614 | if (filename == NULL) | |
2615 | last_filename = NULL; | |
2616 | else | |
2617 | last_filename = xstrdup (filename); | |
2618 | } | |
2619 | } | |
2620 | ||
2621 | if (q->sym_ptr_ptr && *q->sym_ptr_ptr) | |
2622 | { | |
2623 | sym_name = (*(q->sym_ptr_ptr))->name; | |
2624 | section_name = (*(q->sym_ptr_ptr))->section->name; | |
2625 | } | |
2626 | else | |
2627 | { | |
2628 | sym_name = NULL; | |
2629 | section_name = NULL; | |
2630 | } | |
98a91d6a | 2631 | |
f9ecb0a4 JJ |
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); | |
2637 | else | |
2638 | printf (" %-16d ", q->howto->type); | |
252b5132 | 2639 | if (sym_name) |
f9ecb0a4 | 2640 | objdump_print_symname (abfd, NULL, *q->sym_ptr_ptr); |
252b5132 RH |
2641 | else |
2642 | { | |
d3ba0551 | 2643 | if (section_name == NULL) |
252b5132 | 2644 | section_name = "*unknown*"; |
f9ecb0a4 | 2645 | printf ("[%s]", section_name); |
252b5132 | 2646 | } |
98a91d6a | 2647 | |
252b5132 RH |
2648 | if (q->addend) |
2649 | { | |
2650 | printf ("+0x"); | |
d8180c76 | 2651 | bfd_printf_vma (abfd, q->addend); |
252b5132 | 2652 | } |
98a91d6a | 2653 | |
252b5132 RH |
2654 | printf ("\n"); |
2655 | } | |
2656 | } | |
43ac9881 | 2657 | |
155e0d23 | 2658 | static void |
3b9ad1cc AM |
2659 | dump_relocs_in_section (bfd *abfd, |
2660 | asection *section, | |
2661 | void *dummy ATTRIBUTE_UNUSED) | |
155e0d23 NC |
2662 | { |
2663 | arelent **relpp; | |
2664 | long relcount; | |
2665 | long relsize; | |
2666 | ||
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)) | |
2672 | return; | |
2673 | ||
2674 | relsize = bfd_get_reloc_upper_bound (abfd, section); | |
2675 | if (relsize < 0) | |
2676 | bfd_fatal (bfd_get_filename (abfd)); | |
2677 | ||
2678 | printf ("RELOCATION RECORDS FOR [%s]:", section->name); | |
2679 | ||
2680 | if (relsize == 0) | |
2681 | { | |
2682 | printf (" (none)\n\n"); | |
2683 | return; | |
2684 | } | |
2685 | ||
2686 | relpp = xmalloc (relsize); | |
2687 | relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms); | |
2688 | ||
2689 | if (relcount < 0) | |
2690 | bfd_fatal (bfd_get_filename (abfd)); | |
2691 | else if (relcount == 0) | |
2692 | printf (" (none)\n\n"); | |
2693 | else | |
2694 | { | |
2695 | printf ("\n"); | |
2696 | dump_reloc_set (abfd, section, relpp, relcount); | |
2697 | printf ("\n\n"); | |
2698 | } | |
2699 | free (relpp); | |
2700 | } | |
2701 | ||
2702 | static void | |
2703 | dump_relocs (bfd *abfd) | |
2704 | { | |
2705 | bfd_map_over_sections (abfd, dump_relocs_in_section, NULL); | |
2706 | } | |
2707 | ||
2708 | static void | |
2709 | dump_dynamic_relocs (bfd *abfd) | |
2710 | { | |
2711 | long relsize; | |
2712 | arelent **relpp; | |
2713 | long relcount; | |
2714 | ||
2715 | relsize = bfd_get_dynamic_reloc_upper_bound (abfd); | |
2716 | if (relsize < 0) | |
2717 | bfd_fatal (bfd_get_filename (abfd)); | |
2718 | ||
2719 | printf ("DYNAMIC RELOCATION RECORDS"); | |
2720 | ||
2721 | if (relsize == 0) | |
2722 | printf (" (none)\n\n"); | |
2723 | else | |
2724 | { | |
2725 | relpp = xmalloc (relsize); | |
2726 | relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms); | |
2727 | ||
2728 | if (relcount < 0) | |
2729 | bfd_fatal (bfd_get_filename (abfd)); | |
2730 | else if (relcount == 0) | |
2731 | printf (" (none)\n\n"); | |
2732 | else | |
2733 | { | |
2734 | printf ("\n"); | |
2735 | dump_reloc_set (abfd, NULL, relpp, relcount); | |
2736 | printf ("\n\n"); | |
2737 | } | |
2738 | free (relpp); | |
2739 | } | |
2740 | } | |
2741 | ||
43ac9881 AM |
2742 | /* Creates a table of paths, to search for source files. */ |
2743 | ||
2744 | static void | |
2745 | add_include_path (const char *path) | |
2746 | { | |
2747 | if (path[0] == 0) | |
2748 | return; | |
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); | |
2755 | #endif | |
2756 | include_paths[include_path_count - 1] = path; | |
2757 | } | |
155e0d23 NC |
2758 | |
2759 | static void | |
3b9ad1cc AM |
2760 | adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED, |
2761 | asection *section, | |
bc79cded | 2762 | void *arg) |
155e0d23 | 2763 | { |
bc79cded L |
2764 | if ((section->flags & SEC_DEBUGGING) == 0) |
2765 | { | |
2766 | bfd_boolean *has_reloc_p = (bfd_boolean *) arg; | |
2767 | section->vma += adjust_section_vma; | |
2768 | if (*has_reloc_p) | |
2769 | section->lma += adjust_section_vma; | |
2770 | } | |
155e0d23 NC |
2771 | } |
2772 | ||
2773 | /* Dump selected contents of ABFD. */ | |
2774 | ||
2775 | static void | |
2776 | dump_bfd (bfd *abfd) | |
2777 | { | |
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) | |
bc79cded L |
2782 | { |
2783 | bfd_boolean has_reloc = (abfd->flags & HAS_RELOC); | |
2784 | bfd_map_over_sections (abfd, adjust_addresses, &has_reloc); | |
2785 | } | |
155e0d23 NC |
2786 | |
2787 | if (! dump_debugging_tags) | |
2788 | printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd), | |
2789 | abfd->xvec->name); | |
2790 | if (dump_ar_hdrs) | |
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) | |
2797 | putchar ('\n'); | |
2798 | if (dump_section_headers) | |
2799 | dump_headers (abfd); | |
2800 | ||
365544c3 L |
2801 | if (dump_symtab |
2802 | || dump_reloc_info | |
2803 | || disassemble | |
2804 | || dump_debugging | |
2805 | || dump_dwarf_section_info) | |
155e0d23 | 2806 | syms = slurp_symtab (abfd); |
4c45e5c9 JJ |
2807 | if (dump_dynamic_symtab || dump_dynamic_reloc_info |
2808 | || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0)) | |
155e0d23 | 2809 | dynsyms = slurp_dynamic_symtab (abfd); |
90e3cdf2 | 2810 | if (disassemble) |
4c45e5c9 | 2811 | { |
c9727e01 AM |
2812 | synthcount = bfd_get_synthetic_symtab (abfd, symcount, syms, |
2813 | dynsymcount, dynsyms, &synthsyms); | |
2814 | if (synthcount < 0) | |
2815 | synthcount = 0; | |
4c45e5c9 | 2816 | } |
155e0d23 NC |
2817 | |
2818 | if (dump_symtab) | |
2819 | dump_symbols (abfd, FALSE); | |
2820 | if (dump_dynamic_symtab) | |
2821 | dump_symbols (abfd, TRUE); | |
365544c3 L |
2822 | if (dump_dwarf_section_info) |
2823 | dump_dwarf (abfd); | |
155e0d23 NC |
2824 | if (dump_stab_section_info) |
2825 | dump_stabs (abfd); | |
2826 | if (dump_reloc_info && ! disassemble) | |
2827 | dump_relocs (abfd); | |
2828 | if (dump_dynamic_reloc_info && ! disassemble) | |
2829 | dump_dynamic_relocs (abfd); | |
2830 | if (dump_section_contents) | |
2831 | dump_data (abfd); | |
2832 | if (disassemble) | |
2833 | disassemble_data (abfd); | |
2834 | ||
2835 | if (dump_debugging) | |
2836 | { | |
2837 | void *dhandle; | |
2838 | ||
2839 | dhandle = read_debugging_info (abfd, syms, symcount); | |
2840 | if (dhandle != NULL) | |
2841 | { | |
2842 | if (! print_debugging_info (stdout, dhandle, abfd, syms, demangle, | |
2843 | dump_debugging_tags ? TRUE : FALSE)) | |
2844 | { | |
2845 | non_fatal (_("%s: printing debugging information failed"), | |
2846 | bfd_get_filename (abfd)); | |
2847 | exit_status = 1; | |
2848 | } | |
2849 | } | |
2850 | } | |
2851 | ||
2852 | if (syms) | |
2853 | { | |
2854 | free (syms); | |
2855 | syms = NULL; | |
2856 | } | |
2857 | ||
2858 | if (dynsyms) | |
2859 | { | |
2860 | free (dynsyms); | |
2861 | dynsyms = NULL; | |
2862 | } | |
4c45e5c9 JJ |
2863 | |
2864 | if (synthsyms) | |
2865 | { | |
2866 | free (synthsyms); | |
2867 | synthsyms = NULL; | |
2868 | } | |
2869 | ||
2870 | symcount = 0; | |
2871 | dynsymcount = 0; | |
2872 | synthcount = 0; | |
155e0d23 NC |
2873 | } |
2874 | ||
2875 | static void | |
2876 | display_bfd (bfd *abfd) | |
2877 | { | |
2878 | char **matching; | |
2879 | ||
2880 | if (bfd_check_format_matches (abfd, bfd_object, &matching)) | |
2881 | { | |
2882 | dump_bfd (abfd); | |
2883 | return; | |
2884 | } | |
2885 | ||
2886 | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) | |
2887 | { | |
2888 | nonfatal (bfd_get_filename (abfd)); | |
2889 | list_matching_formats (matching); | |
2890 | free (matching); | |
2891 | return; | |
2892 | } | |
2893 | ||
2894 | if (bfd_get_error () != bfd_error_file_not_recognized) | |
2895 | { | |
2896 | nonfatal (bfd_get_filename (abfd)); | |
2897 | return; | |
2898 | } | |
2899 | ||
2900 | if (bfd_check_format_matches (abfd, bfd_core, &matching)) | |
2901 | { | |
2902 | dump_bfd (abfd); | |
2903 | return; | |
2904 | } | |
2905 | ||
2906 | nonfatal (bfd_get_filename (abfd)); | |
2907 | ||
2908 | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) | |
2909 | { | |
2910 | list_matching_formats (matching); | |
2911 | free (matching); | |
2912 | } | |
2913 | } | |
2914 | ||
2915 | static void | |
2916 | display_file (char *filename, char *target) | |
2917 | { | |
f24ddbdd NC |
2918 | bfd *file; |
2919 | bfd *arfile = NULL; | |
2920 | ||
2921 | if (get_file_size (filename) < 1) | |
2922 | return; | |
155e0d23 NC |
2923 | |
2924 | file = bfd_openr (filename, target); | |
2925 | if (file == NULL) | |
2926 | { | |
2927 | nonfatal (filename); | |
2928 | return; | |
2929 | } | |
2930 | ||
2931 | /* If the file is an archive, process all of its elements. */ | |
2932 | if (bfd_check_format (file, bfd_archive)) | |
2933 | { | |
2934 | bfd *last_arfile = NULL; | |
2935 | ||
2936 | printf (_("In archive %s:\n"), bfd_get_filename (file)); | |
2937 | for (;;) | |
2938 | { | |
2939 | bfd_set_error (bfd_error_no_error); | |
2940 | ||
2941 | arfile = bfd_openr_next_archived_file (file, arfile); | |
2942 | if (arfile == NULL) | |
2943 | { | |
2944 | if (bfd_get_error () != bfd_error_no_more_archived_files) | |
2945 | nonfatal (bfd_get_filename (file)); | |
2946 | break; | |
2947 | } | |
2948 | ||
2949 | display_bfd (arfile); | |
2950 | ||
2951 | if (last_arfile != NULL) | |
2952 | bfd_close (last_arfile); | |
2953 | last_arfile = arfile; | |
2954 | } | |
2955 | ||
2956 | if (last_arfile != NULL) | |
2957 | bfd_close (last_arfile); | |
2958 | } | |
2959 | else | |
2960 | display_bfd (file); | |
2961 | ||
2962 | bfd_close (file); | |
2963 | } | |
252b5132 | 2964 | \f |
252b5132 | 2965 | int |
46dca2e0 | 2966 | main (int argc, char **argv) |
252b5132 RH |
2967 | { |
2968 | int c; | |
2969 | char *target = default_target; | |
b34976b6 | 2970 | bfd_boolean seenflag = FALSE; |
252b5132 | 2971 | |
155e0d23 NC |
2972 | #if defined (HAVE_SETLOCALE) |
2973 | #if defined (HAVE_LC_MESSAGES) | |
252b5132 | 2974 | setlocale (LC_MESSAGES, ""); |
3882b010 | 2975 | #endif |
3882b010 | 2976 | setlocale (LC_CTYPE, ""); |
252b5132 | 2977 | #endif |
155e0d23 | 2978 | |
252b5132 RH |
2979 | bindtextdomain (PACKAGE, LOCALEDIR); |
2980 | textdomain (PACKAGE); | |
2981 | ||
2982 | program_name = *argv; | |
2983 | xmalloc_set_program_name (program_name); | |
2984 | ||
2985 | START_PROGRESS (program_name, 0); | |
2986 | ||
869b9d07 MM |
2987 | expandargv (&argc, &argv); |
2988 | ||
252b5132 RH |
2989 | bfd_init (); |
2990 | set_default_bfd_target (); | |
2991 | ||
365544c3 | 2992 | while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfaHhrRtTxsSI:j:wE:zgeGW", |
252b5132 RH |
2993 | long_options, (int *) 0)) |
2994 | != EOF) | |
2995 | { | |
252b5132 RH |
2996 | switch (c) |
2997 | { | |
2998 | case 0: | |
8b53311e | 2999 | break; /* We've been given a long option. */ |
252b5132 RH |
3000 | case 'm': |
3001 | machine = optarg; | |
3002 | break; | |
dd92f639 | 3003 | case 'M': |
073fbac6 | 3004 | if (disassembler_options) |
31e0f3cd | 3005 | /* Ignore potential memory leak for now. */ |
46dca2e0 NC |
3006 | disassembler_options = concat (disassembler_options, ",", |
3007 | optarg, NULL); | |
31e0f3cd NC |
3008 | else |
3009 | disassembler_options = optarg; | |
dd92f639 | 3010 | break; |
252b5132 | 3011 | case 'j': |
43ac9881 | 3012 | if (only_used == only_size) |
6e50c90c L |
3013 | { |
3014 | only_size += 8; | |
43ac9881 | 3015 | only = xrealloc (only, only_size * sizeof (char *)); |
6e50c90c L |
3016 | } |
3017 | only [only_used++] = optarg; | |
252b5132 RH |
3018 | break; |
3019 | case 'l': | |
b34976b6 | 3020 | with_line_numbers = TRUE; |
252b5132 RH |
3021 | break; |
3022 | case 'b': | |
3023 | target = optarg; | |
3024 | break; | |
1dada9c5 | 3025 | case 'C': |
b34976b6 | 3026 | do_demangle = TRUE; |
28c309a2 NC |
3027 | if (optarg != NULL) |
3028 | { | |
3029 | enum demangling_styles style; | |
8b53311e | 3030 | |
28c309a2 | 3031 | style = cplus_demangle_name_to_style (optarg); |
0af11b59 | 3032 | if (style == unknown_demangling) |
28c309a2 NC |
3033 | fatal (_("unknown demangling style `%s'"), |
3034 | optarg); | |
8b53311e | 3035 | |
28c309a2 | 3036 | cplus_demangle_set_style (style); |
0af11b59 | 3037 | } |
1dada9c5 NC |
3038 | break; |
3039 | case 'w': | |
b34976b6 | 3040 | wide_output = TRUE; |
1dada9c5 NC |
3041 | break; |
3042 | case OPTION_ADJUST_VMA: | |
3043 | adjust_section_vma = parse_vma (optarg, "--adjust-vma"); | |
3044 | break; | |
3045 | case OPTION_START_ADDRESS: | |
3046 | start_address = parse_vma (optarg, "--start-address"); | |
3047 | break; | |
3048 | case OPTION_STOP_ADDRESS: | |
3049 | stop_address = parse_vma (optarg, "--stop-address"); | |
3050 | break; | |
3051 | case 'E': | |
3052 | if (strcmp (optarg, "B") == 0) | |
3053 | endian = BFD_ENDIAN_BIG; | |
3054 | else if (strcmp (optarg, "L") == 0) | |
3055 | endian = BFD_ENDIAN_LITTLE; | |
3056 | else | |
3057 | { | |
37cc8ec1 | 3058 | non_fatal (_("unrecognized -E option")); |
1dada9c5 NC |
3059 | usage (stderr, 1); |
3060 | } | |
3061 | break; | |
3062 | case OPTION_ENDIAN: | |
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; | |
3067 | else | |
3068 | { | |
37cc8ec1 | 3069 | non_fatal (_("unrecognized --endian type `%s'"), optarg); |
1dada9c5 NC |
3070 | usage (stderr, 1); |
3071 | } | |
3072 | break; | |
8b53311e | 3073 | |
252b5132 | 3074 | case 'f': |
b34976b6 AM |
3075 | dump_file_header = TRUE; |
3076 | seenflag = TRUE; | |
252b5132 RH |
3077 | break; |
3078 | case 'i': | |
b34976b6 AM |
3079 | formats_info = TRUE; |
3080 | seenflag = TRUE; | |
252b5132 | 3081 | break; |
43ac9881 AM |
3082 | case 'I': |
3083 | add_include_path (optarg); | |
3084 | break; | |
252b5132 | 3085 | case 'p': |
b34976b6 AM |
3086 | dump_private_headers = TRUE; |
3087 | seenflag = TRUE; | |
252b5132 RH |
3088 | break; |
3089 | case 'x': | |
b34976b6 AM |
3090 | dump_private_headers = TRUE; |
3091 | dump_symtab = TRUE; | |
3092 | dump_reloc_info = TRUE; | |
3093 | dump_file_header = TRUE; | |
3094 | dump_ar_hdrs = TRUE; | |
3095 | dump_section_headers = TRUE; | |
3096 | seenflag = TRUE; | |
252b5132 RH |
3097 | break; |
3098 | case 't': | |
b34976b6 AM |
3099 | dump_symtab = TRUE; |
3100 | seenflag = TRUE; | |
252b5132 RH |
3101 | break; |
3102 | case 'T': | |
b34976b6 AM |
3103 | dump_dynamic_symtab = TRUE; |
3104 | seenflag = TRUE; | |
252b5132 RH |
3105 | break; |
3106 | case 'd': | |
b34976b6 AM |
3107 | disassemble = TRUE; |
3108 | seenflag = TRUE; | |
1dada9c5 NC |
3109 | break; |
3110 | case 'z': | |
b34976b6 | 3111 | disassemble_zeroes = TRUE; |
252b5132 RH |
3112 | break; |
3113 | case 'D': | |
b34976b6 AM |
3114 | disassemble = TRUE; |
3115 | disassemble_all = TRUE; | |
3116 | seenflag = TRUE; | |
252b5132 RH |
3117 | break; |
3118 | case 'S': | |
b34976b6 AM |
3119 | disassemble = TRUE; |
3120 | with_source_code = TRUE; | |
3121 | seenflag = TRUE; | |
1dada9c5 NC |
3122 | break; |
3123 | case 'g': | |
3124 | dump_debugging = 1; | |
b34976b6 | 3125 | seenflag = TRUE; |
1dada9c5 | 3126 | break; |
51cdc6e0 NC |
3127 | case 'e': |
3128 | dump_debugging = 1; | |
3129 | dump_debugging_tags = 1; | |
3130 | do_demangle = TRUE; | |
3131 | seenflag = TRUE; | |
3132 | break; | |
365544c3 L |
3133 | case 'W': |
3134 | dump_dwarf_section_info = TRUE; | |
3135 | seenflag = TRUE; | |
3136 | do_debug_info = 1; | |
3137 | do_debug_abbrevs = 1; | |
3138 | do_debug_lines = 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; | |
3144 | do_debug_str = 1; | |
3145 | do_debug_loc = 1; | |
3146 | break; | |
1dada9c5 | 3147 | case 'G': |
b34976b6 AM |
3148 | dump_stab_section_info = TRUE; |
3149 | seenflag = TRUE; | |
252b5132 RH |
3150 | break; |
3151 | case 's': | |
b34976b6 AM |
3152 | dump_section_contents = TRUE; |
3153 | seenflag = TRUE; | |
252b5132 RH |
3154 | break; |
3155 | case 'r': | |
b34976b6 AM |
3156 | dump_reloc_info = TRUE; |
3157 | seenflag = TRUE; | |
252b5132 RH |
3158 | break; |
3159 | case 'R': | |
b34976b6 AM |
3160 | dump_dynamic_reloc_info = TRUE; |
3161 | seenflag = TRUE; | |
252b5132 RH |
3162 | break; |
3163 | case 'a': | |
b34976b6 AM |
3164 | dump_ar_hdrs = TRUE; |
3165 | seenflag = TRUE; | |
252b5132 RH |
3166 | break; |
3167 | case 'h': | |
b34976b6 AM |
3168 | dump_section_headers = TRUE; |
3169 | seenflag = TRUE; | |
252b5132 RH |
3170 | break; |
3171 | case 'H': | |
3172 | usage (stdout, 0); | |
b34976b6 | 3173 | seenflag = TRUE; |
8b53311e | 3174 | case 'v': |
252b5132 | 3175 | case 'V': |
b34976b6 AM |
3176 | show_version = TRUE; |
3177 | seenflag = TRUE; | |
252b5132 | 3178 | break; |
0af11b59 | 3179 | |
252b5132 RH |
3180 | default: |
3181 | usage (stderr, 1); | |
3182 | } | |
3183 | } | |
3184 | ||
3185 | if (show_version) | |
3186 | print_version ("objdump"); | |
3187 | ||
b34976b6 | 3188 | if (!seenflag) |
1dada9c5 | 3189 | usage (stderr, 2); |
252b5132 RH |
3190 | |
3191 | if (formats_info) | |
06d86cf7 | 3192 | exit_status = display_info (); |
252b5132 RH |
3193 | else |
3194 | { | |
3195 | if (optind == argc) | |
3196 | display_file ("a.out", target); | |
3197 | else | |
3198 | for (; optind < argc;) | |
3199 | display_file (argv[optind++], target); | |
3200 | } | |
3201 | ||
3202 | END_PROGRESS (program_name); | |
3203 | ||
75cd796a | 3204 | return exit_status; |
252b5132 | 3205 | } |