1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
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
32 #include "elf/common.h"
33 #include "elf/external.h"
34 #include "elf/internal.h"
35 #include "elf/dwarf2.h"
37 /* The following headers use the elf/reloc-macros.h file to
38 automatically generate relocation recognition functions
39 such as elf_mips_reloc_type() */
41 #define RELOC_MACROS_GEN_FUNC
47 #include "elf/alpha.h"
50 #include "elf/sparc.h"
55 #include "elf/mn10200.h"
56 #include "elf/mn10300.h"
60 #include "elf/mcore.h"
66 #ifdef ANSI_PROTOTYPES
72 char * program_name
= "readelf";
73 unsigned int dynamic_addr
;
74 unsigned int dynamic_size
;
75 unsigned int rela_addr
;
76 unsigned int rela_size
;
77 char * dynamic_strings
;
79 Elf_Internal_Sym
* dynamic_symbols
;
80 Elf_Internal_Syminfo
* dynamic_syminfo
;
81 unsigned long dynamic_syminfo_offset
;
82 unsigned int dynamic_syminfo_nent
;
83 char program_interpreter
[64];
84 int dynamic_info
[DT_JMPREL
+ 1];
87 Elf_Internal_Ehdr elf_header
;
88 Elf_Internal_Shdr
* section_headers
;
89 Elf_Internal_Dyn
* dynamic_segment
;
103 int do_debug_abbrevs
;
105 int do_debug_pubnames
;
106 int do_debug_aranges
;
109 /* A dynamic array of flags indicating which sections require dumping. */
110 char * dump_sects
= NULL
;
111 unsigned int num_dump_sects
= 0;
113 #define HEX_DUMP (1 << 0)
114 #define DISASS_DUMP (1 << 1)
115 #define DEBUG_DUMP (1 << 2)
117 /* Forward declarations for dumb compilers. */
118 static unsigned long (* byte_get
) PARAMS ((unsigned char *, int));
119 static const char * get_mips_dynamic_type
PARAMS ((unsigned long type
));
120 static const char * get_dynamic_type
PARAMS ((unsigned long type
));
121 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, char *, int));
122 static char * get_file_type
PARAMS ((unsigned e_type
));
123 static char * get_machine_name
PARAMS ((unsigned e_machine
));
124 static char * get_machine_data
PARAMS ((unsigned e_data
));
125 static char * get_machine_flags
PARAMS ((unsigned, unsigned e_machine
));
126 static const char * get_mips_segment_type
PARAMS ((unsigned long type
));
127 static const char * get_segment_type
PARAMS ((unsigned long p_type
));
128 static const char * get_mips_section_type_name
PARAMS ((unsigned int sh_type
));
129 static const char * get_section_type_name
PARAMS ((unsigned int sh_type
));
130 static char * get_symbol_binding
PARAMS ((unsigned int binding
));
131 static char * get_symbol_type
PARAMS ((unsigned int type
));
132 static void usage
PARAMS ((void));
133 static void parse_args
PARAMS ((int argc
, char ** argv
));
134 static int process_file_header
PARAMS ((void));
135 static int process_program_headers
PARAMS ((FILE *));
136 static int process_section_headers
PARAMS ((FILE *));
137 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*entry
));
138 static int process_dynamic_segment
PARAMS ((FILE *));
139 static int process_symbol_table
PARAMS ((FILE *));
140 static int process_section_contents
PARAMS ((FILE *));
141 static void process_file
PARAMS ((char * file_name
));
142 static int process_relocs
PARAMS ((FILE *));
143 static int process_version_sections
PARAMS ((FILE *));
144 static char * get_ver_flags
PARAMS ((unsigned int flags
));
145 static char * get_symbol_index_type
PARAMS ((unsigned int type
));
146 static int get_section_headers
PARAMS ((FILE * file
));
147 static int get_file_header
PARAMS ((FILE * file
));
148 static Elf_Internal_Sym
* get_elf_symbols
PARAMS ((FILE * file
, unsigned long offset
, unsigned long number
));
149 static int * get_dynamic_data
PARAMS ((FILE * file
, unsigned int number
));
150 #ifdef SUPPORT_DISASSEMBLY
151 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
153 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
154 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
155 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
156 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
157 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
158 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
159 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
160 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
161 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
162 static int process_extended_line_op
PARAMS ((unsigned char *, int));
163 static void reset_state_machine
PARAMS ((int));
164 static char * get_TAG_name
PARAMS ((unsigned long));
165 static char * get_AT_name
PARAMS ((unsigned long));
166 static char * get_FORM_name
PARAMS ((unsigned long));
167 static void free_abbrevs
PARAMS ((void));
168 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
169 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
170 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
171 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
172 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int));
173 static void request_dump
PARAMS ((unsigned int, char));
174 static const char * get_elf_class
PARAMS ((unsigned char));
175 static const char * get_data_encoding
PARAMS ((unsigned char));
176 static const char * get_osabi_name
PARAMS ((unsigned char));
177 static int guess_is_rela
PARAMS ((unsigned long));
179 typedef int Elf32_Word
;
187 #define SECTION_NAME(X) (string_table + (X)->sh_name)
189 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
191 #define BYTE_GET(field) byte_get (field, sizeof (field))
193 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
195 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
196 if (fseek (file, offset, SEEK_SET)) \
198 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
202 var = (type) malloc (size); \
206 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
210 if (fread (var, size, 1, file) != 1) \
212 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
219 #define GET_DATA(offset, var, reason) \
220 if (fseek (file, offset, SEEK_SET)) \
222 error (_("Unable to seek to %x for %s\n"), offset, reason); \
225 else if (fread (& var, sizeof (var), 1, file) != 1) \
227 error (_("Unable to read data at %x for %s\n"), offset, reason); \
231 #ifdef ANSI_PROTOTYPES
233 error (const char * message
, ...)
237 fprintf (stderr
, _("%s: Error: "), program_name
);
238 va_start (args
, message
);
239 vfprintf (stderr
, message
, args
);
245 warn (const char * message
, ...)
249 fprintf (stderr
, _("%s: Warning: "), program_name
);
250 va_start (args
, message
);
251 vfprintf (stderr
, message
, args
);
263 fprintf (stderr
, _("%s: Error: "), program_name
);
265 message
= va_arg (args
, char *);
266 vfprintf (stderr
, message
, args
);
278 fprintf (stderr
, _("%s: Warning: "), program_name
);
280 message
= va_arg (args
, char *);
281 vfprintf (stderr
, message
, args
);
287 static unsigned long int
288 byte_get_little_endian (field
, size
)
289 unsigned char * field
;
298 return ((unsigned int) (field
[0]))
299 | (((unsigned int) (field
[1])) << 8);
302 return ((unsigned long) (field
[0]))
303 | (((unsigned long) (field
[1])) << 8)
304 | (((unsigned long) (field
[2])) << 16)
305 | (((unsigned long) (field
[3])) << 24);
308 error (_("Unhandled data length: %d\n"), size
);
313 static unsigned long int
314 byte_get_big_endian (field
, size
)
315 unsigned char * field
;
324 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
327 return ((unsigned long) (field
[3]))
328 | (((unsigned long) (field
[2])) << 8)
329 | (((unsigned long) (field
[1])) << 16)
330 | (((unsigned long) (field
[0])) << 24);
333 error (_("Unhandled data length: %d\n"), size
);
339 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
341 guess_is_rela (e_machine
)
342 unsigned long e_machine
;
346 /* Targets that use REL relocations. */
357 /* Targets that use RELA relocations. */
363 case EM_CYGNUS_MN10200
:
364 case EM_CYGNUS_MN10300
:
372 warn (_("Don't know about relocations on this machine architecture\n"));
377 /* Display the contents of the relocation data
378 found at the specified offset. */
380 dump_relocations (file
, rel_offset
, rel_size
, symtab
, strtab
, is_rela
)
382 unsigned long rel_offset
;
383 unsigned long rel_size
;
384 Elf_Internal_Sym
* symtab
;
389 Elf_Internal_Rel
* rels
;
390 Elf_Internal_Rela
* relas
;
393 if (is_rela
== UNKNOWN
)
394 is_rela
= guess_is_rela (elf_header
.e_machine
);
398 Elf32_External_Rela
* erelas
;
400 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
401 Elf32_External_Rela
*, "relocs");
403 rel_size
= rel_size
/ sizeof (Elf32_External_Rela
);
405 relas
= (Elf_Internal_Rela
*) malloc (rel_size
*
406 sizeof (Elf_Internal_Rela
));
410 error(_("out of memory parsing relocs"));
414 for (i
= 0; i
< rel_size
; i
++)
416 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
417 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
418 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
423 rels
= (Elf_Internal_Rel
*) relas
;
427 Elf32_External_Rel
* erels
;
428 unsigned long saved_rel_size
= rel_size
;
430 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
431 Elf32_External_Rel
*, "relocs");
433 rel_size
= rel_size
/ sizeof (Elf32_External_Rel
);
435 rels
= (Elf_Internal_Rel
*) malloc (rel_size
*
436 sizeof (Elf_Internal_Rel
));
439 error(_("out of memory parsing relocs"));
443 for (i
= 0; i
< rel_size
; i
++)
445 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
446 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
451 relas
= (Elf_Internal_Rela
*) rels
;
456 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
459 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
461 for (i
= 0; i
< rel_size
; i
++)
464 unsigned long offset
;
470 offset
= relas
[i
].r_offset
;
471 info
= relas
[i
].r_info
;
475 offset
= rels
[i
].r_offset
;
476 info
= rels
[i
].r_info
;
479 printf (" %8.8lx %5.5lx ", offset
, info
);
481 switch (elf_header
.e_machine
)
488 rtype
= elf_m32r_reloc_type (ELF32_R_TYPE (info
));
493 rtype
= elf_i386_reloc_type (ELF32_R_TYPE (info
));
497 rtype
= elf_m68k_reloc_type (ELF32_R_TYPE (info
));
501 rtype
= elf_i960_reloc_type (ELF32_R_TYPE (info
));
505 rtype
= elf_sparc_reloc_type (ELF32_R_TYPE (info
));
509 rtype
= v850_reloc_type (ELF32_R_TYPE (info
));
513 rtype
= elf_d10v_reloc_type (ELF32_R_TYPE (info
));
517 rtype
= elf_d30v_reloc_type (ELF32_R_TYPE (info
));
521 rtype
= elf_sh_reloc_type (ELF32_R_TYPE (info
));
524 case EM_CYGNUS_MN10300
:
525 rtype
= elf_mn10300_reloc_type (ELF32_R_TYPE (info
));
528 case EM_CYGNUS_MN10200
:
529 rtype
= elf_mn10200_reloc_type (ELF32_R_TYPE (info
));
533 rtype
= elf_fr30_reloc_type (ELF32_R_TYPE (info
));
537 rtype
= elf_mcore_reloc_type (ELF32_R_TYPE (info
));
541 rtype
= elf_ppc_reloc_type (ELF32_R_TYPE (info
));
546 rtype
= elf_mips_reloc_type (ELF32_R_TYPE (info
));
550 rtype
= elf_alpha_reloc_type (ELF32_R_TYPE (info
));
554 rtype
= elf_arm_reloc_type (ELF32_R_TYPE (info
));
558 rtype
= elf_arc_reloc_type (ELF32_R_TYPE (info
));
562 rtype
= elf32_hppa_reloc_type (ELF32_R_TYPE (info
));
567 printf (_("unrecognised: %-7lx"), ELF32_R_TYPE (info
));
569 printf ("%-21.21s", rtype
);
571 symtab_index
= ELF32_R_SYM (info
);
573 if (symtab_index
&& symtab
!= NULL
)
575 Elf_Internal_Sym
* psym
;
577 psym
= symtab
+ symtab_index
;
579 printf (" %08lx ", (unsigned long) psym
->st_value
);
581 if (psym
->st_name
== 0)
583 SECTION_NAME (section_headers
+ psym
->st_shndx
));
584 else if (strtab
== NULL
)
585 printf (_("<string table index %3ld>"), psym
->st_name
);
587 printf ("%-25.25s", strtab
+ psym
->st_name
);
590 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
593 printf ("%34c%lx", ' ', (unsigned long) relas
[i
].r_addend
);
604 get_mips_dynamic_type (type
)
609 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
610 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
611 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
612 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
613 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
614 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
615 case DT_MIPS_MSYM
: return "MIPS_MSYM";
616 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
617 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
618 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
619 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
620 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
621 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
622 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
623 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
624 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
625 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
626 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
627 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
628 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
629 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
630 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
631 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
632 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
633 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
634 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
635 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
636 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
637 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
638 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
639 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
640 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
641 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
642 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
643 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
644 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
645 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
646 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
647 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
648 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
649 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
650 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
651 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
658 get_dynamic_type (type
)
661 static char buff
[32];
665 case DT_NULL
: return "NULL";
666 case DT_NEEDED
: return "NEEDED";
667 case DT_PLTRELSZ
: return "PLTRELSZ";
668 case DT_PLTGOT
: return "PLTGOT";
669 case DT_HASH
: return "HASH";
670 case DT_STRTAB
: return "STRTAB";
671 case DT_SYMTAB
: return "SYMTAB";
672 case DT_RELA
: return "RELA";
673 case DT_RELASZ
: return "RELASZ";
674 case DT_RELAENT
: return "RELAENT";
675 case DT_STRSZ
: return "STRSZ";
676 case DT_SYMENT
: return "SYMENT";
677 case DT_INIT
: return "INIT";
678 case DT_FINI
: return "FINI";
679 case DT_SONAME
: return "SONAME";
680 case DT_RPATH
: return "RPATH";
681 case DT_SYMBOLIC
: return "SYMBOLIC";
682 case DT_REL
: return "REL";
683 case DT_RELSZ
: return "RELSZ";
684 case DT_RELENT
: return "RELENT";
685 case DT_PLTREL
: return "PLTREL";
686 case DT_DEBUG
: return "DEBUG";
687 case DT_TEXTREL
: return "TEXTREL";
688 case DT_JMPREL
: return "JMPREL";
689 case DT_BIND_NOW
: return "BIND_NOW";
690 case DT_INIT_ARRAY
: return "INIT_ARRAY";
691 case DT_FINI_ARRAY
: return "FINI_ARRAY";
692 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
693 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
695 case DT_PLTPADSZ
: return "PLTPADSZ";
696 case DT_MOVEENT
: return "MOVEENT";
697 case DT_MOVESZ
: return "MOVESZ";
698 case DT_FEATURE_1
: return "FEATURE_1";
699 case DT_POSFLAG_1
: return "POSFLAG_1";
700 case DT_SYMINSZ
: return "SYMINSZ";
701 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
703 case DT_ADDRRNGLO
: return "ADDRRNGLO";
704 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
706 case DT_VERSYM
: return "VERSYM";
708 case DT_RELACOUNT
: return "RELACOUNT";
709 case DT_RELCOUNT
: return "RELCOUNT";
710 case DT_FLAGS_1
: return "FLAGS_1";
711 case DT_VERDEF
: return "VERDEF";
712 case DT_VERDEFNUM
: return "VERDEFNUM";
713 case DT_VERNEED
: return "VERNEED";
714 case DT_VERNEEDNUM
: return "VERNEEDNUM";
716 case DT_AUXILIARY
: return "AUXILARY";
717 case DT_USED
: return "USED";
718 case DT_FILTER
: return "FILTER";
721 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
725 switch (elf_header
.e_machine
)
729 result
= get_mips_dynamic_type (type
);
739 sprintf (buff
, _("Processor Specific: %lx"), type
);
741 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
742 sprintf (buff
, _("Operating System specific: %lx"), type
);
744 sprintf (buff
, _("<unknown>: %lx"), type
);
751 get_file_type (e_type
)
754 static char buff
[32];
758 case ET_NONE
: return _("NONE (None)");
759 case ET_REL
: return _("REL (Relocatable file)");
760 case ET_EXEC
: return _("EXEC (Executable file)");
761 case ET_DYN
: return _("DYN (Shared object file)");
762 case ET_CORE
: return _("CORE (Core file)");
765 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
766 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
767 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
768 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
770 sprintf (buff
, _("<unknown>: %x"), e_type
);
776 get_machine_name (e_machine
)
779 static char buff
[32];
783 case EM_NONE
: return _("None");
784 case EM_M32
: return "WE32100";
785 case EM_SPARC
: return "Sparc";
786 case EM_386
: return "Intel 80386";
787 case EM_68K
: return "MC68000";
788 case EM_88K
: return "MC88000";
789 case EM_486
: return "Intel 80486";
790 case EM_860
: return "Intel 80860";
791 case EM_MIPS
: return "MIPS R3000 big-endian";
792 case EM_S370
: return "Amdahl";
793 case EM_MIPS_RS4_BE
: return "MIPS R4000 big-endian";
794 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
795 case EM_PARISC
: return "HPPA";
796 case EM_PPC_OLD
: return "Power PC (old)";
797 case EM_SPARC32PLUS
: return "Sparc v8+" ;
798 case EM_960
: return "Intel 90860";
799 case EM_PPC
: return "PowerPC";
800 case EM_V800
: return "NEC V800";
801 case EM_FR20
: return "Fujitsu FR20";
802 case EM_RH32
: return "TRW RH32";
803 case EM_MCORE
: return "MCORE";
804 case EM_ARM
: return "ARM";
805 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
806 case EM_SH
: return "Hitachi SH";
807 case EM_SPARCV9
: return "Sparc v9";
808 case EM_TRICORE
: return "Siemens Tricore";
809 case EM_ARC
: return "Argonaut RISC Core";
810 case EM_H8_300
: return "Hitachi H8/300";
811 case EM_H8_300H
: return "Hitachi H8/300H";
812 case EM_H8S
: return "Hitachi H8S";
813 case EM_H8_500
: return "Hitachi H8/500";
814 case EM_IA_64
: return "Intel Merced";
815 case EM_MIPS_X
: return "Stanford MIPS-X";
816 case EM_COLDFIRE
: return "Motorola Coldfire";
817 case EM_68HC12
: return "Motorola M68HC12";
818 case EM_ALPHA
: return "Alpha";
819 case EM_CYGNUS_D10V
: return "d10v";
820 case EM_CYGNUS_D30V
: return "d30v";
821 case EM_CYGNUS_ARC
: return "Arc";
822 case EM_CYGNUS_M32R
: return "Mitsubishi M32r";
823 case EM_CYGNUS_V850
: return "NEC v850";
824 case EM_CYGNUS_MN10300
: return "mn10300";
825 case EM_CYGNUS_MN10200
: return "mn10200";
826 case EM_CYGNUS_FR30
: return "Fujitsu FR30";
829 sprintf (buff
, _("<unknown>: %x"), e_machine
);
835 get_machine_flags (e_flags
, e_machine
)
839 static char buf
[1024];
850 if (e_flags
& EF_CPU32
)
851 strcat (buf
, ", cpu32");
855 if (e_flags
& EF_PPC_EMB
)
856 strcat (buf
, ", emb");
858 if (e_flags
& EF_PPC_RELOCATABLE
)
859 strcat (buf
, ", relocatable");
861 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
862 strcat (buf
, ", relocatable-lib");
866 switch (e_flags
& EF_V850_ARCH
)
869 strcat (buf
, ", v850e");
872 strcat (buf
, ", v850ea");
875 strcat (buf
, ", v850");
878 strcat (buf
, ", unknown v850 architecture variant");
884 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
885 strcat (buf
, ", m32r");
891 if (e_flags
& EF_MIPS_NOREORDER
)
892 strcat (buf
, ", noreorder");
894 if (e_flags
& EF_MIPS_PIC
)
895 strcat (buf
, ", pic");
897 if (e_flags
& EF_MIPS_CPIC
)
898 strcat (buf
, ", cpic");
900 if (e_flags
& EF_MIPS_ABI2
)
901 strcat (buf
, ", abi2");
903 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
904 strcat (buf
, ", mips1");
906 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
907 strcat (buf
, ", mips2");
909 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
910 strcat (buf
, ", mips3");
912 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
913 strcat (buf
, ", mips4");
922 get_machine_data (e_data
)
925 static char buff
[32];
929 case ELFDATA2LSB
: return _("ELFDATA2LSB (little endian)");
930 case ELFDATA2MSB
: return _("ELFDATA2MSB (big endian)");
932 sprintf (buff
, _("<unknown>: %x"), e_data
);
938 get_mips_segment_type (type
)
943 case PT_MIPS_REGINFO
:
947 case PT_MIPS_OPTIONS
:
957 get_segment_type (p_type
)
958 unsigned long p_type
;
960 static char buff
[32];
964 case PT_NULL
: return "NULL";
965 case PT_LOAD
: return "LOAD";
966 case PT_DYNAMIC
: return "DYNAMIC";
967 case PT_INTERP
: return "INTERP";
968 case PT_NOTE
: return "NOTE";
969 case PT_SHLIB
: return "SHLIB";
970 case PT_PHDR
: return "PHDR";
973 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
977 switch (elf_header
.e_machine
)
981 result
= get_mips_segment_type (p_type
);
991 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
993 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
994 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
996 sprintf (buff
, _("<unknown>: %lx"), p_type
);
1003 get_mips_section_type_name (sh_type
)
1004 unsigned int sh_type
;
1008 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1009 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
1010 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1011 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
1012 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
1013 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
1014 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
1015 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
1016 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
1017 case SHT_MIPS_RELD
: return "MIPS_RELD";
1018 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
1019 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
1020 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1021 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
1022 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
1023 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
1024 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
1025 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
1026 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
1027 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
1028 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
1029 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
1030 case SHT_MIPS_LINE
: return "MIPS_LINE";
1031 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
1032 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
1033 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
1034 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
1035 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
1036 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
1037 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1038 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
1039 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
1040 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
1041 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
1042 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
1043 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
1044 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
1045 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
1046 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
1054 get_section_type_name (sh_type
)
1055 unsigned int sh_type
;
1057 static char buff
[32];
1061 case SHT_NULL
: return "NULL";
1062 case SHT_PROGBITS
: return "PROGBITS";
1063 case SHT_SYMTAB
: return "SYMTAB";
1064 case SHT_STRTAB
: return "STRTAB";
1065 case SHT_RELA
: return "RELA";
1066 case SHT_HASH
: return "HASH";
1067 case SHT_DYNAMIC
: return "DYNAMIC";
1068 case SHT_NOTE
: return "NOTE";
1069 case SHT_NOBITS
: return "NOBITS";
1070 case SHT_REL
: return "REL";
1071 case SHT_SHLIB
: return "SHLIB";
1072 case SHT_DYNSYM
: return "DYNSYM";
1073 case SHT_GNU_verdef
: return "VERDEF";
1074 case SHT_GNU_verneed
: return "VERNEED";
1075 case SHT_GNU_versym
: return "VERSYM";
1076 case 0x6ffffff0: return "VERSYM";
1077 case 0x6ffffffc: return "VERDEF";
1078 case 0x7ffffffd: return "AUXILIARY";
1079 case 0x7fffffff: return "FILTER";
1082 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1084 const char * result
;
1086 switch (elf_header
.e_machine
)
1089 case EM_MIPS_RS4_BE
:
1090 result
= get_mips_section_type_name (sh_type
);
1100 sprintf (buff
, "SHT_LOPROC+%x", sh_type
- SHT_LOPROC
);
1102 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
1103 sprintf (buff
, "SHT_LOOS+%x", sh_type
- SHT_LOOS
);
1104 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1105 sprintf (buff
, "SHT_LOUSER+%x", sh_type
- SHT_LOUSER
);
1107 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1113 struct option options
[] =
1115 {"all", no_argument
, 0, 'a'},
1116 {"file-header", no_argument
, 0, 'h'},
1117 {"program-headers", no_argument
, 0, 'l'},
1118 {"headers", no_argument
, 0, 'e'},
1119 {"histogram", no_argument
, & do_histogram
, 1},
1120 {"segments", no_argument
, 0, 'l'},
1121 {"sections", no_argument
, 0, 'S'},
1122 {"section-headers", no_argument
, 0, 'S'},
1123 {"symbols", no_argument
, 0, 's'},
1124 {"syms", no_argument
, 0, 's'},
1125 {"relocs", no_argument
, 0, 'r'},
1126 {"dynamic", no_argument
, 0, 'd'},
1127 {"version-info", no_argument
, 0, 'V'},
1128 {"use-dynamic", no_argument
, 0, 'D'},
1129 {"hex-dump", required_argument
, 0, 'x'},
1130 {"debug-dump", optional_argument
, 0, 'w'},
1131 #ifdef SUPPORT_DISASSEMBLY
1132 {"instruction-dump", required_argument
, 0, 'i'},
1135 {"version", no_argument
, 0, 'v'},
1136 {"help", no_argument
, 0, 'H'},
1137 {0, no_argument
, 0, 0}
1143 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1144 fprintf (stdout
, _(" Options are:\n"));
1145 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V --histogram\n"));
1146 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1147 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1148 fprintf (stdout
, _(" Display the program headers\n"));
1149 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1150 fprintf (stdout
, _(" Display the sections' header\n"));
1151 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1152 fprintf (stdout
, _(" -s or --syms or --symbols Display the symbol table\n"));
1153 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1154 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1155 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1156 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1157 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1158 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1159 fprintf (stdout
, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1160 fprintf (stdout
, _(" Display the contents of DWARF2 debug sections\n"));
1161 #ifdef SUPPORT_DISASSEMBLY
1162 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1163 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1165 fprintf (stdout
, _(" --histogram Display histogram of bucket list lengths\n"));
1166 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1167 fprintf (stdout
, _(" -H or --help Display this information\n"));
1168 fprintf (stdout
, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1174 request_dump (section
, type
)
1175 unsigned int section
;
1178 if (section
>= num_dump_sects
)
1180 char * new_dump_sects
;
1182 new_dump_sects
= (char *) calloc (section
+ 1, 1);
1184 if (new_dump_sects
== NULL
)
1185 error (_("Out of memory allocating dump request table."));
1188 /* Copy current flag settings. */
1189 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
1193 dump_sects
= new_dump_sects
;
1194 num_dump_sects
= section
+ 1;
1199 dump_sects
[section
] |= type
;
1205 parse_args (argc
, argv
)
1214 while ((c
= getopt_long
1215 (argc
, argv
, "ersahldSDw::x:i:vV", options
, NULL
)) != EOF
)
1245 do_using_dynamic
++;
1267 section
= strtoul (optarg
, & cp
, 0);
1268 if (! * cp
&& section
>= 0)
1270 request_dump (section
, HEX_DUMP
);
1290 do_debug_abbrevs
= 1;
1300 do_debug_pubnames
= 1;
1305 do_debug_aranges
= 1;
1309 warn (_("Unrecognised debug option '%s'\n"), optarg
);
1314 #ifdef SUPPORT_DISASSEMBLY
1317 section
= strtoul (optarg
, & cp
, 0);
1318 if (! * cp
&& section
>= 0)
1320 request_dump (section
, DISASS_DUMP
);
1326 print_version (program_name
);
1333 /* xgettext:c-format */
1334 error (_("Invalid option '-%c'\n"), c
);
1341 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
1342 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
1343 && !do_histogram
&& !do_debugging
)
1347 warn (_("Nothing to do.\n"));
1353 get_elf_class (elf_class
)
1354 unsigned char elf_class
;
1356 static char buff
[32];
1360 case ELFCLASSNONE
: return _("none");
1361 case ELFCLASS32
: return _("ELF32");
1362 case ELFCLASS64
: return _("ELF64");
1364 sprintf (buff
, _("<unknown: %lx>"), elf_class
);
1370 get_data_encoding (encoding
)
1371 unsigned char encoding
;
1373 static char buff
[32];
1377 case ELFDATANONE
: return _("none");
1378 case ELFDATA2LSB
: return _("2's complement, little endian");
1379 case ELFDATA2MSB
: return _("2's complement, big endian");
1381 sprintf (buff
, _("<unknown: %lx>"), encoding
);
1387 get_osabi_name (osabi
)
1388 unsigned char osabi
;
1390 static char buff
[32];
1394 case ELFOSABI_SYSV
: return _("UNIX - System V");
1395 case ELFOSABI_HPUX
: return _("UNIX - HP-UX");
1396 case ELFOSABI_STANDALONE
: return _("Standalone App");
1398 sprintf (buff
, _("<unknown: %lx>"), osabi
);
1403 /* Decode the data held in 'elf_header'. */
1405 process_file_header ()
1407 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
1408 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
1409 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
1410 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
1413 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1421 printf (_("ELF Header:\n"));
1422 printf (_(" Magic: "));
1423 for (i
= 0; i
< EI_NIDENT
; i
++)
1424 printf ("%2.2x ", elf_header
.e_ident
[i
]);
1426 printf (_(" Class: %s\n"),
1427 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
1428 printf (_(" Data: %s\n"),
1429 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
1430 printf (_(" Version: %d %s\n"),
1431 elf_header
.e_ident
[EI_VERSION
],
1432 elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
? "(current)" :
1433 elf_header
.e_ident
[EI_VERSION
] != EV_NONE
? "<unknown: %lx>" : "",
1434 elf_header
.e_ident
[EI_VERSION
]);
1435 printf (_(" OS/ABI: %s\n"),
1436 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
1437 printf (_(" ABI Version: %d\n"),
1438 elf_header
.e_ident
[EI_ABIVERSION
]);
1439 printf (_(" Type: %s\n"),
1440 get_file_type (elf_header
.e_type
));
1441 printf (_(" Machine: %s\n"),
1442 get_machine_name (elf_header
.e_machine
));
1443 printf (_(" Version: 0x%lx\n"),
1444 (unsigned long) elf_header
.e_version
);
1445 printf (_(" Data: %s\n"),
1446 get_machine_data (elf_header
.e_ident
[EI_DATA
]));
1447 printf (_(" Entry point address: 0x%lx\n"),
1448 (unsigned long) elf_header
.e_entry
);
1449 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1450 (long) elf_header
.e_phoff
);
1451 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1452 (long) elf_header
.e_shoff
);
1453 printf (_(" Flags: 0x%lx%s\n"),
1454 (unsigned long) elf_header
.e_flags
,
1455 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
1456 printf (_(" Size of this header: %ld (bytes)\n"),
1457 (long) elf_header
.e_ehsize
);
1458 printf (_(" Size of program headers: %ld (bytes)\n"),
1459 (long) elf_header
.e_phentsize
);
1460 printf (_(" Number of program headers: %ld\n"),
1461 (long) elf_header
.e_phnum
);
1462 printf (_(" Size of section headers: %ld (bytes)\n"),
1463 (long) elf_header
.e_shentsize
);
1464 printf (_(" Number of section headers: %ld\n"),
1465 (long) elf_header
.e_shnum
);
1466 printf (_(" Section header string table index: %ld\n"),
1467 (long) elf_header
.e_shstrndx
);
1470 /* Test class after dumping header so that at least the header can be
1471 display on 64 bit binaries. */
1473 binary_class
= elf_header
.e_ident
[EI_CLASS
];
1474 if (binary_class
!= ELFCLASS32
)
1476 error (_("Not a 32 bit ELF file\n"));
1485 process_program_headers (file
)
1488 Elf32_External_Phdr
* phdrs
;
1489 Elf32_Internal_Phdr
* program_headers
;
1490 Elf32_Internal_Phdr
* segment
;
1493 if (elf_header
.e_phnum
== 0)
1496 printf (_("\nThere are no program headers in this file.\n"));
1500 if (do_segments
&& !do_header
)
1502 printf (_("\nElf file is %s\n"), get_file_type (elf_header
.e_type
));
1503 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header
.e_entry
);
1504 printf (_("There are %d program headers, starting at offset %lx:\n"),
1505 elf_header
.e_phnum
, (unsigned long) elf_header
.e_phoff
);
1508 GET_DATA_ALLOC (elf_header
.e_phoff
,
1509 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1510 phdrs
, Elf32_External_Phdr
*, "program headers");
1512 program_headers
= (Elf32_Internal_Phdr
*) malloc
1513 (elf_header
.e_phnum
* sizeof (Elf32_Internal_Phdr
));
1515 if (program_headers
== NULL
)
1517 error (_("Out of memory\n"));
1521 for (i
= 0, segment
= program_headers
;
1522 i
< elf_header
.e_phnum
;
1525 segment
->p_type
= BYTE_GET (phdrs
[i
].p_type
);
1526 segment
->p_offset
= BYTE_GET (phdrs
[i
].p_offset
);
1527 segment
->p_vaddr
= BYTE_GET (phdrs
[i
].p_vaddr
);
1528 segment
->p_paddr
= BYTE_GET (phdrs
[i
].p_paddr
);
1529 segment
->p_filesz
= BYTE_GET (phdrs
[i
].p_filesz
);
1530 segment
->p_memsz
= BYTE_GET (phdrs
[i
].p_memsz
);
1531 segment
->p_flags
= BYTE_GET (phdrs
[i
].p_flags
);
1532 segment
->p_align
= BYTE_GET (phdrs
[i
].p_align
);
1540 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
1542 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1549 for (i
= 0, segment
= program_headers
;
1550 i
< elf_header
.e_phnum
;
1555 printf (" %-11.11s ", get_segment_type (segment
->p_type
));
1556 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
1557 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
1558 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
1559 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
1560 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
1562 (segment
->p_flags
& PF_R
? 'R' : ' '),
1563 (segment
->p_flags
& PF_W
? 'W' : ' '),
1564 (segment
->p_flags
& PF_X
? 'E' : ' '));
1565 printf ("%#lx", (unsigned long) segment
->p_align
);
1568 switch (segment
->p_type
)
1572 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
1573 - (segment
->p_offset
& 0xfffff000);
1578 error (_("more than one dynamic segment\n"));
1580 dynamic_addr
= segment
->p_offset
;
1581 dynamic_size
= segment
->p_filesz
;
1585 if (fseek (file
, segment
->p_offset
, SEEK_SET
))
1586 error (_("Unable to find program interpreter name\n"));
1589 program_interpreter
[0] = 0;
1590 fscanf (file
, "%63s", program_interpreter
);
1593 printf (_("\n [Requesting program interpreter: %s]"),
1594 program_interpreter
);
1600 putc ('\n', stdout
);
1609 if (do_segments
&& section_headers
!= NULL
)
1611 printf (_("\n Section to Segment mapping:\n"));
1612 printf (_(" Segment Sections...\n"));
1614 assert (string_table
!= NULL
);
1616 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1619 Elf32_Internal_Shdr
* section
;
1621 segment
= program_headers
+ i
;
1622 section
= section_headers
;
1624 printf (" %2.2d ", i
);
1626 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
1628 if (section
->sh_size
> 0
1629 /* Compare allocated sections by VMA, unallocated
1630 sections by file offset. */
1631 && (section
->sh_flags
& SHF_ALLOC
1632 ? (section
->sh_addr
>= segment
->p_vaddr
1633 && section
->sh_addr
+ section
->sh_size
1634 <= segment
->p_vaddr
+ segment
->p_memsz
)
1635 : (section
->sh_offset
>= segment
->p_offset
1636 && (section
->sh_offset
+ section
->sh_size
1637 <= segment
->p_offset
+ segment
->p_filesz
))))
1638 printf ("%s ", SECTION_NAME (section
));
1645 free (program_headers
);
1652 get_section_headers (file
)
1655 Elf32_External_Shdr
* shdrs
;
1656 Elf32_Internal_Shdr
* internal
;
1659 GET_DATA_ALLOC (elf_header
.e_shoff
,
1660 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1661 shdrs
, Elf32_External_Shdr
*, "section headers");
1663 section_headers
= (Elf32_Internal_Shdr
*) malloc
1664 (elf_header
.e_shnum
* sizeof (Elf32_Internal_Shdr
));
1666 if (section_headers
== NULL
)
1668 error (_("Out of memory\n"));
1672 for (i
= 0, internal
= section_headers
;
1673 i
< elf_header
.e_shnum
;
1676 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1677 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1678 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
1679 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
1680 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1681 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
1682 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1683 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1684 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
1685 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
1693 static Elf_Internal_Sym
*
1694 get_elf_symbols (file
, offset
, number
)
1696 unsigned long offset
;
1697 unsigned long number
;
1699 Elf32_External_Sym
* esyms
;
1700 Elf_Internal_Sym
* isyms
;
1701 Elf_Internal_Sym
* psym
;
1704 GET_DATA_ALLOC (offset
, number
* sizeof (Elf32_External_Sym
),
1705 esyms
, Elf32_External_Sym
*, "symbols");
1707 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
1711 error (_("Out of memory\n"));
1717 for (j
= 0, psym
= isyms
;
1721 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
1722 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
1723 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
1724 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
1725 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
1726 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
1735 process_section_headers (file
)
1738 Elf32_Internal_Shdr
* section
;
1741 section_headers
= NULL
;
1743 if (elf_header
.e_shnum
== 0)
1746 printf (_("\nThere are no sections in this file.\n"));
1751 if (do_sections
&& !do_header
)
1752 printf (_("There are %d section headers, starting at offset %lx:\n"),
1753 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
1755 if (! get_section_headers (file
))
1758 /* Read in the string table, so that we have names to display. */
1759 section
= section_headers
+ elf_header
.e_shstrndx
;
1761 if (section
->sh_size
!= 0)
1763 unsigned long string_table_offset
;
1765 string_table_offset
= section
->sh_offset
;
1767 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1768 string_table
, char *, "string table");
1771 /* Scan the sections for the dynamic symbol table
1772 and dynamic string table and debug sections. */
1773 dynamic_symbols
= NULL
;
1774 dynamic_strings
= NULL
;
1775 dynamic_syminfo
= NULL
;
1776 for (i
= 0, section
= section_headers
;
1777 i
< elf_header
.e_shnum
;
1780 char * name
= SECTION_NAME (section
);
1782 if (section
->sh_type
== SHT_DYNSYM
)
1784 if (dynamic_symbols
!= NULL
)
1786 error (_("File contains multiple dynamic symbol tables\n"));
1790 dynamic_symbols
= get_elf_symbols
1791 (file
, section
->sh_offset
,
1792 section
->sh_size
/ section
->sh_entsize
);
1794 else if (section
->sh_type
== SHT_STRTAB
1795 && strcmp (name
, ".dynstr") == 0)
1797 if (dynamic_strings
!= NULL
)
1799 error (_("File contains multiple dynamic string tables\n"));
1803 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1804 dynamic_strings
, char *, "dynamic strings");
1806 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
1807 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
)
1808 && strncmp (name
, ".debug_", 7) == 0)
1813 || (do_debug_info
&& (strcmp (name
, "info") == 0))
1814 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
1815 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
1816 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
1817 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
1819 request_dump (i
, DEBUG_DUMP
);
1826 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
1828 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
1830 for (i
= 0, section
= section_headers
;
1831 i
< elf_header
.e_shnum
;
1834 printf (" [%2d] %-17.17s %-15.15s ",
1836 SECTION_NAME (section
),
1837 get_section_type_name (section
->sh_type
));
1839 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
1840 (unsigned long) section
->sh_addr
,
1841 (unsigned long) section
->sh_offset
,
1842 (unsigned long) section
->sh_size
,
1843 (unsigned long) section
->sh_entsize
);
1845 printf (" %c%c%c %2ld %3lx %ld\n",
1846 (section
->sh_flags
& SHF_WRITE
? 'W' : ' '),
1847 (section
->sh_flags
& SHF_ALLOC
? 'A' : ' '),
1848 (section
->sh_flags
& SHF_EXECINSTR
? 'X' : ' '),
1849 (unsigned long) section
->sh_link
,
1850 (unsigned long) section
->sh_info
,
1851 (unsigned long) section
->sh_addralign
);
1857 /* Process the reloc section. */
1859 process_relocs (file
)
1862 unsigned long rel_size
;
1863 unsigned long rel_offset
;
1869 if (do_using_dynamic
)
1876 if (dynamic_info
[DT_REL
])
1878 rel_offset
= dynamic_info
[DT_REL
];
1879 rel_size
= dynamic_info
[DT_RELSZ
];
1882 else if (dynamic_info
[DT_RELA
])
1884 rel_offset
= dynamic_info
[DT_RELA
];
1885 rel_size
= dynamic_info
[DT_RELASZ
];
1888 else if (dynamic_info
[DT_JMPREL
])
1890 rel_offset
= dynamic_info
[DT_JMPREL
];
1891 rel_size
= dynamic_info
[DT_PLTRELSZ
];
1898 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
1899 rel_offset
, rel_size
);
1901 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
1902 dynamic_symbols
, dynamic_strings
, is_rela
);
1905 printf (_("\nThere are no dynamic relocations in this file.\n"));
1909 Elf32_Internal_Shdr
* section
;
1913 for (i
= 0, section
= section_headers
;
1914 i
< elf_header
.e_shnum
;
1917 if ( section
->sh_type
!= SHT_RELA
1918 && section
->sh_type
!= SHT_REL
)
1921 rel_offset
= section
->sh_offset
;
1922 rel_size
= section
->sh_size
;
1926 Elf32_Internal_Shdr
* strsec
;
1927 Elf32_Internal_Shdr
* symsec
;
1928 Elf_Internal_Sym
* symtab
;
1932 printf (_("\nRelocation section "));
1934 if (string_table
== NULL
)
1936 printf ("%d", section
->sh_name
);
1941 printf ("'%s'", SECTION_NAME (section
));
1943 if (strncmp (".rela.", SECTION_NAME (section
), 6) == 0)
1945 else if (strncmp (".rel.", SECTION_NAME (section
), 5) == 0)
1951 printf (_(" at offset 0x%lx contains %lu entries:\n"),
1952 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
1954 symsec
= section_headers
+ section
->sh_link
;
1956 symtab
= get_elf_symbols (file
, symsec
->sh_offset
,
1957 symsec
->sh_size
/ symsec
->sh_entsize
);
1962 strsec
= section_headers
+ symsec
->sh_link
;
1964 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
1965 char *, "string table");
1967 dump_relocations (file
, rel_offset
, rel_size
, symtab
, strtab
, is_rela
);
1977 printf (_("\nThere are no relocations in this file.\n"));
1985 dynamic_segment_mips_val (entry
)
1986 Elf_Internal_Dyn
* entry
;
1988 switch (entry
->d_tag
)
1991 if (entry
->d_un
.d_val
== 0)
1995 static const char * opts
[] =
1997 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
1998 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
1999 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2000 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2005 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
2006 if (entry
->d_un
.d_val
& (1 << cnt
))
2008 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
2015 case DT_MIPS_IVERSION
:
2016 if (dynamic_strings
!= NULL
)
2017 printf ("Interface Version: %s\n",
2018 dynamic_strings
+ entry
->d_un
.d_val
);
2020 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2023 case DT_MIPS_TIME_STAMP
:
2026 time_t time
= entry
->d_un
.d_val
;
2027 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
2028 printf ("Time Stamp: %s\n", timebuf
);
2032 case DT_MIPS_RLD_VERSION
:
2033 case DT_MIPS_LOCAL_GOTNO
:
2034 case DT_MIPS_CONFLICTNO
:
2035 case DT_MIPS_LIBLISTNO
:
2036 case DT_MIPS_SYMTABNO
:
2037 case DT_MIPS_UNREFEXTNO
:
2038 case DT_MIPS_HIPAGENO
:
2039 case DT_MIPS_DELTA_CLASS_NO
:
2040 case DT_MIPS_DELTA_INSTANCE_NO
:
2041 case DT_MIPS_DELTA_RELOC_NO
:
2042 case DT_MIPS_DELTA_SYM_NO
:
2043 case DT_MIPS_DELTA_CLASSSYM_NO
:
2044 case DT_MIPS_COMPACT_SIZE
:
2045 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2049 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2053 /* Parse the dynamic segment */
2055 process_dynamic_segment (file
)
2058 Elf_Internal_Dyn
* entry
;
2059 Elf32_External_Dyn
* edyn
;
2062 if (dynamic_size
== 0)
2065 printf (_("\nThere is no dynamic segment in this file.\n"));
2070 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2071 edyn
, Elf32_External_Dyn
*, "dynamic segment");
2073 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2074 how large .dynamic is now. We can do this even before the byte
2075 swapping since the DT_NULL tag is recognizable. */
2077 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2080 dynamic_segment
= (Elf_Internal_Dyn
*)
2081 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2083 if (dynamic_segment
== NULL
)
2085 error (_("Out of memory\n"));
2090 for (i
= 0, entry
= dynamic_segment
;
2094 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
2095 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
2100 /* Find the appropriate symbol table. */
2101 if (dynamic_symbols
== NULL
)
2103 for (i
= 0, entry
= dynamic_segment
;
2107 unsigned long offset
;
2110 if (entry
->d_tag
!= DT_SYMTAB
)
2113 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
2115 /* Since we do not know how big the symbol table is,
2116 we default to reading in the entire file (!) and
2117 processing that. This is overkill, I know, but it
2120 offset
= entry
->d_un
.d_val
- loadaddr
;
2122 if (fseek (file
, 0, SEEK_END
))
2123 error (_("Unable to seek to end of file!"));
2125 num_syms
= (ftell (file
) - offset
) / sizeof (Elf32_External_Sym
);
2129 error (_("Unable to determine the number of symbols to load\n"));
2133 dynamic_symbols
= get_elf_symbols (file
, offset
, num_syms
);
2137 /* Similarly find a string table. */
2138 if (dynamic_strings
== NULL
)
2140 for (i
= 0, entry
= dynamic_segment
;
2144 unsigned long offset
;
2147 if (entry
->d_tag
!= DT_STRTAB
)
2150 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
2152 /* Since we do not know how big the string table is,
2153 we default to reading in the entire file (!) and
2154 processing that. This is overkill, I know, but it
2157 offset
= entry
->d_un
.d_val
- loadaddr
;
2158 if (fseek (file
, 0, SEEK_END
))
2159 error (_("Unable to seek to end of file\n"));
2160 str_tab_len
= ftell (file
) - offset
;
2162 if (str_tab_len
< 1)
2165 (_("Unable to determine the length of the dynamic string table\n"));
2169 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
2170 "dynamic string table");
2176 /* And find the syminfo section if available. */
2177 if (dynamic_syminfo
== NULL
)
2179 unsigned int syminsz
= 0;
2181 for (i
= 0, entry
= dynamic_segment
;
2185 if (entry
->d_tag
== DT_SYMINENT
)
2187 /* Note: these braces are necessary to avoid a syntax
2188 error from the SunOS4 C compiler. */
2189 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
2191 else if (entry
->d_tag
== DT_SYMINSZ
)
2192 syminsz
= entry
->d_un
.d_val
;
2193 else if (entry
->d_tag
== DT_SYMINFO
)
2194 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
2197 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
2199 Elf_External_Syminfo
*extsyminfo
;
2200 Elf_Internal_Syminfo
*syminfo
;
2202 /* There is a syminfo section. Read the data. */
2203 GET_DATA_ALLOC (dynamic_syminfo_offset
, syminsz
, extsyminfo
,
2204 Elf_External_Syminfo
*, "symbol information");
2206 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
2207 if (dynamic_syminfo
== NULL
)
2209 error (_("Out of memory\n"));
2213 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
2214 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
2217 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
2218 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
2225 if (do_dynamic
&& dynamic_addr
)
2226 printf (_("\nDynamic segment at offset 0x%x contains %d entries:\n"),
2227 dynamic_addr
, dynamic_size
);
2229 printf (_(" Tag Type Name/Value\n"));
2231 for (i
= 0, entry
= dynamic_segment
;
2236 printf (_(" 0x%-8.8lx (%s)%*s"),
2237 (unsigned long) entry
->d_tag
,
2238 get_dynamic_type (entry
->d_tag
),
2239 27 - strlen (get_dynamic_type (entry
->d_tag
)),
2242 switch (entry
->d_tag
)
2248 if (entry
->d_tag
== DT_AUXILIARY
)
2249 printf (_("Auxiliary library"));
2251 printf (_("Filter library"));
2253 if (dynamic_strings
)
2254 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
2256 printf (": %#lx\n", (long) entry
->d_un
.d_val
);
2263 printf (_("Flags:"));
2264 if (entry
->d_un
.d_val
== 0)
2265 printf (_(" None\n"));
2268 unsigned long int val
= entry
->d_un
.d_val
;
2269 if (val
& DTF_1_PARINIT
)
2271 printf (" PARINIT");
2272 val
^= DTF_1_PARINIT
;
2275 printf (" %lx", val
);
2284 printf (_("Flags:"));
2285 if (entry
->d_un
.d_val
== 0)
2286 printf (_(" None\n"));
2289 unsigned long int val
= entry
->d_un
.d_val
;
2290 if (val
& DF_P1_LAZYLOAD
)
2292 printf (" LAZYLOAD");
2293 val
^= DF_P1_LAZYLOAD
;
2295 if (val
& DF_P1_GROUPPERM
)
2297 printf (" GROUPPERM");
2298 val
^= DF_P1_GROUPPERM
;
2301 printf (" %lx", val
);
2310 printf (_("Flags:"));
2311 if (entry
->d_un
.d_val
== 0)
2312 printf (_(" None\n"));
2315 unsigned long int val
= entry
->d_un
.d_val
;
2321 if (val
& DF_1_GLOBAL
)
2326 if (val
& DF_1_GROUP
)
2331 if (val
& DF_1_NODELETE
)
2333 printf (" NODELETE");
2334 val
^= DF_1_NODELETE
;
2336 if (val
& DF_1_LOADFLTR
)
2338 printf (" LOADFLTR");
2339 val
^= DF_1_LOADFLTR
;
2341 if (val
& DF_1_INITFIRST
)
2343 printf (" INITFIRST");
2344 val
^= DF_1_INITFIRST
;
2346 if (val
& DF_1_NOOPEN
)
2351 if (val
& DF_1_ORIGIN
)
2356 if (val
& DF_1_DIRECT
)
2361 if (val
& DF_1_TRANS
)
2366 if (val
& DF_1_INTERPOSE
)
2368 printf (" INTERPOSE");
2369 val
^= DF_1_INTERPOSE
;
2372 printf (" %lx", val
);
2380 puts (get_dynamic_type (entry
->d_un
.d_val
));
2399 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
2405 if (dynamic_strings
== NULL
)
2408 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2412 switch (entry
->d_tag
)
2415 printf (_("Shared library: [%s]"), name
);
2417 if (strcmp (name
, program_interpreter
))
2420 printf (_(" program interpreter\n"));
2424 printf (_("Library soname: [%s]\n"), name
);
2428 printf (_("Library rpath: [%s]\n"), name
);
2432 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2436 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2450 case DT_INIT_ARRAYSZ
:
2451 case DT_FINI_ARRAYSZ
:
2453 printf ("%lu (bytes)\n", (unsigned long) entry
->d_un
.d_val
);
2461 printf ("%lu\n", (unsigned long) entry
->d_un
.d_val
);
2472 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
2476 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2480 printf (_("Not needed object: [%s]\n"), name
);
2485 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2490 /* The value of this entry is ignored. */
2494 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
2495 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
2500 switch (elf_header
.e_machine
)
2503 case EM_MIPS_RS4_BE
:
2504 dynamic_segment_mips_val (entry
);
2507 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2518 get_ver_flags (flags
)
2521 static char buff
[32];
2528 if (flags
& VER_FLG_BASE
)
2529 strcat (buff
, "BASE ");
2531 if (flags
& VER_FLG_WEAK
)
2533 if (flags
& VER_FLG_BASE
)
2534 strcat (buff
, "| ");
2536 strcat (buff
, "WEAK ");
2539 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
2540 strcat (buff
, "| <unknown>");
2545 /* Display the contents of the version sections. */
2547 process_version_sections (file
)
2550 Elf32_Internal_Shdr
* section
;
2557 for (i
= 0, section
= section_headers
;
2558 i
< elf_header
.e_shnum
;
2561 switch (section
->sh_type
)
2563 case SHT_GNU_verdef
:
2565 Elf_External_Verdef
* edefs
;
2572 (_("\nVersion definition section '%s' contains %ld entries:\n"),
2573 SECTION_NAME (section
), section
->sh_info
);
2575 printf (_(" Addr: 0x"));
2576 printf_vma (section
->sh_addr
);
2577 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
2578 (unsigned long) section
->sh_offset
, section
->sh_link
,
2579 SECTION_NAME (section_headers
+ section
->sh_link
));
2581 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2582 edefs
, Elf_External_Verdef
*,
2583 "version definition section");
2585 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
2588 Elf_External_Verdef
* edef
;
2589 Elf_Internal_Verdef ent
;
2590 Elf_External_Verdaux
* eaux
;
2591 Elf_Internal_Verdaux aux
;
2595 vstart
= ((char *) edefs
) + idx
;
2597 edef
= (Elf_External_Verdef
*) vstart
;
2599 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
2600 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
2601 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
2602 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
2603 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
2604 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
2605 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
2607 printf (_(" %#06x: Rev: %d Flags: %s"),
2608 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
2610 printf (_(" Index: %d Cnt: %d "),
2611 ent
.vd_ndx
, ent
.vd_cnt
);
2613 vstart
+= ent
.vd_aux
;
2615 eaux
= (Elf_External_Verdaux
*) vstart
;
2617 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
2618 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
2620 if (dynamic_strings
)
2621 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
2623 printf (_("Name index: %ld\n"), aux
.vda_name
);
2625 isum
= idx
+ ent
.vd_aux
;
2627 for (j
= 1; j
< ent
.vd_cnt
; j
++)
2629 isum
+= aux
.vda_next
;
2630 vstart
+= aux
.vda_next
;
2632 eaux
= (Elf_External_Verdaux
*) vstart
;
2634 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
2635 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
2637 if (dynamic_strings
)
2638 printf (_(" %#06x: Parent %d: %s\n"),
2639 isum
, j
, dynamic_strings
+ aux
.vda_name
);
2641 printf (_(" %#06x: Parent %d, name index: %ld\n"),
2642 isum
, j
, aux
.vda_name
);
2652 case SHT_GNU_verneed
:
2654 Elf_External_Verneed
* eneed
;
2660 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
2661 SECTION_NAME (section
), section
->sh_info
);
2663 printf (_(" Addr: 0x"));
2664 printf_vma (section
->sh_addr
);
2665 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
2666 (unsigned long) section
->sh_offset
, section
->sh_link
,
2667 SECTION_NAME (section_headers
+ section
->sh_link
));
2669 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2670 eneed
, Elf_External_Verneed
*,
2671 "version need section");
2673 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
2675 Elf_External_Verneed
* entry
;
2676 Elf_Internal_Verneed ent
;
2681 vstart
= ((char *) eneed
) + idx
;
2683 entry
= (Elf_External_Verneed
*) vstart
;
2685 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
2686 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
2687 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
2688 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
2689 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
2691 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
2693 if (dynamic_strings
)
2694 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
2696 printf (_(" File: %lx"), ent
.vn_file
);
2698 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
2700 vstart
+= ent
.vn_aux
;
2702 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
2704 Elf_External_Vernaux
* eaux
;
2705 Elf_Internal_Vernaux aux
;
2707 eaux
= (Elf_External_Vernaux
*) vstart
;
2709 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
2710 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
2711 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
2712 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
2713 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
2715 if (dynamic_strings
)
2716 printf (_(" %#06x: Name: %s"),
2717 isum
, dynamic_strings
+ aux
.vna_name
);
2719 printf (_(" %#06x: Name index: %lx"),
2720 isum
, aux
.vna_name
);
2722 printf (_(" Flags: %s Version: %d\n"),
2723 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
2725 isum
+= aux
.vna_next
;
2726 vstart
+= aux
.vna_next
;
2736 case SHT_GNU_versym
:
2738 Elf32_Internal_Shdr
* link_section
;
2741 unsigned char * edata
;
2742 unsigned short * data
;
2744 Elf_Internal_Sym
* symbols
;
2745 Elf32_Internal_Shdr
* string_sec
;
2747 link_section
= section_headers
+ section
->sh_link
;
2748 total
= section
->sh_size
/ section
->sh_entsize
;
2752 symbols
= get_elf_symbols
2753 (file
, link_section
->sh_offset
,
2754 link_section
->sh_size
/ link_section
->sh_entsize
);
2756 string_sec
= section_headers
+ link_section
->sh_link
;
2758 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
2759 strtab
, char *, "version string table");
2761 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
2762 SECTION_NAME (section
), total
);
2764 printf (_(" Addr: "));
2765 printf_vma (section
->sh_addr
);
2766 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
2767 (unsigned long) section
->sh_offset
, section
->sh_link
,
2768 SECTION_NAME (link_section
));
2770 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
2772 total
* sizeof (short), edata
,
2773 unsigned char *, "version symbol data");
2775 data
= (unsigned short *) malloc (total
* sizeof (short));
2777 for (cnt
= total
; cnt
--;)
2778 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
2783 for (cnt
= 0; cnt
< total
; cnt
+= 4)
2787 printf (" %03x:", cnt
);
2789 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
2790 switch (data
[cnt
+ j
])
2793 fputs (_(" 0 (*local*) "), stdout
);
2797 fputs (_(" 1 (*global*) "), stdout
);
2801 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
2802 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
2804 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
2805 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
2808 /* We must test both. */
2809 Elf_Internal_Verneed ivn
;
2810 unsigned long offset
;
2812 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
2817 Elf_External_Verneed evn
;
2818 Elf_External_Vernaux evna
;
2819 Elf_Internal_Vernaux ivna
;
2820 unsigned long vna_off
;
2822 GET_DATA (offset
, evn
, "version need");
2824 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
2825 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
2827 vna_off
= offset
+ ivn
.vn_aux
;
2831 GET_DATA (vna_off
, evna
,
2832 "version need aux (1)");
2834 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
2835 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
2837 vna_off
+= ivna
.vna_next
;
2839 while (ivna
.vna_other
!= data
[cnt
+ j
]
2840 && ivna
.vna_next
!= 0);
2842 if (ivna
.vna_other
== data
[cnt
+ j
])
2844 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
2846 nn
+= printf ("(%s%-*s",
2847 strtab
+ ivna
.vna_name
,
2853 else if (ivn
.vn_next
== 0)
2855 if (data
[cnt
+ j
] != 0x8001)
2857 Elf_Internal_Verdef ivd
;
2858 Elf_External_Verdef evd
;
2860 offset
= version_info
2861 [DT_VERSIONTAGIDX (DT_VERDEF
)]
2866 GET_DATA (offset
, evd
,
2867 "version definition");
2869 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
2870 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
2872 offset
+= ivd
.vd_next
;
2875 != (data
[cnt
+ j
] & 0x7fff)
2876 && ivd
.vd_next
!= 0);
2879 == (data
[cnt
+ j
] & 0x7fff))
2881 Elf_External_Verdaux evda
;
2882 Elf_Internal_Verdaux ivda
;
2884 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
2886 GET_DATA (offset
+ ivd
.vd_aux
, evda
,
2887 "version definition aux");
2890 BYTE_GET (evda
.vda_name
);
2894 strtab
+ ivda
.vda_name
,
2905 offset
+= ivn
.vn_next
;
2907 while (ivn
.vn_next
);
2909 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
2911 Elf_Internal_Verneed ivn
;
2912 unsigned long offset
;
2914 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
2919 Elf_Internal_Vernaux ivna
;
2920 Elf_External_Verneed evn
;
2921 Elf_External_Vernaux evna
;
2922 unsigned long a_off
;
2924 GET_DATA (offset
, evn
, "version need");
2926 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
2927 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
2929 a_off
= offset
+ ivn
.vn_aux
;
2933 GET_DATA (a_off
, evna
,
2934 "version need aux (2)");
2936 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
2937 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
2939 a_off
+= ivna
.vna_next
;
2941 while (ivna
.vna_other
!= data
[cnt
+ j
]
2942 && ivna
.vna_next
!= 0);
2944 if (ivna
.vna_other
== data
[cnt
+ j
])
2946 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
2948 nn
+= printf ("(%s%-*s",
2949 strtab
+ ivna
.vna_name
,
2956 offset
+= ivn
.vn_next
;
2958 while (ivn
.vn_next
);
2960 else if (data
[cnt
+ j
] != 0x8001)
2962 Elf_Internal_Verdef ivd
;
2963 Elf_External_Verdef evd
;
2964 unsigned long offset
;
2966 offset
= version_info
2967 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
2971 GET_DATA (offset
, evd
, "version def");
2973 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
2974 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
2976 offset
+= ivd
.vd_next
;
2978 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
2979 && ivd
.vd_next
!= 0);
2981 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
2983 Elf_External_Verdaux evda
;
2984 Elf_Internal_Verdaux ivda
;
2986 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
2988 GET_DATA (offset
- ivd
.vd_next
+ ivd
.vd_aux
,
2989 evda
, "version def aux");
2991 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
2993 nn
+= printf ("(%s%-*s",
2994 strtab
+ ivda
.vda_name
,
3002 printf ("%*c", 18 - nn
, ' ');
3020 printf (_("\nNo version information found in this file.\n"));
3026 get_symbol_binding (binding
)
3027 unsigned int binding
;
3029 static char buff
[32];
3033 case STB_LOCAL
: return _("LOCAL");
3034 case STB_GLOBAL
: return _("GLOBAL");
3035 case STB_WEAK
: return _("WEAK");
3037 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
3038 sprintf (buff
, _("<processor specific>: %d"), binding
);
3039 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
3040 sprintf (buff
, _("<OS specific>: %d"), binding
);
3042 sprintf (buff
, _("<unknown>: %d"), binding
);
3048 get_symbol_type (type
)
3051 static char buff
[32];
3055 case STT_NOTYPE
: return _("NOTYPE");
3056 case STT_OBJECT
: return _("OBJECT");
3057 case STT_FUNC
: return _("FUNC");
3058 case STT_SECTION
: return _("SECTION");
3059 case STT_FILE
: return _("FILE");
3061 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
3062 sprintf (buff
, _("<processor specific>: %d"), type
);
3063 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
3064 sprintf (buff
, _("<OS specific>: %d"), type
);
3066 sprintf (buff
, _("<unknown>: %d"), type
);
3072 get_symbol_index_type (type
)
3077 case SHN_UNDEF
: return "UND";
3078 case SHN_ABS
: return "ABS";
3079 case SHN_COMMON
: return "COM";
3081 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
3083 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
3085 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
3089 static char buff
[32];
3091 sprintf (buff
, "%3d", type
);
3099 get_dynamic_data (file
, number
)
3101 unsigned int number
;
3106 e_data
= (char *) malloc (number
* 4);
3110 error (_("Out of memory\n"));
3114 if (fread (e_data
, 4, number
, file
) != number
)
3116 error (_("Unable to read in dynamic data\n"));
3120 i_data
= (int *) malloc (number
* sizeof (* i_data
));
3124 error (_("Out of memory\n"));
3130 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
3137 /* Dump the symbol table */
3139 process_symbol_table (file
)
3142 Elf32_Internal_Shdr
* section
;
3147 int * buckets
= NULL
;
3148 int * chains
= NULL
;
3150 if (! do_syms
&& !do_histogram
)
3153 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
3156 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
3158 error (_("Unable to seek to start of dynamic information"));
3162 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
3164 error (_("Failed to read in number of buckets\n"));
3168 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
3170 error (_("Failed to read in number of chains\n"));
3174 nbuckets
= byte_get (nb
, 4);
3175 nchains
= byte_get (nc
, 4);
3177 buckets
= get_dynamic_data (file
, nbuckets
);
3178 chains
= get_dynamic_data (file
, nchains
);
3180 if (buckets
== NULL
|| chains
== NULL
)
3185 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
3190 printf (_("\nSymbol table for image:\n"));
3191 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3193 for (hn
= 0; hn
< nbuckets
; hn
++)
3198 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3200 Elf_Internal_Sym
* psym
;
3202 psym
= dynamic_symbols
+ si
;
3204 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3206 (unsigned long) psym
->st_value
,
3207 (unsigned long) psym
->st_size
,
3208 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3209 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3212 printf ("%3.3s", get_symbol_index_type (psym
->st_shndx
));
3214 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
3218 else if (do_syms
&& !do_using_dynamic
)
3222 for (i
= 0, section
= section_headers
;
3223 i
< elf_header
.e_shnum
;
3228 Elf_Internal_Sym
* symtab
;
3229 Elf_Internal_Sym
* psym
;
3232 if ( section
->sh_type
!= SHT_SYMTAB
3233 && section
->sh_type
!= SHT_DYNSYM
)
3236 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3237 SECTION_NAME (section
),
3238 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
3239 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3242 symtab
= get_elf_symbols (file
, section
->sh_offset
,
3243 section
->sh_size
/ section
->sh_entsize
);
3247 if (section
->sh_link
== elf_header
.e_shstrndx
)
3248 strtab
= string_table
;
3251 Elf32_Internal_Shdr
* string_sec
;
3253 string_sec
= section_headers
+ section
->sh_link
;
3255 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3256 strtab
, char *, "string table");
3259 for (si
= 0, psym
= symtab
;
3260 si
< section
->sh_size
/ section
->sh_entsize
;
3263 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3265 (unsigned long) psym
->st_value
,
3266 (unsigned long) psym
->st_size
,
3267 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3268 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3271 printf ("%4s", get_symbol_index_type (psym
->st_shndx
));
3273 printf (" %s", strtab
+ psym
->st_name
);
3275 if (section
->sh_type
== SHT_DYNSYM
&&
3276 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
3278 unsigned char data
[2];
3279 unsigned short vers_data
;
3280 unsigned long offset
;
3284 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3287 GET_DATA (offset
+ si
* sizeof (vers_data
), data
,
3290 vers_data
= byte_get (data
, 2);
3292 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
3293 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
3296 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
3298 if ((vers_data
& 0x8000) || vers_data
> 1)
3300 if (is_nobits
|| ! check_def
)
3302 Elf_External_Verneed evn
;
3303 Elf_Internal_Verneed ivn
;
3304 Elf_Internal_Vernaux ivna
;
3306 /* We must test both. */
3307 offset
= version_info
3308 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
3310 GET_DATA (offset
, evn
, "version need");
3312 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3313 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3317 unsigned long vna_off
;
3319 vna_off
= offset
+ ivn
.vn_aux
;
3323 Elf_External_Vernaux evna
;
3325 GET_DATA (vna_off
, evna
,
3326 "version need aux (3)");
3328 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3329 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3330 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3332 vna_off
+= ivna
.vna_next
;
3334 while (ivna
.vna_other
!= vers_data
3335 && ivna
.vna_next
!= 0);
3337 if (ivna
.vna_other
== vers_data
)
3340 offset
+= ivn
.vn_next
;
3342 while (ivn
.vn_next
!= 0);
3344 if (ivna
.vna_other
== vers_data
)
3347 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
3350 else if (! is_nobits
)
3351 error (_("bad dynamic symbol"));
3358 if (vers_data
!= 0x8001)
3360 Elf_Internal_Verdef ivd
;
3361 Elf_Internal_Verdaux ivda
;
3362 Elf_External_Verdaux evda
;
3363 unsigned long offset
;
3366 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
3371 Elf_External_Verdef evd
;
3373 GET_DATA (offset
, evd
, "version def");
3375 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3376 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3377 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3379 offset
+= ivd
.vd_next
;
3381 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
3382 && ivd
.vd_next
!= 0);
3384 offset
-= ivd
.vd_next
;
3385 offset
+= ivd
.vd_aux
;
3387 GET_DATA (offset
, evda
, "version def aux");
3389 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3391 if (psym
->st_name
!= ivda
.vda_name
)
3392 printf ((vers_data
& 0x8000)
3394 strtab
+ ivda
.vda_name
);
3404 if (strtab
!= string_table
)
3410 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
3412 if (do_histogram
&& buckets
!= NULL
)
3419 int nzero_counts
= 0;
3422 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
3424 printf (_(" Length Number %% of total Coverage\n"));
3426 lengths
= (int *) calloc (nbuckets
, sizeof (int));
3427 if (lengths
== NULL
)
3429 error (_("Out of memory"));
3432 for (hn
= 0; hn
< nbuckets
; ++hn
)
3437 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3440 if (maxlength
< ++lengths
[hn
])
3445 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
3448 error (_("Out of memory"));
3452 for (hn
= 0; hn
< nbuckets
; ++hn
)
3453 ++ counts
[lengths
[hn
]];
3455 printf (" 0 %-10d (%5.1f%%)\n",
3456 counts
[0], (counts
[0] * 100.0) / nbuckets
);
3457 for (si
= 1; si
<= maxlength
; ++si
)
3459 nzero_counts
+= counts
[si
] * si
;
3460 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
3461 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
3462 (nzero_counts
* 100.0) / nsyms
);
3469 if (buckets
!= NULL
)
3479 process_syminfo (file
)
3484 if (dynamic_syminfo
== NULL
3486 /* No syminfo, this is ok. */
3489 /* There better should be a dynamic symbol section. */
3490 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
3494 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
3495 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
3497 printf (_(" Num: Name BoundTo Flags\n"));
3498 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
3500 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
3502 printf ("%4d: %-30s ", i
,
3503 dynamic_strings
+ dynamic_symbols
[i
].st_name
);
3505 switch (dynamic_syminfo
[i
].si_boundto
)
3507 case SYMINFO_BT_SELF
:
3508 fputs ("SELF ", stdout
);
3510 case SYMINFO_BT_PARENT
:
3511 fputs ("PARENT ", stdout
);
3514 if (dynamic_syminfo
[i
].si_boundto
> 0
3515 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
3518 + dynamic_segment
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
3520 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
3524 if (flags
& SYMINFO_FLG_DIRECT
)
3526 if (flags
& SYMINFO_FLG_PASSTHRU
)
3527 printf (" PASSTHRU");
3528 if (flags
& SYMINFO_FLG_COPY
)
3530 if (flags
& SYMINFO_FLG_LAZYLOAD
)
3531 printf (" LAZYLOAD");
3539 #ifdef SUPPORT_DISASSEMBLY
3541 disassemble_section (section
, file
)
3542 Elf32_Internal_Shdr
* section
;
3545 printf (_("\nAssembly dump of section %s\n"),
3546 SECTION_NAME (section
));
3548 /* XXX -- to be done --- XXX */
3555 dump_section (section
, file
)
3556 Elf32_Internal_Shdr
* section
;
3561 unsigned char * data
;
3562 unsigned char * start
;
3564 bytes
= section
->sh_size
;
3568 printf (_("\nSection '%s' has no data to dump.\n"),
3569 SECTION_NAME (section
));
3573 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
3575 addr
= section
->sh_addr
;
3577 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, unsigned char *,
3588 lbytes
= (bytes
> 16 ? 16 : bytes
);
3590 printf (" 0x%8.8x ", addr
);
3592 switch (elf_header
.e_ident
[EI_DATA
])
3595 for (j
= 15; j
>= 0; j
--)
3598 printf ("%2.2x", data
[j
]);
3608 for (j
= 0; j
< 16; j
++)
3611 printf ("%2.2x", data
[j
]);
3621 for (j
= 0; j
< lbytes
; j
++)
3624 if (k
>= ' ' && k
< 0x80)
3643 static unsigned long int
3644 read_leb128 (data
, length_return
, sign
)
3645 unsigned char * data
;
3646 int * length_return
;
3649 unsigned long int result
= 0;
3650 unsigned int num_read
= 0;
3659 result
|= (byte
& 0x7f) << shift
;
3664 while (byte
& 0x80);
3666 if (length_return
!= NULL
)
3667 * length_return
= num_read
;
3669 if (sign
&& (shift
< 32) && (byte
& 0x40))
3670 result
|= -1 << shift
;
3675 typedef struct State_Machine_Registers
3677 unsigned long address
;
3680 unsigned int column
;
3684 /* This variable hold the number of the last entry seen
3685 in the File Table. */
3686 unsigned int last_file_entry
;
3689 static SMR state_machine_regs
;
3692 reset_state_machine (is_stmt
)
3695 state_machine_regs
.address
= 0;
3696 state_machine_regs
.file
= 1;
3697 state_machine_regs
.line
= 1;
3698 state_machine_regs
.column
= 0;
3699 state_machine_regs
.is_stmt
= is_stmt
;
3700 state_machine_regs
.basic_block
= 0;
3701 state_machine_regs
.end_sequence
= 0;
3702 state_machine_regs
.last_file_entry
= 0;
3705 /* Handled an extend line op. Returns true if this is the end
3708 process_extended_line_op (data
, is_stmt
)
3709 unsigned char * data
;
3712 unsigned char op_code
;
3715 unsigned char * name
;
3718 len
= read_leb128 (data
, & bytes_read
, 0);
3723 warn (_("badly formed extended line op encountered!"));
3728 op_code
= * data
++;
3730 printf (_(" Extended opcode %d: "), op_code
);
3734 case DW_LNE_end_sequence
:
3735 printf (_("End of Sequence\n\n"));
3736 reset_state_machine (is_stmt
);
3739 case DW_LNE_set_address
:
3740 /* XXX - assumption here that address size is 4! */
3741 adr
= byte_get (data
, 4);
3742 printf (_("set Address to 0x%lx\n"), adr
);
3743 state_machine_regs
.address
= adr
;
3746 case DW_LNE_define_file
:
3747 printf (_(" define new File Table entry\n"));
3748 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3750 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
3752 data
+= strlen (data
) + 1;
3753 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3755 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3757 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3758 printf (_("%s\n\n"), name
);
3762 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
3771 display_debug_lines (section
, start
, file
)
3772 Elf32_Internal_Shdr
* section
;
3773 unsigned char * start
;
3776 DWARF2_External_LineInfo
* external
;
3777 DWARF2_Internal_LineInfo info
;
3778 unsigned char * standard_opcodes
;
3779 unsigned char * data
= start
;
3780 unsigned char * end
= start
+ section
->sh_size
;
3781 unsigned char * end_of_sequence
;
3784 printf (_("\nDump of debug contents of section %s:\n\n"),
3785 SECTION_NAME (section
));
3789 external
= (DWARF2_External_LineInfo
*) data
;
3791 /* Check the length of the block. */
3792 info
.li_length
= BYTE_GET (external
->li_length
);
3793 if (info
.li_length
> section
->sh_size
)
3796 (_("The line info appears to be corrupt - the section is too small\n"));
3800 /* Check its version number. */
3801 info
.li_version
= BYTE_GET (external
->li_version
);
3802 if (info
.li_version
!= 2)
3804 warn (_("Only DWARF version 2 line info is currently supported.\n"));
3808 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
3809 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
3810 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
3811 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
3812 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
3813 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
3815 /* Sign extend the line base field. */
3816 info
.li_line_base
<<= 24;
3817 info
.li_line_base
>>= 24;
3819 printf (_(" Length: %ld\n"), info
.li_length
);
3820 printf (_(" DWARF Version: %d\n"), info
.li_version
);
3821 printf (_(" Prolgue Length: %d\n"), info
.li_prologue_length
);
3822 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
3823 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
3824 printf (_(" Line Base: %d\n"), info
.li_line_base
);
3825 printf (_(" Line Range: %d\n"), info
.li_line_range
);
3826 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
3828 end_of_sequence
= data
+ info
.li_length
+ sizeof (info
.li_length
);
3830 reset_state_machine (info
.li_default_is_stmt
);
3832 /* Display the contents of the Opcodes table. */
3833 standard_opcodes
= data
+ sizeof (* external
);
3835 printf (_("\n Opcodes:\n"));
3837 for (i
= 1; i
< info
.li_opcode_base
; i
++)
3838 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
]);
3840 /* Display the contents of the Directory table. */
3841 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
3844 printf (_("\n The Directory Table is empty.\n"));
3847 printf (_("\n The Directory Table:\n"));
3851 printf (_(" %s\n"), data
);
3853 data
+= strlen (data
) + 1;
3857 /* Skip the NUL at the end of the table. */
3860 /* Display the contents of the File Name table. */
3862 printf (_("\n The File Name Table is empty.\n"));
3865 printf (_("\n The File Name Table:\n"));
3866 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3873 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
3876 data
+= strlen (data
) + 1;
3878 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3880 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3882 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
3884 printf (_("%s\n"), name
);
3888 /* Skip the NUL at the end of the table. */
3891 /* Now display the statements. */
3892 printf (_("\n Line Number Statements:\n"));
3895 while (data
< end_of_sequence
)
3897 unsigned char op_code
;
3901 op_code
= * data
++;
3905 case DW_LNS_extended_op
:
3906 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
3910 printf (_(" Copy\n"));
3913 case DW_LNS_advance_pc
:
3914 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
3916 state_machine_regs
.address
+= adv
;
3917 printf (_(" Advance PC by %d to %lx\n"), adv
,
3918 state_machine_regs
.address
);
3921 case DW_LNS_advance_line
:
3922 adv
= read_leb128 (data
, & bytes_read
, 1);
3924 state_machine_regs
.line
+= adv
;
3925 printf (_(" Advance Line by %d to %d\n"), adv
,
3926 state_machine_regs
.line
);
3929 case DW_LNS_set_file
:
3930 adv
= read_leb128 (data
, & bytes_read
, 0);
3932 printf (_(" Set File Name to entry %d in the File Name Table\n"),
3934 state_machine_regs
.file
= adv
;
3937 case DW_LNS_set_column
:
3938 adv
= read_leb128 (data
, & bytes_read
, 0);
3940 printf (_(" Set column to %d\n"), adv
);
3941 state_machine_regs
.column
= adv
;
3944 case DW_LNS_negate_stmt
:
3945 adv
= state_machine_regs
.is_stmt
;
3947 printf (_(" Set is_stmt to %d\n"), adv
);
3948 state_machine_regs
.is_stmt
= adv
;
3951 case DW_LNS_set_basic_block
:
3952 printf (_(" Set basic block\n"));
3953 state_machine_regs
.basic_block
= 1;
3956 case DW_LNS_const_add_pc
:
3957 adv
= (255 - info
.li_opcode_base
) / info
.li_line_range
;
3958 state_machine_regs
.address
+= adv
;
3959 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
3960 state_machine_regs
.address
);
3963 case DW_LNS_fixed_advance_pc
:
3964 adv
= byte_get (data
, 2);
3966 state_machine_regs
.address
+= adv
;
3967 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
3968 adv
, state_machine_regs
.address
);
3972 op_code
-= info
.li_opcode_base
;
3973 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
3974 state_machine_regs
.address
+= adv
;
3975 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
3976 op_code
, adv
, state_machine_regs
.address
);
3977 adv
+= (op_code
% info
.li_line_range
) + info
.li_line_base
;
3978 state_machine_regs
.line
+= adv
;
3979 printf (_(" and Line by %d to %d\n"),
3980 adv
, state_machine_regs
.line
);
3991 display_debug_pubnames (section
, start
, file
)
3992 Elf32_Internal_Shdr
* section
;
3993 unsigned char * start
;
3996 DWARF2_External_PubNames
* external
;
3997 DWARF2_Internal_PubNames pubnames
;
3998 unsigned char * end
;
4000 end
= start
+ section
->sh_size
;
4002 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4006 unsigned char * data
;
4007 unsigned long offset
;
4009 external
= (DWARF2_External_PubNames
*) start
;
4011 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
4012 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
4013 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
4014 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
4016 data
= start
+ sizeof (* external
);
4017 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
4019 if (pubnames
.pn_version
!= 2)
4021 warn (_("Only DWARF 2 pubnames are currently supported"));
4025 printf (_(" Length: %ld\n"),
4026 pubnames
.pn_length
);
4027 printf (_(" Version: %d\n"),
4028 pubnames
.pn_version
);
4029 printf (_(" Offset into .debug_info section: %ld\n"),
4030 pubnames
.pn_offset
);
4031 printf (_(" Size of area in .debug_info section: %ld\n"),
4034 printf (_("\n Offset\tName\n"));
4038 offset
= byte_get (data
, 4);
4043 printf (" %ld\t\t%s\n", offset
, data
);
4044 data
+= strlen (data
) + 1;
4047 while (offset
!= 0);
4060 case DW_TAG_padding
: return "DW_TAG_padding";
4061 case DW_TAG_array_type
: return "DW_TAG_array_type";
4062 case DW_TAG_class_type
: return "DW_TAG_class_type";
4063 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
4064 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
4065 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
4066 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
4067 case DW_TAG_label
: return "DW_TAG_label";
4068 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
4069 case DW_TAG_member
: return "DW_TAG_member";
4070 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
4071 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
4072 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
4073 case DW_TAG_string_type
: return "DW_TAG_string_type";
4074 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
4075 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
4076 case DW_TAG_typedef
: return "DW_TAG_typedef";
4077 case DW_TAG_union_type
: return "DW_TAG_union_type";
4078 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
4079 case DW_TAG_variant
: return "DW_TAG_variant";
4080 case DW_TAG_common_block
: return "DW_TAG_common_block";
4081 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
4082 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
4083 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
4084 case DW_TAG_module
: return "DW_TAG_module";
4085 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
4086 case DW_TAG_set_type
: return "DW_TAG_set_type";
4087 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
4088 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
4089 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
4090 case DW_TAG_base_type
: return "DW_TAG_base_type";
4091 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
4092 case DW_TAG_const_type
: return "DW_TAG_const_type";
4093 case DW_TAG_constant
: return "DW_TAG_constant";
4094 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
4095 case DW_TAG_file_type
: return "DW_TAG_file_type";
4096 case DW_TAG_friend
: return "DW_TAG_friend";
4097 case DW_TAG_namelist
: return "DW_TAG_namelist";
4098 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
4099 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
4100 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
4101 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
4102 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
4103 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
4104 case DW_TAG_try_block
: return "DW_TAG_try_block";
4105 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
4106 case DW_TAG_variable
: return "DW_TAG_variable";
4107 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
4108 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
4109 case DW_TAG_format_label
: return "DW_TAG_format_label";
4110 case DW_TAG_function_template
: return "DW_TAG_function_template";
4111 case DW_TAG_class_template
: return "DW_TAG_class_template";
4114 static char buffer
[100];
4116 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
4123 get_AT_name (attribute
)
4124 unsigned long attribute
;
4128 case DW_AT_sibling
: return "DW_AT_sibling";
4129 case DW_AT_location
: return "DW_AT_location";
4130 case DW_AT_name
: return "DW_AT_name";
4131 case DW_AT_ordering
: return "DW_AT_ordering";
4132 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
4133 case DW_AT_byte_size
: return "DW_AT_byte_size";
4134 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
4135 case DW_AT_bit_size
: return "DW_AT_bit_size";
4136 case DW_AT_element_list
: return "DW_AT_element_list";
4137 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
4138 case DW_AT_low_pc
: return "DW_AT_low_pc";
4139 case DW_AT_high_pc
: return "DW_AT_high_pc";
4140 case DW_AT_language
: return "DW_AT_language";
4141 case DW_AT_member
: return "DW_AT_member";
4142 case DW_AT_discr
: return "DW_AT_discr";
4143 case DW_AT_discr_value
: return "DW_AT_discr_value";
4144 case DW_AT_visibility
: return "DW_AT_visibility";
4145 case DW_AT_import
: return "DW_AT_import";
4146 case DW_AT_string_length
: return "DW_AT_string_length";
4147 case DW_AT_common_reference
: return "DW_AT_common_reference";
4148 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
4149 case DW_AT_const_value
: return "DW_AT_const_value";
4150 case DW_AT_containing_type
: return "DW_AT_containing_type";
4151 case DW_AT_default_value
: return "DW_AT_default_value";
4152 case DW_AT_inline
: return "DW_AT_inline";
4153 case DW_AT_is_optional
: return "DW_AT_is_optional";
4154 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
4155 case DW_AT_producer
: return "DW_AT_producer";
4156 case DW_AT_prototyped
: return "DW_AT_prototyped";
4157 case DW_AT_return_addr
: return "DW_AT_return_addr";
4158 case DW_AT_start_scope
: return "DW_AT_start_scope";
4159 case DW_AT_stride_size
: return "DW_AT_stride_size";
4160 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
4161 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
4162 case DW_AT_accessibility
: return "DW_AT_accessibility";
4163 case DW_AT_address_class
: return "DW_AT_address_class";
4164 case DW_AT_artificial
: return "DW_AT_artificial";
4165 case DW_AT_base_types
: return "DW_AT_base_types";
4166 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
4167 case DW_AT_count
: return "DW_AT_count";
4168 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
4169 case DW_AT_decl_column
: return "DW_AT_decl_column";
4170 case DW_AT_decl_file
: return "DW_AT_decl_file";
4171 case DW_AT_decl_line
: return "DW_AT_decl_line";
4172 case DW_AT_declaration
: return "DW_AT_declaration";
4173 case DW_AT_discr_list
: return "DW_AT_discr_list";
4174 case DW_AT_encoding
: return "DW_AT_encoding";
4175 case DW_AT_external
: return "DW_AT_external";
4176 case DW_AT_frame_base
: return "DW_AT_frame_base";
4177 case DW_AT_friend
: return "DW_AT_friend";
4178 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
4179 case DW_AT_macro_info
: return "DW_AT_macro_info";
4180 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
4181 case DW_AT_priority
: return "DW_AT_priority";
4182 case DW_AT_segment
: return "DW_AT_segment";
4183 case DW_AT_specification
: return "DW_AT_specification";
4184 case DW_AT_static_link
: return "DW_AT_static_link";
4185 case DW_AT_type
: return "DW_AT_type";
4186 case DW_AT_use_location
: return "DW_AT_use_location";
4187 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
4188 case DW_AT_virtuality
: return "DW_AT_virtuality";
4189 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
4190 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
4191 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
4192 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
4193 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
4194 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
4195 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
4196 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
4197 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
4198 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
4199 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
4200 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
4201 case DW_AT_sf_names
: return "DW_AT_sf_names";
4202 case DW_AT_src_info
: return "DW_AT_src_info";
4203 case DW_AT_mac_info
: return "DW_AT_mac_info";
4204 case DW_AT_src_coords
: return "DW_AT_src_coords";
4205 case DW_AT_body_begin
: return "DW_AT_body_begin";
4206 case DW_AT_body_end
: return "DW_AT_body_end";
4209 static char buffer
[100];
4211 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
4218 get_FORM_name (form
)
4223 case DW_FORM_addr
: return "DW_FORM_addr";
4224 case DW_FORM_block2
: return "DW_FORM_block2";
4225 case DW_FORM_block4
: return "DW_FORM_block4";
4226 case DW_FORM_data2
: return "DW_FORM_data2";
4227 case DW_FORM_data4
: return "DW_FORM_data4";
4228 case DW_FORM_data8
: return "DW_FORM_data8";
4229 case DW_FORM_string
: return "DW_FORM_string";
4230 case DW_FORM_block
: return "DW_FORM_block";
4231 case DW_FORM_block1
: return "DW_FORM_block1";
4232 case DW_FORM_data1
: return "DW_FORM_data1";
4233 case DW_FORM_flag
: return "DW_FORM_flag";
4234 case DW_FORM_sdata
: return "DW_FORM_sdata";
4235 case DW_FORM_strp
: return "DW_FORM_strp";
4236 case DW_FORM_udata
: return "DW_FORM_udata";
4237 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
4238 case DW_FORM_ref1
: return "DW_FORM_ref1";
4239 case DW_FORM_ref2
: return "DW_FORM_ref2";
4240 case DW_FORM_ref4
: return "DW_FORM_ref4";
4241 case DW_FORM_ref8
: return "DW_FORM_ref8";
4242 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
4243 case DW_FORM_indirect
: return "DW_FORM_indirect";
4246 static char buffer
[100];
4248 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
4254 /* FIXME: There are better and more effiecint ways to handle
4255 these structures. For now though, I just want something that
4256 is simple to implement. */
4257 typedef struct abbrev_attr
4259 unsigned long attribute
;
4261 struct abbrev_attr
* next
;
4265 typedef struct abbrev_entry
4267 unsigned long entry
;
4270 struct abbrev_attr
* first_attr
;
4271 struct abbrev_attr
* last_attr
;
4272 struct abbrev_entry
* next
;
4276 static abbrev_entry
* first_abbrev
= NULL
;
4277 static abbrev_entry
* last_abbrev
= NULL
;
4280 free_abbrevs
PARAMS ((void))
4282 abbrev_entry
* abbrev
;
4284 for (abbrev
= first_abbrev
; abbrev
;)
4286 abbrev_entry
* next
= abbrev
->next
;
4289 for (attr
= abbrev
->first_attr
; attr
;)
4291 abbrev_attr
* next
= attr
->next
;
4301 last_abbrev
= first_abbrev
= NULL
;
4305 add_abbrev (number
, tag
, children
)
4306 unsigned long number
;
4310 abbrev_entry
* entry
;
4312 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
4318 entry
->entry
= number
;
4320 entry
->children
= children
;
4321 entry
->first_attr
= NULL
;
4322 entry
->last_attr
= NULL
;
4325 if (first_abbrev
== NULL
)
4326 first_abbrev
= entry
;
4328 last_abbrev
->next
= entry
;
4330 last_abbrev
= entry
;
4334 add_abbrev_attr (attribute
, form
)
4335 unsigned long attribute
;
4340 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
4346 attr
->attribute
= attribute
;
4350 if (last_abbrev
->first_attr
== NULL
)
4351 last_abbrev
->first_attr
= attr
;
4353 last_abbrev
->last_attr
->next
= attr
;
4355 last_abbrev
->last_attr
= attr
;
4358 /* Processes the (partial) contents of a .debug_abbrev section.
4359 Returns NULL if the end of the section was encountered.
4360 Returns the address after the last byte read if the end of
4361 an abbreviation set was found. */
4363 static unsigned char *
4364 process_abbrev_section (start
, end
)
4365 unsigned char * start
;
4366 unsigned char * end
;
4368 if (first_abbrev
!= NULL
)
4374 unsigned long entry
;
4376 unsigned long attribute
;
4379 entry
= read_leb128 (start
, & bytes_read
, 0);
4380 start
+= bytes_read
;
4385 tag
= read_leb128 (start
, & bytes_read
, 0);
4386 start
+= bytes_read
;
4388 children
= * start
++;
4390 add_abbrev (entry
, tag
, children
);
4396 attribute
= read_leb128 (start
, & bytes_read
, 0);
4397 start
+= bytes_read
;
4399 form
= read_leb128 (start
, & bytes_read
, 0);
4400 start
+= bytes_read
;
4403 add_abbrev_attr (attribute
, form
);
4405 while (attribute
!= 0);
4413 display_debug_abbrev (section
, start
, file
)
4414 Elf32_Internal_Shdr
* section
;
4415 unsigned char * start
;
4418 abbrev_entry
* entry
;
4419 unsigned char * end
= start
+ section
->sh_size
;
4421 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4425 start
= process_abbrev_section (start
, end
);
4427 printf (_(" Number TAG\n"));
4429 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4433 printf (_(" %ld %s [%s]\n"),
4435 get_TAG_name (entry
->tag
),
4436 entry
->children
? _("has children") : _("no children"));
4438 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4440 printf (_(" %-18s %s\n"),
4441 get_AT_name (attr
->attribute
),
4442 get_FORM_name (attr
->form
));
4454 static unsigned char *
4455 display_block (data
, length
)
4456 unsigned char * data
;
4457 unsigned long length
;
4459 printf (_(" %lu byte block: "), length
);
4462 printf ("%lx ", byte_get (data
++, 1));
4468 decode_location_expression (data
, pointer_size
)
4469 unsigned char * data
;
4470 unsigned int pointer_size
;
4479 case DW_OP_addr
: printf ("DW_OP_addr: %lx", byte_get (data
, pointer_size
)); break;
4480 case DW_OP_deref
: printf ("DW_OP_deref"); break;
4481 case DW_OP_const1u
: printf ("DW_OP_const1u: %lu", byte_get (data
, 1)); break;
4482 case DW_OP_const1s
: printf ("DW_OP_const1s: %ld", (long) byte_get (data
, 1)); break;
4483 case DW_OP_const2u
: printf ("DW_OP_const2u: %lu", byte_get (data
, 2)); break;
4484 case DW_OP_const2s
: printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2)); break;
4485 case DW_OP_const4u
: printf ("DW_OP_const4u: %lu", byte_get (data
, 4)); break;
4486 case DW_OP_const4s
: printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4)); break;
4487 case DW_OP_const8u
: printf ("DW_OP_const8u: %lu %lu", byte_get (data
, 4), byte_get (data
+ 4, 4)); break;
4488 case DW_OP_const8s
: printf ("DW_OP_const8s: %ld %ld", byte_get (data
, 4), byte_get (data
+ 4, 4)); break;
4489 case DW_OP_constu
: printf ("DW_OP_constu: %lu", read_leb128 (data
, NULL
, 0)); break;
4490 case DW_OP_consts
: printf ("DW_OP_consts: %ld", read_leb128 (data
, NULL
, 1)); break;
4491 case DW_OP_dup
: printf ("DW_OP_dup"); break;
4492 case DW_OP_drop
: printf ("DW_OP_drop"); break;
4493 case DW_OP_over
: printf ("DW_OP_over"); break;
4494 case DW_OP_pick
: printf ("DW_OP_pick: %ld", byte_get (data
, 1)); break;
4495 case DW_OP_swap
: printf ("DW_OP_swap"); break;
4496 case DW_OP_rot
: printf ("DW_OP_rot"); break;
4497 case DW_OP_xderef
: printf ("DW_OP_xderef"); break;
4498 case DW_OP_abs
: printf ("DW_OP_abs"); break;
4499 case DW_OP_and
: printf ("DW_OP_and"); break;
4500 case DW_OP_div
: printf ("DW_OP_div"); break;
4501 case DW_OP_minus
: printf ("DW_OP_minus"); break;
4502 case DW_OP_mod
: printf ("DW_OP_mod"); break;
4503 case DW_OP_mul
: printf ("DW_OP_mul"); break;
4504 case DW_OP_neg
: printf ("DW_OP_neg"); break;
4505 case DW_OP_not
: printf ("DW_OP_not"); break;
4506 case DW_OP_or
: printf ("DW_OP_or"); break;
4507 case DW_OP_plus
: printf ("DW_OP_plus"); break;
4508 case DW_OP_plus_uconst
: printf ("DW_OP_plus_uconst: %lu", read_leb128 (data
, NULL
, 0)); break;
4509 case DW_OP_shl
: printf ("DW_OP_shl"); break;
4510 case DW_OP_shr
: printf ("DW_OP_shr"); break;
4511 case DW_OP_shra
: printf ("DW_OP_shra"); break;
4512 case DW_OP_xor
: printf ("DW_OP_xor"); break;
4513 case DW_OP_bra
: printf ("DW_OP_bra: %ld", byte_get (data
, 2)); break;
4514 case DW_OP_eq
: printf ("DW_OP_eq"); break;
4515 case DW_OP_ge
: printf ("DW_OP_ge"); break;
4516 case DW_OP_gt
: printf ("DW_OP_gt"); break;
4517 case DW_OP_le
: printf ("DW_OP_le"); break;
4518 case DW_OP_lt
: printf ("DW_OP_lt"); break;
4519 case DW_OP_ne
: printf ("DW_OP_ne"); break;
4520 case DW_OP_skip
: printf ("DW_OP_skip: %ld", byte_get (data
, 2)); break;
4521 case DW_OP_lit0
: printf ("DW_OP_lit0"); break;
4522 case DW_OP_lit1
: printf ("DW_OP_lit1"); break;
4523 case DW_OP_lit2
: printf ("DW_OP_lit2"); break;
4524 case DW_OP_lit3
: printf ("DW_OP_lit3"); break;
4525 case DW_OP_lit4
: printf ("DW_OP_lit4"); break;
4526 case DW_OP_lit5
: printf ("DW_OP_lit5"); break;
4527 case DW_OP_lit6
: printf ("DW_OP_lit6"); break;
4528 case DW_OP_lit7
: printf ("DW_OP_lit7"); break;
4529 case DW_OP_lit8
: printf ("DW_OP_lit8"); break;
4530 case DW_OP_lit9
: printf ("DW_OP_lit9"); break;
4531 case DW_OP_lit10
: printf ("DW_OP_lit10"); break;
4532 case DW_OP_lit11
: printf ("DW_OP_lit11"); break;
4533 case DW_OP_lit12
: printf ("DW_OP_lit12"); break;
4534 case DW_OP_lit13
: printf ("DW_OP_lit13"); break;
4535 case DW_OP_lit14
: printf ("DW_OP_lit14"); break;
4536 case DW_OP_lit15
: printf ("DW_OP_lit15"); break;
4537 case DW_OP_lit16
: printf ("DW_OP_lit16"); break;
4538 case DW_OP_lit17
: printf ("DW_OP_lit17"); break;
4539 case DW_OP_lit18
: printf ("DW_OP_lit18"); break;
4540 case DW_OP_lit19
: printf ("DW_OP_lit19"); break;
4541 case DW_OP_lit20
: printf ("DW_OP_lit20"); break;
4542 case DW_OP_lit21
: printf ("DW_OP_lit21"); break;
4543 case DW_OP_lit22
: printf ("DW_OP_lit22"); break;
4544 case DW_OP_lit23
: printf ("DW_OP_lit23"); break;
4545 case DW_OP_lit24
: printf ("DW_OP_lit24"); break;
4546 case DW_OP_lit25
: printf ("DW_OP_lit25"); break;
4547 case DW_OP_lit26
: printf ("DW_OP_lit26"); break;
4548 case DW_OP_lit27
: printf ("DW_OP_lit27"); break;
4549 case DW_OP_lit28
: printf ("DW_OP_lit28"); break;
4550 case DW_OP_lit29
: printf ("DW_OP_lit29"); break;
4551 case DW_OP_lit30
: printf ("DW_OP_lit30"); break;
4552 case DW_OP_lit31
: printf ("DW_OP_lit31"); break;
4553 case DW_OP_reg0
: printf ("DW_OP_reg0"); break;
4554 case DW_OP_reg1
: printf ("DW_OP_reg1"); break;
4555 case DW_OP_reg2
: printf ("DW_OP_reg2"); break;
4556 case DW_OP_reg3
: printf ("DW_OP_reg3"); break;
4557 case DW_OP_reg4
: printf ("DW_OP_reg4"); break;
4558 case DW_OP_reg5
: printf ("DW_OP_reg5"); break;
4559 case DW_OP_reg6
: printf ("DW_OP_reg6"); break;
4560 case DW_OP_reg7
: printf ("DW_OP_reg7"); break;
4561 case DW_OP_reg8
: printf ("DW_OP_reg8"); break;
4562 case DW_OP_reg9
: printf ("DW_OP_reg9"); break;
4563 case DW_OP_reg10
: printf ("DW_OP_reg10"); break;
4564 case DW_OP_reg11
: printf ("DW_OP_reg11"); break;
4565 case DW_OP_reg12
: printf ("DW_OP_reg12"); break;
4566 case DW_OP_reg13
: printf ("DW_OP_reg13"); break;
4567 case DW_OP_reg14
: printf ("DW_OP_reg14"); break;
4568 case DW_OP_reg15
: printf ("DW_OP_reg15"); break;
4569 case DW_OP_reg16
: printf ("DW_OP_reg16"); break;
4570 case DW_OP_reg17
: printf ("DW_OP_reg17"); break;
4571 case DW_OP_reg18
: printf ("DW_OP_reg18"); break;
4572 case DW_OP_reg19
: printf ("DW_OP_reg19"); break;
4573 case DW_OP_reg20
: printf ("DW_OP_reg20"); break;
4574 case DW_OP_reg21
: printf ("DW_OP_reg21"); break;
4575 case DW_OP_reg22
: printf ("DW_OP_reg22"); break;
4576 case DW_OP_reg23
: printf ("DW_OP_reg23"); break;
4577 case DW_OP_reg24
: printf ("DW_OP_reg24"); break;
4578 case DW_OP_reg25
: printf ("DW_OP_reg25"); break;
4579 case DW_OP_reg26
: printf ("DW_OP_reg26"); break;
4580 case DW_OP_reg27
: printf ("DW_OP_reg27"); break;
4581 case DW_OP_reg28
: printf ("DW_OP_reg28"); break;
4582 case DW_OP_reg29
: printf ("DW_OP_reg29"); break;
4583 case DW_OP_reg30
: printf ("DW_OP_reg30"); break;
4584 case DW_OP_reg31
: printf ("DW_OP_reg31"); break;
4585 case DW_OP_breg0
: printf ("DW_OP_breg0: %ld", read_leb128 (data
, NULL
, 1)); break;
4586 case DW_OP_breg1
: printf ("DW_OP_breg1: %ld", read_leb128 (data
, NULL
, 1)); break;
4587 case DW_OP_breg2
: printf ("DW_OP_breg2: %ld", read_leb128 (data
, NULL
, 1)); break;
4588 case DW_OP_breg3
: printf ("DW_OP_breg3: %ld", read_leb128 (data
, NULL
, 1)); break;
4589 case DW_OP_breg4
: printf ("DW_OP_breg4: %ld", read_leb128 (data
, NULL
, 1)); break;
4590 case DW_OP_breg5
: printf ("DW_OP_breg5: %ld", read_leb128 (data
, NULL
, 1)); break;
4591 case DW_OP_breg6
: printf ("DW_OP_breg6: %ld", read_leb128 (data
, NULL
, 1)); break;
4592 case DW_OP_breg7
: printf ("DW_OP_breg7: %ld", read_leb128 (data
, NULL
, 1)); break;
4593 case DW_OP_breg8
: printf ("DW_OP_breg8: %ld", read_leb128 (data
, NULL
, 1)); break;
4594 case DW_OP_breg9
: printf ("DW_OP_breg9: %ld", read_leb128 (data
, NULL
, 1)); break;
4595 case DW_OP_breg10
: printf ("DW_OP_breg10: %ld", read_leb128 (data
, NULL
, 1)); break;
4596 case DW_OP_breg11
: printf ("DW_OP_breg11: %ld", read_leb128 (data
, NULL
, 1)); break;
4597 case DW_OP_breg12
: printf ("DW_OP_breg12: %ld", read_leb128 (data
, NULL
, 1)); break;
4598 case DW_OP_breg13
: printf ("DW_OP_breg13: %ld", read_leb128 (data
, NULL
, 1)); break;
4599 case DW_OP_breg14
: printf ("DW_OP_breg14: %ld", read_leb128 (data
, NULL
, 1)); break;
4600 case DW_OP_breg15
: printf ("DW_OP_breg15: %ld", read_leb128 (data
, NULL
, 1)); break;
4601 case DW_OP_breg16
: printf ("DW_OP_breg16: %ld", read_leb128 (data
, NULL
, 1)); break;
4602 case DW_OP_breg17
: printf ("DW_OP_breg17: %ld", read_leb128 (data
, NULL
, 1)); break;
4603 case DW_OP_breg18
: printf ("DW_OP_breg18: %ld", read_leb128 (data
, NULL
, 1)); break;
4604 case DW_OP_breg19
: printf ("DW_OP_breg19: %ld", read_leb128 (data
, NULL
, 1)); break;
4605 case DW_OP_breg20
: printf ("DW_OP_breg20: %ld", read_leb128 (data
, NULL
, 1)); break;
4606 case DW_OP_breg21
: printf ("DW_OP_breg21: %ld", read_leb128 (data
, NULL
, 1)); break;
4607 case DW_OP_breg22
: printf ("DW_OP_breg22: %ld", read_leb128 (data
, NULL
, 1)); break;
4608 case DW_OP_breg23
: printf ("DW_OP_breg23: %ld", read_leb128 (data
, NULL
, 1)); break;
4609 case DW_OP_breg24
: printf ("DW_OP_breg24: %ld", read_leb128 (data
, NULL
, 1)); break;
4610 case DW_OP_breg25
: printf ("DW_OP_breg25: %ld", read_leb128 (data
, NULL
, 1)); break;
4611 case DW_OP_breg26
: printf ("DW_OP_breg26: %ld", read_leb128 (data
, NULL
, 1)); break;
4612 case DW_OP_breg27
: printf ("DW_OP_breg27: %ld", read_leb128 (data
, NULL
, 1)); break;
4613 case DW_OP_breg28
: printf ("DW_OP_breg28: %ld", read_leb128 (data
, NULL
, 1)); break;
4614 case DW_OP_breg29
: printf ("DW_OP_breg29: %ld", read_leb128 (data
, NULL
, 1)); break;
4615 case DW_OP_breg30
: printf ("DW_OP_breg30: %ld", read_leb128 (data
, NULL
, 1)); break;
4616 case DW_OP_breg31
: printf ("DW_OP_breg31: %ld", read_leb128 (data
, NULL
, 1)); break;
4617 case DW_OP_regx
: printf ("DW_OP_regx: %lu", read_leb128 (data
, NULL
, 0)); break;
4618 case DW_OP_fbreg
: printf ("DW_OP_fbreg: %ld", read_leb128 (data
, NULL
, 1)); break;
4619 case DW_OP_bregx
: printf ("DW_OP_bregx: %lu %ld", read_leb128 (data
, & bytes_read
, 0), read_leb128 (data
+ bytes_read
, NULL
, 1)); break;
4620 case DW_OP_piece
: printf ("DW_OP_piece: %lu", read_leb128 (data
, NULL
, 0)); break;
4621 case DW_OP_deref_size
: printf ("DW_OP_deref_size: %ld", byte_get (data
, 1)); break;
4622 case DW_OP_xderef_size
: printf ("DW_OP_xderef_size: %ld", byte_get (data
, 1)); break;
4623 case DW_OP_nop
: printf ("DW_OP_nop"); break;
4626 if (op
>= DW_OP_lo_user
4627 && op
<= DW_OP_hi_user
)
4628 printf (_("(User defined location op)"));
4630 printf (_("(Unknown location op)"));
4636 static unsigned char *
4637 read_and_display_attr (attribute
, form
, data
, pointer_size
)
4638 unsigned long attribute
;
4640 unsigned char * data
;
4641 unsigned long pointer_size
;
4643 unsigned long uvalue
;
4644 unsigned char * block_start
;
4648 printf (" %-18s:", get_AT_name (attribute
));
4652 case DW_FORM_ref_addr
:
4657 case DW_FORM_ref_udata
:
4663 case DW_FORM_ref_addr
:
4665 uvalue
= byte_get (data
, pointer_size
);
4666 printf (is_ref
? " <%x>" : " %#x", uvalue
);
4667 data
+= pointer_size
;
4673 uvalue
= byte_get (data
++, 1);
4674 printf (is_ref
? " <%x>" : " %d", uvalue
);
4679 uvalue
= byte_get (data
, 2);
4681 printf (is_ref
? " <%x>" : " %d", uvalue
);
4686 uvalue
= byte_get (data
, 4);
4688 printf (is_ref
? " <%x>" : " %d", uvalue
);
4693 uvalue
= byte_get (data
, 4);
4694 printf (" %lx", uvalue
);
4695 printf (" %lx", byte_get (data
+ 4, 4));
4699 case DW_FORM_string
:
4700 printf (" %s", data
);
4701 data
+= strlen (data
) + 1;
4705 uvalue
= read_leb128 (data
, & bytes_read
, 1);
4707 printf (" %ld", (long) uvalue
);
4710 case DW_FORM_ref_udata
:
4712 uvalue
= read_leb128 (data
, & bytes_read
, 0);
4714 printf (is_ref
? " <%lx>" : " %ld", uvalue
);
4718 uvalue
= read_leb128 (data
, & bytes_read
, 0);
4719 block_start
= data
+ bytes_read
;
4720 data
= display_block (block_start
, uvalue
);
4721 uvalue
= * block_start
;
4724 case DW_FORM_block1
:
4725 uvalue
= byte_get (data
, 1);
4726 block_start
= data
+ 1;
4727 data
= display_block (block_start
, uvalue
);
4728 uvalue
= * block_start
;
4731 case DW_FORM_block2
:
4732 uvalue
= byte_get (data
, 2);
4733 block_start
= data
+ 2;
4734 data
= display_block (block_start
, uvalue
);
4735 uvalue
= * block_start
;
4738 case DW_FORM_block4
:
4739 uvalue
= byte_get (data
, 4);
4740 block_start
= data
+ 4;
4741 data
= display_block (block_start
, uvalue
);
4742 uvalue
= * block_start
;
4746 case DW_FORM_indirect
:
4747 warn (_("Unable to handle FORM: %d"), form
);
4751 warn (_("Unrecognised form: %d"), form
);
4755 /* For some attributes we can display futher information. */
4764 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
4765 case DW_INL_inlined
: printf (_("(inlined)")); break;
4766 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
4767 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
4768 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
4772 case DW_AT_frame_base
:
4773 if (uvalue
>= DW_OP_reg0
&& uvalue
<= DW_OP_reg31
)
4774 printf ("(reg %ld)", uvalue
- DW_OP_reg0
);
4777 case DW_AT_language
:
4780 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
4781 case DW_LANG_C89
: printf ("(ANSI C)"); break;
4782 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
4783 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
4784 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
4785 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
4786 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
4787 case DW_LANG_Ada83
: printf ("(Ada)"); break;
4788 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
4789 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
4790 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
4791 default: printf ("(Unknown: %lx)", uvalue
); break;
4795 case DW_AT_encoding
:
4798 case DW_ATE_void
: printf ("(void)"); break;
4799 case DW_ATE_address
: printf ("(machine address)"); break;
4800 case DW_ATE_boolean
: printf ("(boolean)"); break;
4801 case DW_ATE_complex_float
: printf ("(complex float)"); break;
4802 case DW_ATE_float
: printf ("(float)"); break;
4803 case DW_ATE_signed
: printf ("(signed)"); break;
4804 case DW_ATE_signed_char
: printf ("(signed char)"); break;
4805 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
4806 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
4808 if (uvalue
>= DW_ATE_lo_user
4809 && uvalue
<= DW_ATE_hi_user
)
4810 printf ("(user defined type)");
4812 printf ("(unknown type)");
4817 case DW_AT_accessibility
:
4820 case DW_ACCESS_public
: printf ("(public)"); break;
4821 case DW_ACCESS_protected
: printf ("(protected)"); break;
4822 case DW_ACCESS_private
: printf ("(private)"); break;
4823 default: printf ("(unknown accessibility)"); break;
4827 case DW_AT_visibility
:
4830 case DW_VIS_local
: printf ("(local)"); break;
4831 case DW_VIS_exported
: printf ("(exported)"); break;
4832 case DW_VIS_qualified
: printf ("(qualified)"); break;
4833 default: printf ("(unknown visibility)"); break;
4837 case DW_AT_virtuality
:
4840 case DW_VIRTUALITY_none
: printf ("(none)"); break;
4841 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
4842 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
4843 default: printf ("(unknown virtuality)"); break;
4847 case DW_AT_identifier_case
:
4850 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
4851 case DW_ID_up_case
: printf ("(up_case)"); break;
4852 case DW_ID_down_case
: printf ("(down_case)"); break;
4853 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
4854 default: printf ("(unknown case)"); break;
4858 case DW_AT_calling_convention
:
4861 case DW_CC_normal
: printf ("(normal)"); break;
4862 case DW_CC_program
: printf ("(program)"); break;
4863 case DW_CC_nocall
: printf ("(nocall)"); break;
4865 if (uvalue
>= DW_CC_lo_user
4866 && uvalue
<= DW_CC_hi_user
)
4867 printf ("(user defined)");
4869 printf ("(unknown convention)");
4873 case DW_AT_location
:
4874 case DW_AT_data_member_location
:
4875 case DW_AT_vtable_elem_location
:
4877 decode_location_expression (block_start
, pointer_size
);
4890 display_debug_info (section
, start
, file
)
4891 Elf32_Internal_Shdr
* section
;
4892 unsigned char * start
;
4895 unsigned char * end
= start
+ section
->sh_size
;
4896 unsigned char * section_begin
= start
;
4898 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
4902 DWARF2_External_CompUnit
* external
;
4903 DWARF2_Internal_CompUnit compunit
;
4904 unsigned char * tags
;
4908 external
= (DWARF2_External_CompUnit
*) start
;
4910 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
4911 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
4912 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
4913 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
4915 tags
= start
+ sizeof (* external
);
4916 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
4918 if (compunit
.cu_version
!= 2)
4920 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
4924 printf (_(" Compilation Unit:\n"));
4925 printf (_(" Length: %ld\n"), compunit
.cu_length
);
4926 printf (_(" Version: %d\n"), compunit
.cu_version
);
4927 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
4928 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
4930 if (first_abbrev
!= NULL
)
4933 /* Read in the abbrevs used by this compilation unit. */
4936 Elf32_Internal_Shdr
* sec
;
4937 unsigned char * begin
;
4939 /* Locate the .debug_abbrev section and process it. */
4940 for (i
= 0, sec
= section_headers
;
4941 i
< elf_header
.e_shnum
;
4943 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
4946 if (i
== -1 || sec
->sh_size
== 0)
4948 warn (_("Unable to locate .debug_abbrev section!\n"));
4952 GET_DATA_ALLOC (sec
->sh_offset
, sec
->sh_size
, begin
, unsigned char *,
4953 "debug_abbrev section data");
4955 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
4956 begin
+ sec
->sh_size
);
4962 while (tags
< start
)
4966 abbrev_entry
* entry
;
4969 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
4972 /* A null DIE marks the end of a list of children. */
4973 if (abbrev_number
== 0)
4979 /* Scan through the abbreviation list until we reach the
4981 for (entry
= first_abbrev
;
4982 entry
&& entry
->entry
!= abbrev_number
;
4983 entry
= entry
->next
)
4988 warn (_("Unable to locate entry %d in the abbreviation table\n"),
4993 printf (_(" <%d><%x>: Abbrev Number: %d (%s)\n"),
4994 level
, tags
- section_begin
- bytes_read
,
4996 get_TAG_name (entry
->tag
));
4998 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4999 tags
= read_and_display_attr (attr
->attribute
,
5002 compunit
.cu_pointer_size
);
5004 if (entry
->children
)
5015 display_debug_aranges (section
, start
, file
)
5016 Elf32_Internal_Shdr
* section
;
5017 unsigned char * start
;
5020 unsigned char * end
= start
+ section
->sh_size
;
5022 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5026 DWARF2_External_ARange
* external
;
5027 DWARF2_Internal_ARange arange
;
5028 unsigned char * ranges
;
5029 unsigned long length
;
5030 unsigned long address
;
5032 external
= (DWARF2_External_ARange
*) start
;
5034 arange
.ar_length
= BYTE_GET (external
->ar_length
);
5035 arange
.ar_version
= BYTE_GET (external
->ar_version
);
5036 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
5037 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
5038 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
5040 printf (_(" Length: %ld\n"), arange
.ar_length
);
5041 printf (_(" Version: %d\n"), arange
.ar_version
);
5042 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
5043 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
5044 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
5046 printf (_("\n Address Length\n"));
5048 ranges
= start
+ sizeof (* external
);
5052 address
= byte_get (ranges
, arange
.ar_pointer_size
);
5057 ranges
+= arange
.ar_pointer_size
;
5059 length
= byte_get (ranges
, arange
.ar_pointer_size
);
5061 ranges
+= arange
.ar_pointer_size
;
5063 printf (" %8.8lx %lu\n", address
, length
);
5066 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
5076 display_debug_not_supported (section
, start
, file
)
5077 Elf32_Internal_Shdr
* section
;
5078 unsigned char * start
;
5081 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5082 SECTION_NAME (section
));
5087 /* A structure containing the name of a debug section and a pointer
5088 to a function that can decode it. */
5092 int (* display
) PARAMS((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
5096 { ".debug_info", display_debug_info
},
5097 { ".debug_abbrev", display_debug_abbrev
},
5098 { ".debug_line", display_debug_lines
},
5099 { ".debug_aranges", display_debug_aranges
},
5100 { ".debug_pubnames", display_debug_pubnames
},
5101 { ".debug_macinfo", display_debug_not_supported
},
5102 { ".debug_frame", display_debug_not_supported
},
5103 { ".debug_str", display_debug_not_supported
},
5104 { ".debug_static_func", display_debug_not_supported
},
5105 { ".debug_static_vars", display_debug_not_supported
},
5106 { ".debug_types", display_debug_not_supported
},
5107 { ".debug_weaknames", display_debug_not_supported
}
5111 display_debug_section (section
, file
)
5112 Elf32_Internal_Shdr
* section
;
5115 char * name
= SECTION_NAME (section
);
5116 bfd_size_type length
;
5117 unsigned char * start
;
5120 length
= section
->sh_size
;
5123 printf (_("\nSection '%s' has no debugging data.\n"), name
);
5127 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
5128 "debug section data");
5130 /* See if we know how to display the contents of this section. */
5131 for (i
= NUM_ELEM (debug_displays
); i
--;)
5132 if (strcmp (debug_displays
[i
].name
, name
) == 0)
5134 debug_displays
[i
].display (section
, start
, file
);
5139 printf (_("Unrecognised debug section: %s\n"), name
);
5143 /* If we loaded in the abbrev section at some point,
5144 we must release it here. */
5145 if (first_abbrev
!= NULL
)
5152 process_section_contents (file
)
5155 Elf32_Internal_Shdr
* section
;
5161 for (i
= 0, section
= section_headers
;
5162 i
< elf_header
.e_shnum
5163 && i
< num_dump_sects
;
5166 #ifdef SUPPORT_DISASSEMBLY
5167 if (dump_sects
[i
] & DISASS_DUMP
)
5168 disassemble_section (section
, file
);
5170 if (dump_sects
[i
] & HEX_DUMP
)
5171 dump_section (section
, file
);
5173 if (dump_sects
[i
] & DEBUG_DUMP
)
5174 display_debug_section (section
, file
);
5177 if (i
< num_dump_sects
)
5178 warn (_("Some sections were not dumped because they do not exist!\n"));
5184 process_mips_fpe_exception (mask
)
5190 if (mask
& OEX_FPU_INEX
)
5191 fputs ("INEX", stdout
), first
= 0;
5192 if (mask
& OEX_FPU_UFLO
)
5193 printf ("%sUFLO", first
? "" : "|"), first
= 0;
5194 if (mask
& OEX_FPU_OFLO
)
5195 printf ("%sOFLO", first
? "" : "|"), first
= 0;
5196 if (mask
& OEX_FPU_DIV0
)
5197 printf ("%sDIV0", first
? "" : "|"), first
= 0;
5198 if (mask
& OEX_FPU_INVAL
)
5199 printf ("%sINVAL", first
? "" : "|");
5202 fputs ("0", stdout
);
5206 process_mips_specific (file
)
5209 Elf_Internal_Dyn
*entry
;
5210 size_t liblist_offset
= 0;
5211 size_t liblistno
= 0;
5212 size_t conflictsno
= 0;
5213 size_t options_offset
= 0;
5214 size_t conflicts_offset
= 0;
5216 /* We have a lot of special sections. Thanks SGI! */
5217 if (dynamic_segment
== NULL
)
5218 /* No information available. */
5221 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
5222 switch (entry
->d_tag
)
5224 case DT_MIPS_LIBLIST
:
5225 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
5227 case DT_MIPS_LIBLISTNO
:
5228 liblistno
= entry
->d_un
.d_val
;
5230 case DT_MIPS_OPTIONS
:
5231 options_offset
= entry
->d_un
.d_val
- loadaddr
;
5233 case DT_MIPS_CONFLICT
:
5234 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
5236 case DT_MIPS_CONFLICTNO
:
5237 conflictsno
= entry
->d_un
.d_val
;
5243 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
5245 Elf32_External_Lib
*elib
;
5248 GET_DATA_ALLOC (liblist_offset
, liblistno
* sizeof (Elf32_External_Lib
),
5249 elib
, Elf32_External_Lib
*, "liblist");
5251 printf ("\nSection '.liblist' contains %d entries:\n", liblistno
);
5252 fputs (" Library Time Stamp Checksum Version Flags\n",
5255 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
5261 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
5262 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
5263 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
5264 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
5265 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
5267 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
5269 printf ("%3d: %-20s %s %#10lx %-7ld", cnt
,
5270 dynamic_strings
+ liblist
.l_name
, timebuf
,
5271 liblist
.l_checksum
, liblist
.l_version
);
5273 if (liblist
.l_flags
== 0)
5283 { " EXACT_MATCH", LL_EXACT_MATCH
},
5284 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
5285 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
5286 { " EXPORTS", LL_EXPORTS
},
5287 { " DELAY_LOAD", LL_DELAY_LOAD
},
5288 { " DELTA", LL_DELTA
}
5290 int flags
= liblist
.l_flags
;
5294 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
5296 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
5298 fputs (l_flags_vals
[fcnt
].name
, stdout
);
5299 flags
^= l_flags_vals
[fcnt
].bit
;
5302 printf (" %#x", (unsigned int) flags
);
5311 if (options_offset
!= 0)
5313 Elf_External_Options
*eopt
;
5314 Elf_Internal_Shdr
*sect
= section_headers
;
5315 Elf_Internal_Options
*iopt
;
5316 Elf_Internal_Options
*option
;
5320 /* Find the section header so that we get the size. */
5321 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
5324 GET_DATA_ALLOC (options_offset
, sect
->sh_size
, eopt
,
5325 Elf_External_Options
*, "options");
5327 iopt
= (Elf_Internal_Options
*) malloc ((sect
->sh_size
/ sizeof (eopt
))
5331 error (_("Out of memory"));
5337 while (offset
< sect
->sh_size
)
5339 Elf_External_Options
*eoption
;
5341 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
5343 option
->kind
= BYTE_GET (eoption
->kind
);
5344 option
->size
= BYTE_GET (eoption
->size
);
5345 option
->section
= BYTE_GET (eoption
->section
);
5346 option
->info
= BYTE_GET (eoption
->info
);
5348 offset
+= option
->size
;
5353 printf (_("\nSection '%s' contains %d entries:\n"),
5354 string_table
+ sect
->sh_name
, cnt
);
5361 switch (option
->kind
)
5364 /* This shouldn't happen. */
5365 printf (" NULL %d %lx", option
->section
, option
->info
);
5368 printf (" REGINFO ");
5369 if (elf_header
.e_machine
== EM_MIPS
)
5372 Elf32_External_RegInfo
*ereg
;
5373 Elf32_RegInfo reginfo
;
5375 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
5376 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
5377 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
5378 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
5379 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
5380 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
5381 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
5383 printf ("GPR %08lx GP 0x%lx\n",
5385 (unsigned long) reginfo
.ri_gp_value
);
5386 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
5387 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
5388 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
5393 Elf64_External_RegInfo
*ereg
;
5394 Elf64_Internal_RegInfo reginfo
;
5396 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
5397 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
5398 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
5399 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
5400 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
5401 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
5402 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
5404 printf ("GPR %08lx GP 0x",
5405 reginfo
.ri_gprmask
);
5406 printf_vma (reginfo
.ri_gp_value
);
5409 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
5410 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
5411 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
5415 case ODK_EXCEPTIONS
:
5416 fputs (" EXCEPTIONS fpe_min(", stdout
);
5417 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
5418 fputs (") fpe_max(", stdout
);
5419 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
5420 fputs (")", stdout
);
5422 if (option
->info
& OEX_PAGE0
)
5423 fputs (" PAGE0", stdout
);
5424 if (option
->info
& OEX_SMM
)
5425 fputs (" SMM", stdout
);
5426 if (option
->info
& OEX_FPDBUG
)
5427 fputs (" FPDBUG", stdout
);
5428 if (option
->info
& OEX_DISMISS
)
5429 fputs (" DISMISS", stdout
);
5432 fputs (" PAD ", stdout
);
5433 if (option
->info
& OPAD_PREFIX
)
5434 fputs (" PREFIX", stdout
);
5435 if (option
->info
& OPAD_POSTFIX
)
5436 fputs (" POSTFIX", stdout
);
5437 if (option
->info
& OPAD_SYMBOL
)
5438 fputs (" SYMBOL", stdout
);
5441 fputs (" HWPATCH ", stdout
);
5442 if (option
->info
& OHW_R4KEOP
)
5443 fputs (" R4KEOP", stdout
);
5444 if (option
->info
& OHW_R8KPFETCH
)
5445 fputs (" R8KPFETCH", stdout
);
5446 if (option
->info
& OHW_R5KEOP
)
5447 fputs (" R5KEOP", stdout
);
5448 if (option
->info
& OHW_R5KCVTL
)
5449 fputs (" R5KCVTL", stdout
);
5452 fputs (" FILL ", stdout
);
5453 /* XXX Print content of info word? */
5456 fputs (" TAGS ", stdout
);
5457 /* XXX Print content of info word? */
5460 fputs (" HWAND ", stdout
);
5461 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
5462 fputs (" R4KEOP_CHECKED", stdout
);
5463 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
5464 fputs (" R4KEOP_CLEAN", stdout
);
5467 fputs (" HWOR ", stdout
);
5468 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
5469 fputs (" R4KEOP_CHECKED", stdout
);
5470 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
5471 fputs (" R4KEOP_CLEAN", stdout
);
5474 printf (" GP_GROUP %#06lx self-contained %#06lx",
5475 option
->info
& OGP_GROUP
,
5476 (option
->info
& OGP_SELF
) >> 16);
5479 printf (" IDENT %#06lx self-contained %#06lx",
5480 option
->info
& OGP_GROUP
,
5481 (option
->info
& OGP_SELF
) >> 16);
5484 /* This shouldn't happen. */
5485 printf (" %3d ??? %d %lx",
5486 option
->kind
, option
->section
, option
->info
);
5490 len
= sizeof (*eopt
);
5491 while (len
< option
->size
)
5492 if (((char *) option
)[len
] >= ' '
5493 && ((char *) option
)[len
] < 0x7f)
5494 printf ("%c", ((char *) option
)[len
++]);
5496 printf ("\\%03o", ((char *) option
)[len
++]);
5498 fputs ("\n", stdout
);
5505 if (conflicts_offset
!= 0 && conflictsno
!= 0)
5507 Elf32_External_Conflict
*econf32
;
5508 Elf64_External_Conflict
*econf64
;
5509 Elf32_Conflict
*iconf
;
5512 if (dynamic_symbols
== NULL
)
5514 error (_("conflict list with without table"));
5518 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
5521 error (_("Out of memory"));
5525 if (binary_class
== ELFCLASS32
)
5527 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf32
),
5528 econf32
, Elf32_External_Conflict
*, "conflict");
5530 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
5531 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
5535 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf64
),
5536 econf64
, Elf64_External_Conflict
*, "conflict");
5538 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
5539 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
5542 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno
);
5543 puts (_(" Num: Index Value Name"));
5545 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
5547 Elf_Internal_Sym
*psym
= &dynamic_symbols
[iconf
[cnt
]];
5549 printf ("%5u: %8lu %#10lx %s\n",
5550 cnt
, iconf
[cnt
], (unsigned long) psym
->st_value
,
5551 dynamic_strings
+ psym
->st_name
);
5562 process_arch_specific (file
)
5565 switch (elf_header
.e_machine
)
5568 case EM_MIPS_RS4_BE
:
5569 return process_mips_specific (file
);
5578 get_file_header (file
)
5581 Elf32_External_Ehdr ehdr
;
5583 if (fread (& ehdr
, sizeof (ehdr
), 1, file
) != 1)
5586 memcpy (elf_header
.e_ident
, ehdr
.e_ident
, EI_NIDENT
);
5588 if (elf_header
.e_ident
[EI_DATA
] == ELFDATA2LSB
)
5589 byte_get
= byte_get_little_endian
;
5591 byte_get
= byte_get_big_endian
;
5593 elf_header
.e_entry
= BYTE_GET (ehdr
.e_entry
);
5594 elf_header
.e_phoff
= BYTE_GET (ehdr
.e_phoff
);
5595 elf_header
.e_shoff
= BYTE_GET (ehdr
.e_shoff
);
5596 elf_header
.e_version
= BYTE_GET (ehdr
.e_version
);
5597 elf_header
.e_flags
= BYTE_GET (ehdr
.e_flags
);
5598 elf_header
.e_type
= BYTE_GET (ehdr
.e_type
);
5599 elf_header
.e_machine
= BYTE_GET (ehdr
.e_machine
);
5600 elf_header
.e_ehsize
= BYTE_GET (ehdr
.e_ehsize
);
5601 elf_header
.e_phentsize
= BYTE_GET (ehdr
.e_phentsize
);
5602 elf_header
.e_phnum
= BYTE_GET (ehdr
.e_phnum
);
5603 elf_header
.e_shentsize
= BYTE_GET (ehdr
.e_shentsize
);
5604 elf_header
.e_shnum
= BYTE_GET (ehdr
.e_shnum
);
5605 elf_header
.e_shstrndx
= BYTE_GET (ehdr
.e_shstrndx
);
5611 process_file (file_name
)
5615 struct stat statbuf
;
5618 if (stat (file_name
, & statbuf
) < 0)
5620 error (_("Cannot stat input file %s.\n"), file_name
);
5624 file
= fopen (file_name
, "rb");
5627 error (_("Input file %s not found.\n"), file_name
);
5631 if (! get_file_header (file
))
5633 error (_("%s: Failed to read file header\n"), file_name
);
5638 /* Initialise per file variables. */
5639 for (i
= NUM_ELEM (version_info
); i
--;)
5640 version_info
[i
] = 0;
5642 for (i
= NUM_ELEM (dynamic_info
); i
--;)
5643 dynamic_info
[i
] = 0;
5645 /* Process the file. */
5647 printf (_("\nFile: %s\n"), file_name
);
5649 if (! process_file_header ())
5655 process_section_headers (file
);
5657 process_program_headers (file
);
5659 process_dynamic_segment (file
);
5661 process_relocs (file
);
5663 process_symbol_table (file
);
5665 process_syminfo (file
);
5667 process_version_sections (file
);
5669 process_section_contents (file
);
5671 process_arch_specific (file
);
5675 if (section_headers
)
5677 free (section_headers
);
5678 section_headers
= NULL
;
5683 free (string_table
);
5684 string_table
= NULL
;
5687 if (dynamic_strings
)
5689 free (dynamic_strings
);
5690 dynamic_strings
= NULL
;
5693 if (dynamic_symbols
)
5695 free (dynamic_symbols
);
5696 dynamic_symbols
= NULL
;
5699 if (dynamic_syminfo
)
5701 free (dynamic_syminfo
);
5702 dynamic_syminfo
= NULL
;
5706 #ifdef SUPPORT_DISASSEMBLY
5707 /* Needed by the i386 disassembler. For extra credit, someone could
5708 fix this so that we insert symbolic addresses here, esp for GOT/PLT
5712 print_address (unsigned int addr
, FILE * outfile
)
5714 fprintf (outfile
,"0x%8.8x", addr
);
5717 /* Needed by the i386 disassembler. */
5719 db_task_printsym (unsigned int addr
)
5721 print_address (addr
, stderr
);
5730 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
5731 setlocale (LC_MESSAGES
, "");
5733 bindtextdomain (PACKAGE
, LOCALEDIR
);
5734 textdomain (PACKAGE
);
5736 parse_args (argc
, argv
);
5738 if (optind
< (argc
- 1))
5741 while (optind
< argc
)
5742 process_file (argv
[optind
++]);
5744 if (dump_sects
!= NULL
)