1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.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
25 Copyright (C) 2004 Philip Guo, MIT CSAIL Program Analysis Group
27 This file was modified by Philip Guo, MIT CSAIL Program Analysis Group,
28 to perform recording of function return types and parameter types
29 for Kvasir, a Valgrind skin that implements the C language
30 front-end for the Daikon Invariant Detection System.
32 This file interprets the DWARF2 debugging information within
33 the ELF binary and then calls functions in typedata.c
34 My changes are denoted by //PG marks
39 #include <sys/types.h>
45 /* Define BFD64 here, even if our default architecture is 32 bit ELF
46 as this will allow us to read in and parse 64bit and 32bit ELF files.
47 Only do this if we believe that the compiler can support a 64 bit
48 data type. For now we only rely on GCC being able to do this. */
54 #include "elf/common.h"
55 #include "elf/external.h"
56 #include "elf/internal.h"
57 #include "elf/dwarf2.h"
59 #include "typedata.h" //PG
61 /* The following headers use the elf/reloc-macros.h file to
62 automatically generate relocation recognition functions
63 such as elf_mips_reloc_type() */
65 #define RELOC_MACROS_GEN_FUNC
71 //#include "libiberty.h"
73 char *program_name = "readelf";
74 unsigned long dynamic_addr;
75 bfd_size_type dynamic_size;
76 char *dynamic_strings;
78 unsigned long string_table_length;
79 unsigned long num_dynamic_syms;
80 Elf_Internal_Sym *dynamic_symbols;
81 Elf_Internal_Syminfo *dynamic_syminfo;
82 unsigned long dynamic_syminfo_offset;
83 unsigned int dynamic_syminfo_nent;
84 char program_interpreter[64];
85 long dynamic_info[DT_JMPREL + 1];
86 long version_info[16];
88 Elf_Internal_Ehdr elf_header;
89 Elf_Internal_Shdr *section_headers;
90 Elf_Internal_Dyn *dynamic_segment;
91 Elf_Internal_Shdr *symtab_shndx_hdr;
107 int do_debug_abbrevs;
109 int do_debug_pubnames;
110 int do_debug_aranges;
112 int do_debug_frames_interp;
113 int do_debug_macinfo;
120 //PG set this equal to 1 to print out results
121 int print_results = 0;
125 char tag_is_relevant_entry(unsigned long tag);
126 void initialize_dwarf_entry_array(unsigned long num_entries);
127 void destroy_dwarf_entry_array(void);
129 char tag_is_modifier_type(unsigned long tag);
130 char tag_is_collection_type(unsigned long tag);
131 char tag_is_base_type(unsigned long tag);
132 char tag_is_member(unsigned long tag);
133 char tag_is_enumerator(unsigned long tag);
134 char tag_is_function(unsigned long tag);
135 char tag_is_formal_parameter(unsigned long tag);
138 /* A dynamic array of flags indicating which sections require dumping. */
139 char *dump_sects = NULL;
140 unsigned int num_dump_sects = 0;
142 #define HEX_DUMP (1 << 0)
143 #define DISASS_DUMP (1 << 1)
144 #define DEBUG_DUMP (1 << 2)
146 /* How to rpint a vma value. */
147 typedef enum print_mode
159 /* Forward declarations for dumb compilers. */
160 static void print_vma
161 PARAMS ((bfd_vma, print_mode));
162 static void print_symbol
163 PARAMS ((int, const char *));
164 static bfd_vma (*byte_get)
165 PARAMS ((unsigned char *, int));
166 static bfd_vma byte_get_little_endian
167 PARAMS ((unsigned char *, int));
168 static bfd_vma byte_get_big_endian
169 PARAMS ((unsigned char *, int));
170 static void (*byte_put)
171 PARAMS ((unsigned char *, bfd_vma, int));
172 static void byte_put_little_endian
173 PARAMS ((unsigned char *, bfd_vma, int));
174 static void byte_put_big_endian
175 PARAMS ((unsigned char *, bfd_vma, int));
176 static const char *get_mips_dynamic_type
177 PARAMS ((unsigned long));
178 static const char *get_sparc64_dynamic_type
179 PARAMS ((unsigned long));
180 static const char *get_ppc64_dynamic_type
181 PARAMS ((unsigned long));
182 static const char *get_parisc_dynamic_type
183 PARAMS ((unsigned long));
184 static const char *get_ia64_dynamic_type
185 PARAMS ((unsigned long));
186 static const char *get_dynamic_type
187 PARAMS ((unsigned long));
188 static int slurp_rela_relocs
189 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **,
191 static int slurp_rel_relocs
192 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **,
194 static int dump_relocations
195 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *,
196 unsigned long, char *, int));
197 static char *get_file_type
199 static char *get_machine_name
201 static char *get_machine_flags
202 PARAMS ((unsigned, unsigned));
203 static const char *get_mips_segment_type
204 PARAMS ((unsigned long));
205 static const char *get_parisc_segment_type
206 PARAMS ((unsigned long));
207 static const char *get_ia64_segment_type
208 PARAMS ((unsigned long));
209 static const char *get_segment_type
210 PARAMS ((unsigned long));
211 static const char *get_mips_section_type_name
212 PARAMS ((unsigned int));
213 static const char *get_parisc_section_type_name
214 PARAMS ((unsigned int));
215 static const char *get_ia64_section_type_name
216 PARAMS ((unsigned int));
217 static const char *get_section_type_name
218 PARAMS ((unsigned int));
219 static const char *get_symbol_binding
220 PARAMS ((unsigned int));
221 static const char *get_symbol_type
222 PARAMS ((unsigned int));
223 static const char *get_symbol_visibility
224 PARAMS ((unsigned int));
225 static const char *get_symbol_index_type
226 PARAMS ((unsigned int));
227 static const char *get_dynamic_flags
231 static void parse_args
232 PARAMS ((int, char **));
233 static int process_file_header
235 static int process_program_headers
237 static int process_section_headers
239 static int process_unwind
241 static void dynamic_segment_mips_val
242 PARAMS ((Elf_Internal_Dyn *));
243 static void dynamic_segment_parisc_val
244 PARAMS ((Elf_Internal_Dyn *));
245 static void dynamic_segment_ia64_val
246 PARAMS ((Elf_Internal_Dyn *));
247 static int process_dynamic_segment
249 static int process_symbol_table
251 static int process_syminfo
253 static int process_section_contents
255 static int process_mips_specific
257 static int process_file
259 static int process_relocs
261 static int process_version_sections
263 static char *get_ver_flags
264 PARAMS ((unsigned int));
265 static int get_32bit_section_headers
266 PARAMS ((FILE *, unsigned int));
267 static int get_64bit_section_headers
268 PARAMS ((FILE *, unsigned int));
269 static int get_32bit_program_headers
270 PARAMS ((FILE *, Elf_Internal_Phdr *));
271 static int get_64bit_program_headers
272 PARAMS ((FILE *, Elf_Internal_Phdr *));
273 static int get_file_header
275 static Elf_Internal_Sym *get_32bit_elf_symbols
276 PARAMS ((FILE *, Elf_Internal_Shdr *));
277 static Elf_Internal_Sym *get_64bit_elf_symbols
278 PARAMS ((FILE *, Elf_Internal_Shdr *));
279 static const char *get_elf_section_flags
281 static int *get_dynamic_data
282 PARAMS ((FILE *, unsigned int));
283 static int get_32bit_dynamic_segment
285 static int get_64bit_dynamic_segment
287 #ifdef SUPPORT_DISASSEMBLY
288 static int disassemble_section
289 PARAMS ((Elf_Internal_Shdr *, FILE *));
291 static int dump_section
292 PARAMS ((Elf_Internal_Shdr *, FILE *));
293 static int display_debug_section
294 PARAMS ((Elf_Internal_Shdr *, FILE *));
295 static int display_debug_info
296 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
297 static int display_debug_not_supported
298 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
299 static int prescan_debug_info
300 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
301 static int display_debug_lines
302 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
303 static int display_debug_pubnames
304 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
305 static int display_debug_abbrev
306 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
307 static int display_debug_aranges
308 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
309 static int display_debug_frames
310 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
311 static int display_debug_macinfo
312 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
313 static int display_debug_str
314 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
315 static int display_debug_loc
316 PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
317 static unsigned char *process_abbrev_section
318 PARAMS ((unsigned char *, unsigned char *));
319 static void load_debug_str
321 static void free_debug_str
323 static const char *fetch_indirect_string
324 PARAMS ((unsigned long));
325 static void load_debug_loc
327 static void free_debug_loc
329 static unsigned long read_leb128
330 PARAMS ((unsigned char *, int *, int));
331 static int process_extended_line_op
332 PARAMS ((unsigned char *, int, int));
333 static void reset_state_machine
336 // PARAMS ((unsigned long)); //PG don't make this static since typedata.c needs it - put it in typedata.h instead
337 static char *get_AT_name
338 PARAMS ((unsigned long));
339 static char *get_FORM_name
340 PARAMS ((unsigned long));
341 static void free_abbrevs
343 static void add_abbrev
344 PARAMS ((unsigned long, unsigned long, int));
345 static void add_abbrev_attr
346 PARAMS ((unsigned long, unsigned long));
347 static unsigned char *read_and_display_attr
348 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
349 unsigned long, unsigned long, int, dwarf_entry*, char));
350 static unsigned char *read_and_display_attr_value
351 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
352 unsigned long, unsigned long, int, dwarf_entry*, char));
353 static unsigned char *display_block
354 PARAMS ((unsigned char *, unsigned long, char));
355 static void decode_location_expression
356 PARAMS ((unsigned char *, unsigned int, unsigned long, char, long*));
357 static void request_dump
358 PARAMS ((unsigned int, int));
359 static const char *get_elf_class
360 PARAMS ((unsigned int));
361 static const char *get_data_encoding
362 PARAMS ((unsigned int));
363 static const char *get_osabi_name
364 PARAMS ((unsigned int));
365 static int guess_is_rela
366 PARAMS ((unsigned long));
367 static const char *get_note_type
368 PARAMS ((unsigned int));
369 static const char *get_netbsd_elfcore_note_type
370 PARAMS ((unsigned int));
371 static int process_note
372 PARAMS ((Elf_Internal_Note *));
373 static int process_corefile_note_segment
374 PARAMS ((FILE *, bfd_vma, bfd_vma));
375 static int process_corefile_note_segments
377 static int process_corefile_contents
379 static int process_arch_specific
381 static int process_gnu_liblist
385 typedef int Elf32_Word;
389 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
390 ((X)->sh_name >= string_table_length \
391 ? "<corrupt>" : string_table + (X)->sh_name))
393 /* Given st_shndx I, map to section_headers index. */
394 #define SECTION_HEADER_INDEX(I) \
395 ((I) < SHN_LORESERVE \
397 : ((I) <= SHN_HIRESERVE \
399 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
401 /* Reverse of the above. */
402 #define SECTION_HEADER_NUM(N) \
403 ((N) < SHN_LORESERVE \
405 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
407 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
409 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
411 #define BYTE_GET(field) byte_get (field, sizeof (field))
413 /* If we can support a 64 bit data type then BFD64 should be defined
414 and sizeof (bfd_vma) == 8. In this case when translating from an
415 external 8 byte field to an internal field, we can assume that the
416 internal field is also 8 bytes wide and so we can extract all the data.
417 If, however, BFD64 is not defined, then we must assume that the
418 internal data structure only has 4 byte wide fields that are the
419 equivalent of the 8 byte wide external counterparts, and so we must
420 truncate the data. */
422 #define BYTE_GET8(field) byte_get (field, -8)
424 #define BYTE_GET8(field) byte_get (field, 8)
427 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
429 #define GET_ELF_SYMBOLS(file, section) \
430 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
431 : get_64bit_elf_symbols (file, section))
433 //PG - begin custom libiberty.a functions
435 PTR xmalloc (size_t size)
440 PTR xrealloc (PTR oldmem, size_t size)
442 return realloc(oldmem, size);
445 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
450 error VPARAMS ((const char *message, ...))
452 VA_OPEN (args, message);
453 VA_FIXEDARG (args, const char *, message);
455 fprintf (stderr, _("%s: Error: "), program_name);
456 vfprintf (stderr, message, args);
461 warn VPARAMS ((const char *message, ...))
463 VA_OPEN (args, message);
464 VA_FIXEDARG (args, const char *, message);
466 fprintf (stderr, _("%s: Warning: "), program_name);
467 vfprintf (stderr, message, args);
471 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
474 get_data (var, file, offset, size, reason)
486 if (fseek (file, offset, SEEK_SET))
488 error (_("Unable to seek to %x for %s\n"), offset, reason);
495 mvar = (PTR) malloc (size);
499 error (_("Out of memory allocating %d bytes for %s\n"),
505 if (fread (mvar, size, 1, file) != 1)
507 error (_("Unable to read in %d bytes of %s\n"), size, reason);
517 byte_get_little_endian (field, size)
518 unsigned char *field;
527 return ((unsigned int) (field[0]))
528 | (((unsigned int) (field[1])) << 8);
532 /* We want to extract data from an 8 byte wide field and
533 place it into a 4 byte wide field. Since this is a little
534 endian source we can just use the 4 byte extraction code. */
538 return ((unsigned long) (field[0]))
539 | (((unsigned long) (field[1])) << 8)
540 | (((unsigned long) (field[2])) << 16)
541 | (((unsigned long) (field[3])) << 24);
546 /* This is a special case, generated by the BYTE_GET8 macro.
547 It means that we are loading an 8 byte value from a field
548 in an external structure into an 8 byte value in a field
549 in an internal strcuture. */
550 return ((bfd_vma) (field[0]))
551 | (((bfd_vma) (field[1])) << 8)
552 | (((bfd_vma) (field[2])) << 16)
553 | (((bfd_vma) (field[3])) << 24)
554 | (((bfd_vma) (field[4])) << 32)
555 | (((bfd_vma) (field[5])) << 40)
556 | (((bfd_vma) (field[6])) << 48)
557 | (((bfd_vma) (field[7])) << 56);
560 error (_("Unhandled data length: %d\n"), size);
566 byte_put_little_endian (field, value, size)
567 unsigned char * field;
574 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
575 field[6] = ((value >> 24) >> 24) & 0xff;
576 field[5] = ((value >> 24) >> 16) & 0xff;
577 field[4] = ((value >> 24) >> 8) & 0xff;
580 field[3] = (value >> 24) & 0xff;
581 field[2] = (value >> 16) & 0xff;
584 field[1] = (value >> 8) & 0xff;
587 field[0] = value & 0xff;
591 error (_("Unhandled data length: %d\n"), size);
596 /* Print a VMA value. */
598 print_vma (vma, mode)
608 case FULL_HEX: printf ("0x"); /* drop through */
609 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
610 case PREFIX_HEX: printf ("0x"); /* drop through */
611 case HEX: printf ("%lx", (unsigned long) vma); break;
612 case DEC: printf ("%ld", (unsigned long) vma); break;
613 case DEC_5: printf ("%5ld", (long) vma); break;
614 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
635 #if BFD_HOST_64BIT_LONG
638 if (_bfd_int64_high (vma))
639 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
641 printf ("%lx", _bfd_int64_low (vma));
646 #if BFD_HOST_64BIT_LONG
649 if (_bfd_int64_high (vma))
651 printf ("++%ld", _bfd_int64_low (vma));
653 printf ("%ld", _bfd_int64_low (vma));
658 #if BFD_HOST_64BIT_LONG
659 printf ("%5ld", vma);
661 if (_bfd_int64_high (vma))
663 printf ("++%ld", _bfd_int64_low (vma));
665 printf ("%5ld", _bfd_int64_low (vma));
670 #if BFD_HOST_64BIT_LONG
673 if (_bfd_int64_high (vma))
675 printf ("++%lu", _bfd_int64_low (vma));
677 printf ("%lu", _bfd_int64_low (vma));
685 /* Display a symbol on stdout. If do_wide is not true then
686 format the symbol to be at most WIDTH characters,
687 truncating as necessary. If WIDTH is negative then
688 format the string to be exactly - WIDTH characters,
689 truncating or padding as necessary. */
692 print_symbol (width, symbol)
697 printf ("%s", symbol);
699 printf ("%-*.*s", width, width, symbol);
701 printf ("%-.*s", width, symbol);
705 byte_get_big_endian (field, size)
706 unsigned char *field;
715 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
718 return ((unsigned long) (field[3]))
719 | (((unsigned long) (field[2])) << 8)
720 | (((unsigned long) (field[1])) << 16)
721 | (((unsigned long) (field[0])) << 24);
725 /* Although we are extracing data from an 8 byte wide field, we
726 are returning only 4 bytes of data. */
727 return ((unsigned long) (field[7]))
728 | (((unsigned long) (field[6])) << 8)
729 | (((unsigned long) (field[5])) << 16)
730 | (((unsigned long) (field[4])) << 24);
734 /* This is a special case, generated by the BYTE_GET8 macro.
735 It means that we are loading an 8 byte value from a field
736 in an external structure into an 8 byte value in a field
737 in an internal strcuture. */
738 return ((bfd_vma) (field[7]))
739 | (((bfd_vma) (field[6])) << 8)
740 | (((bfd_vma) (field[5])) << 16)
741 | (((bfd_vma) (field[4])) << 24)
742 | (((bfd_vma) (field[3])) << 32)
743 | (((bfd_vma) (field[2])) << 40)
744 | (((bfd_vma) (field[1])) << 48)
745 | (((bfd_vma) (field[0])) << 56);
749 error (_("Unhandled data length: %d\n"), size);
755 byte_put_big_endian (field, value, size)
756 unsigned char * field;
763 field[7] = value & 0xff;
764 field[6] = (value >> 8) & 0xff;
765 field[5] = (value >> 16) & 0xff;
766 field[4] = (value >> 24) & 0xff;
771 field[3] = value & 0xff;
772 field[2] = (value >> 8) & 0xff;
776 field[1] = value & 0xff;
780 field[0] = value & 0xff;
784 error (_("Unhandled data length: %d\n"), size);
789 /* Guess the relocation size commonly used by the specific machines. */
792 guess_is_rela (e_machine)
793 unsigned long e_machine;
797 /* Targets that use REL relocations. */
813 /* Targets that use RELA relocations. */
828 case EM_CYGNUS_MN10200:
830 case EM_CYGNUS_MN10300:
875 warn (_("Don't know about relocations on this machine architecture\n"));
881 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
883 unsigned long rel_offset;
884 unsigned long rel_size;
885 Elf_Internal_Rela **relasp;
886 unsigned long *nrelasp;
888 Elf_Internal_Rela *relas;
889 unsigned long nrelas;
894 Elf32_External_Rela *erelas;
896 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
897 rel_size, _("relocs"));
901 nrelas = rel_size / sizeof (Elf32_External_Rela);
903 relas = (Elf_Internal_Rela *)
904 malloc (nrelas * sizeof (Elf_Internal_Rela));
908 error(_("out of memory parsing relocs"));
912 for (i = 0; i < nrelas; i++)
914 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
915 relas[i].r_info = BYTE_GET (erelas[i].r_info);
916 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
923 Elf64_External_Rela *erelas;
925 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
926 rel_size, _("relocs"));
930 nrelas = rel_size / sizeof (Elf64_External_Rela);
932 relas = (Elf_Internal_Rela *)
933 malloc (nrelas * sizeof (Elf_Internal_Rela));
937 error(_("out of memory parsing relocs"));
941 for (i = 0; i < nrelas; i++)
943 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
944 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
945 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
956 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
958 unsigned long rel_offset;
959 unsigned long rel_size;
960 Elf_Internal_Rela **relsp;
961 unsigned long *nrelsp;
963 Elf_Internal_Rela *rels;
969 Elf32_External_Rel *erels;
971 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
972 rel_size, _("relocs"));
976 nrels = rel_size / sizeof (Elf32_External_Rel);
978 rels = (Elf_Internal_Rela *) malloc (nrels * sizeof (Elf_Internal_Rela));
982 error(_("out of memory parsing relocs"));
986 for (i = 0; i < nrels; i++)
988 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
989 rels[i].r_info = BYTE_GET (erels[i].r_info);
990 rels[i].r_addend = 0;
997 Elf64_External_Rel *erels;
999 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
1000 rel_size, _("relocs"));
1004 nrels = rel_size / sizeof (Elf64_External_Rel);
1006 rels = (Elf_Internal_Rela *) malloc (nrels * sizeof (Elf_Internal_Rela));
1010 error(_("out of memory parsing relocs"));
1014 for (i = 0; i < nrels; i++)
1016 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
1017 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
1018 rels[i].r_addend = 0;
1028 /* Display the contents of the relocation data found at the specified offset. */
1031 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
1033 unsigned long rel_offset;
1034 unsigned long rel_size;
1035 Elf_Internal_Sym *symtab;
1036 unsigned long nsyms;
1041 Elf_Internal_Rela *rels;
1044 if (is_rela == UNKNOWN)
1045 is_rela = guess_is_rela (elf_header.e_machine);
1049 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1054 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
1063 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1065 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1070 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1072 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1080 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1082 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1087 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1089 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1093 for (i = 0; i < rel_size; i++)
1098 bfd_vma symtab_index;
1101 offset = rels[i].r_offset;
1102 info = rels[i].r_info;
1106 type = ELF32_R_TYPE (info);
1107 symtab_index = ELF32_R_SYM (info);
1111 /* The #ifdef BFD64 below is to prevent a compile time warning.
1112 We know that if we do not have a 64 bit data type that we
1113 will never execute this code anyway. */
1115 type = ELF64_R_TYPE (info);
1117 symtab_index = ELF64_R_SYM (info);
1123 #ifdef _bfd_int64_low
1124 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
1126 printf ("%8.8lx %8.8lx ", offset, info);
1131 #ifdef _bfd_int64_low
1133 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1134 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1135 _bfd_int64_high (offset),
1136 _bfd_int64_low (offset),
1137 _bfd_int64_high (info),
1138 _bfd_int64_low (info));
1141 ? "%16.16lx %16.16lx "
1142 : "%12.12lx %12.12lx ",
1147 switch (elf_header.e_machine)
1155 rtype = elf_i386_reloc_type (type);
1161 #ifdef _bfd_int64_low
1162 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1164 printf (_("unrecognized: %-7lx"), type);
1167 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1171 if (symtab == NULL || symtab_index >= nsyms)
1172 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1175 Elf_Internal_Sym *psym;
1177 psym = symtab + symtab_index;
1180 print_vma (psym->st_value, LONG_HEX);
1181 printf (is_32bit_elf ? " " : " ");
1183 if (psym->st_name == 0)
1185 const char *sec_name = "<null>";
1188 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1190 bfd_vma sec_index = (bfd_vma) -1;
1192 if (psym->st_shndx < SHN_LORESERVE)
1193 sec_index = psym->st_shndx;
1194 else if (psym->st_shndx > SHN_LORESERVE)
1195 sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1198 if (sec_index != (bfd_vma) -1)
1199 sec_name = SECTION_NAME (section_headers + sec_index);
1200 else if (psym->st_shndx == SHN_ABS)
1202 else if (psym->st_shndx == SHN_COMMON)
1203 sec_name = "COMMON";
1206 sprintf (name_buf, "<section 0x%x>",
1207 (unsigned int) psym->st_shndx);
1208 sec_name = name_buf;
1211 print_symbol (22, sec_name);
1213 else if (strtab == NULL)
1214 printf (_("<string table index %3ld>"), psym->st_name);
1216 print_symbol (22, strtab + psym->st_name);
1219 printf (" + %lx", (unsigned long) rels[i].r_addend);
1224 printf ("%*c", is_32bit_elf ? (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1225 print_vma (rels[i].r_addend, LONG_HEX);
1238 get_mips_dynamic_type (type)
1249 get_sparc64_dynamic_type (type)
1260 get_ppc64_dynamic_type (type)
1271 get_parisc_dynamic_type (type)
1282 get_ia64_dynamic_type (type)
1293 get_dynamic_type (type)
1296 static char buff[32];
1300 case DT_NULL: return "NULL";
1301 case DT_NEEDED: return "NEEDED";
1302 case DT_PLTRELSZ: return "PLTRELSZ";
1303 case DT_PLTGOT: return "PLTGOT";
1304 case DT_HASH: return "HASH";
1305 case DT_STRTAB: return "STRTAB";
1306 case DT_SYMTAB: return "SYMTAB";
1307 case DT_RELA: return "RELA";
1308 case DT_RELASZ: return "RELASZ";
1309 case DT_RELAENT: return "RELAENT";
1310 case DT_STRSZ: return "STRSZ";
1311 case DT_SYMENT: return "SYMENT";
1312 case DT_INIT: return "INIT";
1313 case DT_FINI: return "FINI";
1314 case DT_SONAME: return "SONAME";
1315 case DT_RPATH: return "RPATH";
1316 case DT_SYMBOLIC: return "SYMBOLIC";
1317 case DT_REL: return "REL";
1318 case DT_RELSZ: return "RELSZ";
1319 case DT_RELENT: return "RELENT";
1320 case DT_PLTREL: return "PLTREL";
1321 case DT_DEBUG: return "DEBUG";
1322 case DT_TEXTREL: return "TEXTREL";
1323 case DT_JMPREL: return "JMPREL";
1324 case DT_BIND_NOW: return "BIND_NOW";
1325 case DT_INIT_ARRAY: return "INIT_ARRAY";
1326 case DT_FINI_ARRAY: return "FINI_ARRAY";
1327 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1328 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1329 case DT_RUNPATH: return "RUNPATH";
1330 case DT_FLAGS: return "FLAGS";
1332 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1333 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1335 case DT_CHECKSUM: return "CHECKSUM";
1336 case DT_PLTPADSZ: return "PLTPADSZ";
1337 case DT_MOVEENT: return "MOVEENT";
1338 case DT_MOVESZ: return "MOVESZ";
1339 case DT_FEATURE: return "FEATURE";
1340 case DT_POSFLAG_1: return "POSFLAG_1";
1341 case DT_SYMINSZ: return "SYMINSZ";
1342 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1344 case DT_ADDRRNGLO: return "ADDRRNGLO";
1345 case DT_CONFIG: return "CONFIG";
1346 case DT_DEPAUDIT: return "DEPAUDIT";
1347 case DT_AUDIT: return "AUDIT";
1348 case DT_PLTPAD: return "PLTPAD";
1349 case DT_MOVETAB: return "MOVETAB";
1350 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1352 case DT_VERSYM: return "VERSYM";
1354 case DT_RELACOUNT: return "RELACOUNT";
1355 case DT_RELCOUNT: return "RELCOUNT";
1356 case DT_FLAGS_1: return "FLAGS_1";
1357 case DT_VERDEF: return "VERDEF";
1358 case DT_VERDEFNUM: return "VERDEFNUM";
1359 case DT_VERNEED: return "VERNEED";
1360 case DT_VERNEEDNUM: return "VERNEEDNUM";
1362 case DT_AUXILIARY: return "AUXILIARY";
1363 case DT_USED: return "USED";
1364 case DT_FILTER: return "FILTER";
1366 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1367 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1368 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1369 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1370 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1373 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1377 switch (elf_header.e_machine)
1380 case EM_MIPS_RS3_LE:
1381 result = get_mips_dynamic_type (type);
1384 result = get_sparc64_dynamic_type (type);
1387 result = get_ppc64_dynamic_type (type);
1390 result = get_ia64_dynamic_type (type);
1400 sprintf (buff, _("Processor Specific: %lx"), type);
1402 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1406 switch (elf_header.e_machine)
1409 result = get_parisc_dynamic_type (type);
1419 sprintf (buff, _("Operating System specific: %lx"), type);
1422 sprintf (buff, _("<unknown>: %lx"), type);
1429 get_file_type (e_type)
1432 static char buff[32];
1436 case ET_NONE: return _("NONE (None)");
1437 case ET_REL: return _("REL (Relocatable file)");
1438 case ET_EXEC: return _("EXEC (Executable file)");
1439 case ET_DYN: return _("DYN (Shared object file)");
1440 case ET_CORE: return _("CORE (Core file)");
1443 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1444 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1445 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1446 sprintf (buff, _("OS Specific: (%x)"), e_type);
1448 sprintf (buff, _("<unknown>: %x"), e_type);
1454 get_machine_name (e_machine)
1457 static char buff[64]; /* XXX */
1461 case EM_NONE: return _("None");
1462 case EM_M32: return "WE32100";
1463 case EM_SPARC: return "Sparc";
1464 case EM_386: return "Intel 80386";
1465 case EM_68K: return "MC68000";
1466 case EM_88K: return "MC88000";
1467 case EM_486: return "Intel 80486";
1468 case EM_860: return "Intel 80860";
1469 case EM_MIPS: return "MIPS R3000";
1470 case EM_S370: return "IBM System/370";
1471 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1472 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1473 case EM_PARISC: return "HPPA";
1474 case EM_PPC_OLD: return "Power PC (old)";
1475 case EM_SPARC32PLUS: return "Sparc v8+" ;
1476 case EM_960: return "Intel 90860";
1477 case EM_PPC: return "PowerPC";
1478 case EM_PPC64: return "PowerPC64";
1479 case EM_V800: return "NEC V800";
1480 case EM_FR20: return "Fujitsu FR20";
1481 case EM_RH32: return "TRW RH32";
1482 case EM_MCORE: return "MCORE";
1483 case EM_ARM: return "ARM";
1484 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1485 case EM_SH: return "Renesas / SuperH SH";
1486 case EM_SPARCV9: return "Sparc v9";
1487 case EM_TRICORE: return "Siemens Tricore";
1488 case EM_ARC: return "ARC";
1489 case EM_H8_300: return "Renesas H8/300";
1490 case EM_H8_300H: return "Renesas H8/300H";
1491 case EM_H8S: return "Renesas H8S";
1492 case EM_H8_500: return "Renesas H8/500";
1493 case EM_IA_64: return "Intel IA-64";
1494 case EM_MIPS_X: return "Stanford MIPS-X";
1495 case EM_COLDFIRE: return "Motorola Coldfire";
1496 case EM_68HC12: return "Motorola M68HC12";
1497 case EM_ALPHA: return "Alpha";
1498 case EM_CYGNUS_D10V:
1499 case EM_D10V: return "d10v";
1500 case EM_CYGNUS_D30V:
1501 case EM_D30V: return "d30v";
1502 case EM_CYGNUS_M32R:
1503 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
1504 case EM_CYGNUS_V850:
1505 case EM_V850: return "NEC v850";
1506 case EM_CYGNUS_MN10300:
1507 case EM_MN10300: return "mn10300";
1508 case EM_CYGNUS_MN10200:
1509 case EM_MN10200: return "mn10200";
1510 case EM_CYGNUS_FR30:
1511 case EM_FR30: return "Fujitsu FR30";
1512 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1514 case EM_PJ: return "picoJava";
1515 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1516 case EM_PCP: return "Siemens PCP";
1517 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1518 case EM_NDR1: return "Denso NDR1 microprocesspr";
1519 case EM_STARCORE: return "Motorola Star*Core processor";
1520 case EM_ME16: return "Toyota ME16 processor";
1521 case EM_ST100: return "STMicroelectronics ST100 processor";
1522 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1523 case EM_FX66: return "Siemens FX66 microcontroller";
1524 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1525 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1526 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1527 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1528 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1529 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1530 case EM_SVX: return "Silicon Graphics SVx";
1531 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1532 case EM_VAX: return "Digital VAX";
1534 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1535 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1536 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1537 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1538 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1539 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1540 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1541 case EM_PRISM: return "Vitesse Prism";
1542 case EM_X86_64: return "Advanced Micro Devices X86-64";
1544 case EM_S390: return "IBM S/390";
1545 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1547 case EM_OR32: return "OpenRISC";
1548 case EM_DLX: return "OpenDLX";
1550 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
1551 case EM_IQ2000: return "Vitesse IQ2000";
1553 case EM_XTENSA: return "Tensilica Xtensa Processor";
1555 sprintf (buff, _("<unknown>: %x"), e_machine);
1561 get_machine_flags (e_flags, e_machine)
1565 static char buf[1024];
1572 get_mips_segment_type (type)
1579 get_parisc_segment_type (type)
1586 get_ia64_segment_type (type)
1593 get_segment_type (p_type)
1594 unsigned long p_type;
1596 static char buff[32];
1600 case PT_NULL: return "NULL";
1601 case PT_LOAD: return "LOAD";
1602 case PT_DYNAMIC: return "DYNAMIC";
1603 case PT_INTERP: return "INTERP";
1604 case PT_NOTE: return "NOTE";
1605 case PT_SHLIB: return "SHLIB";
1606 case PT_PHDR: return "PHDR";
1607 case PT_TLS: return "TLS";
1609 case PT_GNU_EH_FRAME:
1610 return "GNU_EH_FRAME";
1613 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1617 switch (elf_header.e_machine)
1620 case EM_MIPS_RS3_LE:
1621 result = get_mips_segment_type (p_type);
1624 result = get_parisc_segment_type (p_type);
1627 result = get_ia64_segment_type (p_type);
1637 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1639 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1643 switch (elf_header.e_machine)
1646 result = get_parisc_segment_type (p_type);
1649 result = get_ia64_segment_type (p_type);
1659 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1662 sprintf (buff, _("<unknown>: %lx"), p_type);
1669 get_mips_section_type_name (sh_type)
1670 unsigned int sh_type;
1676 get_parisc_section_type_name (sh_type)
1677 unsigned int sh_type;
1683 get_ia64_section_type_name (sh_type)
1684 unsigned int sh_type;
1690 get_section_type_name (sh_type)
1691 unsigned int sh_type;
1693 static char buff[32];
1697 case SHT_NULL: return "NULL";
1698 case SHT_PROGBITS: return "PROGBITS";
1699 case SHT_SYMTAB: return "SYMTAB";
1700 case SHT_STRTAB: return "STRTAB";
1701 case SHT_RELA: return "RELA";
1702 case SHT_HASH: return "HASH";
1703 case SHT_DYNAMIC: return "DYNAMIC";
1704 case SHT_NOTE: return "NOTE";
1705 case SHT_NOBITS: return "NOBITS";
1706 case SHT_REL: return "REL";
1707 case SHT_SHLIB: return "SHLIB";
1708 case SHT_DYNSYM: return "DYNSYM";
1709 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1710 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1711 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1712 case SHT_GROUP: return "GROUP";
1713 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1714 case SHT_GNU_verdef: return "VERDEF";
1715 case SHT_GNU_verneed: return "VERNEED";
1716 case SHT_GNU_versym: return "VERSYM";
1717 case 0x6ffffff0: return "VERSYM";
1718 case 0x6ffffffc: return "VERDEF";
1719 case 0x7ffffffd: return "AUXILIARY";
1720 case 0x7fffffff: return "FILTER";
1721 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
1724 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1728 switch (elf_header.e_machine)
1731 case EM_MIPS_RS3_LE:
1732 result = get_mips_section_type_name (sh_type);
1735 result = get_parisc_section_type_name (sh_type);
1738 result = get_ia64_section_type_name (sh_type);
1748 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
1750 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1751 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
1752 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1753 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
1755 sprintf (buff, _("<unknown>: %x"), sh_type);
1761 #define OPTION_DEBUG_DUMP 512
1763 struct option options[] =
1765 {"all", no_argument, 0, 'a'},
1766 {"file-header", no_argument, 0, 'h'},
1767 {"program-headers", no_argument, 0, 'l'},
1768 {"headers", no_argument, 0, 'e'},
1769 {"histogram", no_argument, 0, 'I'},
1770 {"segments", no_argument, 0, 'l'},
1771 {"sections", no_argument, 0, 'S'},
1772 {"section-headers", no_argument, 0, 'S'},
1773 {"symbols", no_argument, 0, 's'},
1774 {"syms", no_argument, 0, 's'},
1775 {"relocs", no_argument, 0, 'r'},
1776 {"notes", no_argument, 0, 'n'},
1777 {"dynamic", no_argument, 0, 'd'},
1778 {"arch-specific", no_argument, 0, 'A'},
1779 {"version-info", no_argument, 0, 'V'},
1780 {"use-dynamic", no_argument, 0, 'D'},
1781 {"hex-dump", required_argument, 0, 'x'},
1782 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
1783 {"unwind", no_argument, 0, 'u'},
1784 #ifdef SUPPORT_DISASSEMBLY
1785 {"instruction-dump", required_argument, 0, 'i'},
1788 {"version", no_argument, 0, 'v'},
1789 {"wide", no_argument, 0, 'W'},
1790 {"help", no_argument, 0, 'H'},
1791 {0, no_argument, 0, 0}
1797 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
1798 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
1799 fprintf (stdout, _(" Options are:\n\
1800 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
1801 -h --file-header Display the ELF file header\n\
1802 -l --program-headers Display the program headers\n\
1803 --segments An alias for --program-headers\n\
1804 -S --section-headers Display the sections' header\n\
1805 --sections An alias for --section-headers\n\
1806 -e --headers Equivalent to: -h -l -S\n\
1807 -s --syms Display the symbol table\n\
1808 --symbols An alias for --syms\n\
1809 -n --notes Display the core notes (if present)\n\
1810 -r --relocs Display the relocations (if present)\n\
1811 -u --unwind Display the unwind info (if present)\n\
1812 -d --dynamic Display the dynamic segment (if present)\n\
1813 -V --version-info Display the version sections (if present)\n\
1814 -A --arch-specific Display architecture specific information (if any).\n\
1815 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
1816 -x --hex-dump=<number> Dump the contents of section <number>\n\
1817 -w[liaprmfFso] or\n\
1818 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
1819 Display the contents of DWARF2 debug sections\n"));
1820 #ifdef SUPPORT_DISASSEMBLY
1821 fprintf (stdout, _("\
1822 -i --instruction-dump=<number>\n\
1823 Disassemble the contents of section <number>\n"));
1825 fprintf (stdout, _("\
1826 -I --histogram Display histogram of bucket list lengths\n\
1827 -W --wide Allow output width to exceed 80 characters\n\
1828 -H --help Display this information\n\
1829 -v --version Display the version number of readelf\n"));
1830 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
1836 request_dump (section, type)
1837 unsigned int section;
1840 if (section >= num_dump_sects)
1842 char *new_dump_sects;
1844 new_dump_sects = (char *) calloc (section + 1, 1);
1846 if (new_dump_sects == NULL)
1847 error (_("Out of memory allocating dump request table."));
1850 /* Copy current flag settings. */
1851 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1855 dump_sects = new_dump_sects;
1856 num_dump_sects = section + 1;
1861 dump_sects[section] |= type;
1867 parse_args (argc, argv)
1876 while ((c = getopt_long
1877 (argc, argv, "ersuahnldSDAIw::x:i:vVWH", options, NULL)) != EOF)
1944 section = strtoul (optarg, & cp, 0);
1945 if (! *cp && section >= 0)
1947 request_dump (section, HEX_DUMP);
1957 unsigned int idx = 0;
1962 switch (optarg[idx++])
1971 do_debug_abbrevs = 1;
1981 do_debug_pubnames = 1;
1986 do_debug_aranges = 1;
1990 do_debug_frames_interp = 1;
1992 do_debug_frames = 1;
1997 do_debug_macinfo = 1;
2011 warn (_("Unrecognized debug option '%s'\n"), optarg);
2016 case OPTION_DEBUG_DUMP:
2022 static const char *debug_dump_opt[]
2023 = { "line", "info", "abbrev", "pubnames", "ranges",
2024 "macro", "frames", "frames-interp", "str", "loc", NULL };
2033 for (idx = 0; debug_dump_opt[idx]; idx++)
2035 size_t len = strlen (debug_dump_opt[idx]);
2037 if (strncmp (p, debug_dump_opt[idx], len) == 0
2038 && (p[len] == ',' || p[len] == '\0'))
2047 do_debug_abbrevs = 1;
2058 do_debug_pubnames = 1;
2062 do_debug_aranges = 1;
2067 do_debug_frames_interp = 1;
2068 do_debug_frames = 1;
2072 do_debug_macinfo = 1;
2085 if (debug_dump_opt[idx] == NULL)
2087 warn (_("Unrecognized debug option '%s'\n"), p);
2088 p = strchr (p, ',');
2098 #ifdef SUPPORT_DISASSEMBLY
2101 section = strtoul (optarg, & cp, 0);
2102 if (! *cp && section >= 0)
2104 request_dump (section, DISASS_DUMP);
2110 /* print_version (program_name);*/
2120 /* xgettext:c-format */
2121 error (_("Invalid option '-%c'\n"), c);
2128 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2129 && !do_segments && !do_header && !do_dump && !do_version
2130 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2134 warn (_("Nothing to do.\n"));
2140 get_elf_class (elf_class)
2141 unsigned int elf_class;
2143 static char buff[32];
2147 case ELFCLASSNONE: return _("none");
2148 case ELFCLASS32: return "ELF32";
2149 case ELFCLASS64: return "ELF64";
2151 sprintf (buff, _("<unknown: %x>"), elf_class);
2157 get_data_encoding (encoding)
2158 unsigned int encoding;
2160 static char buff[32];
2164 case ELFDATANONE: return _("none");
2165 case ELFDATA2LSB: return _("2's complement, little endian");
2166 case ELFDATA2MSB: return _("2's complement, big endian");
2168 sprintf (buff, _("<unknown: %x>"), encoding);
2174 get_osabi_name (osabi)
2177 static char buff[32];
2181 case ELFOSABI_NONE: return "UNIX - System V";
2182 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2183 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2184 case ELFOSABI_LINUX: return "UNIX - Linux";
2185 case ELFOSABI_HURD: return "GNU/Hurd";
2186 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2187 case ELFOSABI_AIX: return "UNIX - AIX";
2188 case ELFOSABI_IRIX: return "UNIX - IRIX";
2189 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2190 case ELFOSABI_TRU64: return "UNIX - TRU64";
2191 case ELFOSABI_MODESTO: return "Novell - Modesto";
2192 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2193 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
2194 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
2195 case ELFOSABI_AROS: return "Amiga Research OS";
2196 case ELFOSABI_STANDALONE: return _("Standalone App");
2197 case ELFOSABI_ARM: return "ARM";
2199 sprintf (buff, _("<unknown: %x>"), osabi);
2204 /* Decode the data held in 'elf_header'. */
2207 process_file_header ()
2209 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
2210 || elf_header.e_ident[EI_MAG1] != ELFMAG1
2211 || elf_header.e_ident[EI_MAG2] != ELFMAG2
2212 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
2215 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2223 printf (_("ELF Header:\n"));
2224 printf (_(" Magic: "));
2225 for (i = 0; i < EI_NIDENT; i++)
2226 printf ("%2.2x ", elf_header.e_ident[i]);
2228 printf (_(" Class: %s\n"),
2229 get_elf_class (elf_header.e_ident[EI_CLASS]));
2230 printf (_(" Data: %s\n"),
2231 get_data_encoding (elf_header.e_ident[EI_DATA]));
2232 printf (_(" Version: %d %s\n"),
2233 elf_header.e_ident[EI_VERSION],
2234 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
2236 : (elf_header.e_ident[EI_VERSION] != EV_NONE
2239 printf (_(" OS/ABI: %s\n"),
2240 get_osabi_name (elf_header.e_ident[EI_OSABI]));
2241 printf (_(" ABI Version: %d\n"),
2242 elf_header.e_ident[EI_ABIVERSION]);
2243 printf (_(" Type: %s\n"),
2244 get_file_type (elf_header.e_type));
2245 printf (_(" Machine: %s\n"),
2246 get_machine_name (elf_header.e_machine));
2247 printf (_(" Version: 0x%lx\n"),
2248 (unsigned long) elf_header.e_version);
2250 printf (_(" Entry point address: "));
2251 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2252 printf (_("\n Start of program headers: "));
2253 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2254 printf (_(" (bytes into file)\n Start of section headers: "));
2255 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2256 printf (_(" (bytes into file)\n"));
2258 printf (_(" Flags: 0x%lx%s\n"),
2259 (unsigned long) elf_header.e_flags,
2260 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2261 printf (_(" Size of this header: %ld (bytes)\n"),
2262 (long) elf_header.e_ehsize);
2263 printf (_(" Size of program headers: %ld (bytes)\n"),
2264 (long) elf_header.e_phentsize);
2265 printf (_(" Number of program headers: %ld\n"),
2266 (long) elf_header.e_phnum);
2267 printf (_(" Size of section headers: %ld (bytes)\n"),
2268 (long) elf_header.e_shentsize);
2269 printf (_(" Number of section headers: %ld"),
2270 (long) elf_header.e_shnum);
2271 if (section_headers != NULL && elf_header.e_shnum == 0)
2272 printf (" (%ld)", (long) section_headers[0].sh_size);
2273 putc ('\n', stdout);
2274 printf (_(" Section header string table index: %ld"),
2275 (long) elf_header.e_shstrndx);
2276 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
2277 printf (" (%ld)", (long) section_headers[0].sh_link);
2278 putc ('\n', stdout);
2281 if (section_headers != NULL)
2283 if (elf_header.e_shnum == 0)
2284 elf_header.e_shnum = section_headers[0].sh_size;
2285 if (elf_header.e_shstrndx == SHN_XINDEX)
2286 elf_header.e_shstrndx = section_headers[0].sh_link;
2287 free (section_headers);
2288 section_headers = NULL;
2296 get_32bit_program_headers (file, program_headers)
2298 Elf_Internal_Phdr *program_headers;
2300 Elf32_External_Phdr *phdrs;
2301 Elf32_External_Phdr *external;
2302 Elf_Internal_Phdr *internal;
2305 phdrs = ((Elf32_External_Phdr *)
2306 get_data (NULL, file, elf_header.e_phoff,
2307 elf_header.e_phentsize * elf_header.e_phnum,
2308 _("program headers")));
2312 for (i = 0, internal = program_headers, external = phdrs;
2313 i < elf_header.e_phnum;
2314 i++, internal++, external++)
2316 internal->p_type = BYTE_GET (external->p_type);
2317 internal->p_offset = BYTE_GET (external->p_offset);
2318 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2319 internal->p_paddr = BYTE_GET (external->p_paddr);
2320 internal->p_filesz = BYTE_GET (external->p_filesz);
2321 internal->p_memsz = BYTE_GET (external->p_memsz);
2322 internal->p_flags = BYTE_GET (external->p_flags);
2323 internal->p_align = BYTE_GET (external->p_align);
2332 get_64bit_program_headers (file, program_headers)
2334 Elf_Internal_Phdr *program_headers;
2336 Elf64_External_Phdr *phdrs;
2337 Elf64_External_Phdr *external;
2338 Elf_Internal_Phdr *internal;
2341 phdrs = ((Elf64_External_Phdr *)
2342 get_data (NULL, file, elf_header.e_phoff,
2343 elf_header.e_phentsize * elf_header.e_phnum,
2344 _("program headers")));
2348 for (i = 0, internal = program_headers, external = phdrs;
2349 i < elf_header.e_phnum;
2350 i++, internal++, external++)
2352 internal->p_type = BYTE_GET (external->p_type);
2353 internal->p_flags = BYTE_GET (external->p_flags);
2354 internal->p_offset = BYTE_GET8 (external->p_offset);
2355 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2356 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2357 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2358 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2359 internal->p_align = BYTE_GET8 (external->p_align);
2367 /* Returns 1 if the program headers were loaded. */
2370 process_program_headers (file)
2373 Elf_Internal_Phdr *program_headers;
2374 Elf_Internal_Phdr *segment;
2377 if (elf_header.e_phnum == 0)
2380 printf (_("\nThere are no program headers in this file.\n"));
2384 if (do_segments && !do_header)
2386 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2387 printf (_("Entry point "));
2388 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2389 printf (_("\nThere are %d program headers, starting at offset "),
2390 elf_header.e_phnum);
2391 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2395 program_headers = (Elf_Internal_Phdr *) malloc
2396 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2398 if (program_headers == NULL)
2400 error (_("Out of memory\n"));
2405 i = get_32bit_program_headers (file, program_headers);
2407 i = get_64bit_program_headers (file, program_headers);
2411 free (program_headers);
2417 if (elf_header.e_phnum > 1)
2418 printf (_("\nProgram Headers:\n"));
2420 printf (_("\nProgram Headers:\n"));
2424 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2427 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2431 (_(" Type Offset VirtAddr PhysAddr\n"));
2433 (_(" FileSiz MemSiz Flags Align\n"));
2441 for (i = 0, segment = program_headers;
2442 i < elf_header.e_phnum;
2447 printf (" %-14.14s ", get_segment_type (segment->p_type));
2451 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2452 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2453 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2454 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2455 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2457 (segment->p_flags & PF_R ? 'R' : ' '),
2458 (segment->p_flags & PF_W ? 'W' : ' '),
2459 (segment->p_flags & PF_X ? 'E' : ' '));
2460 printf ("%#lx", (unsigned long) segment->p_align);
2464 if ((unsigned long) segment->p_offset == segment->p_offset)
2465 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2468 print_vma (segment->p_offset, FULL_HEX);
2472 print_vma (segment->p_vaddr, FULL_HEX);
2474 print_vma (segment->p_paddr, FULL_HEX);
2477 if ((unsigned long) segment->p_filesz == segment->p_filesz)
2478 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
2481 print_vma (segment->p_filesz, FULL_HEX);
2485 if ((unsigned long) segment->p_memsz == segment->p_memsz)
2486 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
2489 print_vma (segment->p_offset, FULL_HEX);
2493 (segment->p_flags & PF_R ? 'R' : ' '),
2494 (segment->p_flags & PF_W ? 'W' : ' '),
2495 (segment->p_flags & PF_X ? 'E' : ' '));
2497 if ((unsigned long) segment->p_align == segment->p_align)
2498 printf ("%#lx", (unsigned long) segment->p_align);
2501 print_vma (segment->p_align, PREFIX_HEX);
2506 print_vma (segment->p_offset, FULL_HEX);
2508 print_vma (segment->p_vaddr, FULL_HEX);
2510 print_vma (segment->p_paddr, FULL_HEX);
2512 print_vma (segment->p_filesz, FULL_HEX);
2514 print_vma (segment->p_memsz, FULL_HEX);
2516 (segment->p_flags & PF_R ? 'R' : ' '),
2517 (segment->p_flags & PF_W ? 'W' : ' '),
2518 (segment->p_flags & PF_X ? 'E' : ' '));
2519 print_vma (segment->p_align, HEX);
2523 switch (segment->p_type)
2528 unsigned long align_mask = -segment->p_align;
2530 if (align_mask == 0)
2532 loadaddr = ((segment->p_vaddr & align_mask)
2533 - (segment->p_offset & align_mask));
2539 error (_("more than one dynamic segment\n"));
2541 dynamic_addr = segment->p_offset;
2542 dynamic_size = segment->p_filesz;
2546 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2547 error (_("Unable to find program interpreter name\n"));
2550 program_interpreter[0] = 0;
2551 fscanf (file, "%63s", program_interpreter);
2554 printf (_("\n [Requesting program interpreter: %s]"),
2555 program_interpreter);
2561 putc ('\n', stdout);
2570 if (do_segments && section_headers != NULL)
2572 printf (_("\n Section to Segment mapping:\n"));
2573 printf (_(" Segment Sections...\n"));
2575 assert (string_table != NULL);
2577 for (i = 0; i < elf_header.e_phnum; i++)
2580 Elf_Internal_Shdr *section;
2582 segment = program_headers + i;
2583 section = section_headers;
2585 printf (" %2.2d ", i);
2587 for (j = 1; j < elf_header.e_shnum; j++, section++)
2589 if (section->sh_size > 0
2590 /* Compare allocated sections by VMA, unallocated
2591 sections by file offset. */
2592 && (section->sh_flags & SHF_ALLOC
2593 ? (section->sh_addr >= segment->p_vaddr
2594 && section->sh_addr + section->sh_size
2595 <= segment->p_vaddr + segment->p_memsz)
2596 : ((bfd_vma) section->sh_offset >= segment->p_offset
2597 && (section->sh_offset + section->sh_size
2598 <= segment->p_offset + segment->p_filesz))))
2599 printf ("%s ", SECTION_NAME (section));
2606 free (program_headers);
2613 get_32bit_section_headers (file, num)
2617 Elf32_External_Shdr *shdrs;
2618 Elf_Internal_Shdr *internal;
2621 shdrs = ((Elf32_External_Shdr *)
2622 get_data (NULL, file, elf_header.e_shoff,
2623 elf_header.e_shentsize * num,
2624 _("section headers")));
2628 section_headers = ((Elf_Internal_Shdr *)
2629 malloc (num * sizeof (Elf_Internal_Shdr)));
2631 // printf("Just allocated section_headers at 0x%x, size = %d * %d\n",
2632 // section_headers, num, sizeof (Elf_Internal_Shdr)); //PG
2634 if (section_headers == NULL)
2636 error (_("Out of memory\n"));
2640 for (i = 0, internal = section_headers;
2644 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2645 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2646 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2647 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2648 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2649 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2650 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2651 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2652 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2653 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2662 get_64bit_section_headers (file, num)
2666 Elf64_External_Shdr *shdrs;
2667 Elf_Internal_Shdr *internal;
2670 shdrs = ((Elf64_External_Shdr *)
2671 get_data (NULL, file, elf_header.e_shoff,
2672 elf_header.e_shentsize * num,
2673 _("section headers")));
2677 section_headers = ((Elf_Internal_Shdr *)
2678 malloc (num * sizeof (Elf_Internal_Shdr)));
2680 if (section_headers == NULL)
2682 error (_("Out of memory\n"));
2686 for (i = 0, internal = section_headers;
2690 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2691 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2692 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2693 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2694 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2695 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2696 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2697 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2698 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2699 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2707 static Elf_Internal_Sym *
2708 get_32bit_elf_symbols (file, section)
2710 Elf_Internal_Shdr *section;
2712 unsigned long number;
2713 Elf32_External_Sym *esyms;
2714 Elf_External_Sym_Shndx *shndx;
2715 Elf_Internal_Sym *isyms;
2716 Elf_Internal_Sym *psym;
2719 esyms = ((Elf32_External_Sym *)
2720 get_data (NULL, file, section->sh_offset,
2721 section->sh_size, _("symbols")));
2726 if (symtab_shndx_hdr != NULL
2727 && (symtab_shndx_hdr->sh_link
2728 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
2730 shndx = ((Elf_External_Sym_Shndx *)
2731 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
2732 symtab_shndx_hdr->sh_size, _("symtab shndx")));
2740 number = section->sh_size / section->sh_entsize;
2741 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2745 error (_("Out of memory\n"));
2752 for (j = 0, psym = isyms;
2756 psym->st_name = BYTE_GET (esyms[j].st_name);
2757 psym->st_value = BYTE_GET (esyms[j].st_value);
2758 psym->st_size = BYTE_GET (esyms[j].st_size);
2759 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2760 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
2762 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
2763 psym->st_info = BYTE_GET (esyms[j].st_info);
2764 psym->st_other = BYTE_GET (esyms[j].st_other);
2774 static Elf_Internal_Sym *
2775 get_64bit_elf_symbols (file, section)
2777 Elf_Internal_Shdr *section;
2779 unsigned long number;
2780 Elf64_External_Sym *esyms;
2781 Elf_External_Sym_Shndx *shndx;
2782 Elf_Internal_Sym *isyms;
2783 Elf_Internal_Sym *psym;
2786 esyms = ((Elf64_External_Sym *)
2787 get_data (NULL, file, section->sh_offset,
2788 section->sh_size, _("symbols")));
2793 if (symtab_shndx_hdr != NULL
2794 && (symtab_shndx_hdr->sh_link
2795 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
2797 shndx = ((Elf_External_Sym_Shndx *)
2798 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
2799 symtab_shndx_hdr->sh_size, _("symtab shndx")));
2807 number = section->sh_size / section->sh_entsize;
2808 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2812 error (_("Out of memory\n"));
2819 for (j = 0, psym = isyms;
2823 psym->st_name = BYTE_GET (esyms[j].st_name);
2824 psym->st_info = BYTE_GET (esyms[j].st_info);
2825 psym->st_other = BYTE_GET (esyms[j].st_other);
2826 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2827 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
2829 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
2830 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2831 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2842 get_elf_section_flags (sh_flags)
2845 static char buff[32];
2853 flag = sh_flags & - sh_flags;
2858 case SHF_WRITE: strcat (buff, "W"); break;
2859 case SHF_ALLOC: strcat (buff, "A"); break;
2860 case SHF_EXECINSTR: strcat (buff, "X"); break;
2861 case SHF_MERGE: strcat (buff, "M"); break;
2862 case SHF_STRINGS: strcat (buff, "S"); break;
2863 case SHF_INFO_LINK: strcat (buff, "I"); break;
2864 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2865 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2866 case SHF_GROUP: strcat (buff, "G"); break;
2867 case SHF_TLS: strcat (buff, "T"); break;
2870 if (flag & SHF_MASKOS)
2873 sh_flags &= ~ SHF_MASKOS;
2875 else if (flag & SHF_MASKPROC)
2878 sh_flags &= ~ SHF_MASKPROC;
2890 process_section_headers (file)
2893 Elf_Internal_Shdr *section;
2896 section_headers = NULL;
2898 if (elf_header.e_shnum == 0)
2901 printf (_("\nThere are no sections in this file.\n"));
2906 if (do_sections && !do_header)
2907 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2908 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2912 if (! get_32bit_section_headers (file, elf_header.e_shnum))
2915 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
2918 /* Read in the string table, so that we have names to display. */
2919 section = SECTION_HEADER (elf_header.e_shstrndx);
2921 if (section->sh_size != 0)
2923 string_table = (char *) get_data (NULL, file, section->sh_offset,
2924 section->sh_size, _("string table"));
2926 string_table_length = section->sh_size;
2929 /* Scan the sections for the dynamic symbol table
2930 and dynamic string table and debug sections. */
2931 dynamic_symbols = NULL;
2932 dynamic_strings = NULL;
2933 dynamic_syminfo = NULL;
2934 symtab_shndx_hdr = NULL;
2936 for (i = 0, section = section_headers;
2937 i < elf_header.e_shnum;
2940 char *name = SECTION_NAME (section);
2942 if (section->sh_type == SHT_DYNSYM)
2944 if (dynamic_symbols != NULL)
2946 error (_("File contains multiple dynamic symbol tables\n"));
2950 num_dynamic_syms = section->sh_size / section->sh_entsize;
2951 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
2953 else if (section->sh_type == SHT_STRTAB
2954 && strcmp (name, ".dynstr") == 0)
2956 if (dynamic_strings != NULL)
2958 error (_("File contains multiple dynamic string tables\n"));
2962 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
2964 _("dynamic strings"));
2966 else if (section->sh_type == SHT_SYMTAB_SHNDX)
2968 if (symtab_shndx_hdr != NULL)
2970 error (_("File contains multiple symtab shndx tables\n"));
2973 symtab_shndx_hdr = section;
2975 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2976 || do_debug_lines || do_debug_pubnames || do_debug_aranges
2977 || do_debug_frames || do_debug_macinfo || do_debug_str
2979 && strncmp (name, ".debug_", 7) == 0)
2984 || (do_debug_info && (strcmp (name, "info") == 0))
2985 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2986 || (do_debug_lines && (strcmp (name, "line") == 0))
2987 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2988 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2989 || (do_debug_frames && (strcmp (name, "frame") == 0))
2990 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
2991 || (do_debug_str && (strcmp (name, "str") == 0))
2992 || (do_debug_loc && (strcmp (name, "loc") == 0))
2994 request_dump (i, DEBUG_DUMP);
2996 /* linkonce section to be combined with .debug_info at link time. */
2997 else if ((do_debugging || do_debug_info)
2998 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2999 request_dump (i, DEBUG_DUMP);
3000 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3001 request_dump (i, DEBUG_DUMP);
3007 if (elf_header.e_shnum > 1)
3008 printf (_("\nSection Headers:\n"));
3010 printf (_("\nSection Header:\n"));
3014 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3017 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3020 printf (_(" [Nr] Name Type Address Offset\n"));
3021 printf (_(" Size EntSize Flags Link Info Align\n"));
3024 for (i = 0, section = section_headers;
3025 i < elf_header.e_shnum;
3028 printf (" [%2u] %-17.17s %-15.15s ",
3029 SECTION_HEADER_NUM (i),
3030 SECTION_NAME (section),
3031 get_section_type_name (section->sh_type));
3035 print_vma (section->sh_addr, LONG_HEX);
3037 printf ( " %6.6lx %6.6lx %2.2lx",
3038 (unsigned long) section->sh_offset,
3039 (unsigned long) section->sh_size,
3040 (unsigned long) section->sh_entsize);
3042 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3044 printf ("%2ld %3lx %2ld\n",
3045 (unsigned long) section->sh_link,
3046 (unsigned long) section->sh_info,
3047 (unsigned long) section->sh_addralign);
3051 print_vma (section->sh_addr, LONG_HEX);
3053 if ((long) section->sh_offset == section->sh_offset)
3054 printf (" %6.6lx", (unsigned long) section->sh_offset);
3058 print_vma (section->sh_offset, LONG_HEX);
3061 if ((unsigned long) section->sh_size == section->sh_size)
3062 printf (" %6.6lx", (unsigned long) section->sh_size);
3066 print_vma (section->sh_size, LONG_HEX);
3069 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3070 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3074 print_vma (section->sh_entsize, LONG_HEX);
3077 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3079 printf ("%2ld %3lx ",
3080 (unsigned long) section->sh_link,
3081 (unsigned long) section->sh_info);
3083 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3084 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3087 print_vma (section->sh_addralign, DEC);
3094 print_vma (section->sh_addr, LONG_HEX);
3095 if ((long) section->sh_offset == section->sh_offset)
3096 printf (" %8.8lx", (unsigned long) section->sh_offset);
3100 print_vma (section->sh_offset, LONG_HEX);
3103 print_vma (section->sh_size, LONG_HEX);
3105 print_vma (section->sh_entsize, LONG_HEX);
3107 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3109 printf (" %2ld %3lx %ld\n",
3110 (unsigned long) section->sh_link,
3111 (unsigned long) section->sh_info,
3112 (unsigned long) section->sh_addralign);
3116 printf (_("Key to Flags:\n\
3117 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3118 I (info), L (link order), G (group), x (unknown)\n\
3119 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3130 } dynamic_relocations [] =
3132 { "REL", DT_REL, DT_RELSZ, FALSE },
3133 { "RELA", DT_RELA, DT_RELASZ, TRUE },
3134 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
3137 /* Process the reloc section. */
3139 process_relocs (file)
3142 unsigned long rel_size;
3143 unsigned long rel_offset;
3149 if (do_using_dynamic)
3153 int has_dynamic_reloc;
3156 has_dynamic_reloc = 0;
3158 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
3160 is_rela = dynamic_relocations [i].rela;
3161 name = dynamic_relocations [i].name;
3162 rel_size = dynamic_info [dynamic_relocations [i].size];
3163 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
3165 has_dynamic_reloc |= rel_size;
3167 if (is_rela == UNKNOWN)
3169 if (dynamic_relocations [i].reloc == DT_JMPREL)
3170 switch (dynamic_info[DT_PLTREL])
3184 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
3185 name, rel_offset, rel_size);
3187 dump_relocations (file, rel_offset - loadaddr, rel_size,
3188 dynamic_symbols, num_dynamic_syms,
3189 dynamic_strings, is_rela);
3193 if (! has_dynamic_reloc)
3194 printf (_("\nThere are no dynamic relocations in this file.\n"));
3198 Elf_Internal_Shdr *section;
3202 for (i = 0, section = section_headers;
3203 i < elf_header.e_shnum;
3206 if ( section->sh_type != SHT_RELA
3207 && section->sh_type != SHT_REL)
3210 rel_offset = section->sh_offset;
3211 rel_size = section->sh_size;
3215 Elf_Internal_Shdr *strsec;
3216 Elf_Internal_Sym *symtab;
3219 unsigned long nsyms;
3221 printf (_("\nRelocation section "));
3223 if (string_table == NULL)
3224 printf ("%d", section->sh_name);
3226 printf (_("'%s'"), SECTION_NAME (section));
3228 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3229 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3234 if (section->sh_link)
3236 Elf_Internal_Shdr *symsec;
3238 symsec = SECTION_HEADER (section->sh_link);
3239 nsyms = symsec->sh_size / symsec->sh_entsize;
3240 symtab = GET_ELF_SYMBOLS (file, symsec);
3245 strsec = SECTION_HEADER (symsec->sh_link);
3247 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3251 is_rela = section->sh_type == SHT_RELA;
3253 dump_relocations (file, rel_offset, rel_size,
3254 symtab, nsyms, strtab, is_rela);
3266 printf (_("\nThere are no relocations in this file.\n"));
3272 #include "unwind-ia64.h"
3274 /* An absolute address consists of a section and an offset. If the
3275 section is NULL, the offset itself is the address, otherwise, the
3276 address equals to LOAD_ADDRESS(section) + offset. */
3280 unsigned short section;
3286 struct unw_table_entry
3288 struct absaddr start;
3290 struct absaddr info;
3292 *table; /* Unwind table. */
3293 unsigned long table_len; /* Length of unwind table. */
3294 unsigned char *info; /* Unwind info. */
3295 unsigned long info_size; /* Size of unwind info. */
3296 bfd_vma info_addr; /* starting address of unwind info. */
3297 bfd_vma seg_base; /* Starting address of segment. */
3298 Elf_Internal_Sym *symtab; /* The symbol table. */
3299 unsigned long nsyms; /* Number of symbols. */
3300 char *strtab; /* The string table. */
3301 unsigned long strtab_size; /* Size of string table. */
3304 static void find_symbol_for_address
3305 PARAMS ((struct unw_aux_info *, struct absaddr, const char **, bfd_vma *));
3306 static void dump_ia64_unwind
3307 PARAMS ((struct unw_aux_info *));
3308 static int slurp_ia64_unwind_table
3309 PARAMS ((FILE *, struct unw_aux_info *, Elf_Internal_Shdr *));
3312 find_symbol_for_address (aux, addr, symname, offset)
3313 struct unw_aux_info *aux;
3314 struct absaddr addr;
3315 const char **symname;
3318 bfd_vma dist = (bfd_vma) 0x100000;
3319 Elf_Internal_Sym *sym, *best = NULL;
3322 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3324 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3325 && sym->st_name != 0
3326 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3327 && addr.offset >= sym->st_value
3328 && addr.offset - sym->st_value < dist)
3331 dist = addr.offset - sym->st_value;
3338 *symname = (best->st_name >= aux->strtab_size
3339 ? "<corrupt>" : aux->strtab + best->st_name);
3344 *offset = addr.offset;
3348 dump_ia64_unwind (aux)
3349 struct unw_aux_info *aux;
3352 struct unw_table_entry *tp;
3355 addr_size = is_32bit_elf ? 4 : 8;
3357 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3361 const unsigned char *dp;
3362 const unsigned char *head;
3363 const char *procname;
3365 find_symbol_for_address (aux, tp->start, &procname, &offset);
3367 fputs ("\n<", stdout);
3371 fputs (procname, stdout);
3374 printf ("+%lx", (unsigned long) offset);
3377 fputs (">: [", stdout);
3378 print_vma (tp->start.offset, PREFIX_HEX);
3379 fputc ('-', stdout);
3380 print_vma (tp->end.offset, PREFIX_HEX);
3381 printf ("], info at +0x%lx\n",
3382 (unsigned long) (tp->info.offset - aux->seg_base));
3384 head = aux->info + (tp->info.offset - aux->info_addr);
3385 stamp = BYTE_GET8 ((unsigned char *) head);
3387 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
3388 (unsigned) UNW_VER (stamp),
3389 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3390 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3391 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3392 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3394 if (UNW_VER (stamp) != 1)
3396 printf ("\tUnknown version.\n");
3401 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3402 dp = unw_decode (dp, in_body, & in_body);
3407 slurp_ia64_unwind_table (file, aux, sec)
3409 struct unw_aux_info *aux;
3410 Elf_Internal_Shdr *sec;
3412 unsigned long size, addr_size, nrelas, i;
3413 Elf_Internal_Phdr *prog_hdrs, *seg;
3414 struct unw_table_entry *tep;
3415 Elf_Internal_Shdr *relsec;
3416 Elf_Internal_Rela *rela, *rp;
3417 unsigned char *table, *tp;
3418 Elf_Internal_Sym *sym;
3419 const char *relname;
3422 addr_size = is_32bit_elf ? 4 : 8;
3424 /* First, find the starting address of the segment that includes
3427 if (elf_header.e_phnum)
3429 prog_hdrs = (Elf_Internal_Phdr *)
3430 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3433 result = get_32bit_program_headers (file, prog_hdrs);
3435 result = get_64bit_program_headers (file, prog_hdrs);
3443 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3445 if (seg->p_type != PT_LOAD)
3448 if (sec->sh_addr >= seg->p_vaddr
3449 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3451 aux->seg_base = seg->p_vaddr;
3459 /* Second, build the unwind table from the contents of the unwind section: */
3460 size = sec->sh_size;
3461 table = (char *) get_data (NULL, file, sec->sh_offset,
3462 size, _("unwind table"));
3466 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3467 for (tp = table; tp < table + size; tp += 3 * addr_size, ++tep)
3469 tep->start.section = SHN_UNDEF;
3470 tep->end.section = SHN_UNDEF;
3471 tep->info.section = SHN_UNDEF;
3474 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3475 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3476 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3480 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3481 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3482 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3484 tep->start.offset += aux->seg_base;
3485 tep->end.offset += aux->seg_base;
3486 tep->info.offset += aux->seg_base;
3490 /* Third, apply any relocations to the unwind table: */
3492 for (relsec = section_headers;
3493 relsec < section_headers + elf_header.e_shnum;
3496 if (relsec->sh_type != SHT_RELA
3497 || SECTION_HEADER (relsec->sh_info) != sec)
3500 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3504 for (rp = rela; rp < rela + nrelas; ++rp)
3508 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3509 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3511 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3513 warn (_("Skipping unexpected symbol type %u\n"),
3514 ELF32_ST_TYPE (sym->st_info));
3520 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3521 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3523 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3525 warn (_("Skipping unexpected symbol type %u\n"),
3526 ELF64_ST_TYPE (sym->st_info));
3531 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3533 warn (_("Skipping unexpected relocation type %s\n"), relname);
3537 i = rp->r_offset / (3 * addr_size);
3539 switch (rp->r_offset/addr_size % 3)
3542 aux->table[i].start.section = sym->st_shndx;
3543 aux->table[i].start.offset += rp->r_addend;
3546 aux->table[i].end.section = sym->st_shndx;
3547 aux->table[i].end.offset += rp->r_addend;
3550 aux->table[i].info.section = sym->st_shndx;
3551 aux->table[i].info.offset += rp->r_addend;
3561 aux->table_len = size / (3 * addr_size);
3566 process_unwind (file)
3569 Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3570 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3571 struct unw_aux_info aux;
3576 if (elf_header.e_machine != EM_IA_64)
3578 printf (_("\nThere are no unwind sections in this file.\n"));
3582 memset (& aux, 0, sizeof (aux));
3584 addr_size = is_32bit_elf ? 4 : 8;
3586 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3588 if (sec->sh_type == SHT_SYMTAB)
3590 aux.nsyms = sec->sh_size / sec->sh_entsize;
3591 aux.symtab = GET_ELF_SYMBOLS (file, sec);
3593 strsec = SECTION_HEADER (sec->sh_link);
3594 aux.strtab_size = strsec->sh_size;
3595 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3596 aux.strtab_size, _("string table"));
3598 else if (sec->sh_type == SHT_IA_64_UNWIND)
3603 printf (_("\nThere are no unwind sections in this file.\n"));
3605 while (unwcount-- > 0)
3610 for (i = unwstart, sec = section_headers + unwstart;
3611 i < elf_header.e_shnum; ++i, ++sec)
3612 if (sec->sh_type == SHT_IA_64_UNWIND)
3619 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3621 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3624 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3625 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3626 suffix = SECTION_NAME (unwsec) + len;
3627 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3629 if (strncmp (SECTION_NAME (sec),
3630 ELF_STRING_ia64_unwind_info_once, len2) == 0
3631 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3636 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3637 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3638 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3639 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3641 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3643 suffix = SECTION_NAME (unwsec) + len;
3644 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3646 if (strncmp (SECTION_NAME (sec),
3647 ELF_STRING_ia64_unwind_info, len2) == 0
3648 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3652 if (i == elf_header.e_shnum)
3654 printf (_("\nCould not find unwind info section for "));
3656 if (string_table == NULL)
3657 printf ("%d", unwsec->sh_name);
3659 printf (_("'%s'"), SECTION_NAME (unwsec));
3663 aux.info_size = sec->sh_size;
3664 aux.info_addr = sec->sh_addr;
3665 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3666 aux.info_size, _("unwind info"));
3668 printf (_("\nUnwind section "));
3670 if (string_table == NULL)
3671 printf ("%d", unwsec->sh_name);
3673 printf (_("'%s'"), SECTION_NAME (unwsec));
3675 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3676 (unsigned long) unwsec->sh_offset,
3677 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3679 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3681 if (aux.table_len > 0)
3682 dump_ia64_unwind (& aux);
3685 free ((char *) aux.table);
3687 free ((char *) aux.info);
3696 free ((char *) aux.strtab);
3702 dynamic_segment_mips_val (entry)
3703 Elf_Internal_Dyn *entry;
3705 switch (entry->d_tag)
3708 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3714 dynamic_segment_parisc_val (entry)
3715 Elf_Internal_Dyn *entry;
3717 switch (entry->d_tag)
3720 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3727 dynamic_segment_ia64_val (entry)
3728 Elf_Internal_Dyn *entry;
3733 get_32bit_dynamic_segment (file)
3736 Elf32_External_Dyn *edyn;
3737 Elf_Internal_Dyn *entry;
3740 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
3741 dynamic_size, _("dynamic segment"));
3745 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3746 how large this .dynamic is now. We can do this even before the byte
3747 swapping since the DT_NULL tag is recognizable. */
3749 while (*(Elf32_Word *) edyn[dynamic_size++].d_tag != DT_NULL)
3752 dynamic_segment = (Elf_Internal_Dyn *)
3753 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3755 if (dynamic_segment == NULL)
3757 error (_("Out of memory\n"));
3762 for (i = 0, entry = dynamic_segment;
3766 entry->d_tag = BYTE_GET (edyn[i].d_tag);
3767 entry->d_un.d_val = BYTE_GET (edyn[i].d_un.d_val);
3776 get_64bit_dynamic_segment (file)
3779 Elf64_External_Dyn *edyn;
3780 Elf_Internal_Dyn *entry;
3783 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
3784 dynamic_size, _("dynamic segment"));
3788 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3789 how large this .dynamic is now. We can do this even before the byte
3790 swapping since the DT_NULL tag is recognizable. */
3792 while (*(bfd_vma *) edyn[dynamic_size++].d_tag != DT_NULL)
3795 dynamic_segment = (Elf_Internal_Dyn *)
3796 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3798 if (dynamic_segment == NULL)
3800 error (_("Out of memory\n"));
3805 for (i = 0, entry = dynamic_segment;
3809 entry->d_tag = BYTE_GET8 (edyn[i].d_tag);
3810 entry->d_un.d_val = BYTE_GET8 (edyn[i].d_un.d_val);
3819 get_dynamic_flags (flags)
3822 static char buff[128];
3830 flag = flags & - flags;
3838 case DF_ORIGIN: strcpy (p, "ORIGIN"); break;
3839 case DF_SYMBOLIC: strcpy (p, "SYMBOLIC"); break;
3840 case DF_TEXTREL: strcpy (p, "TEXTREL"); break;
3841 case DF_BIND_NOW: strcpy (p, "BIND_NOW"); break;
3842 case DF_STATIC_TLS: strcpy (p, "STATIC_TLS"); break;
3843 default: strcpy (p, "unknown"); break;
3846 p = strchr (p, '\0');
3851 /* Parse and display the contents of the dynamic segment. */
3853 process_dynamic_segment (file)
3856 Elf_Internal_Dyn *entry;
3859 if (dynamic_size == 0)
3862 printf (_("\nThere is no dynamic segment in this file.\n"));
3869 if (! get_32bit_dynamic_segment (file))
3872 else if (! get_64bit_dynamic_segment (file))
3875 /* Find the appropriate symbol table. */
3876 if (dynamic_symbols == NULL)
3878 for (i = 0, entry = dynamic_segment;
3882 Elf_Internal_Shdr section;
3884 if (entry->d_tag != DT_SYMTAB)
3887 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3889 /* Since we do not know how big the symbol table is,
3890 we default to reading in the entire file (!) and
3891 processing that. This is overkill, I know, but it
3893 section.sh_offset = entry->d_un.d_val - loadaddr;
3895 if (fseek (file, 0, SEEK_END))
3896 error (_("Unable to seek to end of file!"));
3898 section.sh_size = ftell (file) - section.sh_offset;
3900 section.sh_entsize = sizeof (Elf32_External_Sym);
3902 section.sh_entsize = sizeof (Elf64_External_Sym);
3904 num_dynamic_syms = section.sh_size / section.sh_entsize;
3905 if (num_dynamic_syms < 1)
3907 error (_("Unable to determine the number of symbols to load\n"));
3911 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
3915 /* Similarly find a string table. */
3916 if (dynamic_strings == NULL)
3918 for (i = 0, entry = dynamic_segment;
3922 unsigned long offset;
3925 if (entry->d_tag != DT_STRTAB)
3928 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3930 /* Since we do not know how big the string table is,
3931 we default to reading in the entire file (!) and
3932 processing that. This is overkill, I know, but it
3935 offset = entry->d_un.d_val - loadaddr;
3936 if (fseek (file, 0, SEEK_END))
3937 error (_("Unable to seek to end of file\n"));
3938 str_tab_len = ftell (file) - offset;
3940 if (str_tab_len < 1)
3943 (_("Unable to determine the length of the dynamic string table\n"));
3947 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
3948 _("dynamic string table"));
3953 /* And find the syminfo section if available. */
3954 if (dynamic_syminfo == NULL)
3956 unsigned long syminsz = 0;
3958 for (i = 0, entry = dynamic_segment;
3962 if (entry->d_tag == DT_SYMINENT)
3964 /* Note: these braces are necessary to avoid a syntax
3965 error from the SunOS4 C compiler. */
3966 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3968 else if (entry->d_tag == DT_SYMINSZ)
3969 syminsz = entry->d_un.d_val;
3970 else if (entry->d_tag == DT_SYMINFO)
3971 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3974 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3976 Elf_External_Syminfo *extsyminfo;
3977 Elf_Internal_Syminfo *syminfo;
3979 /* There is a syminfo section. Read the data. */
3980 extsyminfo = ((Elf_External_Syminfo *)
3981 get_data (NULL, file, dynamic_syminfo_offset,
3982 syminsz, _("symbol information")));
3986 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3987 if (dynamic_syminfo == NULL)
3989 error (_("Out of memory\n"));
3993 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3994 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3997 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3998 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4005 if (do_dynamic && dynamic_addr)
4006 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4007 dynamic_addr, (long) dynamic_size);
4009 printf (_(" Tag Type Name/Value\n"));
4011 for (i = 0, entry = dynamic_segment;
4020 print_vma (entry->d_tag, FULL_HEX);
4021 dtype = get_dynamic_type (entry->d_tag);
4022 printf (" (%s)%*s", dtype,
4023 ((is_32bit_elf ? 27 : 19)
4024 - (int) strlen (dtype)),
4028 switch (entry->d_tag)
4032 puts (get_dynamic_flags (entry->d_un.d_val));
4042 switch (entry->d_tag)
4045 printf (_("Auxiliary library"));
4049 printf (_("Filter library"));
4053 printf (_("Configuration file"));
4057 printf (_("Dependency audit library"));
4061 printf (_("Audit library"));
4065 if (dynamic_strings)
4066 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4070 print_vma (entry->d_un.d_val, PREFIX_HEX);
4079 printf (_("Flags:"));
4081 if (entry->d_un.d_val == 0)
4082 printf (_(" None\n"));
4085 unsigned long int val = entry->d_un.d_val;
4087 if (val & DTF_1_PARINIT)
4089 printf (" PARINIT");
4090 val ^= DTF_1_PARINIT;
4092 if (val & DTF_1_CONFEXP)
4094 printf (" CONFEXP");
4095 val ^= DTF_1_CONFEXP;
4098 printf (" %lx", val);
4107 printf (_("Flags:"));
4109 if (entry->d_un.d_val == 0)
4110 printf (_(" None\n"));
4113 unsigned long int val = entry->d_un.d_val;
4115 if (val & DF_P1_LAZYLOAD)
4117 printf (" LAZYLOAD");
4118 val ^= DF_P1_LAZYLOAD;
4120 if (val & DF_P1_GROUPPERM)
4122 printf (" GROUPPERM");
4123 val ^= DF_P1_GROUPPERM;
4126 printf (" %lx", val);
4135 printf (_("Flags:"));
4136 if (entry->d_un.d_val == 0)
4137 printf (_(" None\n"));
4140 unsigned long int val = entry->d_un.d_val;
4147 if (val & DF_1_GLOBAL)
4152 if (val & DF_1_GROUP)
4157 if (val & DF_1_NODELETE)
4159 printf (" NODELETE");
4160 val ^= DF_1_NODELETE;
4162 if (val & DF_1_LOADFLTR)
4164 printf (" LOADFLTR");
4165 val ^= DF_1_LOADFLTR;
4167 if (val & DF_1_INITFIRST)
4169 printf (" INITFIRST");
4170 val ^= DF_1_INITFIRST;
4172 if (val & DF_1_NOOPEN)
4177 if (val & DF_1_ORIGIN)
4182 if (val & DF_1_DIRECT)
4187 if (val & DF_1_TRANS)
4192 if (val & DF_1_INTERPOSE)
4194 printf (" INTERPOSE");
4195 val ^= DF_1_INTERPOSE;
4197 if (val & DF_1_NODEFLIB)
4199 printf (" NODEFLIB");
4200 val ^= DF_1_NODEFLIB;
4202 if (val & DF_1_NODUMP)
4207 if (val & DF_1_CONLFAT)
4209 printf (" CONLFAT");
4210 val ^= DF_1_CONLFAT;
4213 printf (" %lx", val);
4220 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4222 puts (get_dynamic_type (entry->d_un.d_val));
4242 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4248 if (dynamic_strings == NULL)
4251 name = dynamic_strings + entry->d_un.d_val;
4255 switch (entry->d_tag)
4258 printf (_("Shared library: [%s]"), name);
4260 if (strcmp (name, program_interpreter) == 0)
4261 printf (_(" program interpreter"));
4265 printf (_("Library soname: [%s]"), name);
4269 printf (_("Library rpath: [%s]"), name);
4273 printf (_("Library runpath: [%s]"), name);
4277 print_vma (entry->d_un.d_val, PREFIX_HEX);
4282 print_vma (entry->d_un.d_val, PREFIX_HEX);
4295 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4299 case DT_INIT_ARRAYSZ:
4300 case DT_FINI_ARRAYSZ:
4301 case DT_GNU_CONFLICTSZ:
4302 case DT_GNU_LIBLISTSZ:
4305 print_vma (entry->d_un.d_val, UNSIGNED);
4306 printf (" (bytes)\n");
4316 print_vma (entry->d_un.d_val, UNSIGNED);
4329 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4333 name = dynamic_strings + entry->d_un.d_val;
4337 printf (_("Not needed object: [%s]\n"), name);
4342 print_vma (entry->d_un.d_val, PREFIX_HEX);
4348 /* The value of this entry is ignored. */
4353 case DT_GNU_PRELINKED:
4357 time_t the_time = entry->d_un.d_val;
4359 tmp = gmtime (&the_time);
4360 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
4361 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
4362 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4368 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4369 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
4374 switch (elf_header.e_machine)
4377 case EM_MIPS_RS3_LE:
4378 dynamic_segment_mips_val (entry);
4381 dynamic_segment_parisc_val (entry);
4384 dynamic_segment_ia64_val (entry);
4387 print_vma (entry->d_un.d_val, PREFIX_HEX);
4399 get_ver_flags (flags)
4402 static char buff[32];
4409 if (flags & VER_FLG_BASE)
4410 strcat (buff, "BASE ");
4412 if (flags & VER_FLG_WEAK)
4414 if (flags & VER_FLG_BASE)
4415 strcat (buff, "| ");
4417 strcat (buff, "WEAK ");
4420 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4421 strcat (buff, "| <unknown>");
4426 /* Display the contents of the version sections. */
4428 process_version_sections (file)
4431 Elf_Internal_Shdr *section;
4438 for (i = 0, section = section_headers;
4439 i < elf_header.e_shnum;
4442 switch (section->sh_type)
4444 case SHT_GNU_verdef:
4446 Elf_External_Verdef *edefs;
4453 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4454 SECTION_NAME (section), section->sh_info);
4456 printf (_(" Addr: 0x"));
4457 printf_vma (section->sh_addr);
4458 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4459 (unsigned long) section->sh_offset, section->sh_link,
4460 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4462 edefs = ((Elf_External_Verdef *)
4463 get_data (NULL, file, section->sh_offset,
4465 _("version definition section")));
4469 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4472 Elf_External_Verdef *edef;
4473 Elf_Internal_Verdef ent;
4474 Elf_External_Verdaux *eaux;
4475 Elf_Internal_Verdaux aux;
4479 vstart = ((char *) edefs) + idx;
4481 edef = (Elf_External_Verdef *) vstart;
4483 ent.vd_version = BYTE_GET (edef->vd_version);
4484 ent.vd_flags = BYTE_GET (edef->vd_flags);
4485 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4486 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4487 ent.vd_hash = BYTE_GET (edef->vd_hash);
4488 ent.vd_aux = BYTE_GET (edef->vd_aux);
4489 ent.vd_next = BYTE_GET (edef->vd_next);
4491 printf (_(" %#06x: Rev: %d Flags: %s"),
4492 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4494 printf (_(" Index: %d Cnt: %d "),
4495 ent.vd_ndx, ent.vd_cnt);
4497 vstart += ent.vd_aux;
4499 eaux = (Elf_External_Verdaux *) vstart;
4501 aux.vda_name = BYTE_GET (eaux->vda_name);
4502 aux.vda_next = BYTE_GET (eaux->vda_next);
4504 if (dynamic_strings)
4505 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4507 printf (_("Name index: %ld\n"), aux.vda_name);
4509 isum = idx + ent.vd_aux;
4511 for (j = 1; j < ent.vd_cnt; j++)
4513 isum += aux.vda_next;
4514 vstart += aux.vda_next;
4516 eaux = (Elf_External_Verdaux *) vstart;
4518 aux.vda_name = BYTE_GET (eaux->vda_name);
4519 aux.vda_next = BYTE_GET (eaux->vda_next);
4521 if (dynamic_strings)
4522 printf (_(" %#06x: Parent %d: %s\n"),
4523 isum, j, dynamic_strings + aux.vda_name);
4525 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4526 isum, j, aux.vda_name);
4536 case SHT_GNU_verneed:
4538 Elf_External_Verneed *eneed;
4544 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4545 SECTION_NAME (section), section->sh_info);
4547 printf (_(" Addr: 0x"));
4548 printf_vma (section->sh_addr);
4549 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4550 (unsigned long) section->sh_offset, section->sh_link,
4551 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4553 eneed = ((Elf_External_Verneed *)
4554 get_data (NULL, file, section->sh_offset,
4555 section->sh_size, _("version need section")));
4559 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4561 Elf_External_Verneed *entry;
4562 Elf_Internal_Verneed ent;
4567 vstart = ((char *) eneed) + idx;
4569 entry = (Elf_External_Verneed *) vstart;
4571 ent.vn_version = BYTE_GET (entry->vn_version);
4572 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4573 ent.vn_file = BYTE_GET (entry->vn_file);
4574 ent.vn_aux = BYTE_GET (entry->vn_aux);
4575 ent.vn_next = BYTE_GET (entry->vn_next);
4577 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4579 if (dynamic_strings)
4580 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4582 printf (_(" File: %lx"), ent.vn_file);
4584 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4586 vstart += ent.vn_aux;
4588 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4590 Elf_External_Vernaux *eaux;
4591 Elf_Internal_Vernaux aux;
4593 eaux = (Elf_External_Vernaux *) vstart;
4595 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4596 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4597 aux.vna_other = BYTE_GET (eaux->vna_other);
4598 aux.vna_name = BYTE_GET (eaux->vna_name);
4599 aux.vna_next = BYTE_GET (eaux->vna_next);
4601 if (dynamic_strings)
4602 printf (_(" %#06x: Name: %s"),
4603 isum, dynamic_strings + aux.vna_name);
4605 printf (_(" %#06x: Name index: %lx"),
4606 isum, aux.vna_name);
4608 printf (_(" Flags: %s Version: %d\n"),
4609 get_ver_flags (aux.vna_flags), aux.vna_other);
4611 isum += aux.vna_next;
4612 vstart += aux.vna_next;
4622 case SHT_GNU_versym:
4624 Elf_Internal_Shdr *link_section;
4627 unsigned char *edata;
4628 unsigned short *data;
4630 Elf_Internal_Sym *symbols;
4631 Elf_Internal_Shdr *string_sec;
4633 link_section = SECTION_HEADER (section->sh_link);
4634 total = section->sh_size / section->sh_entsize;
4638 symbols = GET_ELF_SYMBOLS (file, link_section);
4640 string_sec = SECTION_HEADER (link_section->sh_link);
4642 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4643 string_sec->sh_size,
4644 _("version string table"));
4648 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4649 SECTION_NAME (section), total);
4651 printf (_(" Addr: "));
4652 printf_vma (section->sh_addr);
4653 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4654 (unsigned long) section->sh_offset, section->sh_link,
4655 SECTION_NAME (link_section));
4659 get_data (NULL, file,
4660 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4661 total * sizeof (short), _("version symbol data")));
4668 data = (unsigned short *) malloc (total * sizeof (short));
4670 for (cnt = total; cnt --;)
4671 data[cnt] = byte_get (edata + cnt * sizeof (short),
4676 for (cnt = 0; cnt < total; cnt += 4)
4679 int check_def, check_need;
4682 printf (" %03x:", cnt);
4684 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4685 switch (data[cnt + j])
4688 fputs (_(" 0 (*local*) "), stdout);
4692 fputs (_(" 1 (*global*) "), stdout);
4696 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
4697 data[cnt + j] & 0x8000 ? 'h' : ' ');
4701 if (SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
4704 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
4711 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
4713 Elf_Internal_Verneed ivn;
4714 unsigned long offset;
4716 offset = version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
4721 Elf_Internal_Vernaux ivna;
4722 Elf_External_Verneed evn;
4723 Elf_External_Vernaux evna;
4724 unsigned long a_off;
4726 get_data (&evn, file, offset, sizeof (evn),
4729 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4730 ivn.vn_next = BYTE_GET (evn.vn_next);
4732 a_off = offset + ivn.vn_aux;
4736 get_data (&evna, file, a_off, sizeof (evna),
4737 _("version need aux (2)"));
4739 ivna.vna_next = BYTE_GET (evna.vna_next);
4740 ivna.vna_other = BYTE_GET (evna.vna_other);
4742 a_off += ivna.vna_next;
4744 while (ivna.vna_other != data[cnt + j]
4745 && ivna.vna_next != 0);
4747 if (ivna.vna_other == data[cnt + j])
4749 ivna.vna_name = BYTE_GET (evna.vna_name);
4751 name = strtab + ivna.vna_name;
4752 nn += printf ("(%s%-*s",
4754 12 - (int) strlen (name),
4760 offset += ivn.vn_next;
4762 while (ivn.vn_next);
4765 if (check_def && data[cnt + j] != 0x8001
4766 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
4768 Elf_Internal_Verdef ivd;
4769 Elf_External_Verdef evd;
4770 unsigned long offset;
4772 offset = (version_info[DT_VERSIONTAGIDX (DT_VERDEF)]
4777 get_data (&evd, file, offset, sizeof (evd),
4780 ivd.vd_next = BYTE_GET (evd.vd_next);
4781 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4783 offset += ivd.vd_next;
4785 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
4786 && ivd.vd_next != 0);
4788 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
4790 Elf_External_Verdaux evda;
4791 Elf_Internal_Verdaux ivda;
4793 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4795 get_data (&evda, file,
4796 offset - ivd.vd_next + ivd.vd_aux,
4797 sizeof (evda), _("version def aux"));
4799 ivda.vda_name = BYTE_GET (evda.vda_name);
4801 name = strtab + ivda.vda_name;
4802 nn += printf ("(%s%-*s",
4804 12 - (int) strlen (name),
4810 printf ("%*c", 18 - nn, ' ');
4828 printf (_("\nNo version information found in this file.\n"));
4834 get_symbol_binding (binding)
4835 unsigned int binding;
4837 static char buff[32];
4841 case STB_LOCAL: return "LOCAL";
4842 case STB_GLOBAL: return "GLOBAL";
4843 case STB_WEAK: return "WEAK";
4845 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4846 sprintf (buff, _("<processor specific>: %d"), binding);
4847 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4848 sprintf (buff, _("<OS specific>: %d"), binding);
4850 sprintf (buff, _("<unknown>: %d"), binding);
4856 get_symbol_type (type)
4859 static char buff[32];
4863 case STT_NOTYPE: return "NOTYPE";
4864 case STT_OBJECT: return "OBJECT";
4865 case STT_FUNC: return "FUNC";
4866 case STT_SECTION: return "SECTION";
4867 case STT_FILE: return "FILE";
4868 case STT_COMMON: return "COMMON";
4869 case STT_TLS: return "TLS";
4871 if (type >= STT_LOPROC && type <= STT_HIPROC)
4873 sprintf (buff, _("<processor specific>: %d"), type);
4875 else if (type >= STT_LOOS && type <= STT_HIOS)
4877 sprintf (buff, _("<OS specific>: %d"), type);
4880 sprintf (buff, _("<unknown>: %d"), type);
4886 get_symbol_visibility (visibility)
4887 unsigned int visibility;
4891 case STV_DEFAULT: return "DEFAULT";
4892 case STV_INTERNAL: return "INTERNAL";
4893 case STV_HIDDEN: return "HIDDEN";
4894 case STV_PROTECTED: return "PROTECTED";
4900 get_symbol_index_type (type)
4903 static char buff[32];
4907 case SHN_UNDEF: return "UND";
4908 case SHN_ABS: return "ABS";
4909 case SHN_COMMON: return "COM";
4911 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4912 sprintf (buff, "PRC[0x%04x]", type);
4913 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4914 sprintf (buff, "OS [0x%04x]", type);
4915 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4916 sprintf (buff, "RSV[0x%04x]", type);
4918 sprintf (buff, "%3d", type);
4926 get_dynamic_data (file, number)
4928 unsigned int number;
4930 unsigned char *e_data;
4933 e_data = (unsigned char *) malloc (number * 4);
4937 error (_("Out of memory\n"));
4941 if (fread (e_data, 4, number, file) != number)
4943 error (_("Unable to read in dynamic data\n"));
4947 i_data = (int *) malloc (number * sizeof (*i_data));
4951 error (_("Out of memory\n"));
4957 i_data[number] = byte_get (e_data + number * 4, 4);
4964 /* Dump the symbol table. */
4966 process_symbol_table (file)
4969 Elf_Internal_Shdr *section;
4970 unsigned char nb[4];
4971 unsigned char nc[4];
4974 int *buckets = NULL;
4977 if (! do_syms && !do_histogram)
4980 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4983 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4985 error (_("Unable to seek to start of dynamic information"));
4989 if (fread (nb, sizeof (nb), 1, file) != 1)
4991 error (_("Failed to read in number of buckets\n"));
4995 if (fread (nc, sizeof (nc), 1, file) != 1)
4997 error (_("Failed to read in number of chains\n"));
5001 nbuckets = byte_get (nb, 4);
5002 nchains = byte_get (nc, 4);
5004 buckets = get_dynamic_data (file, nbuckets);
5005 chains = get_dynamic_data (file, nchains);
5007 if (buckets == NULL || chains == NULL)
5012 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5017 printf (_("\nSymbol table for image:\n"));
5019 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5021 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5023 for (hn = 0; hn < nbuckets; hn++)
5028 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
5030 Elf_Internal_Sym *psym;
5032 psym = dynamic_symbols + si;
5034 printf (" %3d %3d: ", si, hn);
5035 print_vma (psym->st_value, LONG_HEX);
5037 print_vma (psym->st_size, DEC_5);
5039 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5040 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5041 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5042 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
5043 print_symbol (25, dynamic_strings + psym->st_name);
5048 else if (do_syms && !do_using_dynamic)
5052 for (i = 0, section = section_headers;
5053 i < elf_header.e_shnum;
5058 Elf_Internal_Sym *symtab;
5059 Elf_Internal_Sym *psym;
5062 if ( section->sh_type != SHT_SYMTAB
5063 && section->sh_type != SHT_DYNSYM)
5066 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5067 SECTION_NAME (section),
5068 (unsigned long) (section->sh_size / section->sh_entsize));
5070 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5072 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5074 symtab = GET_ELF_SYMBOLS (file, section);
5078 if (section->sh_link == elf_header.e_shstrndx)
5079 strtab = string_table;
5082 Elf_Internal_Shdr *string_sec;
5084 string_sec = SECTION_HEADER (section->sh_link);
5086 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5087 string_sec->sh_size,
5091 for (si = 0, psym = symtab;
5092 si < section->sh_size / section->sh_entsize;
5095 printf ("%6d: ", si);
5096 print_vma (psym->st_value, LONG_HEX);
5098 print_vma (psym->st_size, DEC_5);
5099 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5100 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5101 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5102 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
5103 print_symbol (25, strtab + psym->st_name);
5105 if (section->sh_type == SHT_DYNSYM &&
5106 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5108 unsigned char data[2];
5109 unsigned short vers_data;
5110 unsigned long offset;
5114 offset = version_info[DT_VERSIONTAGIDX (DT_VERSYM)]
5117 get_data (&data, file, offset + si * sizeof (vers_data),
5118 sizeof (data), _("version data"));
5120 vers_data = byte_get (data, 2);
5122 is_nobits = (SECTION_HEADER (psym->st_shndx)->sh_type
5125 check_def = (psym->st_shndx != SHN_UNDEF);
5127 if ((vers_data & 0x8000) || vers_data > 1)
5129 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
5130 && (is_nobits || ! check_def))
5132 Elf_External_Verneed evn;
5133 Elf_Internal_Verneed ivn;
5134 Elf_Internal_Vernaux ivna;
5136 /* We must test both. */
5137 offset = (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
5142 unsigned long vna_off;
5144 get_data (&evn, file, offset, sizeof (evn),
5147 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5148 ivn.vn_next = BYTE_GET (evn.vn_next);
5150 vna_off = offset + ivn.vn_aux;
5154 Elf_External_Vernaux evna;
5156 get_data (&evna, file, vna_off,
5158 _("version need aux (3)"));
5160 ivna.vna_other = BYTE_GET (evna.vna_other);
5161 ivna.vna_next = BYTE_GET (evna.vna_next);
5162 ivna.vna_name = BYTE_GET (evna.vna_name);
5164 vna_off += ivna.vna_next;
5166 while (ivna.vna_other != vers_data
5167 && ivna.vna_next != 0);
5169 if (ivna.vna_other == vers_data)
5172 offset += ivn.vn_next;
5174 while (ivn.vn_next != 0);
5176 if (ivna.vna_other == vers_data)
5179 strtab + ivna.vna_name, ivna.vna_other);
5182 else if (! is_nobits)
5183 error (_("bad dynamic symbol"));
5190 if (vers_data != 0x8001
5191 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
5193 Elf_Internal_Verdef ivd;
5194 Elf_Internal_Verdaux ivda;
5195 Elf_External_Verdaux evda;
5199 = (version_info[DT_VERSIONTAGIDX (DT_VERDEF)]
5204 Elf_External_Verdef evd;
5206 get_data (&evd, file, off, sizeof (evd),
5209 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5210 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5211 ivd.vd_next = BYTE_GET (evd.vd_next);
5215 while (ivd.vd_ndx != (vers_data & 0x7fff)
5216 && ivd.vd_next != 0);
5221 get_data (&evda, file, off, sizeof (evda),
5222 _("version def aux"));
5224 ivda.vda_name = BYTE_GET (evda.vda_name);
5226 if (psym->st_name != ivda.vda_name)
5227 printf ((vers_data & 0x8000)
5229 strtab + ivda.vda_name);
5239 if (strtab != string_table)
5245 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5247 if (do_histogram && buckets != NULL)
5254 int nzero_counts = 0;
5257 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5259 printf (_(" Length Number %% of total Coverage\n"));
5261 lengths = (int *) calloc (nbuckets, sizeof (int));
5262 if (lengths == NULL)
5264 error (_("Out of memory"));
5267 for (hn = 0; hn < nbuckets; ++hn)
5272 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5275 if (maxlength < ++lengths[hn])
5280 counts = (int *) calloc (maxlength + 1, sizeof (int));
5283 error (_("Out of memory"));
5287 for (hn = 0; hn < nbuckets; ++hn)
5288 ++counts[lengths[hn]];
5292 printf (" 0 %-10d (%5.1f%%)\n",
5293 counts[0], (counts[0] * 100.0) / nbuckets);
5294 for (si = 1; si <= maxlength; ++si)
5296 nzero_counts += counts[si] * si;
5297 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5298 si, counts[si], (counts[si] * 100.0) / nbuckets,
5299 (nzero_counts * 100.0) / nsyms);
5307 if (buckets != NULL)
5317 process_syminfo (file)
5318 FILE *file ATTRIBUTE_UNUSED;
5322 if (dynamic_syminfo == NULL
5324 /* No syminfo, this is ok. */
5327 /* There better should be a dynamic symbol section. */
5328 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5332 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5333 dynamic_syminfo_offset, dynamic_syminfo_nent);
5335 printf (_(" Num: Name BoundTo Flags\n"));
5336 for (i = 0; i < dynamic_syminfo_nent; ++i)
5338 unsigned short int flags = dynamic_syminfo[i].si_flags;
5340 printf ("%4d: ", i);
5341 print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
5344 switch (dynamic_syminfo[i].si_boundto)
5346 case SYMINFO_BT_SELF:
5347 fputs ("SELF ", stdout);
5349 case SYMINFO_BT_PARENT:
5350 fputs ("PARENT ", stdout);
5353 if (dynamic_syminfo[i].si_boundto > 0
5354 && dynamic_syminfo[i].si_boundto < dynamic_size)
5359 [dynamic_syminfo[i].si_boundto].d_un.d_val));
5363 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5367 if (flags & SYMINFO_FLG_DIRECT)
5369 if (flags & SYMINFO_FLG_PASSTHRU)
5370 printf (" PASSTHRU");
5371 if (flags & SYMINFO_FLG_COPY)
5373 if (flags & SYMINFO_FLG_LAZYLOAD)
5374 printf (" LAZYLOAD");
5382 #ifdef SUPPORT_DISASSEMBLY
5384 disassemble_section (section, file)
5385 Elf_Internal_Shdr *section;
5388 printf (_("\nAssembly dump of section %s\n"),
5389 SECTION_NAME (section));
5391 /* XXX -- to be done --- XXX */
5398 dump_section (section, file)
5399 Elf_Internal_Shdr *section;
5402 bfd_size_type bytes;
5404 unsigned char *data;
5405 unsigned char *start;
5407 bytes = section->sh_size;
5411 printf (_("\nSection '%s' has no data to dump.\n"),
5412 SECTION_NAME (section));
5416 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5418 addr = section->sh_addr;
5420 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5433 lbytes = (bytes > 16 ? 16 : bytes);
5435 printf (" 0x%8.8lx ", (unsigned long) addr);
5437 switch (elf_header.e_ident[EI_DATA])
5441 for (j = 15; j >= 0; j --)
5444 printf ("%2.2x", data[j]);
5454 for (j = 0; j < 16; j++)
5457 printf ("%2.2x", data[j]);
5467 for (j = 0; j < lbytes; j++)
5470 if (k >= ' ' && k < 0x80)
5489 static unsigned long int
5490 read_leb128 (data, length_return, sign)
5491 unsigned char *data;
5495 unsigned long int result = 0;
5496 unsigned int num_read = 0;
5505 result |= (byte & 0x7f) << shift;
5510 while (byte & 0x80);
5512 if (length_return != NULL)
5513 *length_return = num_read;
5515 if (sign && (shift < 32) && (byte & 0x40))
5516 result |= -1 << shift;
5521 typedef struct State_Machine_Registers
5523 unsigned long address;
5526 unsigned int column;
5530 /* This variable hold the number of the last entry seen
5531 in the File Table. */
5532 unsigned int last_file_entry;
5535 static SMR state_machine_regs;
5538 reset_state_machine (is_stmt)
5541 state_machine_regs.address = 0;
5542 state_machine_regs.file = 1;
5543 state_machine_regs.line = 1;
5544 state_machine_regs.column = 0;
5545 state_machine_regs.is_stmt = is_stmt;
5546 state_machine_regs.basic_block = 0;
5547 state_machine_regs.end_sequence = 0;
5548 state_machine_regs.last_file_entry = 0;
5551 /* Handled an extend line op. Returns true if this is the end
5554 process_extended_line_op (data, is_stmt, pointer_size)
5555 unsigned char *data;
5559 unsigned char op_code;
5562 unsigned char *name;
5565 len = read_leb128 (data, & bytes_read, 0);
5570 warn (_("badly formed extended line op encountered!\n"));
5577 printf (_(" Extended opcode %d: "), op_code);
5581 case DW_LNE_end_sequence:
5582 printf (_("End of Sequence\n\n"));
5583 reset_state_machine (is_stmt);
5586 case DW_LNE_set_address:
5587 adr = byte_get (data, pointer_size);
5588 printf (_("set Address to 0x%lx\n"), adr);
5589 state_machine_regs.address = adr;
5592 case DW_LNE_define_file:
5593 printf (_(" define new File Table entry\n"));
5594 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5596 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
5598 data += strlen ((char *) data) + 1;
5599 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5601 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5603 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5604 printf (_("%s\n\n"), name);
5608 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5615 /* Size of pointers in the .debug_line section. This information is not
5616 really present in that section. It's obtained before dumping the debug
5617 sections by doing some pre-scan of the .debug_info section. */
5618 static int debug_line_pointer_size = 4;
5621 display_debug_lines (section, start, file)
5622 Elf_Internal_Shdr *section;
5623 unsigned char * start;
5624 FILE *file ATTRIBUTE_UNUSED;
5626 unsigned char *hdrptr;
5627 DWARF2_Internal_LineInfo info;
5628 unsigned char *standard_opcodes;
5629 unsigned char *data = start;
5630 unsigned char *end = start + section->sh_size;
5631 unsigned char *end_of_sequence;
5634 int initial_length_size;
5636 printf (_("\nDump of debug contents of section %s:\n\n"),
5637 SECTION_NAME (section));
5643 /* Check the length of the block. */
5644 info.li_length = byte_get (hdrptr, 4);
5647 if (info.li_length == 0xffffffff)
5649 /* This section is 64-bit DWARF 3. */
5650 info.li_length = byte_get (hdrptr, 8);
5653 initial_length_size = 12;
5658 initial_length_size = 4;
5661 if (info.li_length + initial_length_size > section->sh_size)
5664 (_("The line info appears to be corrupt - the section is too small\n"));
5668 /* Check its version number. */
5669 info.li_version = byte_get (hdrptr, 2);
5671 if (info.li_version != 2 && info.li_version != 3)
5673 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
5677 info.li_prologue_length = byte_get (hdrptr, offset_size);
5678 hdrptr += offset_size;
5679 info.li_min_insn_length = byte_get (hdrptr, 1);
5681 info.li_default_is_stmt = byte_get (hdrptr, 1);
5683 info.li_line_base = byte_get (hdrptr, 1);
5685 info.li_line_range = byte_get (hdrptr, 1);
5687 info.li_opcode_base = byte_get (hdrptr, 1);
5690 /* Sign extend the line base field. */
5691 info.li_line_base <<= 24;
5692 info.li_line_base >>= 24;
5694 printf (_(" Length: %ld\n"), info.li_length);
5695 printf (_(" DWARF Version: %d\n"), info.li_version);
5696 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5697 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5698 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5699 printf (_(" Line Base: %d\n"), info.li_line_base);
5700 printf (_(" Line Range: %d\n"), info.li_line_range);
5701 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5703 end_of_sequence = data + info.li_length + initial_length_size;
5705 reset_state_machine (info.li_default_is_stmt);
5707 /* Display the contents of the Opcodes table. */
5708 standard_opcodes = hdrptr;
5710 printf (_("\n Opcodes:\n"));
5712 for (i = 1; i < info.li_opcode_base; i++)
5713 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5715 /* Display the contents of the Directory table. */
5716 data = standard_opcodes + info.li_opcode_base - 1;
5719 printf (_("\n The Directory Table is empty.\n"));
5722 printf (_("\n The Directory Table:\n"));
5726 printf (_(" %s\n"), data);
5728 data += strlen ((char *) data) + 1;
5732 /* Skip the NUL at the end of the table. */
5735 /* Display the contents of the File Name table. */
5737 printf (_("\n The File Name Table is empty.\n"));
5740 printf (_("\n The File Name Table:\n"));
5741 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5745 unsigned char *name;
5748 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
5751 data += strlen ((char *) data) + 1;
5753 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5755 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5757 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5759 printf (_("%s\n"), name);
5763 /* Skip the NUL at the end of the table. */
5766 /* Now display the statements. */
5767 printf (_("\n Line Number Statements:\n"));
5770 while (data < end_of_sequence)
5772 unsigned char op_code;
5778 if (op_code >= info.li_opcode_base)
5780 op_code -= info.li_opcode_base;
5781 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5782 state_machine_regs.address += adv;
5783 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5784 op_code, adv, state_machine_regs.address);
5785 adv = (op_code % info.li_line_range) + info.li_line_base;
5786 state_machine_regs.line += adv;
5787 printf (_(" and Line by %d to %d\n"),
5788 adv, state_machine_regs.line);
5790 else switch (op_code)
5792 case DW_LNS_extended_op:
5793 data += process_extended_line_op (data, info.li_default_is_stmt,
5794 debug_line_pointer_size);
5798 printf (_(" Copy\n"));
5801 case DW_LNS_advance_pc:
5802 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5804 state_machine_regs.address += adv;
5805 printf (_(" Advance PC by %d to %lx\n"), adv,
5806 state_machine_regs.address);
5809 case DW_LNS_advance_line:
5810 adv = read_leb128 (data, & bytes_read, 1);
5812 state_machine_regs.line += adv;
5813 printf (_(" Advance Line by %d to %d\n"), adv,
5814 state_machine_regs.line);
5817 case DW_LNS_set_file:
5818 adv = read_leb128 (data, & bytes_read, 0);
5820 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5822 state_machine_regs.file = adv;
5825 case DW_LNS_set_column:
5826 adv = read_leb128 (data, & bytes_read, 0);
5828 printf (_(" Set column to %d\n"), adv);
5829 state_machine_regs.column = adv;
5832 case DW_LNS_negate_stmt:
5833 adv = state_machine_regs.is_stmt;
5835 printf (_(" Set is_stmt to %d\n"), adv);
5836 state_machine_regs.is_stmt = adv;
5839 case DW_LNS_set_basic_block:
5840 printf (_(" Set basic block\n"));
5841 state_machine_regs.basic_block = 1;
5844 case DW_LNS_const_add_pc:
5845 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5846 * info.li_min_insn_length);
5847 state_machine_regs.address += adv;
5848 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5849 state_machine_regs.address);
5852 case DW_LNS_fixed_advance_pc:
5853 adv = byte_get (data, 2);
5855 state_machine_regs.address += adv;
5856 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5857 adv, state_machine_regs.address);
5860 case DW_LNS_set_prologue_end:
5861 printf (_(" Set prologue_end to true\n"));
5864 case DW_LNS_set_epilogue_begin:
5865 printf (_(" Set epilogue_begin to true\n"));
5868 case DW_LNS_set_isa:
5869 adv = read_leb128 (data, & bytes_read, 0);
5871 printf (_(" Set ISA to %d\n"), adv);
5875 printf (_(" Unknown opcode %d with operands: "), op_code);
5878 for (j = standard_opcodes[op_code - 1]; j > 0 ; --j)
5880 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
5881 j == 1 ? "" : ", ");
5896 display_debug_pubnames (section, start, file)
5897 Elf_Internal_Shdr *section;
5898 unsigned char *start;
5899 FILE *file ATTRIBUTE_UNUSED;
5901 DWARF2_Internal_PubNames pubnames;
5904 end = start + section->sh_size;
5906 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5910 unsigned char *data;
5911 unsigned long offset;
5912 int offset_size, initial_length_size;
5916 pubnames.pn_length = byte_get (data, 4);
5918 if (pubnames.pn_length == 0xffffffff)
5920 pubnames.pn_length = byte_get (data, 8);
5923 initial_length_size = 12;
5928 initial_length_size = 4;
5931 pubnames.pn_version = byte_get (data, 2);
5933 pubnames.pn_offset = byte_get (data, offset_size);
5934 data += offset_size;
5935 pubnames.pn_size = byte_get (data, offset_size);
5936 data += offset_size;
5938 start += pubnames.pn_length + initial_length_size;
5940 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
5942 static int warned = 0;
5946 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5953 printf (_(" Length: %ld\n"),
5954 pubnames.pn_length);
5955 printf (_(" Version: %d\n"),
5956 pubnames.pn_version);
5957 printf (_(" Offset into .debug_info section: %ld\n"),
5958 pubnames.pn_offset);
5959 printf (_(" Size of area in .debug_info section: %ld\n"),
5962 printf (_("\n Offset\tName\n"));
5966 offset = byte_get (data, offset_size);
5970 data += offset_size;
5971 printf (" %ld\t\t%s\n", offset, data);
5972 data += strlen ((char *) data) + 1;
5975 while (offset != 0);
5982 //PG don't make this static!
5989 case DW_TAG_padding: return "DW_TAG_padding";
5990 case DW_TAG_array_type: return "DW_TAG_array_type";
5991 case DW_TAG_class_type: return "DW_TAG_class_type";
5992 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5993 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5994 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5995 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5996 case DW_TAG_label: return "DW_TAG_label";
5997 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5998 case DW_TAG_member: return "DW_TAG_member";
5999 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6000 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6001 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6002 case DW_TAG_string_type: return "DW_TAG_string_type";
6003 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6004 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6005 case DW_TAG_typedef: return "DW_TAG_typedef";
6006 case DW_TAG_union_type: return "DW_TAG_union_type";
6007 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6008 case DW_TAG_variant: return "DW_TAG_variant";
6009 case DW_TAG_common_block: return "DW_TAG_common_block";
6010 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6011 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6012 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6013 case DW_TAG_module: return "DW_TAG_module";
6014 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6015 case DW_TAG_set_type: return "DW_TAG_set_type";
6016 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6017 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6018 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6019 case DW_TAG_base_type: return "DW_TAG_base_type";
6020 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6021 case DW_TAG_const_type: return "DW_TAG_const_type";
6022 case DW_TAG_constant: return "DW_TAG_constant";
6023 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6024 case DW_TAG_file_type: return "DW_TAG_file_type";
6025 case DW_TAG_friend: return "DW_TAG_friend";
6026 case DW_TAG_namelist: return "DW_TAG_namelist";
6027 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6028 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6029 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6030 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6031 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6032 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6033 case DW_TAG_try_block: return "DW_TAG_try_block";
6034 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6035 case DW_TAG_variable: return "DW_TAG_variable";
6036 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6037 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6038 case DW_TAG_format_label: return "DW_TAG_format_label";
6039 case DW_TAG_function_template: return "DW_TAG_function_template";
6040 case DW_TAG_class_template: return "DW_TAG_class_template";
6041 /* DWARF 2.1 values. */
6042 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6043 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6044 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6045 case DW_TAG_namespace: return "DW_TAG_namespace";
6046 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6047 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6048 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6049 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6051 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
6052 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
6053 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
6056 static char buffer[100];
6058 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6065 get_AT_name (attribute)
6066 unsigned long attribute;
6070 case DW_AT_sibling: return "DW_AT_sibling";
6071 case DW_AT_location: return "DW_AT_location";
6072 case DW_AT_name: return "DW_AT_name";
6073 case DW_AT_ordering: return "DW_AT_ordering";
6074 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6075 case DW_AT_byte_size: return "DW_AT_byte_size";
6076 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6077 case DW_AT_bit_size: return "DW_AT_bit_size";
6078 case DW_AT_element_list: return "DW_AT_element_list";
6079 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6080 case DW_AT_low_pc: return "DW_AT_low_pc";
6081 case DW_AT_high_pc: return "DW_AT_high_pc";
6082 case DW_AT_language: return "DW_AT_language";
6083 case DW_AT_member: return "DW_AT_member";
6084 case DW_AT_discr: return "DW_AT_discr";
6085 case DW_AT_discr_value: return "DW_AT_discr_value";
6086 case DW_AT_visibility: return "DW_AT_visibility";
6087 case DW_AT_import: return "DW_AT_import";
6088 case DW_AT_string_length: return "DW_AT_string_length";
6089 case DW_AT_common_reference: return "DW_AT_common_reference";
6090 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6091 case DW_AT_const_value: return "DW_AT_const_value";
6092 case DW_AT_containing_type: return "DW_AT_containing_type";
6093 case DW_AT_default_value: return "DW_AT_default_value";
6094 case DW_AT_inline: return "DW_AT_inline";
6095 case DW_AT_is_optional: return "DW_AT_is_optional";
6096 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6097 case DW_AT_producer: return "DW_AT_producer";
6098 case DW_AT_prototyped: return "DW_AT_prototyped";
6099 case DW_AT_return_addr: return "DW_AT_return_addr";
6100 case DW_AT_start_scope: return "DW_AT_start_scope";
6101 case DW_AT_stride_size: return "DW_AT_stride_size";
6102 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6103 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6104 case DW_AT_accessibility: return "DW_AT_accessibility";
6105 case DW_AT_address_class: return "DW_AT_address_class";
6106 case DW_AT_artificial: return "DW_AT_artificial";
6107 case DW_AT_base_types: return "DW_AT_base_types";
6108 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6109 case DW_AT_count: return "DW_AT_count";
6110 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6111 case DW_AT_decl_column: return "DW_AT_decl_column";
6112 case DW_AT_decl_file: return "DW_AT_decl_file";
6113 case DW_AT_decl_line: return "DW_AT_decl_line";
6114 case DW_AT_declaration: return "DW_AT_declaration";
6115 case DW_AT_discr_list: return "DW_AT_discr_list";
6116 case DW_AT_encoding: return "DW_AT_encoding";
6117 case DW_AT_external: return "DW_AT_external";
6118 case DW_AT_frame_base: return "DW_AT_frame_base";
6119 case DW_AT_friend: return "DW_AT_friend";
6120 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6121 case DW_AT_macro_info: return "DW_AT_macro_info";
6122 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6123 case DW_AT_priority: return "DW_AT_priority";
6124 case DW_AT_segment: return "DW_AT_segment";
6125 case DW_AT_specification: return "DW_AT_specification";
6126 case DW_AT_static_link: return "DW_AT_static_link";
6127 case DW_AT_type: return "DW_AT_type";
6128 case DW_AT_use_location: return "DW_AT_use_location";
6129 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6130 case DW_AT_virtuality: return "DW_AT_virtuality";
6131 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6132 /* DWARF 2.1 values. */
6133 case DW_AT_allocated: return "DW_AT_allocated";
6134 case DW_AT_associated: return "DW_AT_associated";
6135 case DW_AT_data_location: return "DW_AT_data_location";
6136 case DW_AT_stride: return "DW_AT_stride";
6137 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6138 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6139 case DW_AT_extension: return "DW_AT_extension";
6140 case DW_AT_ranges: return "DW_AT_ranges";
6141 case DW_AT_trampoline: return "DW_AT_trampoline";
6142 case DW_AT_call_column: return "DW_AT_call_column";
6143 case DW_AT_call_file: return "DW_AT_call_file";
6144 case DW_AT_call_line: return "DW_AT_call_line";
6145 /* SGI/MIPS extensions. */
6146 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6147 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6148 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6149 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6150 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6151 case DW_AT_MIPS_software_pipeline_depth:
6152 return "DW_AT_MIPS_software_pipeline_depth";
6153 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6154 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6155 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6156 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6157 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6158 /* GNU extensions. */
6159 case DW_AT_sf_names: return "DW_AT_sf_names";
6160 case DW_AT_src_info: return "DW_AT_src_info";
6161 case DW_AT_mac_info: return "DW_AT_mac_info";
6162 case DW_AT_src_coords: return "DW_AT_src_coords";
6163 case DW_AT_body_begin: return "DW_AT_body_begin";
6164 case DW_AT_body_end: return "DW_AT_body_end";
6165 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
6166 /* UPC extension. */
6167 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
6170 static char buffer[100];
6172 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6179 get_FORM_name (form)
6184 case DW_FORM_addr: return "DW_FORM_addr";
6185 case DW_FORM_block2: return "DW_FORM_block2";
6186 case DW_FORM_block4: return "DW_FORM_block4";
6187 case DW_FORM_data2: return "DW_FORM_data2";
6188 case DW_FORM_data4: return "DW_FORM_data4";
6189 case DW_FORM_data8: return "DW_FORM_data8";
6190 case DW_FORM_string: return "DW_FORM_string";
6191 case DW_FORM_block: return "DW_FORM_block";
6192 case DW_FORM_block1: return "DW_FORM_block1";
6193 case DW_FORM_data1: return "DW_FORM_data1";
6194 case DW_FORM_flag: return "DW_FORM_flag";
6195 case DW_FORM_sdata: return "DW_FORM_sdata";
6196 case DW_FORM_strp: return "DW_FORM_strp";
6197 case DW_FORM_udata: return "DW_FORM_udata";
6198 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6199 case DW_FORM_ref1: return "DW_FORM_ref1";
6200 case DW_FORM_ref2: return "DW_FORM_ref2";
6201 case DW_FORM_ref4: return "DW_FORM_ref4";
6202 case DW_FORM_ref8: return "DW_FORM_ref8";
6203 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6204 case DW_FORM_indirect: return "DW_FORM_indirect";
6207 static char buffer[100];
6209 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6215 /* FIXME: There are better and more effiecint ways to handle
6216 these structures. For now though, I just want something that
6217 is simple to implement. */
6218 typedef struct abbrev_attr
6220 unsigned long attribute;
6222 struct abbrev_attr *next;
6226 typedef struct abbrev_entry
6228 unsigned long entry;
6231 struct abbrev_attr *first_attr;
6232 struct abbrev_attr *last_attr;
6233 struct abbrev_entry *next;
6237 static abbrev_entry *first_abbrev = NULL;
6238 static abbrev_entry *last_abbrev = NULL;
6243 abbrev_entry *abbrev;
6245 for (abbrev = first_abbrev; abbrev;)
6247 abbrev_entry *next = abbrev->next;
6250 for (attr = abbrev->first_attr; attr;)
6252 abbrev_attr *next_attr = attr->next;
6262 last_abbrev = first_abbrev = NULL;
6266 add_abbrev (number, tag, children)
6267 unsigned long number;
6271 abbrev_entry *entry;
6273 entry = (abbrev_entry *) malloc (sizeof (*entry));
6279 entry->entry = number;
6281 entry->children = children;
6282 entry->first_attr = NULL;
6283 entry->last_attr = NULL;
6286 if (first_abbrev == NULL)
6287 first_abbrev = entry;
6289 last_abbrev->next = entry;
6291 last_abbrev = entry;
6295 add_abbrev_attr (attribute, form)
6296 unsigned long attribute;
6301 attr = (abbrev_attr *) malloc (sizeof (*attr));
6307 attr->attribute = attribute;
6311 if (last_abbrev->first_attr == NULL)
6312 last_abbrev->first_attr = attr;
6314 last_abbrev->last_attr->next = attr;
6316 last_abbrev->last_attr = attr;
6319 /* Processes the (partial) contents of a .debug_abbrev section.
6320 Returns NULL if the end of the section was encountered.
6321 Returns the address after the last byte read if the end of
6322 an abbreviation set was found. */
6324 static unsigned char *
6325 process_abbrev_section (start, end)
6326 unsigned char *start;
6329 if (first_abbrev != NULL)
6335 unsigned long entry;
6337 unsigned long attribute;
6340 entry = read_leb128 (start, & bytes_read, 0);
6341 start += bytes_read;
6343 /* A single zero is supposed to end the section according
6344 to the standard. If there's more, then signal that to
6347 return start == end ? NULL : start;
6349 tag = read_leb128 (start, & bytes_read, 0);
6350 start += bytes_read;
6352 children = *start++;
6354 add_abbrev (entry, tag, children);
6360 attribute = read_leb128 (start, & bytes_read, 0);
6361 start += bytes_read;
6363 form = read_leb128 (start, & bytes_read, 0);
6364 start += bytes_read;
6367 add_abbrev_attr (attribute, form);
6369 while (attribute != 0);
6377 display_debug_macinfo (section, start, file)
6378 Elf_Internal_Shdr *section;
6379 unsigned char *start;
6380 FILE *file ATTRIBUTE_UNUSED;
6382 unsigned char *end = start + section->sh_size;
6383 unsigned char *curr = start;
6384 unsigned int bytes_read;
6385 enum dwarf_macinfo_record_type op;
6387 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6391 unsigned int lineno;
6399 case DW_MACINFO_start_file:
6401 unsigned int filenum;
6403 lineno = read_leb128 (curr, & bytes_read, 0);
6405 filenum = read_leb128 (curr, & bytes_read, 0);
6408 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6412 case DW_MACINFO_end_file:
6413 printf (_(" DW_MACINFO_end_file\n"));
6416 case DW_MACINFO_define:
6417 lineno = read_leb128 (curr, & bytes_read, 0);
6420 curr += strlen (string) + 1;
6421 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6424 case DW_MACINFO_undef:
6425 lineno = read_leb128 (curr, & bytes_read, 0);
6428 curr += strlen (string) + 1;
6429 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6432 case DW_MACINFO_vendor_ext:
6434 unsigned int constant;
6436 constant = read_leb128 (curr, & bytes_read, 0);
6439 curr += strlen (string) + 1;
6440 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6451 display_debug_abbrev (section, start, file)
6452 Elf_Internal_Shdr *section;
6453 unsigned char *start;
6454 FILE *file ATTRIBUTE_UNUSED;
6456 abbrev_entry *entry;
6457 unsigned char *end = start + section->sh_size;
6459 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6463 start = process_abbrev_section (start, end);
6465 if (first_abbrev == NULL)
6468 printf (_(" Number TAG\n"));
6470 for (entry = first_abbrev; entry; entry = entry->next)
6474 printf (_(" %ld %s [%s]\n"),
6476 get_TAG_name (entry->tag),
6477 entry->children ? _("has children") : _("no children"));
6479 for (attr = entry->first_attr; attr; attr = attr->next)
6481 printf (_(" %-18s %s\n"),
6482 get_AT_name (attr->attribute),
6483 get_FORM_name (attr->form));
6497 static unsigned char *
6498 display_block (data, length, ok_to_harvest)
6499 unsigned char *data;
6500 unsigned long length;
6503 if (print_results && ok_to_harvest)
6504 printf (_(" %lu byte block: "), length);
6508 unsigned long temp = (unsigned long) byte_get (data++, 1);
6509 if (print_results && ok_to_harvest)
6510 printf ("%lx ", temp);
6511 // printf ("%lx ", (unsigned long) byte_get (data++, 1));
6518 decode_location_expression (data, pointer_size, length, ok_to_harvest, location_data)
6519 unsigned char * data;
6520 unsigned int pointer_size;
6521 unsigned long length;
6523 long* location_data;
6527 unsigned long uvalue;
6528 unsigned char *end = data + length;
6530 int print_results_and_ok = print_results && ok_to_harvest;
6539 if (print_results_and_ok)
6541 printf ("DW_OP_addr: %lx",
6542 (unsigned long) byte_get (data, pointer_size));
6543 data += pointer_size;
6547 byte_get (data, pointer_size);
6548 data += pointer_size;
6552 if (print_results_and_ok) {printf ("DW_OP_deref");}
6555 if (print_results_and_ok) {printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));}
6556 else {byte_get (data++, 1);}
6559 if (print_results_and_ok) {printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));}
6560 else {byte_get (data++, 1);}
6563 if (print_results_and_ok)
6565 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6575 if (print_results_and_ok)
6577 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6587 if (print_results_and_ok)
6589 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6599 if (print_results_and_ok)
6601 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6611 if (print_results_and_ok)
6613 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6614 (unsigned long) byte_get (data + 4, 4));
6620 byte_get (data + 4, 4);
6625 if (print_results_and_ok)
6627 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6628 (long) byte_get (data + 4, 4));
6634 byte_get (data + 4, 4);
6639 if (print_results_and_ok)
6641 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6646 read_leb128 (data, &bytes_read, 0);
6651 if (print_results_and_ok)
6653 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6658 read_leb128 (data, &bytes_read, 1);
6663 if (print_results_and_ok) printf ("DW_OP_dup");
6666 if (print_results_and_ok) printf ("DW_OP_drop");
6669 if (print_results_and_ok) printf ("DW_OP_over");
6672 if (print_results_and_ok)
6674 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6678 byte_get (data++, 1);
6682 if (print_results_and_ok) printf ("DW_OP_swap");
6685 if (print_results_and_ok) printf ("DW_OP_rot");
6688 if (print_results_and_ok) printf ("DW_OP_xderef");
6691 if (print_results_and_ok) printf ("DW_OP_abs");
6694 if (print_results_and_ok) printf ("DW_OP_and");
6697 if (print_results_and_ok) printf ("DW_OP_div");
6700 if (print_results_and_ok) printf ("DW_OP_minus");
6703 if (print_results_and_ok) printf ("DW_OP_mod");
6706 if (print_results_and_ok) printf ("DW_OP_mul");
6709 if (print_results_and_ok) printf ("DW_OP_neg");
6712 if (print_results_and_ok) printf ("DW_OP_not");
6715 if (print_results_and_ok) printf ("DW_OP_or");
6718 if (print_results_and_ok) printf ("DW_OP_plus");
6720 case DW_OP_plus_uconst:
6721 if (ok_to_harvest && location_data)
6723 unsigned long uconst_data = read_leb128 (data, &bytes_read, 0);
6724 *location_data = (long)uconst_data;
6727 printf ("DW_OP_plus_uconst: %lu",
6734 read_leb128 (data, &bytes_read, 0);
6739 if (print_results_and_ok) printf ("DW_OP_shl");
6742 if (print_results_and_ok) printf ("DW_OP_shr");
6745 if (print_results_and_ok) printf ("DW_OP_shra");
6748 if (print_results_and_ok) printf ("DW_OP_xor");
6751 if (print_results_and_ok)
6753 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6763 if (print_results_and_ok) printf ("DW_OP_eq");
6766 if (print_results_and_ok) printf ("DW_OP_ge");
6769 if (print_results_and_ok) printf ("DW_OP_gt");
6772 if (print_results_and_ok) printf ("DW_OP_le");
6775 if (print_results_and_ok) printf ("DW_OP_lt");
6778 if (print_results_and_ok) printf ("DW_OP_ne");
6781 if (print_results_and_ok)
6783 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6825 if (print_results_and_ok) printf ("DW_OP_lit%d", op - DW_OP_lit0);
6860 if (print_results_and_ok) printf ("DW_OP_reg%d", op - DW_OP_reg0);
6895 if (print_results_and_ok)
6897 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6898 read_leb128 (data, &bytes_read, 1));
6903 read_leb128 (data, &bytes_read, 1);
6909 if (print_results_and_ok)
6911 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6916 read_leb128 (data, &bytes_read, 0);
6921 if (ok_to_harvest && location_data)
6923 unsigned long fbreg_value = read_leb128 (data, &bytes_read, 1);
6924 *location_data = (long)fbreg_value;
6925 if (print_results_and_ok)
6927 printf ("DW_OP_fbreg: %ld", fbreg_value);
6933 read_leb128 (data, &bytes_read, 1);
6938 if (print_results_and_ok)
6940 uvalue = read_leb128 (data, &bytes_read, 0);
6942 printf ("DW_OP_bregx: %lu %ld", uvalue,
6943 read_leb128 (data, &bytes_read, 1));
6948 uvalue = read_leb128 (data, &bytes_read, 0);
6950 read_leb128 (data, &bytes_read, 1);
6955 if (print_results_and_ok)
6957 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6962 read_leb128 (data, &bytes_read, 0);
6966 case DW_OP_deref_size:
6967 if (print_results_and_ok)
6969 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6973 byte_get (data++, 1);
6976 case DW_OP_xderef_size:
6977 if (print_results_and_ok)
6979 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6983 byte_get (data++, 1);
6987 if (print_results_and_ok) printf ("DW_OP_nop");
6990 /* DWARF 3 extensions. */
6991 case DW_OP_push_object_address:
6992 if (print_results_and_ok) printf ("DW_OP_push_object_address");
6995 if (print_results_and_ok)
6997 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7007 if (print_results_and_ok)
7009 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7018 case DW_OP_call_ref:
7019 if (print_results_and_ok) printf ("DW_OP_call_ref");
7022 /* GNU extensions. */
7023 case DW_OP_GNU_push_tls_address:
7024 if (print_results_and_ok) printf ("DW_OP_GNU_push_tls_address");
7028 if (op >= DW_OP_lo_user
7029 && op <= DW_OP_hi_user)
7030 printf (_("(User defined location op)"));
7032 printf (_("(Unknown location op)"));
7033 /* No way to tell where the next op is, so just bail. */
7037 /* Separate the ops. */
7040 if (print_results_and_ok)
7049 unsigned long uvalue;
7050 unsigned char *end = data + length;
7059 if (display) printf ("DW_OP_addr: %lx",
7060 (unsigned long) byte_get (data, pointer_size));
7061 data += pointer_size;
7064 if (display) printf ("DW_OP_deref");
7067 if (display) printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
7071 if (display) printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
7075 if (display) printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
7079 if (display) printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
7083 if (display) printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
7087 if (display) printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
7091 if (display) printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
7092 (unsigned long) byte_get (data + 4, 4));
7096 if (display) printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
7097 (long) byte_get (data + 4, 4));
7101 if (display) printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
7105 if (display) printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
7109 if (display) printf ("DW_OP_dup");
7112 if (display) printf ("DW_OP_drop");
7115 if (display) printf ("DW_OP_over");
7118 if (display) printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
7122 if (display) printf ("DW_OP_swap");
7125 if (display) printf ("DW_OP_rot");
7128 if (display) printf ("DW_OP_xderef");
7131 if (display) printf ("DW_OP_abs");
7134 if (display) printf ("DW_OP_and");
7137 if (display) printf ("DW_OP_div");
7140 if (display) printf ("DW_OP_minus");
7143 if (display) printf ("DW_OP_mod");
7146 if (display) printf ("DW_OP_mul");
7149 if (display) printf ("DW_OP_neg");
7152 if (display) printf ("DW_OP_not");
7155 if (display) printf ("DW_OP_or");
7158 if (display) printf ("DW_OP_plus");
7160 case DW_OP_plus_uconst:
7163 unsigned long uconst_data = read_leb128 (data, &bytes_read, 0);
7165 *location_data = (long)uconst_data;
7166 printf ("DW_OP_plus_uconst: %lu",
7172 if (display) printf ("DW_OP_shl");
7175 if (display) printf ("DW_OP_shr");
7178 if (display) printf ("DW_OP_shra");
7181 if (display) printf ("DW_OP_xor");
7184 if (display) printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
7188 if (display) printf ("DW_OP_eq");
7191 if (display) printf ("DW_OP_ge");
7194 if (display) printf ("DW_OP_gt");
7197 if (display) printf ("DW_OP_le");
7200 if (display) printf ("DW_OP_lt");
7203 if (display) printf ("DW_OP_ne");
7206 if (display) printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
7242 if (display) printf ("DW_OP_lit%d", op - DW_OP_lit0);
7277 if (display) printf ("DW_OP_reg%d", op - DW_OP_reg0);
7312 if (display) printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
7313 read_leb128 (data, &bytes_read, 1));
7318 if (display) printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
7324 unsigned long fbreg_value = read_leb128 (data, &bytes_read, 1);
7326 *location_data = (long)fbreg_value;
7327 printf ("DW_OP_fbreg: %ld", fbreg_value);
7332 uvalue = read_leb128 (data, &bytes_read, 0);
7334 if (display) printf ("DW_OP_bregx: %lu %ld", uvalue,
7335 read_leb128 (data, &bytes_read, 1));
7339 if (display) printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
7342 case DW_OP_deref_size:
7343 if (display) printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
7346 case DW_OP_xderef_size:
7347 if (display) printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
7351 if (display) printf ("DW_OP_nop");
7354 // DWARF 3 extensions.
7355 case DW_OP_push_object_address:
7356 if (display) printf ("DW_OP_push_object_address");
7359 if (display) printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7363 if (display) printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7366 case DW_OP_call_ref:
7367 if (display) printf ("DW_OP_call_ref");
7371 case DW_OP_GNU_push_tls_address:
7372 if (display) printf ("DW_OP_GNU_push_tls_address");
7376 if (op >= DW_OP_lo_user
7377 && op <= DW_OP_hi_user)
7379 if (display) printf (_("(User defined location op)"));
7383 if (display) printf (_("(Unknown location op)"));
7385 // No way to tell where the next op is, so just bail.
7389 // Separate the ops.
7392 if (display) printf ("; ");
7398 static const char *debug_loc_contents;
7399 static bfd_vma debug_loc_size;
7402 load_debug_loc (file)
7405 Elf_Internal_Shdr *sec;
7408 /* If it is already loaded, do nothing. */
7409 if (debug_loc_contents != NULL)
7412 /* Locate the .debug_loc section. */
7413 for (i = 0, sec = section_headers;
7414 i < elf_header.e_shnum;
7416 if (strcmp (SECTION_NAME (sec), ".debug_loc") == 0)
7419 if (i == elf_header.e_shnum || sec->sh_size == 0)
7422 debug_loc_size = sec->sh_size;
7424 debug_loc_contents = ((char *)
7425 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7426 _("debug_loc section data")));
7432 if (debug_loc_contents == NULL)
7435 free ((char *) debug_loc_contents);
7436 debug_loc_contents = NULL;
7442 display_debug_loc (section, start, file)
7443 Elf_Internal_Shdr *section;
7444 unsigned char *start;
7445 FILE *file ATTRIBUTE_UNUSED;
7447 unsigned char *section_end;
7448 unsigned long bytes;
7449 unsigned char *section_begin = start;
7452 addr = section->sh_addr;
7453 bytes = section->sh_size;
7454 section_end = start + bytes;
7458 printf (_("\nThe .debug_loc section is empty.\n"));
7462 printf (_("Contents of the .debug_loc section:\n\n"));
7463 printf (_("\n Offset Begin End Expression\n"));
7465 while (start < section_end)
7467 unsigned long begin;
7469 unsigned short length;
7470 unsigned long offset;
7472 offset = start - section_begin;
7476 /* Normally, the lists in the debug_loc section are related to a
7477 given compilation unit, and thus, we would use the pointer size
7478 of that compilation unit. However, since we are displaying it
7479 seperately here, we either have to store pointer sizes of all
7480 compilation units, or assume they don't change. We assume,
7481 like the debug_line display, that it doesn't change. */
7482 begin = byte_get (start, debug_line_pointer_size);
7483 start += debug_line_pointer_size;
7484 end = byte_get (start, debug_line_pointer_size);
7485 start += debug_line_pointer_size;
7487 if (begin == 0 && end == 0)
7490 /* For now, skip any base address specifiers. */
7491 if (begin == 0xffffffff)
7497 length = byte_get (start, 2);
7500 printf (" %8.8lx %8.8lx %8.8lx (", offset, begin, end);
7501 decode_location_expression (start, debug_line_pointer_size, length, 1, 0);
7511 static const char *debug_str_contents;
7512 static bfd_vma debug_str_size;
7515 load_debug_str (file)
7518 Elf_Internal_Shdr *sec;
7521 /* If it is already loaded, do nothing. */
7522 if (debug_str_contents != NULL)
7525 /* Locate the .debug_str section. */
7526 for (i = 0, sec = section_headers;
7527 i < elf_header.e_shnum;
7529 if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
7532 if (i == elf_header.e_shnum || sec->sh_size == 0)
7535 debug_str_size = sec->sh_size;
7537 debug_str_contents = ((char *)
7538 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7539 _("debug_str section data")));
7545 if (debug_str_contents == NULL)
7548 free ((char *) debug_str_contents);
7549 debug_str_contents = NULL;
7554 fetch_indirect_string (offset)
7555 unsigned long offset;
7557 if (debug_str_contents == NULL)
7558 return _("<no .debug_str section>");
7560 if (offset > debug_str_size)
7561 return _("<offset is too big>");
7563 return debug_str_contents + offset;
7567 display_debug_str (section, start, file)
7568 Elf_Internal_Shdr *section;
7569 unsigned char *start;
7570 FILE *file ATTRIBUTE_UNUSED;
7572 unsigned long bytes;
7575 addr = section->sh_addr;
7576 bytes = section->sh_size;
7580 printf (_("\nThe .debug_str section is empty.\n"));
7584 printf (_("Contents of the .debug_str section:\n\n"));
7592 lbytes = (bytes > 16 ? 16 : bytes);
7594 printf (" 0x%8.8lx ", (unsigned long) addr);
7596 for (j = 0; j < 16; j++)
7599 printf ("%2.2x", start[j]);
7607 for (j = 0; j < lbytes; j++)
7610 if (k >= ' ' && k < 0x80)
7626 static unsigned char *
7627 read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size,
7628 offset_size, dwarf_version, entry, ok)
7629 unsigned long attribute;
7631 unsigned char *data;
7632 unsigned long cu_offset;
7633 unsigned long pointer_size;
7634 unsigned long offset_size;
7639 unsigned long uvalue = 0;
7640 unsigned char *block_start = NULL;
7643 int print_results_and_ok = print_results && ok;
7650 case DW_FORM_ref_addr:
7651 if (dwarf_version == 2)
7653 uvalue = byte_get (data, pointer_size);
7654 data += pointer_size;
7656 else if (dwarf_version == 3)
7658 uvalue = byte_get (data, offset_size);
7659 data += offset_size;
7663 error (_("Internal error: DWARF version is not 2 or 3.\n"));
7668 uvalue = byte_get (data, pointer_size);
7669 data += pointer_size;
7673 uvalue = byte_get (data, offset_size);
7674 data += offset_size;
7680 uvalue = byte_get (data++, 1);
7685 uvalue = byte_get (data, 2);
7691 uvalue = byte_get (data, 4);
7696 uvalue = read_leb128 (data, & bytes_read, 1);
7700 case DW_FORM_ref_udata:
7702 uvalue = read_leb128 (data, & bytes_read, 0);
7706 case DW_FORM_indirect:
7707 form = read_leb128 (data, & bytes_read, 0);
7709 if (print_results_and_ok) {printf (" %s", get_FORM_name (form));}
7710 return read_and_display_attr_value (attribute, form, data, cu_offset,
7711 pointer_size, offset_size,
7712 dwarf_version, entry, ok);
7717 case DW_FORM_ref_addr:
7718 if (print_results_and_ok) {printf (" <#%lx>", uvalue);}
7721 // DW_AT_type returns data in this form (REMEMBER cu_offset!):
7725 case DW_FORM_ref_udata:
7728 harvest_type_value(entry, uvalue + cu_offset);
7731 printf (" <%lx>", uvalue + cu_offset);
7739 harvest_address_value(entry, attribute, uvalue);
7741 printf (" %#lx", uvalue);
7744 if (print_results_and_ok)
7746 // DW_AT_byte_size, DW_AT_encoding, DW_AT_const_value,
7747 // DW_AT_bit_size, DW_AT_bit_offset, and DW_AT_external
7748 // return data in this form:
7757 harvest_ordinary_unsigned_value(entry, attribute, uvalue);
7758 if (print_results_and_ok)
7760 printf (" %ld", uvalue);
7767 uvalue = byte_get (data, 4);
7768 if (print_results_and_ok) {printf (" %lx", uvalue);}
7769 if (print_results_and_ok)
7771 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
7775 byte_get (data + 4, 4);
7780 // DW_AT_name/DW_AT_comp_dir can be a string, or an indirect string ... (see below)
7781 case DW_FORM_string:
7784 harvest_string(entry, attribute, data);
7785 if (print_results_and_ok)
7787 printf (" %s", data);
7790 data += strlen ((char *) data) + 1;
7794 uvalue = read_leb128 (data, & bytes_read, 0);
7795 block_start = data + bytes_read;
7796 data = display_block (block_start, uvalue, ok);
7799 case DW_FORM_block1:
7800 uvalue = byte_get (data, 1);
7801 block_start = data + 1;
7802 data = display_block (block_start, uvalue, ok);
7805 case DW_FORM_block2:
7806 uvalue = byte_get (data, 2);
7807 block_start = data + 2;
7808 data = display_block (block_start, uvalue, ok);
7811 case DW_FORM_block4:
7812 uvalue = byte_get (data, 4);
7813 block_start = data + 4;
7814 data = display_block (block_start, uvalue, ok);
7817 // DW_AT_name/DW_AT_comp_dir can be an indirect string ... but it can also be a string (see above)
7821 const char* ind_str = fetch_indirect_string (uvalue);
7822 harvest_string(entry, attribute, ind_str);
7823 if (print_results_and_ok)
7825 printf (_(" (indirect string, offset: 0x%lx): %s"),
7831 case DW_FORM_indirect:
7832 /* Handled above. */
7836 warn (_("Unrecognized form: %d\n"), form);
7840 /* For some attributes we can display futher information. */
7842 if (print_results_and_ok) {printf ("\t");}
7849 case DW_INL_not_inlined:
7850 if (print_results_and_ok) {printf (_("(not inlined)"));}
7852 case DW_INL_inlined:
7853 if (print_results_and_ok) {printf (_("(inlined)"));}
7855 case DW_INL_declared_not_inlined:
7856 if (print_results_and_ok) {printf (_("(declared as inline but ignored)"));}
7858 case DW_INL_declared_inlined:
7859 if (print_results_and_ok) {printf (_("(declared as inline and inlined)"));}
7862 if (print_results_and_ok) {printf (_(" (Unknown inline attribute value: %lx)"), uvalue);}
7867 case DW_AT_language:
7870 case DW_LANG_C: if (print_results_and_ok) {printf ("(non-ANSI C)");} break;
7871 case DW_LANG_C89: if (print_results_and_ok) {printf ("(ANSI C)");} break;
7872 case DW_LANG_C_plus_plus: if (print_results_and_ok) {printf ("(C++)");} break;
7873 case DW_LANG_Fortran77: if (print_results_and_ok) {printf ("(FORTRAN 77)");} break;
7874 case DW_LANG_Fortran90: if (print_results_and_ok) {printf ("(Fortran 90)");} break;
7875 case DW_LANG_Modula2: if (print_results_and_ok) {printf ("(Modula 2)");} break;
7876 case DW_LANG_Pascal83: if (print_results_and_ok) {printf ("(ANSI Pascal)");} break;
7877 case DW_LANG_Ada83: if (print_results_and_ok) {printf ("(Ada)");} break;
7878 case DW_LANG_Cobol74: if (print_results_and_ok) {printf ("(Cobol 74)");} break;
7879 case DW_LANG_Cobol85: if (print_results_and_ok) {printf ("(Cobol 85)");} break;
7880 /* DWARF 2.1 values. */
7881 case DW_LANG_C99: if (print_results_and_ok) {printf ("(ANSI C99)");} break;
7882 case DW_LANG_Ada95: if (print_results_and_ok) {printf ("(ADA 95)");} break;
7883 case DW_LANG_Fortran95: if (print_results_and_ok) {printf ("(Fortran 95)");} break;
7884 /* MIPS extension. */
7885 case DW_LANG_Mips_Assembler: if (print_results_and_ok) {printf ("(MIPS assembler)");} break;
7886 /* UPC extension. */
7887 case DW_LANG_Upc: if (print_results_and_ok) {printf ("(Unified Parallel C)");} break;
7889 if (print_results_and_ok) {printf ("(Unknown: %lx)", uvalue);}
7894 case DW_AT_encoding:
7897 case DW_ATE_void: if (print_results_and_ok) {printf ("(void)");} break;
7898 case DW_ATE_address: if (print_results_and_ok) {printf ("(machine address)");} break;
7899 case DW_ATE_boolean: if (print_results_and_ok) {printf ("(boolean)");} break;
7900 case DW_ATE_complex_float: if (print_results_and_ok) {printf ("(complex float)");} break;
7901 case DW_ATE_float: if (print_results_and_ok) {printf ("(float)");} break;
7902 case DW_ATE_signed: if (print_results_and_ok) {printf ("(signed)");} break;
7903 case DW_ATE_signed_char: if (print_results_and_ok) {printf ("(signed char)");} break;
7904 case DW_ATE_unsigned: if (print_results_and_ok) {printf ("(unsigned)");} break;
7905 case DW_ATE_unsigned_char: if (print_results_and_ok) {printf ("(unsigned char)");} break;
7906 /* DWARF 2.1 value. */
7907 case DW_ATE_imaginary_float: if (print_results_and_ok) {printf ("(imaginary float)");} break;
7909 if (uvalue >= DW_ATE_lo_user
7910 && uvalue <= DW_ATE_hi_user)
7912 if (print_results_and_ok) {printf ("(user defined type)");}
7916 if (print_results_and_ok) {printf ("(unknown type)");}
7922 case DW_AT_accessibility:
7925 case DW_ACCESS_public: if (print_results_and_ok) printf ("(public)"); break;
7926 case DW_ACCESS_protected: if (print_results_and_ok) printf ("(protected)"); break;
7927 case DW_ACCESS_private: if (print_results_and_ok) printf ("(private)"); break;
7929 if (print_results_and_ok) printf ("(unknown accessibility)");
7934 case DW_AT_visibility:
7937 case DW_VIS_local: if (print_results_and_ok) printf ("(local)"); break;
7938 case DW_VIS_exported: if (print_results_and_ok) printf ("(exported)"); break;
7939 case DW_VIS_qualified: if (print_results_and_ok) printf ("(qualified)"); break;
7940 default: if (print_results_and_ok) printf ("(unknown visibility)"); break;
7944 case DW_AT_virtuality:
7947 case DW_VIRTUALITY_none: if (print_results_and_ok) printf ("(none)"); break;
7948 case DW_VIRTUALITY_virtual: if (print_results_and_ok) printf ("(virtual)"); break;
7949 case DW_VIRTUALITY_pure_virtual:if (print_results_and_ok) printf ("(pure_virtual)"); break;
7950 default: if (print_results_and_ok) printf ("(unknown virtuality)"); break;
7954 case DW_AT_identifier_case:
7957 case DW_ID_case_sensitive: if (print_results_and_ok) printf ("(case_sensitive)"); break;
7958 case DW_ID_up_case: if (print_results_and_ok) printf ("(up_case)"); break;
7959 case DW_ID_down_case: if (print_results_and_ok) printf ("(down_case)"); break;
7960 case DW_ID_case_insensitive: if (print_results_and_ok) printf ("(case_insensitive)"); break;
7961 default: if (print_results_and_ok) printf ("(unknown case)"); break;
7965 case DW_AT_calling_convention:
7968 case DW_CC_normal: if (print_results_and_ok) printf ("(normal)"); break;
7969 case DW_CC_program: if (print_results_and_ok) printf ("(program)"); break;
7970 case DW_CC_nocall: if (print_results_and_ok) printf ("(nocall)"); break;
7972 if (uvalue >= DW_CC_lo_user
7973 && uvalue <= DW_CC_hi_user)
7975 if (print_results_and_ok) printf ("(user defined)");
7979 if (print_results_and_ok) printf ("(unknown convention)");
7984 case DW_AT_ordering:
7987 case -1: if (print_results_and_ok) printf ("(undefined)"); break;
7988 case 0: if (print_results_and_ok) printf ("(row major)"); break;
7989 case 1: if (print_results_and_ok) printf ("(column major)"); break;
7993 // DW_AT_location, DW_AT_data_member_location return data in this form:
7994 case DW_AT_location:
7998 if (print_results_and_ok) printf ("(");
7999 decode_location_expression (block_start, pointer_size, uvalue, ok, &loc_data);
8000 if (print_results_and_ok) printf (")");
8001 harvest_location(entry, loc_data);
8003 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
8005 if (print_results_and_ok) printf ("(");
8006 if (print_results_and_ok) printf ("location list");
8007 if (print_results_and_ok) printf (")");
8011 case DW_AT_data_member_location:
8015 if (print_results_and_ok) printf ("(");
8016 decode_location_expression (block_start, pointer_size, uvalue, ok, &loc_data);
8017 if (print_results_and_ok) printf (")");
8018 harvest_data_member_location(entry, loc_data);
8020 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
8022 if (print_results_and_ok) printf ("(");
8023 if (print_results_and_ok) printf ("location list");
8024 if (print_results_and_ok) printf (")");
8028 case DW_AT_frame_base:
8029 case DW_AT_vtable_elem_location:
8030 case DW_AT_allocated:
8031 case DW_AT_associated:
8032 case DW_AT_data_location:
8034 case DW_AT_upper_bound:
8035 case DW_AT_lower_bound:
8038 if (print_results_and_ok) printf ("(");
8039 decode_location_expression (block_start, pointer_size, uvalue, ok, 0);
8040 if (print_results_and_ok) printf (")");
8042 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
8044 if (print_results_and_ok) printf ("(");
8045 if (print_results_and_ok) printf ("location list");
8046 if (print_results_and_ok) printf (")");
8057 static unsigned char *
8058 read_and_display_attr (attribute, form, data, cu_offset, pointer_size,
8059 offset_size, dwarf_version, entry, ok_to_harvest)
8060 unsigned long attribute;
8062 unsigned char *data;
8063 unsigned long cu_offset;
8064 unsigned long pointer_size;
8065 unsigned long offset_size;
8070 char entry_is_listening = entry_is_listening_for_attribute(entry, attribute);
8072 // Ok process attributes when ok_to_harvest is on and the entry is listening:
8073 char ok_to_process = entry_is_listening && ok_to_harvest;
8074 // printf("ENTRY LISTENING: %d\n", (int)entry_is_listening);
8075 // if (ok_to_process)
8076 if (print_results && ok_to_process)
8077 printf (" %-18s:", get_AT_name (attribute));
8078 data = read_and_display_attr_value (attribute, form, data, cu_offset,
8079 pointer_size, offset_size, dwarf_version,
8080 entry, ok_to_process);
8081 if (ok_to_process && print_results)
8087 display_debug_info (section, start, file)
8088 Elf_Internal_Shdr *section;
8089 unsigned char *start;
8092 unsigned char *end = start + section->sh_size;
8093 unsigned char *section_begin = start;
8095 //PG - Number of relevant entries to record in the dwarf_entry array
8096 unsigned long num_relevant_entries = 0;
8097 unsigned long idx = 0; // The index in the array, (< dwarf_entry_array_size)
8099 //PG - Do one dummy run to see how many entries need to be put in the dwarf_entry array
8100 // The sole purpose of this run is to get a number into num_relevant_entries
8101 Elf_Internal_Shdr *section_dummy = section;
8102 unsigned char *start_dummy = start;
8103 FILE *file_dummy = file;
8105 unsigned char *end_dummy = start_dummy + section_dummy->sh_size;
8106 unsigned char *section_begin_dummy = start_dummy;
8108 // printf (_("The section %s contains:\n\n"), SECTION_NAME (section_dummy));
8110 load_debug_str (file_dummy);
8111 load_debug_loc (file_dummy);
8113 while (start_dummy < end_dummy)
8115 DWARF2_Internal_CompUnit compunit;
8116 Elf_Internal_Shdr *relsec;
8117 unsigned char *hdrptr;
8118 unsigned char *cu_abbrev_offset_ptr;
8119 unsigned char *tags;
8122 unsigned long cu_offset;
8124 int initial_length_size;
8126 hdrptr = start_dummy;
8128 compunit.cu_length = byte_get (hdrptr, 4);
8131 if (compunit.cu_length == 0xffffffff)
8133 compunit.cu_length = byte_get (hdrptr, 8);
8136 initial_length_size = 12;
8141 initial_length_size = 4;
8144 compunit.cu_version = byte_get (hdrptr, 2);
8147 /* Apply addends of RELA relocations. */
8148 for (relsec = section_headers;
8149 relsec < section_headers + elf_header.e_shnum;
8152 unsigned long nrelas;
8153 Elf_Internal_Rela *rela, *rp;
8154 Elf_Internal_Shdr *symsec;
8155 Elf_Internal_Sym *symtab;
8156 Elf_Internal_Sym *sym;
8158 if (relsec->sh_type != SHT_RELA
8159 || SECTION_HEADER (relsec->sh_info) != section_dummy
8160 || relsec->sh_size == 0)
8163 if (!slurp_rela_relocs (file_dummy, relsec->sh_offset, relsec->sh_size,
8167 symsec = SECTION_HEADER (relsec->sh_link);
8168 symtab = GET_ELF_SYMBOLS (file_dummy, symsec);
8170 for (rp = rela; rp < rela + nrelas; ++rp)
8174 if (rp->r_offset >= (bfd_vma) (hdrptr - section_begin_dummy)
8175 && section_dummy->sh_size > (bfd_vma) offset_size
8176 && rp->r_offset <= section_dummy->sh_size - offset_size)
8177 loc = section_begin_dummy + rp->r_offset;
8183 sym = symtab + ELF32_R_SYM (rp->r_info);
8185 if (ELF32_R_SYM (rp->r_info) != 0
8186 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
8188 warn (_("Skipping unexpected symbol type %u\n"),
8189 ELF32_ST_TYPE (sym->st_info));
8195 sym = symtab + ELF64_R_SYM (rp->r_info);
8197 if (ELF64_R_SYM (rp->r_info) != 0
8198 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
8200 warn (_("Skipping unexpected symbol type %u\n"),
8201 ELF64_ST_TYPE (sym->st_info));
8206 byte_put (loc, rp->r_addend, offset_size);
8213 cu_abbrev_offset_ptr = hdrptr;
8214 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
8215 hdrptr += offset_size;
8217 compunit.cu_pointer_size = byte_get (hdrptr, 1);
8221 cu_offset = start_dummy - section_begin_dummy;
8222 start_dummy += compunit.cu_length + initial_length_size;
8224 // printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
8225 // printf (_(" Length: %ld\n"), compunit.cu_length);
8226 // printf (_(" Version: %d\n"), compunit.cu_version);
8227 // printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
8228 // printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
8230 if (compunit.cu_version != 2 && compunit.cu_version != 3)
8232 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8238 /* Read in the abbrevs used by this compilation unit. */
8240 Elf_Internal_Shdr *sec;
8241 unsigned char *begin;
8243 /* Locate the .debug_abbrev section and process it. */
8244 for (i = 0, sec = section_headers;
8245 i < elf_header.e_shnum;
8247 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
8250 if (i == elf_header.e_shnum || sec->sh_size == 0)
8252 warn (_("Unable to locate .debug_abbrev section!\n"));
8256 begin = ((unsigned char *)
8257 get_data (NULL, file_dummy, sec->sh_offset, sec->sh_size,
8258 _("debug_abbrev section data")));
8262 process_abbrev_section (begin + compunit.cu_abbrev_offset,
8263 begin + sec->sh_size);
8269 while (tags < start_dummy)
8272 unsigned long abbrev_number;
8273 abbrev_entry *entry;
8275 char is_relevant_entry; //PG
8277 abbrev_number = read_leb128 (tags, & bytes_read, 0);
8280 /* A null DIE marks the end of a list of children. */
8281 if (abbrev_number == 0)
8287 /* Scan through the abbreviation list until we reach the
8289 for (entry = first_abbrev;
8290 entry && entry->entry != abbrev_number;
8291 entry = entry->next)
8296 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8301 //PG - increment relevant entry and make a note of it:
8302 is_relevant_entry = tag_is_relevant_entry(entry->tag);
8303 if (is_relevant_entry)
8305 // printf ("RELEVANT ENTRY!!!\n");
8306 num_relevant_entries++;
8309 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8311 (unsigned long) (tags - section_begin_dummy - bytes_read),
8313 get_TAG_name (entry->tag));
8317 for (attr = entry->first_attr; attr; attr = attr->next)
8318 tags = read_and_display_attr (attr->attribute,
8321 compunit.cu_pointer_size,
8323 compunit.cu_version,
8324 entry, /* XXX this can't be right */
8325 0); // parse tags but DO NOT harvest data
8327 if (entry->children)
8336 printf ("Number of relevant entries: %u\n\n", num_relevant_entries);
8338 //PG - End dummy run code
8340 // Construct the global dwarf_entry array
8341 // Question - when do we destroy it???
8342 dwarf_entry_array_size = num_relevant_entries;
8343 initialize_dwarf_entry_array(num_relevant_entries);
8345 //PG - Begin real code
8347 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
8350 load_debug_str (file);
8351 load_debug_loc (file);
8355 DWARF2_Internal_CompUnit compunit;
8356 Elf_Internal_Shdr *relsec;
8357 unsigned char *hdrptr;
8358 unsigned char *cu_abbrev_offset_ptr;
8359 unsigned char *tags;
8362 unsigned long cu_offset;
8364 int initial_length_size;
8368 compunit.cu_length = byte_get (hdrptr, 4);
8371 if (compunit.cu_length == 0xffffffff)
8373 compunit.cu_length = byte_get (hdrptr, 8);
8376 initial_length_size = 12;
8381 initial_length_size = 4;
8384 compunit.cu_version = byte_get (hdrptr, 2);
8387 /* Apply addends of RELA relocations. */
8388 for (relsec = section_headers;
8389 relsec < section_headers + elf_header.e_shnum;
8392 unsigned long nrelas;
8393 Elf_Internal_Rela *rela, *rp;
8394 Elf_Internal_Shdr *symsec;
8395 Elf_Internal_Sym *symtab;
8396 Elf_Internal_Sym *sym;
8398 if (relsec->sh_type != SHT_RELA
8399 || SECTION_HEADER (relsec->sh_info) != section
8400 || relsec->sh_size == 0)
8403 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
8407 symsec = SECTION_HEADER (relsec->sh_link);
8408 symtab = GET_ELF_SYMBOLS (file, symsec);
8410 for (rp = rela; rp < rela + nrelas; ++rp)
8414 if (rp->r_offset >= (bfd_vma) (hdrptr - section_begin)
8415 && section->sh_size > (bfd_vma) offset_size
8416 && rp->r_offset <= section->sh_size - offset_size)
8417 loc = section_begin + rp->r_offset;
8423 sym = symtab + ELF32_R_SYM (rp->r_info);
8425 if (ELF32_R_SYM (rp->r_info) != 0
8426 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
8428 warn (_("Skipping unexpected symbol type %u\n"),
8429 ELF32_ST_TYPE (sym->st_info));
8435 sym = symtab + ELF64_R_SYM (rp->r_info);
8437 if (ELF64_R_SYM (rp->r_info) != 0
8438 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
8440 warn (_("Skipping unexpected symbol type %u\n"),
8441 ELF64_ST_TYPE (sym->st_info));
8446 byte_put (loc, rp->r_addend, offset_size);
8453 cu_abbrev_offset_ptr = hdrptr;
8454 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
8455 hdrptr += offset_size;
8457 compunit.cu_pointer_size = byte_get (hdrptr, 1);
8461 cu_offset = start - section_begin;
8462 start += compunit.cu_length + initial_length_size;
8465 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
8466 printf (_(" Length: %ld\n"), compunit.cu_length);
8467 printf (_(" Version: %d\n"), compunit.cu_version);
8468 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
8469 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
8472 if (compunit.cu_version != 2 && compunit.cu_version != 3)
8474 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8480 /* Read in the abbrevs used by this compilation unit. */
8482 Elf_Internal_Shdr *sec;
8483 unsigned char *begin;
8485 /* Locate the .debug_abbrev section and process it. */
8486 for (i = 0, sec = section_headers;
8487 i < elf_header.e_shnum;
8489 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
8492 if (i == elf_header.e_shnum || sec->sh_size == 0)
8494 warn (_("Unable to locate .debug_abbrev section!\n"));
8498 begin = ((unsigned char *)
8499 get_data (NULL, file, sec->sh_offset, sec->sh_size,
8500 _("debug_abbrev section data")));
8504 process_abbrev_section (begin + compunit.cu_abbrev_offset,
8505 begin + sec->sh_size);
8511 while (tags < start)
8514 unsigned long abbrev_number;
8515 abbrev_entry *entry;
8517 char is_relevant_entry; //PG
8519 abbrev_number = read_leb128 (tags, & bytes_read, 0);
8522 /* A null DIE marks the end of a list of children. */
8523 if (abbrev_number == 0)
8529 /* Scan through the abbreviation list until we reach the
8531 for (entry = first_abbrev;
8532 entry && entry->entry != abbrev_number;
8533 entry = entry->next)
8538 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8543 is_relevant_entry = tag_is_relevant_entry(entry->tag);
8544 if (is_relevant_entry)
8545 //PG - This is where all the action takes place
8546 // store the info. as a dwarf_entry struct in dwarf_entry_array
8548 unsigned long temp_ID = (unsigned long) (tags - section_begin - bytes_read);
8549 unsigned long temp_tag_name = entry->tag;
8551 // Fill the ID and tag_name fields:
8552 dwarf_entry_array[idx].ID = temp_ID;
8553 dwarf_entry_array[idx].tag_name = temp_tag_name;
8554 dwarf_entry_array[idx].level=level;
8556 // Initialize the entry_ptr based on tag_name
8557 initialize_dwarf_entry_ptr(&dwarf_entry_array[idx]);
8561 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8565 get_TAG_name (temp_tag_name));
8568 for (attr = entry->first_attr; attr; attr = attr->next)
8569 tags = read_and_display_attr (attr->attribute,
8572 compunit.cu_pointer_size,
8574 compunit.cu_version,
8575 &dwarf_entry_array[idx],
8578 // printf("Index=%u, ID=%x, tag_name=%s\n",
8580 // dwarf_entry_array[idx].ID,
8581 // get_TAG_name(dwarf_entry_array[idx].tag_name));
8583 if (entry->children)
8590 for (attr = entry->first_attr; attr; attr = attr->next)
8591 tags = read_and_display_attr (attr->attribute,
8594 compunit.cu_pointer_size,
8596 compunit.cu_version,
8598 0); // DO NOT harvest
8600 if (entry->children)
8610 //PG - Now that all of the entries are in the array, finish initializing
8611 // it by creating various links and filling in all dwarf_entry fields
8612 finish_dwarf_entry_array_init();
8614 // print_dwarf_entry_array();
8621 display_debug_aranges (section, start, file)
8622 Elf_Internal_Shdr *section;
8623 unsigned char *start;
8624 FILE *file ATTRIBUTE_UNUSED;
8626 unsigned char *end = start + section->sh_size;
8628 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
8632 unsigned char *hdrptr;
8633 DWARF2_Internal_ARange arange;
8634 unsigned char *ranges;
8635 unsigned long length;
8636 unsigned long address;
8639 int initial_length_size;
8643 arange.ar_length = byte_get (hdrptr, 4);
8646 if (arange.ar_length == 0xffffffff)
8648 arange.ar_length = byte_get (hdrptr, 8);
8651 initial_length_size = 12;
8656 initial_length_size = 4;
8659 arange.ar_version = byte_get (hdrptr, 2);
8662 arange.ar_info_offset = byte_get (hdrptr, offset_size);
8663 hdrptr += offset_size;
8665 arange.ar_pointer_size = byte_get (hdrptr, 1);
8668 arange.ar_segment_size = byte_get (hdrptr, 1);
8671 if (arange.ar_version != 2 && arange.ar_version != 3)
8673 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8677 printf (_(" Length: %ld\n"), arange.ar_length);
8678 printf (_(" Version: %d\n"), arange.ar_version);
8679 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
8680 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
8681 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
8683 printf (_("\n Address Length\n"));
8687 /* Must pad to an alignment boundary that is twice the pointer size. */
8688 excess = (hdrptr - start) % (2 * arange.ar_pointer_size);
8690 ranges += (2 * arange.ar_pointer_size) - excess;
8694 address = byte_get (ranges, arange.ar_pointer_size);
8696 ranges += arange.ar_pointer_size;
8698 length = byte_get (ranges, arange.ar_pointer_size);
8700 ranges += arange.ar_pointer_size;
8702 /* A pair of zeros marks the end of the list. */
8703 if (address == 0 && length == 0)
8706 printf (" %8.8lx %lu\n", address, length);
8709 start += arange.ar_length + initial_length_size;
8717 typedef struct Frame_Chunk
8719 struct Frame_Chunk *next;
8720 unsigned char *chunk_start;
8722 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8723 short int *col_type;
8726 unsigned int code_factor;
8728 unsigned long pc_begin;
8729 unsigned long pc_range;
8733 unsigned char fde_encoding;
8734 unsigned char cfa_exp;
8738 /* A marker for a col_type that means this column was never referenced
8739 in the frame info. */
8740 #define DW_CFA_unreferenced (-1)
8742 static void frame_need_space PARAMS ((Frame_Chunk *, int));
8743 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
8744 static int size_of_encoded_value PARAMS ((int));
8747 frame_need_space (fc, reg)
8751 int prev = fc->ncols;
8753 if (reg < fc->ncols)
8756 fc->ncols = reg + 1;
8757 fc->col_type = (short int *) xrealloc (fc->col_type,
8758 fc->ncols * sizeof (short int));
8759 fc->col_offset = (int *) xrealloc (fc->col_offset,
8760 fc->ncols * sizeof (int));
8762 while (prev < fc->ncols)
8764 fc->col_type[prev] = DW_CFA_unreferenced;
8765 fc->col_offset[prev] = 0;
8771 frame_display_row (fc, need_col_headers, max_regs)
8773 int *need_col_headers;
8779 if (*max_regs < fc->ncols)
8780 *max_regs = fc->ncols;
8782 if (*need_col_headers)
8784 *need_col_headers = 0;
8786 printf (" LOC CFA ");
8788 for (r = 0; r < *max_regs; r++)
8789 if (fc->col_type[r] != DW_CFA_unreferenced)
8794 printf ("r%-4d", r);
8800 printf ("%08lx ", fc->pc_begin);
8802 strcpy (tmp, "exp");
8804 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
8805 printf ("%-8s ", tmp);
8807 for (r = 0; r < fc->ncols; r++)
8809 if (fc->col_type[r] != DW_CFA_unreferenced)
8811 switch (fc->col_type[r])
8813 case DW_CFA_undefined:
8816 case DW_CFA_same_value:
8820 sprintf (tmp, "c%+d", fc->col_offset[r]);
8822 case DW_CFA_register:
8823 sprintf (tmp, "r%d", fc->col_offset[r]);
8825 case DW_CFA_expression:
8826 strcpy (tmp, "exp");
8829 strcpy (tmp, "n/a");
8832 printf ("%-5s", tmp);
8839 size_of_encoded_value (encoding)
8842 switch (encoding & 0x7)
8845 case 0: return is_32bit_elf ? 4 : 8;
8852 #define GET(N) byte_get (start, N); start += N
8853 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8854 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8857 display_debug_frames (section, start, file)
8858 Elf_Internal_Shdr *section;
8859 unsigned char *start;
8860 FILE *file ATTRIBUTE_UNUSED;
8862 unsigned char *end = start + section->sh_size;
8863 unsigned char *section_start = start;
8864 Frame_Chunk *chunks = 0;
8865 Frame_Chunk *remembered_state = 0;
8867 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
8870 int addr_size = is_32bit_elf ? 4 : 8;
8872 printf (_("The section %s contains:\n"), SECTION_NAME (section));
8876 unsigned char *saved_start;
8877 unsigned char *block_end;
8878 unsigned long length;
8879 unsigned long cie_id;
8882 int need_col_headers = 1;
8883 unsigned char *augmentation_data = NULL;
8884 unsigned long augmentation_data_len = 0;
8885 int encoded_ptr_size = addr_size;
8887 int initial_length_size;
8889 saved_start = start;
8890 length = byte_get (start, 4); start += 4;
8894 printf ("\n%08lx ZERO terminator\n\n",
8895 (unsigned long)(saved_start - section_start));
8899 if (length == 0xffffffff)
8901 length = byte_get (start, 8);
8904 initial_length_size = 12;
8909 initial_length_size = 4;
8912 block_end = saved_start + length + initial_length_size;
8913 cie_id = byte_get (start, offset_size); start += offset_size;
8915 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
8919 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8920 memset (fc, 0, sizeof (Frame_Chunk));
8924 fc->chunk_start = saved_start;
8926 fc->col_type = (short int *) xmalloc (sizeof (short int));
8927 fc->col_offset = (int *) xmalloc (sizeof (int));
8928 frame_need_space (fc, max_regs-1);
8932 fc->augmentation = start;
8933 start = strchr (start, '\0') + 1;
8935 if (fc->augmentation[0] == 'z')
8937 fc->code_factor = LEB ();
8938 fc->data_factor = SLEB ();
8939 fc->ra = byte_get (start, 1); start += 1;
8940 augmentation_data_len = LEB ();
8941 augmentation_data = start;
8942 start += augmentation_data_len;
8944 else if (strcmp (fc->augmentation, "eh") == 0)
8947 fc->code_factor = LEB ();
8948 fc->data_factor = SLEB ();
8949 fc->ra = byte_get (start, 1); start += 1;
8953 fc->code_factor = LEB ();
8954 fc->data_factor = SLEB ();
8955 fc->ra = byte_get (start, 1); start += 1;
8959 if (do_debug_frames_interp)
8960 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8961 (unsigned long)(saved_start - section_start), length, cie_id,
8962 fc->augmentation, fc->code_factor, fc->data_factor,
8966 printf ("\n%08lx %08lx %08lx CIE\n",
8967 (unsigned long)(saved_start - section_start), length, cie_id);
8968 printf (" Version: %d\n", version);
8969 printf (" Augmentation: \"%s\"\n", fc->augmentation);
8970 printf (" Code alignment factor: %u\n", fc->code_factor);
8971 printf (" Data alignment factor: %d\n", fc->data_factor);
8972 printf (" Return address column: %d\n", fc->ra);
8974 if (augmentation_data_len)
8977 printf (" Augmentation data: ");
8978 for (i = 0; i < augmentation_data_len; ++i)
8979 printf (" %02x", augmentation_data[i]);
8985 if (augmentation_data_len)
8987 unsigned char *p, *q;
8988 p = fc->augmentation + 1;
8989 q = augmentation_data;
8996 q += 1 + size_of_encoded_value (*q);
8998 fc->fde_encoding = *q++;
9004 if (fc->fde_encoding)
9005 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
9008 frame_need_space (fc, fc->ra);
9012 unsigned char *look_for;
9013 static Frame_Chunk fde_fc;
9016 memset (fc, 0, sizeof (Frame_Chunk));
9018 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
9020 for (cie = chunks; cie ; cie = cie->next)
9021 if (cie->chunk_start == look_for)
9026 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
9027 cie_id, saved_start);
9030 fc->col_type = (short int *) xmalloc (sizeof (short int));
9031 fc->col_offset = (int *) xmalloc (sizeof (int));
9032 frame_need_space (fc, max_regs - 1);
9034 fc->augmentation = "";
9035 fc->fde_encoding = 0;
9039 fc->ncols = cie->ncols;
9040 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
9041 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
9042 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
9043 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
9044 fc->augmentation = cie->augmentation;
9045 fc->code_factor = cie->code_factor;
9046 fc->data_factor = cie->data_factor;
9047 fc->cfa_reg = cie->cfa_reg;
9048 fc->cfa_offset = cie->cfa_offset;
9050 frame_need_space (fc, max_regs-1);
9051 fc->fde_encoding = cie->fde_encoding;
9054 if (fc->fde_encoding)
9055 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
9057 fc->pc_begin = byte_get (start, encoded_ptr_size);
9058 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
9059 fc->pc_begin += section->sh_addr + (start - section_start);
9060 start += encoded_ptr_size;
9061 fc->pc_range = byte_get (start, encoded_ptr_size);
9062 start += encoded_ptr_size;
9064 if (cie->augmentation[0] == 'z')
9066 augmentation_data_len = LEB ();
9067 augmentation_data = start;
9068 start += augmentation_data_len;
9071 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
9072 (unsigned long)(saved_start - section_start), length, cie_id,
9073 (unsigned long)(cie->chunk_start - section_start),
9074 fc->pc_begin, fc->pc_begin + fc->pc_range);
9075 if (! do_debug_frames_interp && augmentation_data_len)
9078 printf (" Augmentation data: ");
9079 for (i = 0; i < augmentation_data_len; ++i)
9080 printf (" %02x", augmentation_data[i]);
9086 /* At this point, fc is the current chunk, cie (if any) is set, and we're
9087 about to interpret instructions for the chunk. */
9089 if (do_debug_frames_interp)
9091 /* Start by making a pass over the chunk, allocating storage
9092 and taking note of what registers are used. */
9093 unsigned char *tmp = start;
9095 while (start < block_end)
9098 unsigned long reg, temp;
9105 /* Warning: if you add any more cases to this switch, be
9106 sure to add them to the corresponding switch below. */
9109 case DW_CFA_advance_loc:
9113 frame_need_space (fc, opa);
9114 fc->col_type[opa] = DW_CFA_undefined;
9116 case DW_CFA_restore:
9117 frame_need_space (fc, opa);
9118 fc->col_type[opa] = DW_CFA_undefined;
9120 case DW_CFA_set_loc:
9121 start += encoded_ptr_size;
9123 case DW_CFA_advance_loc1:
9126 case DW_CFA_advance_loc2:
9129 case DW_CFA_advance_loc4:
9132 case DW_CFA_offset_extended:
9133 reg = LEB (); LEB ();
9134 frame_need_space (fc, reg);
9135 fc->col_type[reg] = DW_CFA_undefined;
9137 case DW_CFA_restore_extended:
9139 frame_need_space (fc, reg);
9140 fc->col_type[reg] = DW_CFA_undefined;
9142 case DW_CFA_undefined:
9144 frame_need_space (fc, reg);
9145 fc->col_type[reg] = DW_CFA_undefined;
9147 case DW_CFA_same_value:
9149 frame_need_space (fc, reg);
9150 fc->col_type[reg] = DW_CFA_undefined;
9152 case DW_CFA_register:
9153 reg = LEB (); LEB ();
9154 frame_need_space (fc, reg);
9155 fc->col_type[reg] = DW_CFA_undefined;
9157 case DW_CFA_def_cfa:
9160 case DW_CFA_def_cfa_register:
9163 case DW_CFA_def_cfa_offset:
9166 case DW_CFA_def_cfa_expression:
9170 case DW_CFA_expression:
9174 frame_need_space (fc, reg);
9175 fc->col_type[reg] = DW_CFA_undefined;
9177 case DW_CFA_offset_extended_sf:
9178 reg = LEB (); SLEB ();
9179 frame_need_space (fc, reg);
9180 fc->col_type[reg] = DW_CFA_undefined;
9182 case DW_CFA_def_cfa_sf:
9185 case DW_CFA_def_cfa_offset_sf:
9188 case DW_CFA_MIPS_advance_loc8:
9191 case DW_CFA_GNU_args_size:
9194 case DW_CFA_GNU_negative_offset_extended:
9195 reg = LEB (); LEB ();
9196 frame_need_space (fc, reg);
9197 fc->col_type[reg] = DW_CFA_undefined;
9206 /* Now we know what registers are used, make a second pass over
9207 the chunk, this time actually printing out the info. */
9209 while (start < block_end)
9212 unsigned long ul, reg, roffs;
9221 /* Warning: if you add any more cases to this switch, be
9222 sure to add them to the corresponding switch above. */
9225 case DW_CFA_advance_loc:
9226 if (do_debug_frames_interp)
9227 frame_display_row (fc, &need_col_headers, &max_regs);
9229 printf (" DW_CFA_advance_loc: %d to %08lx\n",
9230 opa * fc->code_factor,
9231 fc->pc_begin + opa * fc->code_factor);
9232 fc->pc_begin += opa * fc->code_factor;
9237 if (! do_debug_frames_interp)
9238 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
9239 opa, roffs * fc->data_factor);
9240 fc->col_type[opa] = DW_CFA_offset;
9241 fc->col_offset[opa] = roffs * fc->data_factor;
9244 case DW_CFA_restore:
9245 if (! do_debug_frames_interp)
9246 printf (" DW_CFA_restore: r%d\n", opa);
9247 fc->col_type[opa] = cie->col_type[opa];
9248 fc->col_offset[opa] = cie->col_offset[opa];
9251 case DW_CFA_set_loc:
9252 vma = byte_get (start, encoded_ptr_size);
9253 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
9254 vma += section->sh_addr + (start - section_start);
9255 start += encoded_ptr_size;
9256 if (do_debug_frames_interp)
9257 frame_display_row (fc, &need_col_headers, &max_regs);
9259 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
9263 case DW_CFA_advance_loc1:
9264 ofs = byte_get (start, 1); start += 1;
9265 if (do_debug_frames_interp)
9266 frame_display_row (fc, &need_col_headers, &max_regs);
9268 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
9269 ofs * fc->code_factor,
9270 fc->pc_begin + ofs * fc->code_factor);
9271 fc->pc_begin += ofs * fc->code_factor;
9274 case DW_CFA_advance_loc2:
9275 ofs = byte_get (start, 2); start += 2;
9276 if (do_debug_frames_interp)
9277 frame_display_row (fc, &need_col_headers, &max_regs);
9279 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
9280 ofs * fc->code_factor,
9281 fc->pc_begin + ofs * fc->code_factor);
9282 fc->pc_begin += ofs * fc->code_factor;
9285 case DW_CFA_advance_loc4:
9286 ofs = byte_get (start, 4); start += 4;
9287 if (do_debug_frames_interp)
9288 frame_display_row (fc, &need_col_headers, &max_regs);
9290 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
9291 ofs * fc->code_factor,
9292 fc->pc_begin + ofs * fc->code_factor);
9293 fc->pc_begin += ofs * fc->code_factor;
9296 case DW_CFA_offset_extended:
9299 if (! do_debug_frames_interp)
9300 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9301 reg, roffs * fc->data_factor);
9302 fc->col_type[reg] = DW_CFA_offset;
9303 fc->col_offset[reg] = roffs * fc->data_factor;
9306 case DW_CFA_restore_extended:
9308 if (! do_debug_frames_interp)
9309 printf (" DW_CFA_restore_extended: r%ld\n", reg);
9310 fc->col_type[reg] = cie->col_type[reg];
9311 fc->col_offset[reg] = cie->col_offset[reg];
9314 case DW_CFA_undefined:
9316 if (! do_debug_frames_interp)
9317 printf (" DW_CFA_undefined: r%ld\n", reg);
9318 fc->col_type[reg] = DW_CFA_undefined;
9319 fc->col_offset[reg] = 0;
9322 case DW_CFA_same_value:
9324 if (! do_debug_frames_interp)
9325 printf (" DW_CFA_same_value: r%ld\n", reg);
9326 fc->col_type[reg] = DW_CFA_same_value;
9327 fc->col_offset[reg] = 0;
9330 case DW_CFA_register:
9333 if (! do_debug_frames_interp)
9334 printf (" DW_CFA_register: r%ld\n", reg);
9335 fc->col_type[reg] = DW_CFA_register;
9336 fc->col_offset[reg] = roffs;
9339 case DW_CFA_remember_state:
9340 if (! do_debug_frames_interp)
9341 printf (" DW_CFA_remember_state\n");
9342 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
9343 rs->ncols = fc->ncols;
9344 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
9345 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
9346 memcpy (rs->col_type, fc->col_type, rs->ncols);
9347 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
9348 rs->next = remembered_state;
9349 remembered_state = rs;
9352 case DW_CFA_restore_state:
9353 if (! do_debug_frames_interp)
9354 printf (" DW_CFA_restore_state\n");
9355 rs = remembered_state;
9356 remembered_state = rs->next;
9357 frame_need_space (fc, rs->ncols-1);
9358 memcpy (fc->col_type, rs->col_type, rs->ncols);
9359 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
9360 free (rs->col_type);
9361 free (rs->col_offset);
9365 case DW_CFA_def_cfa:
9366 fc->cfa_reg = LEB ();
9367 fc->cfa_offset = LEB ();
9369 if (! do_debug_frames_interp)
9370 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9371 fc->cfa_reg, fc->cfa_offset);
9374 case DW_CFA_def_cfa_register:
9375 fc->cfa_reg = LEB ();
9377 if (! do_debug_frames_interp)
9378 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
9381 case DW_CFA_def_cfa_offset:
9382 fc->cfa_offset = LEB ();
9383 if (! do_debug_frames_interp)
9384 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
9388 if (! do_debug_frames_interp)
9389 printf (" DW_CFA_nop\n");
9392 case DW_CFA_def_cfa_expression:
9394 if (! do_debug_frames_interp)
9396 printf (" DW_CFA_def_cfa_expression (");
9397 decode_location_expression (start, addr_size, ul, 1, 0);
9404 case DW_CFA_expression:
9407 if (! do_debug_frames_interp)
9409 printf (" DW_CFA_expression: r%ld (", reg);
9410 decode_location_expression (start, addr_size, ul, 1, 0);
9413 fc->col_type[reg] = DW_CFA_expression;
9417 case DW_CFA_offset_extended_sf:
9420 frame_need_space (fc, reg);
9421 if (! do_debug_frames_interp)
9422 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9423 reg, l * fc->data_factor);
9424 fc->col_type[reg] = DW_CFA_offset;
9425 fc->col_offset[reg] = l * fc->data_factor;
9428 case DW_CFA_def_cfa_sf:
9429 fc->cfa_reg = LEB ();
9430 fc->cfa_offset = SLEB ();
9432 if (! do_debug_frames_interp)
9433 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9434 fc->cfa_reg, fc->cfa_offset);
9437 case DW_CFA_def_cfa_offset_sf:
9438 fc->cfa_offset = SLEB ();
9439 if (! do_debug_frames_interp)
9440 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
9443 case DW_CFA_MIPS_advance_loc8:
9444 ofs = byte_get (start, 8); start += 8;
9445 if (do_debug_frames_interp)
9446 frame_display_row (fc, &need_col_headers, &max_regs);
9448 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
9449 ofs * fc->code_factor,
9450 fc->pc_begin + ofs * fc->code_factor);
9451 fc->pc_begin += ofs * fc->code_factor;
9454 case DW_CFA_GNU_window_save:
9455 if (! do_debug_frames_interp)
9456 printf (" DW_CFA_GNU_window_save\n");
9459 case DW_CFA_GNU_args_size:
9461 if (! do_debug_frames_interp)
9462 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
9465 case DW_CFA_GNU_negative_offset_extended:
9468 frame_need_space (fc, reg);
9469 if (! do_debug_frames_interp)
9470 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9471 reg, l * fc->data_factor);
9472 fc->col_type[reg] = DW_CFA_offset;
9473 fc->col_offset[reg] = l * fc->data_factor;
9477 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
9482 if (do_debug_frames_interp)
9483 frame_display_row (fc, &need_col_headers, &max_regs);
9498 display_debug_not_supported (section, start, file)
9499 Elf_Internal_Shdr *section;
9500 unsigned char *start ATTRIBUTE_UNUSED;
9501 FILE *file ATTRIBUTE_UNUSED;
9503 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9504 SECTION_NAME (section));
9509 /* Pre-scan the .debug_info section to record the size of address.
9510 When dumping the .debug_line, we use that size information, assuming
9511 that all compilation units have the same address size. */
9513 prescan_debug_info (section, start, file)
9514 Elf_Internal_Shdr *section ATTRIBUTE_UNUSED;
9515 unsigned char *start;
9516 FILE *file ATTRIBUTE_UNUSED;
9518 unsigned long length;
9520 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
9521 be the length. For a 64-bit DWARF section, it'll be the escape
9522 code 0xffffffff followed by an 8 byte length. For the purposes
9523 of this prescan, we don't care about the actual length, but the
9524 presence of the escape bytes does affect the location of the byte
9525 which describes the address size. */
9526 length = byte_get (start, 4);
9528 if (length == 0xffffffff)
9530 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
9531 from the start of the section. This is computed as follows:
9533 unit_length: 12 bytes
9535 debug_abbrev_offset: 8 bytes
9536 -----------------------------
9539 debug_line_pointer_size = byte_get (start + 22, 1);
9543 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
9544 the start of the section:
9545 unit_length: 4 bytes
9547 debug_abbrev_offset: 4 bytes
9548 -----------------------------
9551 debug_line_pointer_size = byte_get (start + 10, 1);
9556 /* A structure containing the name of a debug section and a pointer
9557 to a function that can decode it. The third field is a prescan
9558 function to be run over the section before displaying any of the
9562 const char *const name;
9563 int (*display) PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
9564 int (*prescan) PARAMS ((Elf_Internal_Shdr *, unsigned char *, FILE *));
9568 { ".debug_abbrev", display_debug_abbrev, NULL },
9569 { ".debug_aranges", display_debug_aranges, NULL },
9570 { ".debug_frame", display_debug_frames, NULL },
9571 { ".debug_info", display_debug_info, prescan_debug_info },
9572 { ".debug_line", display_debug_lines, NULL },
9573 { ".debug_pubnames", display_debug_pubnames, NULL },
9574 { ".eh_frame", display_debug_frames, NULL },
9575 { ".debug_macinfo", display_debug_macinfo, NULL },
9576 { ".debug_str", display_debug_str, NULL },
9577 { ".debug_loc", display_debug_loc, NULL },
9578 { ".debug_pubtypes", display_debug_not_supported, NULL },
9579 { ".debug_ranges", display_debug_not_supported, NULL },
9580 { ".debug_static_func", display_debug_not_supported, NULL },
9581 { ".debug_static_vars", display_debug_not_supported, NULL },
9582 { ".debug_types", display_debug_not_supported, NULL },
9583 { ".debug_weaknames", display_debug_not_supported, NULL }
9587 display_debug_section (section, file)
9588 Elf_Internal_Shdr *section;
9591 char *name = SECTION_NAME (section);
9592 bfd_size_type length;
9593 unsigned char *start;
9596 length = section->sh_size;
9599 printf (_("\nSection '%s' has no debugging data.\n"), name);
9603 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
9604 _("debug section data"));
9608 /* See if we know how to display the contents of this section. */
9609 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
9610 name = ".debug_info";
9612 for (i = NUM_ELEM (debug_displays); i--;)
9613 if (strcmp (debug_displays[i].name, name) == 0)
9615 debug_displays[i].display (section, start, file);
9620 printf (_("Unrecognized debug section: %s\n"), name);
9624 /* If we loaded in the abbrev section at some point,
9625 we must release it here. */
9632 process_section_contents (file)
9635 Elf_Internal_Shdr *section;
9641 // printf("process_section_contents() - before 1st for loop\n");
9643 /* Pre-scan the debug sections to find some debug information not
9644 present in some of them. For the .debug_line, we must find out the
9645 size of address (specified in .debug_info and .debug_aranges). */
9646 for (i = 0, section = section_headers;
9647 i < elf_header.e_shnum && i < num_dump_sects;
9650 char *name = SECTION_NAME (section);
9653 if (section->sh_size == 0)
9656 /* See if there is some pre-scan operation for this section. */
9657 for (j = NUM_ELEM (debug_displays); j--;)
9658 if (strcmp (debug_displays[j].name, name) == 0)
9660 if (debug_displays[j].prescan != NULL)
9662 bfd_size_type length;
9663 unsigned char *start;
9665 length = section->sh_size;
9666 start = ((unsigned char *)
9667 get_data (NULL, file, section->sh_offset, length,
9668 _("debug section data")));
9672 debug_displays[j].prescan (section, start, file);
9680 // printf("process_section_contents() - before 2nd for loop\n");
9682 for (i = 0, section = section_headers;
9683 i < elf_header.e_shnum && i < num_dump_sects;
9686 #ifdef SUPPORT_DISASSEMBLY
9687 if (dump_sects[i] & DISASS_DUMP)
9688 disassemble_section (section, file);
9690 if (dump_sects[i] & HEX_DUMP)
9692 dump_section (section, file);
9695 if (dump_sects[i] & DEBUG_DUMP)
9697 display_debug_section (section, file);
9701 // printf("process_section_contents() - after 2nd for loop\n");
9703 if (i < num_dump_sects)
9705 warn (_("Some sections were not dumped because they do not exist!\n"));
9712 process_mips_specific (file)
9715 /* We have a lot of special sections. Thanks SGI! */
9716 if (dynamic_segment == NULL)
9717 /* No information available. */
9723 process_gnu_liblist (file)
9730 get_note_type (e_type)
9733 static char buff[64];
9737 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
9738 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
9739 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
9740 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
9741 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
9742 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
9743 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
9744 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
9745 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9746 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9747 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9749 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9755 get_netbsd_elfcore_note_type (e_type)
9758 static char buff[64];
9760 if (e_type == NT_NETBSDCORE_PROCINFO)
9762 /* NetBSD core "procinfo" structure. */
9763 return _("NetBSD procinfo structure");
9766 /* As of Jan 2002 there are no other machine-independent notes
9767 defined for NetBSD core files. If the note type is less
9768 than the start of the machine-dependent note types, we don't
9771 if (e_type < NT_NETBSDCORE_FIRSTMACH)
9773 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9777 switch (elf_header.e_machine)
9779 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9780 and PT_GETFPREGS == mach+2. */
9785 case EM_SPARC32PLUS:
9789 case NT_NETBSDCORE_FIRSTMACH+0:
9790 return _("PT_GETREGS (reg structure)");
9791 case NT_NETBSDCORE_FIRSTMACH+2:
9792 return _("PT_GETFPREGS (fpreg structure)");
9798 /* On all other arch's, PT_GETREGS == mach+1 and
9799 PT_GETFPREGS == mach+3. */
9803 case NT_NETBSDCORE_FIRSTMACH+1:
9804 return _("PT_GETREGS (reg structure)");
9805 case NT_NETBSDCORE_FIRSTMACH+3:
9806 return _("PT_GETFPREGS (fpreg structure)");
9812 sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
9816 /* Note that by the ELF standard, the name field is already null byte
9817 terminated, and namesz includes the terminating null byte.
9818 I.E. the value of namesz for the name "FSF" is 4.
9820 If the value of namesz is zero, there is no name present. */
9822 process_note (pnote)
9823 Elf_Internal_Note *pnote;
9827 if (pnote->namesz == 0)
9829 /* If there is no note name, then use the default set of
9830 note type strings. */
9831 nt = get_note_type (pnote->type);
9833 else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
9835 /* NetBSD-specific core file notes. */
9836 nt = get_netbsd_elfcore_note_type (pnote->type);
9840 /* Don't recognize this note name; just use the default set of
9841 note type strings. */
9842 nt = get_note_type (pnote->type);
9845 printf (" %s\t\t0x%08lx\t%s\n",
9846 pnote->namesz ? pnote->namedata : "(NONE)",
9853 process_corefile_note_segment (file, offset, length)
9858 Elf_External_Note *pnotes;
9859 Elf_External_Note *external;
9865 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
9872 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9873 (unsigned long) offset, (unsigned long) length);
9874 printf (_(" Owner\t\tData size\tDescription\n"));
9876 while (external < (Elf_External_Note *)((char *) pnotes + length))
9878 Elf_External_Note *next;
9879 Elf_Internal_Note inote;
9882 inote.type = BYTE_GET (external->type);
9883 inote.namesz = BYTE_GET (external->namesz);
9884 inote.namedata = external->name;
9885 inote.descsz = BYTE_GET (external->descsz);
9886 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
9887 inote.descpos = offset + (inote.descdata - (char *) pnotes);
9889 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
9891 if (((char *) next) > (((char *) pnotes) + length))
9893 warn (_("corrupt note found at offset %x into core notes\n"),
9894 ((char *) external) - ((char *) pnotes));
9895 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
9896 inote.type, inote.namesz, inote.descsz);
9902 /* Verify that name is null terminated. It appears that at least
9903 one version of Linux (RedHat 6.0) generates corefiles that don't
9904 comply with the ELF spec by failing to include the null byte in
9906 if (inote.namedata[inote.namesz] != '\0')
9908 temp = malloc (inote.namesz + 1);
9912 error (_("Out of memory\n"));
9917 strncpy (temp, inote.namedata, inote.namesz);
9918 temp[inote.namesz] = 0;
9920 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9921 inote.namedata = temp;
9924 res &= process_note (& inote);
9939 process_corefile_note_segments (file)
9942 Elf_Internal_Phdr *program_headers;
9943 Elf_Internal_Phdr *segment;
9947 program_headers = (Elf_Internal_Phdr *) malloc
9948 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
9950 if (program_headers == NULL)
9952 error (_("Out of memory\n"));
9957 i = get_32bit_program_headers (file, program_headers);
9959 i = get_64bit_program_headers (file, program_headers);
9963 free (program_headers);
9967 for (i = 0, segment = program_headers;
9968 i < elf_header.e_phnum;
9971 if (segment->p_type == PT_NOTE)
9972 res &= process_corefile_note_segment (file,
9973 (bfd_vma) segment->p_offset,
9974 (bfd_vma) segment->p_filesz);
9977 free (program_headers);
9983 process_corefile_contents (file)
9986 /* If we have not been asked to display the notes then do nothing. */
9990 /* If file is not a core file then exit. */
9991 if (elf_header.e_type != ET_CORE)
9994 /* No program headers means no NOTE segment. */
9995 if (elf_header.e_phnum == 0)
9997 printf (_("No note segments present in the core file.\n"));
10001 return process_corefile_note_segments (file);
10005 process_arch_specific (file)
10011 switch (elf_header.e_machine)
10014 case EM_MIPS_RS3_LE:
10015 return process_mips_specific (file);
10024 get_file_header (file)
10027 /* Read in the identity array. */
10028 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
10031 /* Determine how to read the rest of the header. */
10032 switch (elf_header.e_ident[EI_DATA])
10034 default: /* fall through */
10035 case ELFDATANONE: /* fall through */
10037 byte_get = byte_get_little_endian;
10038 byte_put = byte_put_little_endian;
10041 byte_get = byte_get_big_endian;
10042 byte_put = byte_put_big_endian;
10046 /* For now we only support 32 bit and 64 bit ELF files. */
10047 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
10049 /* Read in the rest of the header. */
10052 Elf32_External_Ehdr ehdr32;
10054 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
10057 elf_header.e_type = BYTE_GET (ehdr32.e_type);
10058 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
10059 elf_header.e_version = BYTE_GET (ehdr32.e_version);
10060 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
10061 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
10062 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
10063 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
10064 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
10065 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
10066 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
10067 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
10068 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
10069 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
10073 Elf64_External_Ehdr ehdr64;
10075 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10076 we will not be able to cope with the 64bit data found in
10077 64 ELF files. Detect this now and abort before we start
10078 overwritting things. */
10079 if (sizeof (bfd_vma) < 8)
10081 error (_("This instance of readelf has been built without support for a\n\
10082 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10086 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
10089 elf_header.e_type = BYTE_GET (ehdr64.e_type);
10090 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
10091 elf_header.e_version = BYTE_GET (ehdr64.e_version);
10092 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
10093 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
10094 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
10095 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
10096 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
10097 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
10098 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
10099 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
10100 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
10101 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
10104 if (elf_header.e_shoff)
10106 /* There may be some extensions in the first section header. Don't
10107 bomb if we can't read it. */
10109 get_32bit_section_headers (file, 1);
10111 get_64bit_section_headers (file, 1);
10118 process_file (file_name)
10122 struct stat statbuf;
10125 if (stat (file_name, & statbuf) < 0)
10127 error (_("Cannot stat input file %s.\n"), file_name);
10131 file = fopen (file_name, "rb");
10134 error (_("Input file %s not found.\n"), file_name);
10138 if (! get_file_header (file))
10140 error (_("%s: Failed to read file header\n"), file_name);
10145 /* Initialise per file variables. */
10146 for (i = NUM_ELEM (version_info); i--;)
10147 version_info[i] = 0;
10149 for (i = NUM_ELEM (dynamic_info); i--;)
10150 dynamic_info[i] = 0;
10152 /* Process the file. */
10155 printf (_("\nFile: %s\n"), file_name);
10158 // printf("before process_file_header()\n"); //PG
10160 if (! process_file_header ())
10162 printf("failed process_file_header()\n"); //PG
10167 // printf("before process_section_headers()\n"); //PG
10169 if (! process_section_headers (file))
10171 printf("failed process_section_headers()\n"); //PG
10172 /* Without loaded section headers we
10173 cannot process lots of things. */
10174 do_unwind = do_version = do_dump = do_arch = 0;
10176 if (! do_using_dynamic)
10177 do_syms = do_reloc = 0;
10180 // printf("before process_program_headers()\n"); //PG
10182 if (process_program_headers (file))
10183 process_dynamic_segment (file);
10184 // printf("before process_relocs()\n"); //PG
10185 process_relocs (file);
10186 // printf("before process_unwind()\n"); //PG
10187 process_unwind (file);
10188 // printf("before process_symbol_table()\n"); //PG
10189 process_symbol_table (file);
10190 // printf("before process_syminfo()\n"); //PG
10191 process_syminfo (file);
10192 // printf("before process_version_sections()\n"); //PG
10193 process_version_sections (file);
10194 // printf("before process_section_contents()\n"); //PG
10195 process_section_contents (file);
10196 // printf("before process_corefile_contents()\n"); //PG
10197 process_corefile_contents (file);
10198 // printf("before process_gnu_liblist()\n"); //PG
10199 process_gnu_liblist (file);
10200 // printf("before process_arch_specific()\n"); //PG
10201 process_arch_specific (file);
10205 if (section_headers)
10207 free (section_headers);
10208 section_headers = NULL;
10213 free (string_table);
10214 string_table = NULL;
10215 string_table_length = 0;
10218 if (dynamic_strings)
10220 free (dynamic_strings);
10221 dynamic_strings = NULL;
10224 if (dynamic_symbols)
10226 free (dynamic_symbols);
10227 dynamic_symbols = NULL;
10228 num_dynamic_syms = 0;
10231 if (dynamic_syminfo)
10233 free (dynamic_syminfo);
10234 dynamic_syminfo = NULL;
10240 #ifdef SUPPORT_DISASSEMBLY
10241 /* Needed by the i386 disassembler. For extra credit, someone could
10242 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10246 print_address (unsigned int addr, FILE *outfile)
10248 fprintf (outfile,"0x%8.8x", addr);
10251 /* Needed by the i386 disassembler. */
10253 db_task_printsym (unsigned int addr)
10255 print_address (addr, stderr);
10259 //PG insert a fake main which is a hacked copy that can be called
10260 // with a filename argument
10262 int process_elf_binary_data(char* filename)
10265 char *cmdline_dump_sects = NULL;
10267 char **hack_argv = 0;
10270 static char default_exec_name[10] = "./readelf"; // dummy!!! (why size 10 instead of 9?)
10271 static char default_option[17] = "--debug-dump=info";
10274 // for (i = 0; i < argc; i++)
10275 // printf("argv[%d] = %s\n", i, argv[i]);
10277 // printf("\n-------------------------------------\n\n");
10280 argument format - argv[0] is executable, argv[1] is the option that we
10281 want to hijack "--debug-dump=info", and argv[2] is the filename
10282 argv[0] = ./readelf (executable name)
10283 argv[1] = --debug-dump=info (desired option)
10284 argv[2] = ../tests/TypesTest/TypesTest (filename)
10286 Here is my hack. Instead of requiring the user to pass in --debug-dump=info,
10287 we just make the user pass in the filename as the only argument and then
10288 apply --debug-dump=info by default
10290 Let's create our own hack_argv array:
10292 hack_argv[0] = "./readelf"
10293 hack_argv[1] = "--debug-dump=info"
10294 hack_argv[2] = filename
10297 // Allocate three character pointer
10298 hack_argv = malloc(3 * sizeof(*hack_argv));
10300 hack_argv[0] = default_exec_name;
10301 hack_argv[1] = default_option;
10302 hack_argv[2] = filename;
10305 printf("filename: 0x%x\n", filename);
10306 for (i = 0; i < argc; i++)
10307 printf("hack_argv[%d] = %s\n", i, hack_argv[i]);
10309 printf("\n-------------------------------------\n\n");
10312 // PG - now hijack parse_args and pass in my hacked argv
10313 // parse_args (argc, argv);
10314 // printf("before parse_args(%d, 0x%x)\n", argc, hack_argv);
10315 parse_args (argc, hack_argv);
10316 // printf("after parse_args\n");
10317 // printf("optind = %d\n", optind);
10319 // if (optind < (argc - 1))
10322 /* When processing more than one file remember the dump requests
10323 issued on command line to reset them after each file. */
10326 if (optind + 1 < argc && dump_sects != NULL)
10328 cmdline_dump_sects = malloc (num_dump_sects);
10329 if (cmdline_dump_sects == NULL)
10330 error (_("Out of memory allocating dump request table."));
10333 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
10334 num_cmdline_dump_sects = num_dump_sects;
10340 // while (optind < argc)
10342 // err |= process_file (hack_argv[optind++]); //PG - replace argv with hack_argv
10344 // /* Reset dump requests. */
10345 // if (optind < argc && dump_sects != NULL)
10347 // num_dump_sects = num_cmdline_dump_sects;
10348 // if (num_cmdline_dump_sects > 0)
10349 // memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
10353 err = process_file (hack_argv[argc - 1]); //PG - replace argv with hack_argv
10355 // printf("AFTER process_file(0x%x)\n", hack_argv[argc-1]);
10357 if (dump_sects != NULL)
10359 if (cmdline_dump_sects != NULL)
10360 free (cmdline_dump_sects);
10367 int main PARAMS ((int, char **));
10374 int status = process_elf_binary_data(argv[argc-1]); // Past last argument, which should be target filename