1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005-2013 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
32 #if !HAVE_DECL_STRNLEN
33 size_t strnlen (const char *, size_t);
36 static const char *regname (unsigned int regno, int row);
38 static int have_frame_base;
39 static int need_base_address;
41 static unsigned int last_pointer_size = 0;
42 static int warned_about_missing_comp_units = FALSE;
44 static unsigned int num_debug_info_entries = 0;
45 static debug_info *debug_information = NULL;
46 /* Special value for num_debug_info_entries to indicate
47 that the .debug_info section could not be loaded/parsed. */
48 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
55 int do_debug_pubnames;
56 int do_debug_pubtypes;
60 int do_debug_frames_interp;
69 int do_debug_cu_index;
72 int dwarf_cutoff_level = -1;
73 unsigned long dwarf_start_die;
77 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
78 sections. For version 1 package files, each set is stored in SHNDX_POOL
79 as a zero-terminated list of section indexes comprising one set of debug
80 sections from a .dwo file. */
82 static int cu_tu_indexes_read = 0;
83 static unsigned int *shndx_pool = NULL;
84 static unsigned int shndx_pool_size = 0;
85 static unsigned int shndx_pool_used = 0;
87 /* For version 2 package files, each set contains an array of section offsets
88 and an array of section sizes, giving the offset and size of the
89 contribution from a CU or TU within one of the debug sections.
90 When displaying debug info from a package file, we need to use these
91 tables to locate the corresponding contributions to each section. */
96 dwarf_vma section_offsets[DW_SECT_MAX];
97 size_t section_sizes[DW_SECT_MAX];
100 static int cu_count = 0;
101 static int tu_count = 0;
102 static struct cu_tu_set *cu_sets = NULL;
103 static struct cu_tu_set *tu_sets = NULL;
105 static void load_cu_tu_indexes (void *file);
107 /* Values for do_debug_lines. */
108 #define FLAG_DEBUG_LINES_RAW 1
109 #define FLAG_DEBUG_LINES_DECODED 2
112 size_of_encoded_value (int encoding)
114 switch (encoding & 0x7)
117 case 0: return eh_addr_size;
125 get_encoded_value (unsigned char *data,
127 struct dwarf_section *section)
129 int size = size_of_encoded_value (encoding);
132 if (encoding & DW_EH_PE_signed)
133 val = byte_get_signed (data, size);
135 val = byte_get (data, size);
137 if ((encoding & 0x70) == DW_EH_PE_pcrel)
138 val += section->address + (data - section->start);
142 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
144 #define DWARF_VMA_FMT "ll"
145 #define DWARF_VMA_FMT_LONG "%16.16llx"
147 #define DWARF_VMA_FMT "I64"
148 #define DWARF_VMA_FMT_LONG "%016I64x"
151 #define DWARF_VMA_FMT "l"
152 #define DWARF_VMA_FMT_LONG "%16.16lx"
155 /* Convert a dwarf vma value into a string. Returns a pointer to a static
156 buffer containing the converted VALUE. The value is converted according
157 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
158 it specifies the maximum number of bytes to be displayed in the converted
159 value and FMTCH is ignored - hex is always used. */
162 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
164 /* As dwarf_vmatoa is used more then once in a printf call
165 for output, we are cycling through an fixed array of pointers
166 for return address. */
167 static int buf_pos = 0;
168 static struct dwarf_vmatoa_buf
174 ret = buf[buf_pos++].place;
175 buf_pos %= ARRAY_SIZE (buf);
179 /* Printf does not have a way of specifiying a maximum field width for an
180 integer value, so we print the full value into a buffer and then select
181 the precision we need. */
182 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
185 return ret + (16 - 2 * num_bytes);
191 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
192 snprintf (ret, sizeof (buf[0].place), fmt, value);
197 static inline const char *
198 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
200 return dwarf_vmatoa_1 (fmtch, value, 0);
203 /* Print a dwarf_vma value (typically an address, offset or length) in
204 hexadecimal format, followed by a space. The length of the VALUE (and
205 hence the precision displayed) is determined by the NUM_BYTES parameter. */
208 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
210 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
213 /* Format a 64-bit value, given as two 32-bit values, in hex.
214 For reentrancy, this uses a buffer provided by the caller. */
217 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
218 unsigned int buf_len)
223 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
226 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
227 snprintf (buf + len, buf_len - len,
228 "%08" DWARF_VMA_FMT "x", lvalue);
234 /* Read in a LEB128 encoded value starting at address DATA.
235 If SIGN is true, return a signed LEB128 value.
236 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
237 No bytes will be read at address END or beyond. */
240 read_leb128 (unsigned char *data,
241 unsigned int *length_return,
243 const unsigned char * const end)
245 dwarf_vma result = 0;
246 unsigned int num_read = 0;
247 unsigned int shift = 0;
248 unsigned char byte = 0;
255 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
258 if ((byte & 0x80) == 0)
262 if (length_return != NULL)
263 *length_return = num_read;
265 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
266 result |= -1L << shift;
271 /* Create a signed version to avoid painful typecasts. */
272 static inline dwarf_signed_vma
273 read_sleb128 (unsigned char * data,
274 unsigned int * length_return,
275 const unsigned char * const end)
277 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
280 static inline dwarf_vma
281 read_uleb128 (unsigned char * data,
282 unsigned int * length_return,
283 const unsigned char * const end)
285 return read_leb128 (data, length_return, FALSE, end);
288 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
291 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
292 unsigned int amount = (AMOUNT); \
293 if (((PTR) + amount) >= (END)) \
296 amount = (END) - (PTR); \
301 VAL = byte_get ((PTR), amount); \
307 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
310 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
315 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
318 unsigned int amount = (AMOUNT); \
319 if (((PTR) + amount) >= (END)) \
322 amount = (END) - (PTR); \
327 VAL = byte_get_signed ((PTR), amount); \
333 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
336 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
341 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
344 if (((PTR) + 8) <= (END)) \
346 byte_get_64 ((PTR), (HIGH), (LOW)); \
350 * (LOW) = * (HIGH) = 0; \
355 typedef struct State_Machine_Registers
363 unsigned char op_index;
364 unsigned char end_sequence;
365 /* This variable hold the number of the last entry seen
366 in the File Table. */
367 unsigned int last_file_entry;
370 static SMR state_machine_regs;
373 reset_state_machine (int is_stmt)
375 state_machine_regs.address = 0;
376 state_machine_regs.op_index = 0;
377 state_machine_regs.file = 1;
378 state_machine_regs.line = 1;
379 state_machine_regs.column = 0;
380 state_machine_regs.is_stmt = is_stmt;
381 state_machine_regs.basic_block = 0;
382 state_machine_regs.end_sequence = 0;
383 state_machine_regs.last_file_entry = 0;
386 /* Handled an extend line op.
387 Returns the number of bytes read. */
390 process_extended_line_op (unsigned char * data,
394 unsigned char op_code;
395 unsigned int bytes_read;
398 unsigned char *orig_data = data;
401 len = read_uleb128 (data, & bytes_read, end);
404 if (len == 0 || data == end)
406 warn (_("badly formed extended line op encountered!\n"));
413 printf (_(" Extended opcode %d: "), op_code);
417 case DW_LNE_end_sequence:
418 printf (_("End of Sequence\n\n"));
419 reset_state_machine (is_stmt);
422 case DW_LNE_set_address:
423 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
424 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
425 state_machine_regs.address = adr;
426 state_machine_regs.op_index = 0;
429 case DW_LNE_define_file:
430 printf (_("define new File Table entry\n"));
431 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
432 printf (" %d\t", ++state_machine_regs.last_file_entry);
435 data += strnlen ((char *) data, end - data) + 1;
436 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
438 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
440 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
442 printf ("%s\n\n", name);
444 if (((unsigned int) (data - orig_data) != len) || data == end)
445 warn (_("DW_LNE_define_file: Bad opcode length\n"));
448 case DW_LNE_set_discriminator:
449 printf (_("set Discriminator to %s\n"),
450 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
454 case DW_LNE_HP_negate_is_UV_update:
455 printf ("DW_LNE_HP_negate_is_UV_update\n");
457 case DW_LNE_HP_push_context:
458 printf ("DW_LNE_HP_push_context\n");
460 case DW_LNE_HP_pop_context:
461 printf ("DW_LNE_HP_pop_context\n");
463 case DW_LNE_HP_set_file_line_column:
464 printf ("DW_LNE_HP_set_file_line_column\n");
466 case DW_LNE_HP_set_routine_name:
467 printf ("DW_LNE_HP_set_routine_name\n");
469 case DW_LNE_HP_set_sequence:
470 printf ("DW_LNE_HP_set_sequence\n");
472 case DW_LNE_HP_negate_post_semantics:
473 printf ("DW_LNE_HP_negate_post_semantics\n");
475 case DW_LNE_HP_negate_function_exit:
476 printf ("DW_LNE_HP_negate_function_exit\n");
478 case DW_LNE_HP_negate_front_end_logical:
479 printf ("DW_LNE_HP_negate_front_end_logical\n");
481 case DW_LNE_HP_define_proc:
482 printf ("DW_LNE_HP_define_proc\n");
484 case DW_LNE_HP_source_file_correlation:
486 unsigned char *edata = data + len - bytes_read - 1;
488 printf ("DW_LNE_HP_source_file_correlation\n");
494 opc = read_uleb128 (data, & bytes_read, edata);
499 case DW_LNE_HP_SFC_formfeed:
500 printf (" DW_LNE_HP_SFC_formfeed\n");
502 case DW_LNE_HP_SFC_set_listing_line:
503 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
505 read_uleb128 (data, & bytes_read, edata)));
508 case DW_LNE_HP_SFC_associate:
509 printf (" DW_LNE_HP_SFC_associate ");
512 read_uleb128 (data, & bytes_read, edata)));
516 read_uleb128 (data, & bytes_read, edata)));
520 read_uleb128 (data, & bytes_read, edata)));
524 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
534 unsigned int rlen = len - bytes_read - 1;
536 if (op_code >= DW_LNE_lo_user
537 /* The test against DW_LNW_hi_user is redundant due to
538 the limited range of the unsigned char data type used
540 /*&& op_code <= DW_LNE_hi_user*/)
541 printf (_("user defined: "));
543 printf (_("UNKNOWN: "));
544 printf (_("length %d ["), rlen);
546 printf (" %02x", *data++);
555 static const unsigned char *
556 fetch_indirect_string (dwarf_vma offset)
558 struct dwarf_section *section = &debug_displays [str].section;
560 if (section->start == NULL)
561 return (const unsigned char *) _("<no .debug_str section>");
563 if (offset > section->size)
565 warn (_("DW_FORM_strp offset too big: %s\n"),
566 dwarf_vmatoa ("x", offset));
567 return (const unsigned char *) _("<offset is too big>");
570 return (const unsigned char *) section->start + offset;
574 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
575 dwarf_vma offset_size, int dwo)
577 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
578 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
579 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
580 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
581 dwarf_vma index_offset = idx * offset_size;
582 dwarf_vma str_offset;
584 if (index_section->start == NULL)
585 return (dwo ? _("<no .debug_str_offsets.dwo section>")
586 : _("<no .debug_str_offsets section>"));
588 if (this_set != NULL)
589 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
590 if (index_offset > index_section->size)
592 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
593 dwarf_vmatoa ("x", index_offset));
594 return _("<index offset is too big>");
597 if (str_section->start == NULL)
598 return (dwo ? _("<no .debug_str.dwo section>")
599 : _("<no .debug_str section>"));
601 str_offset = byte_get (index_section->start + index_offset, offset_size);
602 str_offset -= str_section->address;
603 if (str_offset > str_section->size)
605 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
606 dwarf_vmatoa ("x", str_offset));
607 return _("<indirect index offset is too big>");
610 return (const char *) str_section->start + str_offset;
614 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
616 struct dwarf_section *section = &debug_displays [debug_addr].section;
618 if (section->start == NULL)
619 return (_("<no .debug_addr section>"));
621 if (offset + bytes > section->size)
623 warn (_("Offset into section %s too big: %s\n"),
624 section->name, dwarf_vmatoa ("x", offset));
625 return "<offset too big>";
628 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
632 /* FIXME: There are better and more efficient ways to handle
633 these structures. For now though, I just want something that
634 is simple to implement. */
635 typedef struct abbrev_attr
637 unsigned long attribute;
639 struct abbrev_attr *next;
643 typedef struct abbrev_entry
648 struct abbrev_attr *first_attr;
649 struct abbrev_attr *last_attr;
650 struct abbrev_entry *next;
654 static abbrev_entry *first_abbrev = NULL;
655 static abbrev_entry *last_abbrev = NULL;
662 for (abbrv = first_abbrev; abbrv;)
664 abbrev_entry *next_abbrev = abbrv->next;
667 for (attr = abbrv->first_attr; attr;)
669 abbrev_attr *next_attr = attr->next;
679 last_abbrev = first_abbrev = NULL;
683 add_abbrev (unsigned long number, unsigned long tag, int children)
687 entry = (abbrev_entry *) malloc (sizeof (*entry));
692 entry->entry = number;
694 entry->children = children;
695 entry->first_attr = NULL;
696 entry->last_attr = NULL;
699 if (first_abbrev == NULL)
700 first_abbrev = entry;
702 last_abbrev->next = entry;
708 add_abbrev_attr (unsigned long attribute, unsigned long form)
712 attr = (abbrev_attr *) malloc (sizeof (*attr));
717 attr->attribute = attribute;
721 if (last_abbrev->first_attr == NULL)
722 last_abbrev->first_attr = attr;
724 last_abbrev->last_attr->next = attr;
726 last_abbrev->last_attr = attr;
729 /* Processes the (partial) contents of a .debug_abbrev section.
730 Returns NULL if the end of the section was encountered.
731 Returns the address after the last byte read if the end of
732 an abbreviation set was found. */
734 static unsigned char *
735 process_abbrev_section (unsigned char *start, unsigned char *end)
737 if (first_abbrev != NULL)
742 unsigned int bytes_read;
745 unsigned long attribute;
748 entry = read_uleb128 (start, & bytes_read, end);
751 /* A single zero is supposed to end the section according
752 to the standard. If there's more, then signal that to
759 tag = read_uleb128 (start, & bytes_read, end);
766 add_abbrev (entry, tag, children);
772 attribute = read_uleb128 (start, & bytes_read, end);
777 form = read_uleb128 (start, & bytes_read, end);
782 add_abbrev_attr (attribute, form);
784 while (attribute != 0);
787 /* Report the missing single zero which ends the section. */
788 error (_(".debug_abbrev section not zero terminated\n"));
794 get_TAG_name (unsigned long tag)
796 const char *name = get_DW_TAG_name ((unsigned int)tag);
800 static char buffer[100];
802 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
810 get_FORM_name (unsigned long form)
815 return "DW_FORM value: 0";
817 name = get_DW_FORM_name (form);
820 static char buffer[100];
822 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
829 static unsigned char *
830 display_block (unsigned char *data,
832 const unsigned char * const end)
836 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
838 maxlen = (dwarf_vma) (end - data);
839 length = length > maxlen ? maxlen : length;
842 printf ("%lx ", (unsigned long) byte_get (data++, 1));
848 decode_location_expression (unsigned char * data,
849 unsigned int pointer_size,
850 unsigned int offset_size,
854 struct dwarf_section * section)
857 unsigned int bytes_read;
859 dwarf_signed_vma svalue;
860 unsigned char *end = data + length;
861 int need_frame_base = 0;
870 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
871 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
874 printf ("DW_OP_deref");
877 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
878 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
881 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
882 printf ("DW_OP_const1s: %ld", (long) svalue);
885 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
886 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
889 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
890 printf ("DW_OP_const2s: %ld", (long) svalue);
893 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
894 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
897 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
898 printf ("DW_OP_const4s: %ld", (long) svalue);
901 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
902 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
903 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
904 printf ("%lu", (unsigned long) uvalue);
907 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
908 printf ("DW_OP_const8s: %ld ", (long) svalue);
909 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
910 printf ("%ld", (long) svalue);
913 printf ("DW_OP_constu: %s",
914 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
918 printf ("DW_OP_consts: %s",
919 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
923 printf ("DW_OP_dup");
926 printf ("DW_OP_drop");
929 printf ("DW_OP_over");
932 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
933 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
936 printf ("DW_OP_swap");
939 printf ("DW_OP_rot");
942 printf ("DW_OP_xderef");
945 printf ("DW_OP_abs");
948 printf ("DW_OP_and");
951 printf ("DW_OP_div");
954 printf ("DW_OP_minus");
957 printf ("DW_OP_mod");
960 printf ("DW_OP_mul");
963 printf ("DW_OP_neg");
966 printf ("DW_OP_not");
972 printf ("DW_OP_plus");
974 case DW_OP_plus_uconst:
975 printf ("DW_OP_plus_uconst: %s",
976 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
980 printf ("DW_OP_shl");
983 printf ("DW_OP_shr");
986 printf ("DW_OP_shra");
989 printf ("DW_OP_xor");
992 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
993 printf ("DW_OP_bra: %ld", (long) svalue);
1002 printf ("DW_OP_gt");
1005 printf ("DW_OP_le");
1008 printf ("DW_OP_lt");
1011 printf ("DW_OP_ne");
1014 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1015 printf ("DW_OP_skip: %ld", (long) svalue);
1050 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1085 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1086 regname (op - DW_OP_reg0, 1));
1121 printf ("DW_OP_breg%d (%s): %s",
1123 regname (op - DW_OP_breg0, 1),
1124 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1129 uvalue = read_uleb128 (data, &bytes_read, end);
1131 printf ("DW_OP_regx: %s (%s)",
1132 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1135 need_frame_base = 1;
1136 printf ("DW_OP_fbreg: %s",
1137 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1141 uvalue = read_uleb128 (data, &bytes_read, end);
1143 printf ("DW_OP_bregx: %s (%s) %s",
1144 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1145 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1149 printf ("DW_OP_piece: %s",
1150 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1153 case DW_OP_deref_size:
1154 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1155 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1157 case DW_OP_xderef_size:
1158 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1159 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1162 printf ("DW_OP_nop");
1165 /* DWARF 3 extensions. */
1166 case DW_OP_push_object_address:
1167 printf ("DW_OP_push_object_address");
1170 /* XXX: Strictly speaking for 64-bit DWARF3 files
1171 this ought to be an 8-byte wide computation. */
1172 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1173 printf ("DW_OP_call2: <0x%s>",
1174 dwarf_vmatoa ("x", svalue + cu_offset));
1177 /* XXX: Strictly speaking for 64-bit DWARF3 files
1178 this ought to be an 8-byte wide computation. */
1179 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1180 printf ("DW_OP_call4: <0x%s>",
1181 dwarf_vmatoa ("x", svalue + cu_offset));
1183 case DW_OP_call_ref:
1184 /* XXX: Strictly speaking for 64-bit DWARF3 files
1185 this ought to be an 8-byte wide computation. */
1186 if (dwarf_version == -1)
1188 printf (_("(DW_OP_call_ref in frame info)"));
1189 /* No way to tell where the next op is, so just bail. */
1190 return need_frame_base;
1192 if (dwarf_version == 2)
1194 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1198 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1200 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1202 case DW_OP_form_tls_address:
1203 printf ("DW_OP_form_tls_address");
1205 case DW_OP_call_frame_cfa:
1206 printf ("DW_OP_call_frame_cfa");
1208 case DW_OP_bit_piece:
1209 printf ("DW_OP_bit_piece: ");
1210 printf (_("size: %s "),
1211 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1213 printf (_("offset: %s "),
1214 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1218 /* DWARF 4 extensions. */
1219 case DW_OP_stack_value:
1220 printf ("DW_OP_stack_value");
1223 case DW_OP_implicit_value:
1224 printf ("DW_OP_implicit_value");
1225 uvalue = read_uleb128 (data, &bytes_read, end);
1227 display_block (data, uvalue, end);
1231 /* GNU extensions. */
1232 case DW_OP_GNU_push_tls_address:
1233 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1235 case DW_OP_GNU_uninit:
1236 printf ("DW_OP_GNU_uninit");
1237 /* FIXME: Is there data associated with this OP ? */
1239 case DW_OP_GNU_encoded_addr:
1245 addr = get_encoded_value (data, encoding, section);
1246 data += size_of_encoded_value (encoding);
1248 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1249 print_dwarf_vma (addr, pointer_size);
1252 case DW_OP_GNU_implicit_pointer:
1253 /* XXX: Strictly speaking for 64-bit DWARF3 files
1254 this ought to be an 8-byte wide computation. */
1255 if (dwarf_version == -1)
1257 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1258 /* No way to tell where the next op is, so just bail. */
1259 return need_frame_base;
1261 if (dwarf_version == 2)
1263 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1267 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1269 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1270 dwarf_vmatoa ("x", uvalue),
1271 dwarf_vmatoa ("d", read_sleb128 (data,
1272 &bytes_read, end)));
1275 case DW_OP_GNU_entry_value:
1276 uvalue = read_uleb128 (data, &bytes_read, end);
1278 printf ("DW_OP_GNU_entry_value: (");
1279 if (decode_location_expression (data, pointer_size, offset_size,
1280 dwarf_version, uvalue,
1281 cu_offset, section))
1282 need_frame_base = 1;
1286 case DW_OP_GNU_const_type:
1287 uvalue = read_uleb128 (data, &bytes_read, end);
1289 printf ("DW_OP_GNU_const_type: <0x%s> ",
1290 dwarf_vmatoa ("x", cu_offset + uvalue));
1291 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1292 display_block (data, uvalue, end);
1295 case DW_OP_GNU_regval_type:
1296 uvalue = read_uleb128 (data, &bytes_read, end);
1298 printf ("DW_OP_GNU_regval_type: %s (%s)",
1299 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1300 uvalue = read_uleb128 (data, &bytes_read, end);
1302 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1304 case DW_OP_GNU_deref_type:
1305 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1306 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
1307 uvalue = read_uleb128 (data, &bytes_read, end);
1309 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1311 case DW_OP_GNU_convert:
1312 uvalue = read_uleb128 (data, &bytes_read, end);
1314 printf ("DW_OP_GNU_convert <0x%s>",
1315 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1317 case DW_OP_GNU_reinterpret:
1318 uvalue = read_uleb128 (data, &bytes_read, end);
1320 printf ("DW_OP_GNU_reinterpret <0x%s>",
1321 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1323 case DW_OP_GNU_parameter_ref:
1324 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1325 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1326 dwarf_vmatoa ("x", cu_offset + uvalue));
1328 case DW_OP_GNU_addr_index:
1329 uvalue = read_uleb128 (data, &bytes_read, end);
1331 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1333 case DW_OP_GNU_const_index:
1334 uvalue = read_uleb128 (data, &bytes_read, end);
1336 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1339 /* HP extensions. */
1340 case DW_OP_HP_is_value:
1341 printf ("DW_OP_HP_is_value");
1342 /* FIXME: Is there data associated with this OP ? */
1344 case DW_OP_HP_fltconst4:
1345 printf ("DW_OP_HP_fltconst4");
1346 /* FIXME: Is there data associated with this OP ? */
1348 case DW_OP_HP_fltconst8:
1349 printf ("DW_OP_HP_fltconst8");
1350 /* FIXME: Is there data associated with this OP ? */
1352 case DW_OP_HP_mod_range:
1353 printf ("DW_OP_HP_mod_range");
1354 /* FIXME: Is there data associated with this OP ? */
1356 case DW_OP_HP_unmod_range:
1357 printf ("DW_OP_HP_unmod_range");
1358 /* FIXME: Is there data associated with this OP ? */
1361 printf ("DW_OP_HP_tls");
1362 /* FIXME: Is there data associated with this OP ? */
1365 /* PGI (STMicroelectronics) extensions. */
1366 case DW_OP_PGI_omp_thread_num:
1367 /* Pushes the thread number for the current thread as it would be
1368 returned by the standard OpenMP library function:
1369 omp_get_thread_num(). The "current thread" is the thread for
1370 which the expression is being evaluated. */
1371 printf ("DW_OP_PGI_omp_thread_num");
1375 if (op >= DW_OP_lo_user
1376 && op <= DW_OP_hi_user)
1377 printf (_("(User defined location op)"));
1379 printf (_("(Unknown location op)"));
1380 /* No way to tell where the next op is, so just bail. */
1381 return need_frame_base;
1384 /* Separate the ops. */
1389 return need_frame_base;
1392 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1393 This is used for DWARF package files. */
1395 static struct cu_tu_set *
1396 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1398 struct cu_tu_set *p;
1400 unsigned int dw_sect;
1406 dw_sect = DW_SECT_TYPES;
1412 dw_sect = DW_SECT_INFO;
1416 if (p->section_offsets [dw_sect] == cu_offset)
1424 /* Add INC to HIGH_BITS:LOW_BITS. */
1426 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1428 dwarf_vma tmp = * low_bits;
1432 /* FIXME: There is probably a better way of handling this:
1434 We need to cope with dwarf_vma being a 32-bit or 64-bit
1435 type. Plus regardless of its size LOW_BITS is meant to
1436 only hold 32-bits, so if there is overflow or wrap around
1437 we must propagate into HIGH_BITS. */
1438 if (tmp < * low_bits)
1442 else if (sizeof (tmp) > 8
1452 static unsigned char *
1453 read_and_display_attr_value (unsigned long attribute,
1455 unsigned char * data,
1456 unsigned char * end,
1457 dwarf_vma cu_offset,
1458 dwarf_vma pointer_size,
1459 dwarf_vma offset_size,
1461 debug_info * debug_info_p,
1463 struct dwarf_section * section,
1464 struct cu_tu_set * this_set)
1466 dwarf_vma uvalue = 0;
1467 unsigned char *block_start = NULL;
1468 unsigned char * orig_data = data;
1469 unsigned int bytes_read;
1473 warn (_("corrupt attribute\n"));
1482 case DW_FORM_ref_addr:
1483 if (dwarf_version == 2)
1484 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1485 else if (dwarf_version == 3 || dwarf_version == 4)
1486 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1488 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1493 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1497 case DW_FORM_sec_offset:
1498 case DW_FORM_GNU_ref_alt:
1499 case DW_FORM_GNU_strp_alt:
1500 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1503 case DW_FORM_flag_present:
1510 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1515 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1520 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1524 uvalue = read_sleb128 (data, & bytes_read, end);
1528 case DW_FORM_GNU_str_index:
1529 uvalue = read_uleb128 (data, & bytes_read, end);
1533 case DW_FORM_ref_udata:
1535 uvalue = read_uleb128 (data, & bytes_read, end);
1539 case DW_FORM_indirect:
1540 form = read_uleb128 (data, & bytes_read, end);
1543 printf (" %s", get_FORM_name (form));
1544 return read_and_display_attr_value (attribute, form, data, end,
1545 cu_offset, pointer_size,
1546 offset_size, dwarf_version,
1547 debug_info_p, do_loc,
1549 case DW_FORM_GNU_addr_index:
1550 uvalue = read_uleb128 (data, & bytes_read, end);
1557 case DW_FORM_ref_addr:
1559 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1562 case DW_FORM_GNU_ref_alt:
1564 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1570 case DW_FORM_ref_udata:
1572 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1577 case DW_FORM_sec_offset:
1579 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1582 case DW_FORM_flag_present:
1589 printf (" %s", dwarf_vmatoa ("d", uvalue));
1596 dwarf_vma high_bits;
1600 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1602 if (form == DW_FORM_ref8)
1603 add64 (& high_bits, & utmp, cu_offset);
1605 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1608 if ((do_loc || do_debug_loc || do_debug_ranges)
1609 && num_debug_info_entries == 0)
1611 if (sizeof (uvalue) == 8)
1612 SAFE_BYTE_GET (uvalue, data, 8, end);
1614 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1620 case DW_FORM_string:
1622 printf (" %.*s", (int) (end - data), data);
1623 data += strnlen ((char *) data, end - data) + 1;
1627 case DW_FORM_exprloc:
1628 uvalue = read_uleb128 (data, & bytes_read, end);
1629 block_start = data + bytes_read;
1631 data = block_start + uvalue;
1633 data = display_block (block_start, uvalue, end);
1636 case DW_FORM_block1:
1637 SAFE_BYTE_GET (uvalue, data, 1, end);
1638 block_start = data + 1;
1640 data = block_start + uvalue;
1642 data = display_block (block_start, uvalue, end);
1645 case DW_FORM_block2:
1646 SAFE_BYTE_GET (uvalue, data, 2, end);
1647 block_start = data + 2;
1649 data = block_start + uvalue;
1651 data = display_block (block_start, uvalue, end);
1654 case DW_FORM_block4:
1655 SAFE_BYTE_GET (uvalue, data, 4, end);
1656 block_start = data + 4;
1658 data = block_start + uvalue;
1660 data = display_block (block_start, uvalue, end);
1665 printf (_(" (indirect string, offset: 0x%s): %s"),
1666 dwarf_vmatoa ("x", uvalue),
1667 fetch_indirect_string (uvalue));
1670 case DW_FORM_GNU_str_index:
1673 const char *suffix = strrchr (section->name, '.');
1674 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1676 printf (_(" (indexed string: 0x%s): %s"),
1677 dwarf_vmatoa ("x", uvalue),
1678 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1682 case DW_FORM_GNU_strp_alt:
1684 printf (_(" (alt indirect string, offset: 0x%s)"),
1685 dwarf_vmatoa ("x", uvalue));
1688 case DW_FORM_indirect:
1689 /* Handled above. */
1692 case DW_FORM_ref_sig8:
1695 dwarf_vma high_bits;
1698 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1699 printf (" signature: 0x%s",
1700 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1705 case DW_FORM_GNU_addr_index:
1707 printf (_(" (addr_index: 0x%s): %s"),
1708 dwarf_vmatoa ("x", uvalue),
1709 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1713 warn (_("Unrecognized form: %lu\n"), form);
1717 if ((do_loc || do_debug_loc || do_debug_ranges)
1718 && num_debug_info_entries == 0
1719 && debug_info_p != NULL)
1723 case DW_AT_frame_base:
1724 have_frame_base = 1;
1725 case DW_AT_location:
1726 case DW_AT_string_length:
1727 case DW_AT_return_addr:
1728 case DW_AT_data_member_location:
1729 case DW_AT_vtable_elem_location:
1731 case DW_AT_static_link:
1732 case DW_AT_use_location:
1733 case DW_AT_GNU_call_site_value:
1734 case DW_AT_GNU_call_site_data_value:
1735 case DW_AT_GNU_call_site_target:
1736 case DW_AT_GNU_call_site_target_clobbered:
1737 if ((dwarf_version < 4
1738 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1739 || form == DW_FORM_sec_offset)
1741 /* Process location list. */
1742 unsigned int lmax = debug_info_p->max_loc_offsets;
1743 unsigned int num = debug_info_p->num_loc_offsets;
1745 if (lmax == 0 || num >= lmax)
1748 debug_info_p->loc_offsets = (dwarf_vma *)
1749 xcrealloc (debug_info_p->loc_offsets,
1750 lmax, sizeof (*debug_info_p->loc_offsets));
1751 debug_info_p->have_frame_base = (int *)
1752 xcrealloc (debug_info_p->have_frame_base,
1753 lmax, sizeof (*debug_info_p->have_frame_base));
1754 debug_info_p->max_loc_offsets = lmax;
1756 if (this_set != NULL)
1757 uvalue += this_set->section_offsets [DW_SECT_LOC];
1758 debug_info_p->loc_offsets [num] = uvalue;
1759 debug_info_p->have_frame_base [num] = have_frame_base;
1760 debug_info_p->num_loc_offsets++;
1765 if (need_base_address)
1766 debug_info_p->base_address = uvalue;
1769 case DW_AT_GNU_addr_base:
1770 debug_info_p->addr_base = uvalue;
1773 case DW_AT_GNU_ranges_base:
1774 debug_info_p->ranges_base = uvalue;
1778 if ((dwarf_version < 4
1779 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1780 || form == DW_FORM_sec_offset)
1782 /* Process range list. */
1783 unsigned int lmax = debug_info_p->max_range_lists;
1784 unsigned int num = debug_info_p->num_range_lists;
1786 if (lmax == 0 || num >= lmax)
1789 debug_info_p->range_lists = (dwarf_vma *)
1790 xcrealloc (debug_info_p->range_lists,
1791 lmax, sizeof (*debug_info_p->range_lists));
1792 debug_info_p->max_range_lists = lmax;
1794 debug_info_p->range_lists [num] = uvalue;
1795 debug_info_p->num_range_lists++;
1804 if (do_loc || attribute == 0)
1807 /* For some attributes we can display further information. */
1814 case DW_INL_not_inlined:
1815 printf (_("(not inlined)"));
1817 case DW_INL_inlined:
1818 printf (_("(inlined)"));
1820 case DW_INL_declared_not_inlined:
1821 printf (_("(declared as inline but ignored)"));
1823 case DW_INL_declared_inlined:
1824 printf (_("(declared as inline and inlined)"));
1827 printf (_(" (Unknown inline attribute value: %s)"),
1828 dwarf_vmatoa ("x", uvalue));
1833 case DW_AT_language:
1837 /* Ordered by the numeric value of these constants. */
1838 case DW_LANG_C89: printf ("(ANSI C)"); break;
1839 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1840 case DW_LANG_Ada83: printf ("(Ada)"); break;
1841 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1842 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1843 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1844 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1845 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1846 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1847 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1848 /* DWARF 2.1 values. */
1849 case DW_LANG_Java: printf ("(Java)"); break;
1850 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1851 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1852 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1853 /* DWARF 3 values. */
1854 case DW_LANG_PLI: printf ("(PLI)"); break;
1855 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1856 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1857 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1858 case DW_LANG_D: printf ("(D)"); break;
1859 /* DWARF 4 values. */
1860 case DW_LANG_Python: printf ("(Python)"); break;
1861 /* DWARF 5 values. */
1862 case DW_LANG_Go: printf ("(Go)"); break;
1863 /* MIPS extension. */
1864 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1865 /* UPC extension. */
1866 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1868 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1869 printf (_("(implementation defined: %s)"),
1870 dwarf_vmatoa ("x", uvalue));
1872 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1877 case DW_AT_encoding:
1881 case DW_ATE_void: printf ("(void)"); break;
1882 case DW_ATE_address: printf ("(machine address)"); break;
1883 case DW_ATE_boolean: printf ("(boolean)"); break;
1884 case DW_ATE_complex_float: printf ("(complex float)"); break;
1885 case DW_ATE_float: printf ("(float)"); break;
1886 case DW_ATE_signed: printf ("(signed)"); break;
1887 case DW_ATE_signed_char: printf ("(signed char)"); break;
1888 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1889 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1890 /* DWARF 2.1 values: */
1891 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1892 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1893 /* DWARF 3 values: */
1894 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1895 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1896 case DW_ATE_edited: printf ("(edited)"); break;
1897 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1898 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1899 /* HP extensions: */
1900 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1901 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1902 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1903 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1904 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1905 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1906 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1909 if (uvalue >= DW_ATE_lo_user
1910 && uvalue <= DW_ATE_hi_user)
1911 printf (_("(user defined type)"));
1913 printf (_("(unknown type)"));
1918 case DW_AT_accessibility:
1922 case DW_ACCESS_public: printf ("(public)"); break;
1923 case DW_ACCESS_protected: printf ("(protected)"); break;
1924 case DW_ACCESS_private: printf ("(private)"); break;
1926 printf (_("(unknown accessibility)"));
1931 case DW_AT_visibility:
1935 case DW_VIS_local: printf ("(local)"); break;
1936 case DW_VIS_exported: printf ("(exported)"); break;
1937 case DW_VIS_qualified: printf ("(qualified)"); break;
1938 default: printf (_("(unknown visibility)")); break;
1942 case DW_AT_virtuality:
1946 case DW_VIRTUALITY_none: printf ("(none)"); break;
1947 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1948 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1949 default: printf (_("(unknown virtuality)")); break;
1953 case DW_AT_identifier_case:
1957 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1958 case DW_ID_up_case: printf ("(up_case)"); break;
1959 case DW_ID_down_case: printf ("(down_case)"); break;
1960 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1961 default: printf (_("(unknown case)")); break;
1965 case DW_AT_calling_convention:
1969 case DW_CC_normal: printf ("(normal)"); break;
1970 case DW_CC_program: printf ("(program)"); break;
1971 case DW_CC_nocall: printf ("(nocall)"); break;
1973 if (uvalue >= DW_CC_lo_user
1974 && uvalue <= DW_CC_hi_user)
1975 printf (_("(user defined)"));
1977 printf (_("(unknown convention)"));
1981 case DW_AT_ordering:
1985 case -1: printf (_("(undefined)")); break;
1986 case 0: printf ("(row major)"); break;
1987 case 1: printf ("(column major)"); break;
1991 case DW_AT_frame_base:
1992 have_frame_base = 1;
1993 case DW_AT_location:
1994 case DW_AT_string_length:
1995 case DW_AT_return_addr:
1996 case DW_AT_data_member_location:
1997 case DW_AT_vtable_elem_location:
1999 case DW_AT_static_link:
2000 case DW_AT_use_location:
2001 case DW_AT_GNU_call_site_value:
2002 case DW_AT_GNU_call_site_data_value:
2003 case DW_AT_GNU_call_site_target:
2004 case DW_AT_GNU_call_site_target_clobbered:
2005 if ((dwarf_version < 4
2006 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2007 || form == DW_FORM_sec_offset)
2008 printf (_(" (location list)"));
2010 case DW_AT_allocated:
2011 case DW_AT_associated:
2012 case DW_AT_data_location:
2014 case DW_AT_upper_bound:
2015 case DW_AT_lower_bound:
2018 int need_frame_base;
2021 need_frame_base = decode_location_expression (block_start,
2026 cu_offset, section);
2028 if (need_frame_base && !have_frame_base)
2029 printf (_(" [without DW_AT_frame_base]"));
2035 if (form == DW_FORM_ref_sig8
2036 || form == DW_FORM_GNU_ref_alt)
2039 if (form == DW_FORM_ref1
2040 || form == DW_FORM_ref2
2041 || form == DW_FORM_ref4
2042 || form == DW_FORM_ref_udata)
2043 uvalue += cu_offset;
2045 if (uvalue >= section->size)
2046 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2047 dwarf_vmatoa ("x", uvalue),
2048 (unsigned long) (orig_data - section->start));
2051 unsigned long abbrev_number;
2052 abbrev_entry * entry;
2054 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2056 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2057 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2058 use different abbrev table, and we don't track .debug_info chunks
2060 if (form != DW_FORM_ref_addr)
2062 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2063 if (entry->entry == abbrev_number)
2066 printf (" (%s)", get_TAG_name (entry->tag));
2081 get_AT_name (unsigned long attribute)
2086 return "DW_AT value: 0";
2088 /* One value is shared by the MIPS and HP extensions: */
2089 if (attribute == DW_AT_MIPS_fde)
2090 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2092 name = get_DW_AT_name (attribute);
2096 static char buffer[100];
2098 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2106 static unsigned char *
2107 read_and_display_attr (unsigned long attribute,
2109 unsigned char * data,
2110 unsigned char * end,
2111 dwarf_vma cu_offset,
2112 dwarf_vma pointer_size,
2113 dwarf_vma offset_size,
2115 debug_info * debug_info_p,
2117 struct dwarf_section * section,
2118 struct cu_tu_set * this_set)
2121 printf (" %-18s:", get_AT_name (attribute));
2122 data = read_and_display_attr_value (attribute, form, data, end,
2123 cu_offset, pointer_size, offset_size,
2124 dwarf_version, debug_info_p,
2125 do_loc, section, this_set);
2131 /* Process the contents of a .debug_info section. If do_loc is non-zero
2132 then we are scanning for location lists and we do not want to display
2133 anything to the user. If do_types is non-zero, we are processing
2134 a .debug_types section instead of a .debug_info section. */
2137 process_debug_info (struct dwarf_section *section,
2139 enum dwarf_section_display_enum abbrev_sec,
2143 unsigned char *start = section->start;
2144 unsigned char *end = start + section->size;
2145 unsigned char *section_begin;
2147 unsigned int num_units = 0;
2149 if ((do_loc || do_debug_loc || do_debug_ranges)
2150 && num_debug_info_entries == 0
2155 /* First scan the section to get the number of comp units. */
2156 for (section_begin = start, num_units = 0; section_begin < end;
2159 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2160 will be the length. For a 64-bit DWARF section, it'll be
2161 the escape code 0xffffffff followed by an 8 byte length. */
2162 SAFE_BYTE_GET (length, section_begin, 4, end);
2164 if (length == 0xffffffff)
2166 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2167 section_begin += length + 12;
2169 else if (length >= 0xfffffff0 && length < 0xffffffff)
2171 warn (_("Reserved length value (0x%s) found in section %s\n"),
2172 dwarf_vmatoa ("x", length), section->name);
2176 section_begin += length + 4;
2178 /* Negative values are illegal, they may even cause infinite
2179 looping. This can happen if we can't accurately apply
2180 relocations to an object file. */
2181 if ((signed long) length <= 0)
2183 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2184 dwarf_vmatoa ("x", length), section->name);
2191 error (_("No comp units in %s section ?"), section->name);
2195 /* Then allocate an array to hold the information. */
2196 debug_information = (debug_info *) cmalloc (num_units,
2197 sizeof (* debug_information));
2198 if (debug_information == NULL)
2200 error (_("Not enough memory for a debug info array of %u entries"),
2208 if (dwarf_start_die == 0)
2209 printf (_("Contents of the %s section:\n\n"), section->name);
2211 load_debug_section (str, file);
2212 load_debug_section (str_dwo, file);
2213 load_debug_section (str_index, file);
2214 load_debug_section (str_index_dwo, file);
2215 load_debug_section (debug_addr, file);
2218 load_debug_section (abbrev_sec, file);
2219 if (debug_displays [abbrev_sec].section.start == NULL)
2221 warn (_("Unable to locate %s section!\n"),
2222 debug_displays [abbrev_sec].section.name);
2226 for (section_begin = start, unit = 0; start < end; unit++)
2228 DWARF2_Internal_CompUnit compunit;
2229 unsigned char *hdrptr;
2230 unsigned char *tags;
2231 int level, last_level, saved_level;
2232 dwarf_vma cu_offset;
2233 unsigned int offset_size;
2234 int initial_length_size;
2235 dwarf_vma signature_high = 0;
2236 dwarf_vma signature_low = 0;
2237 dwarf_vma type_offset = 0;
2238 struct cu_tu_set *this_set;
2239 dwarf_vma abbrev_base;
2244 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2246 if (compunit.cu_length == 0xffffffff)
2248 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2250 initial_length_size = 12;
2255 initial_length_size = 4;
2258 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2260 cu_offset = start - section_begin;
2262 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2264 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2266 if (this_set == NULL)
2269 abbrev_size = debug_displays [abbrev_sec].section.size;
2273 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2274 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2277 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2281 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2283 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2286 if ((do_loc || do_debug_loc || do_debug_ranges)
2287 && num_debug_info_entries == 0
2290 debug_information [unit].cu_offset = cu_offset;
2291 debug_information [unit].pointer_size
2292 = compunit.cu_pointer_size;
2293 debug_information [unit].offset_size = offset_size;
2294 debug_information [unit].dwarf_version = compunit.cu_version;
2295 debug_information [unit].base_address = 0;
2296 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2297 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2298 debug_information [unit].loc_offsets = NULL;
2299 debug_information [unit].have_frame_base = NULL;
2300 debug_information [unit].max_loc_offsets = 0;
2301 debug_information [unit].num_loc_offsets = 0;
2302 debug_information [unit].range_lists = NULL;
2303 debug_information [unit].max_range_lists= 0;
2304 debug_information [unit].num_range_lists = 0;
2307 if (!do_loc && dwarf_start_die == 0)
2309 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2310 dwarf_vmatoa ("x", cu_offset));
2311 printf (_(" Length: 0x%s (%s)\n"),
2312 dwarf_vmatoa ("x", compunit.cu_length),
2313 offset_size == 8 ? "64-bit" : "32-bit");
2314 printf (_(" Version: %d\n"), compunit.cu_version);
2315 printf (_(" Abbrev Offset: 0x%s\n"),
2316 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2317 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2322 printf (_(" Signature: 0x%s\n"),
2323 dwarf_vmatoa64 (signature_high, signature_low,
2324 buf, sizeof (buf)));
2325 printf (_(" Type Offset: 0x%s\n"),
2326 dwarf_vmatoa ("x", type_offset));
2328 if (this_set != NULL)
2330 dwarf_vma *offsets = this_set->section_offsets;
2331 size_t *sizes = this_set->section_sizes;
2333 printf (_(" Section contributions:\n"));
2334 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2335 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2336 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2337 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2338 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2339 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2340 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2341 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2342 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2343 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2344 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2345 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2349 if (cu_offset + compunit.cu_length + initial_length_size
2352 warn (_("Debug info is corrupted, length of CU at %s"
2353 " extends beyond end of section (length = %s)\n"),
2354 dwarf_vmatoa ("x", cu_offset),
2355 dwarf_vmatoa ("x", compunit.cu_length));
2359 start += compunit.cu_length + initial_length_size;
2361 if (compunit.cu_version != 2
2362 && compunit.cu_version != 3
2363 && compunit.cu_version != 4)
2365 warn (_("CU at offset %s contains corrupt or "
2366 "unsupported version number: %d.\n"),
2367 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2373 /* Process the abbrevs used by this compilation unit. */
2374 if (compunit.cu_abbrev_offset >= abbrev_size)
2375 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2376 (unsigned long) compunit.cu_abbrev_offset,
2377 (unsigned long) abbrev_size);
2379 process_abbrev_section
2380 (((unsigned char *) debug_displays [abbrev_sec].section.start
2381 + abbrev_base + compunit.cu_abbrev_offset),
2382 ((unsigned char *) debug_displays [abbrev_sec].section.start
2383 + abbrev_base + abbrev_size));
2388 while (tags < start)
2390 unsigned int bytes_read;
2391 unsigned long abbrev_number;
2392 unsigned long die_offset;
2393 abbrev_entry *entry;
2395 int do_printing = 1;
2397 die_offset = tags - section_begin;
2399 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2402 /* A null DIE marks the end of a list of siblings or it may also be
2403 a section padding. */
2404 if (abbrev_number == 0)
2406 /* Check if it can be a section padding for the last CU. */
2407 if (level == 0 && start == end)
2411 for (chk = tags; chk < start; chk++)
2418 if (!do_loc && die_offset >= dwarf_start_die
2419 && (dwarf_cutoff_level == -1
2420 || level < dwarf_cutoff_level))
2421 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2427 static unsigned num_bogus_warns = 0;
2429 if (num_bogus_warns < 3)
2431 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2432 die_offset, section->name);
2434 if (num_bogus_warns == 3)
2435 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2438 if (dwarf_start_die != 0 && level < saved_level)
2445 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2449 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2450 saved_level = level;
2451 do_printing = (dwarf_cutoff_level == -1
2452 || level < dwarf_cutoff_level);
2454 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2455 level, die_offset, abbrev_number);
2456 else if (dwarf_cutoff_level == -1
2457 || last_level < dwarf_cutoff_level)
2458 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2463 /* Scan through the abbreviation list until we reach the
2465 for (entry = first_abbrev;
2466 entry && entry->entry != abbrev_number;
2467 entry = entry->next)
2472 if (!do_loc && do_printing)
2477 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2478 die_offset, abbrev_number);
2482 if (!do_loc && do_printing)
2483 printf (" (%s)\n", get_TAG_name (entry->tag));
2488 need_base_address = 0;
2490 case DW_TAG_compile_unit:
2491 need_base_address = 1;
2493 case DW_TAG_entry_point:
2494 case DW_TAG_subprogram:
2495 need_base_address = 0;
2496 /* Assuming that there is no DW_AT_frame_base. */
2497 have_frame_base = 0;
2501 for (attr = entry->first_attr;
2502 attr && attr->attribute;
2507 if (! do_loc && do_printing)
2508 /* Show the offset from where the tag was extracted. */
2509 printf (" <%lx>", (unsigned long)(tags - section_begin));
2511 arg = debug_information;
2512 if (debug_information)
2515 tags = read_and_display_attr (attr->attribute,
2520 compunit.cu_pointer_size,
2522 compunit.cu_version,
2524 do_loc || ! do_printing,
2529 if (entry->children)
2534 /* Set num_debug_info_entries here so that it can be used to check if
2535 we need to process .debug_loc and .debug_ranges sections. */
2536 if ((do_loc || do_debug_loc || do_debug_ranges)
2537 && num_debug_info_entries == 0
2539 num_debug_info_entries = num_units;
2547 /* Locate and scan the .debug_info section in the file and record the pointer
2548 sizes and offsets for the compilation units in it. Usually an executable
2549 will have just one pointer size, but this is not guaranteed, and so we try
2550 not to make any assumptions. Returns zero upon failure, or the number of
2551 compilation units upon success. */
2554 load_debug_info (void * file)
2556 /* Reset the last pointer size so that we can issue correct error
2557 messages if we are displaying the contents of more than one section. */
2558 last_pointer_size = 0;
2559 warned_about_missing_comp_units = FALSE;
2561 /* If we have already tried and failed to load the .debug_info
2562 section then do not bother to repeat the task. */
2563 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2566 /* If we already have the information there is nothing else to do. */
2567 if (num_debug_info_entries > 0)
2568 return num_debug_info_entries;
2570 /* If this is a DWARF package file, load the CU and TU indexes. */
2571 load_cu_tu_indexes (file);
2573 if (load_debug_section (info, file)
2574 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2575 return num_debug_info_entries;
2576 else if (load_debug_section (info_dwo, file)
2577 && process_debug_info (&debug_displays [info_dwo].section, file,
2579 return num_debug_info_entries;
2581 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2585 /* Read a DWARF .debug_line section header starting at DATA.
2586 Upon success returns an updated DATA pointer and the LINFO
2587 structure and the END_OF_SEQUENCE pointer will be filled in.
2588 Otherwise returns NULL. */
2590 static unsigned char *
2591 read_debug_line_header (struct dwarf_section * section,
2592 unsigned char * data,
2593 unsigned char * end,
2594 DWARF2_Internal_LineInfo * linfo,
2595 unsigned char ** end_of_sequence)
2597 unsigned char *hdrptr;
2598 unsigned int offset_size;
2599 unsigned int initial_length_size;
2601 /* Extract information from the Line Number Program Header.
2602 (section 6.2.4 in the Dwarf3 doc). */
2605 /* Get and check the length of the block. */
2606 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2608 if (linfo->li_length == 0xffffffff)
2610 /* This section is 64-bit DWARF 3. */
2611 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2613 initial_length_size = 12;
2618 initial_length_size = 4;
2621 if (linfo->li_length + initial_length_size > section->size)
2623 /* If the length is just a bias against the initial_length_size then
2624 this means that the field has a relocation against it which has not
2625 been applied. (Ie we are dealing with an object file, not a linked
2626 binary). Do not complain but instead assume that the rest of the
2627 section applies to this particular header. */
2628 if (linfo->li_length == - initial_length_size)
2630 linfo->li_length = section->size - initial_length_size;
2634 warn (_("The line info appears to be corrupt - "
2635 "the section is too small\n"));
2640 /* Get and check the version number. */
2641 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2643 if (linfo->li_version != 2
2644 && linfo->li_version != 3
2645 && linfo->li_version != 4)
2647 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2651 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2652 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2654 if (linfo->li_version >= 4)
2656 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2658 if (linfo->li_max_ops_per_insn == 0)
2660 warn (_("Invalid maximum operations per insn.\n"));
2665 linfo->li_max_ops_per_insn = 1;
2667 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2668 SAFE_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2669 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2670 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2672 /* Sign extend the line base field. */
2673 linfo->li_line_base <<= 24;
2674 linfo->li_line_base >>= 24;
2676 * end_of_sequence = data + linfo->li_length + initial_length_size;
2681 display_debug_lines_raw (struct dwarf_section *section,
2682 unsigned char *data,
2685 unsigned char *start = section->start;
2687 printf (_("Raw dump of debug contents of section %s:\n\n"),
2692 static DWARF2_Internal_LineInfo saved_linfo;
2693 DWARF2_Internal_LineInfo linfo;
2694 unsigned char *standard_opcodes;
2695 unsigned char *end_of_sequence;
2696 unsigned int last_dir_entry = 0;
2699 if (const_strneq (section->name, ".debug_line.")
2700 /* Note: the following does not apply to .debug_line.dwo sections.
2701 These are full debug_line sections. */
2702 && strcmp (section->name, ".debug_line.dwo") != 0)
2704 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2705 section containing just the Line Number Statements. They are
2706 created by the assembler and intended to be used alongside gcc's
2707 -ffunction-sections command line option. When the linker's
2708 garbage collection decides to discard a .text.<foo> section it
2709 can then also discard the line number information in .debug_line.<foo>.
2711 Since the section is a fragment it does not have the details
2712 needed to fill out a LineInfo structure, so instead we use the
2713 details from the last full debug_line section that we processed. */
2714 end_of_sequence = end;
2715 standard_opcodes = NULL;
2716 linfo = saved_linfo;
2717 reset_state_machine (linfo.li_default_is_stmt);
2721 unsigned char * hdrptr;
2723 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2724 & end_of_sequence)) == NULL)
2727 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2728 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2729 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2730 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2731 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2732 if (linfo.li_version >= 4)
2733 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2734 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2735 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2736 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2737 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2739 reset_state_machine (linfo.li_default_is_stmt);
2741 /* Display the contents of the Opcodes table. */
2742 standard_opcodes = hdrptr;
2744 printf (_("\n Opcodes:\n"));
2746 for (i = 1; i < linfo.li_opcode_base; i++)
2747 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2749 /* Display the contents of the Directory table. */
2750 data = standard_opcodes + linfo.li_opcode_base - 1;
2753 printf (_("\n The Directory Table is empty.\n"));
2756 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2757 (long)(data - start));
2761 printf (" %d\t%s\n", ++last_dir_entry, data);
2763 data += strnlen ((char *) data, end - data) + 1;
2767 /* Skip the NUL at the end of the table. */
2770 /* Display the contents of the File Name table. */
2772 printf (_("\n The File Name Table is empty.\n"));
2775 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2776 (long)(data - start));
2777 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2781 unsigned char *name;
2782 unsigned int bytes_read;
2784 printf (" %d\t", ++state_machine_regs.last_file_entry);
2786 data += strnlen ((char *) data, end - data) + 1;
2789 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2792 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2795 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2797 printf ("%s\n", name);
2801 warn (_("Corrupt file name table entry\n"));
2807 /* Skip the NUL at the end of the table. */
2810 saved_linfo = linfo;
2813 /* Now display the statements. */
2814 if (data >= end_of_sequence)
2815 printf (_(" No Line Number Statements.\n"));
2818 printf (_(" Line Number Statements:\n"));
2820 while (data < end_of_sequence)
2822 unsigned char op_code;
2823 dwarf_signed_vma adv;
2825 unsigned int bytes_read;
2827 printf (" [0x%08lx]", (long)(data - start));
2831 if (op_code >= linfo.li_opcode_base)
2833 op_code -= linfo.li_opcode_base;
2834 uladv = (op_code / linfo.li_line_range);
2835 if (linfo.li_max_ops_per_insn == 1)
2837 uladv *= linfo.li_min_insn_length;
2838 state_machine_regs.address += uladv;
2839 printf (_(" Special opcode %d: "
2840 "advance Address by %s to 0x%s"),
2841 op_code, dwarf_vmatoa ("u", uladv),
2842 dwarf_vmatoa ("x", state_machine_regs.address));
2846 state_machine_regs.address
2847 += ((state_machine_regs.op_index + uladv)
2848 / linfo.li_max_ops_per_insn)
2849 * linfo.li_min_insn_length;
2850 state_machine_regs.op_index
2851 = (state_machine_regs.op_index + uladv)
2852 % linfo.li_max_ops_per_insn;
2853 printf (_(" Special opcode %d: "
2854 "advance Address by %s to 0x%s[%d]"),
2855 op_code, dwarf_vmatoa ("u", uladv),
2856 dwarf_vmatoa ("x", state_machine_regs.address),
2857 state_machine_regs.op_index);
2859 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2860 state_machine_regs.line += adv;
2861 printf (_(" and Line by %s to %d\n"),
2862 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2864 else switch (op_code)
2866 case DW_LNS_extended_op:
2867 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
2871 printf (_(" Copy\n"));
2874 case DW_LNS_advance_pc:
2875 uladv = read_uleb128 (data, & bytes_read, end);
2877 if (linfo.li_max_ops_per_insn == 1)
2879 uladv *= linfo.li_min_insn_length;
2880 state_machine_regs.address += uladv;
2881 printf (_(" Advance PC by %s to 0x%s\n"),
2882 dwarf_vmatoa ("u", uladv),
2883 dwarf_vmatoa ("x", state_machine_regs.address));
2887 state_machine_regs.address
2888 += ((state_machine_regs.op_index + uladv)
2889 / linfo.li_max_ops_per_insn)
2890 * linfo.li_min_insn_length;
2891 state_machine_regs.op_index
2892 = (state_machine_regs.op_index + uladv)
2893 % linfo.li_max_ops_per_insn;
2894 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2895 dwarf_vmatoa ("u", uladv),
2896 dwarf_vmatoa ("x", state_machine_regs.address),
2897 state_machine_regs.op_index);
2901 case DW_LNS_advance_line:
2902 adv = read_sleb128 (data, & bytes_read, end);
2904 state_machine_regs.line += adv;
2905 printf (_(" Advance Line by %s to %d\n"),
2906 dwarf_vmatoa ("d", adv),
2907 state_machine_regs.line);
2910 case DW_LNS_set_file:
2911 adv = read_uleb128 (data, & bytes_read, end);
2913 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2914 dwarf_vmatoa ("d", adv));
2915 state_machine_regs.file = adv;
2918 case DW_LNS_set_column:
2919 uladv = read_uleb128 (data, & bytes_read, end);
2921 printf (_(" Set column to %s\n"),
2922 dwarf_vmatoa ("u", uladv));
2923 state_machine_regs.column = uladv;
2926 case DW_LNS_negate_stmt:
2927 adv = state_machine_regs.is_stmt;
2929 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2930 state_machine_regs.is_stmt = adv;
2933 case DW_LNS_set_basic_block:
2934 printf (_(" Set basic block\n"));
2935 state_machine_regs.basic_block = 1;
2938 case DW_LNS_const_add_pc:
2939 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2940 if (linfo.li_max_ops_per_insn)
2942 uladv *= linfo.li_min_insn_length;
2943 state_machine_regs.address += uladv;
2944 printf (_(" Advance PC by constant %s to 0x%s\n"),
2945 dwarf_vmatoa ("u", uladv),
2946 dwarf_vmatoa ("x", state_machine_regs.address));
2950 state_machine_regs.address
2951 += ((state_machine_regs.op_index + uladv)
2952 / linfo.li_max_ops_per_insn)
2953 * linfo.li_min_insn_length;
2954 state_machine_regs.op_index
2955 = (state_machine_regs.op_index + uladv)
2956 % linfo.li_max_ops_per_insn;
2957 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2958 dwarf_vmatoa ("u", uladv),
2959 dwarf_vmatoa ("x", state_machine_regs.address),
2960 state_machine_regs.op_index);
2964 case DW_LNS_fixed_advance_pc:
2965 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
2966 state_machine_regs.address += uladv;
2967 state_machine_regs.op_index = 0;
2968 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2969 dwarf_vmatoa ("u", uladv),
2970 dwarf_vmatoa ("x", state_machine_regs.address));
2973 case DW_LNS_set_prologue_end:
2974 printf (_(" Set prologue_end to true\n"));
2977 case DW_LNS_set_epilogue_begin:
2978 printf (_(" Set epilogue_begin to true\n"));
2981 case DW_LNS_set_isa:
2982 uladv = read_uleb128 (data, & bytes_read, end);
2984 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2988 printf (_(" Unknown opcode %d with operands: "), op_code);
2990 if (standard_opcodes != NULL)
2991 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2993 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
2995 i == 1 ? "" : ", ");
3011 unsigned char *name;
3012 unsigned int directory_index;
3013 unsigned int modification_date;
3014 unsigned int length;
3017 /* Output a decoded representation of the .debug_line section. */
3020 display_debug_lines_decoded (struct dwarf_section *section,
3021 unsigned char *data,
3024 static DWARF2_Internal_LineInfo saved_linfo;
3026 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3031 /* This loop amounts to one iteration per compilation unit. */
3032 DWARF2_Internal_LineInfo linfo;
3033 unsigned char *standard_opcodes;
3034 unsigned char *end_of_sequence;
3036 File_Entry *file_table = NULL;
3037 unsigned int n_files = 0;
3038 unsigned char **directory_table = NULL;
3039 unsigned int n_directories = 0;
3041 if (const_strneq (section->name, ".debug_line.")
3042 /* Note: the following does not apply to .debug_line.dwo sections.
3043 These are full debug_line sections. */
3044 && strcmp (section->name, ".debug_line.dwo") != 0)
3046 /* See comment in display_debug_lines_raw(). */
3047 end_of_sequence = end;
3048 standard_opcodes = NULL;
3049 linfo = saved_linfo;
3050 reset_state_machine (linfo.li_default_is_stmt);
3054 unsigned char *hdrptr;
3056 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3057 & end_of_sequence)) == NULL)
3060 reset_state_machine (linfo.li_default_is_stmt);
3062 /* Save a pointer to the contents of the Opcodes table. */
3063 standard_opcodes = hdrptr;
3065 /* Traverse the Directory table just to count entries. */
3066 data = standard_opcodes + linfo.li_opcode_base - 1;
3069 unsigned char *ptr_directory_table = data;
3073 data += strnlen ((char *) data, end - data) + 1;
3077 /* Go through the directory table again to save the directories. */
3078 directory_table = (unsigned char **)
3079 xmalloc (n_directories * sizeof (unsigned char *));
3082 while (*ptr_directory_table != 0)
3084 directory_table[i] = ptr_directory_table;
3085 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3086 ptr_directory_table - end) + 1;
3090 /* Skip the NUL at the end of the table. */
3093 /* Traverse the File Name table just to count the entries. */
3096 unsigned char *ptr_file_name_table = data;
3100 unsigned int bytes_read;
3102 /* Skip Name, directory index, last modification time and length
3104 data += strnlen ((char *) data, end - data) + 1;
3105 read_uleb128 (data, & bytes_read, end);
3107 read_uleb128 (data, & bytes_read, end);
3109 read_uleb128 (data, & bytes_read, end);
3115 /* Go through the file table again to save the strings. */
3116 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3119 while (*ptr_file_name_table != 0)
3121 unsigned int bytes_read;
3123 file_table[i].name = ptr_file_name_table;
3124 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3125 end - ptr_file_name_table) + 1;
3127 /* We are not interested in directory, time or size. */
3128 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3130 ptr_file_name_table += bytes_read;
3131 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3133 ptr_file_name_table += bytes_read;
3134 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3135 ptr_file_name_table += bytes_read;
3140 /* Print the Compilation Unit's name and a header. */
3141 if (directory_table == NULL)
3143 printf (_("CU: %s:\n"), file_table[0].name);
3144 printf (_("File name Line number Starting address\n"));
3148 unsigned int ix = file_table[0].directory_index;
3149 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
3151 if (do_wide || strlen (directory) < 76)
3152 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3154 printf ("%s:\n", file_table[0].name);
3156 printf (_("File name Line number Starting address\n"));
3160 /* Skip the NUL at the end of the table. */
3163 saved_linfo = linfo;
3166 /* This loop iterates through the Dwarf Line Number Program. */
3167 while (data < end_of_sequence)
3169 unsigned char op_code;
3171 unsigned long int uladv;
3172 unsigned int bytes_read;
3173 int is_special_opcode = 0;
3177 if (op_code >= linfo.li_opcode_base)
3179 op_code -= linfo.li_opcode_base;
3180 uladv = (op_code / linfo.li_line_range);
3181 if (linfo.li_max_ops_per_insn == 1)
3183 uladv *= linfo.li_min_insn_length;
3184 state_machine_regs.address += uladv;
3188 state_machine_regs.address
3189 += ((state_machine_regs.op_index + uladv)
3190 / linfo.li_max_ops_per_insn)
3191 * linfo.li_min_insn_length;
3192 state_machine_regs.op_index
3193 = (state_machine_regs.op_index + uladv)
3194 % linfo.li_max_ops_per_insn;
3197 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3198 state_machine_regs.line += adv;
3199 is_special_opcode = 1;
3201 else switch (op_code)
3203 case DW_LNS_extended_op:
3205 unsigned int ext_op_code_len;
3206 unsigned char ext_op_code;
3207 unsigned char *op_code_data = data;
3209 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3211 op_code_data += bytes_read;
3213 if (ext_op_code_len == 0)
3215 warn (_("badly formed extended line op encountered!\n"));
3218 ext_op_code_len += bytes_read;
3219 ext_op_code = *op_code_data++;
3221 switch (ext_op_code)
3223 case DW_LNE_end_sequence:
3224 reset_state_machine (linfo.li_default_is_stmt);
3226 case DW_LNE_set_address:
3227 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3229 ext_op_code_len - bytes_read - 1,
3231 state_machine_regs.op_index = 0;
3233 case DW_LNE_define_file:
3235 file_table = (File_Entry *) xrealloc
3236 (file_table, (n_files + 1) * sizeof (File_Entry));
3238 ++state_machine_regs.last_file_entry;
3239 /* Source file name. */
3240 file_table[n_files].name = op_code_data;
3241 op_code_data += strlen ((char *) op_code_data) + 1;
3242 /* Directory index. */
3243 file_table[n_files].directory_index =
3244 read_uleb128 (op_code_data, & bytes_read,
3246 op_code_data += bytes_read;
3247 /* Last modification time. */
3248 file_table[n_files].modification_date =
3249 read_uleb128 (op_code_data, & bytes_read,
3251 op_code_data += bytes_read;
3253 file_table[n_files].length =
3254 read_uleb128 (op_code_data, & bytes_read,
3260 case DW_LNE_set_discriminator:
3261 case DW_LNE_HP_set_sequence:
3262 /* Simply ignored. */
3266 printf (_("UNKNOWN (%u): length %d\n"),
3267 ext_op_code, ext_op_code_len - bytes_read);
3270 data += ext_op_code_len;
3276 case DW_LNS_advance_pc:
3277 uladv = read_uleb128 (data, & bytes_read, end);
3279 if (linfo.li_max_ops_per_insn == 1)
3281 uladv *= linfo.li_min_insn_length;
3282 state_machine_regs.address += uladv;
3286 state_machine_regs.address
3287 += ((state_machine_regs.op_index + uladv)
3288 / linfo.li_max_ops_per_insn)
3289 * linfo.li_min_insn_length;
3290 state_machine_regs.op_index
3291 = (state_machine_regs.op_index + uladv)
3292 % linfo.li_max_ops_per_insn;
3296 case DW_LNS_advance_line:
3297 adv = read_sleb128 (data, & bytes_read, end);
3299 state_machine_regs.line += adv;
3302 case DW_LNS_set_file:
3303 adv = read_uleb128 (data, & bytes_read, end);
3305 state_machine_regs.file = adv;
3307 if (file_table == NULL)
3308 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
3309 else if (file_table[state_machine_regs.file - 1].directory_index == 0)
3310 /* If directory index is 0, that means current directory. */
3311 printf ("\n./%s:[++]\n",
3312 file_table[state_machine_regs.file - 1].name);
3313 else if (directory_table == NULL)
3314 printf (_("\n [Use directory table entry %d]\n"),
3315 file_table[state_machine_regs.file - 1].directory_index - 1);
3317 /* The directory index starts counting at 1. */
3318 printf ("\n%s/%s:\n",
3319 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3320 file_table[state_machine_regs.file - 1].name);
3323 case DW_LNS_set_column:
3324 uladv = read_uleb128 (data, & bytes_read, end);
3326 state_machine_regs.column = uladv;
3329 case DW_LNS_negate_stmt:
3330 adv = state_machine_regs.is_stmt;
3332 state_machine_regs.is_stmt = adv;
3335 case DW_LNS_set_basic_block:
3336 state_machine_regs.basic_block = 1;
3339 case DW_LNS_const_add_pc:
3340 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3341 if (linfo.li_max_ops_per_insn == 1)
3343 uladv *= linfo.li_min_insn_length;
3344 state_machine_regs.address += uladv;
3348 state_machine_regs.address
3349 += ((state_machine_regs.op_index + uladv)
3350 / linfo.li_max_ops_per_insn)
3351 * linfo.li_min_insn_length;
3352 state_machine_regs.op_index
3353 = (state_machine_regs.op_index + uladv)
3354 % linfo.li_max_ops_per_insn;
3358 case DW_LNS_fixed_advance_pc:
3359 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3360 state_machine_regs.address += uladv;
3361 state_machine_regs.op_index = 0;
3364 case DW_LNS_set_prologue_end:
3367 case DW_LNS_set_epilogue_begin:
3370 case DW_LNS_set_isa:
3371 uladv = read_uleb128 (data, & bytes_read, end);
3373 printf (_(" Set ISA to %lu\n"), uladv);
3377 printf (_(" Unknown opcode %d with operands: "), op_code);
3379 if (standard_opcodes != NULL)
3380 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3382 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3384 i == 1 ? "" : ", ");
3391 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3392 to the DWARF address/line matrix. */
3393 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3394 || (op_code == DW_LNS_copy))
3396 const unsigned int MAX_FILENAME_LENGTH = 35;
3398 char *newFileName = NULL;
3399 size_t fileNameLength;
3402 fileName = (char *) file_table[state_machine_regs.file - 1].name;
3404 fileName = "<unknown>";
3406 fileNameLength = strlen (fileName);
3408 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3410 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3411 /* Truncate file name */
3412 strncpy (newFileName,
3413 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3414 MAX_FILENAME_LENGTH + 1);
3418 newFileName = (char *) xmalloc (fileNameLength + 1);
3419 strncpy (newFileName, fileName, fileNameLength + 1);
3422 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3424 if (linfo.li_max_ops_per_insn == 1)
3425 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3426 newFileName, state_machine_regs.line,
3427 state_machine_regs.address);
3429 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3430 newFileName, state_machine_regs.line,
3431 state_machine_regs.address,
3432 state_machine_regs.op_index);
3436 if (linfo.li_max_ops_per_insn == 1)
3437 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3438 newFileName, state_machine_regs.line,
3439 state_machine_regs.address);
3441 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3442 newFileName, state_machine_regs.line,
3443 state_machine_regs.address,
3444 state_machine_regs.op_index);
3447 if (op_code == DW_LNE_end_sequence)
3461 if (directory_table)
3463 free (directory_table);
3464 directory_table = NULL;
3475 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3477 unsigned char *data = section->start;
3478 unsigned char *end = data + section->size;
3480 int retValDecoded = 1;
3482 if (do_debug_lines == 0)
3483 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3485 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3486 retValRaw = display_debug_lines_raw (section, data, end);
3488 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3489 retValDecoded = display_debug_lines_decoded (section, data, end);
3491 if (!retValRaw || !retValDecoded)
3498 find_debug_info_for_offset (unsigned long offset)
3502 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3505 for (i = 0; i < num_debug_info_entries; i++)
3506 if (debug_information[i].cu_offset == offset)
3507 return debug_information + i;
3513 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3515 /* See gdb/gdb-index.h. */
3516 static const char * const kinds[] =
3528 return _ (kinds[kind]);
3532 display_debug_pubnames_worker (struct dwarf_section *section,
3533 void *file ATTRIBUTE_UNUSED,
3536 DWARF2_Internal_PubNames names;
3537 unsigned char *start = section->start;
3538 unsigned char *end = start + section->size;
3540 /* It does not matter if this load fails,
3541 we test for that later on. */
3542 load_debug_info (file);
3544 printf (_("Contents of the %s section:\n\n"), section->name);
3548 unsigned char *data;
3549 unsigned long offset;
3550 unsigned int offset_size, initial_length_size;
3554 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3555 if (names.pn_length == 0xffffffff)
3557 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3559 initial_length_size = 12;
3564 initial_length_size = 4;
3567 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3568 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3570 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3571 && num_debug_info_entries > 0
3572 && find_debug_info_for_offset (names.pn_offset) == NULL)
3573 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3574 (unsigned long) names.pn_offset, section->name);
3576 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3578 start += names.pn_length + initial_length_size;
3580 if (names.pn_version != 2 && names.pn_version != 3)
3582 static int warned = 0;
3586 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3593 printf (_(" Length: %ld\n"),
3594 (long) names.pn_length);
3595 printf (_(" Version: %d\n"),
3597 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3598 (unsigned long) names.pn_offset);
3599 printf (_(" Size of area in .debug_info section: %ld\n"),
3600 (long) names.pn_size);
3603 printf (_("\n Offset Kind Name\n"));
3605 printf (_("\n Offset\tName\n"));
3609 SAFE_BYTE_GET (offset, data, offset_size, end);
3613 data += offset_size;
3616 unsigned int kind_data;
3617 gdb_index_symbol_kind kind;
3618 const char *kind_name;
3621 SAFE_BYTE_GET (kind_data, data, 1, end);
3623 /* GCC computes the kind as the upper byte in the CU index
3624 word, and then right shifts it by the CU index size.
3625 Left shift KIND to where the gdb-index.h accessor macros
3627 kind_data <<= GDB_INDEX_CU_BITSIZE;
3628 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3629 kind_name = get_gdb_index_symbol_kind_name (kind);
3630 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3631 printf (" %-6lx %s,%-10s %s\n",
3632 offset, is_static ? _("s") : _("g"),
3636 printf (" %-6lx\t%s\n", offset, data);
3637 data += strnlen ((char *) data, end - data) + 1;
3640 while (offset != 0);
3648 display_debug_pubnames (struct dwarf_section *section, void *file)
3650 return display_debug_pubnames_worker (section, file, 0);
3654 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3656 return display_debug_pubnames_worker (section, file, 1);
3660 display_debug_macinfo (struct dwarf_section *section,
3661 void *file ATTRIBUTE_UNUSED)
3663 unsigned char *start = section->start;
3664 unsigned char *end = start + section->size;
3665 unsigned char *curr = start;
3666 unsigned int bytes_read;
3667 enum dwarf_macinfo_record_type op;
3669 printf (_("Contents of the %s section:\n\n"), section->name);
3673 unsigned int lineno;
3674 const unsigned char *string;
3676 op = (enum dwarf_macinfo_record_type) *curr;
3681 case DW_MACINFO_start_file:
3683 unsigned int filenum;
3685 lineno = read_uleb128 (curr, & bytes_read, end);
3687 filenum = read_uleb128 (curr, & bytes_read, end);
3690 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3695 case DW_MACINFO_end_file:
3696 printf (_(" DW_MACINFO_end_file\n"));
3699 case DW_MACINFO_define:
3700 lineno = read_uleb128 (curr, & bytes_read, end);
3703 curr += strnlen ((char *) string, end - string) + 1;
3704 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3708 case DW_MACINFO_undef:
3709 lineno = read_uleb128 (curr, & bytes_read, end);
3712 curr += strnlen ((char *) string, end - string) + 1;
3713 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3717 case DW_MACINFO_vendor_ext:
3719 unsigned int constant;
3721 constant = read_uleb128 (curr, & bytes_read, end);
3724 curr += strnlen ((char *) string, end - string) + 1;
3725 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3735 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3736 filename and dirname corresponding to file name table entry with index
3737 FILEIDX. Return NULL on failure. */
3739 static unsigned char *
3740 get_line_filename_and_dirname (dwarf_vma line_offset,
3742 unsigned char **dir_name)
3744 struct dwarf_section *section = &debug_displays [line].section;
3745 unsigned char *hdrptr, *dirtable, *file_name;
3746 unsigned int offset_size, initial_length_size;
3747 unsigned int version, opcode_base, bytes_read;
3748 dwarf_vma length, diridx;
3749 const unsigned char * end;
3752 if (section->start == NULL
3753 || line_offset >= section->size
3757 hdrptr = section->start + line_offset;
3758 end = section->start + section->size;
3760 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
3761 if (length == 0xffffffff)
3763 /* This section is 64-bit DWARF 3. */
3764 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
3766 initial_length_size = 12;
3771 initial_length_size = 4;
3773 if (length + initial_length_size > section->size)
3776 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
3777 if (version != 2 && version != 3 && version != 4)
3779 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3781 hdrptr++; /* Skip max_ops_per_insn. */
3782 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3784 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
3785 if (opcode_base == 0)
3788 hdrptr += opcode_base - 1;
3790 /* Skip over dirname table. */
3791 while (*hdrptr != '\0')
3792 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3793 hdrptr++; /* Skip the NUL at the end of the table. */
3794 /* Now skip over preceding filename table entries. */
3795 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3797 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3798 read_uleb128 (hdrptr, &bytes_read, end);
3799 hdrptr += bytes_read;
3800 read_uleb128 (hdrptr, &bytes_read, end);
3801 hdrptr += bytes_read;
3802 read_uleb128 (hdrptr, &bytes_read, end);
3803 hdrptr += bytes_read;
3805 if (hdrptr == end || *hdrptr == '\0')
3808 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3809 diridx = read_uleb128 (hdrptr, &bytes_read, end);
3812 for (; *dirtable != '\0' && diridx > 1; diridx--)
3813 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
3814 if (*dirtable == '\0')
3816 *dir_name = dirtable;
3821 display_debug_macro (struct dwarf_section *section,
3824 unsigned char *start = section->start;
3825 unsigned char *end = start + section->size;
3826 unsigned char *curr = start;
3827 unsigned char *extended_op_buf[256];
3828 unsigned int bytes_read;
3830 load_debug_section (str, file);
3831 load_debug_section (line, file);
3833 printf (_("Contents of the %s section:\n\n"), section->name);
3837 unsigned int lineno, version, flags;
3838 unsigned int offset_size = 4;
3839 const unsigned char *string;
3840 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3841 unsigned char **extended_ops = NULL;
3843 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
3846 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3851 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
3854 printf (_(" Offset: 0x%lx\n"),
3855 (unsigned long) sec_offset);
3856 printf (_(" Version: %d\n"), version);
3857 printf (_(" Offset size: %d\n"), offset_size);
3860 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
3861 printf (_(" Offset into .debug_line: 0x%lx\n"),
3862 (unsigned long) line_offset);
3866 unsigned int i, count, op;
3869 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
3871 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3872 extended_ops = extended_op_buf;
3875 printf (_(" Extension opcode arguments:\n"));
3876 for (i = 0; i < count; i++)
3878 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
3879 extended_ops[op] = curr;
3880 nargs = read_uleb128 (curr, &bytes_read, end);
3883 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3886 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3887 for (n = 0; n < nargs; n++)
3891 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
3892 printf ("%s%s", get_FORM_name (form),
3893 n == nargs - 1 ? "\n" : ", ");
3903 case DW_FORM_block1:
3904 case DW_FORM_block2:
3905 case DW_FORM_block4:
3907 case DW_FORM_string:
3909 case DW_FORM_sec_offset:
3912 error (_("Invalid extension opcode form %s\n"),
3913 get_FORM_name (form));
3929 error (_(".debug_macro section not zero terminated\n"));
3933 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
3939 case DW_MACRO_GNU_start_file:
3941 unsigned int filenum;
3942 unsigned char *file_name = NULL, *dir_name = NULL;
3944 lineno = read_uleb128 (curr, &bytes_read, end);
3946 filenum = read_uleb128 (curr, &bytes_read, end);
3949 if ((flags & 2) == 0)
3950 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3953 = get_line_filename_and_dirname (line_offset, filenum,
3955 if (file_name == NULL)
3956 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3959 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3961 dir_name != NULL ? (const char *) dir_name : "",
3962 dir_name != NULL ? "/" : "", file_name);
3966 case DW_MACRO_GNU_end_file:
3967 printf (_(" DW_MACRO_GNU_end_file\n"));
3970 case DW_MACRO_GNU_define:
3971 lineno = read_uleb128 (curr, &bytes_read, end);
3974 curr += strnlen ((char *) string, end - string) + 1;
3975 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3979 case DW_MACRO_GNU_undef:
3980 lineno = read_uleb128 (curr, &bytes_read, end);
3983 curr += strnlen ((char *) string, end - string) + 1;
3984 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3988 case DW_MACRO_GNU_define_indirect:
3989 lineno = read_uleb128 (curr, &bytes_read, end);
3991 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
3992 string = fetch_indirect_string (offset);
3993 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3997 case DW_MACRO_GNU_undef_indirect:
3998 lineno = read_uleb128 (curr, &bytes_read, end);
4000 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4001 string = fetch_indirect_string (offset);
4002 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4006 case DW_MACRO_GNU_transparent_include:
4007 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4008 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4009 (unsigned long) offset);
4012 case DW_MACRO_GNU_define_indirect_alt:
4013 lineno = read_uleb128 (curr, &bytes_read, end);
4015 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4016 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4017 lineno, (unsigned long) offset);
4020 case DW_MACRO_GNU_undef_indirect_alt:
4021 lineno = read_uleb128 (curr, &bytes_read, end);
4023 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4024 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4025 lineno, (unsigned long) offset);
4028 case DW_MACRO_GNU_transparent_include_alt:
4029 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4030 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4031 (unsigned long) offset);
4035 if (extended_ops == NULL || extended_ops[op] == NULL)
4037 error (_(" Unknown macro opcode %02x seen\n"), op);
4042 /* Skip over unhandled opcodes. */
4044 unsigned char *desc = extended_ops[op];
4045 nargs = read_uleb128 (desc, &bytes_read, end);
4049 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4052 printf (_(" DW_MACRO_GNU_%02x -"), op);
4053 for (n = 0; n < nargs; n++)
4057 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4059 = read_and_display_attr_value (0, val,
4060 curr, end, 0, 0, offset_size,
4061 version, NULL, 0, NULL,
4079 display_debug_abbrev (struct dwarf_section *section,
4080 void *file ATTRIBUTE_UNUSED)
4082 abbrev_entry *entry;
4083 unsigned char *start = section->start;
4084 unsigned char *end = start + section->size;
4086 printf (_("Contents of the %s section:\n\n"), section->name);
4090 unsigned char *last;
4095 start = process_abbrev_section (start, end);
4097 if (first_abbrev == NULL)
4100 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4102 for (entry = first_abbrev; entry; entry = entry->next)
4106 printf (" %ld %s [%s]\n",
4108 get_TAG_name (entry->tag),
4109 entry->children ? _("has children") : _("no children"));
4111 for (attr = entry->first_attr; attr; attr = attr->next)
4112 printf (" %-18s %s\n",
4113 get_AT_name (attr->attribute),
4114 get_FORM_name (attr->form));
4124 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4127 display_loc_list (struct dwarf_section *section,
4128 unsigned char **start_ptr,
4129 int debug_info_entry,
4130 unsigned long offset,
4131 unsigned long base_address,
4134 unsigned char *start = *start_ptr;
4135 unsigned char *section_end = section->start + section->size;
4136 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4137 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4138 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4139 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4143 unsigned short length;
4144 int need_frame_base;
4148 if (start + 2 * pointer_size > section_end)
4150 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4155 printf (" %8.8lx ", offset + (start - *start_ptr));
4157 /* Note: we use sign extension here in order to be sure that we can detect
4158 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4159 address will not affect the values that we display since we always show
4160 hex values, and always the bottom 32-bits. */
4161 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4162 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4164 if (begin == 0 && end == 0)
4166 printf (_("<End of list>\n"));
4170 /* Check base address specifiers. */
4171 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4174 print_dwarf_vma (begin, pointer_size);
4175 print_dwarf_vma (end, pointer_size);
4176 printf (_("(base address)\n"));
4180 if (start + 2 > section_end)
4182 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4187 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4189 if (start + length > section_end)
4191 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4196 print_dwarf_vma (begin + base_address, pointer_size);
4197 print_dwarf_vma (end + base_address, pointer_size);
4200 need_frame_base = decode_location_expression (start,
4205 cu_offset, section);
4208 if (need_frame_base && !has_frame_base)
4209 printf (_(" [without DW_AT_frame_base]"));
4212 fputs (_(" (start == end)"), stdout);
4213 else if (begin > end)
4214 fputs (_(" (start > end)"), stdout);
4224 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4225 right-adjusted in a field of length LEN, and followed by a space. */
4228 print_addr_index (unsigned int idx, unsigned int len)
4230 static char buf[15];
4231 snprintf (buf, sizeof (buf), "[%d]", idx);
4232 printf ("%*s ", len, buf);
4235 /* Display a location list from a .dwo section. It uses address indexes rather
4236 than embedded addresses. This code closely follows display_loc_list, but the
4237 two are sufficiently different that combining things is very ugly. */
4240 display_loc_list_dwo (struct dwarf_section *section,
4241 unsigned char **start_ptr,
4242 int debug_info_entry,
4243 unsigned long offset,
4246 unsigned char *start = *start_ptr;
4247 unsigned char *section_end = section->start + section->size;
4248 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4249 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4250 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4251 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4253 unsigned short length;
4254 int need_frame_base;
4256 unsigned int bytes_read;
4260 printf (" %8.8lx ", offset + (start - *start_ptr));
4262 if (start >= section_end)
4264 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4269 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4272 case 0: /* A terminating entry. */
4274 printf (_("<End of list>\n"));
4276 case 1: /* A base-address entry. */
4277 idx = read_uleb128 (start, &bytes_read, section_end);
4278 start += bytes_read;
4279 print_addr_index (idx, 8);
4281 printf (_("(base address selection entry)\n"));
4283 case 2: /* A start/end entry. */
4284 idx = read_uleb128 (start, &bytes_read, section_end);
4285 start += bytes_read;
4286 print_addr_index (idx, 8);
4287 idx = read_uleb128 (start, &bytes_read, section_end);
4288 start += bytes_read;
4289 print_addr_index (idx, 8);
4291 case 3: /* A start/length entry. */
4292 idx = read_uleb128 (start, &bytes_read, section_end);
4293 start += bytes_read;
4294 print_addr_index (idx, 8);
4295 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4296 printf ("%08x ", idx);
4298 case 4: /* An offset pair entry. */
4299 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4300 printf ("%08x ", idx);
4301 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4302 printf ("%08x ", idx);
4305 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4310 if (start + 2 > section_end)
4312 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4317 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4318 if (start + length > section_end)
4320 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4326 need_frame_base = decode_location_expression (start,
4331 cu_offset, section);
4334 if (need_frame_base && !has_frame_base)
4335 printf (_(" [without DW_AT_frame_base]"));
4345 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4347 static dwarf_vma *loc_offsets;
4350 loc_offsets_compar (const void *ap, const void *bp)
4352 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4353 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4355 return (a > b) - (b > a);
4359 display_debug_loc (struct dwarf_section *section, void *file)
4361 unsigned char *start = section->start;
4362 unsigned long bytes;
4363 unsigned char *section_begin = start;
4364 unsigned int num_loc_list = 0;
4365 unsigned long last_offset = 0;
4366 unsigned int first = 0;
4370 int seen_first_offset = 0;
4371 int locs_sorted = 1;
4372 unsigned char *next;
4373 unsigned int *array = NULL;
4374 const char *suffix = strrchr (section->name, '.');
4377 if (suffix && strcmp (suffix, ".dwo") == 0)
4380 bytes = section->size;
4384 printf (_("\nThe %s section is empty.\n"), section->name);
4388 if (load_debug_info (file) == 0)
4390 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4395 /* Check the order of location list in .debug_info section. If
4396 offsets of location lists are in the ascending order, we can
4397 use `debug_information' directly. */
4398 for (i = 0; i < num_debug_info_entries; i++)
4402 num = debug_information [i].num_loc_offsets;
4403 if (num > num_loc_list)
4406 /* Check if we can use `debug_information' directly. */
4407 if (locs_sorted && num != 0)
4409 if (!seen_first_offset)
4411 /* This is the first location list. */
4412 last_offset = debug_information [i].loc_offsets [0];
4414 seen_first_offset = 1;
4420 for (; j < num; j++)
4423 debug_information [i].loc_offsets [j])
4428 last_offset = debug_information [i].loc_offsets [j];
4433 if (!seen_first_offset)
4434 error (_("No location lists in .debug_info section!\n"));
4436 if (debug_information [first].num_loc_offsets > 0
4437 && debug_information [first].loc_offsets [0] != 0)
4438 warn (_("Location lists in %s section start at 0x%s\n"),
4440 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4443 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4444 printf (_("Contents of the %s section:\n\n"), section->name);
4445 printf (_(" Offset Begin End Expression\n"));
4447 seen_first_offset = 0;
4448 for (i = first; i < num_debug_info_entries; i++)
4450 unsigned long offset;
4451 unsigned long base_address;
4456 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4458 loc_offsets = debug_information [i].loc_offsets;
4459 qsort (array, debug_information [i].num_loc_offsets,
4460 sizeof (*array), loc_offsets_compar);
4463 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4465 j = locs_sorted ? k : array[k];
4467 && debug_information [i].loc_offsets [locs_sorted
4468 ? k - 1 : array [k - 1]]
4469 == debug_information [i].loc_offsets [j])
4471 has_frame_base = debug_information [i].have_frame_base [j];
4472 offset = debug_information [i].loc_offsets [j];
4473 next = section_begin + offset;
4474 base_address = debug_information [i].base_address;
4476 if (!seen_first_offset)
4477 seen_first_offset = 1;
4481 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4482 (unsigned long) (start - section_begin),
4483 (unsigned long) (next - section_begin));
4484 else if (start > next)
4485 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4486 (unsigned long) (start - section_begin),
4487 (unsigned long) (next - section_begin));
4491 if (offset >= bytes)
4493 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4499 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4501 display_loc_list (section, &start, i, offset, base_address,
4506 if (start < section->start + section->size)
4507 warn (_("There are %ld unused bytes at the end of section %s\n"),
4508 (long) (section->start + section->size - start), section->name);
4515 display_debug_str (struct dwarf_section *section,
4516 void *file ATTRIBUTE_UNUSED)
4518 unsigned char *start = section->start;
4519 unsigned long bytes = section->size;
4520 dwarf_vma addr = section->address;
4524 printf (_("\nThe %s section is empty.\n"), section->name);
4528 printf (_("Contents of the %s section:\n\n"), section->name);
4536 lbytes = (bytes > 16 ? 16 : bytes);
4538 printf (" 0x%8.8lx ", (unsigned long) addr);
4540 for (j = 0; j < 16; j++)
4543 printf ("%2.2x", start[j]);
4551 for (j = 0; j < lbytes; j++)
4554 if (k >= ' ' && k < 0x80)
4573 display_debug_info (struct dwarf_section *section, void *file)
4575 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4579 display_debug_types (struct dwarf_section *section, void *file)
4581 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4585 display_trace_info (struct dwarf_section *section, void *file)
4587 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4591 display_debug_aranges (struct dwarf_section *section,
4592 void *file ATTRIBUTE_UNUSED)
4594 unsigned char *start = section->start;
4595 unsigned char *end = start + section->size;
4597 printf (_("Contents of the %s section:\n\n"), section->name);
4599 /* It does not matter if this load fails,
4600 we test for that later on. */
4601 load_debug_info (file);
4605 unsigned char *hdrptr;
4606 DWARF2_Internal_ARange arange;
4607 unsigned char *addr_ranges;
4610 unsigned char address_size;
4612 unsigned int offset_size;
4613 unsigned int initial_length_size;
4617 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4618 if (arange.ar_length == 0xffffffff)
4620 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4622 initial_length_size = 12;
4627 initial_length_size = 4;
4630 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4631 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4633 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4634 && num_debug_info_entries > 0
4635 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4636 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4637 (unsigned long) arange.ar_info_offset, section->name);
4639 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4640 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4642 if (arange.ar_version != 2 && arange.ar_version != 3)
4644 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4648 printf (_(" Length: %ld\n"),
4649 (long) arange.ar_length);
4650 printf (_(" Version: %d\n"), arange.ar_version);
4651 printf (_(" Offset into .debug_info: 0x%lx\n"),
4652 (unsigned long) arange.ar_info_offset);
4653 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4654 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4656 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4658 if (address_size == 0)
4660 error (_("Invalid address size in %s section!\n"),
4665 /* The DWARF spec does not require that the address size be a power
4666 of two, but we do. This will have to change if we ever encounter
4667 an uneven architecture. */
4668 if ((address_size & (address_size - 1)) != 0)
4670 warn (_("Pointer size + Segment size is not a power of two.\n"));
4674 if (address_size > 4)
4675 printf (_("\n Address Length\n"));
4677 printf (_("\n Address Length\n"));
4679 addr_ranges = hdrptr;
4681 /* Must pad to an alignment boundary that is twice the address size. */
4682 excess = (hdrptr - start) % (2 * address_size);
4684 addr_ranges += (2 * address_size) - excess;
4686 start += arange.ar_length + initial_length_size;
4688 while (addr_ranges + 2 * address_size <= start)
4690 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4691 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
4694 print_dwarf_vma (address, address_size);
4695 print_dwarf_vma (length, address_size);
4705 /* Comparison function for qsort. */
4707 comp_addr_base (const void * v0, const void * v1)
4709 debug_info * info0 = (debug_info *) v0;
4710 debug_info * info1 = (debug_info *) v1;
4711 return info0->addr_base - info1->addr_base;
4714 /* Display the debug_addr section. */
4716 display_debug_addr (struct dwarf_section *section,
4719 debug_info **debug_addr_info;
4720 unsigned char *entry;
4725 if (section->size == 0)
4727 printf (_("\nThe %s section is empty.\n"), section->name);
4731 if (load_debug_info (file) == 0)
4733 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4738 printf (_("Contents of the %s section:\n\n"), section->name);
4740 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4741 * sizeof (debug_info *));
4744 for (i = 0; i < num_debug_info_entries; i++)
4746 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4747 debug_addr_info [count++] = &debug_information [i];
4750 /* Add a sentinel to make iteration convenient. */
4751 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4752 debug_addr_info [count]->addr_base = section->size;
4754 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4755 for (i = 0; i < count; i++)
4758 unsigned int address_size = debug_addr_info [i]->pointer_size;
4760 printf (_(" For compilation unit at offset 0x%s:\n"),
4761 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4763 printf (_("\tIndex\tAddress\n"));
4764 entry = section->start + debug_addr_info [i]->addr_base;
4765 end = section->start + debug_addr_info [i + 1]->addr_base;
4769 dwarf_vma base = byte_get (entry, address_size);
4770 printf (_("\t%d:\t"), idx);
4771 print_dwarf_vma (base, address_size);
4773 entry += address_size;
4779 free (debug_addr_info);
4783 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4785 display_debug_str_offsets (struct dwarf_section *section,
4786 void *file ATTRIBUTE_UNUSED)
4788 if (section->size == 0)
4790 printf (_("\nThe %s section is empty.\n"), section->name);
4793 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4794 what the offset size is for this section. */
4798 /* Each debug_information[x].range_lists[y] gets this representation for
4799 sorting purposes. */
4803 /* The debug_information[x].range_lists[y] value. */
4804 unsigned long ranges_offset;
4806 /* Original debug_information to find parameters of the data. */
4807 debug_info *debug_info_p;
4810 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4813 range_entry_compar (const void *ap, const void *bp)
4815 const struct range_entry *a_re = (const struct range_entry *) ap;
4816 const struct range_entry *b_re = (const struct range_entry *) bp;
4817 const unsigned long a = a_re->ranges_offset;
4818 const unsigned long b = b_re->ranges_offset;
4820 return (a > b) - (b > a);
4824 display_debug_ranges (struct dwarf_section *section,
4825 void *file ATTRIBUTE_UNUSED)
4827 unsigned char *start = section->start;
4828 unsigned char *last_start = start;
4829 unsigned long bytes = section->size;
4830 unsigned char *section_begin = start;
4831 unsigned char *finish = start + bytes;
4832 unsigned int num_range_list, i;
4833 struct range_entry *range_entries, *range_entry_fill;
4837 printf (_("\nThe %s section is empty.\n"), section->name);
4841 if (load_debug_info (file) == 0)
4843 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4849 for (i = 0; i < num_debug_info_entries; i++)
4850 num_range_list += debug_information [i].num_range_lists;
4852 if (num_range_list == 0)
4854 /* This can happen when the file was compiled with -gsplit-debug
4855 which removes references to range lists from the primary .o file. */
4856 printf (_("No range lists in .debug_info section.\n"));
4860 range_entries = (struct range_entry *)
4861 xmalloc (sizeof (*range_entries) * num_range_list);
4862 range_entry_fill = range_entries;
4864 for (i = 0; i < num_debug_info_entries; i++)
4866 debug_info *debug_info_p = &debug_information[i];
4869 for (j = 0; j < debug_info_p->num_range_lists; j++)
4871 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4872 range_entry_fill->debug_info_p = debug_info_p;
4877 qsort (range_entries, num_range_list, sizeof (*range_entries),
4878 range_entry_compar);
4880 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
4881 warn (_("Range lists in %s section start at 0x%lx\n"),
4882 section->name, range_entries[0].ranges_offset);
4884 printf (_("Contents of the %s section:\n\n"), section->name);
4885 printf (_(" Offset Begin End\n"));
4887 for (i = 0; i < num_range_list; i++)
4889 struct range_entry *range_entry = &range_entries[i];
4890 debug_info *debug_info_p = range_entry->debug_info_p;
4891 unsigned int pointer_size;
4892 unsigned long offset;
4893 unsigned char *next;
4894 unsigned long base_address;
4896 pointer_size = debug_info_p->pointer_size;
4898 offset = range_entry->ranges_offset;
4899 next = section_begin + offset;
4900 base_address = debug_info_p->base_address;
4902 if (dwarf_check != 0 && i > 0)
4905 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4906 (unsigned long) (start - section_begin),
4907 (unsigned long) (next - section_begin), section->name);
4908 else if (start > next)
4910 if (next == last_start)
4912 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4913 (unsigned long) (start - section_begin),
4914 (unsigned long) (next - section_begin), section->name);
4920 while (start < finish)
4925 /* Note: we use sign extension here in order to be sure that
4926 we can detect the -1 escape value. Sign extension into the
4927 top 32 bits of a 32-bit address will not affect the values
4928 that we display since we always show hex values, and always
4929 the bottom 32-bits. */
4930 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
4931 if (start >= finish)
4933 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
4935 printf (" %8.8lx ", offset);
4937 if (begin == 0 && end == 0)
4939 printf (_("<End of list>\n"));
4943 /* Check base address specifiers. */
4944 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4947 print_dwarf_vma (begin, pointer_size);
4948 print_dwarf_vma (end, pointer_size);
4949 printf ("(base address)\n");
4953 print_dwarf_vma (begin + base_address, pointer_size);
4954 print_dwarf_vma (end + base_address, pointer_size);
4957 fputs (_("(start == end)"), stdout);
4958 else if (begin > end)
4959 fputs (_("(start > end)"), stdout);
4966 free (range_entries);
4971 typedef struct Frame_Chunk
4973 struct Frame_Chunk *next;
4974 unsigned char *chunk_start;
4976 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4977 short int *col_type;
4980 unsigned int code_factor;
4987 unsigned char fde_encoding;
4988 unsigned char cfa_exp;
4989 unsigned char ptr_size;
4990 unsigned char segment_size;
4994 static const char *const *dwarf_regnames;
4995 static unsigned int dwarf_regnames_count;
4997 /* A marker for a col_type that means this column was never referenced
4998 in the frame info. */
4999 #define DW_CFA_unreferenced (-1)
5001 /* Return 0 if not more space is needed, 1 if more space is needed,
5002 -1 for invalid reg. */
5005 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5007 int prev = fc->ncols;
5009 if (reg < (unsigned int) fc->ncols)
5012 if (dwarf_regnames_count
5013 && reg > dwarf_regnames_count)
5016 fc->ncols = reg + 1;
5017 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5018 sizeof (short int));
5019 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5021 while (prev < fc->ncols)
5023 fc->col_type[prev] = DW_CFA_unreferenced;
5024 fc->col_offset[prev] = 0;
5030 static const char *const dwarf_regnames_i386[] =
5032 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5033 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5034 "eip", "eflags", NULL, /* 8 - 10 */
5035 "st0", "st1", "st2", "st3", /* 11 - 14 */
5036 "st4", "st5", "st6", "st7", /* 15 - 18 */
5037 NULL, NULL, /* 19 - 20 */
5038 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5039 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5040 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5041 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5042 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5043 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5044 "tr", "ldtr", /* 48 - 49 */
5045 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5046 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5047 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5048 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5049 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5050 NULL, NULL, NULL, /* 90 - 92 */
5051 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5055 init_dwarf_regnames_i386 (void)
5057 dwarf_regnames = dwarf_regnames_i386;
5058 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5061 static const char *const dwarf_regnames_x86_64[] =
5063 "rax", "rdx", "rcx", "rbx",
5064 "rsi", "rdi", "rbp", "rsp",
5065 "r8", "r9", "r10", "r11",
5066 "r12", "r13", "r14", "r15",
5068 "xmm0", "xmm1", "xmm2", "xmm3",
5069 "xmm4", "xmm5", "xmm6", "xmm7",
5070 "xmm8", "xmm9", "xmm10", "xmm11",
5071 "xmm12", "xmm13", "xmm14", "xmm15",
5072 "st0", "st1", "st2", "st3",
5073 "st4", "st5", "st6", "st7",
5074 "mm0", "mm1", "mm2", "mm3",
5075 "mm4", "mm5", "mm6", "mm7",
5077 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5078 "fs.base", "gs.base", NULL, NULL,
5080 "mxcsr", "fcw", "fsw",
5081 "xmm16", "xmm17", "xmm18", "xmm19",
5082 "xmm20", "xmm21", "xmm22", "xmm23",
5083 "xmm24", "xmm25", "xmm26", "xmm27",
5084 "xmm28", "xmm29", "xmm30", "xmm31",
5085 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5086 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5087 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5088 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5089 NULL, NULL, NULL, /* 115 - 117 */
5090 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5094 init_dwarf_regnames_x86_64 (void)
5096 dwarf_regnames = dwarf_regnames_x86_64;
5097 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5101 init_dwarf_regnames (unsigned int e_machine)
5107 init_dwarf_regnames_i386 ();
5113 init_dwarf_regnames_x86_64 ();
5122 regname (unsigned int regno, int row)
5124 static char reg[64];
5126 && regno < dwarf_regnames_count
5127 && dwarf_regnames [regno] != NULL)
5130 return dwarf_regnames [regno];
5131 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5132 dwarf_regnames [regno]);
5135 snprintf (reg, sizeof (reg), "r%d", regno);
5140 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
5145 if (*max_regs < fc->ncols)
5146 *max_regs = fc->ncols;
5148 if (*need_col_headers)
5150 static const char *sloc = " LOC";
5152 *need_col_headers = 0;
5154 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5156 for (r = 0; r < *max_regs; r++)
5157 if (fc->col_type[r] != DW_CFA_unreferenced)
5162 printf ("%-5s ", regname (r, 1));
5168 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5170 strcpy (tmp, "exp");
5172 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
5173 printf ("%-8s ", tmp);
5175 for (r = 0; r < fc->ncols; r++)
5177 if (fc->col_type[r] != DW_CFA_unreferenced)
5179 switch (fc->col_type[r])
5181 case DW_CFA_undefined:
5184 case DW_CFA_same_value:
5188 sprintf (tmp, "c%+d", fc->col_offset[r]);
5190 case DW_CFA_val_offset:
5191 sprintf (tmp, "v%+d", fc->col_offset[r]);
5193 case DW_CFA_register:
5194 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5196 case DW_CFA_expression:
5197 strcpy (tmp, "exp");
5199 case DW_CFA_val_expression:
5200 strcpy (tmp, "vexp");
5203 strcpy (tmp, "n/a");
5206 printf ("%-5s ", tmp);
5212 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end);
5213 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5214 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5217 display_debug_frames (struct dwarf_section *section,
5218 void *file ATTRIBUTE_UNUSED)
5220 unsigned char *start = section->start;
5221 unsigned char *end = start + section->size;
5222 unsigned char *section_start = start;
5223 Frame_Chunk *chunks = 0;
5224 Frame_Chunk *remembered_state = 0;
5226 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5227 unsigned int length_return;
5229 const char *bad_reg = _("bad register: ");
5230 int saved_eh_addr_size = eh_addr_size;
5232 printf (_("Contents of the %s section:\n"), section->name);
5236 unsigned char *saved_start;
5237 unsigned char *block_end;
5242 int need_col_headers = 1;
5243 unsigned char *augmentation_data = NULL;
5244 unsigned long augmentation_data_len = 0;
5245 unsigned int encoded_ptr_size = saved_eh_addr_size;
5246 unsigned int offset_size;
5247 unsigned int initial_length_size;
5249 saved_start = start;
5251 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5254 printf ("\n%08lx ZERO terminator\n\n",
5255 (unsigned long)(saved_start - section_start));
5259 if (length == 0xffffffff)
5261 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5263 initial_length_size = 12;
5268 initial_length_size = 4;
5271 block_end = saved_start + length + initial_length_size;
5272 if (block_end > end)
5274 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5275 dwarf_vmatoa_1 (NULL, length, offset_size),
5276 (unsigned long) (saved_start - section_start));
5280 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5282 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5283 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5287 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5288 memset (fc, 0, sizeof (Frame_Chunk));
5292 fc->chunk_start = saved_start;
5294 fc->col_type = (short int *) xmalloc (sizeof (short int));
5295 fc->col_offset = (int *) xmalloc (sizeof (int));
5296 frame_need_space (fc, max_regs - 1);
5300 fc->augmentation = (char *) start;
5301 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
5303 if (strcmp (fc->augmentation, "eh") == 0)
5304 start += eh_addr_size;
5308 GET (fc->ptr_size, 1);
5309 GET (fc->segment_size, 1);
5310 eh_addr_size = fc->ptr_size;
5314 fc->ptr_size = eh_addr_size;
5315 fc->segment_size = 0;
5317 fc->code_factor = LEB ();
5318 fc->data_factor = SLEB ();
5328 if (fc->augmentation[0] == 'z')
5330 augmentation_data_len = LEB ();
5331 augmentation_data = start;
5332 start += augmentation_data_len;
5336 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5337 print_dwarf_vma (length, fc->ptr_size);
5338 print_dwarf_vma (cie_id, offset_size);
5340 if (do_debug_frames_interp)
5342 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5343 fc->code_factor, fc->data_factor, fc->ra);
5348 printf (" Version: %d\n", version);
5349 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5352 printf (" Pointer Size: %u\n", fc->ptr_size);
5353 printf (" Segment Size: %u\n", fc->segment_size);
5355 printf (" Code alignment factor: %u\n", fc->code_factor);
5356 printf (" Data alignment factor: %d\n", fc->data_factor);
5357 printf (" Return address column: %d\n", fc->ra);
5359 if (augmentation_data_len)
5362 printf (" Augmentation data: ");
5363 for (i = 0; i < augmentation_data_len; ++i)
5364 printf (" %02x", augmentation_data[i]);
5370 if (augmentation_data_len)
5372 unsigned char *p, *q;
5373 p = (unsigned char *) fc->augmentation + 1;
5374 q = augmentation_data;
5381 q += 1 + size_of_encoded_value (*q);
5383 fc->fde_encoding = *q++;
5391 if (fc->fde_encoding)
5392 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5395 frame_need_space (fc, fc->ra);
5399 unsigned char *look_for;
5400 static Frame_Chunk fde_fc;
5401 unsigned long segment_selector;
5404 memset (fc, 0, sizeof (Frame_Chunk));
5406 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5408 for (cie = chunks; cie ; cie = cie->next)
5409 if (cie->chunk_start == look_for)
5414 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5415 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5416 (unsigned long) (saved_start - section_start));
5418 fc->col_type = (short int *) xmalloc (sizeof (short int));
5419 fc->col_offset = (int *) xmalloc (sizeof (int));
5420 frame_need_space (fc, max_regs - 1);
5422 fc->augmentation = "";
5423 fc->fde_encoding = 0;
5424 fc->ptr_size = eh_addr_size;
5425 fc->segment_size = 0;
5429 fc->ncols = cie->ncols;
5430 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5431 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5432 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5433 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5434 fc->augmentation = cie->augmentation;
5435 fc->ptr_size = cie->ptr_size;
5436 eh_addr_size = cie->ptr_size;
5437 fc->segment_size = cie->segment_size;
5438 fc->code_factor = cie->code_factor;
5439 fc->data_factor = cie->data_factor;
5440 fc->cfa_reg = cie->cfa_reg;
5441 fc->cfa_offset = cie->cfa_offset;
5443 frame_need_space (fc, max_regs - 1);
5444 fc->fde_encoding = cie->fde_encoding;
5447 if (fc->fde_encoding)
5448 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5450 segment_selector = 0;
5451 if (fc->segment_size)
5453 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
5455 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5456 start += encoded_ptr_size;
5458 /* FIXME: It appears that sometimes the final pc_range value is
5459 encoded in less than encoded_ptr_size bytes. See the x86_64
5460 run of the "objcopy on compressed debug sections" test for an
5462 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5464 if (cie->augmentation[0] == 'z')
5466 augmentation_data_len = LEB ();
5467 augmentation_data = start;
5468 start += augmentation_data_len;
5471 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5472 (unsigned long)(saved_start - section_start),
5473 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
5474 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5475 (unsigned long)(cie->chunk_start - section_start));
5477 if (fc->segment_size)
5478 printf ("%04lx:", segment_selector);
5481 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
5482 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
5484 if (! do_debug_frames_interp && augmentation_data_len)
5488 printf (" Augmentation data: ");
5489 for (i = 0; i < augmentation_data_len; ++i)
5490 printf (" %02x", augmentation_data[i]);
5496 /* At this point, fc is the current chunk, cie (if any) is set, and
5497 we're about to interpret instructions for the chunk. */
5498 /* ??? At present we need to do this always, since this sizes the
5499 fc->col_type and fc->col_offset arrays, which we write into always.
5500 We should probably split the interpreted and non-interpreted bits
5501 into two different routines, since there's so much that doesn't
5502 really overlap between them. */
5503 if (1 || do_debug_frames_interp)
5505 /* Start by making a pass over the chunk, allocating storage
5506 and taking note of what registers are used. */
5507 unsigned char *tmp = start;
5509 while (start < block_end)
5512 unsigned long reg, temp;
5519 /* Warning: if you add any more cases to this switch, be
5520 sure to add them to the corresponding switch below. */
5523 case DW_CFA_advance_loc:
5527 if (frame_need_space (fc, opa) >= 0)
5528 fc->col_type[opa] = DW_CFA_undefined;
5530 case DW_CFA_restore:
5531 if (frame_need_space (fc, opa) >= 0)
5532 fc->col_type[opa] = DW_CFA_undefined;
5534 case DW_CFA_set_loc:
5535 start += encoded_ptr_size;
5537 case DW_CFA_advance_loc1:
5540 case DW_CFA_advance_loc2:
5543 case DW_CFA_advance_loc4:
5546 case DW_CFA_offset_extended:
5547 case DW_CFA_val_offset:
5548 reg = LEB (); LEB ();
5549 if (frame_need_space (fc, reg) >= 0)
5550 fc->col_type[reg] = DW_CFA_undefined;
5552 case DW_CFA_restore_extended:
5554 frame_need_space (fc, reg);
5555 if (frame_need_space (fc, reg) >= 0)
5556 fc->col_type[reg] = DW_CFA_undefined;
5558 case DW_CFA_undefined:
5560 if (frame_need_space (fc, reg) >= 0)
5561 fc->col_type[reg] = DW_CFA_undefined;
5563 case DW_CFA_same_value:
5565 if (frame_need_space (fc, reg) >= 0)
5566 fc->col_type[reg] = DW_CFA_undefined;
5568 case DW_CFA_register:
5569 reg = LEB (); LEB ();
5570 if (frame_need_space (fc, reg) >= 0)
5571 fc->col_type[reg] = DW_CFA_undefined;
5573 case DW_CFA_def_cfa:
5576 case DW_CFA_def_cfa_register:
5579 case DW_CFA_def_cfa_offset:
5582 case DW_CFA_def_cfa_expression:
5586 case DW_CFA_expression:
5587 case DW_CFA_val_expression:
5591 if (frame_need_space (fc, reg) >= 0)
5592 fc->col_type[reg] = DW_CFA_undefined;
5594 case DW_CFA_offset_extended_sf:
5595 case DW_CFA_val_offset_sf:
5596 reg = LEB (); SLEB ();
5597 if (frame_need_space (fc, reg) >= 0)
5598 fc->col_type[reg] = DW_CFA_undefined;
5600 case DW_CFA_def_cfa_sf:
5603 case DW_CFA_def_cfa_offset_sf:
5606 case DW_CFA_MIPS_advance_loc8:
5609 case DW_CFA_GNU_args_size:
5612 case DW_CFA_GNU_negative_offset_extended:
5613 reg = LEB (); LEB ();
5614 if (frame_need_space (fc, reg) >= 0)
5615 fc->col_type[reg] = DW_CFA_undefined;
5624 /* Now we know what registers are used, make a second pass over
5625 the chunk, this time actually printing out the info. */
5627 while (start < block_end)
5630 unsigned long ul, reg, roffs;
5634 const char *reg_prefix = "";
5641 /* Warning: if you add any more cases to this switch, be
5642 sure to add them to the corresponding switch above. */
5645 case DW_CFA_advance_loc:
5646 if (do_debug_frames_interp)
5647 frame_display_row (fc, &need_col_headers, &max_regs);
5649 printf (" DW_CFA_advance_loc: %d to %s\n",
5650 opa * fc->code_factor,
5651 dwarf_vmatoa_1 (NULL,
5652 fc->pc_begin + opa * fc->code_factor,
5654 fc->pc_begin += opa * fc->code_factor;
5659 if (opa >= (unsigned int) fc->ncols)
5660 reg_prefix = bad_reg;
5661 if (! do_debug_frames_interp || *reg_prefix != '\0')
5662 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5663 reg_prefix, regname (opa, 0),
5664 roffs * fc->data_factor);
5665 if (*reg_prefix == '\0')
5667 fc->col_type[opa] = DW_CFA_offset;
5668 fc->col_offset[opa] = roffs * fc->data_factor;
5672 case DW_CFA_restore:
5673 if (opa >= (unsigned int) cie->ncols
5674 || opa >= (unsigned int) fc->ncols)
5675 reg_prefix = bad_reg;
5676 if (! do_debug_frames_interp || *reg_prefix != '\0')
5677 printf (" DW_CFA_restore: %s%s\n",
5678 reg_prefix, regname (opa, 0));
5679 if (*reg_prefix == '\0')
5681 fc->col_type[opa] = cie->col_type[opa];
5682 fc->col_offset[opa] = cie->col_offset[opa];
5683 if (do_debug_frames_interp
5684 && fc->col_type[opa] == DW_CFA_unreferenced)
5685 fc->col_type[opa] = DW_CFA_undefined;
5689 case DW_CFA_set_loc:
5690 vma = get_encoded_value (start, fc->fde_encoding, section);
5691 start += encoded_ptr_size;
5692 if (do_debug_frames_interp)
5693 frame_display_row (fc, &need_col_headers, &max_regs);
5695 printf (" DW_CFA_set_loc: %s\n",
5696 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
5700 case DW_CFA_advance_loc1:
5701 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
5702 if (do_debug_frames_interp)
5703 frame_display_row (fc, &need_col_headers, &max_regs);
5705 printf (" DW_CFA_advance_loc1: %ld to %s\n",
5706 (unsigned long) (ofs * fc->code_factor),
5707 dwarf_vmatoa_1 (NULL,
5708 fc->pc_begin + ofs * fc->code_factor,
5710 fc->pc_begin += ofs * fc->code_factor;
5713 case DW_CFA_advance_loc2:
5714 SAFE_BYTE_GET_AND_INC (ofs, start, 2, end);
5715 if (do_debug_frames_interp)
5716 frame_display_row (fc, &need_col_headers, &max_regs);
5718 printf (" DW_CFA_advance_loc2: %ld to %s\n",
5719 (unsigned long) (ofs * fc->code_factor),
5720 dwarf_vmatoa_1 (NULL,
5721 fc->pc_begin + ofs * fc->code_factor,
5723 fc->pc_begin += ofs * fc->code_factor;
5726 case DW_CFA_advance_loc4:
5727 SAFE_BYTE_GET_AND_INC (ofs, start, 4, end);
5728 if (do_debug_frames_interp)
5729 frame_display_row (fc, &need_col_headers, &max_regs);
5731 printf (" DW_CFA_advance_loc4: %ld to %s\n",
5732 (unsigned long) (ofs * fc->code_factor),
5733 dwarf_vmatoa_1 (NULL,
5734 fc->pc_begin + ofs * fc->code_factor,
5736 fc->pc_begin += ofs * fc->code_factor;
5739 case DW_CFA_offset_extended:
5742 if (reg >= (unsigned int) fc->ncols)
5743 reg_prefix = bad_reg;
5744 if (! do_debug_frames_interp || *reg_prefix != '\0')
5745 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5746 reg_prefix, regname (reg, 0),
5747 roffs * fc->data_factor);
5748 if (*reg_prefix == '\0')
5750 fc->col_type[reg] = DW_CFA_offset;
5751 fc->col_offset[reg] = roffs * fc->data_factor;
5755 case DW_CFA_val_offset:
5758 if (reg >= (unsigned int) fc->ncols)
5759 reg_prefix = bad_reg;
5760 if (! do_debug_frames_interp || *reg_prefix != '\0')
5761 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5762 reg_prefix, regname (reg, 0),
5763 roffs * fc->data_factor);
5764 if (*reg_prefix == '\0')
5766 fc->col_type[reg] = DW_CFA_val_offset;
5767 fc->col_offset[reg] = roffs * fc->data_factor;
5771 case DW_CFA_restore_extended:
5773 if (reg >= (unsigned int) cie->ncols
5774 || reg >= (unsigned int) fc->ncols)
5775 reg_prefix = bad_reg;
5776 if (! do_debug_frames_interp || *reg_prefix != '\0')
5777 printf (" DW_CFA_restore_extended: %s%s\n",
5778 reg_prefix, regname (reg, 0));
5779 if (*reg_prefix == '\0')
5781 fc->col_type[reg] = cie->col_type[reg];
5782 fc->col_offset[reg] = cie->col_offset[reg];
5786 case DW_CFA_undefined:
5788 if (reg >= (unsigned int) fc->ncols)
5789 reg_prefix = bad_reg;
5790 if (! do_debug_frames_interp || *reg_prefix != '\0')
5791 printf (" DW_CFA_undefined: %s%s\n",
5792 reg_prefix, regname (reg, 0));
5793 if (*reg_prefix == '\0')
5795 fc->col_type[reg] = DW_CFA_undefined;
5796 fc->col_offset[reg] = 0;
5800 case DW_CFA_same_value:
5802 if (reg >= (unsigned int) fc->ncols)
5803 reg_prefix = bad_reg;
5804 if (! do_debug_frames_interp || *reg_prefix != '\0')
5805 printf (" DW_CFA_same_value: %s%s\n",
5806 reg_prefix, regname (reg, 0));
5807 if (*reg_prefix == '\0')
5809 fc->col_type[reg] = DW_CFA_same_value;
5810 fc->col_offset[reg] = 0;
5814 case DW_CFA_register:
5817 if (reg >= (unsigned int) fc->ncols)
5818 reg_prefix = bad_reg;
5819 if (! do_debug_frames_interp || *reg_prefix != '\0')
5821 printf (" DW_CFA_register: %s%s in ",
5822 reg_prefix, regname (reg, 0));
5823 puts (regname (roffs, 0));
5825 if (*reg_prefix == '\0')
5827 fc->col_type[reg] = DW_CFA_register;
5828 fc->col_offset[reg] = roffs;
5832 case DW_CFA_remember_state:
5833 if (! do_debug_frames_interp)
5834 printf (" DW_CFA_remember_state\n");
5835 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5836 rs->ncols = fc->ncols;
5837 rs->col_type = (short int *) xcmalloc (rs->ncols,
5838 sizeof (short int));
5839 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5840 memcpy (rs->col_type, fc->col_type, rs->ncols);
5841 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5842 rs->next = remembered_state;
5843 remembered_state = rs;
5846 case DW_CFA_restore_state:
5847 if (! do_debug_frames_interp)
5848 printf (" DW_CFA_restore_state\n");
5849 rs = remembered_state;
5852 remembered_state = rs->next;
5853 frame_need_space (fc, rs->ncols - 1);
5854 memcpy (fc->col_type, rs->col_type, rs->ncols);
5855 memcpy (fc->col_offset, rs->col_offset,
5856 rs->ncols * sizeof (int));
5857 free (rs->col_type);
5858 free (rs->col_offset);
5861 else if (do_debug_frames_interp)
5862 printf ("Mismatched DW_CFA_restore_state\n");
5865 case DW_CFA_def_cfa:
5866 fc->cfa_reg = LEB ();
5867 fc->cfa_offset = LEB ();
5869 if (! do_debug_frames_interp)
5870 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5871 regname (fc->cfa_reg, 0), fc->cfa_offset);
5874 case DW_CFA_def_cfa_register:
5875 fc->cfa_reg = LEB ();
5877 if (! do_debug_frames_interp)
5878 printf (" DW_CFA_def_cfa_register: %s\n",
5879 regname (fc->cfa_reg, 0));
5882 case DW_CFA_def_cfa_offset:
5883 fc->cfa_offset = LEB ();
5884 if (! do_debug_frames_interp)
5885 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5889 if (! do_debug_frames_interp)
5890 printf (" DW_CFA_nop\n");
5893 case DW_CFA_def_cfa_expression:
5895 if (! do_debug_frames_interp)
5897 printf (" DW_CFA_def_cfa_expression (");
5898 decode_location_expression (start, eh_addr_size, 0, -1,
5906 case DW_CFA_expression:
5909 if (reg >= (unsigned int) fc->ncols)
5910 reg_prefix = bad_reg;
5911 if (! do_debug_frames_interp || *reg_prefix != '\0')
5913 printf (" DW_CFA_expression: %s%s (",
5914 reg_prefix, regname (reg, 0));
5915 decode_location_expression (start, eh_addr_size, 0, -1,
5919 if (*reg_prefix == '\0')
5920 fc->col_type[reg] = DW_CFA_expression;
5924 case DW_CFA_val_expression:
5927 if (reg >= (unsigned int) fc->ncols)
5928 reg_prefix = bad_reg;
5929 if (! do_debug_frames_interp || *reg_prefix != '\0')
5931 printf (" DW_CFA_val_expression: %s%s (",
5932 reg_prefix, regname (reg, 0));
5933 decode_location_expression (start, eh_addr_size, 0, -1,
5937 if (*reg_prefix == '\0')
5938 fc->col_type[reg] = DW_CFA_val_expression;
5942 case DW_CFA_offset_extended_sf:
5945 if (frame_need_space (fc, reg) < 0)
5946 reg_prefix = bad_reg;
5947 if (! do_debug_frames_interp || *reg_prefix != '\0')
5948 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5949 reg_prefix, regname (reg, 0),
5950 l * fc->data_factor);
5951 if (*reg_prefix == '\0')
5953 fc->col_type[reg] = DW_CFA_offset;
5954 fc->col_offset[reg] = l * fc->data_factor;
5958 case DW_CFA_val_offset_sf:
5961 if (frame_need_space (fc, reg) < 0)
5962 reg_prefix = bad_reg;
5963 if (! do_debug_frames_interp || *reg_prefix != '\0')
5964 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5965 reg_prefix, regname (reg, 0),
5966 l * fc->data_factor);
5967 if (*reg_prefix == '\0')
5969 fc->col_type[reg] = DW_CFA_val_offset;
5970 fc->col_offset[reg] = l * fc->data_factor;
5974 case DW_CFA_def_cfa_sf:
5975 fc->cfa_reg = LEB ();
5976 fc->cfa_offset = SLEB ();
5977 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5979 if (! do_debug_frames_interp)
5980 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5981 regname (fc->cfa_reg, 0), fc->cfa_offset);
5984 case DW_CFA_def_cfa_offset_sf:
5985 fc->cfa_offset = SLEB ();
5986 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5987 if (! do_debug_frames_interp)
5988 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5991 case DW_CFA_MIPS_advance_loc8:
5992 SAFE_BYTE_GET_AND_INC (ofs, start, 8, end);
5993 if (do_debug_frames_interp)
5994 frame_display_row (fc, &need_col_headers, &max_regs);
5996 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
5997 (unsigned long) (ofs * fc->code_factor),
5998 dwarf_vmatoa_1 (NULL,
5999 fc->pc_begin + ofs * fc->code_factor,
6001 fc->pc_begin += ofs * fc->code_factor;
6004 case DW_CFA_GNU_window_save:
6005 if (! do_debug_frames_interp)
6006 printf (" DW_CFA_GNU_window_save\n");
6009 case DW_CFA_GNU_args_size:
6011 if (! do_debug_frames_interp)
6012 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6015 case DW_CFA_GNU_negative_offset_extended:
6018 if (frame_need_space (fc, reg) < 0)
6019 reg_prefix = bad_reg;
6020 if (! do_debug_frames_interp || *reg_prefix != '\0')
6021 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6022 reg_prefix, regname (reg, 0),
6023 l * fc->data_factor);
6024 if (*reg_prefix == '\0')
6026 fc->col_type[reg] = DW_CFA_offset;
6027 fc->col_offset[reg] = l * fc->data_factor;
6032 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6033 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6035 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6040 if (do_debug_frames_interp)
6041 frame_display_row (fc, &need_col_headers, &max_regs);
6044 eh_addr_size = saved_eh_addr_size;
6057 display_gdb_index (struct dwarf_section *section,
6058 void *file ATTRIBUTE_UNUSED)
6060 unsigned char *start = section->start;
6062 uint32_t cu_list_offset, tu_list_offset;
6063 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6064 unsigned int cu_list_elements, tu_list_elements;
6065 unsigned int address_table_size, symbol_table_slots;
6066 unsigned char *cu_list, *tu_list;
6067 unsigned char *address_table, *symbol_table, *constant_pool;
6070 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6072 printf (_("Contents of the %s section:\n"), section->name);
6074 if (section->size < 6 * sizeof (uint32_t))
6076 warn (_("Truncated header in the %s section.\n"), section->name);
6080 version = byte_get_little_endian (start, 4);
6081 printf (_("Version %ld\n"), (long) version);
6083 /* Prior versions are obsolete, and future versions may not be
6084 backwards compatible. */
6085 if (version < 3 || version > 8)
6087 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6091 warn (_("The address table data in version 3 may be wrong.\n"));
6093 warn (_("Version 4 does not support case insensitive lookups.\n"));
6095 warn (_("Version 5 does not include inlined functions.\n"));
6097 warn (_("Version 6 does not include symbol attributes.\n"));
6098 /* Version 7 indices generated by Gold have bad type unit references,
6099 PR binutils/15021. But we don't know if the index was generated by
6100 Gold or not, so to avoid worrying users with gdb-generated indices
6101 we say nothing for version 7 here. */
6103 cu_list_offset = byte_get_little_endian (start + 4, 4);
6104 tu_list_offset = byte_get_little_endian (start + 8, 4);
6105 address_table_offset = byte_get_little_endian (start + 12, 4);
6106 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6107 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6109 if (cu_list_offset > section->size
6110 || tu_list_offset > section->size
6111 || address_table_offset > section->size
6112 || symbol_table_offset > section->size
6113 || constant_pool_offset > section->size)
6115 warn (_("Corrupt header in the %s section.\n"), section->name);
6119 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6120 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6121 address_table_size = symbol_table_offset - address_table_offset;
6122 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6124 cu_list = start + cu_list_offset;
6125 tu_list = start + tu_list_offset;
6126 address_table = start + address_table_offset;
6127 symbol_table = start + symbol_table_offset;
6128 constant_pool = start + constant_pool_offset;
6130 printf (_("\nCU table:\n"));
6131 for (i = 0; i < cu_list_elements; i += 2)
6133 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6134 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6136 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6137 (unsigned long) cu_offset,
6138 (unsigned long) (cu_offset + cu_length - 1));
6141 printf (_("\nTU table:\n"));
6142 for (i = 0; i < tu_list_elements; i += 3)
6144 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6145 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6146 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6148 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6149 (unsigned long) tu_offset,
6150 (unsigned long) type_offset);
6151 print_dwarf_vma (signature, 8);
6155 printf (_("\nAddress table:\n"));
6156 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
6158 uint64_t low = byte_get_little_endian (address_table + i, 8);
6159 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6160 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6162 print_dwarf_vma (low, 8);
6163 print_dwarf_vma (high, 8);
6164 printf (_("%lu\n"), (unsigned long) cu_index);
6167 printf (_("\nSymbol table:\n"));
6168 for (i = 0; i < symbol_table_slots; ++i)
6170 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6171 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6172 uint32_t num_cus, cu;
6174 if (name_offset != 0
6175 || cu_vector_offset != 0)
6179 printf ("[%3u] %s:", i, constant_pool + name_offset);
6180 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
6183 for (j = 0; j < num_cus; ++j)
6186 gdb_index_symbol_kind kind;
6188 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6189 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6190 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6191 cu = GDB_INDEX_CU_VALUE (cu);
6192 /* Convert to TU number if it's for a type unit. */
6193 if (cu >= cu_list_elements / 2)
6194 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6195 (unsigned long) (cu - cu_list_elements / 2));
6197 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6199 printf (" [%s, %s]",
6200 is_static ? _("static") : _("global"),
6201 get_gdb_index_symbol_kind_name (kind));
6213 /* Pre-allocate enough space for the CU/TU sets needed. */
6216 prealloc_cu_tu_list (unsigned int nshndx)
6218 if (shndx_pool == NULL)
6220 shndx_pool_size = nshndx;
6221 shndx_pool_used = 0;
6222 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6223 sizeof (unsigned int));
6227 shndx_pool_size = shndx_pool_used + nshndx;
6228 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6229 sizeof (unsigned int));
6234 add_shndx_to_cu_tu_entry (unsigned int shndx)
6236 if (shndx_pool_used >= shndx_pool_size)
6238 error (_("Internal error: out of space in the shndx pool.\n"));
6241 shndx_pool [shndx_pool_used++] = shndx;
6245 end_cu_tu_entry (void)
6247 if (shndx_pool_used >= shndx_pool_size)
6249 error (_("Internal error: out of space in the shndx pool.\n"));
6252 shndx_pool [shndx_pool_used++] = 0;
6255 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6258 get_DW_SECT_short_name (unsigned int dw_sect)
6260 static char buf[16];
6268 case DW_SECT_ABBREV:
6274 case DW_SECT_STR_OFFSETS:
6276 case DW_SECT_MACINFO:
6284 snprintf (buf, sizeof (buf), "%d", dw_sect);
6288 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6289 These sections are extensions for Fission.
6290 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6293 process_cu_tu_index (struct dwarf_section *section, int do_display)
6295 unsigned char *phdr = section->start;
6296 unsigned char *limit = phdr + section->size;
6297 unsigned char *phash;
6298 unsigned char *pindex;
6299 unsigned char *ppool;
6300 unsigned int version;
6301 unsigned int ncols = 0;
6303 unsigned int nslots;
6306 dwarf_vma signature_high;
6307 dwarf_vma signature_low;
6310 version = byte_get (phdr, 4);
6312 ncols = byte_get (phdr + 4, 4);
6313 nused = byte_get (phdr + 8, 4);
6314 nslots = byte_get (phdr + 12, 4);
6316 pindex = phash + nslots * 8;
6317 ppool = pindex + nslots * 4;
6321 printf (_("Contents of the %s section:\n\n"), section->name);
6322 printf (_(" Version: %d\n"), version);
6324 printf (_(" Number of columns: %d\n"), ncols);
6325 printf (_(" Number of used entries: %d\n"), nused);
6326 printf (_(" Number of slots: %d\n\n"), nslots);
6331 warn (_("Section %s too small for %d hash table entries\n"),
6332 section->name, nslots);
6339 prealloc_cu_tu_list ((limit - ppool) / 4);
6340 for (i = 0; i < nslots; i++)
6342 unsigned char *shndx_list;
6345 byte_get_64 (phash, &signature_high, &signature_low);
6346 if (signature_high != 0 || signature_low != 0)
6348 j = byte_get (pindex, 4);
6349 shndx_list = ppool + j * 4;
6351 printf (_(" [%3d] Signature: 0x%s Sections: "),
6352 i, dwarf_vmatoa64 (signature_high, signature_low,
6353 buf, sizeof (buf)));
6356 if (shndx_list >= limit)
6358 warn (_("Section %s too small for shndx pool\n"),
6362 shndx = byte_get (shndx_list, 4);
6366 printf (" %d", shndx);
6368 add_shndx_to_cu_tu_entry (shndx);
6380 else if (version == 2)
6383 unsigned int dw_sect;
6384 unsigned char *ph = phash;
6385 unsigned char *pi = pindex;
6386 unsigned char *poffsets = ppool + ncols * 4;
6387 unsigned char *psizes = poffsets + nused * ncols * 4;
6388 unsigned char *pend = psizes + nused * ncols * 4;
6389 bfd_boolean is_tu_index;
6390 struct cu_tu_set *this_set = NULL;
6392 unsigned char *prow;
6394 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6398 warn (_("Section %s too small for offset and size tables\n"),
6405 printf (_(" Offset table\n"));
6406 printf (" slot %-16s ",
6407 is_tu_index ? _("signature") : _("dwo_id"));
6414 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6420 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6426 for (j = 0; j < ncols; j++)
6428 dw_sect = byte_get (ppool + j * 4, 4);
6429 printf (" %8s", get_DW_SECT_short_name (dw_sect));
6433 for (i = 0; i < nslots; i++)
6435 byte_get_64 (ph, &signature_high, &signature_low);
6436 row = byte_get (pi, 4);
6440 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6441 prow = poffsets + (row - 1) * ncols * 4;
6443 printf (_(" [%3d] 0x%s"),
6444 i, dwarf_vmatoa64 (signature_high, signature_low,
6445 buf, sizeof (buf)));
6446 for (j = 0; j < ncols; j++)
6448 val = byte_get (prow + j * 4, 4);
6450 printf (" %8d", val);
6453 dw_sect = byte_get (ppool + j * 4, 4);
6454 this_set [row - 1].section_offsets [dw_sect] = val;
6469 printf (_(" Size table\n"));
6470 printf (" slot %-16s ",
6471 is_tu_index ? _("signature") : _("dwo_id"));
6473 for (j = 0; j < ncols; j++)
6475 val = byte_get (ppool + j * 4, 4);
6477 printf (" %8s", get_DW_SECT_short_name (val));
6481 for (i = 0; i < nslots; i++)
6483 byte_get_64 (ph, &signature_high, &signature_low);
6484 row = byte_get (pi, 4);
6487 prow = psizes + (row - 1) * ncols * 4;
6489 printf (_(" [%3d] 0x%s"),
6490 i, dwarf_vmatoa64 (signature_high, signature_low,
6491 buf, sizeof (buf)));
6492 for (j = 0; j < ncols; j++)
6494 val = byte_get (prow + j * 4, 4);
6496 printf (" %8d", val);
6499 dw_sect = byte_get (ppool + j * 4, 4);
6500 this_set [row - 1].section_sizes [dw_sect] = val;
6510 else if (do_display)
6511 printf (_(" Unsupported version\n"));
6519 /* Load the CU and TU indexes if present. This will build a list of
6520 section sets that we can use to associate a .debug_info.dwo section
6521 with its associated .debug_abbrev.dwo section in a .dwp file. */
6524 load_cu_tu_indexes (void *file)
6526 /* If we have already loaded (or tried to load) the CU and TU indexes
6527 then do not bother to repeat the task. */
6528 if (cu_tu_indexes_read)
6531 if (load_debug_section (dwp_cu_index, file))
6532 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6534 if (load_debug_section (dwp_tu_index, file))
6535 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6537 cu_tu_indexes_read = 1;
6540 /* Find the set of sections that includes section SHNDX. */
6543 find_cu_tu_set (void *file, unsigned int shndx)
6547 load_cu_tu_indexes (file);
6549 /* Find SHNDX in the shndx pool. */
6550 for (i = 0; i < shndx_pool_used; i++)
6551 if (shndx_pool [i] == shndx)
6554 if (i >= shndx_pool_used)
6557 /* Now backup to find the first entry in the set. */
6558 while (i > 0 && shndx_pool [i - 1] != 0)
6561 return shndx_pool + i;
6564 /* Display a .debug_cu_index or .debug_tu_index section. */
6567 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6569 return process_cu_tu_index (section, 1);
6573 display_debug_not_supported (struct dwarf_section *section,
6574 void *file ATTRIBUTE_UNUSED)
6576 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6583 cmalloc (size_t nmemb, size_t size)
6585 /* Check for overflow. */
6586 if (nmemb >= ~(size_t) 0 / size)
6589 return malloc (nmemb * size);
6593 xcmalloc (size_t nmemb, size_t size)
6595 /* Check for overflow. */
6596 if (nmemb >= ~(size_t) 0 / size)
6599 return xmalloc (nmemb * size);
6603 xcrealloc (void *ptr, size_t nmemb, size_t size)
6605 /* Check for overflow. */
6606 if (nmemb >= ~(size_t) 0 / size)
6609 return xrealloc (ptr, nmemb * size);
6613 free_debug_memory (void)
6619 for (i = 0; i < max; i++)
6620 free_debug_section ((enum dwarf_section_display_enum) i);
6622 if (debug_information != NULL)
6624 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
6626 for (i = 0; i < num_debug_info_entries; i++)
6628 if (!debug_information [i].max_loc_offsets)
6630 free (debug_information [i].loc_offsets);
6631 free (debug_information [i].have_frame_base);
6633 if (!debug_information [i].max_range_lists)
6634 free (debug_information [i].range_lists);
6638 free (debug_information);
6639 debug_information = NULL;
6640 num_debug_info_entries = 0;
6645 dwarf_select_sections_by_names (const char *names)
6649 const char * option;
6653 debug_dump_long_opts;
6655 static const debug_dump_long_opts opts_table [] =
6657 /* Please keep this table alpha- sorted. */
6658 { "Ranges", & do_debug_ranges, 1 },
6659 { "abbrev", & do_debug_abbrevs, 1 },
6660 { "addr", & do_debug_addr, 1 },
6661 { "aranges", & do_debug_aranges, 1 },
6662 { "cu_index", & do_debug_cu_index, 1 },
6663 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
6664 { "frames", & do_debug_frames, 1 },
6665 { "frames-interp", & do_debug_frames_interp, 1 },
6666 /* The special .gdb_index section. */
6667 { "gdb_index", & do_gdb_index, 1 },
6668 { "info", & do_debug_info, 1 },
6669 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
6670 { "loc", & do_debug_loc, 1 },
6671 { "macro", & do_debug_macinfo, 1 },
6672 { "pubnames", & do_debug_pubnames, 1 },
6673 { "pubtypes", & do_debug_pubtypes, 1 },
6674 /* This entry is for compatability
6675 with earlier versions of readelf. */
6676 { "ranges", & do_debug_aranges, 1 },
6677 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
6678 { "str", & do_debug_str, 1 },
6679 /* These trace_* sections are used by Itanium VMS. */
6680 { "trace_abbrev", & do_trace_abbrevs, 1 },
6681 { "trace_aranges", & do_trace_aranges, 1 },
6682 { "trace_info", & do_trace_info, 1 },
6691 const debug_dump_long_opts * entry;
6693 for (entry = opts_table; entry->option; entry++)
6695 size_t len = strlen (entry->option);
6697 if (strncmp (p, entry->option, len) == 0
6698 && (p[len] == ',' || p[len] == '\0'))
6700 * entry->variable |= entry->val;
6702 /* The --debug-dump=frames-interp option also
6703 enables the --debug-dump=frames option. */
6704 if (do_debug_frames_interp)
6705 do_debug_frames = 1;
6712 if (entry->option == NULL)
6714 warn (_("Unrecognized debug option '%s'\n"), p);
6715 p = strchr (p, ',');
6726 dwarf_select_sections_by_letters (const char *letters)
6728 unsigned int lindex = 0;
6730 while (letters[lindex])
6731 switch (letters[lindex++])
6738 do_debug_abbrevs = 1;
6742 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6746 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6750 do_debug_pubnames = 1;
6754 do_debug_pubtypes = 1;
6758 do_debug_aranges = 1;
6762 do_debug_ranges = 1;
6766 do_debug_frames_interp = 1;
6768 do_debug_frames = 1;
6772 do_debug_macinfo = 1;
6784 warn (_("Unrecognized debug option '%s'\n"), optarg);
6790 dwarf_select_sections_all (void)
6793 do_debug_abbrevs = 1;
6794 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6795 do_debug_pubnames = 1;
6796 do_debug_pubtypes = 1;
6797 do_debug_aranges = 1;
6798 do_debug_ranges = 1;
6799 do_debug_frames = 1;
6800 do_debug_macinfo = 1;
6805 do_trace_abbrevs = 1;
6806 do_trace_aranges = 1;
6808 do_debug_cu_index = 1;
6811 struct dwarf_section_display debug_displays[] =
6813 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
6814 display_debug_abbrev, &do_debug_abbrevs, 0 },
6815 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
6816 display_debug_aranges, &do_debug_aranges, 1 },
6817 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
6818 display_debug_frames, &do_debug_frames, 1 },
6819 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6820 display_debug_info, &do_debug_info, 1 },
6821 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
6822 display_debug_lines, &do_debug_lines, 1 },
6823 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
6824 display_debug_pubnames, &do_debug_pubnames, 0 },
6825 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0 },
6826 display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
6827 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
6828 display_debug_frames, &do_debug_frames, 1 },
6829 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
6830 display_debug_macinfo, &do_debug_macinfo, 0 },
6831 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
6832 display_debug_macro, &do_debug_macinfo, 1 },
6833 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
6834 display_debug_str, &do_debug_str, 0 },
6835 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
6836 display_debug_loc, &do_debug_loc, 1 },
6837 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
6838 display_debug_pubnames, &do_debug_pubtypes, 0 },
6839 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0 },
6840 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
6841 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
6842 display_debug_ranges, &do_debug_ranges, 1 },
6843 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
6844 display_debug_not_supported, NULL, 0 },
6845 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
6846 display_debug_not_supported, NULL, 0 },
6847 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6848 display_debug_types, &do_debug_info, 1 },
6849 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
6850 display_debug_not_supported, NULL, 0 },
6851 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6852 display_gdb_index, &do_gdb_index, 0 },
6853 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6854 display_trace_info, &do_trace_info, 1 },
6855 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6856 display_debug_abbrev, &do_trace_abbrevs, 0 },
6857 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6858 display_debug_aranges, &do_trace_aranges, 0 },
6859 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6860 display_debug_info, &do_debug_info, 1 },
6861 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6862 display_debug_abbrev, &do_debug_abbrevs, 0 },
6863 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6864 display_debug_types, &do_debug_info, 1 },
6865 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6866 display_debug_lines, &do_debug_lines, 1 },
6867 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
6868 display_debug_loc, &do_debug_loc, 1 },
6869 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
6870 display_debug_macro, &do_debug_macinfo, 1 },
6871 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
6872 display_debug_macinfo, &do_debug_macinfo, 0 },
6873 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6874 display_debug_str, &do_debug_str, 1 },
6875 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
6876 display_debug_str_offsets, NULL, 0 },
6877 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
6878 display_debug_str_offsets, NULL, 0 },
6879 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6880 display_debug_addr, &do_debug_addr, 1 },
6881 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6882 display_cu_index, &do_debug_cu_index, 0 },
6883 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6884 display_cu_index, &do_debug_cu_index, 0 },