* objdump.c (disassemble_data): Handle unknown endianness.
[deliverable/binutils-gdb.git] / binutils / objdump.c
CommitLineData
d20f480f 1/* objdump.c -- dump information about an object file.
71897943 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
2fa0b342 3
b3a2b497 4This file is part of GNU Binutils.
2fa0b342 5
b3a2b497 6This program is free software; you can redistribute it and/or modify
2fa0b342 7it under the terms of the GNU General Public License as published by
d20f480f 8the Free Software Foundation; either version 2, or (at your option)
2fa0b342
DHW
9any later version.
10
b3a2b497 11This program is distributed in the hope that it will be useful,
2fa0b342
DHW
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
b3a2b497 17along with this program; if not, write to the Free Software
a65619c8 18Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2fa0b342 19
2fa0b342
DHW
20#include "bfd.h"
21#include "getopt.h"
be1d162b 22#include "progress.h"
e1ec9f07 23#include "bucomm.h"
2fa0b342 24#include <ctype.h>
2e8adbd7 25#include "dis-asm.h"
105da05c 26#include "libiberty.h"
e1c14599
ILT
27#include "debug.h"
28#include "budbg.h"
2fa0b342 29
73b8f102
JG
30/* Internal headers for the ELF .stab-dump code - sorry. */
31#define BYTES_IN_WORD 32
32#include "aout/aout64.h"
bf661056 33
746cffcf
ILT
34#ifdef NEED_DECLARATION_FPRINTF
35/* This is needed by INIT_DISASSEMBLE_INFO. */
36extern int fprintf ();
80d19ec1 37#endif
2fa0b342
DHW
38
39char *default_target = NULL; /* default at runtime */
40
e1ec9f07 41extern char *program_version;
2fa0b342 42
249c6fc0 43int show_version = 0; /* show the version number */
2fa0b342
DHW
44int dump_section_contents; /* -s */
45int dump_section_headers; /* -h */
46boolean dump_file_header; /* -f */
47int dump_symtab; /* -t */
de3b08ac 48int dump_dynamic_symtab; /* -T */
2fa0b342 49int dump_reloc_info; /* -r */
de3b08ac 50int dump_dynamic_reloc_info; /* -R */
2fa0b342 51int dump_ar_hdrs; /* -a */
a65619c8 52int dump_private_headers; /* -p */
aa0a709a 53int with_line_numbers; /* -l */
be1d162b 54boolean with_source_code; /* -S */
458bbd1f 55int show_raw_insn; /* --show-raw-insn */
9b018ecd 56int dump_stab_section_info; /* --stabs */
aa0a709a 57boolean disassemble; /* -d */
d5464baa 58boolean disassemble_all; /* -D */
e1ec9f07 59boolean formats_info; /* -i */
195d1adf 60char *only; /* -j secname */
13e4db2e 61int wide_output; /* -w */
aa21a2a9
ILT
62bfd_vma start_address = (bfd_vma) -1; /* --start-address */
63bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
e1c14599 64int dump_debugging; /* --debugging */
195d1adf 65
cef35d48 66/* Extra info to pass to the disassembler address printing function. */
195d1adf
KR
67struct objdump_disasm_info {
68 bfd *abfd;
69 asection *sec;
8b129785 70 boolean require_sec;
195d1adf 71};
2fa0b342 72
cef35d48 73/* Architecture to disassemble for, or default if NULL. */
aa0a709a 74char *machine = (char *) NULL;
f7b839f7
DM
75
76/* The symbol table. */
aa0a709a 77asymbol **syms;
2fa0b342 78
f7b839f7 79/* Number of symbols in `syms'. */
ae5d2ff5 80long symcount = 0;
2fa0b342 81
be1d162b
ILT
82/* The sorted symbol table. */
83asymbol **sorted_syms;
84
85/* Number of symbols in `sorted_syms'. */
86long sorted_symcount = 0;
87
de3b08ac
ILT
88/* The dynamic symbol table. */
89asymbol **dynsyms;
90
91/* Number of symbols in `dynsyms'. */
92long dynsymcount = 0;
93
d9971b83
KR
94/* Forward declarations. */
95
96static void
97display_file PARAMS ((char *filename, char *target));
98
99static void
100dump_data PARAMS ((bfd *abfd));
101
102static void
103dump_relocs PARAMS ((bfd *abfd));
104
105static void
de3b08ac
ILT
106dump_dynamic_relocs PARAMS ((bfd * abfd));
107
108static void
109dump_reloc_set PARAMS ((bfd *, arelent **, long));
110
111static void
112dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
02a68547
ILT
113
114static void
115display_bfd PARAMS ((bfd *abfd));
8f197c94 116
c5ba2759
ILT
117static void
118objdump_print_value PARAMS ((bfd_vma, FILE *));
119
8f197c94
ILT
120static void
121objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
be1d162b
ILT
122
123static void
124show_line PARAMS ((bfd *, asection *, bfd_vma));
e1c14599
ILT
125
126static const char *
127endian_string PARAMS ((enum bfd_endian));
d9971b83 128\f
2fa0b342 129void
b3a2b497
ILT
130usage (stream, status)
131 FILE *stream;
132 int status;
2fa0b342 133{
b3a2b497 134 fprintf (stream, "\
a65619c8 135Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
e1c14599 136 [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
d5464baa 137 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
13e4db2e
SC
138 [--info] [--section=section-name] [--line-numbers] [--source]\n",
139 program_name);
140 fprintf (stream, "\
d5464baa
ILT
141 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
142 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
aa21a2a9 143 [--wide] [--version] [--help] [--private-headers]\n\
458bbd1f
DE
144 [--start-address=addr] [--stop-address=addr]\n\
145 [--show-raw-insn] objfile...\n\
13e4db2e 146at least one option besides -l (--line-numbers) must be given\n");
be1d162b 147 list_supported_targets (program_name, stream);
b3a2b497 148 exit (status);
2fa0b342
DHW
149}
150
aa21a2a9
ILT
151/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
152
153#define OPTION_START_ADDRESS (150)
154#define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
155
aa0a709a
SC
156static struct option long_options[]=
157{
02a68547 158 {"all-headers", no_argument, NULL, 'x'},
a65619c8 159 {"private-headers", no_argument, NULL, 'p'},
02a68547
ILT
160 {"architecture", required_argument, NULL, 'm'},
161 {"archive-headers", no_argument, NULL, 'a'},
e1c14599 162 {"debugging", no_argument, &dump_debugging, 1},
02a68547 163 {"disassemble", no_argument, NULL, 'd'},
d5464baa 164 {"disassemble-all", no_argument, NULL, 'D'},
de3b08ac
ILT
165 {"dynamic-reloc", no_argument, NULL, 'R'},
166 {"dynamic-syms", no_argument, NULL, 'T'},
02a68547
ILT
167 {"file-headers", no_argument, NULL, 'f'},
168 {"full-contents", no_argument, NULL, 's'},
169 {"headers", no_argument, NULL, 'h'},
170 {"help", no_argument, NULL, 'H'},
171 {"info", no_argument, NULL, 'i'},
172 {"line-numbers", no_argument, NULL, 'l'},
173 {"reloc", no_argument, NULL, 'r'},
174 {"section", required_argument, NULL, 'j'},
175 {"section-headers", no_argument, NULL, 'h'},
458bbd1f 176 {"show-raw-insn", no_argument, &show_raw_insn, 1},
be1d162b 177 {"source", no_argument, NULL, 'S'},
73b8f102 178 {"stabs", no_argument, &dump_stab_section_info, 1},
aa21a2a9
ILT
179 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
180 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
02a68547
ILT
181 {"syms", no_argument, NULL, 't'},
182 {"target", required_argument, NULL, 'b'},
aa21a2a9 183 {"version", no_argument, &show_version, 1},
13e4db2e 184 {"wide", no_argument, &wide_output, 'w'},
d2442698
DM
185 {0, no_argument, 0, 0}
186};
f7b839f7 187\f
2fa0b342 188static void
f7b839f7 189dump_section_header (abfd, section, ignored)
aa0a709a 190 bfd *abfd;
f7b839f7
DM
191 asection *section;
192 PTR ignored;
2fa0b342 193{
f7b839f7 194 char *comma = "";
aa0a709a 195
2fa0b342 196#define PF(x,y) \
f7b839f7
DM
197 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
198
199
200 printf ("SECTION %d [%s]\t: size %08x",
201 section->index,
202 section->name,
203 (unsigned) bfd_get_section_size_before_reloc (section));
204 printf (" vma ");
205 printf_vma (section->vma);
13e4db2e
SC
206 printf (" lma ");
207 printf_vma (section->lma);
208 printf (" align 2**%u%s ",
209 section->alignment_power, (wide_output) ? "" : "\n");
f7b839f7
DM
210 PF (SEC_ALLOC, "ALLOC");
211 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
212 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
213 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
214 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
215 PF (SEC_LOAD, "LOAD");
216 PF (SEC_RELOC, "RELOC");
195d1adf 217#ifdef SEC_BALIGN
f7b839f7 218 PF (SEC_BALIGN, "BALIGN");
195d1adf 219#endif
f7b839f7
DM
220 PF (SEC_READONLY, "READONLY");
221 PF (SEC_CODE, "CODE");
222 PF (SEC_DATA, "DATA");
223 PF (SEC_ROM, "ROM");
224 PF (SEC_DEBUGGING, "DEBUGGING");
28d1b01e 225 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
83f4323e
MM
226 PF (SEC_EXCLUDE, "EXCLUDE");
227 PF (SEC_SORT_ENTRIES, "SORT ENTRIES");
f7b839f7 228 printf ("\n");
2fa0b342 229#undef PF
2fa0b342
DHW
230}
231
f7b839f7
DM
232static void
233dump_headers (abfd)
234 bfd *abfd;
235{
236 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
237}
238\f
2fa0b342 239static asymbol **
abdcac0f
DM
240slurp_symtab (abfd)
241 bfd *abfd;
2fa0b342 242{
aa0a709a 243 asymbol **sy = (asymbol **) NULL;
ae5d2ff5 244 long storage;
2fa0b342 245
aa0a709a
SC
246 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
247 {
f7b839f7 248 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
c5ba2759 249 symcount = 0;
f7b839f7 250 return NULL;
aa0a709a
SC
251 }
252
ae5d2ff5
ILT
253 storage = bfd_get_symtab_upper_bound (abfd);
254 if (storage < 0)
255 bfd_fatal (bfd_get_filename (abfd));
256
aa0a709a
SC
257 if (storage)
258 {
02a68547 259 sy = (asymbol **) xmalloc (storage);
aa0a709a
SC
260 }
261 symcount = bfd_canonicalize_symtab (abfd, sy);
ae5d2ff5
ILT
262 if (symcount < 0)
263 bfd_fatal (bfd_get_filename (abfd));
264 if (symcount == 0)
de3b08ac
ILT
265 fprintf (stderr, "%s: %s: No symbols\n",
266 program_name, bfd_get_filename (abfd));
267 return sy;
268}
269
270/* Read in the dynamic symbols. */
271
272static asymbol **
273slurp_dynamic_symtab (abfd)
274 bfd *abfd;
275{
276 asymbol **sy = (asymbol **) NULL;
277 long storage;
278
de3b08ac
ILT
279 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
280 if (storage < 0)
28d1b01e
ILT
281 {
282 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
283 {
284 fprintf (stderr, "%s: %s: not a dynamic object\n",
285 program_name, bfd_get_filename (abfd));
c5ba2759 286 dynsymcount = 0;
28d1b01e
ILT
287 return NULL;
288 }
289
290 bfd_fatal (bfd_get_filename (abfd));
291 }
de3b08ac
ILT
292
293 if (storage)
294 {
295 sy = (asymbol **) xmalloc (storage);
296 }
297 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
298 if (dynsymcount < 0)
299 bfd_fatal (bfd_get_filename (abfd));
300 if (dynsymcount == 0)
301 fprintf (stderr, "%s: %s: No dynamic symbols\n",
302 program_name, bfd_get_filename (abfd));
aa0a709a 303 return sy;
2fa0b342 304}
aa0a709a 305
f7b839f7
DM
306/* Filter out (in place) symbols that are useless for disassembly.
307 COUNT is the number of elements in SYMBOLS.
308 Return the number of useful symbols. */
3ae36cb6 309
ae5d2ff5 310long
f7b839f7
DM
311remove_useless_symbols (symbols, count)
312 asymbol **symbols;
ae5d2ff5 313 long count;
3ae36cb6 314{
f7b839f7 315 register asymbol **in_ptr = symbols, **out_ptr = symbols;
3ae36cb6 316
f7b839f7 317 while (--count >= 0)
3ae36cb6
PB
318 {
319 asymbol *sym = *in_ptr++;
320
321 if (sym->name == NULL || sym->name[0] == '\0')
322 continue;
323 if (sym->flags & (BSF_DEBUGGING))
324 continue;
28d1b01e 325 if (bfd_is_und_section (sym->section)
3ae36cb6
PB
326 || bfd_is_com_section (sym->section))
327 continue;
328
329 *out_ptr++ = sym;
330 }
f7b839f7 331 return out_ptr - symbols;
3ae36cb6
PB
332}
333
e1c14599 334/* Sort symbols into value order. */
37853673 335
aa0a709a 336static int
37853673 337compare_symbols (ap, bp)
d5464baa
ILT
338 const PTR ap;
339 const PTR bp;
2fa0b342 340{
d5464baa
ILT
341 const asymbol *a = *(const asymbol **)ap;
342 const asymbol *b = *(const asymbol **)bp;
db552bda
ILT
343 const char *an, *bn;
344 size_t anl, bnl;
345 boolean af, bf;
e1c14599 346 flagword aflags, bflags;
2fa0b342 347
be1d162b 348 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
3ae36cb6 349 return 1;
be1d162b 350 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
3ae36cb6 351 return -1;
2fa0b342 352
3ae36cb6
PB
353 if (a->section > b->section)
354 return 1;
355 else if (a->section < b->section)
356 return -1;
db552bda
ILT
357
358 an = bfd_asymbol_name (a);
359 bn = bfd_asymbol_name (b);
360 anl = strlen (an);
361 bnl = strlen (bn);
362
363 /* The symbols gnu_compiled and gcc2_compiled convey no real
364 information, so put them after other symbols with the same value. */
365
366 af = (strstr (an, "gnu_compiled") != NULL
367 || strstr (an, "gcc2_compiled") != NULL);
368 bf = (strstr (bn, "gnu_compiled") != NULL
369 || strstr (bn, "gcc2_compiled") != NULL);
370
371 if (af && ! bf)
372 return 1;
373 if (! af && bf)
374 return -1;
375
376 /* We use a heuristic for the file name, to try to sort it after
377 more useful symbols. It may not work on non Unix systems, but it
378 doesn't really matter; the only difference is precisely which
379 symbol names get printed. */
380
381#define file_symbol(s, sn, snl) \
382 (((s)->flags & BSF_FILE) != 0 \
383 || ((sn)[(snl) - 2] == '.' \
384 && ((sn)[(snl) - 1] == 'o' \
385 || (sn)[(snl) - 1] == 'a')))
386
387 af = file_symbol (a, an, anl);
388 bf = file_symbol (b, bn, bnl);
389
390 if (af && ! bf)
391 return 1;
392 if (! af && bf)
393 return -1;
394
e1c14599
ILT
395 /* Finally, try to sort global symbols before local symbols before
396 debugging symbols. */
397
398 aflags = a->flags;
399 bflags = b->flags;
400
401 if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
402 {
403 if ((aflags & BSF_DEBUGGING) != 0)
404 return 1;
405 else
406 return -1;
407 }
408 if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
409 {
410 if ((aflags & BSF_LOCAL) != 0)
411 return 1;
412 else
413 return -1;
414 }
415
3ae36cb6 416 return 0;
2fa0b342
DHW
417}
418
d5464baa
ILT
419/* Sort relocs into address order. */
420
421static int
422compare_relocs (ap, bp)
423 const PTR ap;
424 const PTR bp;
425{
426 const arelent *a = *(const arelent **)ap;
427 const arelent *b = *(const arelent **)bp;
428
429 if (a->address > b->address)
430 return 1;
431 else if (a->address < b->address)
432 return -1;
433
a65619c8
SC
434 /* So that associated relocations tied to the same address show up
435 in the correct order, we don't do any further sorting. */
436 if (a > b)
437 return 1;
438 else if (a < b)
439 return -1;
440 else
441 return 0;
d5464baa
ILT
442}
443
c5ba2759
ILT
444/* Print VMA to STREAM with no leading zeroes. */
445
446static void
447objdump_print_value (vma, stream)
448 bfd_vma vma;
449 FILE *stream;
450{
451 char buf[30];
452 char *p;
453
454 sprintf_vma (buf, vma);
455 for (p = buf; *p == '0'; ++p)
456 ;
457 fprintf (stream, "%s", p);
458}
459
f7b839f7
DM
460/* Print VMA symbolically to INFO if possible. */
461
8f197c94 462static void
545a2768 463objdump_print_address (vma, info)
aa0a709a 464 bfd_vma vma;
545a2768 465 struct disassemble_info *info;
2fa0b342 466{
195d1adf
KR
467 /* @@ Would it speed things up to cache the last two symbols returned,
468 and maybe their address ranges? For many processors, only one memory
469 operand can be present at a time, so the 2-entry cache wouldn't be
470 constantly churned by code doing heavy memory accesses. */
2fa0b342 471
be1d162b 472 /* Indices in `sorted_syms'. */
ae5d2ff5 473 long min = 0;
be1d162b 474 long max = sorted_symcount;
ae5d2ff5 475 long thisplace;
2fa0b342 476
3ae36cb6
PB
477 fprintf_vma (info->stream, vma);
478
be1d162b 479 if (sorted_symcount < 1)
f7b839f7
DM
480 return;
481
8f197c94
ILT
482 /* Perform a binary search looking for the closest symbol to the
483 required value. We are searching the range (min, max]. */
484 while (min + 1 < max)
aa0a709a 485 {
f7b839f7 486 asymbol *sym;
8f197c94 487
f7b839f7 488 thisplace = (max + min) / 2;
be1d162b 489 sym = sorted_syms[thisplace];
8f197c94 490
13e4db2e 491 if (bfd_asymbol_value (sym) > vma)
f7b839f7 492 max = thisplace;
13e4db2e 493 else if (bfd_asymbol_value (sym) < vma)
f7b839f7
DM
494 min = thisplace;
495 else
aa0a709a 496 {
8f197c94
ILT
497 min = thisplace;
498 break;
aa0a709a 499 }
f7b839f7 500 }
fc5d6074 501
8f197c94 502 /* The symbol we want is now in min, the low end of the range we
e1c14599
ILT
503 were searching. If there are several symbols with the same
504 value, we want the first one. */
8f197c94 505 thisplace = min;
db552bda
ILT
506 while (thisplace > 0
507 && (bfd_asymbol_value (sorted_syms[thisplace])
508 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
509 --thisplace;
8f197c94 510
f7b839f7
DM
511 {
512 /* If the file is relocateable, and the symbol could be from this
513 section, prefer a symbol from this section over symbols from
514 others, even if the other symbol's value might be closer.
515
516 Note that this may be wrong for some symbol references if the
517 sections have overlapping memory ranges, but in that case there's
518 no way to tell what's desired without looking at the relocation
519 table. */
520 struct objdump_disasm_info *aux;
ae5d2ff5 521 long i;
f7b839f7
DM
522
523 aux = (struct objdump_disasm_info *) info->application_data;
be1d162b 524 if (sorted_syms[thisplace]->section != aux->sec
2d054641
ILT
525 && (aux->require_sec
526 || ((aux->abfd->flags & HAS_RELOC) != 0
527 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
528 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
c5ba2759 529 + bfd_section_size (aux->abfd, aux->sec)))))
f7b839f7 530 {
be1d162b 531 for (i = thisplace + 1; i < sorted_symcount; i++)
8f197c94 532 {
be1d162b
ILT
533 if (bfd_asymbol_value (sorted_syms[i])
534 != bfd_asymbol_value (sorted_syms[thisplace]))
28d1b01e 535 break;
8f197c94 536 }
28d1b01e 537 --i;
8f197c94
ILT
538 for (; i >= 0; i--)
539 {
db552bda
ILT
540 if (sorted_syms[i]->section == aux->sec
541 && (i == 0
542 || sorted_syms[i - 1]->section != aux->sec
543 || (bfd_asymbol_value (sorted_syms[i])
544 != bfd_asymbol_value (sorted_syms[i - 1]))))
8f197c94
ILT
545 {
546 thisplace = i;
547 break;
548 }
549 }
2d054641 550
be1d162b 551 if (sorted_syms[thisplace]->section != aux->sec)
2d054641
ILT
552 {
553 /* We didn't find a good symbol with a smaller value.
554 Look for one with a larger value. */
be1d162b 555 for (i = thisplace + 1; i < sorted_symcount; i++)
2d054641 556 {
be1d162b 557 if (sorted_syms[i]->section == aux->sec)
2d054641
ILT
558 {
559 thisplace = i;
560 break;
561 }
562 }
563 }
c5ba2759
ILT
564
565 if (sorted_syms[thisplace]->section != aux->sec
566 && (aux->require_sec
567 || ((aux->abfd->flags & HAS_RELOC) != 0
568 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
569 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
570 + bfd_section_size (aux->abfd, aux->sec)))))
571 {
572 bfd_vma secaddr;
573
574 fprintf (info->stream, " <%s",
575 bfd_get_section_name (aux->abfd, aux->sec));
576 secaddr = bfd_get_section_vma (aux->abfd, aux->sec);
577 if (vma < secaddr)
578 {
579 fprintf (info->stream, "-");
580 objdump_print_value (secaddr - vma, info->stream);
581 }
582 else if (vma > secaddr)
583 {
584 fprintf (info->stream, "+");
585 objdump_print_value (vma - secaddr, info->stream);
586 }
587 fprintf (info->stream, ">");
588 return;
589 }
195d1adf 590 }
f7b839f7 591 }
2d054641 592
be1d162b
ILT
593 fprintf (info->stream, " <%s", sorted_syms[thisplace]->name);
594 if (bfd_asymbol_value (sorted_syms[thisplace]) > vma)
f7b839f7 595 {
c5ba2759
ILT
596 fprintf (info->stream, "-");
597 objdump_print_value (bfd_asymbol_value (sorted_syms[thisplace]) - vma,
598 info->stream);
f7b839f7 599 }
be1d162b 600 else if (vma > bfd_asymbol_value (sorted_syms[thisplace]))
f7b839f7 601 {
c5ba2759
ILT
602 fprintf (info->stream, "+");
603 objdump_print_value (vma - bfd_asymbol_value (sorted_syms[thisplace]),
604 info->stream);
2fa0b342 605 }
f7b839f7 606 fprintf (info->stream, ">");
2fa0b342
DHW
607}
608
be1d162b
ILT
609/* Hold the last function name and the last line number we displayed
610 in a disassembly. */
611
612static char *prev_functionname;
613static unsigned int prev_line;
614
615/* We keep a list of all files that we have seen when doing a
616 dissassembly with source, so that we know how much of the file to
617 display. This can be important for inlined functions. */
618
619struct print_file_list
620{
621 struct print_file_list *next;
622 char *filename;
623 unsigned int line;
624 FILE *f;
625};
626
627static struct print_file_list *print_files;
628
629/* The number of preceding context lines to show when we start
630 displaying a file for the first time. */
631
632#define SHOW_PRECEDING_CONTEXT_LINES (5)
633
634/* Skip ahead to a given line in a file, optionally printing each
635 line. */
636
637static void
638skip_to_line PARAMS ((struct print_file_list *, unsigned int, boolean));
639
640static void
641skip_to_line (p, line, show)
642 struct print_file_list *p;
643 unsigned int line;
644 boolean show;
645{
646 while (p->line < line)
647 {
648 char buf[100];
649
650 if (fgets (buf, sizeof buf, p->f) == NULL)
651 {
652 fclose (p->f);
653 p->f = NULL;
654 break;
655 }
656
657 if (show)
658 printf ("%s", buf);
659
660 if (strchr (buf, '\n') != NULL)
661 ++p->line;
662 }
663}
664
665/* Show the line number, or the source line, in a dissassembly
666 listing. */
667
668static void
669show_line (abfd, section, off)
aa0a709a 670 bfd *abfd;
be1d162b
ILT
671 asection *section;
672 bfd_vma off;
2fa0b342 673{
be1d162b
ILT
674 CONST char *filename;
675 CONST char *functionname;
676 unsigned int line;
2e8adbd7 677
be1d162b
ILT
678 if (! with_line_numbers && ! with_source_code)
679 return;
d20f480f 680
be1d162b
ILT
681 if (! bfd_find_nearest_line (abfd, section, syms, off, &filename,
682 &functionname, &line))
683 return;
aa0a709a 684
be1d162b
ILT
685 if (filename != NULL && *filename == '\0')
686 filename = NULL;
687 if (functionname != NULL && *functionname == '\0')
688 functionname = NULL;
aa0a709a 689
be1d162b 690 if (with_line_numbers)
d5464baa 691 {
be1d162b
ILT
692 if (functionname != NULL
693 && (prev_functionname == NULL
694 || strcmp (functionname, prev_functionname) != 0))
695 printf ("%s():\n", functionname);
696 if (line > 0 && line != prev_line)
697 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
698 }
699
700 if (with_source_code
701 && filename != NULL
702 && line > 0)
703 {
704 struct print_file_list **pp, *p;
705
706 for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
707 if (strcmp ((*pp)->filename, filename) == 0)
708 break;
709 p = *pp;
710
711 if (p != NULL)
d5464baa 712 {
be1d162b
ILT
713 if (p != print_files)
714 {
715 int l;
716
717 /* We have reencountered a file name which we saw
718 earlier. This implies that either we are dumping out
719 code from an included file, or the same file was
720 linked in more than once. There are two common cases
721 of an included file: inline functions in a header
722 file, and a bison or flex skeleton file. In the
723 former case we want to just start printing (but we
724 back up a few lines to give context); in the latter
725 case we want to continue from where we left off. I
726 can't think of a good way to distinguish the cases,
727 so I used a heuristic based on the file name. */
728 if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0)
729 l = p->line;
730 else
731 {
732 l = line - SHOW_PRECEDING_CONTEXT_LINES;
733 if (l <= 0)
734 l = 1;
735 }
d5464baa 736
be1d162b
ILT
737 if (p->f == NULL)
738 {
739 p->f = fopen (p->filename, "r");
740 p->line = 0;
741 }
742 if (p->f != NULL)
743 skip_to_line (p, l, false);
d5464baa 744
be1d162b
ILT
745 if (print_files->f != NULL)
746 {
747 fclose (print_files->f);
748 print_files->f = NULL;
749 }
750 }
d5464baa 751
be1d162b
ILT
752 if (p->f != NULL)
753 {
754 skip_to_line (p, line, true);
755 *pp = p->next;
756 p->next = print_files;
757 print_files = p;
758 }
759 }
760 else
761 {
762 FILE *f;
d5464baa 763
be1d162b
ILT
764 f = fopen (filename, "r");
765 if (f != NULL)
d5464baa 766 {
be1d162b 767 int l;
d5464baa 768
be1d162b
ILT
769 p = ((struct print_file_list *)
770 xmalloc (sizeof (struct print_file_list)));
771 p->filename = xmalloc (strlen (filename) + 1);
772 strcpy (p->filename, filename);
773 p->line = 0;
774 p->f = f;
775
776 if (print_files != NULL && print_files->f != NULL)
777 {
778 fclose (print_files->f);
779 print_files->f = NULL;
780 }
781 p->next = print_files;
782 print_files = p;
783
784 l = line - SHOW_PRECEDING_CONTEXT_LINES;
785 if (l <= 0)
786 l = 1;
787 skip_to_line (p, l, false);
788 if (p->f != NULL)
789 skip_to_line (p, line, true);
d5464baa
ILT
790 }
791 }
792 }
793
be1d162b
ILT
794 if (functionname != NULL
795 && (prev_functionname == NULL
796 || strcmp (functionname, prev_functionname) != 0))
aa0a709a 797 {
be1d162b
ILT
798 if (prev_functionname != NULL)
799 free (prev_functionname);
800 prev_functionname = xmalloc (strlen (functionname) + 1);
801 strcpy (prev_functionname, functionname);
aa0a709a 802 }
2fa0b342 803
be1d162b
ILT
804 if (line > 0 && line != prev_line)
805 prev_line = line;
806}
807
808void
809disassemble_data (abfd)
810 bfd *abfd;
811{
812 long i;
be1d162b
ILT
813 disassembler_ftype disassemble_fn = 0; /* New style */
814 struct disassemble_info disasm_info;
815 struct objdump_disasm_info aux;
816 asection *section;
817 boolean done_dot = false;
818
819 print_files = NULL;
820 prev_functionname = NULL;
821 prev_line = -1;
822
823 /* We make a copy of syms to sort. We don't want to sort syms
824 because that will screw up the relocs. */
825 sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
826 memcpy (sorted_syms, syms, symcount * sizeof (asymbol *));
827
828 sorted_symcount = remove_useless_symbols (sorted_syms, symcount);
2fa0b342
DHW
829
830 /* Sort the symbols into section and symbol order */
be1d162b 831 qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
2fa0b342 832
cef35d48
DM
833 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
834 disasm_info.application_data = (PTR) &aux;
835 aux.abfd = abfd;
836 disasm_info.print_address_func = objdump_print_address;
458bbd1f
DE
837 if (show_raw_insn)
838 disasm_info.flags |= DISASM_RAW_INSN_FLAG;
cef35d48 839
aa0a709a
SC
840 if (machine != (char *) NULL)
841 {
db552bda 842 const bfd_arch_info_type *info = bfd_scan_arch (machine);
cef35d48 843 if (info == NULL)
aa0a709a
SC
844 {
845 fprintf (stderr, "%s: Can't use supplied machine %s\n",
846 program_name,
847 machine);
848 exit (1);
849 }
850 abfd->arch_info = info;
2fa0b342 851 }
e779a58c 852
db552bda
ILT
853 disassemble_fn = disassembler (abfd);
854 if (!disassemble_fn)
aa0a709a 855 {
db552bda
ILT
856 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
857 program_name,
858 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
859 exit (1);
aa0a709a 860 }
2fa0b342 861
458bbd1f
DE
862 disasm_info.arch = bfd_get_arch (abfd);
863 disasm_info.mach = bfd_get_mach (abfd);
864 if (bfd_big_endian (abfd))
865 disasm_info.endian = BFD_ENDIAN_BIG;
38aa863c 866 else if (bfd_little_endian (abfd))
458bbd1f 867 disasm_info.endian = BFD_ENDIAN_LITTLE;
38aa863c
DE
868 else
869 /* ??? Aborting here seems too drastic. We could default to big or little
870 instead. */
871 disasm_info.endian = BFD_ENDIAN_UNKNOWN;
458bbd1f 872
2fa0b342 873 for (section = abfd->sections;
aa0a709a
SC
874 section != (asection *) NULL;
875 section = section->next)
65cceb78 876 {
cef35d48
DM
877 bfd_byte *data = NULL;
878 bfd_size_type datasize = 0;
be1d162b 879 arelent **relbuf = NULL;
d5464baa
ILT
880 arelent **relpp = NULL;
881 arelent **relppend = NULL;
aa21a2a9 882 long stop;
2fa0b342 883
d5464baa
ILT
884 if ((section->flags & SEC_LOAD) == 0
885 || (! disassemble_all
886 && only == NULL
887 && (section->flags & SEC_CODE) == 0))
cef35d48
DM
888 continue;
889 if (only != (char *) NULL && strcmp (only, section->name) != 0)
890 continue;
2fa0b342 891
d5464baa
ILT
892 if (dump_reloc_info
893 && (section->flags & SEC_RELOC) != 0)
894 {
be1d162b
ILT
895 long relsize;
896
897 relsize = bfd_get_reloc_upper_bound (abfd, section);
898 if (relsize < 0)
899 bfd_fatal (bfd_get_filename (abfd));
900
901 if (relsize > 0)
902 {
903 long relcount;
904
905 relbuf = (arelent **) xmalloc (relsize);
906 relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
907 if (relcount < 0)
908 bfd_fatal (bfd_get_filename (abfd));
909
910 /* Sort the relocs by address. */
911 qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
912
913 relpp = relbuf;
914 relppend = relpp + relcount;
915 }
d5464baa
ILT
916 }
917
cef35d48 918 printf ("Disassembly of section %s:\n", section->name);
2fa0b342 919
cef35d48
DM
920 datasize = bfd_get_section_size_before_reloc (section);
921 if (datasize == 0)
922 continue;
2fa0b342 923
cef35d48 924 data = (bfd_byte *) xmalloc ((size_t) datasize);
2fa0b342 925
cef35d48 926 bfd_get_section_contents (abfd, section, data, 0, datasize);
2fa0b342 927
cef35d48
DM
928 aux.sec = section;
929 disasm_info.buffer = data;
930 disasm_info.buffer_vma = section->vma;
931 disasm_info.buffer_length = datasize;
aa21a2a9
ILT
932 if (start_address == (bfd_vma) -1
933 || start_address < disasm_info.buffer_vma)
934 i = 0;
935 else
936 i = start_address - disasm_info.buffer_vma;
937 if (stop_address == (bfd_vma) -1)
938 stop = datasize;
939 else
940 {
941 if (stop_address < disasm_info.buffer_vma)
942 stop = 0;
943 else
944 stop = stop_address - disasm_info.buffer_vma;
945 if (stop > disasm_info.buffer_length)
946 stop = disasm_info.buffer_length;
947 }
948 while (i < stop)
cef35d48 949 {
d5464baa 950 int bytes;
13e4db2e 951 boolean need_nl = false;
d5464baa 952
cef35d48
DM
953 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
954 data[i + 3] == 0)
aa0a709a 955 {
cef35d48 956 if (done_dot == false)
aa0a709a 957 {
cef35d48
DM
958 printf ("...\n");
959 done_dot = true;
65cceb78 960 }
d5464baa 961 bytes = 4;
cef35d48
DM
962 }
963 else
964 {
965 done_dot = false;
be1d162b
ILT
966 if (with_line_numbers || with_source_code)
967 show_line (abfd, section, i);
8b129785 968 aux.require_sec = true;
cef35d48 969 objdump_print_address (section->vma + i, &disasm_info);
8b129785 970 aux.require_sec = false;
cef35d48 971 putchar (' ');
65cceb78 972
db552bda
ILT
973 bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
974 if (bytes < 0)
975 break;
976
13e4db2e
SC
977 if (!wide_output)
978 putchar ('\n');
979 else
980 need_nl = true;
96d7950b 981 }
d5464baa
ILT
982
983 if (dump_reloc_info
984 && (section->flags & SEC_RELOC) != 0)
985 {
986 while (relpp < relppend
746cffcf
ILT
987 && ((*relpp)->address >= (bfd_vma) i
988 && (*relpp)->address < (bfd_vma) i + bytes))
d5464baa
ILT
989 {
990 arelent *q;
991 const char *sym_name;
992
993 q = *relpp;
994
995 printf ("\t\tRELOC: ");
996
997 printf_vma (section->vma + q->address);
998
999 printf (" %s ", q->howto->name);
1000
1001 if (q->sym_ptr_ptr != NULL
1002 && *q->sym_ptr_ptr != NULL)
1003 {
1004 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
1005 if (sym_name == NULL || *sym_name == '\0')
1006 {
1007 asection *sym_sec;
1008
1009 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
1010 sym_name = bfd_get_section_name (abfd, sym_sec);
1011 if (sym_name == NULL || *sym_name == '\0')
1012 sym_name = "*unknown*";
1013 }
1014 }
1015
1016 printf ("%s", sym_name);
1017
1018 if (q->addend)
1019 {
1020 printf ("+0x");
1021 printf_vma (q->addend);
1022 }
1023
1024 printf ("\n");
13e4db2e 1025 need_nl = false;
d5464baa
ILT
1026 ++relpp;
1027 }
1028 }
1029
13e4db2e
SC
1030 if (need_nl)
1031 printf ("\n");
1032
d5464baa 1033 i += bytes;
96d7950b 1034 }
be1d162b 1035
cef35d48 1036 free (data);
be1d162b
ILT
1037 if (relbuf != NULL)
1038 free (relbuf);
2fa0b342 1039 }
c5ba2759 1040 free (sorted_syms);
2fa0b342 1041}
73b8f102 1042\f
73b8f102
JG
1043
1044/* Define a table of stab values and print-strings. We wish the initializer
1045 could be a direct-mapped table, but instead we build one the first
1046 time we need it. */
1047
fe2750e1 1048char **stab_name;
73b8f102
JG
1049
1050struct stab_print {
1051 int value;
fe2750e1 1052 char *string;
73b8f102
JG
1053};
1054
1055struct stab_print stab_print[] = {
1056#define __define_stab(NAME, CODE, STRING) {CODE, STRING},
1057#include "aout/stab.def"
1058#undef __define_stab
02a68547 1059 {0, ""}
73b8f102
JG
1060};
1061
250e36fe
DM
1062void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
1063 char *strsect_name));
249c6fc0 1064
250e36fe 1065/* Dump the stabs sections from an object file that has a section that
73b8f102
JG
1066 uses Sun stabs encoding. It has to use some hooks into BFD because
1067 string table sections are not normally visible to BFD callers. */
1068
1069void
9b018ecd 1070dump_stabs (abfd)
73b8f102
JG
1071 bfd *abfd;
1072{
fe2750e1
SS
1073 /* Allocate and initialize stab name array if first time. */
1074 if (stab_name == NULL)
73b8f102 1075 {
250e36fe
DM
1076 int i;
1077
fe2750e1
SS
1078 stab_name = (char **) xmalloc (256 * sizeof(char *));
1079 /* Clear the array. */
73b8f102 1080 for (i = 0; i < 256; i++)
fe2750e1
SS
1081 stab_name[i] = NULL;
1082 /* Fill in the defined stabs. */
1083 for (i = 0; *stab_print[i].string; i++)
1084 stab_name[stab_print[i].value] = stab_print[i].string;
73b8f102
JG
1085 }
1086
250e36fe
DM
1087 dump_section_stabs (abfd, ".stab", ".stabstr");
1088 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
1089 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
1090 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
249c6fc0
RS
1091}
1092
250e36fe
DM
1093static struct internal_nlist *stabs;
1094static bfd_size_type stab_size;
1095
1096static char *strtab;
1097static bfd_size_type stabstr_size;
1098
1099/* Read ABFD's stabs section STABSECT_NAME into `stabs'
1100 and string table section STRSECT_NAME into `strtab'.
1101 If the section exists and was read, allocate the space and return true.
1102 Otherwise return false. */
1103
1104boolean
1105read_section_stabs (abfd, stabsect_name, strsect_name)
249c6fc0 1106 bfd *abfd;
250e36fe
DM
1107 char *stabsect_name;
1108 char *strsect_name;
249c6fc0 1109{
9b018ecd 1110 asection *stabsect, *stabstrsect;
9b018ecd 1111
d5671c53
ILT
1112 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
1113 if (0 == stabsect)
73b8f102 1114 {
250e36fe
DM
1115 printf ("No %s section present\n\n", stabsect_name);
1116 return false;
73b8f102
JG
1117 }
1118
d5671c53
ILT
1119 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
1120 if (0 == stabstrsect)
73b8f102 1121 {
eae82145 1122 fprintf (stderr, "%s: %s has no %s section\n", program_name,
250e36fe
DM
1123 bfd_get_filename (abfd), strsect_name);
1124 return false;
73b8f102 1125 }
9b018ecd 1126
d5671c53
ILT
1127 stab_size = bfd_section_size (abfd, stabsect);
1128 stabstr_size = bfd_section_size (abfd, stabstrsect);
73b8f102 1129
9b018ecd
ILT
1130 stabs = (struct internal_nlist *) xmalloc (stab_size);
1131 strtab = (char *) xmalloc (stabstr_size);
73b8f102 1132
d5671c53 1133 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
9b018ecd 1134 {
d5671c53
ILT
1135 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1136 program_name, stabsect_name, bfd_get_filename (abfd),
1137 bfd_errmsg (bfd_get_error ()));
1138 free (stabs);
1139 free (strtab);
1140 return false;
73b8f102 1141 }
2fa0b342 1142
d5671c53
ILT
1143 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
1144 stabstr_size))
9b018ecd 1145 {
d5671c53
ILT
1146 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1147 program_name, strsect_name, bfd_get_filename (abfd),
1148 bfd_errmsg (bfd_get_error ()));
1149 free (stabs);
1150 free (strtab);
1151 return false;
73b8f102 1152 }
d5671c53 1153
250e36fe
DM
1154 return true;
1155}
73b8f102
JG
1156
1157#define SWAP_SYMBOL(symp, abfd) \
250e36fe 1158{ \
73b8f102 1159 (symp)->n_strx = bfd_h_get_32(abfd, \
250e36fe 1160 (unsigned char *)&(symp)->n_strx); \
73b8f102 1161 (symp)->n_desc = bfd_h_get_16 (abfd, \
250e36fe 1162 (unsigned char *)&(symp)->n_desc); \
73b8f102 1163 (symp)->n_value = bfd_h_get_32 (abfd, \
250e36fe
DM
1164 (unsigned char *)&(symp)->n_value); \
1165}
73b8f102 1166
250e36fe
DM
1167/* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1168 using string table section STRSECT_NAME (in `strtab'). */
1169
1170void
1171print_section_stabs (abfd, stabsect_name, strsect_name)
1172 bfd *abfd;
1173 char *stabsect_name;
1174 char *strsect_name;
1175{
1176 int i;
1177 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
1178 struct internal_nlist *stabp = stabs,
1179 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
73b8f102 1180
250e36fe
DM
1181 printf ("Contents of %s section:\n\n", stabsect_name);
1182 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
249c6fc0
RS
1183
1184 /* Loop through all symbols and print them.
1185
1186 We start the index at -1 because there is a dummy symbol on
250e36fe 1187 the front of stabs-in-{coff,elf} sections that supplies sizes. */
249c6fc0 1188
250e36fe 1189 for (i = -1; stabp < stabs_end; stabp++, i++)
73b8f102 1190 {
250e36fe 1191 SWAP_SYMBOL (stabp, abfd);
fe2750e1 1192 printf ("\n%-6d ", i);
250e36fe 1193 /* Either print the stab name, or, if unnamed, print its number
fe2750e1 1194 again (makes consistent formatting for tools like awk). */
250e36fe
DM
1195 if (stab_name[stabp->n_type])
1196 printf ("%-6s", stab_name[stabp->n_type]);
105da05c
ILT
1197 else if (stabp->n_type == N_UNDF)
1198 printf ("HdrSym");
fe2750e1 1199 else
105da05c 1200 printf ("%-6d", stabp->n_type);
250e36fe
DM
1201 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
1202 printf_vma (stabp->n_value);
1203 printf (" %-6lu", stabp->n_strx);
249c6fc0
RS
1204
1205 /* Symbols with type == 0 (N_UNDF) specify the length of the
1206 string table associated with this file. We use that info
1207 to know how to relocate the *next* file's string table indices. */
1208
250e36fe 1209 if (stabp->n_type == N_UNDF)
249c6fc0
RS
1210 {
1211 file_string_table_offset = next_file_string_table_offset;
250e36fe 1212 next_file_string_table_offset += stabp->n_value;
249c6fc0 1213 }
249c6fc0 1214 else
e1ec9f07 1215 {
250e36fe 1216 /* Using the (possibly updated) string table offset, print the
e1ec9f07
SS
1217 string (if any) associated with this symbol. */
1218
250e36fe
DM
1219 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
1220 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
e1ec9f07
SS
1221 else
1222 printf (" *");
1223 }
73b8f102
JG
1224 }
1225 printf ("\n\n");
1226}
249c6fc0 1227
250e36fe
DM
1228void
1229dump_section_stabs (abfd, stabsect_name, strsect_name)
1230 bfd *abfd;
1231 char *stabsect_name;
1232 char *strsect_name;
1233{
13e4db2e 1234 asection *s;
13e4db2e 1235
a65619c8
SC
1236 /* Check for section names for which stabsect_name is a prefix, to
1237 handle .stab0, etc. */
13e4db2e 1238 for (s = abfd->sections;
a65619c8 1239 s != NULL;
13e4db2e
SC
1240 s = s->next)
1241 {
a65619c8
SC
1242 if (strncmp (stabsect_name, s->name, strlen (stabsect_name)) == 0
1243 && strncmp (strsect_name, s->name, strlen (strsect_name)) != 0)
13e4db2e 1244 {
a65619c8
SC
1245 if (read_section_stabs (abfd, s->name, strsect_name))
1246 {
1247 print_section_stabs (abfd, s->name, strsect_name);
1248 free (stabs);
1249 free (strtab);
1250 }
13e4db2e
SC
1251 }
1252 }
250e36fe
DM
1253}
1254\f
eae82145 1255static void
f7b839f7
DM
1256dump_bfd_header (abfd)
1257 bfd *abfd;
1258{
1259 char *comma = "";
1260
1261 printf ("architecture: %s, ",
1262 bfd_printable_arch_mach (bfd_get_arch (abfd),
1263 bfd_get_mach (abfd)));
1264 printf ("flags 0x%08x:\n", abfd->flags);
1265
1266#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
1267 PF (HAS_RELOC, "HAS_RELOC");
1268 PF (EXEC_P, "EXEC_P");
1269 PF (HAS_LINENO, "HAS_LINENO");
1270 PF (HAS_DEBUG, "HAS_DEBUG");
1271 PF (HAS_SYMS, "HAS_SYMS");
1272 PF (HAS_LOCALS, "HAS_LOCALS");
1273 PF (DYNAMIC, "DYNAMIC");
1274 PF (WP_TEXT, "WP_TEXT");
1275 PF (D_PAGED, "D_PAGED");
1276 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
1277 printf ("\nstart address 0x");
1278 printf_vma (abfd->start_address);
1279}
a65619c8
SC
1280\f
1281static void
1282dump_bfd_private_header (abfd)
1283bfd *abfd;
1284{
1285 bfd_print_private_bfd_data (abfd, stdout);
1286}
02a68547 1287static void
2fa0b342
DHW
1288display_bfd (abfd)
1289 bfd *abfd;
1290{
209e5610
DM
1291 char **matching;
1292
1293 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
aa0a709a 1294 {
cef35d48 1295 bfd_nonfatal (bfd_get_filename (abfd));
8f197c94 1296 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
209e5610
DM
1297 {
1298 list_matching_formats (matching);
1299 free (matching);
1300 }
aa0a709a
SC
1301 return;
1302 }
f7b839f7 1303
cef35d48
DM
1304 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
1305 abfd->xvec->name);
aa0a709a
SC
1306 if (dump_ar_hdrs)
1307 print_arelt_descr (stdout, abfd, true);
aa0a709a 1308 if (dump_file_header)
f7b839f7 1309 dump_bfd_header (abfd);
a65619c8
SC
1310 if (dump_private_headers)
1311 dump_bfd_private_header (abfd);
f7b839f7 1312 putchar ('\n');
2fa0b342 1313 if (dump_section_headers)
aa0a709a 1314 dump_headers (abfd);
83f4323e 1315 if (dump_symtab || dump_reloc_info || disassemble || dump_debugging)
aa0a709a
SC
1316 {
1317 syms = slurp_symtab (abfd);
1318 }
de3b08ac
ILT
1319 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
1320 {
1321 dynsyms = slurp_dynamic_symtab (abfd);
1322 }
aa0a709a 1323 if (dump_symtab)
de3b08ac
ILT
1324 dump_symbols (abfd, false);
1325 if (dump_dynamic_symtab)
1326 dump_symbols (abfd, true);
73b8f102 1327 if (dump_stab_section_info)
9b018ecd 1328 dump_stabs (abfd);
d5464baa 1329 if (dump_reloc_info && ! disassemble)
aa0a709a 1330 dump_relocs (abfd);
de3b08ac
ILT
1331 if (dump_dynamic_reloc_info)
1332 dump_dynamic_relocs (abfd);
aa0a709a
SC
1333 if (dump_section_contents)
1334 dump_data (abfd);
1335 if (disassemble)
1336 disassemble_data (abfd);
e1c14599
ILT
1337 if (dump_debugging)
1338 {
1339 PTR dhandle;
1340
83f4323e 1341 dhandle = read_debugging_info (abfd, syms, symcount);
e1c14599
ILT
1342 if (dhandle != NULL)
1343 {
1344 if (! print_debugging_info (stdout, dhandle))
1345 fprintf (stderr, "%s: printing debugging information failed\n",
1346 bfd_get_filename (abfd));
1347 }
1348 }
c5ba2759
ILT
1349 if (syms)
1350 {
1351 free (syms);
1352 syms = NULL;
1353 }
1354 if (dynsyms)
1355 {
1356 free (dynsyms);
1357 dynsyms = NULL;
1358 }
2fa0b342
DHW
1359}
1360
d9971b83 1361static void
2fa0b342
DHW
1362display_file (filename, target)
1363 char *filename;
1364 char *target;
1365{
1366 bfd *file, *arfile = (bfd *) NULL;
1367
1368 file = bfd_openr (filename, target);
aa0a709a
SC
1369 if (file == NULL)
1370 {
cef35d48 1371 bfd_nonfatal (filename);
aa0a709a
SC
1372 return;
1373 }
2fa0b342 1374
aa0a709a
SC
1375 if (bfd_check_format (file, bfd_archive) == true)
1376 {
8f197c94
ILT
1377 bfd *last_arfile = NULL;
1378
aa0a709a
SC
1379 printf ("In archive %s:\n", bfd_get_filename (file));
1380 for (;;)
1381 {
8f197c94 1382 bfd_set_error (bfd_error_no_error);
aa0a709a
SC
1383
1384 arfile = bfd_openr_next_archived_file (file, arfile);
1385 if (arfile == NULL)
1386 {
8f197c94 1387 if (bfd_get_error () != bfd_error_no_more_archived_files)
d2442698 1388 {
cef35d48 1389 bfd_nonfatal (bfd_get_filename (file));
d2442698 1390 }
8f197c94 1391 break;
aa0a709a 1392 }
2fa0b342 1393
aa0a709a 1394 display_bfd (arfile);
8f197c94
ILT
1395
1396 if (last_arfile != NULL)
1397 bfd_close (last_arfile);
1398 last_arfile = arfile;
aa0a709a 1399 }
8f197c94
ILT
1400
1401 if (last_arfile != NULL)
1402 bfd_close (last_arfile);
2fa0b342 1403 }
2fa0b342 1404 else
aa0a709a 1405 display_bfd (file);
2fa0b342 1406
aa0a709a 1407 bfd_close (file);
2fa0b342
DHW
1408}
1409\f
1410/* Actually display the various requested regions */
1411
d9971b83 1412static void
2fa0b342
DHW
1413dump_data (abfd)
1414 bfd *abfd;
1415{
1416 asection *section;
aa0a709a 1417 bfd_byte *data = 0;
fc5d6074
SC
1418 bfd_size_type datasize = 0;
1419 bfd_size_type i;
aa21a2a9 1420 bfd_size_type start, stop;
2fa0b342
DHW
1421
1422 for (section = abfd->sections; section != NULL; section =
aa0a709a
SC
1423 section->next)
1424 {
1425 int onaline = 16;
2fa0b342 1426
aa0a709a
SC
1427 if (only == (char *) NULL ||
1428 strcmp (only, section->name) == 0)
60c80016 1429 {
aa0a709a
SC
1430 if (section->flags & SEC_HAS_CONTENTS)
1431 {
1432 printf ("Contents of section %s:\n", section->name);
1433
9b018ecd 1434 if (bfd_section_size (abfd, section) == 0)
aa0a709a 1435 continue;
02a68547 1436 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
9b018ecd 1437 datasize = bfd_section_size (abfd, section);
2fa0b342 1438
2fa0b342 1439
9b018ecd 1440 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
2fa0b342 1441
aa21a2a9
ILT
1442 if (start_address == (bfd_vma) -1
1443 || start_address < section->vma)
1444 start = 0;
1445 else
1446 start = start_address - section->vma;
1447 if (stop_address == (bfd_vma) -1)
1448 stop = bfd_section_size (abfd, section);
1449 else
1450 {
1451 if (stop_address < section->vma)
1452 stop = 0;
1453 else
1454 stop = stop_address - section->vma;
1455 if (stop > bfd_section_size (abfd, section))
1456 stop = bfd_section_size (abfd, section);
1457 }
1458 for (i = start; i < stop; i += onaline)
aa0a709a
SC
1459 {
1460 bfd_size_type j;
1461
1462 printf (" %04lx ", (unsigned long int) (i + section->vma));
1463 for (j = i; j < i + onaline; j++)
1464 {
aa21a2a9 1465 if (j < stop)
aa0a709a
SC
1466 printf ("%02x", (unsigned) (data[j]));
1467 else
1468 printf (" ");
1469 if ((j & 3) == 3)
1470 printf (" ");
1471 }
2fa0b342 1472
aa0a709a
SC
1473 printf (" ");
1474 for (j = i; j < i + onaline; j++)
1475 {
aa21a2a9 1476 if (j >= stop)
aa0a709a
SC
1477 printf (" ");
1478 else
1479 printf ("%c", isprint (data[j]) ? data[j] : '.');
1480 }
1481 putchar ('\n');
1482 }
d9971b83 1483 free (data);
60c80016 1484 }
2fa0b342 1485 }
2fa0b342 1486 }
2fa0b342
DHW
1487}
1488
2fa0b342 1489/* Should perhaps share code and display with nm? */
d9971b83 1490static void
de3b08ac 1491dump_symbols (abfd, dynamic)
2fa0b342 1492 bfd *abfd;
de3b08ac 1493 boolean dynamic;
2fa0b342 1494{
de3b08ac
ILT
1495 asymbol **current;
1496 long max;
ae5d2ff5 1497 long count;
2fa0b342 1498
de3b08ac 1499 if (dynamic)
aa0a709a 1500 {
de3b08ac
ILT
1501 current = dynsyms;
1502 max = dynsymcount;
1503 if (max == 0)
1504 return;
1505 printf ("DYNAMIC SYMBOL TABLE:\n");
1506 }
1507 else
1508 {
1509 current = syms;
1510 max = symcount;
1511 if (max == 0)
1512 return;
1513 printf ("SYMBOL TABLE:\n");
1514 }
2fa0b342 1515
de3b08ac
ILT
1516 for (count = 0; count < max; count++)
1517 {
d9971b83 1518 if (*current)
aa0a709a 1519 {
d9971b83
KR
1520 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1521 if (cur_bfd)
1522 {
1523 bfd_print_symbol (cur_bfd,
1524 stdout,
1525 *current, bfd_print_symbol_all);
1526 printf ("\n");
1527 }
aa0a709a
SC
1528 }
1529 current++;
2fa0b342 1530 }
aa0a709a
SC
1531 printf ("\n");
1532 printf ("\n");
2fa0b342
DHW
1533}
1534
d9971b83 1535static void
aa0a709a
SC
1536dump_relocs (abfd)
1537 bfd *abfd;
2fa0b342
DHW
1538{
1539 arelent **relpp;
ae5d2ff5 1540 long relcount;
2fa0b342 1541 asection *a;
aa0a709a
SC
1542
1543 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1544 {
ae5d2ff5
ILT
1545 long relsize;
1546
28d1b01e 1547 if (bfd_is_abs_section (a))
aa0a709a 1548 continue;
28d1b01e 1549 if (bfd_is_und_section (a))
aa0a709a 1550 continue;
d9971b83 1551 if (bfd_is_com_section (a))
aa0a709a
SC
1552 continue;
1553
195d1adf
KR
1554 if (only)
1555 {
1556 if (strcmp (only, a->name))
1557 continue;
1558 }
1559 else if ((a->flags & SEC_RELOC) == 0)
1560 continue;
1561
ae5d2ff5
ILT
1562 relsize = bfd_get_reloc_upper_bound (abfd, a);
1563 if (relsize < 0)
1564 bfd_fatal (bfd_get_filename (abfd));
1565
c5ba2759
ILT
1566 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1567
ae5d2ff5 1568 if (relsize == 0)
aa0a709a
SC
1569 {
1570 printf (" (none)\n\n");
d20f480f 1571 }
aa0a709a
SC
1572 else
1573 {
ae5d2ff5 1574 relpp = (arelent **) xmalloc (relsize);
aa0a709a 1575 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
ae5d2ff5
ILT
1576 if (relcount < 0)
1577 bfd_fatal (bfd_get_filename (abfd));
1578 else if (relcount == 0)
aa0a709a
SC
1579 {
1580 printf (" (none)\n\n");
d20f480f 1581 }
aa0a709a
SC
1582 else
1583 {
1584 printf ("\n");
de3b08ac 1585 dump_reloc_set (abfd, relpp, relcount);
aa0a709a 1586 printf ("\n\n");
d20f480f 1587 }
de3b08ac 1588 free (relpp);
2fa0b342 1589 }
de3b08ac
ILT
1590 }
1591}
2fa0b342 1592
de3b08ac
ILT
1593static void
1594dump_dynamic_relocs (abfd)
1595 bfd *abfd;
1596{
1597 long relsize;
1598 arelent **relpp;
1599 long relcount;
1600
de3b08ac
ILT
1601 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1602 if (relsize < 0)
1603 bfd_fatal (bfd_get_filename (abfd));
1604
c5ba2759
ILT
1605 printf ("DYNAMIC RELOCATION RECORDS");
1606
de3b08ac
ILT
1607 if (relsize == 0)
1608 {
1609 printf (" (none)\n\n");
1610 }
1611 else
1612 {
1613 relpp = (arelent **) xmalloc (relsize);
1614 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1615 if (relcount < 0)
1616 bfd_fatal (bfd_get_filename (abfd));
1617 else if (relcount == 0)
1618 {
1619 printf (" (none)\n\n");
1620 }
1621 else
1622 {
1623 printf ("\n");
1624 dump_reloc_set (abfd, relpp, relcount);
1625 printf ("\n\n");
1626 }
1627 free (relpp);
1628 }
1629}
1630
1631static void
1632dump_reloc_set (abfd, relpp, relcount)
1633 bfd *abfd;
1634 arelent **relpp;
1635 long relcount;
1636{
1637 arelent **p;
1638
1639 /* Get column headers lined up reasonably. */
1640 {
1641 static int width;
1642 if (width == 0)
1643 {
1644 char buf[30];
1645 sprintf_vma (buf, (bfd_vma) -1);
1646 width = strlen (buf) - 7;
1647 }
1648 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1649 }
1650
1651 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1652 {
1653 arelent *q = *p;
1654 CONST char *sym_name;
1655 CONST char *section_name;
1656
aa21a2a9
ILT
1657 if (start_address != (bfd_vma) -1
1658 && q->address < start_address)
1659 continue;
1660 if (stop_address != (bfd_vma) -1
1661 && q->address > stop_address)
1662 continue;
1663
de3b08ac
ILT
1664 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1665 {
1666 sym_name = (*(q->sym_ptr_ptr))->name;
1667 section_name = (*(q->sym_ptr_ptr))->section->name;
1668 }
1669 else
1670 {
1671 sym_name = NULL;
1672 section_name = NULL;
1673 }
1674 if (sym_name)
1675 {
1676 printf_vma (q->address);
1677 printf (" %-16s %s",
1678 q->howto->name,
1679 sym_name);
1680 }
1681 else
1682 {
1683 if (section_name == (CONST char *) NULL)
1684 section_name = "*unknown*";
1685 printf_vma (q->address);
1686 printf (" %-16s [%s]",
1687 q->howto->name,
1688 section_name);
1689 }
1690 if (q->addend)
1691 {
1692 printf ("+0x");
1693 printf_vma (q->addend);
1694 }
1695 printf ("\n");
d20f480f 1696 }
2fa0b342 1697}
f7b839f7 1698\f
f7b839f7
DM
1699/* The length of the longest architecture name + 1. */
1700#define LONGEST_ARCH sizeof("rs6000:6000")
1701
be1d162b
ILT
1702#ifndef L_tmpnam
1703#define L_tmpnam 25
1704#endif
1705
e1c14599
ILT
1706static const char *
1707endian_string (endian)
1708 enum bfd_endian endian;
1709{
1710 if (endian == BFD_ENDIAN_BIG)
1711 return "big endian";
1712 else if (endian == BFD_ENDIAN_LITTLE)
1713 return "little endian";
1714 else
1715 return "endianness unknown";
1716}
1717
f7b839f7
DM
1718/* List the targets that BFD is configured to support, each followed
1719 by its endianness and the architectures it supports. */
1720
1721static void
1722display_target_list ()
1723{
de04bceb 1724 extern char *tmpnam ();
f7b839f7 1725 extern bfd_target *bfd_target_vector[];
be1d162b 1726 char tmparg[L_tmpnam];
de04bceb 1727 char *dummy_name;
f7b839f7
DM
1728 int t;
1729
be1d162b 1730 dummy_name = tmpnam (tmparg);
f7b839f7
DM
1731 for (t = 0; bfd_target_vector[t]; t++)
1732 {
f7b839f7 1733 bfd_target *p = bfd_target_vector[t];
de04bceb 1734 bfd *abfd = bfd_openw (dummy_name, p->name);
105da05c
ILT
1735 int a;
1736
1737 printf ("%s\n (header %s, data %s)\n", p->name,
e1c14599
ILT
1738 endian_string (p->header_byteorder),
1739 endian_string (p->byteorder));
f7b839f7 1740
334d6e76
SS
1741 if (abfd == NULL)
1742 {
de04bceb 1743 bfd_nonfatal (dummy_name);
105da05c 1744 continue;
334d6e76 1745 }
105da05c
ILT
1746
1747 if (! bfd_set_format (abfd, bfd_object))
1748 {
1749 if (bfd_get_error () != bfd_error_invalid_operation)
1750 bfd_nonfatal (p->name);
1751 continue;
1752 }
1753
f7b839f7
DM
1754 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1755 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1756 printf (" %s\n",
1757 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1758 }
de04bceb 1759 unlink (dummy_name);
f7b839f7
DM
1760}
1761
1762/* Print a table showing which architectures are supported for entries
1763 FIRST through LAST-1 of bfd_target_vector (targets across,
1764 architectures down). */
1765
9872a49c 1766static void
abdcac0f
DM
1767display_info_table (first, last)
1768 int first;
1769 int last;
9872a49c 1770{
abdcac0f 1771 extern bfd_target *bfd_target_vector[];
de04bceb 1772 extern char *tmpnam ();
be1d162b 1773 char tmparg[L_tmpnam];
de04bceb
ILT
1774 int t, a;
1775 char *dummy_name;
9872a49c 1776
f7b839f7 1777 /* Print heading of target names. */
ae5d2ff5 1778 printf ("\n%*s", (int) LONGEST_ARCH, " ");
105da05c 1779 for (t = first; t < last && bfd_target_vector[t]; t++)
f7b839f7
DM
1780 printf ("%s ", bfd_target_vector[t]->name);
1781 putchar ('\n');
9872a49c 1782
be1d162b 1783 dummy_name = tmpnam (tmparg);
f7b839f7
DM
1784 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1785 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
e779a58c 1786 {
ae5d2ff5
ILT
1787 printf ("%*s ", (int) LONGEST_ARCH - 1,
1788 bfd_printable_arch_mach (a, 0));
105da05c 1789 for (t = first; t < last && bfd_target_vector[t]; t++)
aa0a709a 1790 {
f7b839f7 1791 bfd_target *p = bfd_target_vector[t];
105da05c 1792 boolean ok = true;
de04bceb 1793 bfd *abfd = bfd_openw (dummy_name, p->name);
aa0a709a 1794
334d6e76
SS
1795 if (abfd == NULL)
1796 {
105da05c
ILT
1797 bfd_nonfatal (p->name);
1798 ok = false;
1799 }
1800
1801 if (ok)
1802 {
1803 if (! bfd_set_format (abfd, bfd_object))
1804 {
1805 if (bfd_get_error () != bfd_error_invalid_operation)
1806 bfd_nonfatal (p->name);
1807 ok = false;
1808 }
334d6e76 1809 }
105da05c
ILT
1810
1811 if (ok)
1812 {
1813 if (! bfd_set_arch_mach (abfd, a, 0))
1814 ok = false;
1815 }
1816
1817 if (ok)
aa0a709a
SC
1818 printf ("%s ", p->name);
1819 else
e779a58c 1820 {
f7b839f7 1821 int l = strlen (p->name);
aa0a709a 1822 while (l--)
f7b839f7
DM
1823 putchar ('-');
1824 putchar (' ');
e779a58c 1825 }
e779a58c 1826 }
f7b839f7 1827 putchar ('\n');
e779a58c 1828 }
de04bceb 1829 unlink (dummy_name);
9872a49c 1830}
aa0a709a 1831
f7b839f7
DM
1832/* Print tables of all the target-architecture combinations that
1833 BFD has been configured to support. */
1834
aa0a709a 1835static void
f7b839f7 1836display_target_tables ()
aa0a709a 1837{
f7b839f7 1838 int t, columns;
abdcac0f 1839 extern bfd_target *bfd_target_vector[];
f7b839f7 1840 char *colum;
aa0a709a
SC
1841 extern char *getenv ();
1842
aa0a709a 1843 columns = 0;
f7b839f7
DM
1844 colum = getenv ("COLUMNS");
1845 if (colum != NULL)
aa0a709a 1846 columns = atoi (colum);
f7b839f7 1847 if (columns == 0)
aa0a709a 1848 columns = 80;
f7b839f7 1849
105da05c
ILT
1850 t = 0;
1851 while (bfd_target_vector[t] != NULL)
aa0a709a 1852 {
f7b839f7
DM
1853 int oldt = t, wid;
1854
105da05c
ILT
1855 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1856 ++t;
1857 while (wid < columns && bfd_target_vector[t] != NULL)
1858 {
1859 int newwid;
1860
1861 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1862 if (newwid >= columns)
1863 break;
1864 wid = newwid;
1865 ++t;
1866 }
f7b839f7 1867 display_info_table (oldt, t);
aa0a709a
SC
1868 }
1869}
1870
f7b839f7
DM
1871static void
1872display_info ()
1873{
1874 printf ("BFD header file version %s\n", BFD_VERSION);
1875 display_target_list ();
1876 display_target_tables ();
1877}
1878
2fa0b342
DHW
1879int
1880main (argc, argv)
1881 int argc;
1882 char **argv;
1883{
1884 int c;
2fa0b342
DHW
1885 char *target = default_target;
1886 boolean seenflag = false;
2fa0b342
DHW
1887
1888 program_name = *argv;
8f197c94
ILT
1889 xmalloc_set_program_name (program_name);
1890
be1d162b
ILT
1891 START_PROGRESS (program_name, 0);
1892
8f197c94 1893 bfd_init ();
2fa0b342 1894
a65619c8 1895 while ((c = getopt_long (argc, argv, "pib:m:VdDlfahrRtTxsSj:w", long_options,
d2442698 1896 (int *) 0))
aa0a709a
SC
1897 != EOF)
1898 {
aa21a2a9
ILT
1899 if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS)
1900 seenflag = true;
aa0a709a
SC
1901 switch (c)
1902 {
b3a2b497
ILT
1903 case 0:
1904 break; /* we've been given a long option */
aa0a709a
SC
1905 case 'm':
1906 machine = optarg;
1907 break;
1908 case 'j':
1909 only = optarg;
1910 break;
1911 case 'l':
1912 with_line_numbers = 1;
1913 break;
1914 case 'b':
1915 target = optarg;
1916 break;
1917 case 'f':
1918 dump_file_header = true;
1919 break;
1920 case 'i':
e1ec9f07 1921 formats_info = true;
aa0a709a 1922 break;
a65619c8
SC
1923 case 'p':
1924 dump_private_headers = 1;
1925 break;
aa0a709a 1926 case 'x':
a65619c8 1927 dump_private_headers = 1;
aa0a709a
SC
1928 dump_symtab = 1;
1929 dump_reloc_info = 1;
1930 dump_file_header = true;
1931 dump_ar_hdrs = 1;
1932 dump_section_headers = 1;
1933 break;
aa0a709a
SC
1934 case 't':
1935 dump_symtab = 1;
1936 break;
de3b08ac
ILT
1937 case 'T':
1938 dump_dynamic_symtab = 1;
1939 break;
aa0a709a
SC
1940 case 'd':
1941 disassemble = true;
1942 break;
d5464baa
ILT
1943 case 'D':
1944 disassemble = disassemble_all = true;
1945 break;
be1d162b
ILT
1946 case 'S':
1947 disassemble = true;
1948 with_source_code = true;
1949 break;
aa0a709a
SC
1950 case 's':
1951 dump_section_contents = 1;
1952 break;
1953 case 'r':
1954 dump_reloc_info = 1;
1955 break;
de3b08ac
ILT
1956 case 'R':
1957 dump_dynamic_reloc_info = 1;
1958 break;
aa0a709a
SC
1959 case 'a':
1960 dump_ar_hdrs = 1;
1961 break;
1962 case 'h':
1963 dump_section_headers = 1;
1964 break;
b3a2b497
ILT
1965 case 'H':
1966 usage (stdout, 0);
249c6fc0
RS
1967 case 'V':
1968 show_version = 1;
1969 break;
13e4db2e
SC
1970 case 'w':
1971 wide_output = 1;
1972 break;
aa21a2a9
ILT
1973 case OPTION_START_ADDRESS:
1974 start_address = parse_vma (optarg, "--start-address");
1975 break;
1976 case OPTION_STOP_ADDRESS:
1977 stop_address = parse_vma (optarg, "--stop-address");
1978 break;
aa0a709a 1979 default:
b3a2b497 1980 usage (stderr, 1);
aa0a709a 1981 }
2fa0b342 1982 }
2fa0b342 1983
249c6fc0 1984 if (show_version)
b3a2b497
ILT
1985 {
1986 printf ("GNU %s version %s\n", program_name, program_version);
1987 exit (0);
1988 }
249c6fc0 1989
2fa0b342 1990 if (seenflag == false)
b3a2b497 1991 usage (stderr, 1);
2fa0b342 1992
e1ec9f07 1993 if (formats_info)
aa0a709a
SC
1994 {
1995 display_info ();
1996 }
1997 else
1998 {
1999 if (optind == argc)
2000 display_file ("a.out", target);
2001 else
2002 for (; optind < argc;)
2003 display_file (argv[optind++], target);
2004 }
be1d162b
ILT
2005
2006 END_PROGRESS (program_name);
2007
2fa0b342
DHW
2008 return 0;
2009}
This page took 0.250316 seconds and 4 git commands to generate.