* Makefile.in: Add targets to automatically rebuild dependencies.
[deliverable/binutils-gdb.git] / binutils / objdump.c
CommitLineData
d20f480f 1/* objdump.c -- dump information about an object file.
37853673 2 Copyright 1990, 1991, 1992, 1993, 1994 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"
0140d746 24#include <sys/types.h>
2fa0b342
DHW
25#include <stdio.h>
26#include <ctype.h>
2e8adbd7 27#include "dis-asm.h"
105da05c 28#include "libiberty.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 */
9b018ecd 55int dump_stab_section_info; /* --stabs */
aa0a709a 56boolean disassemble; /* -d */
d5464baa 57boolean disassemble_all; /* -D */
e1ec9f07 58boolean formats_info; /* -i */
195d1adf 59char *only; /* -j secname */
13e4db2e 60int wide_output; /* -w */
aa21a2a9
ILT
61bfd_vma start_address = (bfd_vma) -1; /* --start-address */
62bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
195d1adf 63
cef35d48 64/* Extra info to pass to the disassembler address printing function. */
195d1adf
KR
65struct objdump_disasm_info {
66 bfd *abfd;
67 asection *sec;
8b129785 68 boolean require_sec;
195d1adf 69};
2fa0b342 70
cef35d48 71/* Architecture to disassemble for, or default if NULL. */
aa0a709a 72char *machine = (char *) NULL;
f7b839f7
DM
73
74/* The symbol table. */
aa0a709a 75asymbol **syms;
2fa0b342 76
f7b839f7 77/* Number of symbols in `syms'. */
ae5d2ff5 78long symcount = 0;
2fa0b342 79
be1d162b
ILT
80/* The sorted symbol table. */
81asymbol **sorted_syms;
82
83/* Number of symbols in `sorted_syms'. */
84long sorted_symcount = 0;
85
de3b08ac
ILT
86/* The dynamic symbol table. */
87asymbol **dynsyms;
88
89/* Number of symbols in `dynsyms'. */
90long dynsymcount = 0;
91
d9971b83
KR
92/* Forward declarations. */
93
94static void
95display_file PARAMS ((char *filename, char *target));
96
97static void
98dump_data PARAMS ((bfd *abfd));
99
100static void
101dump_relocs PARAMS ((bfd *abfd));
102
103static void
de3b08ac
ILT
104dump_dynamic_relocs PARAMS ((bfd * abfd));
105
106static void
107dump_reloc_set PARAMS ((bfd *, arelent **, long));
108
109static void
110dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
02a68547
ILT
111
112static void
113display_bfd PARAMS ((bfd *abfd));
8f197c94 114
c5ba2759
ILT
115static void
116objdump_print_value PARAMS ((bfd_vma, FILE *));
117
8f197c94
ILT
118static void
119objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
be1d162b
ILT
120
121static void
122show_line PARAMS ((bfd *, asection *, bfd_vma));
d9971b83 123\f
2fa0b342 124void
b3a2b497
ILT
125usage (stream, status)
126 FILE *stream;
127 int status;
2fa0b342 128{
b3a2b497 129 fprintf (stream, "\
a65619c8 130Usage: %s [-ahifdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
d5464baa
ILT
131 [--archive-headers] [--target=bfdname] [--disassemble]\n\
132 [--disassemble-all] [--file-headers] [--section-headers] [--headers]\n\
13e4db2e
SC
133 [--info] [--section=section-name] [--line-numbers] [--source]\n",
134 program_name);
135 fprintf (stream, "\
d5464baa
ILT
136 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
137 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
aa21a2a9
ILT
138 [--wide] [--version] [--help] [--private-headers]\n\
139 [--start-address=addr] [--stop-address=addr] objfile...\n\
13e4db2e 140at least one option besides -l (--line-numbers) must be given\n");
be1d162b 141 list_supported_targets (program_name, stream);
b3a2b497 142 exit (status);
2fa0b342
DHW
143}
144
aa21a2a9
ILT
145/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
146
147#define OPTION_START_ADDRESS (150)
148#define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
149
aa0a709a
SC
150static struct option long_options[]=
151{
02a68547 152 {"all-headers", no_argument, NULL, 'x'},
a65619c8 153 {"private-headers", no_argument, NULL, 'p'},
02a68547
ILT
154 {"architecture", required_argument, NULL, 'm'},
155 {"archive-headers", no_argument, NULL, 'a'},
156 {"disassemble", no_argument, NULL, 'd'},
d5464baa 157 {"disassemble-all", no_argument, NULL, 'D'},
de3b08ac
ILT
158 {"dynamic-reloc", no_argument, NULL, 'R'},
159 {"dynamic-syms", no_argument, NULL, 'T'},
02a68547
ILT
160 {"file-headers", no_argument, NULL, 'f'},
161 {"full-contents", no_argument, NULL, 's'},
162 {"headers", no_argument, NULL, 'h'},
163 {"help", no_argument, NULL, 'H'},
164 {"info", no_argument, NULL, 'i'},
165 {"line-numbers", no_argument, NULL, 'l'},
166 {"reloc", no_argument, NULL, 'r'},
167 {"section", required_argument, NULL, 'j'},
168 {"section-headers", no_argument, NULL, 'h'},
be1d162b 169 {"source", no_argument, NULL, 'S'},
73b8f102 170 {"stabs", no_argument, &dump_stab_section_info, 1},
aa21a2a9
ILT
171 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
172 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
02a68547
ILT
173 {"syms", no_argument, NULL, 't'},
174 {"target", required_argument, NULL, 'b'},
aa21a2a9 175 {"version", no_argument, &show_version, 1},
13e4db2e 176 {"wide", no_argument, &wide_output, 'w'},
d2442698
DM
177 {0, no_argument, 0, 0}
178};
f7b839f7 179\f
2fa0b342 180static void
f7b839f7 181dump_section_header (abfd, section, ignored)
aa0a709a 182 bfd *abfd;
f7b839f7
DM
183 asection *section;
184 PTR ignored;
2fa0b342 185{
f7b839f7 186 char *comma = "";
aa0a709a 187
2fa0b342 188#define PF(x,y) \
f7b839f7
DM
189 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
190
191
192 printf ("SECTION %d [%s]\t: size %08x",
193 section->index,
194 section->name,
195 (unsigned) bfd_get_section_size_before_reloc (section));
196 printf (" vma ");
197 printf_vma (section->vma);
13e4db2e
SC
198 printf (" lma ");
199 printf_vma (section->lma);
200 printf (" align 2**%u%s ",
201 section->alignment_power, (wide_output) ? "" : "\n");
f7b839f7
DM
202 PF (SEC_ALLOC, "ALLOC");
203 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
204 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
205 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
206 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
207 PF (SEC_LOAD, "LOAD");
208 PF (SEC_RELOC, "RELOC");
195d1adf 209#ifdef SEC_BALIGN
f7b839f7 210 PF (SEC_BALIGN, "BALIGN");
195d1adf 211#endif
f7b839f7
DM
212 PF (SEC_READONLY, "READONLY");
213 PF (SEC_CODE, "CODE");
214 PF (SEC_DATA, "DATA");
215 PF (SEC_ROM, "ROM");
216 PF (SEC_DEBUGGING, "DEBUGGING");
28d1b01e 217 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
f7b839f7 218 printf ("\n");
2fa0b342 219#undef PF
2fa0b342
DHW
220}
221
f7b839f7
DM
222static void
223dump_headers (abfd)
224 bfd *abfd;
225{
226 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
227}
228\f
2fa0b342 229static asymbol **
abdcac0f
DM
230slurp_symtab (abfd)
231 bfd *abfd;
2fa0b342 232{
aa0a709a 233 asymbol **sy = (asymbol **) NULL;
ae5d2ff5 234 long storage;
2fa0b342 235
aa0a709a
SC
236 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
237 {
f7b839f7 238 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
c5ba2759 239 symcount = 0;
f7b839f7 240 return NULL;
aa0a709a
SC
241 }
242
ae5d2ff5
ILT
243 storage = bfd_get_symtab_upper_bound (abfd);
244 if (storage < 0)
245 bfd_fatal (bfd_get_filename (abfd));
246
aa0a709a
SC
247 if (storage)
248 {
02a68547 249 sy = (asymbol **) xmalloc (storage);
aa0a709a
SC
250 }
251 symcount = bfd_canonicalize_symtab (abfd, sy);
ae5d2ff5
ILT
252 if (symcount < 0)
253 bfd_fatal (bfd_get_filename (abfd));
254 if (symcount == 0)
de3b08ac
ILT
255 fprintf (stderr, "%s: %s: No symbols\n",
256 program_name, bfd_get_filename (abfd));
257 return sy;
258}
259
260/* Read in the dynamic symbols. */
261
262static asymbol **
263slurp_dynamic_symtab (abfd)
264 bfd *abfd;
265{
266 asymbol **sy = (asymbol **) NULL;
267 long storage;
268
de3b08ac
ILT
269 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
270 if (storage < 0)
28d1b01e
ILT
271 {
272 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
273 {
274 fprintf (stderr, "%s: %s: not a dynamic object\n",
275 program_name, bfd_get_filename (abfd));
c5ba2759 276 dynsymcount = 0;
28d1b01e
ILT
277 return NULL;
278 }
279
280 bfd_fatal (bfd_get_filename (abfd));
281 }
de3b08ac
ILT
282
283 if (storage)
284 {
285 sy = (asymbol **) xmalloc (storage);
286 }
287 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
288 if (dynsymcount < 0)
289 bfd_fatal (bfd_get_filename (abfd));
290 if (dynsymcount == 0)
291 fprintf (stderr, "%s: %s: No dynamic symbols\n",
292 program_name, bfd_get_filename (abfd));
aa0a709a 293 return sy;
2fa0b342 294}
aa0a709a 295
f7b839f7
DM
296/* Filter out (in place) symbols that are useless for disassembly.
297 COUNT is the number of elements in SYMBOLS.
298 Return the number of useful symbols. */
3ae36cb6 299
ae5d2ff5 300long
f7b839f7
DM
301remove_useless_symbols (symbols, count)
302 asymbol **symbols;
ae5d2ff5 303 long count;
3ae36cb6 304{
f7b839f7 305 register asymbol **in_ptr = symbols, **out_ptr = symbols;
3ae36cb6 306
f7b839f7 307 while (--count >= 0)
3ae36cb6
PB
308 {
309 asymbol *sym = *in_ptr++;
310
311 if (sym->name == NULL || sym->name[0] == '\0')
312 continue;
313 if (sym->flags & (BSF_DEBUGGING))
314 continue;
28d1b01e 315 if (bfd_is_und_section (sym->section)
3ae36cb6
PB
316 || bfd_is_com_section (sym->section))
317 continue;
318
319 *out_ptr++ = sym;
320 }
f7b839f7 321 return out_ptr - symbols;
3ae36cb6
PB
322}
323
37853673
SS
324/* Sort symbols into value order. */
325
aa0a709a 326static int
37853673 327compare_symbols (ap, bp)
d5464baa
ILT
328 const PTR ap;
329 const PTR bp;
2fa0b342 330{
d5464baa
ILT
331 const asymbol *a = *(const asymbol **)ap;
332 const asymbol *b = *(const asymbol **)bp;
db552bda
ILT
333 const char *an, *bn;
334 size_t anl, bnl;
335 boolean af, bf;
2fa0b342 336
be1d162b 337 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
3ae36cb6 338 return 1;
be1d162b 339 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
3ae36cb6 340 return -1;
2fa0b342 341
3ae36cb6
PB
342 if (a->section > b->section)
343 return 1;
344 else if (a->section < b->section)
345 return -1;
db552bda
ILT
346
347 an = bfd_asymbol_name (a);
348 bn = bfd_asymbol_name (b);
349 anl = strlen (an);
350 bnl = strlen (bn);
351
352 /* The symbols gnu_compiled and gcc2_compiled convey no real
353 information, so put them after other symbols with the same value. */
354
355 af = (strstr (an, "gnu_compiled") != NULL
356 || strstr (an, "gcc2_compiled") != NULL);
357 bf = (strstr (bn, "gnu_compiled") != NULL
358 || strstr (bn, "gcc2_compiled") != NULL);
359
360 if (af && ! bf)
361 return 1;
362 if (! af && bf)
363 return -1;
364
365 /* We use a heuristic for the file name, to try to sort it after
366 more useful symbols. It may not work on non Unix systems, but it
367 doesn't really matter; the only difference is precisely which
368 symbol names get printed. */
369
370#define file_symbol(s, sn, snl) \
371 (((s)->flags & BSF_FILE) != 0 \
372 || ((sn)[(snl) - 2] == '.' \
373 && ((sn)[(snl) - 1] == 'o' \
374 || (sn)[(snl) - 1] == 'a')))
375
376 af = file_symbol (a, an, anl);
377 bf = file_symbol (b, bn, bnl);
378
379 if (af && ! bf)
380 return 1;
381 if (! af && bf)
382 return -1;
383
3ae36cb6 384 return 0;
2fa0b342
DHW
385}
386
d5464baa
ILT
387/* Sort relocs into address order. */
388
389static int
390compare_relocs (ap, bp)
391 const PTR ap;
392 const PTR bp;
393{
394 const arelent *a = *(const arelent **)ap;
395 const arelent *b = *(const arelent **)bp;
396
397 if (a->address > b->address)
398 return 1;
399 else if (a->address < b->address)
400 return -1;
401
a65619c8
SC
402 /* So that associated relocations tied to the same address show up
403 in the correct order, we don't do any further sorting. */
404 if (a > b)
405 return 1;
406 else if (a < b)
407 return -1;
408 else
409 return 0;
d5464baa
ILT
410}
411
c5ba2759
ILT
412/* Print VMA to STREAM with no leading zeroes. */
413
414static void
415objdump_print_value (vma, stream)
416 bfd_vma vma;
417 FILE *stream;
418{
419 char buf[30];
420 char *p;
421
422 sprintf_vma (buf, vma);
423 for (p = buf; *p == '0'; ++p)
424 ;
425 fprintf (stream, "%s", p);
426}
427
f7b839f7
DM
428/* Print VMA symbolically to INFO if possible. */
429
8f197c94 430static void
545a2768 431objdump_print_address (vma, info)
aa0a709a 432 bfd_vma vma;
545a2768 433 struct disassemble_info *info;
2fa0b342 434{
195d1adf
KR
435 /* @@ For relocateable files, should filter out symbols belonging to
436 the wrong section. Unfortunately, not enough information is supplied
437 to this routine to determine the correct section in all cases. */
438 /* @@ Would it speed things up to cache the last two symbols returned,
439 and maybe their address ranges? For many processors, only one memory
440 operand can be present at a time, so the 2-entry cache wouldn't be
441 constantly churned by code doing heavy memory accesses. */
2fa0b342 442
be1d162b 443 /* Indices in `sorted_syms'. */
ae5d2ff5 444 long min = 0;
be1d162b 445 long max = sorted_symcount;
ae5d2ff5 446 long thisplace;
2fa0b342 447
3ae36cb6
PB
448 fprintf_vma (info->stream, vma);
449
be1d162b 450 if (sorted_symcount < 1)
f7b839f7
DM
451 return;
452
8f197c94
ILT
453 /* Perform a binary search looking for the closest symbol to the
454 required value. We are searching the range (min, max]. */
455 while (min + 1 < max)
aa0a709a 456 {
f7b839f7 457 asymbol *sym;
8f197c94 458
f7b839f7 459 thisplace = (max + min) / 2;
be1d162b 460 sym = sorted_syms[thisplace];
8f197c94 461
13e4db2e 462 if (bfd_asymbol_value (sym) > vma)
f7b839f7 463 max = thisplace;
13e4db2e 464 else if (bfd_asymbol_value (sym) < vma)
f7b839f7
DM
465 min = thisplace;
466 else
aa0a709a 467 {
8f197c94
ILT
468 min = thisplace;
469 break;
aa0a709a 470 }
f7b839f7 471 }
fc5d6074 472
8f197c94
ILT
473 /* The symbol we want is now in min, the low end of the range we
474 were searching. */
475 thisplace = min;
db552bda
ILT
476 while (thisplace > 0
477 && (bfd_asymbol_value (sorted_syms[thisplace])
478 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
479 --thisplace;
8f197c94 480
f7b839f7
DM
481 {
482 /* If this symbol isn't global, search for one with the same value
483 that is. */
be1d162b 484 bfd_vma val = bfd_asymbol_value (sorted_syms[thisplace]);
ae5d2ff5 485 long i;
be1d162b 486 if (sorted_syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
f7b839f7 487 for (i = thisplace - 1; i >= 0; i--)
aa0a709a 488 {
be1d162b
ILT
489 if (bfd_asymbol_value (sorted_syms[i]) == val
490 && (!(sorted_syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
491 || ((sorted_syms[thisplace]->flags & BSF_DEBUGGING)
492 && !(sorted_syms[i]->flags & BSF_DEBUGGING))))
aa0a709a 493 {
f7b839f7
DM
494 thisplace = i;
495 break;
aa0a709a
SC
496 }
497 }
be1d162b
ILT
498 if (sorted_syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
499 for (i = thisplace + 1; i < sorted_symcount; i++)
f7b839f7 500 {
be1d162b
ILT
501 if (bfd_asymbol_value (sorted_syms[i]) == val
502 && (!(sorted_syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
503 || ((sorted_syms[thisplace]->flags & BSF_DEBUGGING)
504 && !(sorted_syms[i]->flags & BSF_DEBUGGING))))
195d1adf 505 {
f7b839f7
DM
506 thisplace = i;
507 break;
195d1adf 508 }
f7b839f7
DM
509 }
510 }
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;
837
aa0a709a
SC
838 if (machine != (char *) NULL)
839 {
db552bda 840 const bfd_arch_info_type *info = bfd_scan_arch (machine);
cef35d48 841 if (info == NULL)
aa0a709a
SC
842 {
843 fprintf (stderr, "%s: Can't use supplied machine %s\n",
844 program_name,
845 machine);
846 exit (1);
847 }
848 abfd->arch_info = info;
2fa0b342 849 }
e779a58c 850
db552bda
ILT
851 disassemble_fn = disassembler (abfd);
852 if (!disassemble_fn)
aa0a709a 853 {
db552bda
ILT
854 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
855 program_name,
856 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
857 exit (1);
aa0a709a 858 }
2fa0b342
DHW
859
860 for (section = abfd->sections;
aa0a709a
SC
861 section != (asection *) NULL;
862 section = section->next)
65cceb78 863 {
cef35d48
DM
864 bfd_byte *data = NULL;
865 bfd_size_type datasize = 0;
be1d162b 866 arelent **relbuf = NULL;
d5464baa
ILT
867 arelent **relpp = NULL;
868 arelent **relppend = NULL;
aa21a2a9 869 long stop;
2fa0b342 870
d5464baa
ILT
871 if ((section->flags & SEC_LOAD) == 0
872 || (! disassemble_all
873 && only == NULL
874 && (section->flags & SEC_CODE) == 0))
cef35d48
DM
875 continue;
876 if (only != (char *) NULL && strcmp (only, section->name) != 0)
877 continue;
2fa0b342 878
d5464baa
ILT
879 if (dump_reloc_info
880 && (section->flags & SEC_RELOC) != 0)
881 {
be1d162b
ILT
882 long relsize;
883
884 relsize = bfd_get_reloc_upper_bound (abfd, section);
885 if (relsize < 0)
886 bfd_fatal (bfd_get_filename (abfd));
887
888 if (relsize > 0)
889 {
890 long relcount;
891
892 relbuf = (arelent **) xmalloc (relsize);
893 relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
894 if (relcount < 0)
895 bfd_fatal (bfd_get_filename (abfd));
896
897 /* Sort the relocs by address. */
898 qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
899
900 relpp = relbuf;
901 relppend = relpp + relcount;
902 }
d5464baa
ILT
903 }
904
cef35d48 905 printf ("Disassembly of section %s:\n", section->name);
2fa0b342 906
cef35d48
DM
907 datasize = bfd_get_section_size_before_reloc (section);
908 if (datasize == 0)
909 continue;
2fa0b342 910
cef35d48 911 data = (bfd_byte *) xmalloc ((size_t) datasize);
2fa0b342 912
cef35d48 913 bfd_get_section_contents (abfd, section, data, 0, datasize);
2fa0b342 914
cef35d48
DM
915 aux.sec = section;
916 disasm_info.buffer = data;
917 disasm_info.buffer_vma = section->vma;
918 disasm_info.buffer_length = datasize;
aa21a2a9
ILT
919 if (start_address == (bfd_vma) -1
920 || start_address < disasm_info.buffer_vma)
921 i = 0;
922 else
923 i = start_address - disasm_info.buffer_vma;
924 if (stop_address == (bfd_vma) -1)
925 stop = datasize;
926 else
927 {
928 if (stop_address < disasm_info.buffer_vma)
929 stop = 0;
930 else
931 stop = stop_address - disasm_info.buffer_vma;
932 if (stop > disasm_info.buffer_length)
933 stop = disasm_info.buffer_length;
934 }
935 while (i < stop)
cef35d48 936 {
d5464baa 937 int bytes;
13e4db2e 938 boolean need_nl = false;
d5464baa 939
cef35d48
DM
940 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
941 data[i + 3] == 0)
aa0a709a 942 {
cef35d48 943 if (done_dot == false)
aa0a709a 944 {
cef35d48
DM
945 printf ("...\n");
946 done_dot = true;
65cceb78 947 }
d5464baa 948 bytes = 4;
cef35d48
DM
949 }
950 else
951 {
952 done_dot = false;
be1d162b
ILT
953 if (with_line_numbers || with_source_code)
954 show_line (abfd, section, i);
8b129785 955 aux.require_sec = true;
cef35d48 956 objdump_print_address (section->vma + i, &disasm_info);
8b129785 957 aux.require_sec = false;
cef35d48 958 putchar (' ');
65cceb78 959
db552bda
ILT
960 bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
961 if (bytes < 0)
962 break;
963
13e4db2e
SC
964 if (!wide_output)
965 putchar ('\n');
966 else
967 need_nl = true;
96d7950b 968 }
d5464baa
ILT
969
970 if (dump_reloc_info
971 && (section->flags & SEC_RELOC) != 0)
972 {
973 while (relpp < relppend
746cffcf
ILT
974 && ((*relpp)->address >= (bfd_vma) i
975 && (*relpp)->address < (bfd_vma) i + bytes))
d5464baa
ILT
976 {
977 arelent *q;
978 const char *sym_name;
979
980 q = *relpp;
981
982 printf ("\t\tRELOC: ");
983
984 printf_vma (section->vma + q->address);
985
986 printf (" %s ", q->howto->name);
987
988 if (q->sym_ptr_ptr != NULL
989 && *q->sym_ptr_ptr != NULL)
990 {
991 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
992 if (sym_name == NULL || *sym_name == '\0')
993 {
994 asection *sym_sec;
995
996 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
997 sym_name = bfd_get_section_name (abfd, sym_sec);
998 if (sym_name == NULL || *sym_name == '\0')
999 sym_name = "*unknown*";
1000 }
1001 }
1002
1003 printf ("%s", sym_name);
1004
1005 if (q->addend)
1006 {
1007 printf ("+0x");
1008 printf_vma (q->addend);
1009 }
1010
1011 printf ("\n");
13e4db2e 1012 need_nl = false;
d5464baa
ILT
1013 ++relpp;
1014 }
1015 }
1016
13e4db2e
SC
1017 if (need_nl)
1018 printf ("\n");
1019
d5464baa 1020 i += bytes;
96d7950b 1021 }
be1d162b 1022
cef35d48 1023 free (data);
be1d162b
ILT
1024 if (relbuf != NULL)
1025 free (relbuf);
2fa0b342 1026 }
c5ba2759 1027 free (sorted_syms);
2fa0b342 1028}
73b8f102 1029\f
73b8f102
JG
1030
1031/* Define a table of stab values and print-strings. We wish the initializer
1032 could be a direct-mapped table, but instead we build one the first
1033 time we need it. */
1034
fe2750e1 1035char **stab_name;
73b8f102
JG
1036
1037struct stab_print {
1038 int value;
fe2750e1 1039 char *string;
73b8f102
JG
1040};
1041
1042struct stab_print stab_print[] = {
1043#define __define_stab(NAME, CODE, STRING) {CODE, STRING},
1044#include "aout/stab.def"
1045#undef __define_stab
02a68547 1046 {0, ""}
73b8f102
JG
1047};
1048
250e36fe
DM
1049void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
1050 char *strsect_name));
249c6fc0 1051
250e36fe 1052/* Dump the stabs sections from an object file that has a section that
73b8f102
JG
1053 uses Sun stabs encoding. It has to use some hooks into BFD because
1054 string table sections are not normally visible to BFD callers. */
1055
1056void
9b018ecd 1057dump_stabs (abfd)
73b8f102
JG
1058 bfd *abfd;
1059{
fe2750e1
SS
1060 /* Allocate and initialize stab name array if first time. */
1061 if (stab_name == NULL)
73b8f102 1062 {
250e36fe
DM
1063 int i;
1064
fe2750e1
SS
1065 stab_name = (char **) xmalloc (256 * sizeof(char *));
1066 /* Clear the array. */
73b8f102 1067 for (i = 0; i < 256; i++)
fe2750e1
SS
1068 stab_name[i] = NULL;
1069 /* Fill in the defined stabs. */
1070 for (i = 0; *stab_print[i].string; i++)
1071 stab_name[stab_print[i].value] = stab_print[i].string;
73b8f102
JG
1072 }
1073
250e36fe
DM
1074 dump_section_stabs (abfd, ".stab", ".stabstr");
1075 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
1076 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
1077 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
249c6fc0
RS
1078}
1079
250e36fe
DM
1080static struct internal_nlist *stabs;
1081static bfd_size_type stab_size;
1082
1083static char *strtab;
1084static bfd_size_type stabstr_size;
1085
1086/* Read ABFD's stabs section STABSECT_NAME into `stabs'
1087 and string table section STRSECT_NAME into `strtab'.
1088 If the section exists and was read, allocate the space and return true.
1089 Otherwise return false. */
1090
1091boolean
1092read_section_stabs (abfd, stabsect_name, strsect_name)
249c6fc0 1093 bfd *abfd;
250e36fe
DM
1094 char *stabsect_name;
1095 char *strsect_name;
249c6fc0 1096{
9b018ecd 1097 asection *stabsect, *stabstrsect;
9b018ecd 1098
d5671c53
ILT
1099 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
1100 if (0 == stabsect)
73b8f102 1101 {
250e36fe
DM
1102 printf ("No %s section present\n\n", stabsect_name);
1103 return false;
73b8f102
JG
1104 }
1105
d5671c53
ILT
1106 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
1107 if (0 == stabstrsect)
73b8f102 1108 {
eae82145 1109 fprintf (stderr, "%s: %s has no %s section\n", program_name,
250e36fe
DM
1110 bfd_get_filename (abfd), strsect_name);
1111 return false;
73b8f102 1112 }
9b018ecd 1113
d5671c53
ILT
1114 stab_size = bfd_section_size (abfd, stabsect);
1115 stabstr_size = bfd_section_size (abfd, stabstrsect);
73b8f102 1116
9b018ecd
ILT
1117 stabs = (struct internal_nlist *) xmalloc (stab_size);
1118 strtab = (char *) xmalloc (stabstr_size);
73b8f102 1119
d5671c53 1120 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
9b018ecd 1121 {
d5671c53
ILT
1122 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1123 program_name, stabsect_name, bfd_get_filename (abfd),
1124 bfd_errmsg (bfd_get_error ()));
1125 free (stabs);
1126 free (strtab);
1127 return false;
73b8f102 1128 }
2fa0b342 1129
d5671c53
ILT
1130 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
1131 stabstr_size))
9b018ecd 1132 {
d5671c53
ILT
1133 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1134 program_name, strsect_name, bfd_get_filename (abfd),
1135 bfd_errmsg (bfd_get_error ()));
1136 free (stabs);
1137 free (strtab);
1138 return false;
73b8f102 1139 }
d5671c53 1140
250e36fe
DM
1141 return true;
1142}
73b8f102
JG
1143
1144#define SWAP_SYMBOL(symp, abfd) \
250e36fe 1145{ \
73b8f102 1146 (symp)->n_strx = bfd_h_get_32(abfd, \
250e36fe 1147 (unsigned char *)&(symp)->n_strx); \
73b8f102 1148 (symp)->n_desc = bfd_h_get_16 (abfd, \
250e36fe 1149 (unsigned char *)&(symp)->n_desc); \
73b8f102 1150 (symp)->n_value = bfd_h_get_32 (abfd, \
250e36fe
DM
1151 (unsigned char *)&(symp)->n_value); \
1152}
73b8f102 1153
250e36fe
DM
1154/* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1155 using string table section STRSECT_NAME (in `strtab'). */
1156
1157void
1158print_section_stabs (abfd, stabsect_name, strsect_name)
1159 bfd *abfd;
1160 char *stabsect_name;
1161 char *strsect_name;
1162{
1163 int i;
1164 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
1165 struct internal_nlist *stabp = stabs,
1166 *stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
73b8f102 1167
250e36fe
DM
1168 printf ("Contents of %s section:\n\n", stabsect_name);
1169 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
249c6fc0
RS
1170
1171 /* Loop through all symbols and print them.
1172
1173 We start the index at -1 because there is a dummy symbol on
250e36fe 1174 the front of stabs-in-{coff,elf} sections that supplies sizes. */
249c6fc0 1175
250e36fe 1176 for (i = -1; stabp < stabs_end; stabp++, i++)
73b8f102 1177 {
250e36fe 1178 SWAP_SYMBOL (stabp, abfd);
fe2750e1 1179 printf ("\n%-6d ", i);
250e36fe 1180 /* Either print the stab name, or, if unnamed, print its number
fe2750e1 1181 again (makes consistent formatting for tools like awk). */
250e36fe
DM
1182 if (stab_name[stabp->n_type])
1183 printf ("%-6s", stab_name[stabp->n_type]);
105da05c
ILT
1184 else if (stabp->n_type == N_UNDF)
1185 printf ("HdrSym");
fe2750e1 1186 else
105da05c 1187 printf ("%-6d", stabp->n_type);
250e36fe
DM
1188 printf (" %-6d %-6d ", stabp->n_other, stabp->n_desc);
1189 printf_vma (stabp->n_value);
1190 printf (" %-6lu", stabp->n_strx);
249c6fc0
RS
1191
1192 /* Symbols with type == 0 (N_UNDF) specify the length of the
1193 string table associated with this file. We use that info
1194 to know how to relocate the *next* file's string table indices. */
1195
250e36fe 1196 if (stabp->n_type == N_UNDF)
249c6fc0
RS
1197 {
1198 file_string_table_offset = next_file_string_table_offset;
250e36fe 1199 next_file_string_table_offset += stabp->n_value;
249c6fc0 1200 }
249c6fc0 1201 else
e1ec9f07 1202 {
250e36fe 1203 /* Using the (possibly updated) string table offset, print the
e1ec9f07
SS
1204 string (if any) associated with this symbol. */
1205
250e36fe
DM
1206 if ((stabp->n_strx + file_string_table_offset) < stabstr_size)
1207 printf (" %s", &strtab[stabp->n_strx + file_string_table_offset]);
e1ec9f07
SS
1208 else
1209 printf (" *");
1210 }
73b8f102
JG
1211 }
1212 printf ("\n\n");
1213}
249c6fc0 1214
250e36fe
DM
1215void
1216dump_section_stabs (abfd, stabsect_name, strsect_name)
1217 bfd *abfd;
1218 char *stabsect_name;
1219 char *strsect_name;
1220{
13e4db2e 1221 asection *s;
13e4db2e 1222
a65619c8
SC
1223 /* Check for section names for which stabsect_name is a prefix, to
1224 handle .stab0, etc. */
13e4db2e 1225 for (s = abfd->sections;
a65619c8 1226 s != NULL;
13e4db2e
SC
1227 s = s->next)
1228 {
a65619c8
SC
1229 if (strncmp (stabsect_name, s->name, strlen (stabsect_name)) == 0
1230 && strncmp (strsect_name, s->name, strlen (strsect_name)) != 0)
13e4db2e 1231 {
a65619c8
SC
1232 if (read_section_stabs (abfd, s->name, strsect_name))
1233 {
1234 print_section_stabs (abfd, s->name, strsect_name);
1235 free (stabs);
1236 free (strtab);
1237 }
13e4db2e
SC
1238 }
1239 }
250e36fe
DM
1240}
1241\f
eae82145 1242static void
f7b839f7
DM
1243dump_bfd_header (abfd)
1244 bfd *abfd;
1245{
1246 char *comma = "";
1247
1248 printf ("architecture: %s, ",
1249 bfd_printable_arch_mach (bfd_get_arch (abfd),
1250 bfd_get_mach (abfd)));
1251 printf ("flags 0x%08x:\n", abfd->flags);
1252
1253#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
1254 PF (HAS_RELOC, "HAS_RELOC");
1255 PF (EXEC_P, "EXEC_P");
1256 PF (HAS_LINENO, "HAS_LINENO");
1257 PF (HAS_DEBUG, "HAS_DEBUG");
1258 PF (HAS_SYMS, "HAS_SYMS");
1259 PF (HAS_LOCALS, "HAS_LOCALS");
1260 PF (DYNAMIC, "DYNAMIC");
1261 PF (WP_TEXT, "WP_TEXT");
1262 PF (D_PAGED, "D_PAGED");
1263 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
1264 printf ("\nstart address 0x");
1265 printf_vma (abfd->start_address);
1266}
a65619c8
SC
1267\f
1268static void
1269dump_bfd_private_header (abfd)
1270bfd *abfd;
1271{
1272 bfd_print_private_bfd_data (abfd, stdout);
1273}
02a68547 1274static void
2fa0b342
DHW
1275display_bfd (abfd)
1276 bfd *abfd;
1277{
209e5610
DM
1278 char **matching;
1279
1280 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
aa0a709a 1281 {
cef35d48 1282 bfd_nonfatal (bfd_get_filename (abfd));
8f197c94 1283 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
209e5610
DM
1284 {
1285 list_matching_formats (matching);
1286 free (matching);
1287 }
aa0a709a
SC
1288 return;
1289 }
f7b839f7 1290
cef35d48
DM
1291 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
1292 abfd->xvec->name);
aa0a709a
SC
1293 if (dump_ar_hdrs)
1294 print_arelt_descr (stdout, abfd, true);
aa0a709a 1295 if (dump_file_header)
f7b839f7 1296 dump_bfd_header (abfd);
a65619c8
SC
1297 if (dump_private_headers)
1298 dump_bfd_private_header (abfd);
f7b839f7 1299 putchar ('\n');
2fa0b342 1300 if (dump_section_headers)
aa0a709a
SC
1301 dump_headers (abfd);
1302 if (dump_symtab || dump_reloc_info || disassemble)
1303 {
1304 syms = slurp_symtab (abfd);
1305 }
de3b08ac
ILT
1306 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
1307 {
1308 dynsyms = slurp_dynamic_symtab (abfd);
1309 }
aa0a709a 1310 if (dump_symtab)
de3b08ac
ILT
1311 dump_symbols (abfd, false);
1312 if (dump_dynamic_symtab)
1313 dump_symbols (abfd, true);
73b8f102 1314 if (dump_stab_section_info)
9b018ecd 1315 dump_stabs (abfd);
d5464baa 1316 if (dump_reloc_info && ! disassemble)
aa0a709a 1317 dump_relocs (abfd);
de3b08ac
ILT
1318 if (dump_dynamic_reloc_info)
1319 dump_dynamic_relocs (abfd);
aa0a709a
SC
1320 if (dump_section_contents)
1321 dump_data (abfd);
1322 if (disassemble)
1323 disassemble_data (abfd);
c5ba2759
ILT
1324 if (syms)
1325 {
1326 free (syms);
1327 syms = NULL;
1328 }
1329 if (dynsyms)
1330 {
1331 free (dynsyms);
1332 dynsyms = NULL;
1333 }
2fa0b342
DHW
1334}
1335
d9971b83 1336static void
2fa0b342
DHW
1337display_file (filename, target)
1338 char *filename;
1339 char *target;
1340{
1341 bfd *file, *arfile = (bfd *) NULL;
1342
1343 file = bfd_openr (filename, target);
aa0a709a
SC
1344 if (file == NULL)
1345 {
cef35d48 1346 bfd_nonfatal (filename);
aa0a709a
SC
1347 return;
1348 }
2fa0b342 1349
aa0a709a
SC
1350 if (bfd_check_format (file, bfd_archive) == true)
1351 {
8f197c94
ILT
1352 bfd *last_arfile = NULL;
1353
aa0a709a
SC
1354 printf ("In archive %s:\n", bfd_get_filename (file));
1355 for (;;)
1356 {
8f197c94 1357 bfd_set_error (bfd_error_no_error);
aa0a709a
SC
1358
1359 arfile = bfd_openr_next_archived_file (file, arfile);
1360 if (arfile == NULL)
1361 {
8f197c94 1362 if (bfd_get_error () != bfd_error_no_more_archived_files)
d2442698 1363 {
cef35d48 1364 bfd_nonfatal (bfd_get_filename (file));
d2442698 1365 }
8f197c94 1366 break;
aa0a709a 1367 }
2fa0b342 1368
aa0a709a 1369 display_bfd (arfile);
8f197c94
ILT
1370
1371 if (last_arfile != NULL)
1372 bfd_close (last_arfile);
1373 last_arfile = arfile;
aa0a709a 1374 }
8f197c94
ILT
1375
1376 if (last_arfile != NULL)
1377 bfd_close (last_arfile);
2fa0b342 1378 }
2fa0b342 1379 else
aa0a709a 1380 display_bfd (file);
2fa0b342 1381
aa0a709a 1382 bfd_close (file);
2fa0b342
DHW
1383}
1384\f
1385/* Actually display the various requested regions */
1386
d9971b83 1387static void
2fa0b342
DHW
1388dump_data (abfd)
1389 bfd *abfd;
1390{
1391 asection *section;
aa0a709a 1392 bfd_byte *data = 0;
fc5d6074
SC
1393 bfd_size_type datasize = 0;
1394 bfd_size_type i;
aa21a2a9 1395 bfd_size_type start, stop;
2fa0b342
DHW
1396
1397 for (section = abfd->sections; section != NULL; section =
aa0a709a
SC
1398 section->next)
1399 {
1400 int onaline = 16;
2fa0b342 1401
aa0a709a
SC
1402 if (only == (char *) NULL ||
1403 strcmp (only, section->name) == 0)
60c80016 1404 {
aa0a709a
SC
1405 if (section->flags & SEC_HAS_CONTENTS)
1406 {
1407 printf ("Contents of section %s:\n", section->name);
1408
9b018ecd 1409 if (bfd_section_size (abfd, section) == 0)
aa0a709a 1410 continue;
02a68547 1411 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
9b018ecd 1412 datasize = bfd_section_size (abfd, section);
2fa0b342 1413
2fa0b342 1414
9b018ecd 1415 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
2fa0b342 1416
aa21a2a9
ILT
1417 if (start_address == (bfd_vma) -1
1418 || start_address < section->vma)
1419 start = 0;
1420 else
1421 start = start_address - section->vma;
1422 if (stop_address == (bfd_vma) -1)
1423 stop = bfd_section_size (abfd, section);
1424 else
1425 {
1426 if (stop_address < section->vma)
1427 stop = 0;
1428 else
1429 stop = stop_address - section->vma;
1430 if (stop > bfd_section_size (abfd, section))
1431 stop = bfd_section_size (abfd, section);
1432 }
1433 for (i = start; i < stop; i += onaline)
aa0a709a
SC
1434 {
1435 bfd_size_type j;
1436
1437 printf (" %04lx ", (unsigned long int) (i + section->vma));
1438 for (j = i; j < i + onaline; j++)
1439 {
aa21a2a9 1440 if (j < stop)
aa0a709a
SC
1441 printf ("%02x", (unsigned) (data[j]));
1442 else
1443 printf (" ");
1444 if ((j & 3) == 3)
1445 printf (" ");
1446 }
2fa0b342 1447
aa0a709a
SC
1448 printf (" ");
1449 for (j = i; j < i + onaline; j++)
1450 {
aa21a2a9 1451 if (j >= stop)
aa0a709a
SC
1452 printf (" ");
1453 else
1454 printf ("%c", isprint (data[j]) ? data[j] : '.');
1455 }
1456 putchar ('\n');
1457 }
d9971b83 1458 free (data);
60c80016 1459 }
2fa0b342 1460 }
2fa0b342 1461 }
2fa0b342
DHW
1462}
1463
2fa0b342 1464/* Should perhaps share code and display with nm? */
d9971b83 1465static void
de3b08ac 1466dump_symbols (abfd, dynamic)
2fa0b342 1467 bfd *abfd;
de3b08ac 1468 boolean dynamic;
2fa0b342 1469{
de3b08ac
ILT
1470 asymbol **current;
1471 long max;
ae5d2ff5 1472 long count;
2fa0b342 1473
de3b08ac 1474 if (dynamic)
aa0a709a 1475 {
de3b08ac
ILT
1476 current = dynsyms;
1477 max = dynsymcount;
1478 if (max == 0)
1479 return;
1480 printf ("DYNAMIC SYMBOL TABLE:\n");
1481 }
1482 else
1483 {
1484 current = syms;
1485 max = symcount;
1486 if (max == 0)
1487 return;
1488 printf ("SYMBOL TABLE:\n");
1489 }
2fa0b342 1490
de3b08ac
ILT
1491 for (count = 0; count < max; count++)
1492 {
d9971b83 1493 if (*current)
aa0a709a 1494 {
d9971b83
KR
1495 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1496 if (cur_bfd)
1497 {
1498 bfd_print_symbol (cur_bfd,
1499 stdout,
1500 *current, bfd_print_symbol_all);
1501 printf ("\n");
1502 }
aa0a709a
SC
1503 }
1504 current++;
2fa0b342 1505 }
aa0a709a
SC
1506 printf ("\n");
1507 printf ("\n");
2fa0b342
DHW
1508}
1509
d9971b83 1510static void
aa0a709a
SC
1511dump_relocs (abfd)
1512 bfd *abfd;
2fa0b342
DHW
1513{
1514 arelent **relpp;
ae5d2ff5 1515 long relcount;
2fa0b342 1516 asection *a;
aa0a709a
SC
1517
1518 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1519 {
ae5d2ff5
ILT
1520 long relsize;
1521
28d1b01e 1522 if (bfd_is_abs_section (a))
aa0a709a 1523 continue;
28d1b01e 1524 if (bfd_is_und_section (a))
aa0a709a 1525 continue;
d9971b83 1526 if (bfd_is_com_section (a))
aa0a709a
SC
1527 continue;
1528
195d1adf
KR
1529 if (only)
1530 {
1531 if (strcmp (only, a->name))
1532 continue;
1533 }
1534 else if ((a->flags & SEC_RELOC) == 0)
1535 continue;
1536
ae5d2ff5
ILT
1537 relsize = bfd_get_reloc_upper_bound (abfd, a);
1538 if (relsize < 0)
1539 bfd_fatal (bfd_get_filename (abfd));
1540
c5ba2759
ILT
1541 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1542
ae5d2ff5 1543 if (relsize == 0)
aa0a709a
SC
1544 {
1545 printf (" (none)\n\n");
d20f480f 1546 }
aa0a709a
SC
1547 else
1548 {
ae5d2ff5 1549 relpp = (arelent **) xmalloc (relsize);
aa0a709a 1550 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
ae5d2ff5
ILT
1551 if (relcount < 0)
1552 bfd_fatal (bfd_get_filename (abfd));
1553 else if (relcount == 0)
aa0a709a
SC
1554 {
1555 printf (" (none)\n\n");
d20f480f 1556 }
aa0a709a
SC
1557 else
1558 {
1559 printf ("\n");
de3b08ac 1560 dump_reloc_set (abfd, relpp, relcount);
aa0a709a 1561 printf ("\n\n");
d20f480f 1562 }
de3b08ac 1563 free (relpp);
2fa0b342 1564 }
de3b08ac
ILT
1565 }
1566}
2fa0b342 1567
de3b08ac
ILT
1568static void
1569dump_dynamic_relocs (abfd)
1570 bfd *abfd;
1571{
1572 long relsize;
1573 arelent **relpp;
1574 long relcount;
1575
de3b08ac
ILT
1576 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
1577 if (relsize < 0)
1578 bfd_fatal (bfd_get_filename (abfd));
1579
c5ba2759
ILT
1580 printf ("DYNAMIC RELOCATION RECORDS");
1581
de3b08ac
ILT
1582 if (relsize == 0)
1583 {
1584 printf (" (none)\n\n");
1585 }
1586 else
1587 {
1588 relpp = (arelent **) xmalloc (relsize);
1589 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
1590 if (relcount < 0)
1591 bfd_fatal (bfd_get_filename (abfd));
1592 else if (relcount == 0)
1593 {
1594 printf (" (none)\n\n");
1595 }
1596 else
1597 {
1598 printf ("\n");
1599 dump_reloc_set (abfd, relpp, relcount);
1600 printf ("\n\n");
1601 }
1602 free (relpp);
1603 }
1604}
1605
1606static void
1607dump_reloc_set (abfd, relpp, relcount)
1608 bfd *abfd;
1609 arelent **relpp;
1610 long relcount;
1611{
1612 arelent **p;
1613
1614 /* Get column headers lined up reasonably. */
1615 {
1616 static int width;
1617 if (width == 0)
1618 {
1619 char buf[30];
1620 sprintf_vma (buf, (bfd_vma) -1);
1621 width = strlen (buf) - 7;
1622 }
1623 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1624 }
1625
1626 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
1627 {
1628 arelent *q = *p;
1629 CONST char *sym_name;
1630 CONST char *section_name;
1631
aa21a2a9
ILT
1632 if (start_address != (bfd_vma) -1
1633 && q->address < start_address)
1634 continue;
1635 if (stop_address != (bfd_vma) -1
1636 && q->address > stop_address)
1637 continue;
1638
de3b08ac
ILT
1639 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1640 {
1641 sym_name = (*(q->sym_ptr_ptr))->name;
1642 section_name = (*(q->sym_ptr_ptr))->section->name;
1643 }
1644 else
1645 {
1646 sym_name = NULL;
1647 section_name = NULL;
1648 }
1649 if (sym_name)
1650 {
1651 printf_vma (q->address);
1652 printf (" %-16s %s",
1653 q->howto->name,
1654 sym_name);
1655 }
1656 else
1657 {
1658 if (section_name == (CONST char *) NULL)
1659 section_name = "*unknown*";
1660 printf_vma (q->address);
1661 printf (" %-16s [%s]",
1662 q->howto->name,
1663 section_name);
1664 }
1665 if (q->addend)
1666 {
1667 printf ("+0x");
1668 printf_vma (q->addend);
1669 }
1670 printf ("\n");
d20f480f 1671 }
2fa0b342 1672}
f7b839f7 1673\f
f7b839f7
DM
1674/* The length of the longest architecture name + 1. */
1675#define LONGEST_ARCH sizeof("rs6000:6000")
1676
be1d162b
ILT
1677#ifndef L_tmpnam
1678#define L_tmpnam 25
1679#endif
1680
f7b839f7
DM
1681/* List the targets that BFD is configured to support, each followed
1682 by its endianness and the architectures it supports. */
1683
1684static void
1685display_target_list ()
1686{
de04bceb 1687 extern char *tmpnam ();
f7b839f7 1688 extern bfd_target *bfd_target_vector[];
be1d162b 1689 char tmparg[L_tmpnam];
de04bceb 1690 char *dummy_name;
f7b839f7
DM
1691 int t;
1692
be1d162b 1693 dummy_name = tmpnam (tmparg);
f7b839f7
DM
1694 for (t = 0; bfd_target_vector[t]; t++)
1695 {
f7b839f7 1696 bfd_target *p = bfd_target_vector[t];
de04bceb 1697 bfd *abfd = bfd_openw (dummy_name, p->name);
105da05c
ILT
1698 int a;
1699
1700 printf ("%s\n (header %s, data %s)\n", p->name,
1701 p->header_byteorder_big_p ? "big endian" : "little endian",
1702 p->byteorder_big_p ? "big endian" : "little endian");
f7b839f7 1703
334d6e76
SS
1704 if (abfd == NULL)
1705 {
de04bceb 1706 bfd_nonfatal (dummy_name);
105da05c 1707 continue;
334d6e76 1708 }
105da05c
ILT
1709
1710 if (! bfd_set_format (abfd, bfd_object))
1711 {
1712 if (bfd_get_error () != bfd_error_invalid_operation)
1713 bfd_nonfatal (p->name);
1714 continue;
1715 }
1716
f7b839f7
DM
1717 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1718 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
1719 printf (" %s\n",
1720 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
1721 }
de04bceb 1722 unlink (dummy_name);
f7b839f7
DM
1723}
1724
1725/* Print a table showing which architectures are supported for entries
1726 FIRST through LAST-1 of bfd_target_vector (targets across,
1727 architectures down). */
1728
9872a49c 1729static void
abdcac0f
DM
1730display_info_table (first, last)
1731 int first;
1732 int last;
9872a49c 1733{
abdcac0f 1734 extern bfd_target *bfd_target_vector[];
de04bceb 1735 extern char *tmpnam ();
be1d162b 1736 char tmparg[L_tmpnam];
de04bceb
ILT
1737 int t, a;
1738 char *dummy_name;
9872a49c 1739
f7b839f7 1740 /* Print heading of target names. */
ae5d2ff5 1741 printf ("\n%*s", (int) LONGEST_ARCH, " ");
105da05c 1742 for (t = first; t < last && bfd_target_vector[t]; t++)
f7b839f7
DM
1743 printf ("%s ", bfd_target_vector[t]->name);
1744 putchar ('\n');
9872a49c 1745
be1d162b 1746 dummy_name = tmpnam (tmparg);
f7b839f7
DM
1747 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
1748 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
e779a58c 1749 {
ae5d2ff5
ILT
1750 printf ("%*s ", (int) LONGEST_ARCH - 1,
1751 bfd_printable_arch_mach (a, 0));
105da05c 1752 for (t = first; t < last && bfd_target_vector[t]; t++)
aa0a709a 1753 {
f7b839f7 1754 bfd_target *p = bfd_target_vector[t];
105da05c 1755 boolean ok = true;
de04bceb 1756 bfd *abfd = bfd_openw (dummy_name, p->name);
aa0a709a 1757
334d6e76
SS
1758 if (abfd == NULL)
1759 {
105da05c
ILT
1760 bfd_nonfatal (p->name);
1761 ok = false;
1762 }
1763
1764 if (ok)
1765 {
1766 if (! bfd_set_format (abfd, bfd_object))
1767 {
1768 if (bfd_get_error () != bfd_error_invalid_operation)
1769 bfd_nonfatal (p->name);
1770 ok = false;
1771 }
334d6e76 1772 }
105da05c
ILT
1773
1774 if (ok)
1775 {
1776 if (! bfd_set_arch_mach (abfd, a, 0))
1777 ok = false;
1778 }
1779
1780 if (ok)
aa0a709a
SC
1781 printf ("%s ", p->name);
1782 else
e779a58c 1783 {
f7b839f7 1784 int l = strlen (p->name);
aa0a709a 1785 while (l--)
f7b839f7
DM
1786 putchar ('-');
1787 putchar (' ');
e779a58c 1788 }
e779a58c 1789 }
f7b839f7 1790 putchar ('\n');
e779a58c 1791 }
de04bceb 1792 unlink (dummy_name);
9872a49c 1793}
aa0a709a 1794
f7b839f7
DM
1795/* Print tables of all the target-architecture combinations that
1796 BFD has been configured to support. */
1797
aa0a709a 1798static void
f7b839f7 1799display_target_tables ()
aa0a709a 1800{
f7b839f7 1801 int t, columns;
abdcac0f 1802 extern bfd_target *bfd_target_vector[];
f7b839f7 1803 char *colum;
aa0a709a
SC
1804 extern char *getenv ();
1805
aa0a709a 1806 columns = 0;
f7b839f7
DM
1807 colum = getenv ("COLUMNS");
1808 if (colum != NULL)
aa0a709a 1809 columns = atoi (colum);
f7b839f7 1810 if (columns == 0)
aa0a709a 1811 columns = 80;
f7b839f7 1812
105da05c
ILT
1813 t = 0;
1814 while (bfd_target_vector[t] != NULL)
aa0a709a 1815 {
f7b839f7
DM
1816 int oldt = t, wid;
1817
105da05c
ILT
1818 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
1819 ++t;
1820 while (wid < columns && bfd_target_vector[t] != NULL)
1821 {
1822 int newwid;
1823
1824 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
1825 if (newwid >= columns)
1826 break;
1827 wid = newwid;
1828 ++t;
1829 }
f7b839f7 1830 display_info_table (oldt, t);
aa0a709a
SC
1831 }
1832}
1833
f7b839f7
DM
1834static void
1835display_info ()
1836{
1837 printf ("BFD header file version %s\n", BFD_VERSION);
1838 display_target_list ();
1839 display_target_tables ();
1840}
1841
2fa0b342
DHW
1842int
1843main (argc, argv)
1844 int argc;
1845 char **argv;
1846{
1847 int c;
2fa0b342
DHW
1848 char *target = default_target;
1849 boolean seenflag = false;
2fa0b342
DHW
1850
1851 program_name = *argv;
8f197c94
ILT
1852 xmalloc_set_program_name (program_name);
1853
be1d162b
ILT
1854 START_PROGRESS (program_name, 0);
1855
8f197c94 1856 bfd_init ();
2fa0b342 1857
a65619c8 1858 while ((c = getopt_long (argc, argv, "pib:m:VdDlfahrRtTxsSj:w", long_options,
d2442698 1859 (int *) 0))
aa0a709a
SC
1860 != EOF)
1861 {
aa21a2a9
ILT
1862 if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS)
1863 seenflag = true;
aa0a709a
SC
1864 switch (c)
1865 {
b3a2b497
ILT
1866 case 0:
1867 break; /* we've been given a long option */
aa0a709a
SC
1868 case 'm':
1869 machine = optarg;
1870 break;
1871 case 'j':
1872 only = optarg;
1873 break;
1874 case 'l':
1875 with_line_numbers = 1;
1876 break;
1877 case 'b':
1878 target = optarg;
1879 break;
1880 case 'f':
1881 dump_file_header = true;
1882 break;
1883 case 'i':
e1ec9f07 1884 formats_info = true;
aa0a709a 1885 break;
a65619c8
SC
1886 case 'p':
1887 dump_private_headers = 1;
1888 break;
aa0a709a 1889 case 'x':
a65619c8 1890 dump_private_headers = 1;
aa0a709a
SC
1891 dump_symtab = 1;
1892 dump_reloc_info = 1;
1893 dump_file_header = true;
1894 dump_ar_hdrs = 1;
1895 dump_section_headers = 1;
1896 break;
aa0a709a
SC
1897 case 't':
1898 dump_symtab = 1;
1899 break;
de3b08ac
ILT
1900 case 'T':
1901 dump_dynamic_symtab = 1;
1902 break;
aa0a709a
SC
1903 case 'd':
1904 disassemble = true;
1905 break;
d5464baa
ILT
1906 case 'D':
1907 disassemble = disassemble_all = true;
1908 break;
be1d162b
ILT
1909 case 'S':
1910 disassemble = true;
1911 with_source_code = true;
1912 break;
aa0a709a
SC
1913 case 's':
1914 dump_section_contents = 1;
1915 break;
1916 case 'r':
1917 dump_reloc_info = 1;
1918 break;
de3b08ac
ILT
1919 case 'R':
1920 dump_dynamic_reloc_info = 1;
1921 break;
aa0a709a
SC
1922 case 'a':
1923 dump_ar_hdrs = 1;
1924 break;
1925 case 'h':
1926 dump_section_headers = 1;
1927 break;
b3a2b497
ILT
1928 case 'H':
1929 usage (stdout, 0);
249c6fc0
RS
1930 case 'V':
1931 show_version = 1;
1932 break;
13e4db2e
SC
1933 case 'w':
1934 wide_output = 1;
1935 break;
aa21a2a9
ILT
1936 case OPTION_START_ADDRESS:
1937 start_address = parse_vma (optarg, "--start-address");
1938 break;
1939 case OPTION_STOP_ADDRESS:
1940 stop_address = parse_vma (optarg, "--stop-address");
1941 break;
aa0a709a 1942 default:
b3a2b497 1943 usage (stderr, 1);
aa0a709a 1944 }
2fa0b342 1945 }
2fa0b342 1946
249c6fc0 1947 if (show_version)
b3a2b497
ILT
1948 {
1949 printf ("GNU %s version %s\n", program_name, program_version);
1950 exit (0);
1951 }
249c6fc0 1952
2fa0b342 1953 if (seenflag == false)
b3a2b497 1954 usage (stderr, 1);
2fa0b342 1955
e1ec9f07 1956 if (formats_info)
aa0a709a
SC
1957 {
1958 display_info ();
1959 }
1960 else
1961 {
1962 if (optind == argc)
1963 display_file ("a.out", target);
1964 else
1965 for (; optind < argc;)
1966 display_file (argv[optind++], target);
1967 }
be1d162b
ILT
1968
1969 END_PROGRESS (program_name);
1970
2fa0b342
DHW
1971 return 0;
1972}
This page took 0.43973 seconds and 4 git commands to generate.