* format.c (bfd_check_format_matches): Put the new entry in the
[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
ILT
17along with this program; if not, write to the Free Software
18Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
2fa0b342 19
2fa0b342 20#include "bfd.h"
d20f480f 21#include "sysdep.h"
2fa0b342 22#include "getopt.h"
e1ec9f07 23#include "bucomm.h"
2fa0b342
DHW
24#include <stdio.h>
25#include <ctype.h>
2e8adbd7 26#include "dis-asm.h"
2fa0b342 27
73b8f102
JG
28/* Internal headers for the ELF .stab-dump code - sorry. */
29#define BYTES_IN_WORD 32
30#include "aout/aout64.h"
31#include "elf/internal.h"
d086adf8 32extern Elf_Internal_Shdr *bfd_elf_find_section();
bf661056 33
80d19ec1 34#ifndef FPRINTF_ALREADY_DECLARED
6f575704 35extern int fprintf PARAMS ((FILE *, CONST char *, ...));
80d19ec1 36#endif
2fa0b342
DHW
37
38char *default_target = NULL; /* default at runtime */
39
e1ec9f07 40extern char *program_version;
2fa0b342 41
249c6fc0 42int show_version = 0; /* show the version number */
2fa0b342
DHW
43int dump_section_contents; /* -s */
44int dump_section_headers; /* -h */
45boolean dump_file_header; /* -f */
46int dump_symtab; /* -t */
47int dump_reloc_info; /* -r */
48int dump_ar_hdrs; /* -a */
aa0a709a 49int with_line_numbers; /* -l */
9b018ecd 50int dump_stab_section_info; /* --stabs */
aa0a709a 51boolean disassemble; /* -d */
e1ec9f07 52boolean formats_info; /* -i */
195d1adf
KR
53char *only; /* -j secname */
54
55struct objdump_disasm_info {
56 bfd *abfd;
57 asection *sec;
58};
2fa0b342 59
aa0a709a
SC
60char *machine = (char *) NULL;
61asymbol **syms;
2fa0b342 62
2fa0b342
DHW
63unsigned int storage;
64
65unsigned int symcount = 0;
66
d9971b83
KR
67/* Forward declarations. */
68
69static void
70display_file PARAMS ((char *filename, char *target));
71
72static void
73dump_data PARAMS ((bfd *abfd));
74
75static void
76dump_relocs PARAMS ((bfd *abfd));
77
78static void
79dump_symbols PARAMS ((bfd *abfd));
02a68547
ILT
80
81static void
82display_bfd PARAMS ((bfd *abfd));
d9971b83 83\f
2fa0b342 84void
b3a2b497
ILT
85usage (stream, status)
86 FILE *stream;
87 int status;
2fa0b342 88{
b3a2b497 89 fprintf (stream, "\
02a68547
ILT
90Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\
91 [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
92 [--section-headers] [--headers] [--info] [--section=section-name]\n\
93 [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
94 [--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\
95at least one option besides -l (--line-numbers) must be given\n",
b3a2b497
ILT
96 program_name);
97 exit (status);
2fa0b342
DHW
98}
99
aa0a709a
SC
100static struct option long_options[]=
101{
02a68547
ILT
102 {"all-headers", no_argument, NULL, 'x'},
103 {"architecture", required_argument, NULL, 'm'},
104 {"archive-headers", no_argument, NULL, 'a'},
105 {"disassemble", no_argument, NULL, 'd'},
106 {"file-headers", no_argument, NULL, 'f'},
107 {"full-contents", no_argument, NULL, 's'},
108 {"headers", no_argument, NULL, 'h'},
109 {"help", no_argument, NULL, 'H'},
110 {"info", no_argument, NULL, 'i'},
111 {"line-numbers", no_argument, NULL, 'l'},
112 {"reloc", no_argument, NULL, 'r'},
113 {"section", required_argument, NULL, 'j'},
114 {"section-headers", no_argument, NULL, 'h'},
73b8f102 115 {"stabs", no_argument, &dump_stab_section_info, 1},
02a68547
ILT
116 {"syms", no_argument, NULL, 't'},
117 {"target", required_argument, NULL, 'b'},
118 {"version", no_argument, &show_version, 1},
d2442698
DM
119 {0, no_argument, 0, 0}
120};
2fa0b342
DHW
121
122
2fa0b342 123static void
aa0a709a
SC
124dump_headers (abfd)
125 bfd *abfd;
2fa0b342
DHW
126{
127 asection *section;
aa0a709a 128
2fa0b342
DHW
129 for (section = abfd->sections;
130 section != (asection *) NULL;
aa0a709a
SC
131 section = section->next)
132 {
133 char *comma = "";
134
2fa0b342 135#define PF(x,y) \
e779a58c
JG
136 if (section->flags & x) { printf("%s%s",comma,y); comma = ", "; }
137
138
aa0a709a
SC
139 printf ("SECTION %d [%s]\t: size %08x",
140 section->index,
141 section->name,
142 (unsigned) bfd_get_section_size_before_reloc (section));
143 printf (" vma ");
144 printf_vma (section->vma);
145 printf (" align 2**%u\n ",
146 section->alignment_power);
147 PF (SEC_ALLOC, "ALLOC");
148 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
149 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
150 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
151 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
152 PF (SEC_LOAD, "LOAD");
153 PF (SEC_RELOC, "RELOC");
195d1adf 154#ifdef SEC_BALIGN
aa0a709a 155 PF (SEC_BALIGN, "BALIGN");
195d1adf 156#endif
aa0a709a
SC
157 PF (SEC_READONLY, "READONLY");
158 PF (SEC_CODE, "CODE");
159 PF (SEC_DATA, "DATA");
160 PF (SEC_ROM, "ROM");
80d19ec1 161 PF (SEC_DEBUGGING, "DEBUGGING");
aa0a709a 162 printf ("\n");
2fa0b342 163#undef PF
aa0a709a 164 }
2fa0b342
DHW
165}
166
167static asymbol **
abdcac0f
DM
168slurp_symtab (abfd)
169 bfd *abfd;
2fa0b342 170{
aa0a709a 171 asymbol **sy = (asymbol **) NULL;
2fa0b342 172
aa0a709a
SC
173 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
174 {
175 (void) printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
176 return (NULL);
177 }
178
179 storage = get_symtab_upper_bound (abfd);
180 if (storage)
181 {
02a68547 182 sy = (asymbol **) xmalloc (storage);
aa0a709a
SC
183 }
184 symcount = bfd_canonicalize_symtab (abfd, sy);
f50af42b
KR
185 if (symcount <= 0)
186 {
eae82145 187 fprintf (stderr, "%s: %s: Invalid symbol table\n",
f50af42b
KR
188 program_name, bfd_get_filename (abfd));
189 exit (1);
190 }
aa0a709a 191 return sy;
2fa0b342 192}
aa0a709a 193
3ae36cb6
PB
194/* Filter out (in place) symbols that are useless for dis-assemble.
195 Return count of useful symbols. */
196
197int remove_useless_symbols (syms, count)
198 asymbol **syms;
199 int count;
200{
201 register asymbol **in_ptr = syms;
202 register asymbol **out_ptr = syms;
203
204 while ( --count >= 0 )
205 {
206 asymbol *sym = *in_ptr++;
207
208 if (sym->name == NULL || sym->name[0] == '\0')
209 continue;
210 if (sym->flags & (BSF_DEBUGGING))
211 continue;
212 if (sym->section == &bfd_und_section
213 || bfd_is_com_section (sym->section))
214 continue;
215
216 *out_ptr++ = sym;
217 }
218 return out_ptr - syms;
219}
220
221
37853673
SS
222/* Sort symbols into value order. */
223
aa0a709a 224static int
37853673 225compare_symbols (ap, bp)
770cde30
JG
226 PTR ap;
227 PTR bp;
2fa0b342 228{
770cde30
JG
229 asymbol *a = *(asymbol **)ap;
230 asymbol *b = *(asymbol **)bp;
2fa0b342 231
3ae36cb6
PB
232 if (a->value > b->value)
233 return 1;
234 else if (a->value < b->value)
235 return -1;
2fa0b342 236
3ae36cb6
PB
237 if (a->section > b->section)
238 return 1;
239 else if (a->section < b->section)
240 return -1;
241 return 0;
2fa0b342
DHW
242}
243
244/* Print the supplied address symbolically if possible */
245void
545a2768 246objdump_print_address (vma, info)
aa0a709a 247 bfd_vma vma;
545a2768 248 struct disassemble_info *info;
2fa0b342
DHW
249{
250 /* Perform a binary search looking for the closest symbol to
195d1adf
KR
251 the required value. */
252 /* @@ For relocateable files, should filter out symbols belonging to
253 the wrong section. Unfortunately, not enough information is supplied
254 to this routine to determine the correct section in all cases. */
255 /* @@ Would it speed things up to cache the last two symbols returned,
256 and maybe their address ranges? For many processors, only one memory
257 operand can be present at a time, so the 2-entry cache wouldn't be
258 constantly churned by code doing heavy memory accesses. */
2fa0b342
DHW
259
260 unsigned int min = 0;
261 unsigned int max = symcount;
262
263 unsigned int thisplace = 1;
aa0a709a 264 unsigned int oldthisplace;
2fa0b342
DHW
265
266 int vardiff;
2fa0b342 267
3ae36cb6
PB
268 fprintf_vma (info->stream, vma);
269
270 if (symcount > 0)
aa0a709a
SC
271 {
272 while (true)
273 {
3ae36cb6 274 asymbol *sym; asection *sym_sec;
aa0a709a
SC
275 oldthisplace = thisplace;
276 thisplace = (max + min) / 2;
277 if (thisplace == oldthisplace)
278 break;
3ae36cb6
PB
279 sym = syms[thisplace];
280 vardiff = sym->value - vma;
281 sym_sec = sym->section;
282
283 if (vardiff > 0)
284 max = thisplace;
285 else if (vardiff < 0)
286 min = thisplace;
aa0a709a 287 else
3ae36cb6 288 goto found;
aa0a709a
SC
289 }
290 /* We've run out of places to look, print the symbol before this one
291 see if this or the symbol before describes this location the best */
fc5d6074 292
aa0a709a
SC
293 if (thisplace != 0)
294 {
295 if (syms[thisplace - 1]->value - vma >
296 syms[thisplace]->value - vma)
297 {
298 /* Previous symbol is in correct section and is closer */
299 thisplace--;
300 }
301 }
fc5d6074 302
3ae36cb6 303 found:
195d1adf
KR
304 {
305 bfd_vma val = syms[thisplace]->value;
306 int i;
307 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
308 for (i = thisplace - 1; i >= 0; i--)
309 {
310 if (syms[i]->value == val
311 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
312 || ((syms[thisplace]->flags & BSF_DEBUGGING)
313 && !(syms[i]->flags & BSF_DEBUGGING))))
314 {
315 thisplace = i;
316 break;
317 }
318 }
319 if (syms[thisplace]->flags & (BSF_LOCAL|BSF_DEBUGGING))
320 for (i = thisplace + 1; i < symcount; i++)
321 {
322 if (syms[i]->value == val
323 && (!(syms[i]->flags & (BSF_LOCAL|BSF_DEBUGGING))
324 || ((syms[thisplace]->flags & BSF_DEBUGGING)
325 && !(syms[i]->flags & BSF_DEBUGGING))))
326 {
327 thisplace = i;
328 break;
329 }
330 }
331 }
332 {
333 /* If the file is relocateable, and the symbol could be from this
334 section, prefer a symbol from this section over symbols from
335 others, even if the other symbol's value might be closer.
336
337 Note that this may be wrong for some symbol references if the
338 sections have overlapping memory ranges, but in that case there's
339 no way to tell what's desired without looking at the relocation
340 table. */
341 struct objdump_disasm_info *aux;
342 int i;
343
344 aux = (struct objdump_disasm_info *) info->application_data;
345 if (aux->abfd->flags & HAS_RELOC
346 && vma >= bfd_get_section_vma (aux->abfd, aux->sec)
347 && vma < (bfd_get_section_vma (aux->abfd, aux->sec)
348 + bfd_get_section_size_before_reloc (aux->sec))
349 && syms[thisplace]->section != aux->sec)
350 {
351 for (i = thisplace + 1; i < symcount; i++)
352 if (syms[i]->value != syms[thisplace]->value)
353 break;
354 while (--i >= 0)
355 if (syms[i]->section == aux->sec)
356 {
357 thisplace = i;
358 break;
359 }
360 }
361 }
3ae36cb6 362 fprintf (info->stream, " <%s", syms[thisplace]->name);
aa0a709a
SC
363 if (syms[thisplace]->value > vma)
364 {
d086adf8
KR
365 char buf[30], *p = buf;
366 sprintf_vma (buf, syms[thisplace]->value - vma);
367 while (*p == '0')
368 p++;
369 fprintf (info->stream, "-%s", p);
aa0a709a 370 }
3ae36cb6 371 else if (vma > syms[thisplace]->value)
aa0a709a 372 {
d086adf8
KR
373 char buf[30], *p = buf;
374 sprintf_vma (buf, vma - syms[thisplace]->value);
375 while (*p == '0')
376 p++;
377 fprintf (info->stream, "+%s", p);
aa0a709a 378 }
3ae36cb6 379 fprintf (info->stream, ">");
2fa0b342 380 }
2fa0b342
DHW
381}
382
195d1adf
KR
383#ifdef ARCH_all
384#define ARCH_a29k
385#define ARCH_alpha
386#define ARCH_h8300
387#define ARCH_h8500
388#define ARCH_hppa
389#define ARCH_i386
390#define ARCH_i960
391#define ARCH_m68k
392#define ARCH_m88k
393#define ARCH_mips
722087ec 394#define ARCH_rs6000
195d1adf
KR
395#define ARCH_sh
396#define ARCH_sparc
397#define ARCH_z8k
398#endif
399
2fa0b342 400void
aa0a709a
SC
401disassemble_data (abfd)
402 bfd *abfd;
2fa0b342
DHW
403{
404 bfd_byte *data = NULL;
aa0a709a 405 bfd_arch_info_type *info;
fc5d6074
SC
406 bfd_size_type datasize = 0;
407 bfd_size_type i;
2e8adbd7
PB
408 unsigned int (*print) ()= 0; /* Old style */
409 disassembler_ftype disassemble = 0; /* New style */
2fa0b342 410 enum bfd_architecture a;
2e8adbd7 411 struct disassemble_info disasm_info;
195d1adf 412 struct objdump_disasm_info aux;
2e8adbd7
PB
413
414 int prevline;
415 CONST char *prev_function = "";
d20f480f 416
2fa0b342 417 asection *section;
aa0a709a 418
2fa0b342 419 /* Replace symbol section relative values with abs values */
96d7950b 420 boolean done_dot = false;
aa0a709a 421
2e8adbd7 422 INIT_DISASSEMBLE_INFO(disasm_info, stdout);
195d1adf
KR
423 disasm_info.application_data = (PTR) &aux;
424 aux.abfd = abfd;
545a2768 425 disasm_info.print_address_func = objdump_print_address;
2e8adbd7 426
aa0a709a
SC
427 for (i = 0; i < symcount; i++)
428 {
2fa0b342 429 syms[i]->value += syms[i]->section->vma;
aa0a709a 430 }
2fa0b342 431
3ae36cb6 432 symcount = remove_useless_symbols (syms, symcount);
2fa0b342
DHW
433
434 /* Sort the symbols into section and symbol order */
37853673 435 (void) qsort (syms, symcount, sizeof (asymbol *), compare_symbols);
2fa0b342 436
aa0a709a
SC
437 if (machine != (char *) NULL)
438 {
439 info = bfd_scan_arch (machine);
440 if (info == 0)
441 {
442 fprintf (stderr, "%s: Can't use supplied machine %s\n",
443 program_name,
444 machine);
445 exit (1);
446 }
447 abfd->arch_info = info;
2fa0b342 448 }
e779a58c
JG
449
450 /* See if we can disassemble using bfd */
451
aa0a709a
SC
452 if (abfd->arch_info->disassemble)
453 {
454 print = abfd->arch_info->disassemble;
e779a58c 455 }
aa0a709a
SC
456 else
457 {
458 a = bfd_get_arch (abfd);
459 switch (a)
460 {
195d1adf
KR
461 /* If you add a case to this table, also add it to the
462 ARCH_all definition right above this function. */
463#ifdef ARCH_a29k
464 case bfd_arch_a29k:
465 /* As far as I know we only handle big-endian 29k objects. */
466 disassemble = print_insn_big_a29k;
aa0a709a 467 break;
195d1adf
KR
468#endif
469#ifdef ARCH_alpha
470 case bfd_arch_alpha:
471 disassemble = print_insn_alpha;
12da1775 472 break;
195d1adf
KR
473#endif
474#ifdef ARCH_h8300
3ae36cb6
PB
475 case bfd_arch_h8300:
476 if (bfd_get_mach(abfd) == bfd_mach_h8300h)
477 disassemble = print_insn_h8300h;
478 else
479 disassemble = print_insn_h8300;
480 break;
195d1adf
KR
481#endif
482#ifdef ARCH_h8500
483 case bfd_arch_h8500:
484 disassemble = print_insn_h8500;
6f575704 485 break;
195d1adf
KR
486#endif
487#ifdef ARCH_hppa
488 case bfd_arch_hppa:
489 disassemble = print_insn_hppa;
aa0a709a 490 break;
195d1adf
KR
491#endif
492#ifdef ARCH_i386
493 case bfd_arch_i386:
494 disassemble = print_insn_i386;
aa0a709a 495 break;
195d1adf
KR
496#endif
497#ifdef ARCH_i960
aa0a709a 498 case bfd_arch_i960:
545a2768 499 disassemble = print_insn_i960;
aa0a709a 500 break;
195d1adf
KR
501#endif
502#ifdef ARCH_m68k
503 case bfd_arch_m68k:
504 disassemble = print_insn_m68k;
505 break;
506#endif
507#ifdef ARCH_m88k
b3a2b497
ILT
508 case bfd_arch_m88k:
509 disassemble = print_insn_m88k;
510 break;
195d1adf
KR
511#endif
512#ifdef ARCH_mips
d9971b83 513 case bfd_arch_mips:
2e8adbd7
PB
514 if (abfd->xvec->byteorder_big_p)
515 disassemble = print_insn_big_mips;
516 else
517 disassemble = print_insn_little_mips;
d9971b83 518 break;
195d1adf 519#endif
eae82145 520#ifdef ARCH_rs6000
722087ec
ILT
521 case bfd_arch_rs6000:
522 disassemble = print_insn_rs6000;
523 break;
524#endif
195d1adf
KR
525#ifdef ARCH_sh
526 case bfd_arch_sh:
527 disassemble = print_insn_sh;
528 break;
529#endif
530#ifdef ARCH_sparc
531 case bfd_arch_sparc:
532 disassemble = print_insn_sparc;
533 break;
534#endif
535#ifdef ARCH_z8k
536 case bfd_arch_z8k:
537 if (bfd_get_mach(abfd) == bfd_mach_z8001)
538 disassemble = print_insn_z8001;
539 else
540 disassemble = print_insn_z8002;
541 break;
542#endif
aa0a709a
SC
543 default:
544 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
545 program_name,
546 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
547 exit (1);
548 }
2fa0b342 549
aa0a709a 550 }
2fa0b342
DHW
551
552 for (section = abfd->sections;
aa0a709a
SC
553 section != (asection *) NULL;
554 section = section->next)
65cceb78 555 {
195d1adf 556 aux.sec = section;
2fa0b342 557
aa0a709a
SC
558 if ((section->flags & SEC_LOAD)
559 && (only == (char *) NULL || strcmp (only, section->name) == 0))
560 {
561 printf ("Disassembly of section %s:\n", section->name);
2fa0b342 562
aa0a709a
SC
563 if (bfd_get_section_size_before_reloc (section) == 0)
564 continue;
2fa0b342 565
02a68547 566 data = (bfd_byte *) xmalloc ((size_t) bfd_get_section_size_before_reloc (section));
2fa0b342 567
aa0a709a 568 datasize = bfd_get_section_size_before_reloc (section);
2fa0b342 569
aa0a709a 570 bfd_get_section_contents (abfd, section, data, 0, bfd_get_section_size_before_reloc (section));
2fa0b342 571
5d0734a7
JK
572 disasm_info.buffer = data;
573 disasm_info.buffer_vma = section->vma;
574 disasm_info.buffer_length =
575 bfd_get_section_size_before_reloc (section);
aa0a709a 576 i = 0;
5d0734a7 577 while (i < disasm_info.buffer_length)
aa0a709a
SC
578 {
579 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 0 &&
580 data[i + 3] == 0)
581 {
582 if (done_dot == false)
583 {
584 printf ("...\n");
585 done_dot = true;
65cceb78 586 }
aa0a709a 587 i += 4;
65cceb78 588 }
aa0a709a
SC
589 else
590 {
591 done_dot = false;
592 if (with_line_numbers)
593 {
aa0a709a
SC
594 CONST char *filename;
595 CONST char *functionname;
596 unsigned int line;
597
d9971b83
KR
598 if (bfd_find_nearest_line (abfd,
599 section,
600 syms,
601 section->vma + i,
602 &filename,
603 &functionname,
2e8adbd7 604 &line))
aa0a709a 605 {
2e8adbd7
PB
606 if (functionname && *functionname
607 && strcmp(functionname, prev_function))
608 {
609 printf ("%s():\n", functionname);
610 prev_function = functionname;
611 }
612 if (!filename)
613 filename = "???";
614 if (line && line != prevline)
615 {
616 printf ("%s:%u\n", filename, line);
617 prevline = line;
618 }
aa0a709a
SC
619 }
620 }
545a2768 621 objdump_print_address (section->vma + i, &disasm_info);
aa0a709a 622 printf (" ");
65cceb78 623
2e8adbd7 624 if (disassemble) /* New style */
5d0734a7
JK
625 {
626 int bytes = (*disassemble)(section->vma + i,
627 &disasm_info);
628 if (bytes < 0)
629 break;
630 i += bytes;
631 }
2e8adbd7 632 else /* Old style */
d9971b83
KR
633 i += print (section->vma + i,
634 data + i,
635 stdout);
aa0a709a
SC
636 putchar ('\n');
637 }
96d7950b 638 }
aa0a709a 639 free (data);
96d7950b 640 }
2fa0b342 641 }
2fa0b342 642}
73b8f102 643\f
73b8f102
JG
644
645/* Define a table of stab values and print-strings. We wish the initializer
646 could be a direct-mapped table, but instead we build one the first
647 time we need it. */
648
fe2750e1 649char **stab_name;
73b8f102
JG
650
651struct stab_print {
652 int value;
fe2750e1 653 char *string;
73b8f102
JG
654};
655
656struct stab_print stab_print[] = {
657#define __define_stab(NAME, CODE, STRING) {CODE, STRING},
658#include "aout/stab.def"
659#undef __define_stab
02a68547 660 {0, ""}
73b8f102
JG
661};
662
9b018ecd 663void dump_stabs_1 ();
249c6fc0 664
9b018ecd 665/* This dumps the stabs section from object files that have a section that
73b8f102
JG
666 uses Sun stabs encoding. It has to use some hooks into BFD because
667 string table sections are not normally visible to BFD callers. */
668
669void
9b018ecd 670dump_stabs (abfd)
73b8f102
JG
671 bfd *abfd;
672{
249c6fc0 673 int i;
73b8f102 674
fe2750e1
SS
675 /* Allocate and initialize stab name array if first time. */
676 if (stab_name == NULL)
73b8f102 677 {
fe2750e1
SS
678 stab_name = (char **) xmalloc (256 * sizeof(char *));
679 /* Clear the array. */
73b8f102 680 for (i = 0; i < 256; i++)
fe2750e1
SS
681 stab_name[i] = NULL;
682 /* Fill in the defined stabs. */
683 for (i = 0; *stab_print[i].string; i++)
684 stab_name[stab_print[i].value] = stab_print[i].string;
73b8f102
JG
685 }
686
9b018ecd
ILT
687 dump_stabs_1 (abfd, ".stab", ".stabstr");
688 dump_stabs_1 (abfd, ".stab.excl", ".stab.exclstr");
689 dump_stabs_1 (abfd, ".stab.index", ".stab.indexstr");
02a68547 690 dump_stabs_1 (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
249c6fc0
RS
691}
692
693void
9b018ecd 694dump_stabs_1 (abfd, name1, name2)
249c6fc0
RS
695 bfd *abfd;
696 char *name1; /* Section name of .stab */
697 char *name2; /* Section name of its string section */
698{
d086adf8 699 Elf_Internal_Shdr *stab_hdr, *stabstr_hdr;
9b018ecd 700 asection *stabsect, *stabstrsect;
249c6fc0
RS
701 char *strtab;
702 struct internal_nlist *stabs, *stabs_end;
703 int i;
9b018ecd 704 int stab_size, stabstr_size;
249c6fc0 705 unsigned file_string_table_offset, next_file_string_table_offset;
9b018ecd
ILT
706 int is_elf = (0 == strncmp ("elf", abfd->xvec->name, 3));
707
708 if (is_elf)
709 {
710 stab_hdr = bfd_elf_find_section (abfd, name1);
711 }
712 else
713 {
714 stabsect = bfd_get_section_by_name (abfd, name1);
715 }
249c6fc0 716
9b018ecd 717 if (is_elf ? (0 == stab_hdr) : (0 == stabsect))
73b8f102 718 {
9b018ecd 719 printf ("No %s section present.\n\n", name1);
73b8f102
JG
720 return;
721 }
722
9b018ecd
ILT
723 if (is_elf)
724 {
725 stabstr_hdr = bfd_elf_find_section (abfd, name2);
726 }
727 else
728 {
729 stabstrsect = bfd_get_section_by_name (abfd, name2);
730 }
731
732 if (is_elf ? (0 == stabstr_hdr) : (0 == stabstrsect))
73b8f102 733 {
eae82145 734 fprintf (stderr, "%s: %s has no %s section\n", program_name,
249c6fc0 735 abfd->filename, name2);
73b8f102
JG
736 return;
737 }
9b018ecd
ILT
738
739 stab_size = (is_elf ? stab_hdr ->sh_size : bfd_section_size (abfd, stabsect));
740 stabstr_size = (is_elf ? stabstr_hdr->sh_size : bfd_section_size (abfd, stabstrsect));
73b8f102 741
9b018ecd
ILT
742 stabs = (struct internal_nlist *) xmalloc (stab_size);
743 strtab = (char *) xmalloc (stabstr_size);
744 stabs_end = (struct internal_nlist *) (stab_size + (char *) stabs);
73b8f102 745
9b018ecd 746 if (is_elf)
73b8f102 747 {
9b018ecd
ILT
748 if (bfd_seek (abfd, stab_hdr->sh_offset, SEEK_SET) < 0 ||
749 stab_size != bfd_read ((PTR) stabs, stab_size, 1, abfd))
750 {
eae82145 751 fprintf (stderr, "%s: Reading %s section of %s failed\n",
9b018ecd
ILT
752 program_name, name1,
753 abfd->filename);
754 return;
755 }
756 }
757 else
758 {
759 bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size);
73b8f102 760 }
2fa0b342 761
9b018ecd 762 if (is_elf)
73b8f102 763 {
9b018ecd
ILT
764 if (bfd_seek (abfd, stabstr_hdr->sh_offset, SEEK_SET) < 0 ||
765 stabstr_size != bfd_read ((PTR) strtab, stabstr_size, 1, abfd))
766 {
eae82145 767 fprintf (stderr, "%s: Reading %s section of %s failed\n",
9b018ecd
ILT
768 program_name, name2,
769 abfd->filename);
770 return;
771 }
772 }
773 else
774 {
775 bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0, stabstr_size);
73b8f102
JG
776 }
777
778#define SWAP_SYMBOL(symp, abfd) \
779 { \
780 (symp)->n_strx = bfd_h_get_32(abfd, \
781 (unsigned char *)&(symp)->n_strx); \
782 (symp)->n_desc = bfd_h_get_16 (abfd, \
783 (unsigned char *)&(symp)->n_desc); \
784 (symp)->n_value = bfd_h_get_32 (abfd, \
785 (unsigned char *)&(symp)->n_value); \
786 }
787
249c6fc0 788 printf ("Contents of %s section:\n\n", name1);
73b8f102
JG
789 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
790
249c6fc0
RS
791 file_string_table_offset = 0;
792 next_file_string_table_offset = 0;
793
794 /* Loop through all symbols and print them.
795
796 We start the index at -1 because there is a dummy symbol on
e1ec9f07 797 the front of stabs-in-{coff,elf} sections that supplies sizes. */
249c6fc0 798
73b8f102
JG
799 for (i = -1; stabs < stabs_end; stabs++, i++)
800 {
801 SWAP_SYMBOL (stabs, abfd);
fe2750e1
SS
802 printf ("\n%-6d ", i);
803 /* Print either the stab name, or, if unnamed, print its number
804 again (makes consistent formatting for tools like awk). */
805 if (stab_name[stabs->n_type])
806 printf ("%-6s", stab_name[stabs->n_type]);
807 else
808 printf ("%-6d", i);
809 printf (" %-6d %-6d ", stabs->n_other, stabs->n_desc);
02a68547
ILT
810 printf_vma (stabs->n_value);
811 printf (" %-6lu", stabs->n_strx);
249c6fc0
RS
812
813 /* Symbols with type == 0 (N_UNDF) specify the length of the
814 string table associated with this file. We use that info
815 to know how to relocate the *next* file's string table indices. */
816
817 if (stabs->n_type == N_UNDF)
818 {
819 file_string_table_offset = next_file_string_table_offset;
820 next_file_string_table_offset += stabs->n_value;
821 }
249c6fc0 822 else
e1ec9f07
SS
823 {
824 /* Now, using the possibly updated string table offset, print the
825 string (if any) associated with this symbol. */
826
827 if ((stabs->n_strx + file_string_table_offset) < stabstr_size)
828 printf (" %s", &strtab[stabs->n_strx + file_string_table_offset]);
829 else
830 printf (" *");
831 }
73b8f102
JG
832 }
833 printf ("\n\n");
834}
249c6fc0 835
eae82145 836static void
209e5610
DM
837list_matching_formats(p)
838 char **p;
eae82145 839{
eae82145
DM
840 fprintf(stderr, "%s: Matching formats:", program_name);
841 while (*p)
842 fprintf(stderr, " %s", *p++);
843 fprintf(stderr, "\n");
844}
845
02a68547 846static void
2fa0b342
DHW
847display_bfd (abfd)
848 bfd *abfd;
849{
209e5610
DM
850 char **matching;
851
852 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
aa0a709a 853 {
eae82145 854 fprintf (stderr, "%s: %s: %s\n", program_name, abfd->filename,
b3a2b497 855 bfd_errmsg (bfd_error));
eae82145 856 if (bfd_error == file_ambiguously_recognized)
209e5610
DM
857 {
858 list_matching_formats (matching);
859 free (matching);
860 }
aa0a709a
SC
861 return;
862 }
2fa0b342 863 printf ("\n%s: file format %s\n", abfd->filename, abfd->xvec->name);
aa0a709a
SC
864 if (dump_ar_hdrs)
865 print_arelt_descr (stdout, abfd, true);
2fa0b342 866
aa0a709a
SC
867 if (dump_file_header)
868 {
869 char *comma = "";
870
871 printf ("architecture: %s, ",
872 bfd_printable_arch_mach (bfd_get_arch (abfd),
873 bfd_get_mach (abfd)));
874 printf ("flags 0x%08x:\n", abfd->flags);
2fa0b342 875
2fa0b342 876#define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
aa0a709a
SC
877 PF (HAS_RELOC, "HAS_RELOC");
878 PF (EXEC_P, "EXEC_P");
879 PF (HAS_LINENO, "HAS_LINENO");
880 PF (HAS_DEBUG, "HAS_DEBUG");
881 PF (HAS_SYMS, "HAS_SYMS");
882 PF (HAS_LOCALS, "HAS_LOCALS");
883 PF (DYNAMIC, "DYNAMIC");
884 PF (WP_TEXT, "WP_TEXT");
885 PF (D_PAGED, "D_PAGED");
249c6fc0 886 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
aa0a709a
SC
887 printf ("\nstart address 0x");
888 printf_vma (abfd->start_address);
889 }
890 printf ("\n");
2fa0b342
DHW
891
892 if (dump_section_headers)
aa0a709a
SC
893 dump_headers (abfd);
894 if (dump_symtab || dump_reloc_info || disassemble)
895 {
896 syms = slurp_symtab (abfd);
897 }
898 if (dump_symtab)
899 dump_symbols (abfd);
73b8f102 900 if (dump_stab_section_info)
9b018ecd 901 dump_stabs (abfd);
aa0a709a
SC
902 if (dump_reloc_info)
903 dump_relocs (abfd);
904 if (dump_section_contents)
905 dump_data (abfd);
3ae36cb6
PB
906 /* Note that disassemble_data re-orders the syms table, but that is
907 safe - as long as it is done last! */
aa0a709a
SC
908 if (disassemble)
909 disassemble_data (abfd);
2fa0b342
DHW
910}
911
d9971b83 912static void
2fa0b342
DHW
913display_file (filename, target)
914 char *filename;
915 char *target;
916{
917 bfd *file, *arfile = (bfd *) NULL;
918
919 file = bfd_openr (filename, target);
aa0a709a
SC
920 if (file == NULL)
921 {
d2442698 922 fprintf (stderr, "%s: ", program_name);
aa0a709a
SC
923 bfd_perror (filename);
924 return;
925 }
2fa0b342 926
aa0a709a
SC
927 if (bfd_check_format (file, bfd_archive) == true)
928 {
929 printf ("In archive %s:\n", bfd_get_filename (file));
930 for (;;)
931 {
932 bfd_error = no_error;
933
934 arfile = bfd_openr_next_archived_file (file, arfile);
935 if (arfile == NULL)
936 {
937 if (bfd_error != no_more_archived_files)
d2442698
DM
938 {
939 fprintf (stderr, "%s: ", program_name);
940 bfd_perror (bfd_get_filename (file));
941 }
aa0a709a
SC
942 return;
943 }
2fa0b342 944
aa0a709a
SC
945 display_bfd (arfile);
946 /* Don't close the archive elements; we need them for next_archive */
947 }
2fa0b342 948 }
2fa0b342 949 else
aa0a709a 950 display_bfd (file);
2fa0b342 951
aa0a709a 952 bfd_close (file);
2fa0b342
DHW
953}
954\f
955/* Actually display the various requested regions */
956
d9971b83 957static void
2fa0b342
DHW
958dump_data (abfd)
959 bfd *abfd;
960{
961 asection *section;
aa0a709a 962 bfd_byte *data = 0;
fc5d6074
SC
963 bfd_size_type datasize = 0;
964 bfd_size_type i;
2fa0b342
DHW
965
966 for (section = abfd->sections; section != NULL; section =
aa0a709a
SC
967 section->next)
968 {
969 int onaline = 16;
2fa0b342 970
aa0a709a
SC
971 if (only == (char *) NULL ||
972 strcmp (only, section->name) == 0)
60c80016 973 {
aa0a709a
SC
974 if (section->flags & SEC_HAS_CONTENTS)
975 {
976 printf ("Contents of section %s:\n", section->name);
977
9b018ecd 978 if (bfd_section_size (abfd, section) == 0)
aa0a709a 979 continue;
02a68547 980 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
9b018ecd 981 datasize = bfd_section_size (abfd, section);
2fa0b342 982
2fa0b342 983
9b018ecd 984 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
2fa0b342 985
9b018ecd 986 for (i = 0; i < bfd_section_size (abfd, section); i += onaline)
aa0a709a
SC
987 {
988 bfd_size_type j;
989
990 printf (" %04lx ", (unsigned long int) (i + section->vma));
991 for (j = i; j < i + onaline; j++)
992 {
9b018ecd 993 if (j < bfd_section_size (abfd, section))
aa0a709a
SC
994 printf ("%02x", (unsigned) (data[j]));
995 else
996 printf (" ");
997 if ((j & 3) == 3)
998 printf (" ");
999 }
2fa0b342 1000
aa0a709a
SC
1001 printf (" ");
1002 for (j = i; j < i + onaline; j++)
1003 {
9b018ecd 1004 if (j >= bfd_section_size (abfd, section))
aa0a709a
SC
1005 printf (" ");
1006 else
1007 printf ("%c", isprint (data[j]) ? data[j] : '.');
1008 }
1009 putchar ('\n');
1010 }
d9971b83 1011 free (data);
60c80016 1012 }
2fa0b342 1013 }
2fa0b342 1014 }
2fa0b342
DHW
1015}
1016
2fa0b342 1017/* Should perhaps share code and display with nm? */
d9971b83 1018static void
2fa0b342
DHW
1019dump_symbols (abfd)
1020 bfd *abfd;
1021{
1022
1023 unsigned int count;
1024 asymbol **current = syms;
2fa0b342 1025
aa0a709a 1026 printf ("SYMBOL TABLE:\n");
e779a58c 1027
aa0a709a
SC
1028 for (count = 0; count < symcount; count++)
1029 {
2fa0b342 1030
d9971b83 1031 if (*current)
aa0a709a 1032 {
d9971b83
KR
1033 bfd *cur_bfd = bfd_asymbol_bfd(*current);
1034 if (cur_bfd)
1035 {
1036 bfd_print_symbol (cur_bfd,
1037 stdout,
1038 *current, bfd_print_symbol_all);
1039 printf ("\n");
1040 }
aa0a709a
SC
1041
1042 }
1043 current++;
2fa0b342 1044 }
aa0a709a
SC
1045 printf ("\n");
1046 printf ("\n");
2fa0b342
DHW
1047}
1048
d9971b83 1049static void
aa0a709a
SC
1050dump_relocs (abfd)
1051 bfd *abfd;
2fa0b342
DHW
1052{
1053 arelent **relpp;
1054 unsigned int relcount;
1055 asection *a;
aa0a709a
SC
1056
1057 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
1058 {
1059 if (a == &bfd_abs_section)
1060 continue;
1061 if (a == &bfd_und_section)
1062 continue;
d9971b83 1063 if (bfd_is_com_section (a))
aa0a709a
SC
1064 continue;
1065
195d1adf
KR
1066 if (only)
1067 {
1068 if (strcmp (only, a->name))
1069 continue;
1070 }
1071 else if ((a->flags & SEC_RELOC) == 0)
1072 continue;
1073
aa0a709a
SC
1074 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
1075
1076 if (bfd_get_reloc_upper_bound (abfd, a) == 0)
1077 {
1078 printf (" (none)\n\n");
d20f480f 1079 }
aa0a709a
SC
1080 else
1081 {
d20f480f
SC
1082 arelent **p;
1083
aa0a709a 1084 relpp = (arelent **) xmalloc (bfd_get_reloc_upper_bound (abfd, a));
3ae36cb6 1085 /* Note that this must be done *before* we sort the syms table. */
aa0a709a
SC
1086 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
1087 if (relcount == 0)
1088 {
1089 printf (" (none)\n\n");
d20f480f 1090 }
aa0a709a
SC
1091 else
1092 {
1093 printf ("\n");
195d1adf
KR
1094 /* Get column headers lined up reasonably. */
1095 {
1096 static int width;
1097 if (width == 0)
1098 {
1099 char buf[30];
1100 sprintf_vma (buf, (bfd_vma) -1);
1101 width = strlen (buf) - 7;
1102 }
1103 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
1104 }
d20f480f 1105
aa0a709a
SC
1106 for (p = relpp; relcount && *p != (arelent *) NULL; p++,
1107 relcount--)
1108 {
d20f480f
SC
1109 arelent *q = *p;
1110 CONST char *sym_name;
02a68547 1111 CONST char *section_name;
aa0a709a
SC
1112
1113 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
1114 {
1115 sym_name = (*(q->sym_ptr_ptr))->name;
02a68547 1116 section_name = (*(q->sym_ptr_ptr))->section->name;
d20f480f 1117 }
aa0a709a
SC
1118 else
1119 {
02a68547
ILT
1120 sym_name = NULL;
1121 section_name = NULL;
d20f480f 1122 }
aa0a709a
SC
1123 if (sym_name)
1124 {
1125 printf_vma (q->address);
195d1adf 1126 printf (" %-16s %s",
aa0a709a
SC
1127 q->howto->name,
1128 sym_name);
d20f480f 1129 }
aa0a709a
SC
1130 else
1131 {
02a68547
ILT
1132 if (section_name == (CONST char *) NULL)
1133 section_name = "*unknown*";
aa0a709a 1134 printf_vma (q->address);
195d1adf 1135 printf (" %-16s [%s]",
aa0a709a
SC
1136 q->howto->name,
1137 section_name);
d20f480f 1138 }
aa0a709a
SC
1139 if (q->addend)
1140 {
1141 printf ("+0x");
1142 printf_vma (q->addend);
d20f480f 1143 }
aa0a709a 1144 printf ("\n");
d20f480f 1145 }
aa0a709a
SC
1146 printf ("\n\n");
1147 free (relpp);
d20f480f 1148 }
2fa0b342 1149 }
2fa0b342 1150
d20f480f 1151 }
2fa0b342
DHW
1152}
1153
aa0a709a
SC
1154#ifdef unix
1155#define _DUMMY_NAME_ "/dev/null"
1156#else
1157#define _DUMMY_NAME_ "##dummy"
1158#endif
9872a49c 1159static void
abdcac0f
DM
1160display_info_table (first, last)
1161 int first;
1162 int last;
9872a49c 1163{
3fdbfe8d 1164 unsigned int i, j;
abdcac0f 1165 extern bfd_target *bfd_target_vector[];
9872a49c 1166
aa0a709a 1167 printf ("\n%12s", " ");
abdcac0f
DM
1168 for (i = first; i++ < last && bfd_target_vector[i];)
1169 printf ("%s ", bfd_target_vector[i]->name);
aa0a709a 1170 printf ("\n");
9872a49c 1171
aa0a709a
SC
1172 for (j = (int) bfd_arch_obscure + 1; (int) j < (int) bfd_arch_last; j++)
1173 if (strcmp (bfd_printable_arch_mach (j, 0), "UNKNOWN!") != 0)
e779a58c 1174 {
aa0a709a 1175 printf ("%11s ", bfd_printable_arch_mach (j, 0));
abdcac0f 1176 for (i = first; i++ < last && bfd_target_vector[i];)
aa0a709a 1177 {
abdcac0f 1178 bfd_target *p = bfd_target_vector[i];
aa0a709a
SC
1179 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
1180 int l = strlen (p->name);
249c6fc0
RS
1181 int ok;
1182 bfd_set_format (abfd, bfd_object);
1183 ok = bfd_set_arch_mach (abfd, j, 0);
aa0a709a
SC
1184
1185 if (ok)
1186 printf ("%s ", p->name);
1187 else
e779a58c 1188 {
aa0a709a
SC
1189 while (l--)
1190 printf ("%c", ok ? '*' : '-');
1191 printf (" ");
e779a58c 1192 }
e779a58c 1193 }
aa0a709a 1194 printf ("\n");
e779a58c 1195 }
9872a49c 1196}
aa0a709a
SC
1197
1198static void
abdcac0f 1199display_info ()
aa0a709a
SC
1200{
1201 char *colum;
1202 unsigned int i, j, columns;
abdcac0f 1203 extern bfd_target *bfd_target_vector[];
aa0a709a
SC
1204 extern char *getenv ();
1205
1206 printf ("BFD header file version %s\n", BFD_VERSION);
abdcac0f 1207 for (i = 0; bfd_target_vector[i]; i++)
aa0a709a 1208 {
abdcac0f 1209 bfd_target *p = bfd_target_vector[i];
aa0a709a 1210 bfd *abfd = bfd_openw (_DUMMY_NAME_, p->name);
249c6fc0 1211 bfd_set_format (abfd, bfd_object);
aa0a709a
SC
1212 printf ("%s\n (header %s, data %s)\n", p->name,
1213 p->header_byteorder_big_p ? "big endian" : "little endian",
1214 p->byteorder_big_p ? "big endian" : "little endian");
1215 for (j = (int) bfd_arch_obscure + 1; j < (int) bfd_arch_last; j++)
1216 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) j, 0))
1217 printf (" %s\n",
1218 bfd_printable_arch_mach ((enum bfd_architecture) j, 0));
1219 }
1220 columns = 0;
02a68547 1221 if ((colum = getenv ("COLUMNS")) != (char *) NULL)
aa0a709a
SC
1222 columns = atoi (colum);
1223 if (!columns)
1224 columns = 80;
abdcac0f 1225 for (i = 0; bfd_target_vector[i];)
aa0a709a
SC
1226 {
1227 int old;
1228 old = i;
abdcac0f
DM
1229 for (j = 12; bfd_target_vector[i] && j < columns; i++)
1230 j += strlen (bfd_target_vector[i]->name) + 1;
aa0a709a
SC
1231 i--;
1232 if (old == i)
1233 break;
1234 display_info_table (old, i);
1235 }
1236}
1237
2fa0b342
DHW
1238/** main and like trivia */
1239int
1240main (argc, argv)
1241 int argc;
1242 char **argv;
1243{
1244 int c;
2fa0b342
DHW
1245 char *target = default_target;
1246 boolean seenflag = false;
2fa0b342 1247
aa0a709a 1248 bfd_init ();
2fa0b342
DHW
1249 program_name = *argv;
1250
d2442698
DM
1251 while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options,
1252 (int *) 0))
aa0a709a
SC
1253 != EOF)
1254 {
1255 seenflag = true;
1256 switch (c)
1257 {
b3a2b497
ILT
1258 case 0:
1259 break; /* we've been given a long option */
aa0a709a
SC
1260 case 'm':
1261 machine = optarg;
1262 break;
1263 case 'j':
1264 only = optarg;
1265 break;
1266 case 'l':
1267 with_line_numbers = 1;
1268 break;
1269 case 'b':
1270 target = optarg;
1271 break;
1272 case 'f':
1273 dump_file_header = true;
1274 break;
1275 case 'i':
e1ec9f07 1276 formats_info = true;
aa0a709a
SC
1277 break;
1278 case 'x':
1279 dump_symtab = 1;
1280 dump_reloc_info = 1;
1281 dump_file_header = true;
1282 dump_ar_hdrs = 1;
1283 dump_section_headers = 1;
1284 break;
aa0a709a
SC
1285 case 't':
1286 dump_symtab = 1;
1287 break;
1288 case 'd':
1289 disassemble = true;
1290 break;
1291 case 's':
1292 dump_section_contents = 1;
1293 break;
1294 case 'r':
1295 dump_reloc_info = 1;
1296 break;
1297 case 'a':
1298 dump_ar_hdrs = 1;
1299 break;
1300 case 'h':
1301 dump_section_headers = 1;
1302 break;
b3a2b497
ILT
1303 case 'H':
1304 usage (stdout, 0);
249c6fc0
RS
1305 case 'V':
1306 show_version = 1;
1307 break;
aa0a709a 1308 default:
b3a2b497 1309 usage (stderr, 1);
aa0a709a 1310 }
2fa0b342 1311 }
2fa0b342 1312
249c6fc0 1313 if (show_version)
b3a2b497
ILT
1314 {
1315 printf ("GNU %s version %s\n", program_name, program_version);
1316 exit (0);
1317 }
249c6fc0 1318
2fa0b342 1319 if (seenflag == false)
b3a2b497 1320 usage (stderr, 1);
2fa0b342 1321
e1ec9f07 1322 if (formats_info)
aa0a709a
SC
1323 {
1324 display_info ();
1325 }
1326 else
1327 {
1328 if (optind == argc)
1329 display_file ("a.out", target);
1330 else
1331 for (; optind < argc;)
1332 display_file (argv[optind++], target);
1333 }
2fa0b342
DHW
1334 return 0;
1335}
This page took 0.159635 seconds and 4 git commands to generate.