* simple.c (bfd_simple_get_relocated_section_contents): Add
[deliverable/binutils-gdb.git] / binutils / objdump.c
CommitLineData
252b5132 1/* objdump.c -- dump information about an object file.
8c2bc687 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
f0c8c24a 3 2000, 2001, 2002, 2003
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
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
252b5132
RH
21
22#include "bfd.h"
6e1a7e9a 23#include "bfdver.h"
252b5132
RH
24#include "progress.h"
25#include "bucomm.h"
a6637ec0 26#include "budemang.h"
d7a283d4 27#include "getopt.h"
3882b010 28#include "safe-ctype.h"
252b5132
RH
29#include "dis-asm.h"
30#include "libiberty.h"
31#include "demangle.h"
32#include "debug.h"
33#include "budbg.h"
34
252b5132
RH
35/* Internal headers for the ELF .stab-dump code - sorry. */
36#define BYTES_IN_WORD 32
37#include "aout/aout64.h"
38
39#ifdef NEED_DECLARATION_FPRINTF
40/* This is needed by INIT_DISASSEMBLE_INFO. */
b34976b6
AM
41extern int fprintf
42 PARAMS ((FILE *, const char *, ...));
252b5132
RH
43#endif
44
75cd796a
ILT
45/* Exit status. */
46static int exit_status = 0;
47
98a91d6a 48static char *default_target = NULL; /* Default at runtime. */
252b5132 49
98a91d6a 50static int show_version = 0; /* Show the version number. */
252b5132
RH
51static int dump_section_contents; /* -s */
52static int dump_section_headers; /* -h */
b34976b6 53static bfd_boolean dump_file_header; /* -f */
252b5132
RH
54static int dump_symtab; /* -t */
55static int dump_dynamic_symtab; /* -T */
56static int dump_reloc_info; /* -r */
57static int dump_dynamic_reloc_info; /* -R */
58static int dump_ar_hdrs; /* -a */
59static int dump_private_headers; /* -p */
60static int prefix_addresses; /* --prefix-addresses */
61static int with_line_numbers; /* -l */
b34976b6 62static bfd_boolean with_source_code; /* -S */
252b5132
RH
63static int show_raw_insn; /* --show-raw-insn */
64static int dump_stab_section_info; /* --stabs */
65static int do_demangle; /* -C, --demangle */
b34976b6
AM
66static bfd_boolean disassemble; /* -d */
67static bfd_boolean disassemble_all; /* -D */
252b5132 68static int disassemble_zeroes; /* --disassemble-zeroes */
b34976b6 69static bfd_boolean formats_info; /* -i */
252b5132
RH
70static char *only; /* -j secname */
71static int wide_output; /* -w */
72static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
73static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
74static int dump_debugging; /* --debugging */
75static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
f1563258 76static int file_start_context = 0; /* --file-start-context */
252b5132
RH
77
78/* Extra info to pass to the disassembler address printing function. */
026df7c5
NC
79struct objdump_disasm_info
80{
252b5132
RH
81 bfd *abfd;
82 asection *sec;
b34976b6 83 bfd_boolean require_sec;
252b5132
RH
84};
85
86/* Architecture to disassemble for, or default if NULL. */
87static char *machine = (char *) NULL;
88
dd92f639
NC
89/* Target specific options to the disassembler. */
90static char *disassembler_options = (char *) NULL;
91
252b5132
RH
92/* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
93static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
94
95/* The symbol table. */
96static asymbol **syms;
97
98/* Number of symbols in `syms'. */
99static long symcount = 0;
100
101/* The sorted symbol table. */
102static asymbol **sorted_syms;
103
104/* Number of symbols in `sorted_syms'. */
105static long sorted_symcount = 0;
106
107/* The dynamic symbol table. */
108static asymbol **dynsyms;
109
110/* Number of symbols in `dynsyms'. */
111static long dynsymcount = 0;
112
98a91d6a
NC
113static bfd_byte *stabs;
114static bfd_size_type stab_size;
115
116static char *strtab;
117static bfd_size_type stabstr_size;
118
252b5132
RH
119/* Static declarations. */
120
b34976b6
AM
121static void usage
122 PARAMS ((FILE *, int));
123static void nonfatal
124 PARAMS ((const char *));
125static void display_file
06d86cf7 126 PARAMS ((char *, char *));
b34976b6
AM
127static void dump_section_header
128 PARAMS ((bfd *, asection *, PTR));
129static void dump_headers
130 PARAMS ((bfd *));
131static void dump_data
06d86cf7 132 PARAMS ((bfd *));
b34976b6 133static void dump_relocs
06d86cf7 134 PARAMS ((bfd *));
b34976b6 135static void dump_dynamic_relocs
06d86cf7 136 PARAMS ((bfd *));
b34976b6
AM
137static void dump_reloc_set
138 PARAMS ((bfd *, asection *, arelent **, long));
139static void dump_symbols
06d86cf7 140 PARAMS ((bfd *, bfd_boolean));
b34976b6
AM
141static void dump_bfd_header
142 PARAMS ((bfd *));
143static void dump_bfd_private_header
144 PARAMS ((bfd *));
145static void dump_bfd
146 PARAMS ((bfd *));
147static void display_bfd
06d86cf7 148 PARAMS ((bfd *));
2863d58a 149static void objdump_print_value
b34976b6 150 PARAMS ((bfd_vma, struct disassemble_info *, bfd_boolean));
2863d58a
AM
151static void objdump_print_symname
152 PARAMS ((bfd *, struct disassemble_info *, asymbol *));
153static asymbol *find_symbol_for_address
b34976b6 154 PARAMS ((bfd *, asection *, bfd_vma, bfd_boolean, long *));
2863d58a
AM
155static void objdump_print_addr_with_sym
156 PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
b34976b6 157 struct disassemble_info *, bfd_boolean));
2863d58a 158static void objdump_print_addr
b34976b6 159 PARAMS ((bfd_vma, struct disassemble_info *, bfd_boolean));
2863d58a
AM
160static void objdump_print_address
161 PARAMS ((bfd_vma, struct disassemble_info *));
162static int objdump_symbol_at_address
163 PARAMS ((bfd_vma, struct disassemble_info *));
b34976b6
AM
164static void show_line
165 PARAMS ((bfd *, asection *, bfd_vma));
2863d58a 166static void disassemble_bytes
b34976b6 167 PARAMS ((struct disassemble_info *, disassembler_ftype, bfd_boolean,
2863d58a 168 bfd_byte *, bfd_vma, bfd_vma, arelent ***, arelent **));
b34976b6
AM
169static void disassemble_data
170 PARAMS ((bfd *));
b34976b6
AM
171static asymbol ** slurp_symtab
172 PARAMS ((bfd *));
173static asymbol ** slurp_dynamic_symtab
174 PARAMS ((bfd *));
175static long remove_useless_symbols
176 PARAMS ((asymbol **, long));
177static int compare_symbols
178 PARAMS ((const PTR, const PTR));
179static int compare_relocs
180 PARAMS ((const PTR, const PTR));
181static void dump_stabs
182 PARAMS ((bfd *));
183static bfd_boolean read_section_stabs
184 PARAMS ((bfd *, const char *, const char *));
185static void print_section_stabs
186 PARAMS ((bfd *, const char *, const char *));
98a91d6a
NC
187static void dump_section_stabs
188 PARAMS ((bfd *, char *, char *));
252b5132
RH
189\f
190static void
191usage (stream, status)
192 FILE *stream;
193 int status;
194{
8b53311e
NC
195 fprintf (stream, _("Usage: %s <option(s)> <file(s)>\n"), program_name);
196 fprintf (stream, _(" Display information from object <file(s)>.\n"));
197 fprintf (stream, _(" At least one of the following switches must be given:\n"));
252b5132 198 fprintf (stream, _("\
86d65c94
MK
199 -a, --archive-headers Display archive header information\n\
200 -f, --file-headers Display the contents of the overall file header\n\
201 -p, --private-headers Display object format specific file header contents\n\
202 -h, --[section-]headers Display the contents of the section headers\n\
203 -x, --all-headers Display the contents of all headers\n\
204 -d, --disassemble Display assembler contents of executable sections\n\
205 -D, --disassemble-all Display assembler contents of all sections\n\
206 -S, --source Intermix source code with disassembly\n\
207 -s, --full-contents Display the full contents of all sections requested\n\
208 -g, --debugging Display debug information in object file\n\
209 -G, --stabs Display (in raw form) any STABS info in the file\n\
210 -t, --syms Display the contents of the symbol table(s)\n\
211 -T, --dynamic-syms Display the contents of the dynamic symbol table\n\
212 -r, --reloc Display the relocation entries in the file\n\
213 -R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
8b53311e 214 -v, --version Display this program's version number\n\
86d65c94
MK
215 -i, --info List object formats and architectures supported\n\
216 -H, --help Display this information\n\
1dada9c5
NC
217"));
218 if (status != 2)
219 {
220 fprintf (stream, _("\n The following switches are optional:\n"));
221 fprintf (stream, _("\
86d65c94
MK
222 -b, --target=BFDNAME Specify the target object format as BFDNAME\n\
223 -m, --architecture=MACHINE Specify the target architecture as MACHINE\n\
224 -j, --section=NAME Only display information for section NAME\n\
225 -M, --disassembler-options=OPT Pass text OPT on to the disassembler\n\
1dada9c5
NC
226 -EB --endian=big Assume big endian format when disassembling\n\
227 -EL --endian=little Assume little endian format when disassembling\n\
f1563258 228 --file-start-context Include context from start of file (with -S)\n\
86d65c94 229 -l, --line-numbers Include line numbers and filenames in output\n\
28c309a2 230 -C, --demangle[=STYLE] Decode mangled/processed symbol names\n\
f0c8c24a
NC
231 The STYLE, if specified, can be `auto', `gnu',\n\
232 `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
233 or `gnat'\n\
86d65c94
MK
234 -w, --wide Format output for more than 80 columns\n\
235 -z, --disassemble-zeroes Do not skip blocks of zeroes when disassembling\n\
f0c8c24a
NC
236 --start-address=ADDR Only process data whose address is >= ADDR\n\
237 --stop-address=ADDR Only process data whose address is <= ADDR\n\
1dada9c5
NC
238 --prefix-addresses Print complete address alongside disassembly\n\
239 --[no-]show-raw-insn Display hex alongside symbolic disassembly\n\
86d65c94 240 --adjust-vma=OFFSET Add OFFSET to all displayed section addresses\n\
1dada9c5
NC
241\n"));
242 list_supported_targets (program_name, stream);
2f83960e 243 list_supported_architectures (program_name, stream);
86d65c94 244
94470b23 245 disassembler_usage (stream);
1dada9c5 246 }
252b5132 247 if (status == 0)
86d65c94 248 fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
252b5132
RH
249 exit (status);
250}
251
252/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
253
254#define OPTION_ENDIAN (150)
255#define OPTION_START_ADDRESS (OPTION_ENDIAN + 1)
256#define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
257#define OPTION_ADJUST_VMA (OPTION_STOP_ADDRESS + 1)
258
259static struct option long_options[]=
260{
261 {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
262 {"all-headers", no_argument, NULL, 'x'},
263 {"private-headers", no_argument, NULL, 'p'},
264 {"architecture", required_argument, NULL, 'm'},
265 {"archive-headers", no_argument, NULL, 'a'},
1dada9c5 266 {"debugging", no_argument, NULL, 'g'},
28c309a2 267 {"demangle", optional_argument, NULL, 'C'},
252b5132
RH
268 {"disassemble", no_argument, NULL, 'd'},
269 {"disassemble-all", no_argument, NULL, 'D'},
dd92f639 270 {"disassembler-options", required_argument, NULL, 'M'},
1dada9c5 271 {"disassemble-zeroes", no_argument, NULL, 'z'},
252b5132
RH
272 {"dynamic-reloc", no_argument, NULL, 'R'},
273 {"dynamic-syms", no_argument, NULL, 'T'},
274 {"endian", required_argument, NULL, OPTION_ENDIAN},
275 {"file-headers", no_argument, NULL, 'f'},
f1563258 276 {"file-start-context", no_argument, &file_start_context, 1},
252b5132
RH
277 {"full-contents", no_argument, NULL, 's'},
278 {"headers", no_argument, NULL, 'h'},
279 {"help", no_argument, NULL, 'H'},
280 {"info", no_argument, NULL, 'i'},
281 {"line-numbers", no_argument, NULL, 'l'},
282 {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
283 {"prefix-addresses", no_argument, &prefix_addresses, 1},
284 {"reloc", no_argument, NULL, 'r'},
285 {"section", required_argument, NULL, 'j'},
286 {"section-headers", no_argument, NULL, 'h'},
287 {"show-raw-insn", no_argument, &show_raw_insn, 1},
288 {"source", no_argument, NULL, 'S'},
1dada9c5 289 {"stabs", no_argument, NULL, 'G'},
252b5132
RH
290 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
291 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
292 {"syms", no_argument, NULL, 't'},
293 {"target", required_argument, NULL, 'b'},
1dada9c5
NC
294 {"version", no_argument, NULL, 'V'},
295 {"wide", no_argument, NULL, 'w'},
252b5132
RH
296 {0, no_argument, 0, 0}
297};
298\f
299static void
75cd796a
ILT
300nonfatal (msg)
301 const char *msg;
302{
303 bfd_nonfatal (msg);
304 exit_status = 1;
305}
306\f
307static void
252b5132 308dump_section_header (abfd, section, ignored)
b4c96d0d 309 bfd *abfd ATTRIBUTE_UNUSED;
252b5132 310 asection *section;
b4c96d0d 311 PTR ignored ATTRIBUTE_UNUSED;
252b5132
RH
312{
313 char *comma = "";
f6af82bd 314 unsigned int opb = bfd_octets_per_byte (abfd);
252b5132
RH
315
316 printf ("%3d %-13s %08lx ", section->index,
317 bfd_get_section_name (abfd, section),
940b2b78 318 (unsigned long) bfd_section_size (abfd, section) / opb);
d8180c76 319 bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section));
252b5132 320 printf (" ");
d8180c76 321 bfd_printf_vma (abfd, section->lma);
e59b4dfb 322 printf (" %08lx 2**%u", (unsigned long) section->filepos,
252b5132
RH
323 bfd_get_section_alignment (abfd, section));
324 if (! wide_output)
325 printf ("\n ");
326 printf (" ");
327
328#define PF(x, y) \
329 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
330
331 PF (SEC_HAS_CONTENTS, "CONTENTS");
332 PF (SEC_ALLOC, "ALLOC");
333 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
252b5132
RH
334 PF (SEC_LOAD, "LOAD");
335 PF (SEC_RELOC, "RELOC");
252b5132
RH
336 PF (SEC_READONLY, "READONLY");
337 PF (SEC_CODE, "CODE");
338 PF (SEC_DATA, "DATA");
339 PF (SEC_ROM, "ROM");
340 PF (SEC_DEBUGGING, "DEBUGGING");
341 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
342 PF (SEC_EXCLUDE, "EXCLUDE");
343 PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
34cbe64e
TW
344 PF (SEC_BLOCK, "BLOCK");
345 PF (SEC_CLINK, "CLINK");
24c411ed
ILT
346 PF (SEC_SMALL_DATA, "SMALL_DATA");
347 PF (SEC_SHARED, "SHARED");
9e85c2a0 348 PF (SEC_ARCH_BIT_0, "ARCH_BIT_0");
13ae64f3 349 PF (SEC_THREAD_LOCAL, "THREAD_LOCAL");
252b5132
RH
350
351 if ((section->flags & SEC_LINK_ONCE) != 0)
352 {
353 const char *ls;
354
355 switch (section->flags & SEC_LINK_DUPLICATES)
356 {
357 default:
358 abort ();
359 case SEC_LINK_DUPLICATES_DISCARD:
360 ls = "LINK_ONCE_DISCARD";
361 break;
362 case SEC_LINK_DUPLICATES_ONE_ONLY:
363 ls = "LINK_ONCE_ONE_ONLY";
364 break;
365 case SEC_LINK_DUPLICATES_SAME_SIZE:
366 ls = "LINK_ONCE_SAME_SIZE";
367 break;
368 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
369 ls = "LINK_ONCE_SAME_CONTENTS";
370 break;
371 }
372 printf ("%s%s", comma, ls);
deecf979
ILT
373
374 if (section->comdat != NULL)
375 printf (" (COMDAT %s %ld)", section->comdat->name,
376 section->comdat->symbol);
377
252b5132
RH
378 comma = ", ";
379 }
380
381 printf ("\n");
382#undef PF
383}
384
385static void
386dump_headers (abfd)
387 bfd *abfd;
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
252b5132
RH
407 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
408}
409\f
410static asymbol **
411slurp_symtab (abfd)
412 bfd *abfd;
413{
414 asymbol **sy = (asymbol **) NULL;
415 long storage;
416
417 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
418 {
252b5132
RH
419 symcount = 0;
420 return NULL;
421 }
422
423 storage = bfd_get_symtab_upper_bound (abfd);
424 if (storage < 0)
425 bfd_fatal (bfd_get_filename (abfd));
252b5132 426 if (storage)
28b18af1
AM
427 sy = (asymbol **) xmalloc (storage);
428
252b5132
RH
429 symcount = bfd_canonicalize_symtab (abfd, sy);
430 if (symcount < 0)
431 bfd_fatal (bfd_get_filename (abfd));
252b5132
RH
432 return sy;
433}
434
435/* Read in the dynamic symbols. */
436
437static asymbol **
438slurp_dynamic_symtab (abfd)
439 bfd *abfd;
440{
441 asymbol **sy = (asymbol **) NULL;
442 long storage;
443
444 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
445 if (storage < 0)
446 {
447 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
448 {
37cc8ec1 449 non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
252b5132
RH
450 dynsymcount = 0;
451 return NULL;
452 }
453
454 bfd_fatal (bfd_get_filename (abfd));
455 }
252b5132 456 if (storage)
28b18af1
AM
457 sy = (asymbol **) xmalloc (storage);
458
252b5132
RH
459 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
460 if (dynsymcount < 0)
461 bfd_fatal (bfd_get_filename (abfd));
252b5132
RH
462 return sy;
463}
464
465/* Filter out (in place) symbols that are useless for disassembly.
466 COUNT is the number of elements in SYMBOLS.
0af11b59 467 Return the number of useful symbols. */
252b5132
RH
468
469static long
470remove_useless_symbols (symbols, count)
471 asymbol **symbols;
472 long count;
473{
474 register asymbol **in_ptr = symbols, **out_ptr = symbols;
475
476 while (--count >= 0)
477 {
478 asymbol *sym = *in_ptr++;
479
480 if (sym->name == NULL || sym->name[0] == '\0')
481 continue;
482 if (sym->flags & (BSF_DEBUGGING))
483 continue;
484 if (bfd_is_und_section (sym->section)
485 || bfd_is_com_section (sym->section))
486 continue;
487
488 *out_ptr++ = sym;
489 }
490 return out_ptr - symbols;
491}
492
493/* Sort symbols into value order. */
494
0af11b59 495static int
252b5132
RH
496compare_symbols (ap, bp)
497 const PTR ap;
498 const PTR bp;
499{
500 const asymbol *a = *(const asymbol **)ap;
501 const asymbol *b = *(const asymbol **)bp;
502 const char *an, *bn;
503 size_t anl, bnl;
b34976b6 504 bfd_boolean af, bf;
252b5132
RH
505 flagword aflags, bflags;
506
507 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
508 return 1;
509 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
510 return -1;
511
512 if (a->section > b->section)
513 return 1;
514 else if (a->section < b->section)
515 return -1;
516
517 an = bfd_asymbol_name (a);
518 bn = bfd_asymbol_name (b);
519 anl = strlen (an);
520 bnl = strlen (bn);
521
522 /* The symbols gnu_compiled and gcc2_compiled convey no real
523 information, so put them after other symbols with the same value. */
252b5132
RH
524 af = (strstr (an, "gnu_compiled") != NULL
525 || strstr (an, "gcc2_compiled") != NULL);
526 bf = (strstr (bn, "gnu_compiled") != NULL
527 || strstr (bn, "gcc2_compiled") != NULL);
528
529 if (af && ! bf)
530 return 1;
531 if (! af && bf)
532 return -1;
533
534 /* We use a heuristic for the file name, to try to sort it after
535 more useful symbols. It may not work on non Unix systems, but it
536 doesn't really matter; the only difference is precisely which
537 symbol names get printed. */
538
539#define file_symbol(s, sn, snl) \
540 (((s)->flags & BSF_FILE) != 0 \
541 || ((sn)[(snl) - 2] == '.' \
542 && ((sn)[(snl) - 1] == 'o' \
543 || (sn)[(snl) - 1] == 'a')))
544
545 af = file_symbol (a, an, anl);
546 bf = file_symbol (b, bn, bnl);
547
548 if (af && ! bf)
549 return 1;
550 if (! af && bf)
551 return -1;
552
553 /* Try to sort global symbols before local symbols before function
554 symbols before debugging symbols. */
555
556 aflags = a->flags;
557 bflags = b->flags;
558
559 if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
560 {
561 if ((aflags & BSF_DEBUGGING) != 0)
562 return 1;
563 else
564 return -1;
565 }
566 if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
567 {
568 if ((aflags & BSF_FUNCTION) != 0)
569 return -1;
570 else
571 return 1;
572 }
573 if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
574 {
575 if ((aflags & BSF_LOCAL) != 0)
576 return 1;
577 else
578 return -1;
579 }
580 if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
581 {
582 if ((aflags & BSF_GLOBAL) != 0)
583 return -1;
584 else
585 return 1;
586 }
587
588 /* Symbols that start with '.' might be section names, so sort them
589 after symbols that don't start with '.'. */
590 if (an[0] == '.' && bn[0] != '.')
591 return 1;
592 if (an[0] != '.' && bn[0] == '.')
593 return -1;
594
595 /* Finally, if we can't distinguish them in any other way, try to
596 get consistent results by sorting the symbols by name. */
597 return strcmp (an, bn);
598}
599
600/* Sort relocs into address order. */
601
602static int
603compare_relocs (ap, bp)
604 const PTR ap;
605 const PTR bp;
606{
607 const arelent *a = *(const arelent **)ap;
608 const arelent *b = *(const arelent **)bp;
609
610 if (a->address > b->address)
611 return 1;
612 else if (a->address < b->address)
613 return -1;
614
615 /* So that associated relocations tied to the same address show up
616 in the correct order, we don't do any further sorting. */
617 if (a > b)
618 return 1;
619 else if (a < b)
620 return -1;
621 else
622 return 0;
623}
624
b34976b6 625/* Print VMA to STREAM. If SKIP_ZEROES is TRUE, omit leading zeroes. */
252b5132
RH
626
627static void
628objdump_print_value (vma, info, skip_zeroes)
629 bfd_vma vma;
630 struct disassemble_info *info;
b34976b6 631 bfd_boolean skip_zeroes;
252b5132
RH
632{
633 char buf[30];
634 char *p;
d8180c76
L
635 struct objdump_disasm_info *aux
636 = (struct objdump_disasm_info *) info->application_data;
252b5132 637
d8180c76 638 bfd_sprintf_vma (aux->abfd, buf, vma);
252b5132
RH
639 if (! skip_zeroes)
640 p = buf;
641 else
642 {
643 for (p = buf; *p == '0'; ++p)
644 ;
645 if (*p == '\0')
646 --p;
647 }
648 (*info->fprintf_func) (info->stream, "%s", p);
649}
650
651/* Print the name of a symbol. */
652
653static void
654objdump_print_symname (abfd, info, sym)
655 bfd *abfd;
656 struct disassemble_info *info;
657 asymbol *sym;
658{
659 char *alloc;
660 const char *name;
252b5132
RH
661
662 alloc = NULL;
663 name = bfd_asymbol_name (sym);
a6637ec0 664 if (do_demangle && name[0] != '\0')
252b5132
RH
665 {
666 /* Demangle the name. */
a6637ec0
AM
667 alloc = demangle (abfd, name);
668 name = alloc;
252b5132
RH
669 }
670
671 if (info != NULL)
a6637ec0 672 (*info->fprintf_func) (info->stream, "%s", name);
252b5132 673 else
a6637ec0 674 printf ("%s", name);
252b5132
RH
675
676 if (alloc != NULL)
677 free (alloc);
678}
679
680/* Locate a symbol given a bfd, a section, and a VMA. If REQUIRE_SEC
b34976b6 681 is TRUE, then always require the symbol to be in the section. This
252b5132
RH
682 returns NULL if there is no suitable symbol. If PLACE is not NULL,
683 then *PLACE is set to the index of the symbol in sorted_syms. */
684
685static asymbol *
686find_symbol_for_address (abfd, sec, vma, require_sec, place)
687 bfd *abfd;
688 asection *sec;
689 bfd_vma vma;
b34976b6 690 bfd_boolean require_sec;
252b5132
RH
691 long *place;
692{
693 /* @@ Would it speed things up to cache the last two symbols returned,
694 and maybe their address ranges? For many processors, only one memory
695 operand can be present at a time, so the 2-entry cache wouldn't be
696 constantly churned by code doing heavy memory accesses. */
697
698 /* Indices in `sorted_syms'. */
699 long min = 0;
700 long max = sorted_symcount;
701 long thisplace;
0af11b59 702 unsigned int opb = bfd_octets_per_byte (abfd);
252b5132
RH
703
704 if (sorted_symcount < 1)
705 return NULL;
706
707 /* Perform a binary search looking for the closest symbol to the
708 required value. We are searching the range (min, max]. */
709 while (min + 1 < max)
710 {
711 asymbol *sym;
712
713 thisplace = (max + min) / 2;
714 sym = sorted_syms[thisplace];
715
716 if (bfd_asymbol_value (sym) > vma)
717 max = thisplace;
718 else if (bfd_asymbol_value (sym) < vma)
719 min = thisplace;
720 else
721 {
722 min = thisplace;
723 break;
724 }
725 }
726
727 /* The symbol we want is now in min, the low end of the range we
728 were searching. If there are several symbols with the same
729 value, we want the first one. */
730 thisplace = min;
731 while (thisplace > 0
732 && (bfd_asymbol_value (sorted_syms[thisplace])
733 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
734 --thisplace;
735
736 /* If the file is relocateable, and the symbol could be from this
737 section, prefer a symbol from this section over symbols from
738 others, even if the other symbol's value might be closer.
0af11b59 739
252b5132
RH
740 Note that this may be wrong for some symbol references if the
741 sections have overlapping memory ranges, but in that case there's
742 no way to tell what's desired without looking at the relocation
743 table. */
252b5132
RH
744 if (sorted_syms[thisplace]->section != sec
745 && (require_sec
746 || ((abfd->flags & HAS_RELOC) != 0
747 && vma >= bfd_get_section_vma (abfd, sec)
748 && vma < (bfd_get_section_vma (abfd, sec)
940b2b78 749 + bfd_section_size (abfd, sec) / opb))))
252b5132
RH
750 {
751 long i;
752
753 for (i = thisplace + 1; i < sorted_symcount; i++)
754 {
755 if (bfd_asymbol_value (sorted_syms[i])
756 != bfd_asymbol_value (sorted_syms[thisplace]))
757 break;
758 }
98a91d6a 759
252b5132 760 --i;
98a91d6a 761
252b5132
RH
762 for (; i >= 0; i--)
763 {
764 if (sorted_syms[i]->section == sec
765 && (i == 0
766 || sorted_syms[i - 1]->section != sec
767 || (bfd_asymbol_value (sorted_syms[i])
768 != bfd_asymbol_value (sorted_syms[i - 1]))))
769 {
770 thisplace = i;
771 break;
772 }
773 }
774
775 if (sorted_syms[thisplace]->section != sec)
776 {
777 /* We didn't find a good symbol with a smaller value.
778 Look for one with a larger value. */
779 for (i = thisplace + 1; i < sorted_symcount; i++)
780 {
781 if (sorted_syms[i]->section == sec)
782 {
783 thisplace = i;
784 break;
785 }
786 }
787 }
788
789 if (sorted_syms[thisplace]->section != sec
790 && (require_sec
791 || ((abfd->flags & HAS_RELOC) != 0
792 && vma >= bfd_get_section_vma (abfd, sec)
793 && vma < (bfd_get_section_vma (abfd, sec)
794 + bfd_section_size (abfd, sec)))))
795 {
796 /* There is no suitable symbol. */
797 return NULL;
798 }
799 }
800
801 if (place != NULL)
802 *place = thisplace;
803
804 return sorted_syms[thisplace];
805}
806
807/* Print an address to INFO symbolically. */
808
809static void
810objdump_print_addr_with_sym (abfd, sec, sym, vma, info, skip_zeroes)
811 bfd *abfd;
812 asection *sec;
813 asymbol *sym;
814 bfd_vma vma;
815 struct disassemble_info *info;
b34976b6 816 bfd_boolean skip_zeroes;
252b5132
RH
817{
818 objdump_print_value (vma, info, skip_zeroes);
819
820 if (sym == NULL)
821 {
822 bfd_vma secaddr;
823
824 (*info->fprintf_func) (info->stream, " <%s",
825 bfd_get_section_name (abfd, sec));
826 secaddr = bfd_get_section_vma (abfd, sec);
827 if (vma < secaddr)
828 {
829 (*info->fprintf_func) (info->stream, "-0x");
b34976b6 830 objdump_print_value (secaddr - vma, info, TRUE);
252b5132
RH
831 }
832 else if (vma > secaddr)
833 {
834 (*info->fprintf_func) (info->stream, "+0x");
b34976b6 835 objdump_print_value (vma - secaddr, info, TRUE);
252b5132
RH
836 }
837 (*info->fprintf_func) (info->stream, ">");
838 }
839 else
840 {
841 (*info->fprintf_func) (info->stream, " <");
842 objdump_print_symname (abfd, info, sym);
843 if (bfd_asymbol_value (sym) > vma)
844 {
845 (*info->fprintf_func) (info->stream, "-0x");
b34976b6 846 objdump_print_value (bfd_asymbol_value (sym) - vma, info, TRUE);
252b5132
RH
847 }
848 else if (vma > bfd_asymbol_value (sym))
849 {
850 (*info->fprintf_func) (info->stream, "+0x");
b34976b6 851 objdump_print_value (vma - bfd_asymbol_value (sym), info, TRUE);
252b5132
RH
852 }
853 (*info->fprintf_func) (info->stream, ">");
854 }
855}
856
857/* Print VMA to INFO, symbolically if possible. If SKIP_ZEROES is
b34976b6 858 TRUE, don't output leading zeroes. */
252b5132
RH
859
860static void
861objdump_print_addr (vma, info, skip_zeroes)
862 bfd_vma vma;
863 struct disassemble_info *info;
b34976b6 864 bfd_boolean skip_zeroes;
252b5132
RH
865{
866 struct objdump_disasm_info *aux;
867 asymbol *sym;
868
869 if (sorted_symcount < 1)
870 {
871 (*info->fprintf_func) (info->stream, "0x");
872 objdump_print_value (vma, info, skip_zeroes);
873 return;
874 }
875
876 aux = (struct objdump_disasm_info *) info->application_data;
877 sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec,
878 (long *) NULL);
879 objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
880 skip_zeroes);
881}
882
883/* Print VMA to INFO. This function is passed to the disassembler
884 routine. */
885
886static void
887objdump_print_address (vma, info)
888 bfd_vma vma;
889 struct disassemble_info *info;
890{
891 objdump_print_addr (vma, info, ! prefix_addresses);
892}
893
894/* Determine of the given address has a symbol associated with it. */
895
896static int
897objdump_symbol_at_address (vma, info)
898 bfd_vma vma;
899 struct disassemble_info * info;
900{
901 struct objdump_disasm_info * aux;
902 asymbol * sym;
903
904 /* No symbols - do not bother checking. */
905 if (sorted_symcount < 1)
906 return 0;
907
908 aux = (struct objdump_disasm_info *) info->application_data;
909 sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec,
910 (long *) NULL);
911
912 return (sym != NULL && (bfd_asymbol_value (sym) == vma));
913}
914
915/* Hold the last function name and the last line number we displayed
916 in a disassembly. */
917
918static char *prev_functionname;
919static unsigned int prev_line;
920
921/* We keep a list of all files that we have seen when doing a
922 dissassembly with source, so that we know how much of the file to
923 display. This can be important for inlined functions. */
924
925struct print_file_list
926{
927 struct print_file_list *next;
928 char *filename;
929 unsigned int line;
930 FILE *f;
931};
932
933static struct print_file_list *print_files;
934
935/* The number of preceding context lines to show when we start
936 displaying a file for the first time. */
937
938#define SHOW_PRECEDING_CONTEXT_LINES (5)
939
940/* Skip ahead to a given line in a file, optionally printing each
941 line. */
942
b34976b6
AM
943static void skip_to_line
944 PARAMS ((struct print_file_list *, unsigned int, bfd_boolean));
252b5132
RH
945
946static void
947skip_to_line (p, line, show)
948 struct print_file_list *p;
949 unsigned int line;
b34976b6 950 bfd_boolean show;
252b5132
RH
951{
952 while (p->line < line)
953 {
954 char buf[100];
955
956 if (fgets (buf, sizeof buf, p->f) == NULL)
957 {
958 fclose (p->f);
959 p->f = NULL;
960 break;
961 }
962
963 if (show)
964 printf ("%s", buf);
965
966 if (strchr (buf, '\n') != NULL)
967 ++p->line;
968 }
0af11b59 969}
252b5132
RH
970
971/* Show the line number, or the source line, in a dissassembly
972 listing. */
973
974static void
940b2b78 975show_line (abfd, section, addr_offset)
252b5132
RH
976 bfd *abfd;
977 asection *section;
940b2b78 978 bfd_vma addr_offset;
252b5132 979{
b1f88ebe
AM
980 const char *filename;
981 const char *functionname;
252b5132
RH
982 unsigned int line;
983
984 if (! with_line_numbers && ! with_source_code)
985 return;
986
940b2b78 987 if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename,
252b5132
RH
988 &functionname, &line))
989 return;
990
991 if (filename != NULL && *filename == '\0')
992 filename = NULL;
993 if (functionname != NULL && *functionname == '\0')
994 functionname = NULL;
995
996 if (with_line_numbers)
997 {
998 if (functionname != NULL
999 && (prev_functionname == NULL
1000 || strcmp (functionname, prev_functionname) != 0))
1001 printf ("%s():\n", functionname);
1002 if (line > 0 && line != prev_line)
1003 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
1004 }
1005
1006 if (with_source_code
1007 && filename != NULL
1008 && line > 0)
1009 {
1010 struct print_file_list **pp, *p;
1011
1012 for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
1013 if (strcmp ((*pp)->filename, filename) == 0)
1014 break;
1015 p = *pp;
1016
1017 if (p != NULL)
1018 {
1019 if (p != print_files)
1020 {
1021 int l;
1022
1023 /* We have reencountered a file name which we saw
1024 earlier. This implies that either we are dumping out
1025 code from an included file, or the same file was
1026 linked in more than once. There are two common cases
1027 of an included file: inline functions in a header
1028 file, and a bison or flex skeleton file. In the
1029 former case we want to just start printing (but we
1030 back up a few lines to give context); in the latter
1031 case we want to continue from where we left off. I
1032 can't think of a good way to distinguish the cases,
1033 so I used a heuristic based on the file name. */
1034 if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0)
1035 l = p->line;
1036 else
1037 {
1038 l = line - SHOW_PRECEDING_CONTEXT_LINES;
f1563258
TW
1039 if (l < 0)
1040 l = 0;
252b5132
RH
1041 }
1042
1043 if (p->f == NULL)
1044 {
1045 p->f = fopen (p->filename, "r");
1046 p->line = 0;
1047 }
1048 if (p->f != NULL)
b34976b6 1049 skip_to_line (p, l, FALSE);
252b5132
RH
1050
1051 if (print_files->f != NULL)
1052 {
1053 fclose (print_files->f);
1054 print_files->f = NULL;
1055 }
1056 }
1057
1058 if (p->f != NULL)
1059 {
b34976b6 1060 skip_to_line (p, line, TRUE);
252b5132
RH
1061 *pp = p->next;
1062 p->next = print_files;
1063 print_files = p;
1064 }
1065 }
1066 else
1067 {
1068 FILE *f;
1069
1070 f = fopen (filename, "r");
1071 if (f != NULL)
1072 {
1073 int l;
1074
1075 p = ((struct print_file_list *)
1076 xmalloc (sizeof (struct print_file_list)));
1077 p->filename = xmalloc (strlen (filename) + 1);
1078 strcpy (p->filename, filename);
1079 p->line = 0;
1080 p->f = f;
1081
1082 if (print_files != NULL && print_files->f != NULL)
1083 {
1084 fclose (print_files->f);
1085 print_files->f = NULL;
1086 }
1087 p->next = print_files;
1088 print_files = p;
1089
0af11b59
KH
1090 if (file_start_context)
1091 l = 0;
1092 else
1093 l = line - SHOW_PRECEDING_CONTEXT_LINES;
f1563258
TW
1094 if (l < 0)
1095 l = 0;
b34976b6 1096 skip_to_line (p, l, FALSE);
252b5132 1097 if (p->f != NULL)
b34976b6 1098 skip_to_line (p, line, TRUE);
252b5132
RH
1099 }
1100 }
1101 }
1102
1103 if (functionname != NULL
1104 && (prev_functionname == NULL
1105 || strcmp (functionname, prev_functionname) != 0))
1106 {
1107 if (prev_functionname != NULL)
1108 free (prev_functionname);
1109 prev_functionname = xmalloc (strlen (functionname) + 1);
1110 strcpy (prev_functionname, functionname);
1111 }
1112
1113 if (line > 0 && line != prev_line)
1114 prev_line = line;
1115}
1116
1117/* Pseudo FILE object for strings. */
1118typedef struct
1119{
1120 char *buffer;
1121 size_t size;
1122 char *current;
1123} SFILE;
1124
1125/* sprintf to a "stream" */
1126
1127static int
451dad9c 1128objdump_sprintf VPARAMS ((SFILE *f, const char *format, ...))
252b5132 1129{
252b5132 1130 char *buf;
252b5132
RH
1131 size_t n;
1132
451dad9c
AM
1133 VA_OPEN (args, format);
1134 VA_FIXEDARG (args, SFILE *, f);
1135 VA_FIXEDARG (args, const char *, format);
252b5132
RH
1136
1137 vasprintf (&buf, format, args);
1138
252b5132
RH
1139 if (buf == NULL)
1140 {
451dad9c 1141 va_end (args);
37cc8ec1 1142 fatal (_("Out of virtual memory"));
252b5132
RH
1143 }
1144
1145 n = strlen (buf);
1146
b4c96d0d 1147 while ((size_t) ((f->buffer + f->size) - f->current) < n + 1)
252b5132
RH
1148 {
1149 size_t curroff;
1150
1151 curroff = f->current - f->buffer;
1152 f->size *= 2;
1153 f->buffer = xrealloc (f->buffer, f->size);
1154 f->current = f->buffer + curroff;
1155 }
1156
1157 memcpy (f->current, buf, n);
1158 f->current += n;
1159 f->current[0] = '\0';
1160
1161 free (buf);
1162
451dad9c 1163 VA_CLOSE (args);
252b5132
RH
1164 return n;
1165}
1166
1167/* The number of zeroes we want to see before we start skipping them.
1168 The number is arbitrarily chosen. */
1169
20fe0649 1170#ifndef SKIP_ZEROES
252b5132 1171#define SKIP_ZEROES (8)
20fe0649 1172#endif
252b5132
RH
1173
1174/* The number of zeroes to skip at the end of a section. If the
1175 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1176 SKIP_ZEROES, they will be disassembled. If there are fewer than
1177 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1178 attempt to avoid disassembling zeroes inserted by section
1179 alignment. */
1180
20fe0649 1181#ifndef SKIP_ZEROES_AT_END
252b5132 1182#define SKIP_ZEROES_AT_END (3)
20fe0649 1183#endif
252b5132
RH
1184
1185/* Disassemble some data in memory between given values. */
1186
1187static void
0af11b59
KH
1188disassemble_bytes (info, disassemble_fn, insns, data,
1189 start_offset, stop_offset, relppp,
252b5132
RH
1190 relppend)
1191 struct disassemble_info *info;
1192 disassembler_ftype disassemble_fn;
b34976b6 1193 bfd_boolean insns;
252b5132 1194 bfd_byte *data;
940b2b78
TW
1195 bfd_vma start_offset;
1196 bfd_vma stop_offset;
252b5132
RH
1197 arelent ***relppp;
1198 arelent **relppend;
1199{
1200 struct objdump_disasm_info *aux;
1201 asection *section;
940b2b78 1202 int octets_per_line;
b34976b6 1203 bfd_boolean done_dot;
252b5132 1204 int skip_addr_chars;
940b2b78
TW
1205 bfd_vma addr_offset;
1206 int opb = info->octets_per_byte;
252b5132
RH
1207
1208 aux = (struct objdump_disasm_info *) info->application_data;
1209 section = aux->sec;
1210
1211 if (insns)
940b2b78 1212 octets_per_line = 4;
252b5132 1213 else
940b2b78 1214 octets_per_line = 16;
252b5132
RH
1215
1216 /* Figure out how many characters to skip at the start of an
1217 address, to make the disassembly look nicer. We discard leading
1218 zeroes in chunks of 4, ensuring that there is always a leading
1219 zero remaining. */
1220 skip_addr_chars = 0;
1221 if (! prefix_addresses)
1222 {
1223 char buf[30];
1224 char *s;
1225
d8180c76
L
1226 bfd_sprintf_vma
1227 (aux->abfd, buf,
1228 (section->vma
1229 + bfd_section_size (section->owner, section) / opb));
252b5132
RH
1230 s = buf;
1231 while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
1232 && s[4] == '0')
1233 {
1234 skip_addr_chars += 4;
1235 s += 4;
1236 }
1237 }
1238
1239 info->insn_info_valid = 0;
1240
b34976b6 1241 done_dot = FALSE;
940b2b78
TW
1242 addr_offset = start_offset;
1243 while (addr_offset < stop_offset)
252b5132
RH
1244 {
1245 bfd_vma z;
940b2b78 1246 int octets = 0;
b34976b6 1247 bfd_boolean need_nl = FALSE;
252b5132 1248
940b2b78 1249 /* If we see more than SKIP_ZEROES octets of zeroes, we just
252b5132 1250 print `...'. */
940b2b78 1251 for (z = addr_offset * opb; z < stop_offset * opb; z++)
252b5132
RH
1252 if (data[z] != 0)
1253 break;
1254 if (! disassemble_zeroes
1255 && (info->insn_info_valid == 0
1256 || info->branch_delay_insns == 0)
940b2b78 1257 && (z - addr_offset * opb >= SKIP_ZEROES
0af11b59
KH
1258 || (z == stop_offset * opb &&
1259 z - addr_offset * opb < SKIP_ZEROES_AT_END)))
252b5132
RH
1260 {
1261 printf ("\t...\n");
1262
940b2b78 1263 /* If there are more nonzero octets to follow, we only skip
252b5132
RH
1264 zeroes in multiples of 4, to try to avoid running over
1265 the start of an instruction which happens to start with
1266 zero. */
940b2b78
TW
1267 if (z != stop_offset * opb)
1268 z = addr_offset * opb + ((z - addr_offset * opb) &~ 3);
252b5132 1269
940b2b78 1270 octets = z - addr_offset * opb;
252b5132
RH
1271 }
1272 else
1273 {
1274 char buf[50];
1275 SFILE sfile;
1276 int bpc = 0;
1277 int pb = 0;
1278
b34976b6 1279 done_dot = FALSE;
252b5132
RH
1280
1281 if (with_line_numbers || with_source_code)
76a406e5
NC
1282 /* The line number tables will refer to unadjusted
1283 section VMAs, so we must undo any VMA modifications
1284 when calling show_line. */
1285 show_line (aux->abfd, section, addr_offset - adjust_section_vma);
252b5132
RH
1286
1287 if (! prefix_addresses)
1288 {
1289 char *s;
1290
d8180c76 1291 bfd_sprintf_vma (aux->abfd, buf, section->vma + addr_offset);
252b5132
RH
1292 for (s = buf + skip_addr_chars; *s == '0'; s++)
1293 *s = ' ';
1294 if (*s == '\0')
1295 *--s = '0';
1296 printf ("%s:\t", buf + skip_addr_chars);
1297 }
1298 else
1299 {
b34976b6 1300 aux->require_sec = TRUE;
940b2b78 1301 objdump_print_address (section->vma + addr_offset, info);
b34976b6 1302 aux->require_sec = FALSE;
252b5132
RH
1303 putchar (' ');
1304 }
1305
1306 if (insns)
1307 {
1308 sfile.size = 120;
1309 sfile.buffer = xmalloc (sfile.size);
1310 sfile.current = sfile.buffer;
1311 info->fprintf_func = (fprintf_ftype) objdump_sprintf;
1312 info->stream = (FILE *) &sfile;
1313 info->bytes_per_line = 0;
1314 info->bytes_per_chunk = 0;
1315
8b1e6df3 1316#ifdef DISASSEMBLER_NEEDS_RELOCS
940b2b78 1317 /* FIXME: This is wrong. It tests the number of octets
252b5132
RH
1318 in the last instruction, not the current one. */
1319 if (*relppp < relppend
940b2b78 1320 && (**relppp)->address >= addr_offset
8b1e6df3 1321 && (**relppp)->address <= addr_offset + octets / opb)
252b5132
RH
1322 info->flags = INSN_HAS_RELOC;
1323 else
8b1e6df3 1324#endif
252b5132
RH
1325 info->flags = 0;
1326
940b2b78 1327 octets = (*disassemble_fn) (section->vma + addr_offset, info);
252b5132
RH
1328 info->fprintf_func = (fprintf_ftype) fprintf;
1329 info->stream = stdout;
1330 if (info->bytes_per_line != 0)
940b2b78
TW
1331 octets_per_line = info->bytes_per_line;
1332 if (octets < 0)
e07bf1ac
ILT
1333 {
1334 if (sfile.current != sfile.buffer)
1335 printf ("%s\n", sfile.buffer);
1336 free (sfile.buffer);
1337 break;
1338 }
252b5132
RH
1339 }
1340 else
1341 {
b4c96d0d 1342 bfd_vma j;
252b5132 1343
940b2b78
TW
1344 octets = octets_per_line;
1345 if (addr_offset + octets / opb > stop_offset)
1346 octets = (stop_offset - addr_offset) * opb;
252b5132 1347
940b2b78 1348 for (j = addr_offset * opb; j < addr_offset * opb + octets; ++j)
252b5132 1349 {
3882b010 1350 if (ISPRINT (data[j]))
940b2b78 1351 buf[j - addr_offset * opb] = data[j];
252b5132 1352 else
940b2b78 1353 buf[j - addr_offset * opb] = '.';
252b5132 1354 }
940b2b78 1355 buf[j - addr_offset * opb] = '\0';
252b5132
RH
1356 }
1357
1358 if (prefix_addresses
1359 ? show_raw_insn > 0
1360 : show_raw_insn >= 0)
1361 {
b4c96d0d 1362 bfd_vma j;
252b5132
RH
1363
1364 /* If ! prefix_addresses and ! wide_output, we print
940b2b78
TW
1365 octets_per_line octets per line. */
1366 pb = octets;
1367 if (pb > octets_per_line && ! prefix_addresses && ! wide_output)
1368 pb = octets_per_line;
252b5132
RH
1369
1370 if (info->bytes_per_chunk)
1371 bpc = info->bytes_per_chunk;
1372 else
1373 bpc = 1;
1374
940b2b78 1375 for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
252b5132
RH
1376 {
1377 int k;
1378 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1379 {
1380 for (k = bpc - 1; k >= 0; k--)
1381 printf ("%02x", (unsigned) data[j + k]);
1382 putchar (' ');
1383 }
1384 else
1385 {
1386 for (k = 0; k < bpc; k++)
1387 printf ("%02x", (unsigned) data[j + k]);
1388 putchar (' ');
1389 }
1390 }
1391
940b2b78 1392 for (; pb < octets_per_line; pb += bpc)
252b5132
RH
1393 {
1394 int k;
1395
1396 for (k = 0; k < bpc; k++)
1397 printf (" ");
1398 putchar (' ');
1399 }
1400
1401 /* Separate raw data from instruction by extra space. */
1402 if (insns)
1403 putchar ('\t');
1404 else
1405 printf (" ");
1406 }
1407
1408 if (! insns)
1409 printf ("%s", buf);
1410 else
1411 {
1412 printf ("%s", sfile.buffer);
1413 free (sfile.buffer);
1414 }
1415
1416 if (prefix_addresses
1417 ? show_raw_insn > 0
1418 : show_raw_insn >= 0)
1419 {
940b2b78 1420 while (pb < octets)
252b5132 1421 {
b4c96d0d 1422 bfd_vma j;
252b5132
RH
1423 char *s;
1424
1425 putchar ('\n');
940b2b78 1426 j = addr_offset * opb + pb;
252b5132 1427
d8180c76 1428 bfd_sprintf_vma (aux->abfd, buf, section->vma + j / opb);
252b5132
RH
1429 for (s = buf + skip_addr_chars; *s == '0'; s++)
1430 *s = ' ';
1431 if (*s == '\0')
1432 *--s = '0';
1433 printf ("%s:\t", buf + skip_addr_chars);
1434
940b2b78
TW
1435 pb += octets_per_line;
1436 if (pb > octets)
1437 pb = octets;
1438 for (; j < addr_offset * opb + pb; j += bpc)
252b5132
RH
1439 {
1440 int k;
1441
1442 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1443 {
1444 for (k = bpc - 1; k >= 0; k--)
1445 printf ("%02x", (unsigned) data[j + k]);
1446 putchar (' ');
1447 }
1448 else
1449 {
1450 for (k = 0; k < bpc; k++)
1451 printf ("%02x", (unsigned) data[j + k]);
1452 putchar (' ');
1453 }
1454 }
1455 }
1456 }
1457
1458 if (!wide_output)
1459 putchar ('\n');
1460 else
b34976b6 1461 need_nl = TRUE;
252b5132
RH
1462 }
1463
8b1e6df3 1464 if ((section->flags & SEC_RELOC) != 0
0af11b59
KH
1465#ifndef DISASSEMBLER_NEEDS_RELOCS
1466 && dump_reloc_info
8b1e6df3
NC
1467#endif
1468 )
252b5132
RH
1469 {
1470 while ((*relppp) < relppend
940b2b78
TW
1471 && ((**relppp)->address >= (bfd_vma) addr_offset
1472 && (**relppp)->address < (bfd_vma) addr_offset + octets / opb))
8b1e6df3
NC
1473#ifdef DISASSEMBLER_NEEDS_RELOCS
1474 if (! dump_reloc_info)
1475 ++(*relppp);
1476 else
1477#endif
252b5132
RH
1478 {
1479 arelent *q;
1480
1481 q = **relppp;
1482
1483 if (wide_output)
1484 putchar ('\t');
1485 else
1486 printf ("\t\t\t");
1487
b34976b6 1488 objdump_print_value (section->vma + q->address, info, TRUE);
252b5132
RH
1489
1490 printf (": %s\t", q->howto->name);
1491
1492 if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
1493 printf ("*unknown*");
1494 else
1495 {
1496 const char *sym_name;
1497
1498 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
1499 if (sym_name != NULL && *sym_name != '\0')
1500 objdump_print_symname (aux->abfd, info, *q->sym_ptr_ptr);
1501 else
1502 {
1503 asection *sym_sec;
1504
1505 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
1506 sym_name = bfd_get_section_name (aux->abfd, sym_sec);
1507 if (sym_name == NULL || *sym_name == '\0')
1508 sym_name = "*unknown*";
1509 printf ("%s", sym_name);
1510 }
1511 }
1512
1513 if (q->addend)
1514 {
1515 printf ("+0x");
b34976b6 1516 objdump_print_value (q->addend, info, TRUE);
252b5132
RH
1517 }
1518
1519 printf ("\n");
b34976b6 1520 need_nl = FALSE;
252b5132
RH
1521 ++(*relppp);
1522 }
1523 }
1524
1525 if (need_nl)
1526 printf ("\n");
1527
940b2b78 1528 addr_offset += octets / opb;
252b5132
RH
1529 }
1530}
1531
1532/* Disassemble the contents of an object file. */
1533
1534static void
1535disassemble_data (abfd)
1536 bfd *abfd;
1537{
f6af82bd 1538 unsigned long addr_offset;
252b5132
RH
1539 disassembler_ftype disassemble_fn;
1540 struct disassemble_info disasm_info;
1541 struct objdump_disasm_info aux;
1542 asection *section;
ea584125 1543 unsigned int opb;
252b5132
RH
1544
1545 print_files = NULL;
1546 prev_functionname = NULL;
1547 prev_line = -1;
1548
1549 /* We make a copy of syms to sort. We don't want to sort syms
1550 because that will screw up the relocs. */
1551 sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
1552 memcpy (sorted_syms, syms, symcount * sizeof (asymbol *));
1553
1554 sorted_symcount = remove_useless_symbols (sorted_syms, symcount);
1555
98a91d6a 1556 /* Sort the symbols into section and symbol order. */
252b5132
RH
1557 qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
1558
98a91d6a
NC
1559 INIT_DISASSEMBLE_INFO (disasm_info, stdout, fprintf);
1560
252b5132
RH
1561 disasm_info.application_data = (PTR) &aux;
1562 aux.abfd = abfd;
b34976b6 1563 aux.require_sec = FALSE;
252b5132
RH
1564 disasm_info.print_address_func = objdump_print_address;
1565 disasm_info.symbol_at_address_func = objdump_symbol_at_address;
1566
1567 if (machine != (char *) NULL)
1568 {
1569 const bfd_arch_info_type *info = bfd_scan_arch (machine);
98a91d6a 1570
252b5132 1571 if (info == NULL)
98a91d6a
NC
1572 fatal (_("Can't use supplied machine %s"), machine);
1573
252b5132
RH
1574 abfd->arch_info = info;
1575 }
1576
1577 if (endian != BFD_ENDIAN_UNKNOWN)
1578 {
1579 struct bfd_target *xvec;
1580
1581 xvec = (struct bfd_target *) xmalloc (sizeof (struct bfd_target));
1582 memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
1583 xvec->byteorder = endian;
1584 abfd->xvec = xvec;
1585 }
1586
1587 disassemble_fn = disassembler (abfd);
1588 if (!disassemble_fn)
1589 {
37cc8ec1
AM
1590 non_fatal (_("Can't disassemble for architecture %s\n"),
1591 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
75cd796a 1592 exit_status = 1;
252b5132
RH
1593 return;
1594 }
1595
ea584125
TW
1596 opb = bfd_octets_per_byte (abfd);
1597
252b5132
RH
1598 disasm_info.flavour = bfd_get_flavour (abfd);
1599 disasm_info.arch = bfd_get_arch (abfd);
1600 disasm_info.mach = bfd_get_mach (abfd);
dd92f639 1601 disasm_info.disassembler_options = disassembler_options;
ea584125 1602 disasm_info.octets_per_byte = opb;
0af11b59 1603
252b5132 1604 if (bfd_big_endian (abfd))
a8a9050d 1605 disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
252b5132 1606 else if (bfd_little_endian (abfd))
a8a9050d 1607 disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_LITTLE;
252b5132
RH
1608 else
1609 /* ??? Aborting here seems too drastic. We could default to big or little
1610 instead. */
1611 disasm_info.endian = BFD_ENDIAN_UNKNOWN;
1612
1613 for (section = abfd->sections;
1614 section != (asection *) NULL;
1615 section = section->next)
1616 {
1617 bfd_byte *data = NULL;
1618 bfd_size_type datasize = 0;
1619 arelent **relbuf = NULL;
1620 arelent **relpp = NULL;
1621 arelent **relppend = NULL;
f6af82bd 1622 unsigned long stop_offset;
252b5132
RH
1623 asymbol *sym = NULL;
1624 long place = 0;
1625
1626 if ((section->flags & SEC_LOAD) == 0
1627 || (! disassemble_all
1628 && only == NULL
1629 && (section->flags & SEC_CODE) == 0))
1630 continue;
1631 if (only != (char *) NULL && strcmp (only, section->name) != 0)
1632 continue;
1633
8b1e6df3 1634 if ((section->flags & SEC_RELOC) != 0
0af11b59 1635#ifndef DISASSEMBLER_NEEDS_RELOCS
8b1e6df3
NC
1636 && dump_reloc_info
1637#endif
0af11b59 1638 )
252b5132
RH
1639 {
1640 long relsize;
1641
1642 relsize = bfd_get_reloc_upper_bound (abfd, section);
1643 if (relsize < 0)
1644 bfd_fatal (bfd_get_filename (abfd));
1645
1646 if (relsize > 0)
1647 {
1648 long relcount;
1649
1650 relbuf = (arelent **) xmalloc (relsize);
1651 relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
1652 if (relcount < 0)
1653 bfd_fatal (bfd_get_filename (abfd));
1654
1655 /* Sort the relocs by address. */
1656 qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
1657
1658 relpp = relbuf;
1659 relppend = relpp + relcount;
1660
1661 /* Skip over the relocs belonging to addresses below the
1662 start address. */
1663 if (start_address != (bfd_vma) -1)
98a91d6a
NC
1664 while (relpp < relppend
1665 && (*relpp)->address < start_address)
1666 ++relpp;
252b5132
RH
1667 }
1668 }
1669
1670 printf (_("Disassembly of section %s:\n"), section->name);
1671
1672 datasize = bfd_get_section_size_before_reloc (section);
1673 if (datasize == 0)
1674 continue;
1675
1676 data = (bfd_byte *) xmalloc ((size_t) datasize);
1677
1678 bfd_get_section_contents (abfd, section, data, 0, datasize);
1679
1680 aux.sec = section;
1681 disasm_info.buffer = data;
1682 disasm_info.buffer_vma = section->vma;
1683 disasm_info.buffer_length = datasize;
8f9d9bd9 1684 disasm_info.section = section;
98a91d6a 1685
252b5132
RH
1686 if (start_address == (bfd_vma) -1
1687 || start_address < disasm_info.buffer_vma)
940b2b78 1688 addr_offset = 0;
252b5132 1689 else
940b2b78 1690 addr_offset = start_address - disasm_info.buffer_vma;
98a91d6a 1691
252b5132 1692 if (stop_address == (bfd_vma) -1)
940b2b78 1693 stop_offset = datasize / opb;
252b5132
RH
1694 else
1695 {
1696 if (stop_address < disasm_info.buffer_vma)
940b2b78 1697 stop_offset = 0;
252b5132 1698 else
940b2b78
TW
1699 stop_offset = stop_address - disasm_info.buffer_vma;
1700 if (stop_offset > disasm_info.buffer_length / opb)
1701 stop_offset = disasm_info.buffer_length / opb;
252b5132
RH
1702 }
1703
940b2b78 1704 sym = find_symbol_for_address (abfd, section, section->vma + addr_offset,
b34976b6 1705 TRUE, &place);
252b5132 1706
940b2b78 1707 while (addr_offset < stop_offset)
252b5132
RH
1708 {
1709 asymbol *nextsym;
f6af82bd 1710 unsigned long nextstop_offset;
b34976b6 1711 bfd_boolean insns;
0af11b59 1712
940b2b78 1713 if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + addr_offset)
252b5132
RH
1714 {
1715 int x;
1716
1717 for (x = place;
1718 (x < sorted_symcount
940b2b78 1719 && bfd_asymbol_value (sorted_syms[x]) <= section->vma + addr_offset);
252b5132
RH
1720 ++x)
1721 continue;
98a91d6a 1722
252b5132
RH
1723 disasm_info.symbols = & sorted_syms[place];
1724 disasm_info.num_symbols = x - place;
1725 }
1726 else
1727 disasm_info.symbols = NULL;
1728
1729 if (! prefix_addresses)
1730 {
98a91d6a 1731 (* disasm_info.fprintf_func) (disasm_info.stream, "\n");
252b5132 1732 objdump_print_addr_with_sym (abfd, section, sym,
940b2b78 1733 section->vma + addr_offset,
252b5132 1734 &disasm_info,
b34976b6 1735 FALSE);
98a91d6a 1736 (* disasm_info.fprintf_func) (disasm_info.stream, ":\n");
252b5132 1737 }
0af11b59 1738
940b2b78 1739 if (sym != NULL && bfd_asymbol_value (sym) > section->vma + addr_offset)
252b5132
RH
1740 nextsym = sym;
1741 else if (sym == NULL)
1742 nextsym = NULL;
1743 else
1744 {
f1f8ce07
ILT
1745 /* Search forward for the next appropriate symbol in
1746 SECTION. Note that all the symbols are sorted
1747 together into one big array, and that some sections
1748 may have overlapping addresses. */
252b5132 1749 while (place < sorted_symcount
252b5132
RH
1750 && (sorted_syms[place]->section != section
1751 || (bfd_asymbol_value (sorted_syms[place])
1752 <= bfd_asymbol_value (sym))))
1753 ++place;
1754 if (place >= sorted_symcount)
1755 nextsym = NULL;
1756 else
1757 nextsym = sorted_syms[place];
1758 }
0af11b59 1759
940b2b78 1760 if (sym != NULL && bfd_asymbol_value (sym) > section->vma + addr_offset)
252b5132 1761 {
940b2b78
TW
1762 nextstop_offset = bfd_asymbol_value (sym) - section->vma;
1763 if (nextstop_offset > stop_offset)
1764 nextstop_offset = stop_offset;
252b5132
RH
1765 }
1766 else if (nextsym == NULL)
940b2b78 1767 nextstop_offset = stop_offset;
252b5132
RH
1768 else
1769 {
940b2b78
TW
1770 nextstop_offset = bfd_asymbol_value (nextsym) - section->vma;
1771 if (nextstop_offset > stop_offset)
1772 nextstop_offset = stop_offset;
252b5132 1773 }
0af11b59 1774
252b5132
RH
1775 /* If a symbol is explicitly marked as being an object
1776 rather than a function, just dump the bytes without
1777 disassembling them. */
1778 if (disassemble_all
1779 || sym == NULL
940b2b78 1780 || bfd_asymbol_value (sym) > section->vma + addr_offset
252b5132
RH
1781 || ((sym->flags & BSF_OBJECT) == 0
1782 && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
1783 == NULL)
1784 && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
1785 == NULL))
1786 || (sym->flags & BSF_FUNCTION) != 0)
b34976b6 1787 insns = TRUE;
252b5132 1788 else
b34976b6 1789 insns = FALSE;
0af11b59
KH
1790
1791 disassemble_bytes (&disasm_info, disassemble_fn, insns, data,
1792 addr_offset, nextstop_offset, &relpp, relppend);
1793
940b2b78 1794 addr_offset = nextstop_offset;
252b5132
RH
1795 sym = nextsym;
1796 }
0af11b59 1797
252b5132 1798 free (data);
98a91d6a 1799
252b5132
RH
1800 if (relbuf != NULL)
1801 free (relbuf);
1802 }
1803 free (sorted_syms);
1804}
1805\f
252b5132
RH
1806/* Dump the stabs sections from an object file that has a section that
1807 uses Sun stabs encoding. */
1808
1809static void
1810dump_stabs (abfd)
1811 bfd *abfd;
1812{
1813 dump_section_stabs (abfd, ".stab", ".stabstr");
1814 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
1815 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
1816 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
1817}
1818
252b5132
RH
1819/* Read ABFD's stabs section STABSECT_NAME into `stabs'
1820 and string table section STRSECT_NAME into `strtab'.
b34976b6
AM
1821 If the section exists and was read, allocate the space and return TRUE.
1822 Otherwise return FALSE. */
252b5132 1823
b34976b6 1824static bfd_boolean
252b5132
RH
1825read_section_stabs (abfd, stabsect_name, strsect_name)
1826 bfd *abfd;
1827 const char *stabsect_name;
1828 const char *strsect_name;
1829{
1830 asection *stabsect, *stabstrsect;
1831
1832 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
1833 if (0 == stabsect)
1834 {
1835 printf (_("No %s section present\n\n"), stabsect_name);
b34976b6 1836 return FALSE;
252b5132
RH
1837 }
1838
1839 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
1840 if (0 == stabstrsect)
1841 {
37cc8ec1
AM
1842 non_fatal (_("%s has no %s section"),
1843 bfd_get_filename (abfd), strsect_name);
75cd796a 1844 exit_status = 1;
b34976b6 1845 return FALSE;
252b5132 1846 }
0af11b59 1847
252b5132
RH
1848 stab_size = bfd_section_size (abfd, stabsect);
1849 stabstr_size = bfd_section_size (abfd, stabstrsect);
1850
1851 stabs = (bfd_byte *) xmalloc (stab_size);
1852 strtab = (char *) xmalloc (stabstr_size);
0af11b59 1853
252b5132
RH
1854 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
1855 {
37cc8ec1
AM
1856 non_fatal (_("Reading %s section of %s failed: %s"),
1857 stabsect_name, bfd_get_filename (abfd),
1858 bfd_errmsg (bfd_get_error ()));
252b5132
RH
1859 free (stabs);
1860 free (strtab);
75cd796a 1861 exit_status = 1;
b34976b6 1862 return FALSE;
252b5132
RH
1863 }
1864
1865 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
1866 stabstr_size))
1867 {
37cc8ec1
AM
1868 non_fatal (_("Reading %s section of %s failed: %s\n"),
1869 strsect_name, bfd_get_filename (abfd),
1870 bfd_errmsg (bfd_get_error ()));
252b5132
RH
1871 free (stabs);
1872 free (strtab);
75cd796a 1873 exit_status = 1;
b34976b6 1874 return FALSE;
252b5132
RH
1875 }
1876
b34976b6 1877 return TRUE;
252b5132
RH
1878}
1879
1880/* Stabs entries use a 12 byte format:
1881 4 byte string table index
1882 1 byte stab type
1883 1 byte stab other field
1884 2 byte stab desc field
1885 4 byte stab value
1886 FIXME: This will have to change for a 64 bit object format. */
1887
1888#define STRDXOFF (0)
1889#define TYPEOFF (4)
1890#define OTHEROFF (5)
1891#define DESCOFF (6)
1892#define VALOFF (8)
1893#define STABSIZE (12)
1894
1895/* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1896 using string table section STRSECT_NAME (in `strtab'). */
1897
1898static void
1899print_section_stabs (abfd, stabsect_name, strsect_name)
1900 bfd *abfd;
1901 const char *stabsect_name;
b4c96d0d 1902 const char *strsect_name ATTRIBUTE_UNUSED;
252b5132
RH
1903{
1904 int i;
1905 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
1906 bfd_byte *stabp, *stabs_end;
1907
1908 stabp = stabs;
1909 stabs_end = stabp + stab_size;
1910
1911 printf (_("Contents of %s section:\n\n"), stabsect_name);
1912 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
1913
1914 /* Loop through all symbols and print them.
1915
1916 We start the index at -1 because there is a dummy symbol on
1917 the front of stabs-in-{coff,elf} sections that supplies sizes. */
252b5132
RH
1918 for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++)
1919 {
1920 const char *name;
1921 unsigned long strx;
1922 unsigned char type, other;
1923 unsigned short desc;
1924 bfd_vma value;
1925
1926 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
1927 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
1928 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
1929 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
1930 value = bfd_h_get_32 (abfd, stabp + VALOFF);
1931
1932 printf ("\n%-6d ", i);
1933 /* Either print the stab name, or, if unnamed, print its number
0af11b59 1934 again (makes consistent formatting for tools like awk). */
252b5132
RH
1935 name = bfd_get_stab_name (type);
1936 if (name != NULL)
1937 printf ("%-6s", name);
1938 else if (type == N_UNDF)
1939 printf ("HdrSym");
1940 else
1941 printf ("%-6d", type);
1942 printf (" %-6d %-6d ", other, desc);
d8180c76 1943 bfd_printf_vma (abfd, value);
252b5132
RH
1944 printf (" %-6lu", strx);
1945
1946 /* Symbols with type == 0 (N_UNDF) specify the length of the
1947 string table associated with this file. We use that info
1948 to know how to relocate the *next* file's string table indices. */
252b5132
RH
1949 if (type == N_UNDF)
1950 {
1951 file_string_table_offset = next_file_string_table_offset;
1952 next_file_string_table_offset += value;
1953 }
1954 else
1955 {
1956 /* Using the (possibly updated) string table offset, print the
1957 string (if any) associated with this symbol. */
252b5132
RH
1958 if ((strx + file_string_table_offset) < stabstr_size)
1959 printf (" %s", &strtab[strx + file_string_table_offset]);
1960 else
1961 printf (" *");
1962 }
1963 }
1964 printf ("\n\n");
1965}
1966
1967static void
1968dump_section_stabs (abfd, stabsect_name, strsect_name)
1969 bfd *abfd;
1970 char *stabsect_name;
1971 char *strsect_name;
1972{
1973 asection *s;
1974
1975 /* Check for section names for which stabsect_name is a prefix, to
1976 handle .stab0, etc. */
1977 for (s = abfd->sections;
1978 s != NULL;
1979 s = s->next)
1980 {
1981 int len;
1982
1983 len = strlen (stabsect_name);
1984
1985 /* If the prefix matches, and the files section name ends with a
1986 nul or a digit, then we match. I.e., we want either an exact
1987 match or a section followed by a number. */
1988 if (strncmp (stabsect_name, s->name, len) == 0
1989 && (s->name[len] == '\000'
3882b010 1990 || ISDIGIT (s->name[len])))
252b5132
RH
1991 {
1992 if (read_section_stabs (abfd, s->name, strsect_name))
1993 {
1994 print_section_stabs (abfd, s->name, strsect_name);
1995 free (stabs);
1996 free (strtab);
1997 }
1998 }
1999 }
2000}
98a91d6a 2001
252b5132
RH
2002\f
2003static void
2004dump_bfd_header (abfd)
2005 bfd *abfd;
2006{
2007 char *comma = "";
2008
2009 printf (_("architecture: %s, "),
2010 bfd_printable_arch_mach (bfd_get_arch (abfd),
2011 bfd_get_mach (abfd)));
2012 printf (_("flags 0x%08x:\n"), abfd->flags);
2013
2014#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
2015 PF (HAS_RELOC, "HAS_RELOC");
2016 PF (EXEC_P, "EXEC_P");
2017 PF (HAS_LINENO, "HAS_LINENO");
2018 PF (HAS_DEBUG, "HAS_DEBUG");
2019 PF (HAS_SYMS, "HAS_SYMS");
2020 PF (HAS_LOCALS, "HAS_LOCALS");
2021 PF (DYNAMIC, "DYNAMIC");
2022 PF (WP_TEXT, "WP_TEXT");
2023 PF (D_PAGED, "D_PAGED");
2024 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
026df7c5 2025 PF (HAS_LOAD_PAGE, "HAS_LOAD_PAGE");
252b5132 2026 printf (_("\nstart address 0x"));
d8180c76 2027 bfd_printf_vma (abfd, abfd->start_address);
252b5132
RH
2028 printf ("\n");
2029}
98a91d6a 2030
252b5132
RH
2031\f
2032static void
2033dump_bfd_private_header (abfd)
2034bfd *abfd;
2035{
2036 bfd_print_private_bfd_data (abfd, stdout);
2037}
2038
98a91d6a 2039/* Dump selected contents of ABFD. */
d24de309 2040
252b5132 2041static void
d24de309 2042dump_bfd (abfd)
252b5132
RH
2043 bfd *abfd;
2044{
252b5132
RH
2045 /* If we are adjusting section VMA's, change them all now. Changing
2046 the BFD information is a hack. However, we must do it, or
2047 bfd_find_nearest_line will not do the right thing. */
2048 if (adjust_section_vma != 0)
2049 {
2050 asection *s;
2051
2052 for (s = abfd->sections; s != NULL; s = s->next)
2053 {
2054 s->vma += adjust_section_vma;
2055 s->lma += adjust_section_vma;
2056 }
2057 }
2058
fe0507eb
AM
2059 printf (_("\n%s: file format %s\n"), bfd_get_filename (abfd),
2060 abfd->xvec->name);
252b5132 2061 if (dump_ar_hdrs)
b34976b6 2062 print_arelt_descr (stdout, abfd, TRUE);
252b5132
RH
2063 if (dump_file_header)
2064 dump_bfd_header (abfd);
2065 if (dump_private_headers)
2066 dump_bfd_private_header (abfd);
2067 putchar ('\n');
2068 if (dump_section_headers)
2069 dump_headers (abfd);
026df7c5 2070
252b5132 2071 if (dump_symtab || dump_reloc_info || disassemble || dump_debugging)
026df7c5 2072 syms = slurp_symtab (abfd);
252b5132 2073 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
026df7c5
NC
2074 dynsyms = slurp_dynamic_symtab (abfd);
2075
252b5132 2076 if (dump_symtab)
b34976b6 2077 dump_symbols (abfd, FALSE);
252b5132 2078 if (dump_dynamic_symtab)
b34976b6 2079 dump_symbols (abfd, TRUE);
252b5132
RH
2080 if (dump_stab_section_info)
2081 dump_stabs (abfd);
2082 if (dump_reloc_info && ! disassemble)
2083 dump_relocs (abfd);
2084 if (dump_dynamic_reloc_info)
2085 dump_dynamic_relocs (abfd);
2086 if (dump_section_contents)
2087 dump_data (abfd);
2088 if (disassemble)
2089 disassemble_data (abfd);
2090 if (dump_debugging)
2091 {
2092 PTR dhandle;
2093
2094 dhandle = read_debugging_info (abfd, syms, symcount);
2095 if (dhandle != NULL)
2096 {
2097 if (! print_debugging_info (stdout, dhandle))
75cd796a 2098 {
37cc8ec1
AM
2099 non_fatal (_("%s: printing debugging information failed"),
2100 bfd_get_filename (abfd));
75cd796a
ILT
2101 exit_status = 1;
2102 }
252b5132
RH
2103 }
2104 }
026df7c5 2105
252b5132
RH
2106 if (syms)
2107 {
2108 free (syms);
2109 syms = NULL;
2110 }
026df7c5 2111
252b5132
RH
2112 if (dynsyms)
2113 {
2114 free (dynsyms);
2115 dynsyms = NULL;
2116 }
2117}
2118
d24de309
ILT
2119static void
2120display_bfd (abfd)
2121 bfd *abfd;
2122{
2123 char **matching;
2124
2125 if (bfd_check_format_matches (abfd, bfd_object, &matching))
2126 {
2127 dump_bfd (abfd);
2128 return;
2129 }
2130
2131 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
2132 {
2133 nonfatal (bfd_get_filename (abfd));
2134 list_matching_formats (matching);
2135 free (matching);
2136 return;
2137 }
2138
2139 if (bfd_get_error () != bfd_error_file_not_recognized)
2140 {
2141 nonfatal (bfd_get_filename (abfd));
2142 return;
2143 }
2144
2145 if (bfd_check_format_matches (abfd, bfd_core, &matching))
2146 {
2147 dump_bfd (abfd);
2148 return;
2149 }
2150
2151 nonfatal (bfd_get_filename (abfd));
2152
2153 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
2154 {
2155 list_matching_formats (matching);
2156 free (matching);
2157 }
2158}
2159
252b5132
RH
2160static void
2161display_file (filename, target)
2162 char *filename;
2163 char *target;
2164{
2165 bfd *file, *arfile = (bfd *) NULL;
2166
2167 file = bfd_openr (filename, target);
2168 if (file == NULL)
2169 {
75cd796a 2170 nonfatal (filename);
252b5132
RH
2171 return;
2172 }
2173
b34976b6 2174 if (bfd_check_format (file, bfd_archive))
252b5132
RH
2175 {
2176 bfd *last_arfile = NULL;
2177
2178 printf (_("In archive %s:\n"), bfd_get_filename (file));
2179 for (;;)
2180 {
2181 bfd_set_error (bfd_error_no_error);
2182
2183 arfile = bfd_openr_next_archived_file (file, arfile);
2184 if (arfile == NULL)
2185 {
2186 if (bfd_get_error () != bfd_error_no_more_archived_files)
75cd796a 2187 nonfatal (bfd_get_filename (file));
252b5132
RH
2188 break;
2189 }
2190
2191 display_bfd (arfile);
2192
2193 if (last_arfile != NULL)
2194 bfd_close (last_arfile);
2195 last_arfile = arfile;
2196 }
2197
2198 if (last_arfile != NULL)
2199 bfd_close (last_arfile);
2200 }
2201 else
2202 display_bfd (file);
2203
2204 bfd_close (file);
2205}
2206\f
98a91d6a 2207/* Actually display the various requested regions. */
252b5132
RH
2208
2209static void
2210dump_data (abfd)
2211 bfd *abfd;
2212{
2213 asection *section;
2214 bfd_byte *data = 0;
2215 bfd_size_type datasize = 0;
940b2b78
TW
2216 bfd_size_type addr_offset;
2217 bfd_size_type start_offset, stop_offset;
f6af82bd 2218 unsigned int opb = bfd_octets_per_byte (abfd);
252b5132
RH
2219
2220 for (section = abfd->sections; section != NULL; section =
2221 section->next)
2222 {
2223 int onaline = 16;
2224
2225 if (only == (char *) NULL ||
2226 strcmp (only, section->name) == 0)
2227 {
2228 if (section->flags & SEC_HAS_CONTENTS)
2229 {
2230 printf (_("Contents of section %s:\n"), section->name);
2231
2232 if (bfd_section_size (abfd, section) == 0)
2233 continue;
2234 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
2235 datasize = bfd_section_size (abfd, section);
2236
2237
2238 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
2239
2240 if (start_address == (bfd_vma) -1
2241 || start_address < section->vma)
940b2b78 2242 start_offset = 0;
252b5132 2243 else
940b2b78 2244 start_offset = start_address - section->vma;
252b5132 2245 if (stop_address == (bfd_vma) -1)
940b2b78 2246 stop_offset = bfd_section_size (abfd, section) / opb;
252b5132
RH
2247 else
2248 {
2249 if (stop_address < section->vma)
940b2b78 2250 stop_offset = 0;
252b5132 2251 else
940b2b78
TW
2252 stop_offset = stop_address - section->vma;
2253 if (stop_offset > bfd_section_size (abfd, section) / opb)
2254 stop_offset = bfd_section_size (abfd, section) / opb;
252b5132 2255 }
0af11b59 2256 for (addr_offset = start_offset;
8ab56b6f 2257 addr_offset < stop_offset; addr_offset += onaline / opb)
252b5132
RH
2258 {
2259 bfd_size_type j;
2260
0af11b59
KH
2261 printf (" %04lx ", (unsigned long int)
2262 (addr_offset + section->vma));
2263 for (j = addr_offset * opb;
2264 j < addr_offset * opb + onaline; j++)
252b5132 2265 {
940b2b78 2266 if (j < stop_offset * opb)
252b5132
RH
2267 printf ("%02x", (unsigned) (data[j]));
2268 else
2269 printf (" ");
2270 if ((j & 3) == 3)
2271 printf (" ");
2272 }
2273
2274 printf (" ");
8ab56b6f
AM
2275 for (j = addr_offset * opb;
2276 j < addr_offset * opb + onaline; j++)
252b5132 2277 {
940b2b78 2278 if (j >= stop_offset * opb)
252b5132
RH
2279 printf (" ");
2280 else
3882b010 2281 printf ("%c", ISPRINT (data[j]) ? data[j] : '.');
252b5132
RH
2282 }
2283 putchar ('\n');
2284 }
2285 free (data);
2286 }
2287 }
2288 }
2289}
2290
98a91d6a
NC
2291/* Should perhaps share code and display with nm? */
2292
252b5132
RH
2293static void
2294dump_symbols (abfd, dynamic)
b4c96d0d 2295 bfd *abfd ATTRIBUTE_UNUSED;
b34976b6 2296 bfd_boolean dynamic;
252b5132
RH
2297{
2298 asymbol **current;
2299 long max;
2300 long count;
2301
2302 if (dynamic)
2303 {
2304 current = dynsyms;
2305 max = dynsymcount;
252b5132
RH
2306 printf ("DYNAMIC SYMBOL TABLE:\n");
2307 }
2308 else
2309 {
2310 current = syms;
2311 max = symcount;
252b5132
RH
2312 printf ("SYMBOL TABLE:\n");
2313 }
2314
a1df01d1
AM
2315 if (max == 0)
2316 printf (_("no symbols\n"));
2317
252b5132
RH
2318 for (count = 0; count < max; count++)
2319 {
2320 if (*current)
2321 {
2322 bfd *cur_bfd = bfd_asymbol_bfd (*current);
2323
2324 if (cur_bfd != NULL)
2325 {
2326 const char *name;
2327 char *alloc;
2328
a6637ec0 2329 name = (*current)->name;
252b5132
RH
2330 alloc = NULL;
2331 if (do_demangle && name != NULL && *name != '\0')
2332 {
252b5132
RH
2333 /* If we want to demangle the name, we demangle it
2334 here, and temporarily clobber it while calling
2335 bfd_print_symbol. FIXME: This is a gross hack. */
a6637ec0
AM
2336 alloc = demangle (cur_bfd, name);
2337 (*current)->name = alloc;
252b5132
RH
2338 }
2339
2340 bfd_print_symbol (cur_bfd, stdout, *current,
2341 bfd_print_symbol_all);
2342
2343 (*current)->name = name;
2344 if (alloc != NULL)
2345 free (alloc);
2346
2347 printf ("\n");
2348 }
2349 }
2350 current++;
2351 }
2352 printf ("\n");
2353 printf ("\n");
2354}
2355
2356static void
2357dump_relocs (abfd)
2358 bfd *abfd;
2359{
2360 arelent **relpp;
2361 long relcount;
2362 asection *a;
2363
2364 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
2365 {
2366 long relsize;
2367
2368 if (bfd_is_abs_section (a))
2369 continue;
2370 if (bfd_is_und_section (a))
2371 continue;
2372 if (bfd_is_com_section (a))
2373 continue;
2374
2375 if (only)
2376 {
2377 if (strcmp (only, a->name))
2378 continue;
2379 }
2380 else if ((a->flags & SEC_RELOC) == 0)
2381 continue;
2382
2383 relsize = bfd_get_reloc_upper_bound (abfd, a);
2384 if (relsize < 0)
2385 bfd_fatal (bfd_get_filename (abfd));
2386
2387 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
2388
2389 if (relsize == 0)
2390 {
2391 printf (" (none)\n\n");
2392 }
2393 else
2394 {
2395 relpp = (arelent **) xmalloc (relsize);
2396 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
98a91d6a 2397
252b5132
RH
2398 if (relcount < 0)
2399 bfd_fatal (bfd_get_filename (abfd));
2400 else if (relcount == 0)
98a91d6a 2401 printf (" (none)\n\n");
252b5132
RH
2402 else
2403 {
2404 printf ("\n");
2405 dump_reloc_set (abfd, a, relpp, relcount);
2406 printf ("\n\n");
2407 }
2408 free (relpp);
2409 }
2410 }
2411}
2412
2413static void
2414dump_dynamic_relocs (abfd)
2415 bfd *abfd;
2416{
2417 long relsize;
2418 arelent **relpp;
2419 long relcount;
2420
2421 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
2422 if (relsize < 0)
2423 bfd_fatal (bfd_get_filename (abfd));
2424
2425 printf ("DYNAMIC RELOCATION RECORDS");
2426
2427 if (relsize == 0)
98a91d6a 2428 printf (" (none)\n\n");
252b5132
RH
2429 else
2430 {
2431 relpp = (arelent **) xmalloc (relsize);
2432 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
98a91d6a 2433
252b5132
RH
2434 if (relcount < 0)
2435 bfd_fatal (bfd_get_filename (abfd));
2436 else if (relcount == 0)
98a91d6a 2437 printf (" (none)\n\n");
252b5132
RH
2438 else
2439 {
2440 printf ("\n");
2441 dump_reloc_set (abfd, (asection *) NULL, relpp, relcount);
2442 printf ("\n\n");
2443 }
2444 free (relpp);
2445 }
2446}
2447
2448static void
2449dump_reloc_set (abfd, sec, relpp, relcount)
2450 bfd *abfd;
2451 asection *sec;
2452 arelent **relpp;
2453 long relcount;
2454{
2455 arelent **p;
2456 char *last_filename, *last_functionname;
2457 unsigned int last_line;
2458
2459 /* Get column headers lined up reasonably. */
2460 {
2461 static int width;
98a91d6a 2462
252b5132
RH
2463 if (width == 0)
2464 {
2465 char buf[30];
d8180c76 2466 bfd_sprintf_vma (abfd, buf, (bfd_vma) -1);
252b5132
RH
2467 width = strlen (buf) - 7;
2468 }
2469 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
2470 }
2471
2472 last_filename = NULL;
2473 last_functionname = NULL;
2474 last_line = 0;
2475
2476 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
2477 {
2478 arelent *q = *p;
2479 const char *filename, *functionname;
2480 unsigned int line;
2481 const char *sym_name;
2482 const char *section_name;
2483
2484 if (start_address != (bfd_vma) -1
2485 && q->address < start_address)
2486 continue;
2487 if (stop_address != (bfd_vma) -1
2488 && q->address > stop_address)
2489 continue;
2490
2491 if (with_line_numbers
2492 && sec != NULL
2493 && bfd_find_nearest_line (abfd, sec, syms, q->address,
2494 &filename, &functionname, &line))
2495 {
2496 if (functionname != NULL
2497 && (last_functionname == NULL
2498 || strcmp (functionname, last_functionname) != 0))
2499 {
2500 printf ("%s():\n", functionname);
2501 if (last_functionname != NULL)
2502 free (last_functionname);
2503 last_functionname = xstrdup (functionname);
2504 }
98a91d6a 2505
252b5132
RH
2506 if (line > 0
2507 && (line != last_line
2508 || (filename != NULL
2509 && last_filename != NULL
2510 && strcmp (filename, last_filename) != 0)))
2511 {
2512 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
2513 last_line = line;
2514 if (last_filename != NULL)
2515 free (last_filename);
2516 if (filename == NULL)
2517 last_filename = NULL;
2518 else
2519 last_filename = xstrdup (filename);
2520 }
2521 }
2522
2523 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
2524 {
2525 sym_name = (*(q->sym_ptr_ptr))->name;
2526 section_name = (*(q->sym_ptr_ptr))->section->name;
2527 }
2528 else
2529 {
2530 sym_name = NULL;
2531 section_name = NULL;
2532 }
98a91d6a 2533
252b5132
RH
2534 if (sym_name)
2535 {
d8180c76 2536 bfd_printf_vma (abfd, q->address);
09cda596
DD
2537 if (q->howto->name)
2538 printf (" %-16s ", q->howto->name);
2539 else
2540 printf (" %-16d ", q->howto->type);
252b5132
RH
2541 objdump_print_symname (abfd, (struct disassemble_info *) NULL,
2542 *q->sym_ptr_ptr);
2543 }
2544 else
2545 {
b1f88ebe 2546 if (section_name == (const char *) NULL)
252b5132 2547 section_name = "*unknown*";
d8180c76 2548 bfd_printf_vma (abfd, q->address);
252b5132
RH
2549 printf (" %-16s [%s]",
2550 q->howto->name,
2551 section_name);
2552 }
98a91d6a 2553
252b5132
RH
2554 if (q->addend)
2555 {
2556 printf ("+0x");
d8180c76 2557 bfd_printf_vma (abfd, q->addend);
252b5132 2558 }
98a91d6a 2559
252b5132
RH
2560 printf ("\n");
2561 }
2562}
2563\f
65de42c0
TS
2564int main PARAMS ((int, char **));
2565
252b5132
RH
2566int
2567main (argc, argv)
2568 int argc;
2569 char **argv;
2570{
2571 int c;
2572 char *target = default_target;
b34976b6 2573 bfd_boolean seenflag = FALSE;
252b5132
RH
2574
2575#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
2576 setlocale (LC_MESSAGES, "");
3882b010
L
2577#endif
2578#if defined (HAVE_SETLOCALE)
2579 setlocale (LC_CTYPE, "");
252b5132
RH
2580#endif
2581 bindtextdomain (PACKAGE, LOCALEDIR);
2582 textdomain (PACKAGE);
2583
2584 program_name = *argv;
2585 xmalloc_set_program_name (program_name);
2586
2587 START_PROGRESS (program_name, 0);
2588
2589 bfd_init ();
2590 set_default_bfd_target ();
2591
8b53311e 2592 while ((c = getopt_long (argc, argv, "pib:m:M:VvCdDlfaHhrRtTxsSj:wE:zgG",
252b5132
RH
2593 long_options, (int *) 0))
2594 != EOF)
2595 {
252b5132
RH
2596 switch (c)
2597 {
2598 case 0:
8b53311e 2599 break; /* We've been given a long option. */
252b5132
RH
2600 case 'm':
2601 machine = optarg;
2602 break;
dd92f639
NC
2603 case 'M':
2604 disassembler_options = optarg;
2605 break;
252b5132
RH
2606 case 'j':
2607 only = optarg;
2608 break;
2609 case 'l':
b34976b6 2610 with_line_numbers = TRUE;
252b5132
RH
2611 break;
2612 case 'b':
2613 target = optarg;
2614 break;
1dada9c5 2615 case 'C':
b34976b6 2616 do_demangle = TRUE;
28c309a2
NC
2617 if (optarg != NULL)
2618 {
2619 enum demangling_styles style;
8b53311e 2620
28c309a2 2621 style = cplus_demangle_name_to_style (optarg);
0af11b59 2622 if (style == unknown_demangling)
28c309a2
NC
2623 fatal (_("unknown demangling style `%s'"),
2624 optarg);
8b53311e 2625
28c309a2 2626 cplus_demangle_set_style (style);
0af11b59 2627 }
1dada9c5
NC
2628 break;
2629 case 'w':
b34976b6 2630 wide_output = TRUE;
1dada9c5
NC
2631 break;
2632 case OPTION_ADJUST_VMA:
2633 adjust_section_vma = parse_vma (optarg, "--adjust-vma");
2634 break;
2635 case OPTION_START_ADDRESS:
2636 start_address = parse_vma (optarg, "--start-address");
2637 break;
2638 case OPTION_STOP_ADDRESS:
2639 stop_address = parse_vma (optarg, "--stop-address");
2640 break;
2641 case 'E':
2642 if (strcmp (optarg, "B") == 0)
2643 endian = BFD_ENDIAN_BIG;
2644 else if (strcmp (optarg, "L") == 0)
2645 endian = BFD_ENDIAN_LITTLE;
2646 else
2647 {
37cc8ec1 2648 non_fatal (_("unrecognized -E option"));
1dada9c5
NC
2649 usage (stderr, 1);
2650 }
2651 break;
2652 case OPTION_ENDIAN:
2653 if (strncmp (optarg, "big", strlen (optarg)) == 0)
2654 endian = BFD_ENDIAN_BIG;
2655 else if (strncmp (optarg, "little", strlen (optarg)) == 0)
2656 endian = BFD_ENDIAN_LITTLE;
2657 else
2658 {
37cc8ec1 2659 non_fatal (_("unrecognized --endian type `%s'"), optarg);
1dada9c5
NC
2660 usage (stderr, 1);
2661 }
2662 break;
8b53311e 2663
252b5132 2664 case 'f':
b34976b6
AM
2665 dump_file_header = TRUE;
2666 seenflag = TRUE;
252b5132
RH
2667 break;
2668 case 'i':
b34976b6
AM
2669 formats_info = TRUE;
2670 seenflag = TRUE;
252b5132
RH
2671 break;
2672 case 'p':
b34976b6
AM
2673 dump_private_headers = TRUE;
2674 seenflag = TRUE;
252b5132
RH
2675 break;
2676 case 'x':
b34976b6
AM
2677 dump_private_headers = TRUE;
2678 dump_symtab = TRUE;
2679 dump_reloc_info = TRUE;
2680 dump_file_header = TRUE;
2681 dump_ar_hdrs = TRUE;
2682 dump_section_headers = TRUE;
2683 seenflag = TRUE;
252b5132
RH
2684 break;
2685 case 't':
b34976b6
AM
2686 dump_symtab = TRUE;
2687 seenflag = TRUE;
252b5132
RH
2688 break;
2689 case 'T':
b34976b6
AM
2690 dump_dynamic_symtab = TRUE;
2691 seenflag = TRUE;
252b5132
RH
2692 break;
2693 case 'd':
b34976b6
AM
2694 disassemble = TRUE;
2695 seenflag = TRUE;
1dada9c5
NC
2696 break;
2697 case 'z':
b34976b6 2698 disassemble_zeroes = TRUE;
252b5132
RH
2699 break;
2700 case 'D':
b34976b6
AM
2701 disassemble = TRUE;
2702 disassemble_all = TRUE;
2703 seenflag = TRUE;
252b5132
RH
2704 break;
2705 case 'S':
b34976b6
AM
2706 disassemble = TRUE;
2707 with_source_code = TRUE;
2708 seenflag = TRUE;
1dada9c5
NC
2709 break;
2710 case 'g':
2711 dump_debugging = 1;
b34976b6 2712 seenflag = TRUE;
1dada9c5
NC
2713 break;
2714 case 'G':
b34976b6
AM
2715 dump_stab_section_info = TRUE;
2716 seenflag = TRUE;
252b5132
RH
2717 break;
2718 case 's':
b34976b6
AM
2719 dump_section_contents = TRUE;
2720 seenflag = TRUE;
252b5132
RH
2721 break;
2722 case 'r':
b34976b6
AM
2723 dump_reloc_info = TRUE;
2724 seenflag = TRUE;
252b5132
RH
2725 break;
2726 case 'R':
b34976b6
AM
2727 dump_dynamic_reloc_info = TRUE;
2728 seenflag = TRUE;
252b5132
RH
2729 break;
2730 case 'a':
b34976b6
AM
2731 dump_ar_hdrs = TRUE;
2732 seenflag = TRUE;
252b5132
RH
2733 break;
2734 case 'h':
b34976b6
AM
2735 dump_section_headers = TRUE;
2736 seenflag = TRUE;
252b5132
RH
2737 break;
2738 case 'H':
2739 usage (stdout, 0);
b34976b6 2740 seenflag = TRUE;
8b53311e 2741 case 'v':
252b5132 2742 case 'V':
b34976b6
AM
2743 show_version = TRUE;
2744 seenflag = TRUE;
252b5132 2745 break;
0af11b59 2746
252b5132
RH
2747 default:
2748 usage (stderr, 1);
2749 }
2750 }
2751
2752 if (show_version)
2753 print_version ("objdump");
2754
b34976b6 2755 if (!seenflag)
1dada9c5 2756 usage (stderr, 2);
252b5132
RH
2757
2758 if (formats_info)
06d86cf7 2759 exit_status = display_info ();
252b5132
RH
2760 else
2761 {
2762 if (optind == argc)
2763 display_file ("a.out", target);
2764 else
2765 for (; optind < argc;)
2766 display_file (argv[optind++], target);
2767 }
2768
2769 END_PROGRESS (program_name);
2770
75cd796a 2771 return exit_status;
252b5132 2772}
This page took 0.282 seconds and 4 git commands to generate.