1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 /* Define BFD64 here, even if our default architecture is 32 bit ELF
32 as this will allow us to read in and parse 64bit and 32bit ELF files.
33 Only do this if we belive that the compiler can support a 64 bit
34 data type. For now we only rely on GCC being able to do this. */
40 #include "elf/common.h"
41 #include "elf/external.h"
42 #include "elf/internal.h"
43 #include "elf/dwarf2.h"
45 /* The following headers use the elf/reloc-macros.h file to
46 automatically generate relocation recognition functions
47 such as elf_mips_reloc_type() */
49 #define RELOC_MACROS_GEN_FUNC
55 #include "elf/alpha.h"
58 #include "elf/sparc.h"
63 #include "elf/mn10200.h"
64 #include "elf/mn10300.h"
68 #include "elf/mcore.h"
74 #ifdef ANSI_PROTOTYPES
80 char * program_name = "readelf";
81 unsigned int dynamic_addr;
82 bfd_size_type dynamic_size;
83 unsigned int rela_addr;
84 unsigned int rela_size;
85 char * dynamic_strings;
87 unsigned long num_dynamic_syms;
88 Elf_Internal_Sym * dynamic_symbols;
89 Elf_Internal_Syminfo * dynamic_syminfo;
90 unsigned long dynamic_syminfo_offset;
91 unsigned int dynamic_syminfo_nent;
92 char program_interpreter [64];
93 int dynamic_info[DT_JMPREL + 1];
96 Elf_Internal_Ehdr elf_header;
97 Elf_Internal_Shdr * section_headers;
98 Elf_Internal_Dyn * dynamic_segment;
105 int do_using_dynamic;
112 int do_debug_abbrevs;
114 int do_debug_pubnames;
115 int do_debug_aranges;
119 /* A dynamic array of flags indicating which sections require dumping. */
120 char * dump_sects = NULL;
121 unsigned int num_dump_sects = 0;
123 #define HEX_DUMP (1 << 0)
124 #define DISASS_DUMP (1 << 1)
125 #define DEBUG_DUMP (1 << 2)
127 /* Forward declarations for dumb compilers. */
128 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
129 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
130 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
131 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
132 static const char * get_dynamic_type PARAMS ((unsigned long));
133 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
134 static char * get_file_type PARAMS ((unsigned));
135 static char * get_machine_name PARAMS ((unsigned));
136 static char * get_machine_flags PARAMS ((unsigned, unsigned));
137 static const char * get_mips_segment_type PARAMS ((unsigned long));
138 static const char * get_segment_type PARAMS ((unsigned long));
139 static const char * get_mips_section_type_name PARAMS ((unsigned int));
140 static const char * get_section_type_name PARAMS ((unsigned int));
141 static char * get_symbol_binding PARAMS ((unsigned int));
142 static char * get_symbol_type PARAMS ((unsigned int));
143 static void usage PARAMS ((void));
144 static void parse_args PARAMS ((int, char **));
145 static int process_file_header PARAMS ((void));
146 static int process_program_headers PARAMS ((FILE *));
147 static int process_section_headers PARAMS ((FILE *));
148 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
149 static int process_dynamic_segment PARAMS ((FILE *));
150 static int process_symbol_table PARAMS ((FILE *));
151 static int process_section_contents PARAMS ((FILE *));
152 static void process_file PARAMS ((char *));
153 static int process_relocs PARAMS ((FILE *));
154 static int process_version_sections PARAMS ((FILE *));
155 static char * get_ver_flags PARAMS ((unsigned int));
156 static char * get_symbol_index_type PARAMS ((unsigned int));
157 static int get_32bit_section_headers PARAMS ((FILE *));
158 static int get_64bit_section_headers PARAMS ((FILE *));
159 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
160 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
161 static int get_file_header PARAMS ((FILE *));
162 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
163 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
164 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
165 static int get_32bit_dynamic_segment PARAMS ((FILE *));
166 static int get_64bit_dynamic_segment PARAMS ((FILE *));
167 #ifdef SUPPORT_DISASSEMBLY
168 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
170 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
171 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
172 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
173 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
174 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
175 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
176 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
177 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
178 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
179 static int process_extended_line_op PARAMS ((unsigned char *, int));
180 static void reset_state_machine PARAMS ((int));
181 static char * get_TAG_name PARAMS ((unsigned long));
182 static char * get_AT_name PARAMS ((unsigned long));
183 static char * get_FORM_name PARAMS ((unsigned long));
184 static void free_abbrevs PARAMS ((void));
185 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
186 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
187 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
188 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
189 static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
190 static void request_dump PARAMS ((unsigned int, char));
191 static const char * get_elf_class PARAMS ((unsigned char));
192 static const char * get_data_encoding PARAMS ((unsigned char));
193 static const char * get_osabi_name PARAMS ((unsigned char));
194 static int guess_is_rela PARAMS ((unsigned long));
196 typedef int Elf32_Word;
204 #define SECTION_NAME(X) (string_table + (X)->sh_name)
206 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
208 #define BYTE_GET(field) byte_get (field, sizeof (field))
210 /* If we can support a 64 bit data type then BFD64 should be defined
211 and sizeof (bfd_vma) == 8. In this case when translating from an
212 external 8 byte field to an internal field, we can assume that the
213 internal field is also 8 bytes wide and so we can extact all the data.
214 If, however, BFD64 is not defined, then we must assume that the
215 internal data structure only has 4 byte wide fields that are the
216 equivalent of the 8 byte wide external counterparts, and so we must
217 truncate the data. */
219 #define BYTE_GET8(field) byte_get (field, -8)
221 #define BYTE_GET8(field) byte_get (field, 8)
224 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
226 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
227 if (fseek (file, offset, SEEK_SET)) \
229 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
233 var = (type) malloc (size); \
237 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
241 if (fread (var, size, 1, file) != 1) \
243 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
250 #define GET_DATA(offset, var, reason) \
251 if (fseek (file, offset, SEEK_SET)) \
253 error (_("Unable to seek to %x for %s\n"), offset, reason); \
256 else if (fread (& var, sizeof (var), 1, file) != 1) \
258 error (_("Unable to read data at %x for %s\n"), offset, reason); \
262 #define GET_ELF_SYMBOLS(file, offset, size) \
263 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
264 : get_64bit_elf_symbols (file, offset, size))
267 #ifdef ANSI_PROTOTYPES
269 error (const char * message, ...)
273 fprintf (stderr, _("%s: Error: "), program_name);
274 va_start (args, message);
275 vfprintf (stderr, message, args);
281 warn (const char * message, ...)
285 fprintf (stderr, _("%s: Warning: "), program_name);
286 va_start (args, message);
287 vfprintf (stderr, message, args);
299 fprintf (stderr, _("%s: Error: "), program_name);
301 message = va_arg (args, char *);
302 vfprintf (stderr, message, args);
314 fprintf (stderr, _("%s: Warning: "), program_name);
316 message = va_arg (args, char *);
317 vfprintf (stderr, message, args);
324 byte_get_little_endian (field, size)
325 unsigned char * field;
334 return ((unsigned int) (field [0]))
335 | (((unsigned int) (field [1])) << 8);
338 /* We want to extract data from an 8 byte wide field and
339 place it into a 4 byte wide field. Since this is a little
340 endian source we can juts use the 4 byte extraction code. */
343 return ((unsigned long) (field [0]))
344 | (((unsigned long) (field [1])) << 8)
345 | (((unsigned long) (field [2])) << 16)
346 | (((unsigned long) (field [3])) << 24);
350 /* This is a special case, generated by the BYTE_GET8 macro.
351 It means that we are loading an 8 byte value from a field
352 in an external structure into an 8 byte value in a field
353 in an internal strcuture. */
354 return ((bfd_vma) (field [0]))
355 | (((bfd_vma) (field [1])) << 8)
356 | (((bfd_vma) (field [2])) << 16)
357 | (((bfd_vma) (field [3])) << 24)
358 | (((bfd_vma) (field [4])) << 32)
359 | (((bfd_vma) (field [5])) << 40)
360 | (((bfd_vma) (field [6])) << 48)
361 | (((bfd_vma) (field [7])) << 56);
364 error (_("Unhandled data length: %d\n"), size);
370 byte_get_big_endian (field, size)
371 unsigned char * field;
380 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
383 return ((unsigned long) (field [3]))
384 | (((unsigned long) (field [2])) << 8)
385 | (((unsigned long) (field [1])) << 16)
386 | (((unsigned long) (field [0])) << 24);
389 /* Although we are extracing data from an 8 byte wide field, we
390 are returning only 4 bytes of data. */
391 return ((unsigned long) (field [7]))
392 | (((unsigned long) (field [6])) << 8)
393 | (((unsigned long) (field [5])) << 16)
394 | (((unsigned long) (field [4])) << 24);
398 /* This is a special case, generated by the BYTE_GET8 macro.
399 It means that we are loading an 8 byte value from a field
400 in an external structure into an 8 byte value in a field
401 in an internal strcuture. */
402 return ((bfd_vma) (field [7]))
403 | (((bfd_vma) (field [6])) << 8)
404 | (((bfd_vma) (field [5])) << 16)
405 | (((bfd_vma) (field [4])) << 24)
406 | (((bfd_vma) (field [3])) << 32)
407 | (((bfd_vma) (field [2])) << 40)
408 | (((bfd_vma) (field [1])) << 48)
409 | (((bfd_vma) (field [0])) << 56);
413 error (_("Unhandled data length: %d\n"), size);
419 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
421 guess_is_rela (e_machine)
422 unsigned long e_machine;
426 /* Targets that use REL relocations. */
437 /* Targets that use RELA relocations. */
445 case EM_CYGNUS_MN10200:
446 case EM_CYGNUS_MN10300:
454 warn (_("Don't know about relocations on this machine architecture\n"));
459 /* Display the contents of the relocation data found at the specified offset. */
461 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
463 unsigned long rel_offset;
464 unsigned long rel_size;
465 Elf_Internal_Sym * symtab;
471 Elf_Internal_Rel * rels;
472 Elf_Internal_Rela * relas;
475 if (is_rela == UNKNOWN)
476 is_rela = guess_is_rela (elf_header.e_machine);
482 Elf32_External_Rela * erelas;
484 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
485 Elf32_External_Rela *, "relocs");
487 rel_size = rel_size / sizeof (Elf32_External_Rela);
489 relas = (Elf_Internal_Rela *)
490 malloc (rel_size * sizeof (Elf_Internal_Rela));
494 error(_("out of memory parsing relocs"));
498 for (i = 0; i < rel_size; i++)
500 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
501 relas[i].r_info = BYTE_GET (erelas[i].r_info);
502 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
507 rels = (Elf_Internal_Rel *) relas;
511 Elf64_External_Rela * erelas;
513 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
514 Elf64_External_Rela *, "relocs");
516 rel_size = rel_size / sizeof (Elf64_External_Rela);
518 relas = (Elf_Internal_Rela *)
519 malloc (rel_size * sizeof (Elf_Internal_Rela));
523 error(_("out of memory parsing relocs"));
527 for (i = 0; i < rel_size; i++)
529 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
530 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
531 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
536 rels = (Elf_Internal_Rel *) relas;
543 Elf32_External_Rel * erels;
545 GET_DATA_ALLOC (rel_offset, rel_size, erels,
546 Elf32_External_Rel *, "relocs");
548 rel_size = rel_size / sizeof (Elf32_External_Rel);
550 rels = (Elf_Internal_Rel *)
551 malloc (rel_size * sizeof (Elf_Internal_Rel));
555 error(_("out of memory parsing relocs"));
559 for (i = 0; i < rel_size; i++)
561 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
562 rels[i].r_info = BYTE_GET (erels[i].r_info);
567 relas = (Elf_Internal_Rela *) rels;
571 Elf64_External_Rel * erels;
573 GET_DATA_ALLOC (rel_offset, rel_size, erels,
574 Elf64_External_Rel *, "relocs");
576 rel_size = rel_size / sizeof (Elf64_External_Rel);
578 rels = (Elf_Internal_Rel *)
579 malloc (rel_size * sizeof (Elf_Internal_Rel));
583 error(_("out of memory parsing relocs"));
587 for (i = 0; i < rel_size; i++)
589 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
590 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
595 relas = (Elf_Internal_Rela *) rels;
601 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
604 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
606 for (i = 0; i < rel_size; i++)
611 bfd_vma symtab_index;
616 offset = relas [i].r_offset;
617 info = relas [i].r_info;
621 offset = rels [i].r_offset;
622 info = rels [i].r_info;
627 type = ELF32_R_TYPE (info);
628 symtab_index = ELF32_R_SYM (info);
632 if (elf_header.e_machine == EM_SPARCV9)
633 type = ELF64_R_TYPE_ID (info);
635 type = ELF64_R_TYPE (info);
636 /* The #ifdef BFD64 below is to prevent a compile time warning.
637 We know that if we do not have a 64 bit data type that we
638 will never execute this code anyway. */
640 symtab_index = ELF64_R_SYM (info);
644 #ifdef _bfd_int64_low
645 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
647 printf (" %8.8lx %5.5lx ", offset, info);
650 switch (elf_header.e_machine)
657 rtype = elf_m32r_reloc_type (type);
662 rtype = elf_i386_reloc_type (type);
666 rtype = elf_m68k_reloc_type (type);
670 rtype = elf_i960_reloc_type (type);
677 rtype = elf_sparc_reloc_type (type);
681 rtype = v850_reloc_type (type);
685 rtype = elf_d10v_reloc_type (type);
689 rtype = elf_d30v_reloc_type (type);
693 rtype = elf_sh_reloc_type (type);
696 case EM_CYGNUS_MN10300:
697 rtype = elf_mn10300_reloc_type (type);
700 case EM_CYGNUS_MN10200:
701 rtype = elf_mn10200_reloc_type (type);
705 rtype = elf_fr30_reloc_type (type);
709 rtype = elf_mcore_reloc_type (type);
713 rtype = elf_ppc_reloc_type (type);
718 rtype = elf_mips_reloc_type (type);
722 rtype = elf_alpha_reloc_type (type);
726 rtype = elf_arm_reloc_type (type);
730 rtype = elf_arc_reloc_type (type);
734 rtype = elf_hppa_reloc_type (type);
739 #ifdef _bfd_int64_low
740 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
742 printf (_("unrecognised: %-7lx"), type);
745 printf ("%-21.21s", rtype);
751 if (symtab_index >= nsyms)
752 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
755 Elf_Internal_Sym * psym;
757 psym = symtab + symtab_index;
759 printf (" %08lx ", (unsigned long) psym->st_value);
761 if (psym->st_name == 0)
763 SECTION_NAME (section_headers + psym->st_shndx));
764 else if (strtab == NULL)
765 printf (_("<string table index %3ld>"), psym->st_name);
767 printf ("%-25.25s", strtab + psym->st_name);
770 printf (" + %lx", (unsigned long) relas [i].r_addend);
775 printf ("%34c%lx", ' ', (unsigned long) relas[i].r_addend);
777 if (elf_header.e_machine == EM_SPARCV9
778 && !strcmp (rtype, "R_SPARC_OLO10"))
779 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
790 get_mips_dynamic_type (type)
795 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
796 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
797 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
798 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
799 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
800 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
801 case DT_MIPS_MSYM: return "MIPS_MSYM";
802 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
803 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
804 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
805 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
806 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
807 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
808 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
809 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
810 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
811 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
812 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
813 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
814 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
815 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
816 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
817 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
818 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
819 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
820 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
821 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
822 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
823 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
824 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
825 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
826 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
827 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
828 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
829 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
830 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
831 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
832 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
833 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
834 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
835 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
836 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
837 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
844 get_dynamic_type (type)
847 static char buff [32];
851 case DT_NULL: return "NULL";
852 case DT_NEEDED: return "NEEDED";
853 case DT_PLTRELSZ: return "PLTRELSZ";
854 case DT_PLTGOT: return "PLTGOT";
855 case DT_HASH: return "HASH";
856 case DT_STRTAB: return "STRTAB";
857 case DT_SYMTAB: return "SYMTAB";
858 case DT_RELA: return "RELA";
859 case DT_RELASZ: return "RELASZ";
860 case DT_RELAENT: return "RELAENT";
861 case DT_STRSZ: return "STRSZ";
862 case DT_SYMENT: return "SYMENT";
863 case DT_INIT: return "INIT";
864 case DT_FINI: return "FINI";
865 case DT_SONAME: return "SONAME";
866 case DT_RPATH: return "RPATH";
867 case DT_SYMBOLIC: return "SYMBOLIC";
868 case DT_REL: return "REL";
869 case DT_RELSZ: return "RELSZ";
870 case DT_RELENT: return "RELENT";
871 case DT_PLTREL: return "PLTREL";
872 case DT_DEBUG: return "DEBUG";
873 case DT_TEXTREL: return "TEXTREL";
874 case DT_JMPREL: return "JMPREL";
875 case DT_BIND_NOW: return "BIND_NOW";
876 case DT_INIT_ARRAY: return "INIT_ARRAY";
877 case DT_FINI_ARRAY: return "FINI_ARRAY";
878 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
879 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
881 case DT_PLTPADSZ: return "PLTPADSZ";
882 case DT_MOVEENT: return "MOVEENT";
883 case DT_MOVESZ: return "MOVESZ";
884 case DT_FEATURE_1: return "FEATURE_1";
885 case DT_POSFLAG_1: return "POSFLAG_1";
886 case DT_SYMINSZ: return "SYMINSZ";
887 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
889 case DT_ADDRRNGLO: return "ADDRRNGLO";
890 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
892 case DT_VERSYM: return "VERSYM";
894 case DT_RELACOUNT: return "RELACOUNT";
895 case DT_RELCOUNT: return "RELCOUNT";
896 case DT_FLAGS_1: return "FLAGS_1";
897 case DT_VERDEF: return "VERDEF";
898 case DT_VERDEFNUM: return "VERDEFNUM";
899 case DT_VERNEED: return "VERNEED";
900 case DT_VERNEEDNUM: return "VERNEEDNUM";
902 case DT_AUXILIARY: return "AUXILARY";
903 case DT_USED: return "USED";
904 case DT_FILTER: return "FILTER";
907 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
911 switch (elf_header.e_machine)
915 result = get_mips_dynamic_type (type);
925 sprintf (buff, _("Processor Specific: %lx"), type);
927 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
928 sprintf (buff, _("Operating System specific: %lx"), type);
930 sprintf (buff, _("<unknown>: %lx"), type);
937 get_file_type (e_type)
940 static char buff [32];
944 case ET_NONE: return _("NONE (None)");
945 case ET_REL: return _("REL (Relocatable file)");
946 case ET_EXEC: return _("EXEC (Executable file)");
947 case ET_DYN: return _("DYN (Shared object file)");
948 case ET_CORE: return _("CORE (Core file)");
951 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
952 sprintf (buff, _("Processor Specific: (%x)"), e_type);
953 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
954 sprintf (buff, _("OS Specific: (%x)"), e_type);
956 sprintf (buff, _("<unknown>: %x"), e_type);
962 get_machine_name (e_machine)
965 static char buff [32];
969 case EM_NONE: return _("None");
970 case EM_M32: return "WE32100";
971 case EM_SPARC: return "Sparc";
972 case EM_386: return "Intel 80386";
973 case EM_68K: return "MC68000";
974 case EM_88K: return "MC88000";
975 case EM_486: return "Intel 80486";
976 case EM_860: return "Intel 80860";
977 case EM_MIPS: return "MIPS R3000 big-endian";
978 case EM_S370: return "Amdahl";
979 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
980 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
981 case EM_PARISC: return "HPPA";
982 case EM_PPC_OLD: return "Power PC (old)";
983 case EM_SPARC32PLUS: return "Sparc v8+" ;
984 case EM_960: return "Intel 90860";
985 case EM_PPC: return "PowerPC";
986 case EM_V800: return "NEC V800";
987 case EM_FR20: return "Fujitsu FR20";
988 case EM_RH32: return "TRW RH32";
989 case EM_MCORE: return "MCORE";
990 case EM_ARM: return "ARM";
991 case EM_OLD_ALPHA: return "Digital Alpha (old)";
992 case EM_SH: return "Hitachi SH";
993 case EM_SPARCV9: return "Sparc v9";
994 case EM_TRICORE: return "Siemens Tricore";
995 case EM_ARC: return "Argonaut RISC Core";
996 case EM_H8_300: return "Hitachi H8/300";
997 case EM_H8_300H: return "Hitachi H8/300H";
998 case EM_H8S: return "Hitachi H8S";
999 case EM_H8_500: return "Hitachi H8/500";
1000 case EM_IA_64: return "Intel Merced";
1001 case EM_MIPS_X: return "Stanford MIPS-X";
1002 case EM_COLDFIRE: return "Motorola Coldfire";
1003 case EM_68HC12: return "Motorola M68HC12";
1004 case EM_ALPHA: return "Alpha";
1005 case EM_CYGNUS_D10V: return "d10v";
1006 case EM_CYGNUS_D30V: return "d30v";
1007 case EM_CYGNUS_ARC: return "Arc";
1008 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1009 case EM_CYGNUS_V850: return "NEC v850";
1010 case EM_CYGNUS_MN10300: return "mn10300";
1011 case EM_CYGNUS_MN10200: return "mn10200";
1012 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1015 sprintf (buff, _("<unknown>: %x"), e_machine);
1021 get_machine_flags (e_flags, e_machine)
1025 static char buf [1024];
1036 if (e_flags & EF_CPU32)
1037 strcat (buf, ", cpu32");
1041 if (e_flags & EF_PPC_EMB)
1042 strcat (buf, ", emb");
1044 if (e_flags & EF_PPC_RELOCATABLE)
1045 strcat (buf, ", relocatable");
1047 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1048 strcat (buf, ", relocatable-lib");
1051 case EM_CYGNUS_V850:
1052 switch (e_flags & EF_V850_ARCH)
1055 strcat (buf, ", v850e");
1058 strcat (buf, ", v850ea");
1061 strcat (buf, ", v850");
1064 strcat (buf, ", unknown v850 architecture variant");
1069 case EM_CYGNUS_M32R:
1070 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1071 strcat (buf, ", m32r");
1076 case EM_MIPS_RS4_BE:
1077 if (e_flags & EF_MIPS_NOREORDER)
1078 strcat (buf, ", noreorder");
1080 if (e_flags & EF_MIPS_PIC)
1081 strcat (buf, ", pic");
1083 if (e_flags & EF_MIPS_CPIC)
1084 strcat (buf, ", cpic");
1086 if (e_flags & EF_MIPS_ABI2)
1087 strcat (buf, ", abi2");
1089 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1090 strcat (buf, ", mips1");
1092 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1093 strcat (buf, ", mips2");
1095 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1096 strcat (buf, ", mips3");
1098 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1099 strcat (buf, ", mips4");
1103 if (e_flags & EF_SPARC_32PLUS)
1104 strcat (buf, ", v8+");
1106 if (e_flags & EF_SPARC_SUN_US1)
1107 strcat (buf, ", ultrasparcI");
1109 if (e_flags & EF_SPARC_SUN_US3)
1110 strcat (buf, ", ultrasparcIII");
1112 if (e_flags & EF_SPARC_HAL_R1)
1113 strcat (buf, ", halr1");
1115 if (e_flags & EF_SPARC_LEDATA)
1116 strcat (buf, ", ledata");
1118 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1119 strcat (buf, ", tso");
1121 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1122 strcat (buf, ", pso");
1124 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1125 strcat (buf, ", rmo");
1134 get_mips_segment_type (type)
1139 case PT_MIPS_REGINFO:
1141 case PT_MIPS_RTPROC:
1143 case PT_MIPS_OPTIONS:
1153 get_segment_type (p_type)
1154 unsigned long p_type;
1156 static char buff [32];
1160 case PT_NULL: return "NULL";
1161 case PT_LOAD: return "LOAD";
1162 case PT_DYNAMIC: return "DYNAMIC";
1163 case PT_INTERP: return "INTERP";
1164 case PT_NOTE: return "NOTE";
1165 case PT_SHLIB: return "SHLIB";
1166 case PT_PHDR: return "PHDR";
1169 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1171 const char * result;
1173 switch (elf_header.e_machine)
1176 case EM_MIPS_RS4_BE:
1177 result = get_mips_segment_type (p_type);
1187 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1189 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1190 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1192 sprintf (buff, _("<unknown>: %lx"), p_type);
1199 get_mips_section_type_name (sh_type)
1200 unsigned int sh_type;
1204 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1205 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1206 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1207 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1208 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1209 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1210 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1211 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1212 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1213 case SHT_MIPS_RELD: return "MIPS_RELD";
1214 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1215 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1216 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1217 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1218 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1219 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1220 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1221 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1222 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1223 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1224 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1225 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1226 case SHT_MIPS_LINE: return "MIPS_LINE";
1227 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1228 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1229 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1230 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1231 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1232 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1233 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1234 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1235 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1236 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1237 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1238 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1239 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1240 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1241 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1242 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1250 get_section_type_name (sh_type)
1251 unsigned int sh_type;
1253 static char buff [32];
1257 case SHT_NULL: return "NULL";
1258 case SHT_PROGBITS: return "PROGBITS";
1259 case SHT_SYMTAB: return "SYMTAB";
1260 case SHT_STRTAB: return "STRTAB";
1261 case SHT_RELA: return "RELA";
1262 case SHT_HASH: return "HASH";
1263 case SHT_DYNAMIC: return "DYNAMIC";
1264 case SHT_NOTE: return "NOTE";
1265 case SHT_NOBITS: return "NOBITS";
1266 case SHT_REL: return "REL";
1267 case SHT_SHLIB: return "SHLIB";
1268 case SHT_DYNSYM: return "DYNSYM";
1269 case SHT_GNU_verdef: return "VERDEF";
1270 case SHT_GNU_verneed: return "VERNEED";
1271 case SHT_GNU_versym: return "VERSYM";
1272 case 0x6ffffff0: return "VERSYM";
1273 case 0x6ffffffc: return "VERDEF";
1274 case 0x7ffffffd: return "AUXILIARY";
1275 case 0x7fffffff: return "FILTER";
1278 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1280 const char * result;
1282 switch (elf_header.e_machine)
1285 case EM_MIPS_RS4_BE:
1286 result = get_mips_section_type_name (sh_type);
1296 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1298 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1299 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1300 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1301 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1303 sprintf (buff, _("<unknown>: %x"), sh_type);
1309 struct option options [] =
1311 {"all", no_argument, 0, 'a'},
1312 {"file-header", no_argument, 0, 'h'},
1313 {"program-headers", no_argument, 0, 'l'},
1314 {"headers", no_argument, 0, 'e'},
1315 {"histogram", no_argument, 0, 'I'},
1316 {"segments", no_argument, 0, 'l'},
1317 {"sections", no_argument, 0, 'S'},
1318 {"section-headers", no_argument, 0, 'S'},
1319 {"symbols", no_argument, 0, 's'},
1320 {"syms", no_argument, 0, 's'},
1321 {"relocs", no_argument, 0, 'r'},
1322 {"dynamic", no_argument, 0, 'd'},
1323 {"arch-specific", no_argument, 0, 'A'},
1324 {"version-info", no_argument, 0, 'V'},
1325 {"use-dynamic", no_argument, 0, 'D'},
1326 {"hex-dump", required_argument, 0, 'x'},
1327 {"debug-dump", optional_argument, 0, 'w'},
1328 #ifdef SUPPORT_DISASSEMBLY
1329 {"instruction-dump", required_argument, 0, 'i'},
1332 {"version", no_argument, 0, 'v'},
1333 {"help", no_argument, 0, 'H'},
1334 {0, no_argument, 0, 0}
1340 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1341 fprintf (stdout, _(" Options are:\n"));
1342 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1343 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1344 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1345 fprintf (stdout, _(" Display the program headers\n"));
1346 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1347 fprintf (stdout, _(" Display the sections' header\n"));
1348 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1349 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1350 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1351 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1352 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1353 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1354 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1355 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1356 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1357 fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1358 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1359 #ifdef SUPPORT_DISASSEMBLY
1360 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1361 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1363 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1364 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1365 fprintf (stdout, _(" -H or --help Display this information\n"));
1372 request_dump (section, type)
1373 unsigned int section;
1376 if (section >= num_dump_sects)
1378 char * new_dump_sects;
1380 new_dump_sects = (char *) calloc (section + 1, 1);
1382 if (new_dump_sects == NULL)
1383 error (_("Out of memory allocating dump request table."));
1386 /* Copy current flag settings. */
1387 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1391 dump_sects = new_dump_sects;
1392 num_dump_sects = section + 1;
1397 dump_sects [section] |= type;
1403 parse_args (argc, argv)
1412 while ((c = getopt_long
1413 (argc, argv, "ersahldSDAIw::x:i:vV", options, NULL)) != EOF)
1447 do_using_dynamic ++;
1472 section = strtoul (optarg, & cp, 0);
1473 if (! * cp && section >= 0)
1475 request_dump (section, HEX_DUMP);
1495 do_debug_abbrevs = 1;
1505 do_debug_pubnames = 1;
1510 do_debug_aranges = 1;
1514 warn (_("Unrecognised debug option '%s'\n"), optarg);
1519 #ifdef SUPPORT_DISASSEMBLY
1522 section = strtoul (optarg, & cp, 0);
1523 if (! * cp && section >= 0)
1525 request_dump (section, DISASS_DUMP);
1531 print_version (program_name);
1538 /* xgettext:c-format */
1539 error (_("Invalid option '-%c'\n"), c);
1546 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
1547 && !do_segments && !do_header && !do_dump && !do_version
1548 && !do_histogram && !do_debugging && !do_arch)
1552 warn (_("Nothing to do.\n"));
1558 get_elf_class (elf_class)
1559 unsigned char elf_class;
1561 static char buff [32];
1565 case ELFCLASSNONE: return _("none");
1566 case ELFCLASS32: return _("ELF32");
1567 case ELFCLASS64: return _("ELF64");
1569 sprintf (buff, _("<unknown: %x>"), elf_class);
1575 get_data_encoding (encoding)
1576 unsigned char encoding;
1578 static char buff [32];
1582 case ELFDATANONE: return _("none");
1583 case ELFDATA2LSB: return _("2's complement, little endian");
1584 case ELFDATA2MSB: return _("2's complement, big endian");
1586 sprintf (buff, _("<unknown: %x>"), encoding);
1592 get_osabi_name (osabi)
1593 unsigned char osabi;
1595 static char buff [32];
1599 case ELFOSABI_SYSV: return _("UNIX - System V");
1600 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
1601 case ELFOSABI_STANDALONE: return _("Standalone App");
1603 sprintf (buff, _("<unknown: %x>"), osabi);
1608 /* Decode the data held in 'elf_header'. */
1610 process_file_header ()
1612 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
1613 || elf_header.e_ident [EI_MAG1] != ELFMAG1
1614 || elf_header.e_ident [EI_MAG2] != ELFMAG2
1615 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
1618 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1626 printf (_("ELF Header:\n"));
1627 printf (_(" Magic: "));
1628 for (i = 0; i < EI_NIDENT; i ++)
1629 printf ("%2.2x ", elf_header.e_ident [i]);
1631 printf (_(" Class: %s\n"),
1632 get_elf_class (elf_header.e_ident [EI_CLASS]));
1633 printf (_(" Data: %s\n"),
1634 get_data_encoding (elf_header.e_ident [EI_DATA]));
1635 printf (_(" Version: %d %s\n"),
1636 elf_header.e_ident [EI_VERSION],
1637 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
1639 : (elf_header.e_ident [EI_VERSION] != EV_NONE
1642 printf (_(" OS/ABI: %s\n"),
1643 get_osabi_name (elf_header.e_ident [EI_OSABI]));
1644 printf (_(" ABI Version: %d\n"),
1645 elf_header.e_ident [EI_ABIVERSION]);
1646 printf (_(" Type: %s\n"),
1647 get_file_type (elf_header.e_type));
1648 printf (_(" Machine: %s\n"),
1649 get_machine_name (elf_header.e_machine));
1650 printf (_(" Version: 0x%lx\n"),
1651 (unsigned long) elf_header.e_version);
1652 printf (_(" Entry point address: 0x%lx\n"),
1653 (unsigned long) elf_header.e_entry);
1654 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1655 (long) elf_header.e_phoff);
1656 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1657 (long) elf_header.e_shoff);
1658 printf (_(" Flags: 0x%lx%s\n"),
1659 (unsigned long) elf_header.e_flags,
1660 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
1661 printf (_(" Size of this header: %ld (bytes)\n"),
1662 (long) elf_header.e_ehsize);
1663 printf (_(" Size of program headers: %ld (bytes)\n"),
1664 (long) elf_header.e_phentsize);
1665 printf (_(" Number of program headers: %ld\n"),
1666 (long) elf_header.e_phnum);
1667 printf (_(" Size of section headers: %ld (bytes)\n"),
1668 (long) elf_header.e_shentsize);
1669 printf (_(" Number of section headers: %ld\n"),
1670 (long) elf_header.e_shnum);
1671 printf (_(" Section header string table index: %ld\n"),
1672 (long) elf_header.e_shstrndx);
1680 get_32bit_program_headers (file, program_headers)
1682 Elf_Internal_Phdr * program_headers;
1684 Elf32_External_Phdr * phdrs;
1685 Elf32_External_Phdr * external;
1686 Elf32_Internal_Phdr * internal;
1689 GET_DATA_ALLOC (elf_header.e_phoff,
1690 elf_header.e_phentsize * elf_header.e_phnum,
1691 phdrs, Elf32_External_Phdr *, "program headers");
1693 for (i = 0, internal = program_headers, external = phdrs;
1694 i < elf_header.e_phnum;
1695 i ++, internal ++, external ++)
1697 internal->p_type = BYTE_GET (external->p_type);
1698 internal->p_offset = BYTE_GET (external->p_offset);
1699 internal->p_vaddr = BYTE_GET (external->p_vaddr);
1700 internal->p_paddr = BYTE_GET (external->p_paddr);
1701 internal->p_filesz = BYTE_GET (external->p_filesz);
1702 internal->p_memsz = BYTE_GET (external->p_memsz);
1703 internal->p_flags = BYTE_GET (external->p_flags);
1704 internal->p_align = BYTE_GET (external->p_align);
1713 get_64bit_program_headers (file, program_headers)
1715 Elf_Internal_Phdr * program_headers;
1717 Elf64_External_Phdr * phdrs;
1718 Elf64_External_Phdr * external;
1719 Elf64_Internal_Phdr * internal;
1722 GET_DATA_ALLOC (elf_header.e_phoff,
1723 elf_header.e_phentsize * elf_header.e_phnum,
1724 phdrs, Elf64_External_Phdr *, "program headers");
1726 for (i = 0, internal = program_headers, external = phdrs;
1727 i < elf_header.e_phnum;
1728 i ++, internal ++, external ++)
1730 internal->p_type = BYTE_GET (external->p_type);
1731 internal->p_flags = BYTE_GET (external->p_flags);
1732 internal->p_offset = BYTE_GET8 (external->p_offset);
1733 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
1734 internal->p_paddr = BYTE_GET8 (external->p_paddr);
1735 internal->p_filesz = BYTE_GET8 (external->p_filesz);
1736 internal->p_memsz = BYTE_GET8 (external->p_memsz);
1737 internal->p_align = BYTE_GET8 (external->p_align);
1746 process_program_headers (file)
1749 Elf_Internal_Phdr * program_headers;
1750 Elf_Internal_Phdr * segment;
1753 if (elf_header.e_phnum == 0)
1756 printf (_("\nThere are no program headers in this file.\n"));
1760 if (do_segments && !do_header)
1762 printf (_("\nElf file is %s\n"), get_file_type (elf_header.e_type));
1763 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header.e_entry);
1764 printf (_("There are %d program headers, starting at offset %lx:\n"),
1765 elf_header.e_phnum, (unsigned long) elf_header.e_phoff);
1768 program_headers = (Elf_Internal_Phdr *) malloc
1769 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
1771 if (program_headers == NULL)
1773 error (_("Out of memory\n"));
1778 i = get_32bit_program_headers (file, program_headers);
1780 i = get_64bit_program_headers (file, program_headers);
1784 free (program_headers);
1791 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
1793 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1800 for (i = 0, segment = program_headers;
1801 i < elf_header.e_phnum;
1806 printf (" %-11.11s ", get_segment_type (segment->p_type));
1807 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
1808 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
1809 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
1810 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
1811 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
1813 (segment->p_flags & PF_R ? 'R' : ' '),
1814 (segment->p_flags & PF_W ? 'W' : ' '),
1815 (segment->p_flags & PF_X ? 'E' : ' '));
1816 printf ("%#lx", (unsigned long) segment->p_align);
1819 switch (segment->p_type)
1823 loadaddr = (segment->p_vaddr & 0xfffff000)
1824 - (segment->p_offset & 0xfffff000);
1829 error (_("more than one dynamic segment\n"));
1831 dynamic_addr = segment->p_offset;
1832 dynamic_size = segment->p_filesz;
1836 if (fseek (file, segment->p_offset, SEEK_SET))
1837 error (_("Unable to find program interpreter name\n"));
1840 program_interpreter[0] = 0;
1841 fscanf (file, "%63s", program_interpreter);
1844 printf (_("\n [Requesting program interpreter: %s]"),
1845 program_interpreter);
1851 putc ('\n', stdout);
1860 if (do_segments && section_headers != NULL)
1862 printf (_("\n Section to Segment mapping:\n"));
1863 printf (_(" Segment Sections...\n"));
1865 assert (string_table != NULL);
1867 for (i = 0; i < elf_header.e_phnum; i++)
1870 Elf_Internal_Shdr * section;
1872 segment = program_headers + i;
1873 section = section_headers;
1875 printf (" %2.2d ", i);
1877 for (j = 0; j < elf_header.e_shnum; j++, section ++)
1879 if (section->sh_size > 0
1880 /* Compare allocated sections by VMA, unallocated
1881 sections by file offset. */
1882 && (section->sh_flags & SHF_ALLOC
1883 ? (section->sh_addr >= segment->p_vaddr
1884 && section->sh_addr + section->sh_size
1885 <= segment->p_vaddr + segment->p_memsz)
1886 : ((bfd_vma) section->sh_offset >= segment->p_offset
1887 && (section->sh_offset + section->sh_size
1888 <= segment->p_offset + segment->p_filesz))))
1889 printf ("%s ", SECTION_NAME (section));
1896 free (program_headers);
1903 get_32bit_section_headers (file)
1906 Elf32_External_Shdr * shdrs;
1907 Elf32_Internal_Shdr * internal;
1910 GET_DATA_ALLOC (elf_header.e_shoff,
1911 elf_header.e_shentsize * elf_header.e_shnum,
1912 shdrs, Elf32_External_Shdr *, "section headers");
1914 section_headers = (Elf_Internal_Shdr *) malloc
1915 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
1917 if (section_headers == NULL)
1919 error (_("Out of memory\n"));
1923 for (i = 0, internal = section_headers;
1924 i < elf_header.e_shnum;
1927 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
1928 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
1929 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
1930 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
1931 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
1932 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
1933 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
1934 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
1935 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
1936 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
1945 get_64bit_section_headers (file)
1948 Elf64_External_Shdr * shdrs;
1949 Elf64_Internal_Shdr * internal;
1952 GET_DATA_ALLOC (elf_header.e_shoff,
1953 elf_header.e_shentsize * elf_header.e_shnum,
1954 shdrs, Elf64_External_Shdr *, "section headers");
1956 section_headers = (Elf_Internal_Shdr *) malloc
1957 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
1959 if (section_headers == NULL)
1961 error (_("Out of memory\n"));
1965 for (i = 0, internal = section_headers;
1966 i < elf_header.e_shnum;
1969 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
1970 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
1971 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
1972 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
1973 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
1974 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
1975 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
1976 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
1977 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
1978 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
1986 static Elf_Internal_Sym *
1987 get_32bit_elf_symbols (file, offset, number)
1989 unsigned long offset;
1990 unsigned long number;
1992 Elf32_External_Sym * esyms;
1993 Elf_Internal_Sym * isyms;
1994 Elf_Internal_Sym * psym;
1997 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
1998 esyms, Elf32_External_Sym *, "symbols");
2000 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2004 error (_("Out of memory\n"));
2010 for (j = 0, psym = isyms;
2014 psym->st_name = BYTE_GET (esyms[j].st_name);
2015 psym->st_value = BYTE_GET (esyms[j].st_value);
2016 psym->st_size = BYTE_GET (esyms[j].st_size);
2017 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2018 psym->st_info = BYTE_GET (esyms[j].st_info);
2019 psym->st_other = BYTE_GET (esyms[j].st_other);
2027 static Elf_Internal_Sym *
2028 get_64bit_elf_symbols (file, offset, number)
2030 unsigned long offset;
2031 unsigned long number;
2033 Elf64_External_Sym * esyms;
2034 Elf_Internal_Sym * isyms;
2035 Elf_Internal_Sym * psym;
2038 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2039 esyms, Elf64_External_Sym *, "symbols");
2041 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2045 error (_("Out of memory\n"));
2051 for (j = 0, psym = isyms;
2055 psym->st_name = BYTE_GET (esyms[j].st_name);
2056 psym->st_info = BYTE_GET (esyms[j].st_info);
2057 psym->st_other = BYTE_GET (esyms[j].st_other);
2058 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2059 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2060 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2069 process_section_headers (file)
2072 Elf_Internal_Shdr * section;
2075 section_headers = NULL;
2077 if (elf_header.e_shnum == 0)
2080 printf (_("\nThere are no sections in this file.\n"));
2085 if (do_sections && !do_header)
2086 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2087 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2091 if (! get_32bit_section_headers (file))
2094 else if (! get_64bit_section_headers (file))
2097 /* Read in the string table, so that we have names to display. */
2098 section = section_headers + elf_header.e_shstrndx;
2100 if (section->sh_size != 0)
2102 unsigned long string_table_offset;
2104 string_table_offset = section->sh_offset;
2106 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2107 string_table, char *, "string table");
2110 /* Scan the sections for the dynamic symbol table
2111 and dynamic string table and debug sections. */
2112 dynamic_symbols = NULL;
2113 dynamic_strings = NULL;
2114 dynamic_syminfo = NULL;
2116 for (i = 0, section = section_headers;
2117 i < elf_header.e_shnum;
2120 char * name = SECTION_NAME (section);
2122 if (section->sh_type == SHT_DYNSYM)
2124 if (dynamic_symbols != NULL)
2126 error (_("File contains multiple dynamic symbol tables\n"));
2130 num_dynamic_syms = section->sh_size / section->sh_entsize;
2132 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2134 else if (section->sh_type == SHT_STRTAB
2135 && strcmp (name, ".dynstr") == 0)
2137 if (dynamic_strings != NULL)
2139 error (_("File contains multiple dynamic string tables\n"));
2143 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2144 dynamic_strings, char *, "dynamic strings");
2146 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2147 || do_debug_lines || do_debug_pubnames || do_debug_aranges)
2148 && strncmp (name, ".debug_", 7) == 0)
2153 || (do_debug_info && (strcmp (name, "info") == 0))
2154 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2155 || (do_debug_lines && (strcmp (name, "line") == 0))
2156 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2157 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2159 request_dump (i, DEBUG_DUMP);
2166 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2168 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2170 for (i = 0, section = section_headers;
2171 i < elf_header.e_shnum;
2174 printf (" [%2d] %-17.17s %-15.15s ",
2176 SECTION_NAME (section),
2177 get_section_type_name (section->sh_type));
2179 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
2180 (unsigned long) section->sh_addr,
2181 (unsigned long) section->sh_offset,
2182 (unsigned long) section->sh_size,
2183 (unsigned long) section->sh_entsize);
2185 printf (" %c%c%c %2ld %3lx %ld\n",
2186 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2187 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2188 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
2189 (unsigned long) section->sh_link,
2190 (unsigned long) section->sh_info,
2191 (unsigned long) section->sh_addralign);
2197 /* Process the reloc section. */
2199 process_relocs (file)
2202 unsigned long rel_size;
2203 unsigned long rel_offset;
2209 if (do_using_dynamic)
2211 int is_rela = FALSE;
2216 if (dynamic_info[DT_REL])
2218 rel_offset = dynamic_info[DT_REL];
2219 rel_size = dynamic_info[DT_RELSZ];
2222 else if (dynamic_info [DT_RELA])
2224 rel_offset = dynamic_info[DT_RELA];
2225 rel_size = dynamic_info[DT_RELASZ];
2228 else if (dynamic_info[DT_JMPREL])
2230 rel_offset = dynamic_info[DT_JMPREL];
2231 rel_size = dynamic_info[DT_PLTRELSZ];
2233 switch (dynamic_info[DT_PLTREL])
2250 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2251 rel_offset, rel_size);
2253 dump_relocations (file, rel_offset - loadaddr, rel_size,
2254 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2257 printf (_("\nThere are no dynamic relocations in this file.\n"));
2261 Elf32_Internal_Shdr * section;
2265 for (i = 0, section = section_headers;
2266 i < elf_header.e_shnum;
2269 if ( section->sh_type != SHT_RELA
2270 && section->sh_type != SHT_REL)
2273 rel_offset = section->sh_offset;
2274 rel_size = section->sh_size;
2278 Elf32_Internal_Shdr * strsec;
2279 Elf32_Internal_Shdr * symsec;
2280 Elf_Internal_Sym * symtab;
2283 unsigned long nsyms;
2285 printf (_("\nRelocation section "));
2287 if (string_table == NULL)
2288 printf ("%d", section->sh_name);
2290 printf ("'%s'", SECTION_NAME (section));
2292 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2293 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2295 symsec = section_headers + section->sh_link;
2297 nsyms = symsec->sh_size / symsec->sh_entsize;
2298 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2303 strsec = section_headers + symsec->sh_link;
2305 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2306 char *, "string table");
2308 is_rela = section->sh_type == SHT_RELA;
2310 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2320 printf (_("\nThere are no relocations in this file.\n"));
2328 dynamic_segment_mips_val (entry)
2329 Elf_Internal_Dyn * entry;
2331 switch (entry->d_tag)
2334 if (entry->d_un.d_val == 0)
2338 static const char * opts[] =
2340 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2341 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2342 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2343 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2348 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
2349 if (entry->d_un.d_val & (1 << cnt))
2351 printf ("%s%s", first ? "" : " ", opts[cnt]);
2358 case DT_MIPS_IVERSION:
2359 if (dynamic_strings != NULL)
2360 printf ("Interface Version: %s\n",
2361 dynamic_strings + entry->d_un.d_val);
2363 printf ("%ld\n", (long) entry->d_un.d_ptr);
2366 case DT_MIPS_TIME_STAMP:
2369 time_t time = entry->d_un.d_val;
2370 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
2371 printf ("Time Stamp: %s\n", timebuf);
2375 case DT_MIPS_RLD_VERSION:
2376 case DT_MIPS_LOCAL_GOTNO:
2377 case DT_MIPS_CONFLICTNO:
2378 case DT_MIPS_LIBLISTNO:
2379 case DT_MIPS_SYMTABNO:
2380 case DT_MIPS_UNREFEXTNO:
2381 case DT_MIPS_HIPAGENO:
2382 case DT_MIPS_DELTA_CLASS_NO:
2383 case DT_MIPS_DELTA_INSTANCE_NO:
2384 case DT_MIPS_DELTA_RELOC_NO:
2385 case DT_MIPS_DELTA_SYM_NO:
2386 case DT_MIPS_DELTA_CLASSSYM_NO:
2387 case DT_MIPS_COMPACT_SIZE:
2388 printf ("%ld\n", (long) entry->d_un.d_ptr);
2392 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2397 get_32bit_dynamic_segment (file)
2400 Elf32_External_Dyn * edyn;
2401 Elf_Internal_Dyn * entry;
2404 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2405 edyn, Elf32_External_Dyn *, "dynamic segment");
2407 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2408 how large this .dynamic is now. We can do this even before the byte
2409 swapping since the DT_NULL tag is recognizable. */
2411 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
2414 dynamic_segment = (Elf_Internal_Dyn *)
2415 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2417 if (dynamic_segment == NULL)
2419 error (_("Out of memory\n"));
2424 for (i = 0, entry = dynamic_segment;
2428 entry->d_tag = BYTE_GET (edyn [i].d_tag);
2429 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
2438 get_64bit_dynamic_segment (file)
2441 Elf64_External_Dyn * edyn;
2442 Elf_Internal_Dyn * entry;
2445 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2446 edyn, Elf64_External_Dyn *, "dynamic segment");
2448 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2449 how large this .dynamic is now. We can do this even before the byte
2450 swapping since the DT_NULL tag is recognizable. */
2452 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
2455 dynamic_segment = (Elf_Internal_Dyn *)
2456 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2458 if (dynamic_segment == NULL)
2460 error (_("Out of memory\n"));
2465 for (i = 0, entry = dynamic_segment;
2469 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
2470 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
2478 /* Parse and display the contents of the dynamic segment. */
2480 process_dynamic_segment (file)
2483 Elf_Internal_Dyn * entry;
2486 if (dynamic_size == 0)
2489 printf (_("\nThere is no dynamic segment in this file.\n"));
2496 if (! get_32bit_dynamic_segment (file))
2499 else if (! get_64bit_dynamic_segment (file))
2502 /* Find the appropriate symbol table. */
2503 if (dynamic_symbols == NULL)
2505 for (i = 0, entry = dynamic_segment;
2509 unsigned long offset;
2511 if (entry->d_tag != DT_SYMTAB)
2514 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
2516 /* Since we do not know how big the symbol table is,
2517 we default to reading in the entire file (!) and
2518 processing that. This is overkill, I know, but it
2520 offset = entry->d_un.d_val - loadaddr;
2522 if (fseek (file, 0, SEEK_END))
2523 error (_("Unable to seek to end of file!"));
2526 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
2528 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
2530 if (num_dynamic_syms < 1)
2532 error (_("Unable to determine the number of symbols to load\n"));
2536 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
2540 /* Similarly find a string table. */
2541 if (dynamic_strings == NULL)
2543 for (i = 0, entry = dynamic_segment;
2547 unsigned long offset;
2550 if (entry->d_tag != DT_STRTAB)
2553 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
2555 /* Since we do not know how big the string table is,
2556 we default to reading in the entire file (!) and
2557 processing that. This is overkill, I know, but it
2560 offset = entry->d_un.d_val - loadaddr;
2561 if (fseek (file, 0, SEEK_END))
2562 error (_("Unable to seek to end of file\n"));
2563 str_tab_len = ftell (file) - offset;
2565 if (str_tab_len < 1)
2568 (_("Unable to determine the length of the dynamic string table\n"));
2572 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
2573 "dynamic string table");
2579 /* And find the syminfo section if available. */
2580 if (dynamic_syminfo == NULL)
2582 unsigned int syminsz = 0;
2584 for (i = 0, entry = dynamic_segment;
2588 if (entry->d_tag == DT_SYMINENT)
2590 /* Note: these braces are necessary to avoid a syntax
2591 error from the SunOS4 C compiler. */
2592 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
2594 else if (entry->d_tag == DT_SYMINSZ)
2595 syminsz = entry->d_un.d_val;
2596 else if (entry->d_tag == DT_SYMINFO)
2597 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
2600 if (dynamic_syminfo_offset != 0 && syminsz != 0)
2602 Elf_External_Syminfo * extsyminfo;
2603 Elf_Internal_Syminfo * syminfo;
2605 /* There is a syminfo section. Read the data. */
2606 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
2607 Elf_External_Syminfo *, "symbol information");
2609 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
2610 if (dynamic_syminfo == NULL)
2612 error (_("Out of memory\n"));
2616 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
2617 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
2620 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
2621 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
2628 if (do_dynamic && dynamic_addr)
2629 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
2630 dynamic_addr, (long) dynamic_size);
2632 printf (_(" Tag Type Name/Value\n"));
2634 for (i = 0, entry = dynamic_segment;
2639 printf (_(" 0x%-8.8lx (%s)%*s"),
2640 (unsigned long) entry->d_tag,
2641 get_dynamic_type (entry->d_tag),
2642 27 - strlen (get_dynamic_type (entry->d_tag)),
2645 switch (entry->d_tag)
2651 if (entry->d_tag == DT_AUXILIARY)
2652 printf (_("Auxiliary library"));
2654 printf (_("Filter library"));
2656 if (dynamic_strings)
2657 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
2659 printf (": %#lx\n", (long) entry->d_un.d_val);
2666 printf (_("Flags:"));
2667 if (entry->d_un.d_val == 0)
2668 printf (_(" None\n"));
2671 unsigned long int val = entry->d_un.d_val;
2672 if (val & DTF_1_PARINIT)
2674 printf (" PARINIT");
2675 val ^= DTF_1_PARINIT;
2678 printf (" %lx", val);
2687 printf (_("Flags:"));
2688 if (entry->d_un.d_val == 0)
2689 printf (_(" None\n"));
2692 unsigned long int val = entry->d_un.d_val;
2693 if (val & DF_P1_LAZYLOAD)
2695 printf (" LAZYLOAD");
2696 val ^= DF_P1_LAZYLOAD;
2698 if (val & DF_P1_GROUPPERM)
2700 printf (" GROUPPERM");
2701 val ^= DF_P1_GROUPPERM;
2704 printf (" %lx", val);
2713 printf (_("Flags:"));
2714 if (entry->d_un.d_val == 0)
2715 printf (_(" None\n"));
2718 unsigned long int val = entry->d_un.d_val;
2724 if (val & DF_1_GLOBAL)
2729 if (val & DF_1_GROUP)
2734 if (val & DF_1_NODELETE)
2736 printf (" NODELETE");
2737 val ^= DF_1_NODELETE;
2739 if (val & DF_1_LOADFLTR)
2741 printf (" LOADFLTR");
2742 val ^= DF_1_LOADFLTR;
2744 if (val & DF_1_INITFIRST)
2746 printf (" INITFIRST");
2747 val ^= DF_1_INITFIRST;
2749 if (val & DF_1_NOOPEN)
2754 if (val & DF_1_ORIGIN)
2759 if (val & DF_1_DIRECT)
2764 if (val & DF_1_TRANS)
2769 if (val & DF_1_INTERPOSE)
2771 printf (" INTERPOSE");
2772 val ^= DF_1_INTERPOSE;
2775 printf (" %lx", val);
2783 puts (get_dynamic_type (entry->d_un.d_val));
2802 dynamic_info[entry->d_tag] = entry->d_un.d_val;
2808 if (dynamic_strings == NULL)
2811 name = dynamic_strings + entry->d_un.d_val;
2815 switch (entry->d_tag)
2818 printf (_("Shared library: [%s]"), name);
2820 if (strcmp (name, program_interpreter))
2823 printf (_(" program interpreter\n"));
2827 printf (_("Library soname: [%s]\n"), name);
2831 printf (_("Library rpath: [%s]\n"), name);
2835 printf ("%#lx\n", (long) entry->d_un.d_val);
2839 printf ("%#lx\n", (long) entry->d_un.d_val);
2853 case DT_INIT_ARRAYSZ:
2854 case DT_FINI_ARRAYSZ:
2856 printf ("%lu (bytes)\n", (unsigned long) entry->d_un.d_val);
2864 printf ("%lu\n", (unsigned long) entry->d_un.d_val);
2875 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
2879 name = dynamic_strings + entry->d_un.d_val;
2883 printf (_("Not needed object: [%s]\n"), name);
2888 printf ("%#lx\n", (long) entry->d_un.d_val);
2893 /* The value of this entry is ignored. */
2897 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
2898 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
2903 switch (elf_header.e_machine)
2906 case EM_MIPS_RS4_BE:
2907 dynamic_segment_mips_val (entry);
2910 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2921 get_ver_flags (flags)
2924 static char buff [32];
2931 if (flags & VER_FLG_BASE)
2932 strcat (buff, "BASE ");
2934 if (flags & VER_FLG_WEAK)
2936 if (flags & VER_FLG_BASE)
2937 strcat (buff, "| ");
2939 strcat (buff, "WEAK ");
2942 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
2943 strcat (buff, "| <unknown>");
2948 /* Display the contents of the version sections. */
2950 process_version_sections (file)
2953 Elf32_Internal_Shdr * section;
2960 for (i = 0, section = section_headers;
2961 i < elf_header.e_shnum;
2964 switch (section->sh_type)
2966 case SHT_GNU_verdef:
2968 Elf_External_Verdef * edefs;
2975 (_("\nVersion definition section '%s' contains %ld entries:\n"),
2976 SECTION_NAME (section), section->sh_info);
2978 printf (_(" Addr: 0x"));
2979 printf_vma (section->sh_addr);
2980 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
2981 (unsigned long) section->sh_offset, section->sh_link,
2982 SECTION_NAME (section_headers + section->sh_link));
2984 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2985 edefs, Elf_External_Verdef *,
2986 "version definition section");
2988 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
2991 Elf_External_Verdef * edef;
2992 Elf_Internal_Verdef ent;
2993 Elf_External_Verdaux * eaux;
2994 Elf_Internal_Verdaux aux;
2998 vstart = ((char *) edefs) + idx;
3000 edef = (Elf_External_Verdef *) vstart;
3002 ent.vd_version = BYTE_GET (edef->vd_version);
3003 ent.vd_flags = BYTE_GET (edef->vd_flags);
3004 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3005 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3006 ent.vd_hash = BYTE_GET (edef->vd_hash);
3007 ent.vd_aux = BYTE_GET (edef->vd_aux);
3008 ent.vd_next = BYTE_GET (edef->vd_next);
3010 printf (_(" %#06x: Rev: %d Flags: %s"),
3011 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3013 printf (_(" Index: %d Cnt: %d "),
3014 ent.vd_ndx, ent.vd_cnt);
3016 vstart += ent.vd_aux;
3018 eaux = (Elf_External_Verdaux *) vstart;
3020 aux.vda_name = BYTE_GET (eaux->vda_name);
3021 aux.vda_next = BYTE_GET (eaux->vda_next);
3023 if (dynamic_strings)
3024 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3026 printf (_("Name index: %ld\n"), aux.vda_name);
3028 isum = idx + ent.vd_aux;
3030 for (j = 1; j < ent.vd_cnt; j ++)
3032 isum += aux.vda_next;
3033 vstart += aux.vda_next;
3035 eaux = (Elf_External_Verdaux *) vstart;
3037 aux.vda_name = BYTE_GET (eaux->vda_name);
3038 aux.vda_next = BYTE_GET (eaux->vda_next);
3040 if (dynamic_strings)
3041 printf (_(" %#06x: Parent %d: %s\n"),
3042 isum, j, dynamic_strings + aux.vda_name);
3044 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3045 isum, j, aux.vda_name);
3055 case SHT_GNU_verneed:
3057 Elf_External_Verneed * eneed;
3063 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3064 SECTION_NAME (section), section->sh_info);
3066 printf (_(" Addr: 0x"));
3067 printf_vma (section->sh_addr);
3068 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3069 (unsigned long) section->sh_offset, section->sh_link,
3070 SECTION_NAME (section_headers + section->sh_link));
3072 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3073 eneed, Elf_External_Verneed *,
3074 "version need section");
3076 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3078 Elf_External_Verneed * entry;
3079 Elf_Internal_Verneed ent;
3084 vstart = ((char *) eneed) + idx;
3086 entry = (Elf_External_Verneed *) vstart;
3088 ent.vn_version = BYTE_GET (entry->vn_version);
3089 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3090 ent.vn_file = BYTE_GET (entry->vn_file);
3091 ent.vn_aux = BYTE_GET (entry->vn_aux);
3092 ent.vn_next = BYTE_GET (entry->vn_next);
3094 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3096 if (dynamic_strings)
3097 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3099 printf (_(" File: %lx"), ent.vn_file);
3101 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3103 vstart += ent.vn_aux;
3105 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3107 Elf_External_Vernaux * eaux;
3108 Elf_Internal_Vernaux aux;
3110 eaux = (Elf_External_Vernaux *) vstart;
3112 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3113 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3114 aux.vna_other = BYTE_GET (eaux->vna_other);
3115 aux.vna_name = BYTE_GET (eaux->vna_name);
3116 aux.vna_next = BYTE_GET (eaux->vna_next);
3118 if (dynamic_strings)
3119 printf (_(" %#06x: Name: %s"),
3120 isum, dynamic_strings + aux.vna_name);
3122 printf (_(" %#06x: Name index: %lx"),
3123 isum, aux.vna_name);
3125 printf (_(" Flags: %s Version: %d\n"),
3126 get_ver_flags (aux.vna_flags), aux.vna_other);
3128 isum += aux.vna_next;
3129 vstart += aux.vna_next;
3139 case SHT_GNU_versym:
3141 Elf32_Internal_Shdr * link_section;
3144 unsigned char * edata;
3145 unsigned short * data;
3147 Elf_Internal_Sym * symbols;
3148 Elf32_Internal_Shdr * string_sec;
3150 link_section = section_headers + section->sh_link;
3151 total = section->sh_size / section->sh_entsize;
3155 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3156 link_section->sh_size / link_section->sh_entsize);
3158 string_sec = section_headers + link_section->sh_link;
3160 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3161 strtab, char *, "version string table");
3163 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3164 SECTION_NAME (section), total);
3166 printf (_(" Addr: "));
3167 printf_vma (section->sh_addr);
3168 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3169 (unsigned long) section->sh_offset, section->sh_link,
3170 SECTION_NAME (link_section));
3172 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3174 total * sizeof (short), edata,
3175 unsigned char *, "version symbol data");
3177 data = (unsigned short *) malloc (total * sizeof (short));
3179 for (cnt = total; cnt --;)
3180 data [cnt] = byte_get (edata + cnt * sizeof (short),
3185 for (cnt = 0; cnt < total; cnt += 4)
3189 printf (" %03x:", cnt);
3191 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
3192 switch (data [cnt + j])
3195 fputs (_(" 0 (*local*) "), stdout);
3199 fputs (_(" 1 (*global*) "), stdout);
3203 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
3204 data [cnt + j] & 0x8000 ? 'h' : ' ');
3206 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
3207 && section_headers[symbols [cnt + j].st_shndx].sh_type
3210 /* We must test both. */
3211 Elf_Internal_Verneed ivn;
3212 unsigned long offset;
3214 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3219 Elf_External_Verneed evn;
3220 Elf_External_Vernaux evna;
3221 Elf_Internal_Vernaux ivna;
3222 unsigned long vna_off;
3224 GET_DATA (offset, evn, "version need");
3226 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3227 ivn.vn_next = BYTE_GET (evn.vn_next);
3229 vna_off = offset + ivn.vn_aux;
3233 GET_DATA (vna_off, evna,
3234 "version need aux (1)");
3236 ivna.vna_next = BYTE_GET (evna.vna_next);
3237 ivna.vna_other = BYTE_GET (evna.vna_other);
3239 vna_off += ivna.vna_next;
3241 while (ivna.vna_other != data [cnt + j]
3242 && ivna.vna_next != 0);
3244 if (ivna.vna_other == data [cnt + j])
3246 ivna.vna_name = BYTE_GET (evna.vna_name);
3248 nn += printf ("(%s%-*s",
3249 strtab + ivna.vna_name,
3255 else if (ivn.vn_next == 0)
3257 if (data [cnt + j] != 0x8001)
3259 Elf_Internal_Verdef ivd;
3260 Elf_External_Verdef evd;
3262 offset = version_info
3263 [DT_VERSIONTAGIDX (DT_VERDEF)]
3268 GET_DATA (offset, evd,
3269 "version definition");
3271 ivd.vd_next = BYTE_GET (evd.vd_next);
3272 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3274 offset += ivd.vd_next;
3277 != (data [cnt + j] & 0x7fff)
3278 && ivd.vd_next != 0);
3281 == (data [cnt + j] & 0x7fff))
3283 Elf_External_Verdaux evda;
3284 Elf_Internal_Verdaux ivda;
3286 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3288 GET_DATA (offset + ivd.vd_aux, evda,
3289 "version definition aux");
3292 BYTE_GET (evda.vda_name);
3296 strtab + ivda.vda_name,
3307 offset += ivn.vn_next;
3309 while (ivn.vn_next);
3311 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
3313 Elf_Internal_Verneed ivn;
3314 unsigned long offset;
3316 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3321 Elf_Internal_Vernaux ivna;
3322 Elf_External_Verneed evn;
3323 Elf_External_Vernaux evna;
3324 unsigned long a_off;
3326 GET_DATA (offset, evn, "version need");
3328 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3329 ivn.vn_next = BYTE_GET (evn.vn_next);
3331 a_off = offset + ivn.vn_aux;
3335 GET_DATA (a_off, evna,
3336 "version need aux (2)");
3338 ivna.vna_next = BYTE_GET (evna.vna_next);
3339 ivna.vna_other = BYTE_GET (evna.vna_other);
3341 a_off += ivna.vna_next;
3343 while (ivna.vna_other != data [cnt + j]
3344 && ivna.vna_next != 0);
3346 if (ivna.vna_other == data [cnt + j])
3348 ivna.vna_name = BYTE_GET (evna.vna_name);
3350 nn += printf ("(%s%-*s",
3351 strtab + ivna.vna_name,
3358 offset += ivn.vn_next;
3360 while (ivn.vn_next);
3362 else if (data [cnt + j] != 0x8001)
3364 Elf_Internal_Verdef ivd;
3365 Elf_External_Verdef evd;
3366 unsigned long offset;
3368 offset = version_info
3369 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
3373 GET_DATA (offset, evd, "version def");
3375 ivd.vd_next = BYTE_GET (evd.vd_next);
3376 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3378 offset += ivd.vd_next;
3380 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
3381 && ivd.vd_next != 0);
3383 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
3385 Elf_External_Verdaux evda;
3386 Elf_Internal_Verdaux ivda;
3388 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3390 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
3391 evda, "version def aux");
3393 ivda.vda_name = BYTE_GET (evda.vda_name);
3395 nn += printf ("(%s%-*s",
3396 strtab + ivda.vda_name,
3404 printf ("%*c", 18 - nn, ' ');
3422 printf (_("\nNo version information found in this file.\n"));
3428 get_symbol_binding (binding)
3429 unsigned int binding;
3431 static char buff [32];
3435 case STB_LOCAL: return _("LOCAL");
3436 case STB_GLOBAL: return _("GLOBAL");
3437 case STB_WEAK: return _("WEAK");
3439 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
3440 sprintf (buff, _("<processor specific>: %d"), binding);
3441 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3442 sprintf (buff, _("<OS specific>: %d"), binding);
3444 sprintf (buff, _("<unknown>: %d"), binding);
3450 get_symbol_type (type)
3453 static char buff [32];
3457 case STT_NOTYPE: return _("NOTYPE");
3458 case STT_OBJECT: return _("OBJECT");
3459 case STT_FUNC: return _("FUNC");
3460 case STT_SECTION: return _("SECTION");
3461 case STT_FILE: return _("FILE");
3463 if (type >= STT_LOPROC && type <= STT_HIPROC)
3465 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3466 return _("THUMB_FUNC");
3468 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
3469 return _("REGISTER");
3471 sprintf (buff, _("<processor specific>: %d"), type);
3473 else if (type >= STT_LOOS && type <= STT_HIOS)
3474 sprintf (buff, _("<OS specific>: %d"), type);
3476 sprintf (buff, _("<unknown>: %d"), type);
3482 get_symbol_index_type (type)
3487 case SHN_UNDEF: return "UND";
3488 case SHN_ABS: return "ABS";
3489 case SHN_COMMON: return "COM";
3491 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
3493 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
3495 else if (type >= SHN_LOOS && type <= SHN_HIOS)
3499 static char buff [32];
3501 sprintf (buff, "%3d", type);
3509 get_dynamic_data (file, number)
3511 unsigned int number;
3516 e_data = (char *) malloc (number * 4);
3520 error (_("Out of memory\n"));
3524 if (fread (e_data, 4, number, file) != number)
3526 error (_("Unable to read in dynamic data\n"));
3530 i_data = (int *) malloc (number * sizeof (* i_data));
3534 error (_("Out of memory\n"));
3540 i_data [number] = byte_get (e_data + number * 4, 4);
3547 /* Dump the symbol table */
3549 process_symbol_table (file)
3552 Elf32_Internal_Shdr * section;
3557 int * buckets = NULL;
3558 int * chains = NULL;
3560 if (! do_syms && !do_histogram)
3563 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
3566 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
3568 error (_("Unable to seek to start of dynamic information"));
3572 if (fread (nb, sizeof (nb), 1, file) != 1)
3574 error (_("Failed to read in number of buckets\n"));
3578 if (fread (nc, sizeof (nc), 1, file) != 1)
3580 error (_("Failed to read in number of chains\n"));
3584 nbuckets = byte_get (nb, 4);
3585 nchains = byte_get (nc, 4);
3587 buckets = get_dynamic_data (file, nbuckets);
3588 chains = get_dynamic_data (file, nchains);
3590 if (buckets == NULL || chains == NULL)
3595 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
3600 printf (_("\nSymbol table for image:\n"));
3601 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3603 for (hn = 0; hn < nbuckets; hn++)
3608 for (si = buckets [hn]; si; si = chains [si])
3610 Elf_Internal_Sym * psym;
3612 psym = dynamic_symbols + si;
3614 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3616 (unsigned long) psym->st_value,
3617 (unsigned long) psym->st_size,
3618 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
3619 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
3622 printf ("%3.3s", get_symbol_index_type (psym->st_shndx));
3624 printf (" %s\n", dynamic_strings + psym->st_name);
3628 else if (do_syms && !do_using_dynamic)
3632 for (i = 0, section = section_headers;
3633 i < elf_header.e_shnum;
3638 Elf_Internal_Sym * symtab;
3639 Elf_Internal_Sym * psym;
3642 if ( section->sh_type != SHT_SYMTAB
3643 && section->sh_type != SHT_DYNSYM)
3646 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3647 SECTION_NAME (section),
3648 (unsigned long) (section->sh_size / section->sh_entsize));
3649 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3652 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
3653 section->sh_size / section->sh_entsize);
3657 if (section->sh_link == elf_header.e_shstrndx)
3658 strtab = string_table;
3661 Elf32_Internal_Shdr * string_sec;
3663 string_sec = section_headers + section->sh_link;
3665 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3666 strtab, char *, "string table");
3669 for (si = 0, psym = symtab;
3670 si < section->sh_size / section->sh_entsize;
3673 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3675 (unsigned long) psym->st_value,
3676 (unsigned long) psym->st_size,
3677 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
3678 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
3681 printf ("%4s", get_symbol_index_type (psym->st_shndx));
3683 printf (" %s", strtab + psym->st_name);
3685 if (section->sh_type == SHT_DYNSYM &&
3686 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
3688 unsigned char data[2];
3689 unsigned short vers_data;
3690 unsigned long offset;
3694 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3697 GET_DATA (offset + si * sizeof (vers_data), data,
3700 vers_data = byte_get (data, 2);
3702 is_nobits = psym->st_shndx < SHN_LORESERVE ?
3703 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
3706 check_def = (psym->st_shndx != SHN_UNDEF);
3708 if ((vers_data & 0x8000) || vers_data > 1)
3710 if (is_nobits || ! check_def)
3712 Elf_External_Verneed evn;
3713 Elf_Internal_Verneed ivn;
3714 Elf_Internal_Vernaux ivna;
3716 /* We must test both. */
3717 offset = version_info
3718 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
3720 GET_DATA (offset, evn, "version need");
3722 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3723 ivn.vn_next = BYTE_GET (evn.vn_next);
3727 unsigned long vna_off;
3729 vna_off = offset + ivn.vn_aux;
3733 Elf_External_Vernaux evna;
3735 GET_DATA (vna_off, evna,
3736 "version need aux (3)");
3738 ivna.vna_other = BYTE_GET (evna.vna_other);
3739 ivna.vna_next = BYTE_GET (evna.vna_next);
3740 ivna.vna_name = BYTE_GET (evna.vna_name);
3742 vna_off += ivna.vna_next;
3744 while (ivna.vna_other != vers_data
3745 && ivna.vna_next != 0);
3747 if (ivna.vna_other == vers_data)
3750 offset += ivn.vn_next;
3752 while (ivn.vn_next != 0);
3754 if (ivna.vna_other == vers_data)
3757 strtab + ivna.vna_name, ivna.vna_other);
3760 else if (! is_nobits)
3761 error (_("bad dynamic symbol"));
3768 if (vers_data != 0x8001)
3770 Elf_Internal_Verdef ivd;
3771 Elf_Internal_Verdaux ivda;
3772 Elf_External_Verdaux evda;
3773 unsigned long offset;
3776 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
3781 Elf_External_Verdef evd;
3783 GET_DATA (offset, evd, "version def");
3785 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3786 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3787 ivd.vd_next = BYTE_GET (evd.vd_next);
3789 offset += ivd.vd_next;
3791 while (ivd.vd_ndx != (vers_data & 0x7fff)
3792 && ivd.vd_next != 0);
3794 offset -= ivd.vd_next;
3795 offset += ivd.vd_aux;
3797 GET_DATA (offset, evda, "version def aux");
3799 ivda.vda_name = BYTE_GET (evda.vda_name);
3801 if (psym->st_name != ivda.vda_name)
3802 printf ((vers_data & 0x8000)
3804 strtab + ivda.vda_name);
3814 if (strtab != string_table)
3820 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
3822 if (do_histogram && buckets != NULL)
3829 int nzero_counts = 0;
3832 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
3834 printf (_(" Length Number %% of total Coverage\n"));
3836 lengths = (int *) calloc (nbuckets, sizeof (int));
3837 if (lengths == NULL)
3839 error (_("Out of memory"));
3842 for (hn = 0; hn < nbuckets; ++hn)
3847 for (si = buckets[hn]; si; si = chains[si])
3850 if (maxlength < ++lengths[hn])
3855 counts = (int *) calloc (maxlength + 1, sizeof (int));
3858 error (_("Out of memory"));
3862 for (hn = 0; hn < nbuckets; ++hn)
3863 ++ counts [lengths [hn]];
3865 printf (" 0 %-10d (%5.1f%%)\n",
3866 counts[0], (counts[0] * 100.0) / nbuckets);
3867 for (si = 1; si <= maxlength; ++si)
3869 nzero_counts += counts[si] * si;
3870 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
3871 si, counts[si], (counts[si] * 100.0) / nbuckets,
3872 (nzero_counts * 100.0) / nsyms);
3879 if (buckets != NULL)
3889 process_syminfo (file)
3890 FILE * file ATTRIBUTE_UNUSED;
3894 if (dynamic_syminfo == NULL
3896 /* No syminfo, this is ok. */
3899 /* There better should be a dynamic symbol section. */
3900 if (dynamic_symbols == NULL || dynamic_strings == NULL)
3904 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
3905 dynamic_syminfo_offset, dynamic_syminfo_nent);
3907 printf (_(" Num: Name BoundTo Flags\n"));
3908 for (i = 0; i < dynamic_syminfo_nent; ++i)
3910 unsigned short int flags = dynamic_syminfo[i].si_flags;
3912 printf ("%4d: %-30s ", i,
3913 dynamic_strings + dynamic_symbols[i].st_name);
3915 switch (dynamic_syminfo[i].si_boundto)
3917 case SYMINFO_BT_SELF:
3918 fputs ("SELF ", stdout);
3920 case SYMINFO_BT_PARENT:
3921 fputs ("PARENT ", stdout);
3924 if (dynamic_syminfo[i].si_boundto > 0
3925 && dynamic_syminfo[i].si_boundto < dynamic_size)
3928 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
3930 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
3934 if (flags & SYMINFO_FLG_DIRECT)
3936 if (flags & SYMINFO_FLG_PASSTHRU)
3937 printf (" PASSTHRU");
3938 if (flags & SYMINFO_FLG_COPY)
3940 if (flags & SYMINFO_FLG_LAZYLOAD)
3941 printf (" LAZYLOAD");
3949 #ifdef SUPPORT_DISASSEMBLY
3951 disassemble_section (section, file)
3952 Elf32_Internal_Shdr * section;
3955 printf (_("\nAssembly dump of section %s\n"),
3956 SECTION_NAME (section));
3958 /* XXX -- to be done --- XXX */
3965 dump_section (section, file)
3966 Elf32_Internal_Shdr * section;
3969 bfd_size_type bytes;
3971 unsigned char * data;
3972 unsigned char * start;
3974 bytes = section->sh_size;
3978 printf (_("\nSection '%s' has no data to dump.\n"),
3979 SECTION_NAME (section));
3983 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
3985 addr = section->sh_addr;
3987 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
3998 lbytes = (bytes > 16 ? 16 : bytes);
4000 printf (" 0x%8.8lx ", (unsigned long) addr);
4002 switch (elf_header.e_ident [EI_DATA])
4006 for (j = 15; j >= 0; j --)
4009 printf ("%2.2x", data [j]);
4019 for (j = 0; j < 16; j++)
4022 printf ("%2.2x", data [j]);
4032 for (j = 0; j < lbytes; j++)
4035 if (k >= ' ' && k < 0x80)
4054 static unsigned long int
4055 read_leb128 (data, length_return, sign)
4056 unsigned char * data;
4057 int * length_return;
4060 unsigned long int result = 0;
4061 unsigned int num_read = 0;
4070 result |= (byte & 0x7f) << shift;
4075 while (byte & 0x80);
4077 if (length_return != NULL)
4078 * length_return = num_read;
4080 if (sign && (shift < 32) && (byte & 0x40))
4081 result |= -1 << shift;
4086 typedef struct State_Machine_Registers
4088 unsigned long address;
4091 unsigned int column;
4095 /* This variable hold the number of the last entry seen
4096 in the File Table. */
4097 unsigned int last_file_entry;
4100 static SMR state_machine_regs;
4103 reset_state_machine (is_stmt)
4106 state_machine_regs.address = 0;
4107 state_machine_regs.file = 1;
4108 state_machine_regs.line = 1;
4109 state_machine_regs.column = 0;
4110 state_machine_regs.is_stmt = is_stmt;
4111 state_machine_regs.basic_block = 0;
4112 state_machine_regs.end_sequence = 0;
4113 state_machine_regs.last_file_entry = 0;
4116 /* Handled an extend line op. Returns true if this is the end
4119 process_extended_line_op (data, is_stmt)
4120 unsigned char * data;
4123 unsigned char op_code;
4126 unsigned char * name;
4129 len = read_leb128 (data, & bytes_read, 0);
4134 warn (_("badly formed extended line op encountered!"));
4139 op_code = * data ++;
4141 printf (_(" Extended opcode %d: "), op_code);
4145 case DW_LNE_end_sequence:
4146 printf (_("End of Sequence\n\n"));
4147 reset_state_machine (is_stmt);
4150 case DW_LNE_set_address:
4151 /* XXX - assumption here that address size is 4! */
4152 adr = byte_get (data, 4);
4153 printf (_("set Address to 0x%lx\n"), adr);
4154 state_machine_regs.address = adr;
4157 case DW_LNE_define_file:
4158 printf (_(" define new File Table entry\n"));
4159 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4161 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4163 data += strlen (data) + 1;
4164 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4166 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4168 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4169 printf (_("%s\n\n"), name);
4173 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4182 display_debug_lines (section, start, file)
4183 Elf32_Internal_Shdr * section;
4184 unsigned char * start;
4185 FILE * file ATTRIBUTE_UNUSED;
4187 DWARF2_External_LineInfo * external;
4188 DWARF2_Internal_LineInfo info;
4189 unsigned char * standard_opcodes;
4190 unsigned char * data = start;
4191 unsigned char * end = start + section->sh_size;
4192 unsigned char * end_of_sequence;
4195 printf (_("\nDump of debug contents of section %s:\n\n"),
4196 SECTION_NAME (section));
4200 external = (DWARF2_External_LineInfo *) data;
4202 /* Check the length of the block. */
4203 info.li_length = BYTE_GET (external->li_length);
4204 if (info.li_length > section->sh_size)
4207 (_("The line info appears to be corrupt - the section is too small\n"));
4211 /* Check its version number. */
4212 info.li_version = BYTE_GET (external->li_version);
4213 if (info.li_version != 2)
4215 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4219 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4220 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4221 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4222 info.li_line_base = BYTE_GET (external->li_line_base);
4223 info.li_line_range = BYTE_GET (external->li_line_range);
4224 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4226 /* Sign extend the line base field. */
4227 info.li_line_base <<= 24;
4228 info.li_line_base >>= 24;
4230 printf (_(" Length: %ld\n"), info.li_length);
4231 printf (_(" DWARF Version: %d\n"), info.li_version);
4232 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4233 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4234 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4235 printf (_(" Line Base: %d\n"), info.li_line_base);
4236 printf (_(" Line Range: %d\n"), info.li_line_range);
4237 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
4239 end_of_sequence = data + info.li_length + sizeof (info.li_length);
4241 reset_state_machine (info.li_default_is_stmt);
4243 /* Display the contents of the Opcodes table. */
4244 standard_opcodes = data + sizeof (* external);
4246 printf (_("\n Opcodes:\n"));
4248 for (i = 1; i < info.li_opcode_base; i++)
4249 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i]);
4251 /* Display the contents of the Directory table. */
4252 data = standard_opcodes + info.li_opcode_base - 1;
4255 printf (_("\n The Directory Table is empty.\n"));
4258 printf (_("\n The Directory Table:\n"));
4262 printf (_(" %s\n"), data);
4264 data += strlen (data) + 1;
4268 /* Skip the NUL at the end of the table. */
4271 /* Display the contents of the File Name table. */
4273 printf (_("\n The File Name Table is empty.\n"));
4276 printf (_("\n The File Name Table:\n"));
4277 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4284 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4287 data += strlen (data) + 1;
4289 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4291 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4293 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4295 printf (_("%s\n"), name);
4299 /* Skip the NUL at the end of the table. */
4302 /* Now display the statements. */
4303 printf (_("\n Line Number Statements:\n"));
4306 while (data < end_of_sequence)
4308 unsigned char op_code;
4312 op_code = * data ++;
4316 case DW_LNS_extended_op:
4317 data += process_extended_line_op (data, info.li_default_is_stmt);
4321 printf (_(" Copy\n"));
4324 case DW_LNS_advance_pc:
4325 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
4327 state_machine_regs.address += adv;
4328 printf (_(" Advance PC by %d to %lx\n"), adv,
4329 state_machine_regs.address);
4332 case DW_LNS_advance_line:
4333 adv = read_leb128 (data, & bytes_read, 1);
4335 state_machine_regs.line += adv;
4336 printf (_(" Advance Line by %d to %d\n"), adv,
4337 state_machine_regs.line);
4340 case DW_LNS_set_file:
4341 adv = read_leb128 (data, & bytes_read, 0);
4343 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4345 state_machine_regs.file = adv;
4348 case DW_LNS_set_column:
4349 adv = read_leb128 (data, & bytes_read, 0);
4351 printf (_(" Set column to %d\n"), adv);
4352 state_machine_regs.column = adv;
4355 case DW_LNS_negate_stmt:
4356 adv = state_machine_regs.is_stmt;
4358 printf (_(" Set is_stmt to %d\n"), adv);
4359 state_machine_regs.is_stmt = adv;
4362 case DW_LNS_set_basic_block:
4363 printf (_(" Set basic block\n"));
4364 state_machine_regs.basic_block = 1;
4367 case DW_LNS_const_add_pc:
4368 adv = (255 - info.li_opcode_base) / info.li_line_range;
4369 state_machine_regs.address += adv;
4370 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
4371 state_machine_regs.address);
4374 case DW_LNS_fixed_advance_pc:
4375 adv = byte_get (data, 2);
4377 state_machine_regs.address += adv;
4378 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4379 adv, state_machine_regs.address);
4383 op_code -= info.li_opcode_base;
4384 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
4385 state_machine_regs.address += adv;
4386 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4387 op_code, adv, state_machine_regs.address);
4388 adv += (op_code % info.li_line_range) + info.li_line_base;
4389 state_machine_regs.line += adv;
4390 printf (_(" and Line by %d to %d\n"),
4391 adv, state_machine_regs.line);
4402 display_debug_pubnames (section, start, file)
4403 Elf32_Internal_Shdr * section;
4404 unsigned char * start;
4405 FILE * file ATTRIBUTE_UNUSED;
4407 DWARF2_External_PubNames * external;
4408 DWARF2_Internal_PubNames pubnames;
4409 unsigned char * end;
4411 end = start + section->sh_size;
4413 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
4417 unsigned char * data;
4418 unsigned long offset;
4420 external = (DWARF2_External_PubNames *) start;
4422 pubnames.pn_length = BYTE_GET (external->pn_length);
4423 pubnames.pn_version = BYTE_GET (external->pn_version);
4424 pubnames.pn_offset = BYTE_GET (external->pn_offset);
4425 pubnames.pn_size = BYTE_GET (external->pn_size);
4427 data = start + sizeof (* external);
4428 start += pubnames.pn_length + sizeof (external->pn_length);
4430 if (pubnames.pn_version != 2)
4432 warn (_("Only DWARF 2 pubnames are currently supported"));
4436 printf (_(" Length: %ld\n"),
4437 pubnames.pn_length);
4438 printf (_(" Version: %d\n"),
4439 pubnames.pn_version);
4440 printf (_(" Offset into .debug_info section: %ld\n"),
4441 pubnames.pn_offset);
4442 printf (_(" Size of area in .debug_info section: %ld\n"),
4445 printf (_("\n Offset\tName\n"));
4449 offset = byte_get (data, 4);
4454 printf (" %ld\t\t%s\n", offset, data);
4455 data += strlen (data) + 1;
4458 while (offset != 0);
4471 case DW_TAG_padding: return "DW_TAG_padding";
4472 case DW_TAG_array_type: return "DW_TAG_array_type";
4473 case DW_TAG_class_type: return "DW_TAG_class_type";
4474 case DW_TAG_entry_point: return "DW_TAG_entry_point";
4475 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
4476 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
4477 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
4478 case DW_TAG_label: return "DW_TAG_label";
4479 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
4480 case DW_TAG_member: return "DW_TAG_member";
4481 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
4482 case DW_TAG_reference_type: return "DW_TAG_reference_type";
4483 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
4484 case DW_TAG_string_type: return "DW_TAG_string_type";
4485 case DW_TAG_structure_type: return "DW_TAG_structure_type";
4486 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
4487 case DW_TAG_typedef: return "DW_TAG_typedef";
4488 case DW_TAG_union_type: return "DW_TAG_union_type";
4489 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
4490 case DW_TAG_variant: return "DW_TAG_variant";
4491 case DW_TAG_common_block: return "DW_TAG_common_block";
4492 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
4493 case DW_TAG_inheritance: return "DW_TAG_inheritance";
4494 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
4495 case DW_TAG_module: return "DW_TAG_module";
4496 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
4497 case DW_TAG_set_type: return "DW_TAG_set_type";
4498 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
4499 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
4500 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
4501 case DW_TAG_base_type: return "DW_TAG_base_type";
4502 case DW_TAG_catch_block: return "DW_TAG_catch_block";
4503 case DW_TAG_const_type: return "DW_TAG_const_type";
4504 case DW_TAG_constant: return "DW_TAG_constant";
4505 case DW_TAG_enumerator: return "DW_TAG_enumerator";
4506 case DW_TAG_file_type: return "DW_TAG_file_type";
4507 case DW_TAG_friend: return "DW_TAG_friend";
4508 case DW_TAG_namelist: return "DW_TAG_namelist";
4509 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
4510 case DW_TAG_packed_type: return "DW_TAG_packed_type";
4511 case DW_TAG_subprogram: return "DW_TAG_subprogram";
4512 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
4513 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
4514 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
4515 case DW_TAG_try_block: return "DW_TAG_try_block";
4516 case DW_TAG_variant_part: return "DW_TAG_variant_part";
4517 case DW_TAG_variable: return "DW_TAG_variable";
4518 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
4519 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
4520 case DW_TAG_format_label: return "DW_TAG_format_label";
4521 case DW_TAG_function_template: return "DW_TAG_function_template";
4522 case DW_TAG_class_template: return "DW_TAG_class_template";
4525 static char buffer [100];
4527 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
4534 get_AT_name (attribute)
4535 unsigned long attribute;
4539 case DW_AT_sibling: return "DW_AT_sibling";
4540 case DW_AT_location: return "DW_AT_location";
4541 case DW_AT_name: return "DW_AT_name";
4542 case DW_AT_ordering: return "DW_AT_ordering";
4543 case DW_AT_subscr_data: return "DW_AT_subscr_data";
4544 case DW_AT_byte_size: return "DW_AT_byte_size";
4545 case DW_AT_bit_offset: return "DW_AT_bit_offset";
4546 case DW_AT_bit_size: return "DW_AT_bit_size";
4547 case DW_AT_element_list: return "DW_AT_element_list";
4548 case DW_AT_stmt_list: return "DW_AT_stmt_list";
4549 case DW_AT_low_pc: return "DW_AT_low_pc";
4550 case DW_AT_high_pc: return "DW_AT_high_pc";
4551 case DW_AT_language: return "DW_AT_language";
4552 case DW_AT_member: return "DW_AT_member";
4553 case DW_AT_discr: return "DW_AT_discr";
4554 case DW_AT_discr_value: return "DW_AT_discr_value";
4555 case DW_AT_visibility: return "DW_AT_visibility";
4556 case DW_AT_import: return "DW_AT_import";
4557 case DW_AT_string_length: return "DW_AT_string_length";
4558 case DW_AT_common_reference: return "DW_AT_common_reference";
4559 case DW_AT_comp_dir: return "DW_AT_comp_dir";
4560 case DW_AT_const_value: return "DW_AT_const_value";
4561 case DW_AT_containing_type: return "DW_AT_containing_type";
4562 case DW_AT_default_value: return "DW_AT_default_value";
4563 case DW_AT_inline: return "DW_AT_inline";
4564 case DW_AT_is_optional: return "DW_AT_is_optional";
4565 case DW_AT_lower_bound: return "DW_AT_lower_bound";
4566 case DW_AT_producer: return "DW_AT_producer";
4567 case DW_AT_prototyped: return "DW_AT_prototyped";
4568 case DW_AT_return_addr: return "DW_AT_return_addr";
4569 case DW_AT_start_scope: return "DW_AT_start_scope";
4570 case DW_AT_stride_size: return "DW_AT_stride_size";
4571 case DW_AT_upper_bound: return "DW_AT_upper_bound";
4572 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
4573 case DW_AT_accessibility: return "DW_AT_accessibility";
4574 case DW_AT_address_class: return "DW_AT_address_class";
4575 case DW_AT_artificial: return "DW_AT_artificial";
4576 case DW_AT_base_types: return "DW_AT_base_types";
4577 case DW_AT_calling_convention: return "DW_AT_calling_convention";
4578 case DW_AT_count: return "DW_AT_count";
4579 case DW_AT_data_member_location: return "DW_AT_data_member_location";
4580 case DW_AT_decl_column: return "DW_AT_decl_column";
4581 case DW_AT_decl_file: return "DW_AT_decl_file";
4582 case DW_AT_decl_line: return "DW_AT_decl_line";
4583 case DW_AT_declaration: return "DW_AT_declaration";
4584 case DW_AT_discr_list: return "DW_AT_discr_list";
4585 case DW_AT_encoding: return "DW_AT_encoding";
4586 case DW_AT_external: return "DW_AT_external";
4587 case DW_AT_frame_base: return "DW_AT_frame_base";
4588 case DW_AT_friend: return "DW_AT_friend";
4589 case DW_AT_identifier_case: return "DW_AT_identifier_case";
4590 case DW_AT_macro_info: return "DW_AT_macro_info";
4591 case DW_AT_namelist_items: return "DW_AT_namelist_items";
4592 case DW_AT_priority: return "DW_AT_priority";
4593 case DW_AT_segment: return "DW_AT_segment";
4594 case DW_AT_specification: return "DW_AT_specification";
4595 case DW_AT_static_link: return "DW_AT_static_link";
4596 case DW_AT_type: return "DW_AT_type";
4597 case DW_AT_use_location: return "DW_AT_use_location";
4598 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
4599 case DW_AT_virtuality: return "DW_AT_virtuality";
4600 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
4601 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
4602 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
4603 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
4604 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
4605 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
4606 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
4607 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
4608 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
4609 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
4610 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
4611 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
4612 case DW_AT_sf_names: return "DW_AT_sf_names";
4613 case DW_AT_src_info: return "DW_AT_src_info";
4614 case DW_AT_mac_info: return "DW_AT_mac_info";
4615 case DW_AT_src_coords: return "DW_AT_src_coords";
4616 case DW_AT_body_begin: return "DW_AT_body_begin";
4617 case DW_AT_body_end: return "DW_AT_body_end";
4620 static char buffer [100];
4622 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
4629 get_FORM_name (form)
4634 case DW_FORM_addr: return "DW_FORM_addr";
4635 case DW_FORM_block2: return "DW_FORM_block2";
4636 case DW_FORM_block4: return "DW_FORM_block4";
4637 case DW_FORM_data2: return "DW_FORM_data2";
4638 case DW_FORM_data4: return "DW_FORM_data4";
4639 case DW_FORM_data8: return "DW_FORM_data8";
4640 case DW_FORM_string: return "DW_FORM_string";
4641 case DW_FORM_block: return "DW_FORM_block";
4642 case DW_FORM_block1: return "DW_FORM_block1";
4643 case DW_FORM_data1: return "DW_FORM_data1";
4644 case DW_FORM_flag: return "DW_FORM_flag";
4645 case DW_FORM_sdata: return "DW_FORM_sdata";
4646 case DW_FORM_strp: return "DW_FORM_strp";
4647 case DW_FORM_udata: return "DW_FORM_udata";
4648 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
4649 case DW_FORM_ref1: return "DW_FORM_ref1";
4650 case DW_FORM_ref2: return "DW_FORM_ref2";
4651 case DW_FORM_ref4: return "DW_FORM_ref4";
4652 case DW_FORM_ref8: return "DW_FORM_ref8";
4653 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
4654 case DW_FORM_indirect: return "DW_FORM_indirect";
4657 static char buffer [100];
4659 sprintf (buffer, _("Unknown FORM value: %lx"), form);
4665 /* FIXME: There are better and more effiecint ways to handle
4666 these structures. For now though, I just want something that
4667 is simple to implement. */
4668 typedef struct abbrev_attr
4670 unsigned long attribute;
4672 struct abbrev_attr * next;
4676 typedef struct abbrev_entry
4678 unsigned long entry;
4681 struct abbrev_attr * first_attr;
4682 struct abbrev_attr * last_attr;
4683 struct abbrev_entry * next;
4687 static abbrev_entry * first_abbrev = NULL;
4688 static abbrev_entry * last_abbrev = NULL;
4691 free_abbrevs PARAMS ((void))
4693 abbrev_entry * abbrev;
4695 for (abbrev = first_abbrev; abbrev;)
4697 abbrev_entry * next = abbrev->next;
4700 for (attr = abbrev->first_attr; attr;)
4702 abbrev_attr * next = attr->next;
4712 last_abbrev = first_abbrev = NULL;
4716 add_abbrev (number, tag, children)
4717 unsigned long number;
4721 abbrev_entry * entry;
4723 entry = (abbrev_entry *) malloc (sizeof (* entry));
4729 entry->entry = number;
4731 entry->children = children;
4732 entry->first_attr = NULL;
4733 entry->last_attr = NULL;
4736 if (first_abbrev == NULL)
4737 first_abbrev = entry;
4739 last_abbrev->next = entry;
4741 last_abbrev = entry;
4745 add_abbrev_attr (attribute, form)
4746 unsigned long attribute;
4751 attr = (abbrev_attr *) malloc (sizeof (* attr));
4757 attr->attribute = attribute;
4761 if (last_abbrev->first_attr == NULL)
4762 last_abbrev->first_attr = attr;
4764 last_abbrev->last_attr->next = attr;
4766 last_abbrev->last_attr = attr;
4769 /* Processes the (partial) contents of a .debug_abbrev section.
4770 Returns NULL if the end of the section was encountered.
4771 Returns the address after the last byte read if the end of
4772 an abbreviation set was found. */
4774 static unsigned char *
4775 process_abbrev_section (start, end)
4776 unsigned char * start;
4777 unsigned char * end;
4779 if (first_abbrev != NULL)
4785 unsigned long entry;
4787 unsigned long attribute;
4790 entry = read_leb128 (start, & bytes_read, 0);
4791 start += bytes_read;
4796 tag = read_leb128 (start, & bytes_read, 0);
4797 start += bytes_read;
4799 children = * start ++;
4801 add_abbrev (entry, tag, children);
4807 attribute = read_leb128 (start, & bytes_read, 0);
4808 start += bytes_read;
4810 form = read_leb128 (start, & bytes_read, 0);
4811 start += bytes_read;
4814 add_abbrev_attr (attribute, form);
4816 while (attribute != 0);
4824 display_debug_abbrev (section, start, file)
4825 Elf32_Internal_Shdr * section;
4826 unsigned char * start;
4827 FILE * file ATTRIBUTE_UNUSED;
4829 abbrev_entry * entry;
4830 unsigned char * end = start + section->sh_size;
4832 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
4836 start = process_abbrev_section (start, end);
4838 printf (_(" Number TAG\n"));
4840 for (entry = first_abbrev; entry; entry = entry->next)
4844 printf (_(" %ld %s [%s]\n"),
4846 get_TAG_name (entry->tag),
4847 entry->children ? _("has children") : _("no children"));
4849 for (attr = entry->first_attr; attr; attr = attr->next)
4851 printf (_(" %-18s %s\n"),
4852 get_AT_name (attr->attribute),
4853 get_FORM_name (attr->form));
4865 static unsigned char *
4866 display_block (data, length)
4867 unsigned char * data;
4868 unsigned long length;
4870 printf (_(" %lu byte block: "), length);
4873 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
4879 decode_location_expression (data, pointer_size)
4880 unsigned char * data;
4881 unsigned int pointer_size;
4885 unsigned long uvalue;
4892 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data, pointer_size));
4895 printf ("DW_OP_deref");
4898 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data, 1));
4901 printf ("DW_OP_const1s: %ld", (long) byte_get (data, 1));
4904 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
4907 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
4910 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
4913 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
4916 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
4917 (unsigned long) byte_get (data + 4, 4));
4920 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
4921 (long) byte_get (data + 4, 4));
4924 printf ("DW_OP_constu: %lu", read_leb128 (data, NULL, 0));
4927 printf ("DW_OP_consts: %ld", read_leb128 (data, NULL, 1));
4930 printf ("DW_OP_dup");
4933 printf ("DW_OP_drop");
4936 printf ("DW_OP_over");
4939 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data, 1));
4942 printf ("DW_OP_swap");
4945 printf ("DW_OP_rot");
4948 printf ("DW_OP_xderef");
4951 printf ("DW_OP_abs");
4954 printf ("DW_OP_and");
4957 printf ("DW_OP_div");
4960 printf ("DW_OP_minus");
4963 printf ("DW_OP_mod");
4966 printf ("DW_OP_mul");
4969 printf ("DW_OP_neg");
4972 printf ("DW_OP_not");
4975 printf ("DW_OP_or");
4978 printf ("DW_OP_plus");
4980 case DW_OP_plus_uconst:
4981 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data, NULL, 0));
4984 printf ("DW_OP_shl");
4987 printf ("DW_OP_shr");
4990 printf ("DW_OP_shra");
4993 printf ("DW_OP_xor");
4996 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
4999 printf ("DW_OP_eq");
5002 printf ("DW_OP_ge");
5005 printf ("DW_OP_gt");
5008 printf ("DW_OP_le");
5011 printf ("DW_OP_lt");
5014 printf ("DW_OP_ne");
5017 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5020 printf ("DW_OP_lit0");
5023 printf ("DW_OP_lit1");
5026 printf ("DW_OP_lit2");
5029 printf ("DW_OP_lit3");
5032 printf ("DW_OP_lit4");
5035 printf ("DW_OP_lit5");
5038 printf ("DW_OP_lit6");
5041 printf ("DW_OP_lit7");
5044 printf ("DW_OP_lit8");
5047 printf ("DW_OP_lit9");
5050 printf ("DW_OP_lit10");
5053 printf ("DW_OP_lit11");
5056 printf ("DW_OP_lit12");
5059 printf ("DW_OP_lit13");
5062 printf ("DW_OP_lit14");
5065 printf ("DW_OP_lit15");
5068 printf ("DW_OP_lit16");
5071 printf ("DW_OP_lit17");
5074 printf ("DW_OP_lit18");
5077 printf ("DW_OP_lit19");
5080 printf ("DW_OP_lit20");
5083 printf ("DW_OP_lit21");
5086 printf ("DW_OP_lit22");
5089 printf ("DW_OP_lit23");
5092 printf ("DW_OP_lit24");
5095 printf ("DW_OP_lit25");
5098 printf ("DW_OP_lit26");
5101 printf ("DW_OP_lit27");
5104 printf ("DW_OP_lit28");
5107 printf ("DW_OP_lit29");
5110 printf ("DW_OP_lit30");
5113 printf ("DW_OP_lit31");
5116 printf ("DW_OP_reg0");
5119 printf ("DW_OP_reg1");
5122 printf ("DW_OP_reg2");
5125 printf ("DW_OP_reg3");
5128 printf ("DW_OP_reg4");
5131 printf ("DW_OP_reg5");
5134 printf ("DW_OP_reg6");
5137 printf ("DW_OP_reg7");
5140 printf ("DW_OP_reg8");
5143 printf ("DW_OP_reg9");
5146 printf ("DW_OP_reg10");
5149 printf ("DW_OP_reg11");
5152 printf ("DW_OP_reg12");
5155 printf ("DW_OP_reg13");
5158 printf ("DW_OP_reg14");
5161 printf ("DW_OP_reg15");
5164 printf ("DW_OP_reg16");
5167 printf ("DW_OP_reg17");
5170 printf ("DW_OP_reg18");
5173 printf ("DW_OP_reg19");
5176 printf ("DW_OP_reg20");
5179 printf ("DW_OP_reg21");
5182 printf ("DW_OP_reg22");
5185 printf ("DW_OP_reg23");
5188 printf ("DW_OP_reg24");
5191 printf ("DW_OP_reg25");
5194 printf ("DW_OP_reg26");
5197 printf ("DW_OP_reg27");
5200 printf ("DW_OP_reg28");
5203 printf ("DW_OP_reg29");
5206 printf ("DW_OP_reg30");
5209 printf ("DW_OP_reg31");
5212 printf ("DW_OP_breg0: %ld", read_leb128 (data, NULL, 1));
5215 printf ("DW_OP_breg1: %ld", read_leb128 (data, NULL, 1));
5218 printf ("DW_OP_breg2: %ld", read_leb128 (data, NULL, 1));
5221 printf ("DW_OP_breg3: %ld", read_leb128 (data, NULL, 1));
5224 printf ("DW_OP_breg4: %ld", read_leb128 (data, NULL, 1));
5227 printf ("DW_OP_breg5: %ld", read_leb128 (data, NULL, 1));
5230 printf ("DW_OP_breg6: %ld", read_leb128 (data, NULL, 1));
5233 printf ("DW_OP_breg7: %ld", read_leb128 (data, NULL, 1));
5236 printf ("DW_OP_breg8: %ld", read_leb128 (data, NULL, 1));
5239 printf ("DW_OP_breg9: %ld", read_leb128 (data, NULL, 1));
5242 printf ("DW_OP_breg10: %ld", read_leb128 (data, NULL, 1));
5245 printf ("DW_OP_breg11: %ld", read_leb128 (data, NULL, 1));
5248 printf ("DW_OP_breg12: %ld", read_leb128 (data, NULL, 1));
5251 printf ("DW_OP_breg13: %ld", read_leb128 (data, NULL, 1));
5254 printf ("DW_OP_breg14: %ld", read_leb128 (data, NULL, 1));
5257 printf ("DW_OP_breg15: %ld", read_leb128 (data, NULL, 1));
5260 printf ("DW_OP_breg16: %ld", read_leb128 (data, NULL, 1));
5263 printf ("DW_OP_breg17: %ld", read_leb128 (data, NULL, 1));
5266 printf ("DW_OP_breg18: %ld", read_leb128 (data, NULL, 1));
5269 printf ("DW_OP_breg19: %ld", read_leb128 (data, NULL, 1));
5272 printf ("DW_OP_breg20: %ld", read_leb128 (data, NULL, 1));
5275 printf ("DW_OP_breg21: %ld", read_leb128 (data, NULL, 1));
5278 printf ("DW_OP_breg22: %ld", read_leb128 (data, NULL, 1));
5281 printf ("DW_OP_breg23: %ld", read_leb128 (data, NULL, 1));
5284 printf ("DW_OP_breg24: %ld", read_leb128 (data, NULL, 1));
5287 printf ("DW_OP_breg25: %ld", read_leb128 (data, NULL, 1));
5290 printf ("DW_OP_breg26: %ld", read_leb128 (data, NULL, 1));
5293 printf ("DW_OP_breg27: %ld", read_leb128 (data, NULL, 1));
5296 printf ("DW_OP_breg28: %ld", read_leb128 (data, NULL, 1));
5299 printf ("DW_OP_breg29: %ld", read_leb128 (data, NULL, 1));
5302 printf ("DW_OP_breg30: %ld", read_leb128 (data, NULL, 1));
5305 printf ("DW_OP_breg31: %ld", read_leb128 (data, NULL, 1));
5308 printf ("DW_OP_regx: %lu", read_leb128 (data, NULL, 0));
5311 printf ("DW_OP_fbreg: %ld", read_leb128 (data, NULL, 1));
5314 uvalue = read_leb128 (data, &bytes_read, 0);
5315 printf ("DW_OP_bregx: %lu %ld", uvalue,
5316 read_leb128 (data + bytes_read, NULL, 1));
5319 printf ("DW_OP_piece: %lu", read_leb128 (data, NULL, 0));
5321 case DW_OP_deref_size:
5322 printf ("DW_OP_deref_size: %ld", (long) byte_get (data, 1));
5324 case DW_OP_xderef_size:
5325 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data, 1));
5328 printf ("DW_OP_nop");
5332 if (op >= DW_OP_lo_user
5333 && op <= DW_OP_hi_user)
5334 printf (_("(User defined location op)"));
5336 printf (_("(Unknown location op)"));
5342 static unsigned char *
5343 read_and_display_attr (attribute, form, data, pointer_size)
5344 unsigned long attribute;
5346 unsigned char * data;
5347 unsigned long pointer_size;
5349 unsigned long uvalue = 0;
5350 unsigned char * block_start = NULL;
5354 printf (" %-18s:", get_AT_name (attribute));
5358 case DW_FORM_ref_addr:
5363 case DW_FORM_ref_udata:
5369 case DW_FORM_ref_addr:
5371 uvalue = byte_get (data, pointer_size);
5372 printf (is_ref ? " <%x>" : " %#x", uvalue);
5373 data += pointer_size;
5379 uvalue = byte_get (data ++, 1);
5380 printf (is_ref ? " <%x>" : " %d", uvalue);
5385 uvalue = byte_get (data, 2);
5387 printf (is_ref ? " <%x>" : " %d", uvalue);
5392 uvalue = byte_get (data, 4);
5394 printf (is_ref ? " <%x>" : " %d", uvalue);
5399 uvalue = byte_get (data, 4);
5400 printf (" %lx", uvalue);
5401 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
5405 case DW_FORM_string:
5406 printf (" %s", data);
5407 data += strlen (data) + 1;
5411 uvalue = read_leb128 (data, & bytes_read, 1);
5413 printf (" %ld", (long) uvalue);
5416 case DW_FORM_ref_udata:
5418 uvalue = read_leb128 (data, & bytes_read, 0);
5420 printf (is_ref ? " <%lx>" : " %ld", uvalue);
5424 uvalue = read_leb128 (data, & bytes_read, 0);
5425 block_start = data + bytes_read;
5426 data = display_block (block_start, uvalue);
5427 uvalue = * block_start;
5430 case DW_FORM_block1:
5431 uvalue = byte_get (data, 1);
5432 block_start = data + 1;
5433 data = display_block (block_start, uvalue);
5434 uvalue = * block_start;
5437 case DW_FORM_block2:
5438 uvalue = byte_get (data, 2);
5439 block_start = data + 2;
5440 data = display_block (block_start, uvalue);
5441 uvalue = * block_start;
5444 case DW_FORM_block4:
5445 uvalue = byte_get (data, 4);
5446 block_start = data + 4;
5447 data = display_block (block_start, uvalue);
5448 uvalue = * block_start;
5452 case DW_FORM_indirect:
5453 warn (_("Unable to handle FORM: %d"), form);
5457 warn (_("Unrecognised form: %d"), form);
5461 /* For some attributes we can display futher information. */
5470 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
5471 case DW_INL_inlined: printf (_("(inlined)")); break;
5472 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
5473 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
5474 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
5478 case DW_AT_frame_base:
5479 if (uvalue >= DW_OP_reg0 && uvalue <= DW_OP_reg31)
5480 printf ("(reg %ld)", uvalue - DW_OP_reg0);
5483 case DW_AT_language:
5486 case DW_LANG_C: printf ("(non-ANSI C)"); break;
5487 case DW_LANG_C89: printf ("(ANSI C)"); break;
5488 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
5489 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
5490 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
5491 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
5492 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
5493 case DW_LANG_Ada83: printf ("(Ada)"); break;
5494 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
5495 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
5496 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
5497 default: printf ("(Unknown: %lx)", uvalue); break;
5501 case DW_AT_encoding:
5504 case DW_ATE_void: printf ("(void)"); break;
5505 case DW_ATE_address: printf ("(machine address)"); break;
5506 case DW_ATE_boolean: printf ("(boolean)"); break;
5507 case DW_ATE_complex_float: printf ("(complex float)"); break;
5508 case DW_ATE_float: printf ("(float)"); break;
5509 case DW_ATE_signed: printf ("(signed)"); break;
5510 case DW_ATE_signed_char: printf ("(signed char)"); break;
5511 case DW_ATE_unsigned: printf ("(unsigned)"); break;
5512 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
5514 if (uvalue >= DW_ATE_lo_user
5515 && uvalue <= DW_ATE_hi_user)
5516 printf ("(user defined type)");
5518 printf ("(unknown type)");
5523 case DW_AT_accessibility:
5526 case DW_ACCESS_public: printf ("(public)"); break;
5527 case DW_ACCESS_protected: printf ("(protected)"); break;
5528 case DW_ACCESS_private: printf ("(private)"); break;
5529 default: printf ("(unknown accessibility)"); break;
5533 case DW_AT_visibility:
5536 case DW_VIS_local: printf ("(local)"); break;
5537 case DW_VIS_exported: printf ("(exported)"); break;
5538 case DW_VIS_qualified: printf ("(qualified)"); break;
5539 default: printf ("(unknown visibility)"); break;
5543 case DW_AT_virtuality:
5546 case DW_VIRTUALITY_none: printf ("(none)"); break;
5547 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
5548 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
5549 default: printf ("(unknown virtuality)"); break;
5553 case DW_AT_identifier_case:
5556 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
5557 case DW_ID_up_case: printf ("(up_case)"); break;
5558 case DW_ID_down_case: printf ("(down_case)"); break;
5559 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
5560 default: printf ("(unknown case)"); break;
5564 case DW_AT_calling_convention:
5567 case DW_CC_normal: printf ("(normal)"); break;
5568 case DW_CC_program: printf ("(program)"); break;
5569 case DW_CC_nocall: printf ("(nocall)"); break;
5571 if (uvalue >= DW_CC_lo_user
5572 && uvalue <= DW_CC_hi_user)
5573 printf ("(user defined)");
5575 printf ("(unknown convention)");
5579 case DW_AT_location:
5580 case DW_AT_data_member_location:
5581 case DW_AT_vtable_elem_location:
5583 decode_location_expression (block_start, pointer_size);
5596 display_debug_info (section, start, file)
5597 Elf32_Internal_Shdr * section;
5598 unsigned char * start;
5601 unsigned char * end = start + section->sh_size;
5602 unsigned char * section_begin = start;
5604 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
5608 DWARF2_External_CompUnit * external;
5609 DWARF2_Internal_CompUnit compunit;
5610 unsigned char * tags;
5614 external = (DWARF2_External_CompUnit *) start;
5616 compunit.cu_length = BYTE_GET (external->cu_length);
5617 compunit.cu_version = BYTE_GET (external->cu_version);
5618 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
5619 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
5621 tags = start + sizeof (* external);
5622 start += compunit.cu_length + sizeof (external->cu_length);
5624 if (compunit.cu_version != 2)
5626 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
5630 printf (_(" Compilation Unit:\n"));
5631 printf (_(" Length: %ld\n"), compunit.cu_length);
5632 printf (_(" Version: %d\n"), compunit.cu_version);
5633 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
5634 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
5636 if (first_abbrev != NULL)
5639 /* Read in the abbrevs used by this compilation unit. */
5642 Elf32_Internal_Shdr * sec;
5643 unsigned char * begin;
5645 /* Locate the .debug_abbrev section and process it. */
5646 for (i = 0, sec = section_headers;
5647 i < elf_header.e_shnum;
5649 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
5652 if (i == -1 || sec->sh_size == 0)
5654 warn (_("Unable to locate .debug_abbrev section!\n"));
5658 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
5659 "debug_abbrev section data");
5661 process_abbrev_section (begin + compunit.cu_abbrev_offset,
5662 begin + sec->sh_size);
5668 while (tags < start)
5671 unsigned long abbrev_number;
5672 abbrev_entry * entry;
5675 abbrev_number = read_leb128 (tags, & bytes_read, 0);
5678 /* A null DIE marks the end of a list of children. */
5679 if (abbrev_number == 0)
5685 /* Scan through the abbreviation list until we reach the
5687 for (entry = first_abbrev;
5688 entry && entry->entry != abbrev_number;
5689 entry = entry->next)
5694 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
5699 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
5700 level, tags - section_begin - bytes_read,
5702 get_TAG_name (entry->tag));
5704 for (attr = entry->first_attr; attr; attr = attr->next)
5705 tags = read_and_display_attr (attr->attribute,
5708 compunit.cu_pointer_size);
5710 if (entry->children)
5721 display_debug_aranges (section, start, file)
5722 Elf32_Internal_Shdr * section;
5723 unsigned char * start;
5724 FILE * file ATTRIBUTE_UNUSED;
5726 unsigned char * end = start + section->sh_size;
5728 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
5732 DWARF2_External_ARange * external;
5733 DWARF2_Internal_ARange arange;
5734 unsigned char * ranges;
5735 unsigned long length;
5736 unsigned long address;
5738 external = (DWARF2_External_ARange *) start;
5740 arange.ar_length = BYTE_GET (external->ar_length);
5741 arange.ar_version = BYTE_GET (external->ar_version);
5742 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
5743 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
5744 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
5746 printf (_(" Length: %ld\n"), arange.ar_length);
5747 printf (_(" Version: %d\n"), arange.ar_version);
5748 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
5749 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5750 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5752 printf (_("\n Address Length\n"));
5754 ranges = start + sizeof (* external);
5758 address = byte_get (ranges, arange.ar_pointer_size);
5763 ranges += arange.ar_pointer_size;
5765 length = byte_get (ranges, arange.ar_pointer_size);
5767 ranges += arange.ar_pointer_size;
5769 printf (" %8.8lx %lu\n", address, length);
5772 start += arange.ar_length + sizeof (external->ar_length);
5782 display_debug_not_supported (section, start, file)
5783 Elf32_Internal_Shdr * section;
5784 unsigned char * start ATTRIBUTE_UNUSED;
5785 FILE * file ATTRIBUTE_UNUSED;
5787 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5788 SECTION_NAME (section));
5793 /* A structure containing the name of a debug section and a pointer
5794 to a function that can decode it. */
5798 int (* display) PARAMS((Elf32_Internal_Shdr *, unsigned char *, FILE *));
5802 { ".debug_info", display_debug_info },
5803 { ".debug_abbrev", display_debug_abbrev },
5804 { ".debug_line", display_debug_lines },
5805 { ".debug_aranges", display_debug_aranges },
5806 { ".debug_pubnames", display_debug_pubnames },
5807 { ".debug_macinfo", display_debug_not_supported },
5808 { ".debug_frame", display_debug_not_supported },
5809 { ".debug_str", display_debug_not_supported },
5810 { ".debug_static_func", display_debug_not_supported },
5811 { ".debug_static_vars", display_debug_not_supported },
5812 { ".debug_types", display_debug_not_supported },
5813 { ".debug_weaknames", display_debug_not_supported }
5817 display_debug_section (section, file)
5818 Elf32_Internal_Shdr * section;
5821 char * name = SECTION_NAME (section);
5822 bfd_size_type length;
5823 unsigned char * start;
5826 length = section->sh_size;
5829 printf (_("\nSection '%s' has no debugging data.\n"), name);
5833 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
5834 "debug section data");
5836 /* See if we know how to display the contents of this section. */
5837 for (i = NUM_ELEM (debug_displays); i--;)
5838 if (strcmp (debug_displays[i].name, name) == 0)
5840 debug_displays[i].display (section, start, file);
5845 printf (_("Unrecognised debug section: %s\n"), name);
5849 /* If we loaded in the abbrev section at some point,
5850 we must release it here. */
5851 if (first_abbrev != NULL)
5858 process_section_contents (file)
5861 Elf32_Internal_Shdr * section;
5867 for (i = 0, section = section_headers;
5868 i < elf_header.e_shnum
5869 && i < num_dump_sects;
5872 #ifdef SUPPORT_DISASSEMBLY
5873 if (dump_sects[i] & DISASS_DUMP)
5874 disassemble_section (section, file);
5876 if (dump_sects[i] & HEX_DUMP)
5877 dump_section (section, file);
5879 if (dump_sects[i] & DEBUG_DUMP)
5880 display_debug_section (section, file);
5883 if (i < num_dump_sects)
5884 warn (_("Some sections were not dumped because they do not exist!\n"));
5890 process_mips_fpe_exception (mask)
5896 if (mask & OEX_FPU_INEX)
5897 fputs ("INEX", stdout), first = 0;
5898 if (mask & OEX_FPU_UFLO)
5899 printf ("%sUFLO", first ? "" : "|"), first = 0;
5900 if (mask & OEX_FPU_OFLO)
5901 printf ("%sOFLO", first ? "" : "|"), first = 0;
5902 if (mask & OEX_FPU_DIV0)
5903 printf ("%sDIV0", first ? "" : "|"), first = 0;
5904 if (mask & OEX_FPU_INVAL)
5905 printf ("%sINVAL", first ? "" : "|");
5908 fputs ("0", stdout);
5912 process_mips_specific (file)
5915 Elf_Internal_Dyn * entry;
5916 size_t liblist_offset = 0;
5917 size_t liblistno = 0;
5918 size_t conflictsno = 0;
5919 size_t options_offset = 0;
5920 size_t conflicts_offset = 0;
5922 /* We have a lot of special sections. Thanks SGI! */
5923 if (dynamic_segment == NULL)
5924 /* No information available. */
5927 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
5928 switch (entry->d_tag)
5930 case DT_MIPS_LIBLIST:
5931 liblist_offset = entry->d_un.d_val - loadaddr;
5933 case DT_MIPS_LIBLISTNO:
5934 liblistno = entry->d_un.d_val;
5936 case DT_MIPS_OPTIONS:
5937 options_offset = entry->d_un.d_val - loadaddr;
5939 case DT_MIPS_CONFLICT:
5940 conflicts_offset = entry->d_un.d_val - loadaddr;
5942 case DT_MIPS_CONFLICTNO:
5943 conflictsno = entry->d_un.d_val;
5949 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
5951 Elf32_External_Lib * elib;
5954 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
5955 elib, Elf32_External_Lib *, "liblist");
5957 printf ("\nSection '.liblist' contains %d entries:\n", liblistno);
5958 fputs (" Library Time Stamp Checksum Version Flags\n",
5961 for (cnt = 0; cnt < liblistno; ++cnt)
5967 liblist.l_name = BYTE_GET (elib[cnt].l_name);
5968 time = BYTE_GET (elib[cnt].l_time_stamp);
5969 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
5970 liblist.l_version = BYTE_GET (elib[cnt].l_version);
5971 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
5973 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
5975 printf ("%3d: %-20s %s %#10lx %-7ld", cnt,
5976 dynamic_strings + liblist.l_name, timebuf,
5977 liblist.l_checksum, liblist.l_version);
5979 if (liblist.l_flags == 0)
5989 { " EXACT_MATCH", LL_EXACT_MATCH },
5990 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
5991 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
5992 { " EXPORTS", LL_EXPORTS },
5993 { " DELAY_LOAD", LL_DELAY_LOAD },
5994 { " DELTA", LL_DELTA }
5996 int flags = liblist.l_flags;
6000 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
6002 if ((flags & l_flags_vals[fcnt].bit) != 0)
6004 fputs (l_flags_vals[fcnt].name, stdout);
6005 flags ^= l_flags_vals[fcnt].bit;
6008 printf (" %#x", (unsigned int) flags);
6017 if (options_offset != 0)
6019 Elf_External_Options * eopt;
6020 Elf_Internal_Shdr * sect = section_headers;
6021 Elf_Internal_Options * iopt;
6022 Elf_Internal_Options * option;
6026 /* Find the section header so that we get the size. */
6027 while (sect->sh_type != SHT_MIPS_OPTIONS)
6030 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
6031 Elf_External_Options *, "options");
6033 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
6037 error (_("Out of memory"));
6043 while (offset < sect->sh_size)
6045 Elf_External_Options * eoption;
6047 eoption = (Elf_External_Options *) ((char *) eopt + offset);
6049 option->kind = BYTE_GET (eoption->kind);
6050 option->size = BYTE_GET (eoption->size);
6051 option->section = BYTE_GET (eoption->section);
6052 option->info = BYTE_GET (eoption->info);
6054 offset += option->size;
6059 printf (_("\nSection '%s' contains %d entries:\n"),
6060 string_table + sect->sh_name, cnt);
6067 switch (option->kind)
6070 /* This shouldn't happen. */
6071 printf (" NULL %d %lx", option->section, option->info);
6074 printf (" REGINFO ");
6075 if (elf_header.e_machine == EM_MIPS)
6078 Elf32_External_RegInfo *ereg;
6079 Elf32_RegInfo reginfo;
6081 ereg = (Elf32_External_RegInfo *) (option + 1);
6082 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6083 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6084 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6085 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6086 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6087 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
6089 printf ("GPR %08lx GP 0x%lx\n",
6091 (unsigned long) reginfo.ri_gp_value);
6092 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6093 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6094 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6099 Elf64_External_RegInfo * ereg;
6100 Elf64_Internal_RegInfo reginfo;
6102 ereg = (Elf64_External_RegInfo *) (option + 1);
6103 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6104 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6105 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6106 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6107 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6108 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
6110 printf ("GPR %08lx GP 0x",
6111 reginfo.ri_gprmask);
6112 printf_vma (reginfo.ri_gp_value);
6115 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6116 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6117 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6121 case ODK_EXCEPTIONS:
6122 fputs (" EXCEPTIONS fpe_min(", stdout);
6123 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
6124 fputs (") fpe_max(", stdout);
6125 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
6126 fputs (")", stdout);
6128 if (option->info & OEX_PAGE0)
6129 fputs (" PAGE0", stdout);
6130 if (option->info & OEX_SMM)
6131 fputs (" SMM", stdout);
6132 if (option->info & OEX_FPDBUG)
6133 fputs (" FPDBUG", stdout);
6134 if (option->info & OEX_DISMISS)
6135 fputs (" DISMISS", stdout);
6138 fputs (" PAD ", stdout);
6139 if (option->info & OPAD_PREFIX)
6140 fputs (" PREFIX", stdout);
6141 if (option->info & OPAD_POSTFIX)
6142 fputs (" POSTFIX", stdout);
6143 if (option->info & OPAD_SYMBOL)
6144 fputs (" SYMBOL", stdout);
6147 fputs (" HWPATCH ", stdout);
6148 if (option->info & OHW_R4KEOP)
6149 fputs (" R4KEOP", stdout);
6150 if (option->info & OHW_R8KPFETCH)
6151 fputs (" R8KPFETCH", stdout);
6152 if (option->info & OHW_R5KEOP)
6153 fputs (" R5KEOP", stdout);
6154 if (option->info & OHW_R5KCVTL)
6155 fputs (" R5KCVTL", stdout);
6158 fputs (" FILL ", stdout);
6159 /* XXX Print content of info word? */
6162 fputs (" TAGS ", stdout);
6163 /* XXX Print content of info word? */
6166 fputs (" HWAND ", stdout);
6167 if (option->info & OHWA0_R4KEOP_CHECKED)
6168 fputs (" R4KEOP_CHECKED", stdout);
6169 if (option->info & OHWA0_R4KEOP_CLEAN)
6170 fputs (" R4KEOP_CLEAN", stdout);
6173 fputs (" HWOR ", stdout);
6174 if (option->info & OHWA0_R4KEOP_CHECKED)
6175 fputs (" R4KEOP_CHECKED", stdout);
6176 if (option->info & OHWA0_R4KEOP_CLEAN)
6177 fputs (" R4KEOP_CLEAN", stdout);
6180 printf (" GP_GROUP %#06lx self-contained %#06lx",
6181 option->info & OGP_GROUP,
6182 (option->info & OGP_SELF) >> 16);
6185 printf (" IDENT %#06lx self-contained %#06lx",
6186 option->info & OGP_GROUP,
6187 (option->info & OGP_SELF) >> 16);
6190 /* This shouldn't happen. */
6191 printf (" %3d ??? %d %lx",
6192 option->kind, option->section, option->info);
6196 len = sizeof (*eopt);
6197 while (len < option->size)
6198 if (((char *) option)[len] >= ' '
6199 && ((char *) option)[len] < 0x7f)
6200 printf ("%c", ((char *) option)[len++]);
6202 printf ("\\%03o", ((char *) option)[len++]);
6204 fputs ("\n", stdout);
6211 if (conflicts_offset != 0 && conflictsno != 0)
6213 Elf32_External_Conflict * econf32;
6214 Elf64_External_Conflict * econf64;
6215 Elf32_Conflict * iconf;
6218 if (dynamic_symbols == NULL)
6220 error (_("conflict list with without table"));
6224 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf));
6227 error (_("Out of memory"));
6233 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32),
6234 econf32, Elf32_External_Conflict *, "conflict");
6236 for (cnt = 0; cnt < conflictsno; ++cnt)
6237 iconf[cnt] = BYTE_GET (econf32[cnt]);
6241 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64),
6242 econf64, Elf64_External_Conflict *, "conflict");
6244 for (cnt = 0; cnt < conflictsno; ++cnt)
6245 iconf[cnt] = BYTE_GET (econf64[cnt]);
6248 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
6249 puts (_(" Num: Index Value Name"));
6251 for (cnt = 0; cnt < conflictsno; ++cnt)
6253 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
6255 printf ("%5u: %8lu %#10lx %s\n",
6256 cnt, iconf[cnt], (unsigned long) psym->st_value,
6257 dynamic_strings + psym->st_name);
6268 process_arch_specific (file)
6274 switch (elf_header.e_machine)
6277 case EM_MIPS_RS4_BE:
6278 return process_mips_specific (file);
6287 get_file_header (file)
6290 /* Read in the identity array. */
6291 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
6294 /* Determine how to read the rest of the header. */
6295 switch (elf_header.e_ident [EI_DATA])
6297 default: /* fall through */
6298 case ELFDATANONE: /* fall through */
6299 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
6300 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
6303 /* For now we only support 32 bit and 64 bit ELF files. */
6304 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
6306 /* Read in the rest of the header. */
6309 Elf32_External_Ehdr ehdr32;
6311 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
6314 elf_header.e_type = BYTE_GET (ehdr32.e_type);
6315 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
6316 elf_header.e_version = BYTE_GET (ehdr32.e_version);
6317 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
6318 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
6319 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
6320 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
6321 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
6322 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
6323 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
6324 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
6325 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
6326 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
6330 Elf64_External_Ehdr ehdr64;
6332 /* If we have been compiled with sizeof (bfd_vma) == 4, then
6333 we will not be able to cope with the 64bit data found in
6334 64 ELF files. Detect this now and abort before we start
6335 overwritting things. */
6336 if (sizeof (bfd_vma) < 8)
6338 error (_("This instance of readelf has been built without support for a\n"));
6339 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
6343 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
6346 elf_header.e_type = BYTE_GET (ehdr64.e_type);
6347 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
6348 elf_header.e_version = BYTE_GET (ehdr64.e_version);
6349 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
6350 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
6351 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
6352 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
6353 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
6354 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
6355 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
6356 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
6357 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
6358 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
6365 process_file (file_name)
6369 struct stat statbuf;
6372 if (stat (file_name, & statbuf) < 0)
6374 error (_("Cannot stat input file %s.\n"), file_name);
6378 file = fopen (file_name, "rb");
6381 error (_("Input file %s not found.\n"), file_name);
6385 if (! get_file_header (file))
6387 error (_("%s: Failed to read file header\n"), file_name);
6392 /* Initialise per file variables. */
6393 for (i = NUM_ELEM (version_info); i--;)
6394 version_info[i] = 0;
6396 for (i = NUM_ELEM (dynamic_info); i--;)
6397 dynamic_info[i] = 0;
6399 /* Process the file. */
6401 printf (_("\nFile: %s\n"), file_name);
6403 if (! process_file_header ())
6409 process_section_headers (file);
6411 process_program_headers (file);
6413 process_dynamic_segment (file);
6415 process_relocs (file);
6417 process_symbol_table (file);
6419 process_syminfo (file);
6421 process_version_sections (file);
6423 process_section_contents (file);
6425 process_arch_specific (file);
6429 if (section_headers)
6431 free (section_headers);
6432 section_headers = NULL;
6437 free (string_table);
6438 string_table = NULL;
6441 if (dynamic_strings)
6443 free (dynamic_strings);
6444 dynamic_strings = NULL;
6447 if (dynamic_symbols)
6449 free (dynamic_symbols);
6450 dynamic_symbols = NULL;
6451 num_dynamic_syms = 0;
6454 if (dynamic_syminfo)
6456 free (dynamic_syminfo);
6457 dynamic_syminfo = NULL;
6461 #ifdef SUPPORT_DISASSEMBLY
6462 /* Needed by the i386 disassembler. For extra credit, someone could
6463 fix this so that we insert symbolic addresses here, esp for GOT/PLT
6467 print_address (unsigned int addr, FILE * outfile)
6469 fprintf (outfile,"0x%8.8x", addr);
6472 /* Needed by the i386 disassembler. */
6474 db_task_printsym (unsigned int addr)
6476 print_address (addr, stderr);
6485 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
6486 setlocale (LC_MESSAGES, "");
6488 bindtextdomain (PACKAGE, LOCALEDIR);
6489 textdomain (PACKAGE);
6491 parse_args (argc, argv);
6493 if (optind < (argc - 1))
6496 while (optind < argc)
6497 process_file (argv [optind ++]);
6499 if (dump_sects != NULL)