1 /* objdump.c -- dump information about an object file.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "libiberty.h"
31 #ifdef ANSI_PROTOTYPES
37 /* Internal headers for the ELF .stab-dump code - sorry. */
38 #define BYTES_IN_WORD 32
39 #include "aout/aout64.h"
41 #ifdef NEED_DECLARATION_FPRINTF
42 /* This is needed by INIT_DISASSEMBLE_INFO. */
43 extern int fprintf PARAMS ((FILE *, const char *, ...));
46 static char *default_target = NULL; /* default at runtime */
48 static int show_version = 0; /* show the version number */
49 static int dump_section_contents; /* -s */
50 static int dump_section_headers; /* -h */
51 static boolean dump_file_header; /* -f */
52 static int dump_symtab; /* -t */
53 static int dump_dynamic_symtab; /* -T */
54 static int dump_reloc_info; /* -r */
55 static int dump_dynamic_reloc_info; /* -R */
56 static int dump_ar_hdrs; /* -a */
57 static int dump_private_headers; /* -p */
58 static int prefix_addresses; /* --prefix-addresses */
59 static int with_line_numbers; /* -l */
60 static boolean with_source_code; /* -S */
61 static int show_raw_insn; /* --show-raw-insn */
62 static int dump_stab_section_info; /* --stabs */
63 static int do_demangle; /* -C, --demangle */
64 static boolean disassemble; /* -d */
65 static boolean disassemble_all; /* -D */
66 static int disassemble_zeroes; /* --disassemble-zeroes */
67 static boolean formats_info; /* -i */
68 static char *only; /* -j secname */
69 static int wide_output; /* -w */
70 static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
71 static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
72 static int dump_debugging; /* --debugging */
73 static bfd_vma adjust_section_vma = 0; /* --adjust-vma */
75 /* Extra info to pass to the disassembler address printing function. */
76 struct objdump_disasm_info {
82 /* Architecture to disassemble for, or default if NULL. */
83 static char *machine = (char *) NULL;
85 /* Endianness to disassemble for, or default if BFD_ENDIAN_UNKNOWN. */
86 static enum bfd_endian endian = BFD_ENDIAN_UNKNOWN;
88 /* The symbol table. */
89 static asymbol **syms;
91 /* Number of symbols in `syms'. */
92 static long symcount = 0;
94 /* The sorted symbol table. */
95 static asymbol **sorted_syms;
97 /* Number of symbols in `sorted_syms'. */
98 static long sorted_symcount = 0;
100 /* The dynamic symbol table. */
101 static asymbol **dynsyms;
103 /* Number of symbols in `dynsyms'. */
104 static long dynsymcount = 0;
106 /* Forward declarations. */
109 display_file PARAMS ((char *filename, char *target));
112 dump_data PARAMS ((bfd *abfd));
115 dump_relocs PARAMS ((bfd *abfd));
118 dump_dynamic_relocs PARAMS ((bfd * abfd));
121 dump_reloc_set PARAMS ((bfd *, asection *, arelent **, long));
124 dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
127 display_bfd PARAMS ((bfd *abfd));
130 objdump_print_value PARAMS ((bfd_vma, struct disassemble_info *, boolean));
133 objdump_print_symname PARAMS ((bfd *, struct disassemble_info *, asymbol *));
136 find_symbol_for_address PARAMS ((bfd *, asection *, bfd_vma, boolean, long *));
139 objdump_print_addr_with_sym PARAMS ((bfd *, asection *, asymbol *, bfd_vma,
140 struct disassemble_info *, boolean));
143 objdump_print_addr PARAMS ((bfd_vma, struct disassemble_info *, boolean));
146 objdump_print_address PARAMS ((bfd_vma, struct disassemble_info *));
149 show_line PARAMS ((bfd *, asection *, bfd_vma));
152 disassemble_bytes PARAMS ((struct disassemble_info *, disassembler_ftype,
153 boolean, bfd_byte *, long, long, arelent ***,
157 disassemble_data PARAMS ((bfd *));
160 endian_string PARAMS ((enum bfd_endian));
163 usage (stream, status)
168 Usage: %s [-ahifCdDprRtTxsSlw] [-b bfdname] [-m machine] [-j section-name]\n\
169 [--archive-headers] [--target=bfdname] [--debugging] [--disassemble]\n\
170 [--disassemble-all] [--disassemble-zeroes] [--file-headers]\n\
171 [--section-headers] [--headers]\n\
172 [--info] [--section=section-name] [--line-numbers] [--source]\n",
175 [--architecture=machine] [--reloc] [--full-contents] [--stabs]\n\
176 [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
177 [--wide] [--version] [--help] [--private-headers]\n\
178 [--start-address=addr] [--stop-address=addr]\n\
179 [--prefix-addresses] [--[no-]show-raw-insn] [--demangle]\n\
180 [--adjust-vma=offset] [-EB|-EL] [--endian={big|little}] objfile...\n\
181 at least one option besides -l (--line-numbers) must be given\n");
182 list_supported_targets (program_name, stream);
188 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
190 #define OPTION_ENDIAN (150)
191 #define OPTION_START_ADDRESS (OPTION_ENDIAN + 1)
192 #define OPTION_STOP_ADDRESS (OPTION_START_ADDRESS + 1)
193 #define OPTION_ADJUST_VMA (OPTION_STOP_ADDRESS + 1)
195 static struct option long_options[]=
197 {"adjust-vma", required_argument, NULL, OPTION_ADJUST_VMA},
198 {"all-headers", no_argument, NULL, 'x'},
199 {"private-headers", no_argument, NULL, 'p'},
200 {"architecture", required_argument, NULL, 'm'},
201 {"archive-headers", no_argument, NULL, 'a'},
202 {"debugging", no_argument, &dump_debugging, 1},
203 {"demangle", no_argument, &do_demangle, 1},
204 {"disassemble", no_argument, NULL, 'd'},
205 {"disassemble-all", no_argument, NULL, 'D'},
206 {"disassemble-zeroes", no_argument, &disassemble_zeroes, 1},
207 {"dynamic-reloc", no_argument, NULL, 'R'},
208 {"dynamic-syms", no_argument, NULL, 'T'},
209 {"endian", required_argument, NULL, OPTION_ENDIAN},
210 {"file-headers", no_argument, NULL, 'f'},
211 {"full-contents", no_argument, NULL, 's'},
212 {"headers", no_argument, NULL, 'h'},
213 {"help", no_argument, NULL, 'H'},
214 {"info", no_argument, NULL, 'i'},
215 {"line-numbers", no_argument, NULL, 'l'},
216 {"no-show-raw-insn", no_argument, &show_raw_insn, -1},
217 {"prefix-addresses", no_argument, &prefix_addresses, 1},
218 {"reloc", no_argument, NULL, 'r'},
219 {"section", required_argument, NULL, 'j'},
220 {"section-headers", no_argument, NULL, 'h'},
221 {"show-raw-insn", no_argument, &show_raw_insn, 1},
222 {"source", no_argument, NULL, 'S'},
223 {"stabs", no_argument, &dump_stab_section_info, 1},
224 {"start-address", required_argument, NULL, OPTION_START_ADDRESS},
225 {"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
226 {"syms", no_argument, NULL, 't'},
227 {"target", required_argument, NULL, 'b'},
228 {"version", no_argument, &show_version, 1},
229 {"wide", no_argument, &wide_output, 'w'},
230 {0, no_argument, 0, 0}
234 dump_section_header (abfd, section, ignored)
241 printf ("%3d %-13s %08lx ", section->index,
242 bfd_get_section_name (abfd, section),
243 (unsigned long) bfd_section_size (abfd, section));
244 printf_vma (bfd_get_section_vma (abfd, section));
246 printf_vma (section->lma);
247 printf (" %08lx 2**%u", section->filepos,
248 bfd_get_section_alignment (abfd, section));
254 if (section->flags & x) { printf ("%s%s", comma, y); comma = ", "; }
256 PF (SEC_HAS_CONTENTS, "CONTENTS");
257 PF (SEC_ALLOC, "ALLOC");
258 PF (SEC_CONSTRUCTOR, "CONSTRUCTOR");
259 PF (SEC_CONSTRUCTOR_TEXT, "CONSTRUCTOR TEXT");
260 PF (SEC_CONSTRUCTOR_DATA, "CONSTRUCTOR DATA");
261 PF (SEC_CONSTRUCTOR_BSS, "CONSTRUCTOR BSS");
262 PF (SEC_LOAD, "LOAD");
263 PF (SEC_RELOC, "RELOC");
265 PF (SEC_BALIGN, "BALIGN");
267 PF (SEC_READONLY, "READONLY");
268 PF (SEC_CODE, "CODE");
269 PF (SEC_DATA, "DATA");
271 PF (SEC_DEBUGGING, "DEBUGGING");
272 PF (SEC_NEVER_LOAD, "NEVER_LOAD");
273 PF (SEC_EXCLUDE, "EXCLUDE");
274 PF (SEC_SORT_ENTRIES, "SORT_ENTRIES");
276 if ((section->flags & SEC_LINK_ONCE) != 0)
280 switch (section->flags & SEC_LINK_DUPLICATES)
284 case SEC_LINK_DUPLICATES_DISCARD:
285 ls = "LINK_ONCE_DISCARD";
287 case SEC_LINK_DUPLICATES_ONE_ONLY:
288 ls = "LINK_ONCE_ONE_ONLY";
290 case SEC_LINK_DUPLICATES_SAME_SIZE:
291 ls = "LINK_ONCE_SAME_SIZE";
293 case SEC_LINK_DUPLICATES_SAME_CONTENTS:
294 ls = "LINK_ONCE_SAME_CONTENTS";
297 printf ("%s%s", comma, ls);
309 printf ("Sections:\n");
311 printf ("Idx Name Size VMA LMA File off Algn\n");
313 printf ("Idx Name Size VMA LMA File off Algn\n");
315 bfd_map_over_sections (abfd, dump_section_header, (PTR) NULL);
322 asymbol **sy = (asymbol **) NULL;
325 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
327 printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
332 storage = bfd_get_symtab_upper_bound (abfd);
334 bfd_fatal (bfd_get_filename (abfd));
338 sy = (asymbol **) xmalloc (storage);
340 symcount = bfd_canonicalize_symtab (abfd, sy);
342 bfd_fatal (bfd_get_filename (abfd));
344 fprintf (stderr, "%s: %s: No symbols\n",
345 program_name, bfd_get_filename (abfd));
349 /* Read in the dynamic symbols. */
352 slurp_dynamic_symtab (abfd)
355 asymbol **sy = (asymbol **) NULL;
358 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
361 if (!(bfd_get_file_flags (abfd) & DYNAMIC))
363 fprintf (stderr, "%s: %s: not a dynamic object\n",
364 program_name, bfd_get_filename (abfd));
369 bfd_fatal (bfd_get_filename (abfd));
374 sy = (asymbol **) xmalloc (storage);
376 dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
378 bfd_fatal (bfd_get_filename (abfd));
379 if (dynsymcount == 0)
380 fprintf (stderr, "%s: %s: No dynamic symbols\n",
381 program_name, bfd_get_filename (abfd));
385 /* Filter out (in place) symbols that are useless for disassembly.
386 COUNT is the number of elements in SYMBOLS.
387 Return the number of useful symbols. */
390 remove_useless_symbols (symbols, count)
394 register asymbol **in_ptr = symbols, **out_ptr = symbols;
398 asymbol *sym = *in_ptr++;
400 if (sym->name == NULL || sym->name[0] == '\0')
402 if (sym->flags & (BSF_DEBUGGING))
404 if (bfd_is_und_section (sym->section)
405 || bfd_is_com_section (sym->section))
410 return out_ptr - symbols;
413 /* Sort symbols into value order. */
416 compare_symbols (ap, bp)
420 const asymbol *a = *(const asymbol **)ap;
421 const asymbol *b = *(const asymbol **)bp;
425 flagword aflags, bflags;
427 if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
429 else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
432 if (a->section > b->section)
434 else if (a->section < b->section)
437 an = bfd_asymbol_name (a);
438 bn = bfd_asymbol_name (b);
442 /* The symbols gnu_compiled and gcc2_compiled convey no real
443 information, so put them after other symbols with the same value. */
445 af = (strstr (an, "gnu_compiled") != NULL
446 || strstr (an, "gcc2_compiled") != NULL);
447 bf = (strstr (bn, "gnu_compiled") != NULL
448 || strstr (bn, "gcc2_compiled") != NULL);
455 /* We use a heuristic for the file name, to try to sort it after
456 more useful symbols. It may not work on non Unix systems, but it
457 doesn't really matter; the only difference is precisely which
458 symbol names get printed. */
460 #define file_symbol(s, sn, snl) \
461 (((s)->flags & BSF_FILE) != 0 \
462 || ((sn)[(snl) - 2] == '.' \
463 && ((sn)[(snl) - 1] == 'o' \
464 || (sn)[(snl) - 1] == 'a')))
466 af = file_symbol (a, an, anl);
467 bf = file_symbol (b, bn, bnl);
474 /* Try to sort global symbols before local symbols before function
475 symbols before debugging symbols. */
480 if ((aflags & BSF_DEBUGGING) != (bflags & BSF_DEBUGGING))
482 if ((aflags & BSF_DEBUGGING) != 0)
487 if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
489 if ((aflags & BSF_FUNCTION) != 0)
494 if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
496 if ((aflags & BSF_LOCAL) != 0)
501 if ((aflags & BSF_GLOBAL) != (bflags & BSF_GLOBAL))
503 if ((aflags & BSF_GLOBAL) != 0)
509 /* Symbols that start with '.' might be section names, so sort them
510 after symbols that don't start with '.'. */
511 if (an[0] == '.' && bn[0] != '.')
513 if (an[0] != '.' && bn[0] == '.')
516 /* Finally, if we can't distinguish them in any other way, try to
517 get consistent results by sorting the symbols by name. */
518 return strcmp (an, bn);
521 /* Sort relocs into address order. */
524 compare_relocs (ap, bp)
528 const arelent *a = *(const arelent **)ap;
529 const arelent *b = *(const arelent **)bp;
531 if (a->address > b->address)
533 else if (a->address < b->address)
536 /* So that associated relocations tied to the same address show up
537 in the correct order, we don't do any further sorting. */
546 /* Print VMA to STREAM. If SKIP_ZEROES is true, omit leading zeroes. */
549 objdump_print_value (vma, info, skip_zeroes)
551 struct disassemble_info *info;
557 sprintf_vma (buf, vma);
562 for (p = buf; *p == '0'; ++p)
567 (*info->fprintf_func) (info->stream, "%s", p);
570 /* Print the name of a symbol. */
573 objdump_print_symname (abfd, info, sym)
575 struct disassemble_info *info;
583 name = bfd_asymbol_name (sym);
584 if (! do_demangle || name[0] == '\0')
588 /* Demangle the name. */
589 if (bfd_get_symbol_leading_char (abfd) == name[0])
592 alloc = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
600 (*info->fprintf_func) (info->stream, "%s", print);
602 printf ("%s", print);
608 /* Locate a symbol given a bfd, a section, and a VMA. If REQUIRE_SEC
609 is true, then always require the symbol to be in the section. This
610 returns NULL if there is no suitable symbol. If PLACE is not NULL,
611 then *PLACE is set to the index of the symbol in sorted_syms. */
614 find_symbol_for_address (abfd, sec, vma, require_sec, place)
621 /* @@ Would it speed things up to cache the last two symbols returned,
622 and maybe their address ranges? For many processors, only one memory
623 operand can be present at a time, so the 2-entry cache wouldn't be
624 constantly churned by code doing heavy memory accesses. */
626 /* Indices in `sorted_syms'. */
628 long max = sorted_symcount;
631 if (sorted_symcount < 1)
634 /* Perform a binary search looking for the closest symbol to the
635 required value. We are searching the range (min, max]. */
636 while (min + 1 < max)
640 thisplace = (max + min) / 2;
641 sym = sorted_syms[thisplace];
643 if (bfd_asymbol_value (sym) > vma)
645 else if (bfd_asymbol_value (sym) < vma)
654 /* The symbol we want is now in min, the low end of the range we
655 were searching. If there are several symbols with the same
656 value, we want the first one. */
659 && (bfd_asymbol_value (sorted_syms[thisplace])
660 == bfd_asymbol_value (sorted_syms[thisplace - 1])))
663 /* If the file is relocateable, and the symbol could be from this
664 section, prefer a symbol from this section over symbols from
665 others, even if the other symbol's value might be closer.
667 Note that this may be wrong for some symbol references if the
668 sections have overlapping memory ranges, but in that case there's
669 no way to tell what's desired without looking at the relocation
672 if (sorted_syms[thisplace]->section != sec
674 || ((abfd->flags & HAS_RELOC) != 0
675 && vma >= bfd_get_section_vma (abfd, sec)
676 && vma < (bfd_get_section_vma (abfd, sec)
677 + bfd_section_size (abfd, sec)))))
681 for (i = thisplace + 1; i < sorted_symcount; i++)
683 if (bfd_asymbol_value (sorted_syms[i])
684 != bfd_asymbol_value (sorted_syms[thisplace]))
690 if (sorted_syms[i]->section == sec
692 || sorted_syms[i - 1]->section != sec
693 || (bfd_asymbol_value (sorted_syms[i])
694 != bfd_asymbol_value (sorted_syms[i - 1]))))
701 if (sorted_syms[thisplace]->section != sec)
703 /* We didn't find a good symbol with a smaller value.
704 Look for one with a larger value. */
705 for (i = thisplace + 1; i < sorted_symcount; i++)
707 if (sorted_syms[i]->section == sec)
715 if (sorted_syms[thisplace]->section != sec
717 || ((abfd->flags & HAS_RELOC) != 0
718 && vma >= bfd_get_section_vma (abfd, sec)
719 && vma < (bfd_get_section_vma (abfd, sec)
720 + bfd_section_size (abfd, sec)))))
722 /* There is no suitable symbol. */
730 return sorted_syms[thisplace];
733 /* Print an address to INFO symbolically. */
736 objdump_print_addr_with_sym (abfd, sec, sym, vma, info, skip_zeroes)
741 struct disassemble_info *info;
744 objdump_print_value (vma, info, skip_zeroes);
750 (*info->fprintf_func) (info->stream, " <%s",
751 bfd_get_section_name (abfd, sec));
752 secaddr = bfd_get_section_vma (abfd, sec);
755 (*info->fprintf_func) (info->stream, "-");
756 objdump_print_value (secaddr - vma, info, true);
758 else if (vma > secaddr)
760 (*info->fprintf_func) (info->stream, "+");
761 objdump_print_value (vma - secaddr, info, true);
763 (*info->fprintf_func) (info->stream, ">");
767 (*info->fprintf_func) (info->stream, " <");
768 objdump_print_symname (abfd, info, sym);
769 if (bfd_asymbol_value (sym) > vma)
771 (*info->fprintf_func) (info->stream, "-");
772 objdump_print_value (bfd_asymbol_value (sym) - vma, info, true);
774 else if (vma > bfd_asymbol_value (sym))
776 (*info->fprintf_func) (info->stream, "+");
777 objdump_print_value (vma - bfd_asymbol_value (sym), info, true);
779 (*info->fprintf_func) (info->stream, ">");
783 /* Print VMA to INFO, symbolically if possible. If SKIP_ZEROES is
784 true, don't output leading zeroes. */
787 objdump_print_addr (vma, info, skip_zeroes)
789 struct disassemble_info *info;
792 struct objdump_disasm_info *aux;
795 if (sorted_symcount < 1)
797 objdump_print_value (vma, info, skip_zeroes);
801 aux = (struct objdump_disasm_info *) info->application_data;
802 sym = find_symbol_for_address (aux->abfd, aux->sec, vma, aux->require_sec,
804 objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
808 /* Print VMA to INFO. This function is passed to the disassembler
812 objdump_print_address (vma, info)
814 struct disassemble_info *info;
816 objdump_print_addr (vma, info, ! prefix_addresses);
819 /* Hold the last function name and the last line number we displayed
822 static char *prev_functionname;
823 static unsigned int prev_line;
825 /* We keep a list of all files that we have seen when doing a
826 dissassembly with source, so that we know how much of the file to
827 display. This can be important for inlined functions. */
829 struct print_file_list
831 struct print_file_list *next;
837 static struct print_file_list *print_files;
839 /* The number of preceding context lines to show when we start
840 displaying a file for the first time. */
842 #define SHOW_PRECEDING_CONTEXT_LINES (5)
844 /* Skip ahead to a given line in a file, optionally printing each
848 skip_to_line PARAMS ((struct print_file_list *, unsigned int, boolean));
851 skip_to_line (p, line, show)
852 struct print_file_list *p;
856 while (p->line < line)
860 if (fgets (buf, sizeof buf, p->f) == NULL)
870 if (strchr (buf, '\n') != NULL)
875 /* Show the line number, or the source line, in a dissassembly
879 show_line (abfd, section, off)
884 CONST char *filename;
885 CONST char *functionname;
888 if (! with_line_numbers && ! with_source_code)
891 if (! bfd_find_nearest_line (abfd, section, syms, off, &filename,
892 &functionname, &line))
895 if (filename != NULL && *filename == '\0')
897 if (functionname != NULL && *functionname == '\0')
900 if (with_line_numbers)
902 if (functionname != NULL
903 && (prev_functionname == NULL
904 || strcmp (functionname, prev_functionname) != 0))
905 printf ("%s():\n", functionname);
906 if (line > 0 && line != prev_line)
907 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
914 struct print_file_list **pp, *p;
916 for (pp = &print_files; *pp != NULL; pp = &(*pp)->next)
917 if (strcmp ((*pp)->filename, filename) == 0)
923 if (p != print_files)
927 /* We have reencountered a file name which we saw
928 earlier. This implies that either we are dumping out
929 code from an included file, or the same file was
930 linked in more than once. There are two common cases
931 of an included file: inline functions in a header
932 file, and a bison or flex skeleton file. In the
933 former case we want to just start printing (but we
934 back up a few lines to give context); in the latter
935 case we want to continue from where we left off. I
936 can't think of a good way to distinguish the cases,
937 so I used a heuristic based on the file name. */
938 if (strcmp (p->filename + strlen (p->filename) - 2, ".h") != 0)
942 l = line - SHOW_PRECEDING_CONTEXT_LINES;
949 p->f = fopen (p->filename, "r");
953 skip_to_line (p, l, false);
955 if (print_files->f != NULL)
957 fclose (print_files->f);
958 print_files->f = NULL;
964 skip_to_line (p, line, true);
966 p->next = print_files;
974 f = fopen (filename, "r");
979 p = ((struct print_file_list *)
980 xmalloc (sizeof (struct print_file_list)));
981 p->filename = xmalloc (strlen (filename) + 1);
982 strcpy (p->filename, filename);
986 if (print_files != NULL && print_files->f != NULL)
988 fclose (print_files->f);
989 print_files->f = NULL;
991 p->next = print_files;
994 l = line - SHOW_PRECEDING_CONTEXT_LINES;
997 skip_to_line (p, l, false);
999 skip_to_line (p, line, true);
1004 if (functionname != NULL
1005 && (prev_functionname == NULL
1006 || strcmp (functionname, prev_functionname) != 0))
1008 if (prev_functionname != NULL)
1009 free (prev_functionname);
1010 prev_functionname = xmalloc (strlen (functionname) + 1);
1011 strcpy (prev_functionname, functionname);
1014 if (line > 0 && line != prev_line)
1018 /* Pseudo FILE object for strings. */
1024 /* sprintf to a "stream" */
1026 #ifdef ANSI_PROTOTYPES
1028 objdump_sprintf (SFILE *f, const char *format, ...)
1033 va_start (args, format);
1034 vsprintf (f->current, format, args);
1035 f->current += n = strlen (f->current);
1041 objdump_sprintf (va_alist)
1050 f = va_arg (args, SFILE *);
1051 format = va_arg (args, const char *);
1052 vsprintf (f->current, format, args);
1053 f->current += n = strlen (f->current);
1059 /* The number of zeroes we want to see before we start skipping them.
1060 The number is arbitrarily chosen. */
1062 #define SKIP_ZEROES (8)
1064 /* The number of zeroes to skip at the end of a section. If the
1065 number of zeroes at the end is between SKIP_ZEROES_AT_END and
1066 SKIP_ZEROES, they will be disassembled. If there are fewer than
1067 SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic
1068 attempt to avoid disassembling zeroes inserted by section
1071 #define SKIP_ZEROES_AT_END (3)
1073 /* Disassemble some data in memory between given values. */
1076 disassemble_bytes (info, disassemble_fn, insns, data, start, stop, relppp,
1078 struct disassemble_info *info;
1079 disassembler_ftype disassemble_fn;
1087 struct objdump_disasm_info *aux;
1091 int skip_addr_chars;
1094 aux = (struct objdump_disasm_info *) info->application_data;
1100 bytes_per_line = 16;
1102 /* Figure out how many characters to skip at the start of an
1103 address, to make the disassembly look nicer. We discard leading
1104 zeroes in chunks of 4, ensuring that there is always a leading
1106 skip_addr_chars = 0;
1107 if (! prefix_addresses)
1113 section->vma + bfd_section_size (section->owner, section));
1115 while (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0'
1118 skip_addr_chars += 4;
1123 info->insn_info_valid = 0;
1131 boolean need_nl = false;
1133 /* If we see more than SKIP_ZEROES bytes of zeroes, we just
1135 for (z = i; z < stop; z++)
1138 if (! disassemble_zeroes
1139 && (info->insn_info_valid == 0
1140 || info->branch_delay_insns == 0)
1141 && (z - i >= SKIP_ZEROES
1142 || (z == stop && z - i < SKIP_ZEROES_AT_END)))
1146 /* If there are more nonzero bytes to follow, we only skip
1147 zeroes in multiples of 4, to try to avoid running over
1148 the start of an instruction which happens to start with
1151 z = i + ((z - i) &~ 3);
1163 if (with_line_numbers || with_source_code)
1164 show_line (aux->abfd, section, i);
1166 if (! prefix_addresses)
1170 sprintf_vma (buf, section->vma + i);
1171 for (s = buf + skip_addr_chars; *s == '0'; s++)
1175 printf ("%s:\t", buf + skip_addr_chars);
1179 aux->require_sec = true;
1180 objdump_print_address (section->vma + i, info);
1181 aux->require_sec = false;
1187 sfile.buffer = sfile.current = buf;
1188 info->fprintf_func = (fprintf_ftype) objdump_sprintf;
1189 info->stream = (FILE *) &sfile;
1190 info->bytes_per_line = 0;
1191 info->bytes_per_chunk = 0;
1192 bytes = (*disassemble_fn) (section->vma + i, info);
1193 info->fprintf_func = (fprintf_ftype) fprintf;
1194 info->stream = stdout;
1195 if (info->bytes_per_line != 0)
1196 bytes_per_line = info->bytes_per_line;
1204 bytes = bytes_per_line;
1205 if (i + bytes > stop)
1208 for (j = i; j < i + bytes; ++j)
1210 if (isprint (data[j]))
1211 buf[j - i] = data[j];
1218 if (prefix_addresses
1220 : show_raw_insn >= 0)
1224 /* If ! prefix_addresses and ! wide_output, we print
1225 bytes_per_line bytes per line. */
1227 if (pb > bytes_per_line && ! prefix_addresses && ! wide_output)
1228 pb = bytes_per_line;
1230 if (info->bytes_per_chunk)
1231 bpc = info->bytes_per_chunk;
1235 for (j = i; j < i + pb; j += bpc)
1238 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1240 for (k = bpc - 1; k >= 0; k--)
1241 printf ("%02x", (unsigned) data[j + k]);
1246 for (k = 0; k < bpc; k++)
1247 printf ("%02x", (unsigned) data[j + k]);
1252 for (; pb < bytes_per_line; pb += bpc)
1256 for (k = 0; k < bpc; k++)
1261 /* Separate raw data from instruction by extra space. */
1270 if (prefix_addresses
1272 : show_raw_insn >= 0)
1282 sprintf_vma (buf, section->vma + j);
1283 for (s = buf + skip_addr_chars; *s == '0'; s++)
1287 printf ("%s:\t", buf + skip_addr_chars);
1289 pb += bytes_per_line;
1292 for (; j < i + pb; j += bpc)
1296 if (bpc > 1 && info->display_endian == BFD_ENDIAN_LITTLE)
1298 for (k = bpc - 1; k >= 0; k--)
1299 printf ("%02x", (unsigned) data[j + k]);
1304 for (k = 0; k < bpc; k++)
1305 printf ("%02x", (unsigned) data[j + k]);
1319 && (section->flags & SEC_RELOC) != 0)
1321 while ((*relppp) < relppend
1322 && ((**relppp)->address >= (bfd_vma) i
1323 && (**relppp)->address < (bfd_vma) i + bytes))
1334 objdump_print_value (section->vma + q->address, info, true);
1336 printf (": %s\t", q->howto->name);
1338 if (q->sym_ptr_ptr == NULL || *q->sym_ptr_ptr == NULL)
1339 printf ("*unknown*");
1342 const char *sym_name;
1344 sym_name = bfd_asymbol_name (*q->sym_ptr_ptr);
1345 if (sym_name != NULL && *sym_name != '\0')
1346 objdump_print_symname (aux->abfd, info, *q->sym_ptr_ptr);
1351 sym_sec = bfd_get_section (*q->sym_ptr_ptr);
1352 sym_name = bfd_get_section_name (aux->abfd, sym_sec);
1353 if (sym_name == NULL || *sym_name == '\0')
1354 sym_name = "*unknown*";
1355 printf ("%s", sym_name);
1362 objdump_print_value (q->addend, info, true);
1378 /* Disassemble the contents of an object file. */
1381 disassemble_data (abfd)
1385 disassembler_ftype disassemble_fn;
1386 struct disassemble_info disasm_info;
1387 struct objdump_disasm_info aux;
1391 prev_functionname = NULL;
1394 /* We make a copy of syms to sort. We don't want to sort syms
1395 because that will screw up the relocs. */
1396 sorted_syms = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
1397 memcpy (sorted_syms, syms, symcount * sizeof (asymbol *));
1399 sorted_symcount = remove_useless_symbols (sorted_syms, symcount);
1401 /* Sort the symbols into section and symbol order */
1402 qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
1404 INIT_DISASSEMBLE_INFO(disasm_info, stdout, fprintf);
1405 disasm_info.application_data = (PTR) &aux;
1407 aux.require_sec = false;
1408 disasm_info.print_address_func = objdump_print_address;
1410 if (machine != (char *) NULL)
1412 const bfd_arch_info_type *info = bfd_scan_arch (machine);
1415 fprintf (stderr, "%s: Can't use supplied machine %s\n",
1420 abfd->arch_info = info;
1423 if (endian != BFD_ENDIAN_UNKNOWN)
1425 struct bfd_target *xvec;
1427 xvec = (struct bfd_target *) xmalloc (sizeof (struct bfd_target));
1428 memcpy (xvec, abfd->xvec, sizeof (struct bfd_target));
1429 xvec->byteorder = endian;
1433 disassemble_fn = disassembler (abfd);
1434 if (!disassemble_fn)
1436 fprintf (stderr, "%s: Can't disassemble for architecture %s\n",
1438 bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
1442 disasm_info.flavour = bfd_get_flavour (abfd);
1443 disasm_info.arch = bfd_get_arch (abfd);
1444 disasm_info.mach = bfd_get_mach (abfd);
1445 if (bfd_big_endian (abfd))
1446 disasm_info.endian = BFD_ENDIAN_BIG;
1447 else if (bfd_little_endian (abfd))
1448 disasm_info.endian = BFD_ENDIAN_LITTLE;
1450 /* ??? Aborting here seems too drastic. We could default to big or little
1452 disasm_info.endian = BFD_ENDIAN_UNKNOWN;
1454 for (section = abfd->sections;
1455 section != (asection *) NULL;
1456 section = section->next)
1458 bfd_byte *data = NULL;
1459 bfd_size_type datasize = 0;
1460 arelent **relbuf = NULL;
1461 arelent **relpp = NULL;
1462 arelent **relppend = NULL;
1465 if ((section->flags & SEC_LOAD) == 0
1466 || (! disassemble_all
1468 && (section->flags & SEC_CODE) == 0))
1470 if (only != (char *) NULL && strcmp (only, section->name) != 0)
1474 && (section->flags & SEC_RELOC) != 0)
1478 relsize = bfd_get_reloc_upper_bound (abfd, section);
1480 bfd_fatal (bfd_get_filename (abfd));
1486 relbuf = (arelent **) xmalloc (relsize);
1487 relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
1489 bfd_fatal (bfd_get_filename (abfd));
1491 /* Sort the relocs by address. */
1492 qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
1495 relppend = relpp + relcount;
1499 printf ("Disassembly of section %s:\n", section->name);
1501 datasize = bfd_get_section_size_before_reloc (section);
1505 data = (bfd_byte *) xmalloc ((size_t) datasize);
1507 bfd_get_section_contents (abfd, section, data, 0, datasize);
1510 disasm_info.buffer = data;
1511 disasm_info.buffer_vma = section->vma;
1512 disasm_info.buffer_length = datasize;
1513 if (start_address == (bfd_vma) -1
1514 || start_address < disasm_info.buffer_vma)
1517 i = start_address - disasm_info.buffer_vma;
1518 if (stop_address == (bfd_vma) -1)
1522 if (stop_address < disasm_info.buffer_vma)
1525 stop = stop_address - disasm_info.buffer_vma;
1526 if (stop > disasm_info.buffer_length)
1527 stop = disasm_info.buffer_length;
1530 if (prefix_addresses)
1531 disassemble_bytes (&disasm_info, disassemble_fn, true, data, i, stop,
1538 sym = find_symbol_for_address (abfd, section, section->vma + i,
1547 if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + i)
1548 disasm_info.symbol = sym;
1550 disasm_info.symbol = NULL;
1553 objdump_print_addr_with_sym (abfd, section, sym,
1559 if (sym != NULL && bfd_asymbol_value (sym) > section->vma + i)
1561 else if (sym == NULL)
1565 while (place < sorted_symcount
1566 && (sorted_syms[place]->section != section
1567 || (bfd_asymbol_value (sorted_syms[place])
1568 <= bfd_asymbol_value (sym))))
1570 if (place >= sorted_symcount)
1573 nextsym = sorted_syms[place];
1576 if (sym != NULL && bfd_asymbol_value (sym) > section->vma + i)
1578 nextstop = bfd_asymbol_value (sym) - section->vma;
1579 if (nextstop > stop)
1582 else if (nextsym == NULL)
1586 nextstop = bfd_asymbol_value (nextsym) - section->vma;
1587 if (nextstop > stop)
1591 /* If a symbol is explicitly marked as being an object
1592 rather than a function, just dump the bytes without
1593 disassembling them. */
1596 || bfd_asymbol_value (sym) > section->vma + i
1597 || ((sym->flags & BSF_OBJECT) == 0
1598 && (strstr (bfd_asymbol_name (sym), "gnu_compiled")
1600 && (strstr (bfd_asymbol_name (sym), "gcc2_compiled")
1602 || (sym->flags & BSF_FUNCTION) != 0)
1607 disassemble_bytes (&disasm_info, disassemble_fn, insns, data, i,
1608 nextstop, &relpp, relppend);
1623 /* Define a table of stab values and print-strings. We wish the initializer
1624 could be a direct-mapped table, but instead we build one the first
1627 static void dump_section_stabs PARAMS ((bfd *abfd, char *stabsect_name,
1628 char *strsect_name));
1630 /* Dump the stabs sections from an object file that has a section that
1631 uses Sun stabs encoding. */
1637 dump_section_stabs (abfd, ".stab", ".stabstr");
1638 dump_section_stabs (abfd, ".stab.excl", ".stab.exclstr");
1639 dump_section_stabs (abfd, ".stab.index", ".stab.indexstr");
1640 dump_section_stabs (abfd, "$GDB_SYMBOLS$", "$GDB_STRINGS$");
1643 static bfd_byte *stabs;
1644 static bfd_size_type stab_size;
1646 static char *strtab;
1647 static bfd_size_type stabstr_size;
1649 /* Read ABFD's stabs section STABSECT_NAME into `stabs'
1650 and string table section STRSECT_NAME into `strtab'.
1651 If the section exists and was read, allocate the space and return true.
1652 Otherwise return false. */
1655 read_section_stabs (abfd, stabsect_name, strsect_name)
1657 char *stabsect_name;
1660 asection *stabsect, *stabstrsect;
1662 stabsect = bfd_get_section_by_name (abfd, stabsect_name);
1665 printf ("No %s section present\n\n", stabsect_name);
1669 stabstrsect = bfd_get_section_by_name (abfd, strsect_name);
1670 if (0 == stabstrsect)
1672 fprintf (stderr, "%s: %s has no %s section\n", program_name,
1673 bfd_get_filename (abfd), strsect_name);
1677 stab_size = bfd_section_size (abfd, stabsect);
1678 stabstr_size = bfd_section_size (abfd, stabstrsect);
1680 stabs = (bfd_byte *) xmalloc (stab_size);
1681 strtab = (char *) xmalloc (stabstr_size);
1683 if (! bfd_get_section_contents (abfd, stabsect, (PTR) stabs, 0, stab_size))
1685 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1686 program_name, stabsect_name, bfd_get_filename (abfd),
1687 bfd_errmsg (bfd_get_error ()));
1693 if (! bfd_get_section_contents (abfd, stabstrsect, (PTR) strtab, 0,
1696 fprintf (stderr, "%s: Reading %s section of %s failed: %s\n",
1697 program_name, strsect_name, bfd_get_filename (abfd),
1698 bfd_errmsg (bfd_get_error ()));
1707 /* Stabs entries use a 12 byte format:
1708 4 byte string table index
1710 1 byte stab other field
1711 2 byte stab desc field
1713 FIXME: This will have to change for a 64 bit object format. */
1715 #define STRDXOFF (0)
1717 #define OTHEROFF (5)
1720 #define STABSIZE (12)
1722 /* Print ABFD's stabs section STABSECT_NAME (in `stabs'),
1723 using string table section STRSECT_NAME (in `strtab'). */
1726 print_section_stabs (abfd, stabsect_name, strsect_name)
1728 char *stabsect_name;
1732 unsigned file_string_table_offset = 0, next_file_string_table_offset = 0;
1733 bfd_byte *stabp, *stabs_end;
1736 stabs_end = stabp + stab_size;
1738 printf ("Contents of %s section:\n\n", stabsect_name);
1739 printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
1741 /* Loop through all symbols and print them.
1743 We start the index at -1 because there is a dummy symbol on
1744 the front of stabs-in-{coff,elf} sections that supplies sizes. */
1746 for (i = -1; stabp < stabs_end; stabp += STABSIZE, i++)
1750 unsigned char type, other;
1751 unsigned short desc;
1754 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
1755 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
1756 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
1757 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
1758 value = bfd_h_get_32 (abfd, stabp + VALOFF);
1760 printf ("\n%-6d ", i);
1761 /* Either print the stab name, or, if unnamed, print its number
1762 again (makes consistent formatting for tools like awk). */
1763 name = bfd_get_stab_name (type);
1765 printf ("%-6s", name);
1766 else if (type == N_UNDF)
1769 printf ("%-6d", type);
1770 printf (" %-6d %-6d ", other, desc);
1772 printf (" %-6lu", strx);
1774 /* Symbols with type == 0 (N_UNDF) specify the length of the
1775 string table associated with this file. We use that info
1776 to know how to relocate the *next* file's string table indices. */
1780 file_string_table_offset = next_file_string_table_offset;
1781 next_file_string_table_offset += value;
1785 /* Using the (possibly updated) string table offset, print the
1786 string (if any) associated with this symbol. */
1788 if ((strx + file_string_table_offset) < stabstr_size)
1789 printf (" %s", &strtab[strx + file_string_table_offset]);
1798 dump_section_stabs (abfd, stabsect_name, strsect_name)
1800 char *stabsect_name;
1805 /* Check for section names for which stabsect_name is a prefix, to
1806 handle .stab0, etc. */
1807 for (s = abfd->sections;
1813 len = strlen (stabsect_name);
1815 /* If the prefix matches, and the files section name ends with a nul or a digit,
1816 then we match. Ie: we want either an exact match or a a section followed by
1818 if (strncmp (stabsect_name, s->name, len) == 0
1819 && (s->name[len] == '\000' || isdigit (s->name[len])))
1821 if (read_section_stabs (abfd, s->name, strsect_name))
1823 print_section_stabs (abfd, s->name, strsect_name);
1832 dump_bfd_header (abfd)
1837 printf ("architecture: %s, ",
1838 bfd_printable_arch_mach (bfd_get_arch (abfd),
1839 bfd_get_mach (abfd)));
1840 printf ("flags 0x%08x:\n", abfd->flags);
1842 #define PF(x, y) if (abfd->flags & x) {printf("%s%s", comma, y); comma=", ";}
1843 PF (HAS_RELOC, "HAS_RELOC");
1844 PF (EXEC_P, "EXEC_P");
1845 PF (HAS_LINENO, "HAS_LINENO");
1846 PF (HAS_DEBUG, "HAS_DEBUG");
1847 PF (HAS_SYMS, "HAS_SYMS");
1848 PF (HAS_LOCALS, "HAS_LOCALS");
1849 PF (DYNAMIC, "DYNAMIC");
1850 PF (WP_TEXT, "WP_TEXT");
1851 PF (D_PAGED, "D_PAGED");
1852 PF (BFD_IS_RELAXABLE, "BFD_IS_RELAXABLE");
1853 printf ("\nstart address 0x");
1854 printf_vma (abfd->start_address);
1859 dump_bfd_private_header (abfd)
1862 bfd_print_private_bfd_data (abfd, stdout);
1871 if (!bfd_check_format_matches (abfd, bfd_object, &matching))
1873 bfd_nonfatal (bfd_get_filename (abfd));
1874 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
1876 list_matching_formats (matching);
1882 /* If we are adjusting section VMA's, change them all now. Changing
1883 the BFD information is a hack. However, we must do it, or
1884 bfd_find_nearest_line will not do the right thing. */
1885 if (adjust_section_vma != 0)
1889 for (s = abfd->sections; s != NULL; s = s->next)
1891 s->vma += adjust_section_vma;
1892 s->lma += adjust_section_vma;
1896 printf ("\n%s: file format %s\n", bfd_get_filename (abfd),
1899 print_arelt_descr (stdout, abfd, true);
1900 if (dump_file_header)
1901 dump_bfd_header (abfd);
1902 if (dump_private_headers)
1903 dump_bfd_private_header (abfd);
1905 if (dump_section_headers)
1906 dump_headers (abfd);
1907 if (dump_symtab || dump_reloc_info || disassemble || dump_debugging)
1909 syms = slurp_symtab (abfd);
1911 if (dump_dynamic_symtab || dump_dynamic_reloc_info)
1913 dynsyms = slurp_dynamic_symtab (abfd);
1916 dump_symbols (abfd, false);
1917 if (dump_dynamic_symtab)
1918 dump_symbols (abfd, true);
1919 if (dump_stab_section_info)
1921 if (dump_reloc_info && ! disassemble)
1923 if (dump_dynamic_reloc_info)
1924 dump_dynamic_relocs (abfd);
1925 if (dump_section_contents)
1928 disassemble_data (abfd);
1933 dhandle = read_debugging_info (abfd, syms, symcount);
1934 if (dhandle != NULL)
1936 if (! print_debugging_info (stdout, dhandle))
1937 fprintf (stderr, "%s: printing debugging information failed\n",
1938 bfd_get_filename (abfd));
1954 display_file (filename, target)
1958 bfd *file, *arfile = (bfd *) NULL;
1960 file = bfd_openr (filename, target);
1963 bfd_nonfatal (filename);
1967 if (bfd_check_format (file, bfd_archive) == true)
1969 bfd *last_arfile = NULL;
1971 printf ("In archive %s:\n", bfd_get_filename (file));
1974 bfd_set_error (bfd_error_no_error);
1976 arfile = bfd_openr_next_archived_file (file, arfile);
1979 if (bfd_get_error () != bfd_error_no_more_archived_files)
1981 bfd_nonfatal (bfd_get_filename (file));
1986 display_bfd (arfile);
1988 if (last_arfile != NULL)
1989 bfd_close (last_arfile);
1990 last_arfile = arfile;
1993 if (last_arfile != NULL)
1994 bfd_close (last_arfile);
2002 /* Actually display the various requested regions */
2010 bfd_size_type datasize = 0;
2012 bfd_size_type start, stop;
2014 for (section = abfd->sections; section != NULL; section =
2019 if (only == (char *) NULL ||
2020 strcmp (only, section->name) == 0)
2022 if (section->flags & SEC_HAS_CONTENTS)
2024 printf ("Contents of section %s:\n", section->name);
2026 if (bfd_section_size (abfd, section) == 0)
2028 data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (abfd, section));
2029 datasize = bfd_section_size (abfd, section);
2032 bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section));
2034 if (start_address == (bfd_vma) -1
2035 || start_address < section->vma)
2038 start = start_address - section->vma;
2039 if (stop_address == (bfd_vma) -1)
2040 stop = bfd_section_size (abfd, section);
2043 if (stop_address < section->vma)
2046 stop = stop_address - section->vma;
2047 if (stop > bfd_section_size (abfd, section))
2048 stop = bfd_section_size (abfd, section);
2050 for (i = start; i < stop; i += onaline)
2054 printf (" %04lx ", (unsigned long int) (i + section->vma));
2055 for (j = i; j < i + onaline; j++)
2058 printf ("%02x", (unsigned) (data[j]));
2066 for (j = i; j < i + onaline; j++)
2071 printf ("%c", isprint (data[j]) ? data[j] : '.');
2081 /* Should perhaps share code and display with nm? */
2083 dump_symbols (abfd, dynamic)
2097 printf ("DYNAMIC SYMBOL TABLE:\n");
2105 printf ("SYMBOL TABLE:\n");
2108 for (count = 0; count < max; count++)
2112 bfd *cur_bfd = bfd_asymbol_bfd (*current);
2114 if (cur_bfd != NULL)
2119 name = bfd_asymbol_name (*current);
2121 if (do_demangle && name != NULL && *name != '\0')
2125 /* If we want to demangle the name, we demangle it
2126 here, and temporarily clobber it while calling
2127 bfd_print_symbol. FIXME: This is a gross hack. */
2130 if (bfd_get_symbol_leading_char (cur_bfd) == *n)
2132 alloc = cplus_demangle (n, DMGL_ANSI | DMGL_PARAMS);
2134 (*current)->name = alloc;
2136 (*current)->name = n;
2139 bfd_print_symbol (cur_bfd, stdout, *current,
2140 bfd_print_symbol_all);
2142 (*current)->name = name;
2163 for (a = abfd->sections; a != (asection *) NULL; a = a->next)
2167 if (bfd_is_abs_section (a))
2169 if (bfd_is_und_section (a))
2171 if (bfd_is_com_section (a))
2176 if (strcmp (only, a->name))
2179 else if ((a->flags & SEC_RELOC) == 0)
2182 relsize = bfd_get_reloc_upper_bound (abfd, a);
2184 bfd_fatal (bfd_get_filename (abfd));
2186 printf ("RELOCATION RECORDS FOR [%s]:", a->name);
2190 printf (" (none)\n\n");
2194 relpp = (arelent **) xmalloc (relsize);
2195 relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
2197 bfd_fatal (bfd_get_filename (abfd));
2198 else if (relcount == 0)
2200 printf (" (none)\n\n");
2205 dump_reloc_set (abfd, a, relpp, relcount);
2214 dump_dynamic_relocs (abfd)
2221 relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
2223 bfd_fatal (bfd_get_filename (abfd));
2225 printf ("DYNAMIC RELOCATION RECORDS");
2229 printf (" (none)\n\n");
2233 relpp = (arelent **) xmalloc (relsize);
2234 relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
2236 bfd_fatal (bfd_get_filename (abfd));
2237 else if (relcount == 0)
2239 printf (" (none)\n\n");
2244 dump_reloc_set (abfd, (asection *) NULL, relpp, relcount);
2252 dump_reloc_set (abfd, sec, relpp, relcount)
2259 char *last_filename, *last_functionname;
2260 unsigned int last_line;
2262 /* Get column headers lined up reasonably. */
2268 sprintf_vma (buf, (bfd_vma) -1);
2269 width = strlen (buf) - 7;
2271 printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
2274 last_filename = NULL;
2275 last_functionname = NULL;
2278 for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
2281 const char *filename, *functionname;
2283 const char *sym_name;
2284 const char *section_name;
2286 if (start_address != (bfd_vma) -1
2287 && q->address < start_address)
2289 if (stop_address != (bfd_vma) -1
2290 && q->address > stop_address)
2293 if (with_line_numbers
2295 && bfd_find_nearest_line (abfd, sec, syms, q->address,
2296 &filename, &functionname, &line))
2298 if (functionname != NULL
2299 && (last_functionname == NULL
2300 || strcmp (functionname, last_functionname) != 0))
2302 printf ("%s():\n", functionname);
2303 if (last_functionname != NULL)
2304 free (last_functionname);
2305 last_functionname = xstrdup (functionname);
2308 && (line != last_line
2309 || (filename != NULL
2310 && last_filename != NULL
2311 && strcmp (filename, last_filename) != 0)))
2313 printf ("%s:%u\n", filename == NULL ? "???" : filename, line);
2315 if (last_filename != NULL)
2316 free (last_filename);
2317 if (filename == NULL)
2318 last_filename = NULL;
2320 last_filename = xstrdup (filename);
2324 if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
2326 sym_name = (*(q->sym_ptr_ptr))->name;
2327 section_name = (*(q->sym_ptr_ptr))->section->name;
2332 section_name = NULL;
2336 printf_vma (q->address);
2337 printf (" %-16s ", q->howto->name);
2338 objdump_print_symname (abfd, (struct disassemble_info *) NULL,
2343 if (section_name == (CONST char *) NULL)
2344 section_name = "*unknown*";
2345 printf_vma (q->address);
2346 printf (" %-16s [%s]",
2353 printf_vma (q->addend);
2359 /* The length of the longest architecture name + 1. */
2360 #define LONGEST_ARCH sizeof("rs6000:6000")
2363 endian_string (endian)
2364 enum bfd_endian endian;
2366 if (endian == BFD_ENDIAN_BIG)
2367 return "big endian";
2368 else if (endian == BFD_ENDIAN_LITTLE)
2369 return "little endian";
2371 return "endianness unknown";
2374 /* List the targets that BFD is configured to support, each followed
2375 by its endianness and the architectures it supports. */
2378 display_target_list ()
2380 extern bfd_target *bfd_target_vector[];
2384 dummy_name = choose_temp_base ();
2385 for (t = 0; bfd_target_vector[t]; t++)
2387 bfd_target *p = bfd_target_vector[t];
2388 bfd *abfd = bfd_openw (dummy_name, p->name);
2391 printf ("%s\n (header %s, data %s)\n", p->name,
2392 endian_string (p->header_byteorder),
2393 endian_string (p->byteorder));
2397 bfd_nonfatal (dummy_name);
2401 if (! bfd_set_format (abfd, bfd_object))
2403 if (bfd_get_error () != bfd_error_invalid_operation)
2404 bfd_nonfatal (p->name);
2408 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
2409 if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
2411 bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
2413 unlink (dummy_name);
2417 /* Print a table showing which architectures are supported for entries
2418 FIRST through LAST-1 of bfd_target_vector (targets across,
2419 architectures down). */
2422 display_info_table (first, last)
2426 extern bfd_target *bfd_target_vector[];
2430 /* Print heading of target names. */
2431 printf ("\n%*s", (int) LONGEST_ARCH, " ");
2432 for (t = first; t < last && bfd_target_vector[t]; t++)
2433 printf ("%s ", bfd_target_vector[t]->name);
2436 dummy_name = choose_temp_base ();
2437 for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
2438 if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
2440 printf ("%*s ", (int) LONGEST_ARCH - 1,
2441 bfd_printable_arch_mach (a, 0));
2442 for (t = first; t < last && bfd_target_vector[t]; t++)
2444 bfd_target *p = bfd_target_vector[t];
2446 bfd *abfd = bfd_openw (dummy_name, p->name);
2450 bfd_nonfatal (p->name);
2456 if (! bfd_set_format (abfd, bfd_object))
2458 if (bfd_get_error () != bfd_error_invalid_operation)
2459 bfd_nonfatal (p->name);
2466 if (! bfd_set_arch_mach (abfd, a, 0))
2471 printf ("%s ", p->name);
2474 int l = strlen (p->name);
2482 unlink (dummy_name);
2486 /* Print tables of all the target-architecture combinations that
2487 BFD has been configured to support. */
2490 display_target_tables ()
2493 extern bfd_target *bfd_target_vector[];
2495 extern char *getenv ();
2498 colum = getenv ("COLUMNS");
2500 columns = atoi (colum);
2505 while (bfd_target_vector[t] != NULL)
2509 wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
2511 while (wid < columns && bfd_target_vector[t] != NULL)
2515 newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
2516 if (newwid >= columns)
2521 display_info_table (oldt, t);
2528 printf ("BFD header file version %s\n", BFD_VERSION);
2529 display_target_list ();
2530 display_target_tables ();
2539 char *target = default_target;
2540 boolean seenflag = false;
2542 program_name = *argv;
2543 xmalloc_set_program_name (program_name);
2545 START_PROGRESS (program_name, 0);
2548 set_default_bfd_target ();
2550 while ((c = getopt_long (argc, argv, "pib:m:VCdDlfahrRtTxsSj:wE:",
2551 long_options, (int *) 0))
2554 if (c != 'l' && c != OPTION_START_ADDRESS && c != OPTION_STOP_ADDRESS)
2559 break; /* we've been given a long option */
2567 with_line_numbers = 1;
2573 dump_file_header = true;
2576 formats_info = true;
2579 dump_private_headers = 1;
2582 dump_private_headers = 1;
2584 dump_reloc_info = 1;
2585 dump_file_header = true;
2587 dump_section_headers = 1;
2593 dump_dynamic_symtab = 1;
2602 disassemble = disassemble_all = true;
2606 with_source_code = true;
2609 dump_section_contents = 1;
2612 dump_reloc_info = 1;
2615 dump_dynamic_reloc_info = 1;
2621 dump_section_headers = 1;
2631 case OPTION_ADJUST_VMA:
2632 adjust_section_vma = parse_vma (optarg, "--adjust-vma");
2634 case OPTION_START_ADDRESS:
2635 start_address = parse_vma (optarg, "--start-address");
2637 case OPTION_STOP_ADDRESS:
2638 stop_address = parse_vma (optarg, "--stop-address");
2641 if (strcmp (optarg, "B") == 0)
2642 endian = BFD_ENDIAN_BIG;
2643 else if (strcmp (optarg, "L") == 0)
2644 endian = BFD_ENDIAN_LITTLE;
2647 fprintf (stderr, "%s: unrecognized -E option\n", program_name);
2652 if (strncmp (optarg, "big", strlen (optarg)) == 0)
2653 endian = BFD_ENDIAN_BIG;
2654 else if (strncmp (optarg, "little", strlen (optarg)) == 0)
2655 endian = BFD_ENDIAN_LITTLE;
2658 fprintf (stderr, "%s: unrecognized --endian type `%s'\n",
2659 program_name, optarg);
2669 print_version ("objdump");
2671 if (seenflag == false)
2681 display_file ("a.out", target);
2683 for (; optind < argc;)
2684 display_file (argv[optind++], target);
2687 END_PROGRESS (program_name);