1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2015 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 static const char *regname (unsigned int regno, int row);
34 static int have_frame_base;
35 static int need_base_address;
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
40 static unsigned int num_debug_info_entries = 0;
41 static unsigned int alloc_num_debug_info_entries = 0;
42 static debug_info *debug_information = NULL;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
52 int do_debug_pubnames;
53 int do_debug_pubtypes;
57 int do_debug_frames_interp;
66 int do_debug_cu_index;
69 int dwarf_cutoff_level = -1;
70 unsigned long dwarf_start_die;
74 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
75 sections. For version 1 package files, each set is stored in SHNDX_POOL
76 as a zero-terminated list of section indexes comprising one set of debug
77 sections from a .dwo file. */
79 static int cu_tu_indexes_read = 0;
80 static unsigned int *shndx_pool = NULL;
81 static unsigned int shndx_pool_size = 0;
82 static unsigned int shndx_pool_used = 0;
84 /* For version 2 package files, each set contains an array of section offsets
85 and an array of section sizes, giving the offset and size of the
86 contribution from a CU or TU within one of the debug sections.
87 When displaying debug info from a package file, we need to use these
88 tables to locate the corresponding contributions to each section. */
93 dwarf_vma section_offsets[DW_SECT_MAX];
94 size_t section_sizes[DW_SECT_MAX];
97 static int cu_count = 0;
98 static int tu_count = 0;
99 static struct cu_tu_set *cu_sets = NULL;
100 static struct cu_tu_set *tu_sets = NULL;
102 static void load_cu_tu_indexes (void *file);
104 /* Values for do_debug_lines. */
105 #define FLAG_DEBUG_LINES_RAW 1
106 #define FLAG_DEBUG_LINES_DECODED 2
109 size_of_encoded_value (int encoding)
111 switch (encoding & 0x7)
114 case 0: return eh_addr_size;
122 get_encoded_value (unsigned char **pdata,
124 struct dwarf_section *section,
127 unsigned char * data = * pdata;
128 unsigned int size = size_of_encoded_value (encoding);
131 if (data + size >= end)
133 warn (_("Encoded value extends past end of section\n"));
138 /* PR 17512: file: 002-829853-0.004. */
141 warn (_("Encoded size of %d is too large to read\n"), size);
146 /* PR 17512: file: 1085-5603-0.004. */
149 warn (_("Encoded size of 0 is too small to read\n"));
154 if (encoding & DW_EH_PE_signed)
155 val = byte_get_signed (data, size);
157 val = byte_get (data, size);
159 if ((encoding & 0x70) == DW_EH_PE_pcrel)
160 val += section->address + (data - section->start);
162 * pdata = data + size;
166 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
168 # define DWARF_VMA_FMT "ll"
169 # define DWARF_VMA_FMT_LONG "%16.16llx"
171 # define DWARF_VMA_FMT "I64"
172 # define DWARF_VMA_FMT_LONG "%016I64x"
175 # define DWARF_VMA_FMT "l"
176 # define DWARF_VMA_FMT_LONG "%16.16lx"
179 /* Convert a dwarf vma value into a string. Returns a pointer to a static
180 buffer containing the converted VALUE. The value is converted according
181 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
182 it specifies the maximum number of bytes to be displayed in the converted
183 value and FMTCH is ignored - hex is always used. */
186 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
188 /* As dwarf_vmatoa is used more then once in a printf call
189 for output, we are cycling through an fixed array of pointers
190 for return address. */
191 static int buf_pos = 0;
192 static struct dwarf_vmatoa_buf
198 ret = buf[buf_pos++].place;
199 buf_pos %= ARRAY_SIZE (buf);
203 /* Printf does not have a way of specifiying a maximum field width for an
204 integer value, so we print the full value into a buffer and then select
205 the precision we need. */
206 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
209 return ret + (16 - 2 * num_bytes);
215 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
216 snprintf (ret, sizeof (buf[0].place), fmt, value);
221 static inline const char *
222 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
224 return dwarf_vmatoa_1 (fmtch, value, 0);
227 /* Print a dwarf_vma value (typically an address, offset or length) in
228 hexadecimal format, followed by a space. The length of the VALUE (and
229 hence the precision displayed) is determined by the NUM_BYTES parameter. */
232 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
234 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
237 /* Format a 64-bit value, given as two 32-bit values, in hex.
238 For reentrancy, this uses a buffer provided by the caller. */
241 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
242 unsigned int buf_len)
247 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
250 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
251 snprintf (buf + len, buf_len - len,
252 "%08" DWARF_VMA_FMT "x", lvalue);
258 /* Read in a LEB128 encoded value starting at address DATA.
259 If SIGN is true, return a signed LEB128 value.
260 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
261 No bytes will be read at address END or beyond. */
264 read_leb128 (unsigned char *data,
265 unsigned int *length_return,
267 const unsigned char * const end)
269 dwarf_vma result = 0;
270 unsigned int num_read = 0;
271 unsigned int shift = 0;
272 unsigned char byte = 0;
279 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
282 if ((byte & 0x80) == 0)
286 if (length_return != NULL)
287 *length_return = num_read;
289 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
290 result |= (dwarf_vma) -1 << shift;
295 /* Create a signed version to avoid painful typecasts. */
296 static inline dwarf_signed_vma
297 read_sleb128 (unsigned char * data,
298 unsigned int * length_return,
299 const unsigned char * const end)
301 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
304 static inline dwarf_vma
305 read_uleb128 (unsigned char * data,
306 unsigned int * length_return,
307 const unsigned char * const end)
309 return read_leb128 (data, length_return, FALSE, end);
312 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
315 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
316 unsigned int amount = (AMOUNT); \
317 if (((PTR) + amount) >= (END)) \
320 amount = (END) - (PTR); \
324 if (amount == 0 || amount > 8) \
327 VAL = byte_get ((PTR), amount); \
331 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
334 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
339 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
342 unsigned int amount = (AMOUNT); \
343 if (((PTR) + amount) >= (END)) \
346 amount = (END) - (PTR); \
351 VAL = byte_get_signed ((PTR), amount); \
357 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
360 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
365 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
368 if (((PTR) + 8) <= (END)) \
370 byte_get_64 ((PTR), (HIGH), (LOW)); \
374 * (LOW) = * (HIGH) = 0; \
379 typedef struct State_Machine_Registers
387 unsigned char op_index;
388 unsigned char end_sequence;
389 /* This variable hold the number of the last entry seen
390 in the File Table. */
391 unsigned int last_file_entry;
394 static SMR state_machine_regs;
397 reset_state_machine (int is_stmt)
399 state_machine_regs.address = 0;
400 state_machine_regs.op_index = 0;
401 state_machine_regs.file = 1;
402 state_machine_regs.line = 1;
403 state_machine_regs.column = 0;
404 state_machine_regs.is_stmt = is_stmt;
405 state_machine_regs.basic_block = 0;
406 state_machine_regs.end_sequence = 0;
407 state_machine_regs.last_file_entry = 0;
410 /* Handled an extend line op.
411 Returns the number of bytes read. */
414 process_extended_line_op (unsigned char * data,
418 unsigned char op_code;
419 unsigned int bytes_read;
422 unsigned char *orig_data = data;
425 len = read_uleb128 (data, & bytes_read, end);
428 if (len == 0 || data == end || len > (uintptr_t) (end - data))
430 warn (_("Badly formed extended line op encountered!\n"));
437 printf (_(" Extended opcode %d: "), op_code);
441 case DW_LNE_end_sequence:
442 printf (_("End of Sequence\n\n"));
443 reset_state_machine (is_stmt);
446 case DW_LNE_set_address:
447 /* PR 17512: file: 002-100480-0.004. */
448 if (len - bytes_read - 1 > 8)
449 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
450 len - bytes_read - 1);
451 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
452 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
453 state_machine_regs.address = adr;
454 state_machine_regs.op_index = 0;
457 case DW_LNE_define_file:
458 printf (_("define new File Table entry\n"));
459 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
460 printf (" %d\t", ++state_machine_regs.last_file_entry);
463 data += strnlen ((char *) data, end - data) + 1;
464 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
466 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
468 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
470 printf ("%s\n\n", name);
472 if (((unsigned int) (data - orig_data) != len) || data == end)
473 warn (_("DW_LNE_define_file: Bad opcode length\n"));
476 case DW_LNE_set_discriminator:
477 printf (_("set Discriminator to %s\n"),
478 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
482 case DW_LNE_HP_negate_is_UV_update:
483 printf ("DW_LNE_HP_negate_is_UV_update\n");
485 case DW_LNE_HP_push_context:
486 printf ("DW_LNE_HP_push_context\n");
488 case DW_LNE_HP_pop_context:
489 printf ("DW_LNE_HP_pop_context\n");
491 case DW_LNE_HP_set_file_line_column:
492 printf ("DW_LNE_HP_set_file_line_column\n");
494 case DW_LNE_HP_set_routine_name:
495 printf ("DW_LNE_HP_set_routine_name\n");
497 case DW_LNE_HP_set_sequence:
498 printf ("DW_LNE_HP_set_sequence\n");
500 case DW_LNE_HP_negate_post_semantics:
501 printf ("DW_LNE_HP_negate_post_semantics\n");
503 case DW_LNE_HP_negate_function_exit:
504 printf ("DW_LNE_HP_negate_function_exit\n");
506 case DW_LNE_HP_negate_front_end_logical:
507 printf ("DW_LNE_HP_negate_front_end_logical\n");
509 case DW_LNE_HP_define_proc:
510 printf ("DW_LNE_HP_define_proc\n");
512 case DW_LNE_HP_source_file_correlation:
514 unsigned char *edata = data + len - bytes_read - 1;
516 printf ("DW_LNE_HP_source_file_correlation\n");
522 opc = read_uleb128 (data, & bytes_read, edata);
527 case DW_LNE_HP_SFC_formfeed:
528 printf (" DW_LNE_HP_SFC_formfeed\n");
530 case DW_LNE_HP_SFC_set_listing_line:
531 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
533 read_uleb128 (data, & bytes_read, edata)));
536 case DW_LNE_HP_SFC_associate:
537 printf (" DW_LNE_HP_SFC_associate ");
540 read_uleb128 (data, & bytes_read, edata)));
544 read_uleb128 (data, & bytes_read, edata)));
548 read_uleb128 (data, & bytes_read, edata)));
552 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
562 unsigned int rlen = len - bytes_read - 1;
564 if (op_code >= DW_LNE_lo_user
565 /* The test against DW_LNW_hi_user is redundant due to
566 the limited range of the unsigned char data type used
568 /*&& op_code <= DW_LNE_hi_user*/)
569 printf (_("user defined: "));
571 printf (_("UNKNOWN: "));
572 printf (_("length %d ["), rlen);
574 printf (" %02x", *data++);
583 static const unsigned char *
584 fetch_indirect_string (dwarf_vma offset)
586 struct dwarf_section *section = &debug_displays [str].section;
588 if (section->start == NULL)
589 return (const unsigned char *) _("<no .debug_str section>");
591 if (offset > section->size)
593 warn (_("DW_FORM_strp offset too big: %s\n"),
594 dwarf_vmatoa ("x", offset));
595 return (const unsigned char *) _("<offset is too big>");
598 return (const unsigned char *) section->start + offset;
602 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
603 dwarf_vma offset_size, int dwo)
605 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
606 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
607 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
608 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
609 dwarf_vma index_offset = idx * offset_size;
610 dwarf_vma str_offset;
612 if (index_section->start == NULL)
613 return (dwo ? _("<no .debug_str_offsets.dwo section>")
614 : _("<no .debug_str_offsets section>"));
616 if (this_set != NULL)
617 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
618 if (index_offset > index_section->size)
620 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
621 dwarf_vmatoa ("x", index_offset));
622 return _("<index offset is too big>");
625 if (str_section->start == NULL)
626 return (dwo ? _("<no .debug_str.dwo section>")
627 : _("<no .debug_str section>"));
629 str_offset = byte_get (index_section->start + index_offset, offset_size);
630 str_offset -= str_section->address;
631 if (str_offset > str_section->size)
633 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
634 dwarf_vmatoa ("x", str_offset));
635 return _("<indirect index offset is too big>");
638 return (const char *) str_section->start + str_offset;
642 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
644 struct dwarf_section *section = &debug_displays [debug_addr].section;
646 if (section->start == NULL)
647 return (_("<no .debug_addr section>"));
649 if (offset + bytes > section->size)
651 warn (_("Offset into section %s too big: %s\n"),
652 section->name, dwarf_vmatoa ("x", offset));
653 return "<offset too big>";
656 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
660 /* FIXME: There are better and more efficient ways to handle
661 these structures. For now though, I just want something that
662 is simple to implement. */
663 typedef struct abbrev_attr
665 unsigned long attribute;
667 struct abbrev_attr *next;
671 typedef struct abbrev_entry
676 struct abbrev_attr *first_attr;
677 struct abbrev_attr *last_attr;
678 struct abbrev_entry *next;
682 static abbrev_entry *first_abbrev = NULL;
683 static abbrev_entry *last_abbrev = NULL;
690 for (abbrv = first_abbrev; abbrv;)
692 abbrev_entry *next_abbrev = abbrv->next;
695 for (attr = abbrv->first_attr; attr;)
697 abbrev_attr *next_attr = attr->next;
707 last_abbrev = first_abbrev = NULL;
711 add_abbrev (unsigned long number, unsigned long tag, int children)
715 entry = (abbrev_entry *) malloc (sizeof (*entry));
720 entry->entry = number;
722 entry->children = children;
723 entry->first_attr = NULL;
724 entry->last_attr = NULL;
727 if (first_abbrev == NULL)
728 first_abbrev = entry;
730 last_abbrev->next = entry;
736 add_abbrev_attr (unsigned long attribute, unsigned long form)
740 attr = (abbrev_attr *) malloc (sizeof (*attr));
745 attr->attribute = attribute;
749 if (last_abbrev->first_attr == NULL)
750 last_abbrev->first_attr = attr;
752 last_abbrev->last_attr->next = attr;
754 last_abbrev->last_attr = attr;
757 /* Processes the (partial) contents of a .debug_abbrev section.
758 Returns NULL if the end of the section was encountered.
759 Returns the address after the last byte read if the end of
760 an abbreviation set was found. */
762 static unsigned char *
763 process_abbrev_section (unsigned char *start, unsigned char *end)
765 if (first_abbrev != NULL)
770 unsigned int bytes_read;
773 unsigned long attribute;
776 entry = read_uleb128 (start, & bytes_read, end);
779 /* A single zero is supposed to end the section according
780 to the standard. If there's more, then signal that to
787 tag = read_uleb128 (start, & bytes_read, end);
794 add_abbrev (entry, tag, children);
800 attribute = read_uleb128 (start, & bytes_read, end);
805 form = read_uleb128 (start, & bytes_read, end);
810 add_abbrev_attr (attribute, form);
812 while (attribute != 0);
815 /* Report the missing single zero which ends the section. */
816 error (_(".debug_abbrev section not zero terminated\n"));
822 get_TAG_name (unsigned long tag)
824 const char *name = get_DW_TAG_name ((unsigned int)tag);
828 static char buffer[100];
830 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
838 get_FORM_name (unsigned long form)
843 return "DW_FORM value: 0";
845 name = get_DW_FORM_name (form);
848 static char buffer[100];
850 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
857 static unsigned char *
858 display_block (unsigned char *data,
860 const unsigned char * const end)
864 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
866 return (unsigned char *) end;
868 maxlen = (dwarf_vma) (end - data);
869 length = length > maxlen ? maxlen : length;
872 printf ("%lx ", (unsigned long) byte_get (data++, 1));
878 decode_location_expression (unsigned char * data,
879 unsigned int pointer_size,
880 unsigned int offset_size,
884 struct dwarf_section * section)
887 unsigned int bytes_read;
889 dwarf_signed_vma svalue;
890 unsigned char *end = data + length;
891 int need_frame_base = 0;
900 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
901 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
904 printf ("DW_OP_deref");
907 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
908 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
911 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
912 printf ("DW_OP_const1s: %ld", (long) svalue);
915 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
916 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
919 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
920 printf ("DW_OP_const2s: %ld", (long) svalue);
923 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
924 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
927 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
928 printf ("DW_OP_const4s: %ld", (long) svalue);
931 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
932 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
933 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
934 printf ("%lu", (unsigned long) uvalue);
937 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
938 printf ("DW_OP_const8s: %ld ", (long) svalue);
939 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
940 printf ("%ld", (long) svalue);
943 printf ("DW_OP_constu: %s",
944 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
948 printf ("DW_OP_consts: %s",
949 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
953 printf ("DW_OP_dup");
956 printf ("DW_OP_drop");
959 printf ("DW_OP_over");
962 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
963 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
966 printf ("DW_OP_swap");
969 printf ("DW_OP_rot");
972 printf ("DW_OP_xderef");
975 printf ("DW_OP_abs");
978 printf ("DW_OP_and");
981 printf ("DW_OP_div");
984 printf ("DW_OP_minus");
987 printf ("DW_OP_mod");
990 printf ("DW_OP_mul");
993 printf ("DW_OP_neg");
996 printf ("DW_OP_not");
1002 printf ("DW_OP_plus");
1004 case DW_OP_plus_uconst:
1005 printf ("DW_OP_plus_uconst: %s",
1006 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1010 printf ("DW_OP_shl");
1013 printf ("DW_OP_shr");
1016 printf ("DW_OP_shra");
1019 printf ("DW_OP_xor");
1022 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1023 printf ("DW_OP_bra: %ld", (long) svalue);
1026 printf ("DW_OP_eq");
1029 printf ("DW_OP_ge");
1032 printf ("DW_OP_gt");
1035 printf ("DW_OP_le");
1038 printf ("DW_OP_lt");
1041 printf ("DW_OP_ne");
1044 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1045 printf ("DW_OP_skip: %ld", (long) svalue);
1080 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1115 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1116 regname (op - DW_OP_reg0, 1));
1151 printf ("DW_OP_breg%d (%s): %s",
1153 regname (op - DW_OP_breg0, 1),
1154 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1159 uvalue = read_uleb128 (data, &bytes_read, end);
1161 printf ("DW_OP_regx: %s (%s)",
1162 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1165 need_frame_base = 1;
1166 printf ("DW_OP_fbreg: %s",
1167 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1171 uvalue = read_uleb128 (data, &bytes_read, end);
1173 printf ("DW_OP_bregx: %s (%s) %s",
1174 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1175 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1179 printf ("DW_OP_piece: %s",
1180 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1183 case DW_OP_deref_size:
1184 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1185 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1187 case DW_OP_xderef_size:
1188 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1189 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1192 printf ("DW_OP_nop");
1195 /* DWARF 3 extensions. */
1196 case DW_OP_push_object_address:
1197 printf ("DW_OP_push_object_address");
1200 /* XXX: Strictly speaking for 64-bit DWARF3 files
1201 this ought to be an 8-byte wide computation. */
1202 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1203 printf ("DW_OP_call2: <0x%s>",
1204 dwarf_vmatoa ("x", svalue + cu_offset));
1207 /* XXX: Strictly speaking for 64-bit DWARF3 files
1208 this ought to be an 8-byte wide computation. */
1209 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1210 printf ("DW_OP_call4: <0x%s>",
1211 dwarf_vmatoa ("x", svalue + cu_offset));
1213 case DW_OP_call_ref:
1214 /* XXX: Strictly speaking for 64-bit DWARF3 files
1215 this ought to be an 8-byte wide computation. */
1216 if (dwarf_version == -1)
1218 printf (_("(DW_OP_call_ref in frame info)"));
1219 /* No way to tell where the next op is, so just bail. */
1220 return need_frame_base;
1222 if (dwarf_version == 2)
1224 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1228 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1230 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1232 case DW_OP_form_tls_address:
1233 printf ("DW_OP_form_tls_address");
1235 case DW_OP_call_frame_cfa:
1236 printf ("DW_OP_call_frame_cfa");
1238 case DW_OP_bit_piece:
1239 printf ("DW_OP_bit_piece: ");
1240 printf (_("size: %s "),
1241 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1243 printf (_("offset: %s "),
1244 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1248 /* DWARF 4 extensions. */
1249 case DW_OP_stack_value:
1250 printf ("DW_OP_stack_value");
1253 case DW_OP_implicit_value:
1254 printf ("DW_OP_implicit_value");
1255 uvalue = read_uleb128 (data, &bytes_read, end);
1257 data = display_block (data, uvalue, end);
1260 /* GNU extensions. */
1261 case DW_OP_GNU_push_tls_address:
1262 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1264 case DW_OP_GNU_uninit:
1265 printf ("DW_OP_GNU_uninit");
1266 /* FIXME: Is there data associated with this OP ? */
1268 case DW_OP_GNU_encoded_addr:
1275 addr = get_encoded_value (&data, encoding, section, end);
1277 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1278 print_dwarf_vma (addr, pointer_size);
1281 case DW_OP_GNU_implicit_pointer:
1282 /* XXX: Strictly speaking for 64-bit DWARF3 files
1283 this ought to be an 8-byte wide computation. */
1284 if (dwarf_version == -1)
1286 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1287 /* No way to tell where the next op is, so just bail. */
1288 return need_frame_base;
1290 if (dwarf_version == 2)
1292 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1296 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1298 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1299 dwarf_vmatoa ("x", uvalue),
1300 dwarf_vmatoa ("d", read_sleb128 (data,
1301 &bytes_read, end)));
1304 case DW_OP_GNU_entry_value:
1305 uvalue = read_uleb128 (data, &bytes_read, end);
1307 /* PR 17531: file: 0cc9cd00. */
1308 if (uvalue > (dwarf_vma) (end - data))
1309 uvalue = end - data;
1310 printf ("DW_OP_GNU_entry_value: (");
1311 if (decode_location_expression (data, pointer_size, offset_size,
1312 dwarf_version, uvalue,
1313 cu_offset, section))
1314 need_frame_base = 1;
1320 case DW_OP_GNU_const_type:
1321 uvalue = read_uleb128 (data, &bytes_read, end);
1323 printf ("DW_OP_GNU_const_type: <0x%s> ",
1324 dwarf_vmatoa ("x", cu_offset + uvalue));
1325 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1326 data = display_block (data, uvalue, end);
1328 case DW_OP_GNU_regval_type:
1329 uvalue = read_uleb128 (data, &bytes_read, end);
1331 printf ("DW_OP_GNU_regval_type: %s (%s)",
1332 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1333 uvalue = read_uleb128 (data, &bytes_read, end);
1335 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1337 case DW_OP_GNU_deref_type:
1338 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1339 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
1340 uvalue = read_uleb128 (data, &bytes_read, end);
1342 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1344 case DW_OP_GNU_convert:
1345 uvalue = read_uleb128 (data, &bytes_read, end);
1347 printf ("DW_OP_GNU_convert <0x%s>",
1348 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1350 case DW_OP_GNU_reinterpret:
1351 uvalue = read_uleb128 (data, &bytes_read, end);
1353 printf ("DW_OP_GNU_reinterpret <0x%s>",
1354 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1356 case DW_OP_GNU_parameter_ref:
1357 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1358 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1359 dwarf_vmatoa ("x", cu_offset + uvalue));
1361 case DW_OP_GNU_addr_index:
1362 uvalue = read_uleb128 (data, &bytes_read, end);
1364 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1366 case DW_OP_GNU_const_index:
1367 uvalue = read_uleb128 (data, &bytes_read, end);
1369 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1372 /* HP extensions. */
1373 case DW_OP_HP_is_value:
1374 printf ("DW_OP_HP_is_value");
1375 /* FIXME: Is there data associated with this OP ? */
1377 case DW_OP_HP_fltconst4:
1378 printf ("DW_OP_HP_fltconst4");
1379 /* FIXME: Is there data associated with this OP ? */
1381 case DW_OP_HP_fltconst8:
1382 printf ("DW_OP_HP_fltconst8");
1383 /* FIXME: Is there data associated with this OP ? */
1385 case DW_OP_HP_mod_range:
1386 printf ("DW_OP_HP_mod_range");
1387 /* FIXME: Is there data associated with this OP ? */
1389 case DW_OP_HP_unmod_range:
1390 printf ("DW_OP_HP_unmod_range");
1391 /* FIXME: Is there data associated with this OP ? */
1394 printf ("DW_OP_HP_tls");
1395 /* FIXME: Is there data associated with this OP ? */
1398 /* PGI (STMicroelectronics) extensions. */
1399 case DW_OP_PGI_omp_thread_num:
1400 /* Pushes the thread number for the current thread as it would be
1401 returned by the standard OpenMP library function:
1402 omp_get_thread_num(). The "current thread" is the thread for
1403 which the expression is being evaluated. */
1404 printf ("DW_OP_PGI_omp_thread_num");
1408 if (op >= DW_OP_lo_user
1409 && op <= DW_OP_hi_user)
1410 printf (_("(User defined location op)"));
1412 printf (_("(Unknown location op)"));
1413 /* No way to tell where the next op is, so just bail. */
1414 return need_frame_base;
1417 /* Separate the ops. */
1422 return need_frame_base;
1425 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1426 This is used for DWARF package files. */
1428 static struct cu_tu_set *
1429 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1431 struct cu_tu_set *p;
1433 unsigned int dw_sect;
1439 dw_sect = DW_SECT_TYPES;
1445 dw_sect = DW_SECT_INFO;
1449 if (p->section_offsets [dw_sect] == cu_offset)
1457 /* Add INC to HIGH_BITS:LOW_BITS. */
1459 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1461 dwarf_vma tmp = * low_bits;
1465 /* FIXME: There is probably a better way of handling this:
1467 We need to cope with dwarf_vma being a 32-bit or 64-bit
1468 type. Plus regardless of its size LOW_BITS is meant to
1469 only hold 32-bits, so if there is overflow or wrap around
1470 we must propagate into HIGH_BITS. */
1471 if (tmp < * low_bits)
1475 else if (sizeof (tmp) > 8
1485 static unsigned char *
1486 read_and_display_attr_value (unsigned long attribute,
1488 unsigned char * data,
1489 unsigned char * end,
1490 dwarf_vma cu_offset,
1491 dwarf_vma pointer_size,
1492 dwarf_vma offset_size,
1494 debug_info * debug_info_p,
1496 struct dwarf_section * section,
1497 struct cu_tu_set * this_set)
1499 dwarf_vma uvalue = 0;
1500 unsigned char *block_start = NULL;
1501 unsigned char * orig_data = data;
1502 unsigned int bytes_read;
1504 if (data > end || (data == end && form != DW_FORM_flag_present))
1506 warn (_("Corrupt attribute\n"));
1515 case DW_FORM_ref_addr:
1516 if (dwarf_version == 2)
1517 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1518 else if (dwarf_version == 3 || dwarf_version == 4)
1519 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1521 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1526 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1530 case DW_FORM_sec_offset:
1531 case DW_FORM_GNU_ref_alt:
1532 case DW_FORM_GNU_strp_alt:
1533 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1536 case DW_FORM_flag_present:
1543 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1548 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1553 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1557 uvalue = read_sleb128 (data, & bytes_read, end);
1561 case DW_FORM_GNU_str_index:
1562 uvalue = read_uleb128 (data, & bytes_read, end);
1566 case DW_FORM_ref_udata:
1568 uvalue = read_uleb128 (data, & bytes_read, end);
1572 case DW_FORM_indirect:
1573 form = read_uleb128 (data, & bytes_read, end);
1576 printf (" %s", get_FORM_name (form));
1577 return read_and_display_attr_value (attribute, form, data, end,
1578 cu_offset, pointer_size,
1579 offset_size, dwarf_version,
1580 debug_info_p, do_loc,
1582 case DW_FORM_GNU_addr_index:
1583 uvalue = read_uleb128 (data, & bytes_read, end);
1590 case DW_FORM_ref_addr:
1592 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1595 case DW_FORM_GNU_ref_alt:
1597 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1603 case DW_FORM_ref_udata:
1605 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1610 case DW_FORM_sec_offset:
1612 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1615 case DW_FORM_flag_present:
1622 printf (" %s", dwarf_vmatoa ("d", uvalue));
1629 dwarf_vma high_bits;
1633 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1635 if (form == DW_FORM_ref8)
1636 add64 (& high_bits, & utmp, cu_offset);
1638 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1641 if ((do_loc || do_debug_loc || do_debug_ranges)
1642 && num_debug_info_entries == 0)
1644 if (sizeof (uvalue) == 8)
1645 SAFE_BYTE_GET (uvalue, data, 8, end);
1647 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1653 case DW_FORM_string:
1655 printf (" %.*s", (int) (end - data), data);
1656 data += strnlen ((char *) data, end - data) + 1;
1660 case DW_FORM_exprloc:
1661 uvalue = read_uleb128 (data, & bytes_read, end);
1662 block_start = data + bytes_read;
1663 if (block_start >= end)
1665 warn (_("Block ends prematurely\n"));
1669 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1670 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1671 block_start + uvalue here. */
1672 data = block_start + uvalue;
1673 /* PR 17512: file: 008-103549-0.001:0.1. */
1674 if (block_start + uvalue > end || data < block_start)
1676 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1677 uvalue = end - block_start;
1680 data = block_start + uvalue;
1682 data = display_block (block_start, uvalue, end);
1685 case DW_FORM_block1:
1686 SAFE_BYTE_GET (uvalue, data, 1, end);
1687 block_start = data + 1;
1688 if (block_start >= end)
1690 warn (_("Block ends prematurely\n"));
1694 data = block_start + uvalue;
1695 if (block_start + uvalue > end || data < block_start)
1697 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1698 uvalue = end - block_start;
1701 data = block_start + uvalue;
1703 data = display_block (block_start, uvalue, end);
1706 case DW_FORM_block2:
1707 SAFE_BYTE_GET (uvalue, data, 2, end);
1708 block_start = data + 2;
1709 if (block_start >= end)
1711 warn (_("Block ends prematurely\n"));
1715 data = block_start + uvalue;
1716 if (block_start + uvalue > end || data < block_start)
1718 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1719 uvalue = end - block_start;
1722 data = block_start + uvalue;
1724 data = display_block (block_start, uvalue, end);
1727 case DW_FORM_block4:
1728 SAFE_BYTE_GET (uvalue, data, 4, end);
1729 block_start = data + 4;
1730 /* PR 17512: file: 3371-3907-0.004. */
1731 if (block_start >= end)
1733 warn (_("Block ends prematurely\n"));
1737 data = block_start + uvalue;
1738 if (block_start + uvalue > end
1739 /* PR 17531: file: 5b5f0592. */
1740 || data < block_start)
1742 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1743 uvalue = end - block_start;
1746 data = block_start + uvalue;
1748 data = display_block (block_start, uvalue, end);
1753 printf (_(" (indirect string, offset: 0x%s): %s"),
1754 dwarf_vmatoa ("x", uvalue),
1755 fetch_indirect_string (uvalue));
1758 case DW_FORM_GNU_str_index:
1761 const char *suffix = strrchr (section->name, '.');
1762 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1764 printf (_(" (indexed string: 0x%s): %s"),
1765 dwarf_vmatoa ("x", uvalue),
1766 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1770 case DW_FORM_GNU_strp_alt:
1772 printf (_(" (alt indirect string, offset: 0x%s)"),
1773 dwarf_vmatoa ("x", uvalue));
1776 case DW_FORM_indirect:
1777 /* Handled above. */
1780 case DW_FORM_ref_sig8:
1783 dwarf_vma high_bits;
1786 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1787 printf (" signature: 0x%s",
1788 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1793 case DW_FORM_GNU_addr_index:
1795 printf (_(" (addr_index: 0x%s): %s"),
1796 dwarf_vmatoa ("x", uvalue),
1797 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1801 warn (_("Unrecognized form: %lu\n"), form);
1805 if ((do_loc || do_debug_loc || do_debug_ranges)
1806 && num_debug_info_entries == 0
1807 && debug_info_p != NULL)
1811 case DW_AT_frame_base:
1812 have_frame_base = 1;
1813 case DW_AT_location:
1814 case DW_AT_string_length:
1815 case DW_AT_return_addr:
1816 case DW_AT_data_member_location:
1817 case DW_AT_vtable_elem_location:
1819 case DW_AT_static_link:
1820 case DW_AT_use_location:
1821 case DW_AT_GNU_call_site_value:
1822 case DW_AT_GNU_call_site_data_value:
1823 case DW_AT_GNU_call_site_target:
1824 case DW_AT_GNU_call_site_target_clobbered:
1825 if ((dwarf_version < 4
1826 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1827 || form == DW_FORM_sec_offset)
1829 /* Process location list. */
1830 unsigned int lmax = debug_info_p->max_loc_offsets;
1831 unsigned int num = debug_info_p->num_loc_offsets;
1833 if (lmax == 0 || num >= lmax)
1836 debug_info_p->loc_offsets = (dwarf_vma *)
1837 xcrealloc (debug_info_p->loc_offsets,
1838 lmax, sizeof (*debug_info_p->loc_offsets));
1839 debug_info_p->have_frame_base = (int *)
1840 xcrealloc (debug_info_p->have_frame_base,
1841 lmax, sizeof (*debug_info_p->have_frame_base));
1842 debug_info_p->max_loc_offsets = lmax;
1844 if (this_set != NULL)
1845 uvalue += this_set->section_offsets [DW_SECT_LOC];
1846 debug_info_p->loc_offsets [num] = uvalue;
1847 debug_info_p->have_frame_base [num] = have_frame_base;
1848 debug_info_p->num_loc_offsets++;
1853 if (need_base_address)
1854 debug_info_p->base_address = uvalue;
1857 case DW_AT_GNU_addr_base:
1858 debug_info_p->addr_base = uvalue;
1861 case DW_AT_GNU_ranges_base:
1862 debug_info_p->ranges_base = uvalue;
1866 if ((dwarf_version < 4
1867 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1868 || form == DW_FORM_sec_offset)
1870 /* Process range list. */
1871 unsigned int lmax = debug_info_p->max_range_lists;
1872 unsigned int num = debug_info_p->num_range_lists;
1874 if (lmax == 0 || num >= lmax)
1877 debug_info_p->range_lists = (dwarf_vma *)
1878 xcrealloc (debug_info_p->range_lists,
1879 lmax, sizeof (*debug_info_p->range_lists));
1880 debug_info_p->max_range_lists = lmax;
1882 debug_info_p->range_lists [num] = uvalue;
1883 debug_info_p->num_range_lists++;
1892 if (do_loc || attribute == 0)
1895 /* For some attributes we can display further information. */
1902 case DW_INL_not_inlined:
1903 printf (_("(not inlined)"));
1905 case DW_INL_inlined:
1906 printf (_("(inlined)"));
1908 case DW_INL_declared_not_inlined:
1909 printf (_("(declared as inline but ignored)"));
1911 case DW_INL_declared_inlined:
1912 printf (_("(declared as inline and inlined)"));
1915 printf (_(" (Unknown inline attribute value: %s)"),
1916 dwarf_vmatoa ("x", uvalue));
1921 case DW_AT_language:
1925 /* Ordered by the numeric value of these constants. */
1926 case DW_LANG_C89: printf ("(ANSI C)"); break;
1927 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1928 case DW_LANG_Ada83: printf ("(Ada)"); break;
1929 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1930 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1931 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1932 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1933 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1934 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1935 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1936 /* DWARF 2.1 values. */
1937 case DW_LANG_Java: printf ("(Java)"); break;
1938 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1939 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1940 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1941 /* DWARF 3 values. */
1942 case DW_LANG_PLI: printf ("(PLI)"); break;
1943 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1944 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1945 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1946 case DW_LANG_D: printf ("(D)"); break;
1947 /* DWARF 4 values. */
1948 case DW_LANG_Python: printf ("(Python)"); break;
1949 /* DWARF 5 values. */
1950 case DW_LANG_Go: printf ("(Go)"); break;
1951 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
1952 case DW_LANG_C11: printf ("(C11)"); break;
1953 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
1954 /* MIPS extension. */
1955 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1956 /* UPC extension. */
1957 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1959 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1960 printf (_("(implementation defined: %s)"),
1961 dwarf_vmatoa ("x", uvalue));
1963 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1968 case DW_AT_encoding:
1972 case DW_ATE_void: printf ("(void)"); break;
1973 case DW_ATE_address: printf ("(machine address)"); break;
1974 case DW_ATE_boolean: printf ("(boolean)"); break;
1975 case DW_ATE_complex_float: printf ("(complex float)"); break;
1976 case DW_ATE_float: printf ("(float)"); break;
1977 case DW_ATE_signed: printf ("(signed)"); break;
1978 case DW_ATE_signed_char: printf ("(signed char)"); break;
1979 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1980 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1981 /* DWARF 2.1 values: */
1982 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1983 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1984 /* DWARF 3 values: */
1985 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1986 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1987 case DW_ATE_edited: printf ("(edited)"); break;
1988 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1989 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1990 /* HP extensions: */
1991 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1992 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1993 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1994 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1995 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1996 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1997 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2000 if (uvalue >= DW_ATE_lo_user
2001 && uvalue <= DW_ATE_hi_user)
2002 printf (_("(user defined type)"));
2004 printf (_("(unknown type)"));
2009 case DW_AT_accessibility:
2013 case DW_ACCESS_public: printf ("(public)"); break;
2014 case DW_ACCESS_protected: printf ("(protected)"); break;
2015 case DW_ACCESS_private: printf ("(private)"); break;
2017 printf (_("(unknown accessibility)"));
2022 case DW_AT_visibility:
2026 case DW_VIS_local: printf ("(local)"); break;
2027 case DW_VIS_exported: printf ("(exported)"); break;
2028 case DW_VIS_qualified: printf ("(qualified)"); break;
2029 default: printf (_("(unknown visibility)")); break;
2033 case DW_AT_virtuality:
2037 case DW_VIRTUALITY_none: printf ("(none)"); break;
2038 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2039 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2040 default: printf (_("(unknown virtuality)")); break;
2044 case DW_AT_identifier_case:
2048 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2049 case DW_ID_up_case: printf ("(up_case)"); break;
2050 case DW_ID_down_case: printf ("(down_case)"); break;
2051 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2052 default: printf (_("(unknown case)")); break;
2056 case DW_AT_calling_convention:
2060 case DW_CC_normal: printf ("(normal)"); break;
2061 case DW_CC_program: printf ("(program)"); break;
2062 case DW_CC_nocall: printf ("(nocall)"); break;
2064 if (uvalue >= DW_CC_lo_user
2065 && uvalue <= DW_CC_hi_user)
2066 printf (_("(user defined)"));
2068 printf (_("(unknown convention)"));
2072 case DW_AT_ordering:
2076 case -1: printf (_("(undefined)")); break;
2077 case 0: printf ("(row major)"); break;
2078 case 1: printf ("(column major)"); break;
2082 case DW_AT_frame_base:
2083 have_frame_base = 1;
2084 case DW_AT_location:
2085 case DW_AT_string_length:
2086 case DW_AT_return_addr:
2087 case DW_AT_data_member_location:
2088 case DW_AT_vtable_elem_location:
2090 case DW_AT_static_link:
2091 case DW_AT_use_location:
2092 case DW_AT_GNU_call_site_value:
2093 case DW_AT_GNU_call_site_data_value:
2094 case DW_AT_GNU_call_site_target:
2095 case DW_AT_GNU_call_site_target_clobbered:
2096 if ((dwarf_version < 4
2097 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2098 || form == DW_FORM_sec_offset)
2099 printf (_(" (location list)"));
2101 case DW_AT_allocated:
2102 case DW_AT_associated:
2103 case DW_AT_data_location:
2105 case DW_AT_upper_bound:
2106 case DW_AT_lower_bound:
2109 int need_frame_base;
2112 need_frame_base = decode_location_expression (block_start,
2117 cu_offset, section);
2119 if (need_frame_base && !have_frame_base)
2120 printf (_(" [without DW_AT_frame_base]"));
2126 if (form == DW_FORM_ref_sig8
2127 || form == DW_FORM_GNU_ref_alt)
2130 if (form == DW_FORM_ref1
2131 || form == DW_FORM_ref2
2132 || form == DW_FORM_ref4
2133 || form == DW_FORM_ref_udata)
2134 uvalue += cu_offset;
2136 if (uvalue >= section->size)
2137 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2138 dwarf_vmatoa ("x", uvalue),
2139 (unsigned long) (orig_data - section->start));
2142 unsigned long abbrev_number;
2143 abbrev_entry * entry;
2145 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2147 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2148 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2149 use different abbrev table, and we don't track .debug_info chunks
2151 if (form != DW_FORM_ref_addr)
2153 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2154 if (entry->entry == abbrev_number)
2157 printf (" (%s)", get_TAG_name (entry->tag));
2172 get_AT_name (unsigned long attribute)
2177 return "DW_AT value: 0";
2179 /* One value is shared by the MIPS and HP extensions: */
2180 if (attribute == DW_AT_MIPS_fde)
2181 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2183 name = get_DW_AT_name (attribute);
2187 static char buffer[100];
2189 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2197 static unsigned char *
2198 read_and_display_attr (unsigned long attribute,
2200 unsigned char * data,
2201 unsigned char * end,
2202 dwarf_vma cu_offset,
2203 dwarf_vma pointer_size,
2204 dwarf_vma offset_size,
2206 debug_info * debug_info_p,
2208 struct dwarf_section * section,
2209 struct cu_tu_set * this_set)
2212 printf (" %-18s:", get_AT_name (attribute));
2213 data = read_and_display_attr_value (attribute, form, data, end,
2214 cu_offset, pointer_size, offset_size,
2215 dwarf_version, debug_info_p,
2216 do_loc, section, this_set);
2222 /* Process the contents of a .debug_info section. If do_loc is non-zero
2223 then we are scanning for location lists and we do not want to display
2224 anything to the user. If do_types is non-zero, we are processing
2225 a .debug_types section instead of a .debug_info section. */
2228 process_debug_info (struct dwarf_section *section,
2230 enum dwarf_section_display_enum abbrev_sec,
2234 unsigned char *start = section->start;
2235 unsigned char *end = start + section->size;
2236 unsigned char *section_begin;
2238 unsigned int num_units = 0;
2240 if ((do_loc || do_debug_loc || do_debug_ranges)
2241 && num_debug_info_entries == 0
2246 /* First scan the section to get the number of comp units. */
2247 for (section_begin = start, num_units = 0; section_begin < end;
2250 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2251 will be the length. For a 64-bit DWARF section, it'll be
2252 the escape code 0xffffffff followed by an 8 byte length. */
2253 SAFE_BYTE_GET (length, section_begin, 4, end);
2255 if (length == 0xffffffff)
2257 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2258 section_begin += length + 12;
2260 else if (length >= 0xfffffff0 && length < 0xffffffff)
2262 warn (_("Reserved length value (0x%s) found in section %s\n"),
2263 dwarf_vmatoa ("x", length), section->name);
2267 section_begin += length + 4;
2269 /* Negative values are illegal, they may even cause infinite
2270 looping. This can happen if we can't accurately apply
2271 relocations to an object file, or if the file is corrupt. */
2272 if ((signed long) length <= 0 || section_begin < start)
2274 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2275 dwarf_vmatoa ("x", length), section->name);
2282 error (_("No comp units in %s section ?\n"), section->name);
2286 /* Then allocate an array to hold the information. */
2287 debug_information = (debug_info *) cmalloc (num_units,
2288 sizeof (* debug_information));
2289 if (debug_information == NULL)
2291 error (_("Not enough memory for a debug info array of %u entries\n"),
2293 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2296 alloc_num_debug_info_entries = num_units;
2301 if (dwarf_start_die == 0)
2302 printf (_("Contents of the %s section:\n\n"), section->name);
2304 load_debug_section (str, file);
2305 load_debug_section (str_dwo, file);
2306 load_debug_section (str_index, file);
2307 load_debug_section (str_index_dwo, file);
2308 load_debug_section (debug_addr, file);
2311 load_debug_section (abbrev_sec, file);
2312 if (debug_displays [abbrev_sec].section.start == NULL)
2314 warn (_("Unable to locate %s section!\n"),
2315 debug_displays [abbrev_sec].section.name);
2319 for (section_begin = start, unit = 0; start < end; unit++)
2321 DWARF2_Internal_CompUnit compunit;
2322 unsigned char *hdrptr;
2323 unsigned char *tags;
2324 int level, last_level, saved_level;
2325 dwarf_vma cu_offset;
2326 unsigned int offset_size;
2327 int initial_length_size;
2328 dwarf_vma signature_high = 0;
2329 dwarf_vma signature_low = 0;
2330 dwarf_vma type_offset = 0;
2331 struct cu_tu_set *this_set;
2332 dwarf_vma abbrev_base;
2337 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2339 if (compunit.cu_length == 0xffffffff)
2341 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2343 initial_length_size = 12;
2348 initial_length_size = 4;
2351 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2353 cu_offset = start - section_begin;
2355 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2357 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2359 if (this_set == NULL)
2362 abbrev_size = debug_displays [abbrev_sec].section.size;
2366 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2367 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2370 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2371 /* PR 17512: file: 001-108546-0.001:0.1. */
2372 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2374 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2375 compunit.cu_pointer_size, offset_size);
2376 compunit.cu_pointer_size = offset_size;
2381 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2383 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2386 if ((do_loc || do_debug_loc || do_debug_ranges)
2387 && num_debug_info_entries == 0
2390 debug_information [unit].cu_offset = cu_offset;
2391 debug_information [unit].pointer_size
2392 = compunit.cu_pointer_size;
2393 debug_information [unit].offset_size = offset_size;
2394 debug_information [unit].dwarf_version = compunit.cu_version;
2395 debug_information [unit].base_address = 0;
2396 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2397 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2398 debug_information [unit].loc_offsets = NULL;
2399 debug_information [unit].have_frame_base = NULL;
2400 debug_information [unit].max_loc_offsets = 0;
2401 debug_information [unit].num_loc_offsets = 0;
2402 debug_information [unit].range_lists = NULL;
2403 debug_information [unit].max_range_lists= 0;
2404 debug_information [unit].num_range_lists = 0;
2407 if (!do_loc && dwarf_start_die == 0)
2409 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2410 dwarf_vmatoa ("x", cu_offset));
2411 printf (_(" Length: 0x%s (%s)\n"),
2412 dwarf_vmatoa ("x", compunit.cu_length),
2413 offset_size == 8 ? "64-bit" : "32-bit");
2414 printf (_(" Version: %d\n"), compunit.cu_version);
2415 printf (_(" Abbrev Offset: 0x%s\n"),
2416 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2417 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2422 printf (_(" Signature: 0x%s\n"),
2423 dwarf_vmatoa64 (signature_high, signature_low,
2424 buf, sizeof (buf)));
2425 printf (_(" Type Offset: 0x%s\n"),
2426 dwarf_vmatoa ("x", type_offset));
2428 if (this_set != NULL)
2430 dwarf_vma *offsets = this_set->section_offsets;
2431 size_t *sizes = this_set->section_sizes;
2433 printf (_(" Section contributions:\n"));
2434 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2435 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2436 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2437 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2438 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2439 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2440 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2441 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2442 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2443 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2444 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2445 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2449 if (cu_offset + compunit.cu_length + initial_length_size
2452 warn (_("Debug info is corrupted, length of CU at %s"
2453 " extends beyond end of section (length = %s)\n"),
2454 dwarf_vmatoa ("x", cu_offset),
2455 dwarf_vmatoa ("x", compunit.cu_length));
2460 start += compunit.cu_length + initial_length_size;
2464 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2465 dwarf_vmatoa ("x", cu_offset));
2469 if (compunit.cu_version != 2
2470 && compunit.cu_version != 3
2471 && compunit.cu_version != 4)
2473 warn (_("CU at offset %s contains corrupt or "
2474 "unsupported version number: %d.\n"),
2475 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2481 /* Process the abbrevs used by this compilation unit. */
2482 if (compunit.cu_abbrev_offset >= abbrev_size)
2483 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2484 (unsigned long) compunit.cu_abbrev_offset,
2485 (unsigned long) abbrev_size);
2486 /* PR 17531: file:4bcd9ce9. */
2487 else if ((abbrev_base + abbrev_size)
2488 > debug_displays [abbrev_sec].section.size)
2489 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2490 (unsigned long) abbrev_base + abbrev_size,
2491 (unsigned long) debug_displays [abbrev_sec].section.size);
2493 process_abbrev_section
2494 (((unsigned char *) debug_displays [abbrev_sec].section.start
2495 + abbrev_base + compunit.cu_abbrev_offset),
2496 ((unsigned char *) debug_displays [abbrev_sec].section.start
2497 + abbrev_base + abbrev_size));
2502 while (tags < start)
2504 unsigned int bytes_read;
2505 unsigned long abbrev_number;
2506 unsigned long die_offset;
2507 abbrev_entry *entry;
2509 int do_printing = 1;
2511 die_offset = tags - section_begin;
2513 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2516 /* A null DIE marks the end of a list of siblings or it may also be
2517 a section padding. */
2518 if (abbrev_number == 0)
2520 /* Check if it can be a section padding for the last CU. */
2521 if (level == 0 && start == end)
2525 for (chk = tags; chk < start; chk++)
2532 if (!do_loc && die_offset >= dwarf_start_die
2533 && (dwarf_cutoff_level == -1
2534 || level < dwarf_cutoff_level))
2535 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2541 static unsigned num_bogus_warns = 0;
2543 if (num_bogus_warns < 3)
2545 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2546 die_offset, section->name);
2548 if (num_bogus_warns == 3)
2549 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2552 if (dwarf_start_die != 0 && level < saved_level)
2559 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2563 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2564 saved_level = level;
2565 do_printing = (dwarf_cutoff_level == -1
2566 || level < dwarf_cutoff_level);
2568 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2569 level, die_offset, abbrev_number);
2570 else if (dwarf_cutoff_level == -1
2571 || last_level < dwarf_cutoff_level)
2572 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2577 /* Scan through the abbreviation list until we reach the
2579 for (entry = first_abbrev;
2580 entry && entry->entry != abbrev_number;
2581 entry = entry->next)
2586 if (!do_loc && do_printing)
2591 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2592 die_offset, abbrev_number);
2596 if (!do_loc && do_printing)
2597 printf (" (%s)\n", get_TAG_name (entry->tag));
2602 need_base_address = 0;
2604 case DW_TAG_compile_unit:
2605 need_base_address = 1;
2607 case DW_TAG_entry_point:
2608 case DW_TAG_subprogram:
2609 need_base_address = 0;
2610 /* Assuming that there is no DW_AT_frame_base. */
2611 have_frame_base = 0;
2615 for (attr = entry->first_attr;
2616 attr && attr->attribute;
2621 if (! do_loc && do_printing)
2622 /* Show the offset from where the tag was extracted. */
2623 printf (" <%lx>", (unsigned long)(tags - section_begin));
2625 if (debug_information && unit < alloc_num_debug_info_entries)
2626 arg = debug_information + unit;
2630 tags = read_and_display_attr (attr->attribute,
2635 compunit.cu_pointer_size,
2637 compunit.cu_version,
2639 do_loc || ! do_printing,
2644 if (entry->children)
2649 /* Set num_debug_info_entries here so that it can be used to check if
2650 we need to process .debug_loc and .debug_ranges sections. */
2651 if ((do_loc || do_debug_loc || do_debug_ranges)
2652 && num_debug_info_entries == 0
2655 if (num_units > alloc_num_debug_info_entries)
2656 num_debug_info_entries = alloc_num_debug_info_entries;
2658 num_debug_info_entries = num_units;
2667 /* Locate and scan the .debug_info section in the file and record the pointer
2668 sizes and offsets for the compilation units in it. Usually an executable
2669 will have just one pointer size, but this is not guaranteed, and so we try
2670 not to make any assumptions. Returns zero upon failure, or the number of
2671 compilation units upon success. */
2674 load_debug_info (void * file)
2676 /* Reset the last pointer size so that we can issue correct error
2677 messages if we are displaying the contents of more than one section. */
2678 last_pointer_size = 0;
2679 warned_about_missing_comp_units = FALSE;
2681 /* If we have already tried and failed to load the .debug_info
2682 section then do not bother to repeat the task. */
2683 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2686 /* If we already have the information there is nothing else to do. */
2687 if (num_debug_info_entries > 0)
2688 return num_debug_info_entries;
2690 /* If this is a DWARF package file, load the CU and TU indexes. */
2691 load_cu_tu_indexes (file);
2693 if (load_debug_section (info, file)
2694 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2695 return num_debug_info_entries;
2697 if (load_debug_section (info_dwo, file)
2698 && process_debug_info (&debug_displays [info_dwo].section, file,
2700 return num_debug_info_entries;
2702 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2706 /* Read a DWARF .debug_line section header starting at DATA.
2707 Upon success returns an updated DATA pointer and the LINFO
2708 structure and the END_OF_SEQUENCE pointer will be filled in.
2709 Otherwise returns NULL. */
2711 static unsigned char *
2712 read_debug_line_header (struct dwarf_section * section,
2713 unsigned char * data,
2714 unsigned char * end,
2715 DWARF2_Internal_LineInfo * linfo,
2716 unsigned char ** end_of_sequence)
2718 unsigned char *hdrptr;
2719 unsigned int offset_size;
2720 unsigned int initial_length_size;
2722 /* Extract information from the Line Number Program Header.
2723 (section 6.2.4 in the Dwarf3 doc). */
2726 /* Get and check the length of the block. */
2727 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2729 if (linfo->li_length == 0xffffffff)
2731 /* This section is 64-bit DWARF 3. */
2732 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2734 initial_length_size = 12;
2739 initial_length_size = 4;
2742 if (linfo->li_length + initial_length_size > section->size)
2744 /* If the length is just a bias against the initial_length_size then
2745 this means that the field has a relocation against it which has not
2746 been applied. (Ie we are dealing with an object file, not a linked
2747 binary). Do not complain but instead assume that the rest of the
2748 section applies to this particular header. */
2749 if (linfo->li_length == - initial_length_size)
2751 linfo->li_length = section->size - initial_length_size;
2755 warn (_("The line info appears to be corrupt - the section is too small\n"));
2760 /* Get and check the version number. */
2761 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2763 if (linfo->li_version != 2
2764 && linfo->li_version != 3
2765 && linfo->li_version != 4)
2767 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2771 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2772 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2774 if (linfo->li_version >= 4)
2776 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2778 if (linfo->li_max_ops_per_insn == 0)
2780 warn (_("Invalid maximum operations per insn.\n"));
2785 linfo->li_max_ops_per_insn = 1;
2787 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2788 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2789 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2790 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2792 * end_of_sequence = data + linfo->li_length + initial_length_size;
2793 /* PR 17512: file:002-117414-0.004. */
2794 if (* end_of_sequence > end)
2796 warn (_("Line length %s extends beyond end of section\n"),
2797 dwarf_vmatoa ("u", linfo->li_length));
2798 * end_of_sequence = end;
2806 display_debug_lines_raw (struct dwarf_section *section,
2807 unsigned char *data,
2810 unsigned char *start = section->start;
2812 printf (_("Raw dump of debug contents of section %s:\n\n"),
2817 static DWARF2_Internal_LineInfo saved_linfo;
2818 DWARF2_Internal_LineInfo linfo;
2819 unsigned char *standard_opcodes;
2820 unsigned char *end_of_sequence;
2821 unsigned int last_dir_entry = 0;
2824 if (const_strneq (section->name, ".debug_line.")
2825 /* Note: the following does not apply to .debug_line.dwo sections.
2826 These are full debug_line sections. */
2827 && strcmp (section->name, ".debug_line.dwo") != 0)
2829 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2830 section containing just the Line Number Statements. They are
2831 created by the assembler and intended to be used alongside gcc's
2832 -ffunction-sections command line option. When the linker's
2833 garbage collection decides to discard a .text.<foo> section it
2834 can then also discard the line number information in .debug_line.<foo>.
2836 Since the section is a fragment it does not have the details
2837 needed to fill out a LineInfo structure, so instead we use the
2838 details from the last full debug_line section that we processed. */
2839 end_of_sequence = end;
2840 standard_opcodes = NULL;
2841 linfo = saved_linfo;
2842 /* PR 17531: file: 0522b371. */
2843 if (linfo.li_line_range == 0)
2845 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
2848 reset_state_machine (linfo.li_default_is_stmt);
2852 unsigned char * hdrptr;
2854 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2855 & end_of_sequence)) == NULL)
2858 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2859 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2860 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2861 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2862 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2863 if (linfo.li_version >= 4)
2864 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2865 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2866 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2867 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2868 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2870 /* PR 17512: file: 1665-6428-0.004. */
2871 if (linfo.li_line_range == 0)
2873 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2874 linfo.li_line_range = 1;
2877 reset_state_machine (linfo.li_default_is_stmt);
2879 /* Display the contents of the Opcodes table. */
2880 standard_opcodes = hdrptr;
2882 /* PR 17512: file: 002-417945-0.004. */
2883 if (standard_opcodes + linfo.li_opcode_base >= end)
2885 warn (_("Line Base extends beyond end of section\n"));
2889 printf (_("\n Opcodes:\n"));
2891 for (i = 1; i < linfo.li_opcode_base; i++)
2892 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2894 /* Display the contents of the Directory table. */
2895 data = standard_opcodes + linfo.li_opcode_base - 1;
2898 printf (_("\n The Directory Table is empty.\n"));
2901 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2902 (long)(data - start));
2904 while (data < end && *data != 0)
2906 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
2908 data += strnlen ((char *) data, end - data) + 1;
2911 /* PR 17512: file: 002-132094-0.004. */
2912 if (data >= end - 1)
2916 /* Skip the NUL at the end of the table. */
2919 /* Display the contents of the File Name table. */
2921 printf (_("\n The File Name Table is empty.\n"));
2924 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2925 (long)(data - start));
2926 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2928 while (data < end && *data != 0)
2930 unsigned char *name;
2931 unsigned int bytes_read;
2933 printf (" %d\t", ++state_machine_regs.last_file_entry);
2935 data += strnlen ((char *) data, end - data) + 1;
2938 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2941 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2944 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2946 printf ("%.*s\n", (int)(end - name), name);
2950 warn (_("Corrupt file name table entry\n"));
2956 /* Skip the NUL at the end of the table. */
2959 saved_linfo = linfo;
2962 /* Now display the statements. */
2963 if (data >= end_of_sequence)
2964 printf (_(" No Line Number Statements.\n"));
2967 printf (_(" Line Number Statements:\n"));
2969 while (data < end_of_sequence)
2971 unsigned char op_code;
2972 dwarf_signed_vma adv;
2974 unsigned int bytes_read;
2976 printf (" [0x%08lx]", (long)(data - start));
2980 if (op_code >= linfo.li_opcode_base)
2982 op_code -= linfo.li_opcode_base;
2983 uladv = (op_code / linfo.li_line_range);
2984 if (linfo.li_max_ops_per_insn == 1)
2986 uladv *= linfo.li_min_insn_length;
2987 state_machine_regs.address += uladv;
2988 printf (_(" Special opcode %d: "
2989 "advance Address by %s to 0x%s"),
2990 op_code, dwarf_vmatoa ("u", uladv),
2991 dwarf_vmatoa ("x", state_machine_regs.address));
2995 state_machine_regs.address
2996 += ((state_machine_regs.op_index + uladv)
2997 / linfo.li_max_ops_per_insn)
2998 * linfo.li_min_insn_length;
2999 state_machine_regs.op_index
3000 = (state_machine_regs.op_index + uladv)
3001 % linfo.li_max_ops_per_insn;
3002 printf (_(" Special opcode %d: "
3003 "advance Address by %s to 0x%s[%d]"),
3004 op_code, dwarf_vmatoa ("u", uladv),
3005 dwarf_vmatoa ("x", state_machine_regs.address),
3006 state_machine_regs.op_index);
3008 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3009 state_machine_regs.line += adv;
3010 printf (_(" and Line by %s to %d\n"),
3011 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3013 else switch (op_code)
3015 case DW_LNS_extended_op:
3016 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3020 printf (_(" Copy\n"));
3023 case DW_LNS_advance_pc:
3024 uladv = read_uleb128 (data, & bytes_read, end);
3026 if (linfo.li_max_ops_per_insn == 1)
3028 uladv *= linfo.li_min_insn_length;
3029 state_machine_regs.address += uladv;
3030 printf (_(" Advance PC by %s to 0x%s\n"),
3031 dwarf_vmatoa ("u", uladv),
3032 dwarf_vmatoa ("x", state_machine_regs.address));
3036 state_machine_regs.address
3037 += ((state_machine_regs.op_index + uladv)
3038 / linfo.li_max_ops_per_insn)
3039 * linfo.li_min_insn_length;
3040 state_machine_regs.op_index
3041 = (state_machine_regs.op_index + uladv)
3042 % linfo.li_max_ops_per_insn;
3043 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3044 dwarf_vmatoa ("u", uladv),
3045 dwarf_vmatoa ("x", state_machine_regs.address),
3046 state_machine_regs.op_index);
3050 case DW_LNS_advance_line:
3051 adv = read_sleb128 (data, & bytes_read, end);
3053 state_machine_regs.line += adv;
3054 printf (_(" Advance Line by %s to %d\n"),
3055 dwarf_vmatoa ("d", adv),
3056 state_machine_regs.line);
3059 case DW_LNS_set_file:
3060 adv = read_uleb128 (data, & bytes_read, end);
3062 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3063 dwarf_vmatoa ("d", adv));
3064 state_machine_regs.file = adv;
3067 case DW_LNS_set_column:
3068 uladv = read_uleb128 (data, & bytes_read, end);
3070 printf (_(" Set column to %s\n"),
3071 dwarf_vmatoa ("u", uladv));
3072 state_machine_regs.column = uladv;
3075 case DW_LNS_negate_stmt:
3076 adv = state_machine_regs.is_stmt;
3078 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3079 state_machine_regs.is_stmt = adv;
3082 case DW_LNS_set_basic_block:
3083 printf (_(" Set basic block\n"));
3084 state_machine_regs.basic_block = 1;
3087 case DW_LNS_const_add_pc:
3088 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3089 if (linfo.li_max_ops_per_insn)
3091 uladv *= linfo.li_min_insn_length;
3092 state_machine_regs.address += uladv;
3093 printf (_(" Advance PC by constant %s to 0x%s\n"),
3094 dwarf_vmatoa ("u", uladv),
3095 dwarf_vmatoa ("x", state_machine_regs.address));
3099 state_machine_regs.address
3100 += ((state_machine_regs.op_index + uladv)
3101 / linfo.li_max_ops_per_insn)
3102 * linfo.li_min_insn_length;
3103 state_machine_regs.op_index
3104 = (state_machine_regs.op_index + uladv)
3105 % linfo.li_max_ops_per_insn;
3106 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3107 dwarf_vmatoa ("u", uladv),
3108 dwarf_vmatoa ("x", state_machine_regs.address),
3109 state_machine_regs.op_index);
3113 case DW_LNS_fixed_advance_pc:
3114 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3115 state_machine_regs.address += uladv;
3116 state_machine_regs.op_index = 0;
3117 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3118 dwarf_vmatoa ("u", uladv),
3119 dwarf_vmatoa ("x", state_machine_regs.address));
3122 case DW_LNS_set_prologue_end:
3123 printf (_(" Set prologue_end to true\n"));
3126 case DW_LNS_set_epilogue_begin:
3127 printf (_(" Set epilogue_begin to true\n"));
3130 case DW_LNS_set_isa:
3131 uladv = read_uleb128 (data, & bytes_read, end);
3133 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3137 printf (_(" Unknown opcode %d with operands: "), op_code);
3139 if (standard_opcodes != NULL)
3140 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3142 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3144 i == 1 ? "" : ", ");
3160 unsigned char *name;
3161 unsigned int directory_index;
3162 unsigned int modification_date;
3163 unsigned int length;
3166 /* Output a decoded representation of the .debug_line section. */
3169 display_debug_lines_decoded (struct dwarf_section *section,
3170 unsigned char *data,
3173 static DWARF2_Internal_LineInfo saved_linfo;
3175 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3180 /* This loop amounts to one iteration per compilation unit. */
3181 DWARF2_Internal_LineInfo linfo;
3182 unsigned char *standard_opcodes;
3183 unsigned char *end_of_sequence;
3185 File_Entry *file_table = NULL;
3186 unsigned int n_files = 0;
3187 unsigned char **directory_table = NULL;
3188 unsigned int n_directories = 0;
3190 if (const_strneq (section->name, ".debug_line.")
3191 /* Note: the following does not apply to .debug_line.dwo sections.
3192 These are full debug_line sections. */
3193 && strcmp (section->name, ".debug_line.dwo") != 0)
3195 /* See comment in display_debug_lines_raw(). */
3196 end_of_sequence = end;
3197 standard_opcodes = NULL;
3198 linfo = saved_linfo;
3199 /* PR 17531: file: 0522b371. */
3200 if (linfo.li_line_range == 0)
3202 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3205 reset_state_machine (linfo.li_default_is_stmt);
3209 unsigned char *hdrptr;
3211 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3212 & end_of_sequence)) == NULL)
3215 /* PR 17531: file: 0522b371. */
3216 if (linfo.li_line_range == 0)
3218 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3219 linfo.li_line_range = 1;
3221 reset_state_machine (linfo.li_default_is_stmt);
3223 /* Save a pointer to the contents of the Opcodes table. */
3224 standard_opcodes = hdrptr;
3226 /* Traverse the Directory table just to count entries. */
3227 data = standard_opcodes + linfo.li_opcode_base - 1;
3230 unsigned char *ptr_directory_table = data;
3234 data += strnlen ((char *) data, end - data) + 1;
3238 /* Go through the directory table again to save the directories. */
3239 directory_table = (unsigned char **)
3240 xmalloc (n_directories * sizeof (unsigned char *));
3243 while (*ptr_directory_table != 0)
3245 directory_table[i] = ptr_directory_table;
3246 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3247 ptr_directory_table - end) + 1;
3251 /* Skip the NUL at the end of the table. */
3254 /* Traverse the File Name table just to count the entries. */
3257 unsigned char *ptr_file_name_table = data;
3261 unsigned int bytes_read;
3263 /* Skip Name, directory index, last modification time and length
3265 data += strnlen ((char *) data, end - data) + 1;
3266 read_uleb128 (data, & bytes_read, end);
3268 read_uleb128 (data, & bytes_read, end);
3270 read_uleb128 (data, & bytes_read, end);
3276 /* Go through the file table again to save the strings. */
3277 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3280 while (*ptr_file_name_table != 0)
3282 unsigned int bytes_read;
3284 file_table[i].name = ptr_file_name_table;
3285 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3286 end - ptr_file_name_table) + 1;
3288 /* We are not interested in directory, time or size. */
3289 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3291 ptr_file_name_table += bytes_read;
3292 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3294 ptr_file_name_table += bytes_read;
3295 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3296 ptr_file_name_table += bytes_read;
3301 /* Print the Compilation Unit's name and a header. */
3302 if (directory_table == NULL)
3304 printf (_("CU: %s:\n"), file_table[0].name);
3305 printf (_("File name Line number Starting address\n"));
3309 unsigned int ix = file_table[0].directory_index;
3310 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
3312 if (do_wide || strlen (directory) < 76)
3313 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3315 printf ("%s:\n", file_table[0].name);
3317 printf (_("File name Line number Starting address\n"));
3321 /* Skip the NUL at the end of the table. */
3324 saved_linfo = linfo;
3327 /* This loop iterates through the Dwarf Line Number Program. */
3328 while (data < end_of_sequence)
3330 unsigned char op_code;
3332 unsigned long int uladv;
3333 unsigned int bytes_read;
3334 int is_special_opcode = 0;
3338 if (op_code >= linfo.li_opcode_base)
3340 op_code -= linfo.li_opcode_base;
3341 uladv = (op_code / linfo.li_line_range);
3342 if (linfo.li_max_ops_per_insn == 1)
3344 uladv *= linfo.li_min_insn_length;
3345 state_machine_regs.address += uladv;
3349 state_machine_regs.address
3350 += ((state_machine_regs.op_index + uladv)
3351 / linfo.li_max_ops_per_insn)
3352 * linfo.li_min_insn_length;
3353 state_machine_regs.op_index
3354 = (state_machine_regs.op_index + uladv)
3355 % linfo.li_max_ops_per_insn;
3358 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3359 state_machine_regs.line += adv;
3360 is_special_opcode = 1;
3362 else switch (op_code)
3364 case DW_LNS_extended_op:
3366 unsigned int ext_op_code_len;
3367 unsigned char ext_op_code;
3368 unsigned char *op_code_data = data;
3370 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3372 op_code_data += bytes_read;
3374 if (ext_op_code_len == 0)
3376 warn (_("Badly formed extended line op encountered!\n"));
3379 ext_op_code_len += bytes_read;
3380 ext_op_code = *op_code_data++;
3382 switch (ext_op_code)
3384 case DW_LNE_end_sequence:
3385 reset_state_machine (linfo.li_default_is_stmt);
3387 case DW_LNE_set_address:
3388 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3390 ext_op_code_len - bytes_read - 1,
3392 state_machine_regs.op_index = 0;
3394 case DW_LNE_define_file:
3396 file_table = (File_Entry *) xrealloc
3397 (file_table, (n_files + 1) * sizeof (File_Entry));
3399 ++state_machine_regs.last_file_entry;
3400 /* Source file name. */
3401 file_table[n_files].name = op_code_data;
3402 op_code_data += strlen ((char *) op_code_data) + 1;
3403 /* Directory index. */
3404 file_table[n_files].directory_index =
3405 read_uleb128 (op_code_data, & bytes_read,
3407 op_code_data += bytes_read;
3408 /* Last modification time. */
3409 file_table[n_files].modification_date =
3410 read_uleb128 (op_code_data, & bytes_read,
3412 op_code_data += bytes_read;
3414 file_table[n_files].length =
3415 read_uleb128 (op_code_data, & bytes_read,
3421 case DW_LNE_set_discriminator:
3422 case DW_LNE_HP_set_sequence:
3423 /* Simply ignored. */
3427 printf (_("UNKNOWN (%u): length %d\n"),
3428 ext_op_code, ext_op_code_len - bytes_read);
3431 data += ext_op_code_len;
3437 case DW_LNS_advance_pc:
3438 uladv = read_uleb128 (data, & bytes_read, end);
3440 if (linfo.li_max_ops_per_insn == 1)
3442 uladv *= linfo.li_min_insn_length;
3443 state_machine_regs.address += uladv;
3447 state_machine_regs.address
3448 += ((state_machine_regs.op_index + uladv)
3449 / linfo.li_max_ops_per_insn)
3450 * linfo.li_min_insn_length;
3451 state_machine_regs.op_index
3452 = (state_machine_regs.op_index + uladv)
3453 % linfo.li_max_ops_per_insn;
3457 case DW_LNS_advance_line:
3458 adv = read_sleb128 (data, & bytes_read, end);
3460 state_machine_regs.line += adv;
3463 case DW_LNS_set_file:
3464 adv = read_uleb128 (data, & bytes_read, end);
3466 state_machine_regs.file = adv;
3468 if (file_table == NULL)
3469 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
3470 else if (file_table[state_machine_regs.file - 1].directory_index == 0)
3471 /* If directory index is 0, that means current directory. */
3472 printf ("\n./%s:[++]\n",
3473 file_table[state_machine_regs.file - 1].name);
3474 else if (directory_table == NULL)
3475 printf (_("\n [Use directory table entry %d]\n"),
3476 file_table[state_machine_regs.file - 1].directory_index - 1);
3478 /* The directory index starts counting at 1. */
3479 printf ("\n%s/%s:\n",
3480 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3481 file_table[state_machine_regs.file - 1].name);
3484 case DW_LNS_set_column:
3485 uladv = read_uleb128 (data, & bytes_read, end);
3487 state_machine_regs.column = uladv;
3490 case DW_LNS_negate_stmt:
3491 adv = state_machine_regs.is_stmt;
3493 state_machine_regs.is_stmt = adv;
3496 case DW_LNS_set_basic_block:
3497 state_machine_regs.basic_block = 1;
3500 case DW_LNS_const_add_pc:
3501 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3502 if (linfo.li_max_ops_per_insn == 1)
3504 uladv *= linfo.li_min_insn_length;
3505 state_machine_regs.address += uladv;
3509 state_machine_regs.address
3510 += ((state_machine_regs.op_index + uladv)
3511 / linfo.li_max_ops_per_insn)
3512 * linfo.li_min_insn_length;
3513 state_machine_regs.op_index
3514 = (state_machine_regs.op_index + uladv)
3515 % linfo.li_max_ops_per_insn;
3519 case DW_LNS_fixed_advance_pc:
3520 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3521 state_machine_regs.address += uladv;
3522 state_machine_regs.op_index = 0;
3525 case DW_LNS_set_prologue_end:
3528 case DW_LNS_set_epilogue_begin:
3531 case DW_LNS_set_isa:
3532 uladv = read_uleb128 (data, & bytes_read, end);
3534 printf (_(" Set ISA to %lu\n"), uladv);
3538 printf (_(" Unknown opcode %d with operands: "), op_code);
3540 if (standard_opcodes != NULL)
3541 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3543 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3545 i == 1 ? "" : ", ");
3552 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3553 to the DWARF address/line matrix. */
3554 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3555 || (op_code == DW_LNS_copy))
3557 const unsigned int MAX_FILENAME_LENGTH = 35;
3559 char *newFileName = NULL;
3560 size_t fileNameLength;
3563 fileName = (char *) file_table[state_machine_regs.file - 1].name;
3565 fileName = "<unknown>";
3567 fileNameLength = strlen (fileName);
3569 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3571 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3572 /* Truncate file name */
3573 strncpy (newFileName,
3574 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3575 MAX_FILENAME_LENGTH + 1);
3579 newFileName = (char *) xmalloc (fileNameLength + 1);
3580 strncpy (newFileName, fileName, fileNameLength + 1);
3583 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3585 if (linfo.li_max_ops_per_insn == 1)
3586 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3587 newFileName, state_machine_regs.line,
3588 state_machine_regs.address);
3590 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3591 newFileName, state_machine_regs.line,
3592 state_machine_regs.address,
3593 state_machine_regs.op_index);
3597 if (linfo.li_max_ops_per_insn == 1)
3598 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3599 newFileName, state_machine_regs.line,
3600 state_machine_regs.address);
3602 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3603 newFileName, state_machine_regs.line,
3604 state_machine_regs.address,
3605 state_machine_regs.op_index);
3608 if (op_code == DW_LNE_end_sequence)
3622 if (directory_table)
3624 free (directory_table);
3625 directory_table = NULL;
3636 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3638 unsigned char *data = section->start;
3639 unsigned char *end = data + section->size;
3641 int retValDecoded = 1;
3643 if (do_debug_lines == 0)
3644 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3646 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3647 retValRaw = display_debug_lines_raw (section, data, end);
3649 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3650 retValDecoded = display_debug_lines_decoded (section, data, end);
3652 if (!retValRaw || !retValDecoded)
3659 find_debug_info_for_offset (unsigned long offset)
3663 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3666 for (i = 0; i < num_debug_info_entries; i++)
3667 if (debug_information[i].cu_offset == offset)
3668 return debug_information + i;
3674 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3676 /* See gdb/gdb-index.h. */
3677 static const char * const kinds[] =
3689 return _ (kinds[kind]);
3693 display_debug_pubnames_worker (struct dwarf_section *section,
3694 void *file ATTRIBUTE_UNUSED,
3697 DWARF2_Internal_PubNames names;
3698 unsigned char *start = section->start;
3699 unsigned char *end = start + section->size;
3701 /* It does not matter if this load fails,
3702 we test for that later on. */
3703 load_debug_info (file);
3705 printf (_("Contents of the %s section:\n\n"), section->name);
3709 unsigned char *data;
3710 unsigned long offset;
3711 unsigned int offset_size, initial_length_size;
3715 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3716 if (names.pn_length == 0xffffffff)
3718 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3720 initial_length_size = 12;
3725 initial_length_size = 4;
3728 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3729 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3731 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3732 && num_debug_info_entries > 0
3733 && find_debug_info_for_offset (names.pn_offset) == NULL)
3734 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3735 (unsigned long) names.pn_offset, section->name);
3737 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3739 /* PR 17531: file: 7615b6b2. */
3740 if ((dwarf_signed_vma) names.pn_length < 0
3741 /* PR 17531: file: a5dbeaa7. */
3742 || start + names.pn_length + initial_length_size < start)
3744 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
3748 start += names.pn_length + initial_length_size;
3750 printf (_(" Length: %ld\n"),
3751 (long) names.pn_length);
3752 printf (_(" Version: %d\n"),
3754 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3755 (unsigned long) names.pn_offset);
3756 printf (_(" Size of area in .debug_info section: %ld\n"),
3757 (long) names.pn_size);
3759 if (names.pn_version != 2 && names.pn_version != 3)
3761 static int warned = 0;
3765 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3773 printf (_("\n Offset Kind Name\n"));
3775 printf (_("\n Offset\tName\n"));
3779 bfd_size_type maxprint;
3781 SAFE_BYTE_GET (offset, data, offset_size, end);
3785 data += offset_size;
3788 maxprint = (end - data) - 1;
3792 unsigned int kind_data;
3793 gdb_index_symbol_kind kind;
3794 const char *kind_name;
3797 SAFE_BYTE_GET (kind_data, data, 1, end);
3800 /* GCC computes the kind as the upper byte in the CU index
3801 word, and then right shifts it by the CU index size.
3802 Left shift KIND to where the gdb-index.h accessor macros
3804 kind_data <<= GDB_INDEX_CU_BITSIZE;
3805 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3806 kind_name = get_gdb_index_symbol_kind_name (kind);
3807 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3808 printf (" %-6lx %s,%-10s %.*s\n",
3809 offset, is_static ? _("s") : _("g"),
3810 kind_name, (int) maxprint, data);
3813 printf (" %-6lx\t%.*s\n", offset, (int) maxprint, data);
3815 data += strnlen ((char *) data, maxprint) + 1;
3820 while (offset != 0);
3828 display_debug_pubnames (struct dwarf_section *section, void *file)
3830 return display_debug_pubnames_worker (section, file, 0);
3834 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3836 return display_debug_pubnames_worker (section, file, 1);
3840 display_debug_macinfo (struct dwarf_section *section,
3841 void *file ATTRIBUTE_UNUSED)
3843 unsigned char *start = section->start;
3844 unsigned char *end = start + section->size;
3845 unsigned char *curr = start;
3846 unsigned int bytes_read;
3847 enum dwarf_macinfo_record_type op;
3849 printf (_("Contents of the %s section:\n\n"), section->name);
3853 unsigned int lineno;
3854 const unsigned char *string;
3856 op = (enum dwarf_macinfo_record_type) *curr;
3861 case DW_MACINFO_start_file:
3863 unsigned int filenum;
3865 lineno = read_uleb128 (curr, & bytes_read, end);
3867 filenum = read_uleb128 (curr, & bytes_read, end);
3870 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3875 case DW_MACINFO_end_file:
3876 printf (_(" DW_MACINFO_end_file\n"));
3879 case DW_MACINFO_define:
3880 lineno = read_uleb128 (curr, & bytes_read, end);
3883 curr += strnlen ((char *) string, end - string) + 1;
3884 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3888 case DW_MACINFO_undef:
3889 lineno = read_uleb128 (curr, & bytes_read, end);
3892 curr += strnlen ((char *) string, end - string) + 1;
3893 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3897 case DW_MACINFO_vendor_ext:
3899 unsigned int constant;
3901 constant = read_uleb128 (curr, & bytes_read, end);
3904 curr += strnlen ((char *) string, end - string) + 1;
3905 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3915 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3916 filename and dirname corresponding to file name table entry with index
3917 FILEIDX. Return NULL on failure. */
3919 static unsigned char *
3920 get_line_filename_and_dirname (dwarf_vma line_offset,
3922 unsigned char **dir_name)
3924 struct dwarf_section *section = &debug_displays [line].section;
3925 unsigned char *hdrptr, *dirtable, *file_name;
3926 unsigned int offset_size, initial_length_size;
3927 unsigned int version, opcode_base, bytes_read;
3928 dwarf_vma length, diridx;
3929 const unsigned char * end;
3932 if (section->start == NULL
3933 || line_offset >= section->size
3937 hdrptr = section->start + line_offset;
3938 end = section->start + section->size;
3940 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
3941 if (length == 0xffffffff)
3943 /* This section is 64-bit DWARF 3. */
3944 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
3946 initial_length_size = 12;
3951 initial_length_size = 4;
3953 if (length + initial_length_size > section->size)
3956 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
3957 if (version != 2 && version != 3 && version != 4)
3959 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3961 hdrptr++; /* Skip max_ops_per_insn. */
3962 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3964 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
3965 if (opcode_base == 0)
3968 hdrptr += opcode_base - 1;
3970 /* Skip over dirname table. */
3971 while (*hdrptr != '\0')
3972 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3973 hdrptr++; /* Skip the NUL at the end of the table. */
3974 /* Now skip over preceding filename table entries. */
3975 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3977 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3978 read_uleb128 (hdrptr, &bytes_read, end);
3979 hdrptr += bytes_read;
3980 read_uleb128 (hdrptr, &bytes_read, end);
3981 hdrptr += bytes_read;
3982 read_uleb128 (hdrptr, &bytes_read, end);
3983 hdrptr += bytes_read;
3985 if (hdrptr == end || *hdrptr == '\0')
3988 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3989 diridx = read_uleb128 (hdrptr, &bytes_read, end);
3992 for (; *dirtable != '\0' && diridx > 1; diridx--)
3993 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
3994 if (*dirtable == '\0')
3996 *dir_name = dirtable;
4001 display_debug_macro (struct dwarf_section *section,
4004 unsigned char *start = section->start;
4005 unsigned char *end = start + section->size;
4006 unsigned char *curr = start;
4007 unsigned char *extended_op_buf[256];
4008 unsigned int bytes_read;
4010 load_debug_section (str, file);
4011 load_debug_section (line, file);
4013 printf (_("Contents of the %s section:\n\n"), section->name);
4017 unsigned int lineno, version, flags;
4018 unsigned int offset_size = 4;
4019 const unsigned char *string;
4020 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4021 unsigned char **extended_ops = NULL;
4023 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4026 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4031 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4034 printf (_(" Offset: 0x%lx\n"),
4035 (unsigned long) sec_offset);
4036 printf (_(" Version: %d\n"), version);
4037 printf (_(" Offset size: %d\n"), offset_size);
4040 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4041 printf (_(" Offset into .debug_line: 0x%lx\n"),
4042 (unsigned long) line_offset);
4046 unsigned int i, count, op;
4049 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4051 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4052 extended_ops = extended_op_buf;
4055 printf (_(" Extension opcode arguments:\n"));
4056 for (i = 0; i < count; i++)
4058 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4059 extended_ops[op] = curr;
4060 nargs = read_uleb128 (curr, &bytes_read, end);
4063 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
4066 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
4067 for (n = 0; n < nargs; n++)
4071 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4072 printf ("%s%s", get_FORM_name (form),
4073 n == nargs - 1 ? "\n" : ", ");
4083 case DW_FORM_block1:
4084 case DW_FORM_block2:
4085 case DW_FORM_block4:
4087 case DW_FORM_string:
4089 case DW_FORM_sec_offset:
4092 error (_("Invalid extension opcode form %s\n"),
4093 get_FORM_name (form));
4109 error (_(".debug_macro section not zero terminated\n"));
4113 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4119 case DW_MACRO_GNU_start_file:
4121 unsigned int filenum;
4122 unsigned char *file_name = NULL, *dir_name = NULL;
4124 lineno = read_uleb128 (curr, &bytes_read, end);
4126 filenum = read_uleb128 (curr, &bytes_read, end);
4129 if ((flags & 2) == 0)
4130 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4133 = get_line_filename_and_dirname (line_offset, filenum,
4135 if (file_name == NULL)
4136 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4139 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4141 dir_name != NULL ? (const char *) dir_name : "",
4142 dir_name != NULL ? "/" : "", file_name);
4146 case DW_MACRO_GNU_end_file:
4147 printf (_(" DW_MACRO_GNU_end_file\n"));
4150 case DW_MACRO_GNU_define:
4151 lineno = read_uleb128 (curr, &bytes_read, end);
4154 curr += strnlen ((char *) string, end - string) + 1;
4155 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4159 case DW_MACRO_GNU_undef:
4160 lineno = read_uleb128 (curr, &bytes_read, end);
4163 curr += strnlen ((char *) string, end - string) + 1;
4164 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4168 case DW_MACRO_GNU_define_indirect:
4169 lineno = read_uleb128 (curr, &bytes_read, end);
4171 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4172 string = fetch_indirect_string (offset);
4173 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4177 case DW_MACRO_GNU_undef_indirect:
4178 lineno = read_uleb128 (curr, &bytes_read, end);
4180 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4181 string = fetch_indirect_string (offset);
4182 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4186 case DW_MACRO_GNU_transparent_include:
4187 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4188 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4189 (unsigned long) offset);
4192 case DW_MACRO_GNU_define_indirect_alt:
4193 lineno = read_uleb128 (curr, &bytes_read, end);
4195 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4196 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4197 lineno, (unsigned long) offset);
4200 case DW_MACRO_GNU_undef_indirect_alt:
4201 lineno = read_uleb128 (curr, &bytes_read, end);
4203 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4204 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4205 lineno, (unsigned long) offset);
4208 case DW_MACRO_GNU_transparent_include_alt:
4209 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4210 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4211 (unsigned long) offset);
4215 if (extended_ops == NULL || extended_ops[op] == NULL)
4217 error (_(" Unknown macro opcode %02x seen\n"), op);
4222 /* Skip over unhandled opcodes. */
4224 unsigned char *desc = extended_ops[op];
4225 nargs = read_uleb128 (desc, &bytes_read, end);
4229 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4232 printf (_(" DW_MACRO_GNU_%02x -"), op);
4233 for (n = 0; n < nargs; n++)
4237 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4239 = read_and_display_attr_value (0, val,
4240 curr, end, 0, 0, offset_size,
4241 version, NULL, 0, NULL,
4259 display_debug_abbrev (struct dwarf_section *section,
4260 void *file ATTRIBUTE_UNUSED)
4262 abbrev_entry *entry;
4263 unsigned char *start = section->start;
4264 unsigned char *end = start + section->size;
4266 printf (_("Contents of the %s section:\n\n"), section->name);
4270 unsigned char *last;
4275 start = process_abbrev_section (start, end);
4277 if (first_abbrev == NULL)
4280 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4282 for (entry = first_abbrev; entry; entry = entry->next)
4286 printf (" %ld %s [%s]\n",
4288 get_TAG_name (entry->tag),
4289 entry->children ? _("has children") : _("no children"));
4291 for (attr = entry->first_attr; attr; attr = attr->next)
4292 printf (" %-18s %s\n",
4293 get_AT_name (attr->attribute),
4294 get_FORM_name (attr->form));
4304 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4307 display_loc_list (struct dwarf_section *section,
4308 unsigned char **start_ptr,
4309 unsigned int debug_info_entry,
4310 unsigned long offset,
4311 unsigned long base_address,
4314 unsigned char *start = *start_ptr;
4315 unsigned char *section_end = section->start + section->size;
4316 unsigned long cu_offset;
4317 unsigned int pointer_size;
4318 unsigned int offset_size;
4323 unsigned short length;
4324 int need_frame_base;
4326 if (debug_info_entry >= num_debug_info_entries)
4328 warn (_("No debug information available for loc lists of entry: %u\n"),
4333 cu_offset = debug_information [debug_info_entry].cu_offset;
4334 pointer_size = debug_information [debug_info_entry].pointer_size;
4335 offset_size = debug_information [debug_info_entry].offset_size;
4336 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4338 if (pointer_size < 2 || pointer_size > 8)
4340 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4341 pointer_size, debug_info_entry);
4347 if (start + 2 * pointer_size > section_end)
4349 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4354 printf (" %8.8lx ", offset + (start - *start_ptr));
4356 /* Note: we use sign extension here in order to be sure that we can detect
4357 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4358 address will not affect the values that we display since we always show
4359 hex values, and always the bottom 32-bits. */
4360 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4361 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4363 if (begin == 0 && end == 0)
4365 printf (_("<End of list>\n"));
4369 /* Check base address specifiers. */
4370 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4373 print_dwarf_vma (begin, pointer_size);
4374 print_dwarf_vma (end, pointer_size);
4375 printf (_("(base address)\n"));
4379 if (start + 2 > section_end)
4381 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4386 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4388 if (start + length > section_end)
4390 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4395 print_dwarf_vma (begin + base_address, pointer_size);
4396 print_dwarf_vma (end + base_address, pointer_size);
4399 need_frame_base = decode_location_expression (start,
4404 cu_offset, section);
4407 if (need_frame_base && !has_frame_base)
4408 printf (_(" [without DW_AT_frame_base]"));
4411 fputs (_(" (start == end)"), stdout);
4412 else if (begin > end)
4413 fputs (_(" (start > end)"), stdout);
4423 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4424 right-adjusted in a field of length LEN, and followed by a space. */
4427 print_addr_index (unsigned int idx, unsigned int len)
4429 static char buf[15];
4430 snprintf (buf, sizeof (buf), "[%d]", idx);
4431 printf ("%*s ", len, buf);
4434 /* Display a location list from a .dwo section. It uses address indexes rather
4435 than embedded addresses. This code closely follows display_loc_list, but the
4436 two are sufficiently different that combining things is very ugly. */
4439 display_loc_list_dwo (struct dwarf_section *section,
4440 unsigned char **start_ptr,
4441 unsigned int debug_info_entry,
4442 unsigned long offset,
4445 unsigned char *start = *start_ptr;
4446 unsigned char *section_end = section->start + section->size;
4447 unsigned long cu_offset;
4448 unsigned int pointer_size;
4449 unsigned int offset_size;
4452 unsigned short length;
4453 int need_frame_base;
4455 unsigned int bytes_read;
4457 if (debug_info_entry >= num_debug_info_entries)
4459 warn (_("No debug information for loc lists of entry: %u\n"),
4464 cu_offset = debug_information [debug_info_entry].cu_offset;
4465 pointer_size = debug_information [debug_info_entry].pointer_size;
4466 offset_size = debug_information [debug_info_entry].offset_size;
4467 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4469 if (pointer_size < 2 || pointer_size > 8)
4471 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4472 pointer_size, debug_info_entry);
4478 printf (" %8.8lx ", offset + (start - *start_ptr));
4480 if (start >= section_end)
4482 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4487 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4490 case 0: /* A terminating entry. */
4492 printf (_("<End of list>\n"));
4494 case 1: /* A base-address entry. */
4495 idx = read_uleb128 (start, &bytes_read, section_end);
4496 start += bytes_read;
4497 print_addr_index (idx, 8);
4499 printf (_("(base address selection entry)\n"));
4501 case 2: /* A start/end entry. */
4502 idx = read_uleb128 (start, &bytes_read, section_end);
4503 start += bytes_read;
4504 print_addr_index (idx, 8);
4505 idx = read_uleb128 (start, &bytes_read, section_end);
4506 start += bytes_read;
4507 print_addr_index (idx, 8);
4509 case 3: /* A start/length entry. */
4510 idx = read_uleb128 (start, &bytes_read, section_end);
4511 start += bytes_read;
4512 print_addr_index (idx, 8);
4513 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4514 printf ("%08x ", idx);
4516 case 4: /* An offset pair entry. */
4517 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4518 printf ("%08x ", idx);
4519 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4520 printf ("%08x ", idx);
4523 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4528 if (start + 2 > section_end)
4530 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4535 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4536 if (start + length > section_end)
4538 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4544 need_frame_base = decode_location_expression (start,
4549 cu_offset, section);
4552 if (need_frame_base && !has_frame_base)
4553 printf (_(" [without DW_AT_frame_base]"));
4563 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4565 static dwarf_vma *loc_offsets;
4568 loc_offsets_compar (const void *ap, const void *bp)
4570 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4571 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4573 return (a > b) - (b > a);
4577 display_debug_loc (struct dwarf_section *section, void *file)
4579 unsigned char *start = section->start;
4580 unsigned long bytes;
4581 unsigned char *section_begin = start;
4582 unsigned int num_loc_list = 0;
4583 unsigned long last_offset = 0;
4584 unsigned int first = 0;
4588 int seen_first_offset = 0;
4589 int locs_sorted = 1;
4590 unsigned char *next;
4591 unsigned int *array = NULL;
4592 const char *suffix = strrchr (section->name, '.');
4595 if (suffix && strcmp (suffix, ".dwo") == 0)
4598 bytes = section->size;
4602 printf (_("\nThe %s section is empty.\n"), section->name);
4606 if (load_debug_info (file) == 0)
4608 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4613 /* Check the order of location list in .debug_info section. If
4614 offsets of location lists are in the ascending order, we can
4615 use `debug_information' directly. */
4616 for (i = 0; i < num_debug_info_entries; i++)
4620 num = debug_information [i].num_loc_offsets;
4621 if (num > num_loc_list)
4624 /* Check if we can use `debug_information' directly. */
4625 if (locs_sorted && num != 0)
4627 if (!seen_first_offset)
4629 /* This is the first location list. */
4630 last_offset = debug_information [i].loc_offsets [0];
4632 seen_first_offset = 1;
4638 for (; j < num; j++)
4641 debug_information [i].loc_offsets [j])
4646 last_offset = debug_information [i].loc_offsets [j];
4651 if (!seen_first_offset)
4652 error (_("No location lists in .debug_info section!\n"));
4654 if (debug_information [first].num_loc_offsets > 0
4655 && debug_information [first].loc_offsets [0] != 0)
4656 warn (_("Location lists in %s section start at 0x%s\n"),
4658 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4661 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4662 printf (_("Contents of the %s section:\n\n"), section->name);
4663 printf (_(" Offset Begin End Expression\n"));
4665 seen_first_offset = 0;
4666 for (i = first; i < num_debug_info_entries; i++)
4668 unsigned long offset;
4669 unsigned long base_address;
4674 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4676 loc_offsets = debug_information [i].loc_offsets;
4677 qsort (array, debug_information [i].num_loc_offsets,
4678 sizeof (*array), loc_offsets_compar);
4681 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4683 j = locs_sorted ? k : array[k];
4685 && debug_information [i].loc_offsets [locs_sorted
4686 ? k - 1 : array [k - 1]]
4687 == debug_information [i].loc_offsets [j])
4689 has_frame_base = debug_information [i].have_frame_base [j];
4690 offset = debug_information [i].loc_offsets [j];
4691 next = section_begin + offset;
4692 base_address = debug_information [i].base_address;
4694 if (!seen_first_offset)
4695 seen_first_offset = 1;
4699 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4700 (unsigned long) (start - section_begin),
4701 (unsigned long) (next - section_begin));
4702 else if (start > next)
4703 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4704 (unsigned long) (start - section_begin),
4705 (unsigned long) (next - section_begin));
4709 if (offset >= bytes)
4711 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4717 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4719 display_loc_list (section, &start, i, offset, base_address,
4724 if (start < section->start + section->size)
4725 warn (_("There are %ld unused bytes at the end of section %s\n"),
4726 (long) (section->start + section->size - start), section->name);
4733 display_debug_str (struct dwarf_section *section,
4734 void *file ATTRIBUTE_UNUSED)
4736 unsigned char *start = section->start;
4737 unsigned long bytes = section->size;
4738 dwarf_vma addr = section->address;
4742 printf (_("\nThe %s section is empty.\n"), section->name);
4746 printf (_("Contents of the %s section:\n\n"), section->name);
4754 lbytes = (bytes > 16 ? 16 : bytes);
4756 printf (" 0x%8.8lx ", (unsigned long) addr);
4758 for (j = 0; j < 16; j++)
4761 printf ("%2.2x", start[j]);
4769 for (j = 0; j < lbytes; j++)
4772 if (k >= ' ' && k < 0x80)
4791 display_debug_info (struct dwarf_section *section, void *file)
4793 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4797 display_debug_types (struct dwarf_section *section, void *file)
4799 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4803 display_trace_info (struct dwarf_section *section, void *file)
4805 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4809 display_debug_aranges (struct dwarf_section *section,
4810 void *file ATTRIBUTE_UNUSED)
4812 unsigned char *start = section->start;
4813 unsigned char *end = start + section->size;
4815 printf (_("Contents of the %s section:\n\n"), section->name);
4817 /* It does not matter if this load fails,
4818 we test for that later on. */
4819 load_debug_info (file);
4823 unsigned char *hdrptr;
4824 DWARF2_Internal_ARange arange;
4825 unsigned char *addr_ranges;
4828 unsigned char address_size;
4830 unsigned int offset_size;
4831 unsigned int initial_length_size;
4835 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4836 if (arange.ar_length == 0xffffffff)
4838 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4840 initial_length_size = 12;
4845 initial_length_size = 4;
4848 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4849 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4851 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4852 && num_debug_info_entries > 0
4853 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4854 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4855 (unsigned long) arange.ar_info_offset, section->name);
4857 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4858 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4860 if (arange.ar_version != 2 && arange.ar_version != 3)
4862 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4866 printf (_(" Length: %ld\n"),
4867 (long) arange.ar_length);
4868 printf (_(" Version: %d\n"), arange.ar_version);
4869 printf (_(" Offset into .debug_info: 0x%lx\n"),
4870 (unsigned long) arange.ar_info_offset);
4871 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4872 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4874 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4876 /* PR 17512: file: 001-108546-0.001:0.1. */
4877 if (address_size == 0 || address_size > 8)
4879 error (_("Invalid address size in %s section!\n"),
4884 /* The DWARF spec does not require that the address size be a power
4885 of two, but we do. This will have to change if we ever encounter
4886 an uneven architecture. */
4887 if ((address_size & (address_size - 1)) != 0)
4889 warn (_("Pointer size + Segment size is not a power of two.\n"));
4893 if (address_size > 4)
4894 printf (_("\n Address Length\n"));
4896 printf (_("\n Address Length\n"));
4898 addr_ranges = hdrptr;
4900 /* Must pad to an alignment boundary that is twice the address size. */
4901 excess = (hdrptr - start) % (2 * address_size);
4903 addr_ranges += (2 * address_size) - excess;
4905 start += arange.ar_length + initial_length_size;
4907 while (addr_ranges + 2 * address_size <= start)
4909 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4910 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
4913 print_dwarf_vma (address, address_size);
4914 print_dwarf_vma (length, address_size);
4924 /* Comparison function for qsort. */
4926 comp_addr_base (const void * v0, const void * v1)
4928 debug_info * info0 = (debug_info *) v0;
4929 debug_info * info1 = (debug_info *) v1;
4930 return info0->addr_base - info1->addr_base;
4933 /* Display the debug_addr section. */
4935 display_debug_addr (struct dwarf_section *section,
4938 debug_info **debug_addr_info;
4939 unsigned char *entry;
4944 if (section->size == 0)
4946 printf (_("\nThe %s section is empty.\n"), section->name);
4950 if (load_debug_info (file) == 0)
4952 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4957 printf (_("Contents of the %s section:\n\n"), section->name);
4959 /* PR 17531: file: cf38d01b.
4960 We use xcalloc because a corrupt file may not have initialised all of the
4961 fields in the debug_info structure, which means that the sort below might
4962 try to move uninitialised data. */
4963 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
4964 sizeof (debug_info *));
4967 for (i = 0; i < num_debug_info_entries; i++)
4968 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4970 /* PR 17531: file: cf38d01b. */
4971 if (debug_information[i].addr_base >= section->size)
4972 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
4973 (unsigned long) debug_information[i].addr_base, i);
4975 debug_addr_info [count++] = debug_information + i;
4978 /* Add a sentinel to make iteration convenient. */
4979 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4980 debug_addr_info [count]->addr_base = section->size;
4981 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4983 for (i = 0; i < count; i++)
4986 unsigned int address_size = debug_addr_info [i]->pointer_size;
4988 printf (_(" For compilation unit at offset 0x%s:\n"),
4989 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4991 printf (_("\tIndex\tAddress\n"));
4992 entry = section->start + debug_addr_info [i]->addr_base;
4993 end = section->start + debug_addr_info [i + 1]->addr_base;
4997 dwarf_vma base = byte_get (entry, address_size);
4998 printf (_("\t%d:\t"), idx);
4999 print_dwarf_vma (base, address_size);
5001 entry += address_size;
5007 free (debug_addr_info);
5011 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5013 display_debug_str_offsets (struct dwarf_section *section,
5014 void *file ATTRIBUTE_UNUSED)
5016 if (section->size == 0)
5018 printf (_("\nThe %s section is empty.\n"), section->name);
5021 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5022 what the offset size is for this section. */
5026 /* Each debug_information[x].range_lists[y] gets this representation for
5027 sorting purposes. */
5031 /* The debug_information[x].range_lists[y] value. */
5032 unsigned long ranges_offset;
5034 /* Original debug_information to find parameters of the data. */
5035 debug_info *debug_info_p;
5038 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5041 range_entry_compar (const void *ap, const void *bp)
5043 const struct range_entry *a_re = (const struct range_entry *) ap;
5044 const struct range_entry *b_re = (const struct range_entry *) bp;
5045 const unsigned long a = a_re->ranges_offset;
5046 const unsigned long b = b_re->ranges_offset;
5048 return (a > b) - (b > a);
5052 display_debug_ranges (struct dwarf_section *section,
5053 void *file ATTRIBUTE_UNUSED)
5055 unsigned char *start = section->start;
5056 unsigned char *last_start = start;
5057 unsigned long bytes = section->size;
5058 unsigned char *section_begin = start;
5059 unsigned char *finish = start + bytes;
5060 unsigned int num_range_list, i;
5061 struct range_entry *range_entries, *range_entry_fill;
5065 printf (_("\nThe %s section is empty.\n"), section->name);
5069 if (load_debug_info (file) == 0)
5071 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5077 for (i = 0; i < num_debug_info_entries; i++)
5078 num_range_list += debug_information [i].num_range_lists;
5080 if (num_range_list == 0)
5082 /* This can happen when the file was compiled with -gsplit-debug
5083 which removes references to range lists from the primary .o file. */
5084 printf (_("No range lists in .debug_info section.\n"));
5088 range_entries = (struct range_entry *)
5089 xmalloc (sizeof (*range_entries) * num_range_list);
5090 range_entry_fill = range_entries;
5092 for (i = 0; i < num_debug_info_entries; i++)
5094 debug_info *debug_info_p = &debug_information[i];
5097 for (j = 0; j < debug_info_p->num_range_lists; j++)
5099 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
5100 range_entry_fill->debug_info_p = debug_info_p;
5105 qsort (range_entries, num_range_list, sizeof (*range_entries),
5106 range_entry_compar);
5108 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
5109 warn (_("Range lists in %s section start at 0x%lx\n"),
5110 section->name, range_entries[0].ranges_offset);
5112 printf (_("Contents of the %s section:\n\n"), section->name);
5113 printf (_(" Offset Begin End\n"));
5115 for (i = 0; i < num_range_list; i++)
5117 struct range_entry *range_entry = &range_entries[i];
5118 debug_info *debug_info_p = range_entry->debug_info_p;
5119 unsigned int pointer_size;
5120 unsigned long offset;
5121 unsigned char *next;
5122 unsigned long base_address;
5124 pointer_size = debug_info_p->pointer_size;
5125 offset = range_entry->ranges_offset;
5126 next = section_begin + offset;
5127 base_address = debug_info_p->base_address;
5129 /* PR 17512: file: 001-101485-0.001:0.1. */
5130 if (pointer_size < 2 || pointer_size > 8)
5132 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5133 pointer_size, offset);
5137 if (dwarf_check != 0 && i > 0)
5140 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5141 (unsigned long) (start - section_begin),
5142 (unsigned long) (next - section_begin), section->name);
5143 else if (start > next)
5145 if (next == last_start)
5147 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5148 (unsigned long) (start - section_begin),
5149 (unsigned long) (next - section_begin), section->name);
5155 while (start < finish)
5160 /* Note: we use sign extension here in order to be sure that
5161 we can detect the -1 escape value. Sign extension into the
5162 top 32 bits of a 32-bit address will not affect the values
5163 that we display since we always show hex values, and always
5164 the bottom 32-bits. */
5165 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5166 if (start >= finish)
5168 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5170 printf (" %8.8lx ", offset);
5172 if (begin == 0 && end == 0)
5174 printf (_("<End of list>\n"));
5178 /* Check base address specifiers. */
5179 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
5182 print_dwarf_vma (begin, pointer_size);
5183 print_dwarf_vma (end, pointer_size);
5184 printf ("(base address)\n");
5188 print_dwarf_vma (begin + base_address, pointer_size);
5189 print_dwarf_vma (end + base_address, pointer_size);
5192 fputs (_("(start == end)"), stdout);
5193 else if (begin > end)
5194 fputs (_("(start > end)"), stdout);
5201 free (range_entries);
5206 typedef struct Frame_Chunk
5208 struct Frame_Chunk *next;
5209 unsigned char *chunk_start;
5211 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5212 short int *col_type;
5215 unsigned int code_factor;
5222 unsigned char fde_encoding;
5223 unsigned char cfa_exp;
5224 unsigned char ptr_size;
5225 unsigned char segment_size;
5229 static const char *const *dwarf_regnames;
5230 static unsigned int dwarf_regnames_count;
5232 /* A marker for a col_type that means this column was never referenced
5233 in the frame info. */
5234 #define DW_CFA_unreferenced (-1)
5236 /* Return 0 if no more space is needed, 1 if more space is needed,
5237 -1 for invalid reg. */
5240 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5242 unsigned int prev = fc->ncols;
5244 if (reg < (unsigned int) fc->ncols)
5247 if (dwarf_regnames_count
5248 && reg > dwarf_regnames_count)
5251 fc->ncols = reg + 1;
5252 /* PR 17512: file: 10450-2643-0.004.
5253 If reg == -1 then this can happen... */
5257 /* PR 17512: file: 2844a11d. */
5258 if (fc->ncols > 1024)
5260 error (_("Unfeasibly large register number: %u\n"), reg);
5262 /* FIXME: 1024 is an arbitrary limit. Increase it if
5263 we ever encounter a valid binary that exceeds it. */
5267 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5268 sizeof (short int));
5269 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5270 /* PR 17512: file:002-10025-0.005. */
5271 if (fc->col_type == NULL || fc->col_offset == NULL)
5273 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5279 while (prev < fc->ncols)
5281 fc->col_type[prev] = DW_CFA_unreferenced;
5282 fc->col_offset[prev] = 0;
5288 static const char *const dwarf_regnames_i386[] =
5290 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5291 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5292 "eip", "eflags", NULL, /* 8 - 10 */
5293 "st0", "st1", "st2", "st3", /* 11 - 14 */
5294 "st4", "st5", "st6", "st7", /* 15 - 18 */
5295 NULL, NULL, /* 19 - 20 */
5296 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5297 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5298 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5299 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5300 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5301 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5302 "tr", "ldtr", /* 48 - 49 */
5303 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5304 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5305 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5306 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5307 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5308 NULL, NULL, NULL, /* 90 - 92 */
5309 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5313 init_dwarf_regnames_i386 (void)
5315 dwarf_regnames = dwarf_regnames_i386;
5316 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5319 static const char *const dwarf_regnames_x86_64[] =
5321 "rax", "rdx", "rcx", "rbx",
5322 "rsi", "rdi", "rbp", "rsp",
5323 "r8", "r9", "r10", "r11",
5324 "r12", "r13", "r14", "r15",
5326 "xmm0", "xmm1", "xmm2", "xmm3",
5327 "xmm4", "xmm5", "xmm6", "xmm7",
5328 "xmm8", "xmm9", "xmm10", "xmm11",
5329 "xmm12", "xmm13", "xmm14", "xmm15",
5330 "st0", "st1", "st2", "st3",
5331 "st4", "st5", "st6", "st7",
5332 "mm0", "mm1", "mm2", "mm3",
5333 "mm4", "mm5", "mm6", "mm7",
5335 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5336 "fs.base", "gs.base", NULL, NULL,
5338 "mxcsr", "fcw", "fsw",
5339 "xmm16", "xmm17", "xmm18", "xmm19",
5340 "xmm20", "xmm21", "xmm22", "xmm23",
5341 "xmm24", "xmm25", "xmm26", "xmm27",
5342 "xmm28", "xmm29", "xmm30", "xmm31",
5343 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5344 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5345 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5346 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5347 NULL, NULL, NULL, /* 115 - 117 */
5348 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5352 init_dwarf_regnames_x86_64 (void)
5354 dwarf_regnames = dwarf_regnames_x86_64;
5355 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5358 static const char *const dwarf_regnames_aarch64[] =
5360 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5361 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5362 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5363 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5364 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
5365 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5366 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5367 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5368 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5369 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5370 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5371 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5375 init_dwarf_regnames_aarch64 (void)
5377 dwarf_regnames = dwarf_regnames_aarch64;
5378 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
5382 init_dwarf_regnames (unsigned int e_machine)
5388 init_dwarf_regnames_i386 ();
5394 init_dwarf_regnames_x86_64 ();
5398 init_dwarf_regnames_aarch64 ();
5407 regname (unsigned int regno, int row)
5409 static char reg[64];
5411 && regno < dwarf_regnames_count
5412 && dwarf_regnames [regno] != NULL)
5415 return dwarf_regnames [regno];
5416 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5417 dwarf_regnames [regno]);
5420 snprintf (reg, sizeof (reg), "r%d", regno);
5425 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
5430 if (*max_regs < fc->ncols)
5431 *max_regs = fc->ncols;
5433 if (*need_col_headers)
5435 static const char *sloc = " LOC";
5437 *need_col_headers = 0;
5439 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5441 for (r = 0; r < *max_regs; r++)
5442 if (fc->col_type[r] != DW_CFA_unreferenced)
5447 printf ("%-5s ", regname (r, 1));
5453 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5455 strcpy (tmp, "exp");
5457 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
5458 printf ("%-8s ", tmp);
5460 for (r = 0; r < fc->ncols; r++)
5462 if (fc->col_type[r] != DW_CFA_unreferenced)
5464 switch (fc->col_type[r])
5466 case DW_CFA_undefined:
5469 case DW_CFA_same_value:
5473 sprintf (tmp, "c%+d", fc->col_offset[r]);
5475 case DW_CFA_val_offset:
5476 sprintf (tmp, "v%+d", fc->col_offset[r]);
5478 case DW_CFA_register:
5479 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5481 case DW_CFA_expression:
5482 strcpy (tmp, "exp");
5484 case DW_CFA_val_expression:
5485 strcpy (tmp, "vexp");
5488 strcpy (tmp, "n/a");
5491 printf ("%-5s ", tmp);
5497 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5498 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5499 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5501 static unsigned char *
5502 read_cie (unsigned char *start, unsigned char *end,
5503 Frame_Chunk **p_cie, int *p_version,
5504 unsigned long *p_aug_len, unsigned char **p_aug)
5508 unsigned int length_return;
5509 unsigned char *augmentation_data = NULL;
5510 unsigned long augmentation_data_len = 0;
5513 /* PR 17512: file: 001-228113-0.004. */
5517 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5518 memset (fc, 0, sizeof (Frame_Chunk));
5520 fc->col_type = (short int *) xmalloc (sizeof (short int));
5521 fc->col_offset = (int *) xmalloc (sizeof (int));
5525 fc->augmentation = (char *) start;
5526 /* PR 17512: file: 001-228113-0.004.
5527 Skip past augmentation name, but avoid running off the end of the data. */
5529 if (* start ++ == '\0')
5533 warn (_("No terminator for augmentation name\n"));
5537 if (strcmp (fc->augmentation, "eh") == 0)
5538 start += eh_addr_size;
5542 GET (fc->ptr_size, 1);
5543 GET (fc->segment_size, 1);
5544 eh_addr_size = fc->ptr_size;
5548 fc->ptr_size = eh_addr_size;
5549 fc->segment_size = 0;
5551 fc->code_factor = LEB ();
5552 fc->data_factor = SLEB ();
5562 if (fc->augmentation[0] == 'z')
5564 augmentation_data_len = LEB ();
5565 augmentation_data = start;
5566 start += augmentation_data_len;
5567 /* PR 17512: file: 11042-2589-0.004. */
5570 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
5575 if (augmentation_data_len)
5579 unsigned char *qend;
5581 p = (unsigned char *) fc->augmentation + 1;
5582 q = augmentation_data;
5583 qend = q + augmentation_data_len;
5585 /* PR 17531: file: 015adfaa. */
5588 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
5589 augmentation_data_len = 0;
5592 while (p < end && q < augmentation_data + augmentation_data_len)
5597 q += 1 + size_of_encoded_value (*q);
5599 fc->fde_encoding = *q++;
5606 /* Note - it is OK if this loop terminates with q < qend.
5607 Padding may have been inserted to align the end of the CIE. */
5612 *p_version = version;
5615 *p_aug_len = augmentation_data_len;
5616 *p_aug = augmentation_data;
5622 display_debug_frames (struct dwarf_section *section,
5623 void *file ATTRIBUTE_UNUSED)
5625 unsigned char *start = section->start;
5626 unsigned char *end = start + section->size;
5627 unsigned char *section_start = start;
5628 Frame_Chunk *chunks = 0, *forward_refs = 0;
5629 Frame_Chunk *remembered_state = 0;
5631 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5632 unsigned int length_return;
5633 unsigned int max_regs = 0;
5634 const char *bad_reg = _("bad register: ");
5635 int saved_eh_addr_size = eh_addr_size;
5637 printf (_("Contents of the %s section:\n"), section->name);
5641 unsigned char *saved_start;
5642 unsigned char *block_end;
5647 int need_col_headers = 1;
5648 unsigned char *augmentation_data = NULL;
5649 unsigned long augmentation_data_len = 0;
5650 unsigned int encoded_ptr_size = saved_eh_addr_size;
5651 unsigned int offset_size;
5652 unsigned int initial_length_size;
5654 saved_start = start;
5656 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5660 printf ("\n%08lx ZERO terminator\n\n",
5661 (unsigned long)(saved_start - section_start));
5662 /* Skip any zero terminators that directly follow.
5663 A corrupt section size could have loaded a whole
5664 slew of zero filled memory bytes. eg
5665 PR 17512: file: 070-19381-0.004. */
5666 while (start < end && * start == 0)
5671 if (length == 0xffffffff)
5673 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5675 initial_length_size = 12;
5680 initial_length_size = 4;
5683 block_end = saved_start + length + initial_length_size;
5684 if (block_end > end || block_end < start)
5686 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5687 dwarf_vmatoa_1 (NULL, length, offset_size),
5688 (unsigned long) (saved_start - section_start));
5692 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5694 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5695 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5700 start = read_cie (start, end, &cie, &version,
5701 &augmentation_data_len, &augmentation_data);
5702 /* PR 17512: file: 027-135133-0.005. */
5709 fc->chunk_start = saved_start;
5710 mreg = max_regs > 0 ? max_regs - 1 : 0;
5713 if (frame_need_space (fc, mreg) < 0)
5715 if (fc->fde_encoding)
5716 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5718 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5719 print_dwarf_vma (length, fc->ptr_size);
5720 print_dwarf_vma (cie_id, offset_size);
5722 if (do_debug_frames_interp)
5724 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5725 fc->code_factor, fc->data_factor, fc->ra);
5730 printf (" Version: %d\n", version);
5731 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5734 printf (" Pointer Size: %u\n", fc->ptr_size);
5735 printf (" Segment Size: %u\n", fc->segment_size);
5737 printf (" Code alignment factor: %u\n", fc->code_factor);
5738 printf (" Data alignment factor: %d\n", fc->data_factor);
5739 printf (" Return address column: %d\n", fc->ra);
5741 if (augmentation_data_len)
5745 printf (" Augmentation data: ");
5746 for (i = 0; i < augmentation_data_len; ++i)
5747 /* FIXME: If do_wide is FALSE, then we should
5748 add carriage returns at 80 columns... */
5749 printf (" %02x", augmentation_data[i]);
5757 unsigned char *look_for;
5758 static Frame_Chunk fde_fc;
5759 unsigned long segment_selector;
5763 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
5764 look_for = start - 4 - ((cie_id ^ sign) - sign);
5767 look_for = section_start + cie_id;
5769 if (look_for <= saved_start)
5771 for (cie = chunks; cie ; cie = cie->next)
5772 if (cie->chunk_start == look_for)
5777 for (cie = forward_refs; cie ; cie = cie->next)
5778 if (cie->chunk_start == look_for)
5782 unsigned int off_size;
5783 unsigned char *cie_scan;
5785 cie_scan = look_for;
5787 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
5788 if (length == 0xffffffff)
5790 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
5797 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
5800 : ((off_size == 4 && c_id == DW_CIE_ID)
5801 || (off_size == 8 && c_id == DW64_CIE_ID)))
5806 read_cie (cie_scan, end, &cie, &version,
5807 &augmentation_data_len, &augmentation_data);
5808 /* PR 17512: file: 3450-2098-0.004. */
5811 warn (_("Failed to read CIE information\n"));
5814 cie->next = forward_refs;
5816 cie->chunk_start = look_for;
5817 mreg = max_regs > 0 ? max_regs - 1 : 0;
5820 if (frame_need_space (cie, mreg) < 0)
5822 warn (_("Invalid max register\n"));
5825 if (cie->fde_encoding)
5827 = size_of_encoded_value (cie->fde_encoding);
5834 memset (fc, 0, sizeof (Frame_Chunk));
5838 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5839 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5840 (unsigned long) (saved_start - section_start));
5842 fc->col_type = (short int *) xmalloc (sizeof (short int));
5843 fc->col_offset = (int *) xmalloc (sizeof (int));
5844 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
5846 warn (_("Invalid max register\n"));
5850 fc->augmentation = "";
5851 fc->fde_encoding = 0;
5852 fc->ptr_size = eh_addr_size;
5853 fc->segment_size = 0;
5857 fc->ncols = cie->ncols;
5858 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5859 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5860 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5861 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5862 fc->augmentation = cie->augmentation;
5863 fc->ptr_size = cie->ptr_size;
5864 eh_addr_size = cie->ptr_size;
5865 fc->segment_size = cie->segment_size;
5866 fc->code_factor = cie->code_factor;
5867 fc->data_factor = cie->data_factor;
5868 fc->cfa_reg = cie->cfa_reg;
5869 fc->cfa_offset = cie->cfa_offset;
5871 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
5873 warn (_("Invalid max register\n"));
5876 fc->fde_encoding = cie->fde_encoding;
5879 if (fc->fde_encoding)
5880 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5882 segment_selector = 0;
5883 if (fc->segment_size)
5884 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
5886 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
5888 /* FIXME: It appears that sometimes the final pc_range value is
5889 encoded in less than encoded_ptr_size bytes. See the x86_64
5890 run of the "objcopy on compressed debug sections" test for an
5892 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5894 if (cie->augmentation[0] == 'z')
5896 augmentation_data_len = LEB ();
5897 augmentation_data = start;
5898 start += augmentation_data_len;
5899 /* PR 17512: file: 722-8446-0.004. */
5900 if (start >= end || ((signed long) augmentation_data_len) < 0)
5902 warn (_("Corrupt augmentation data length: %lx\n"),
5903 augmentation_data_len);
5905 augmentation_data = NULL;
5906 augmentation_data_len = 0;
5910 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5911 (unsigned long)(saved_start - section_start),
5912 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
5913 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5914 (unsigned long)(cie->chunk_start - section_start));
5916 if (fc->segment_size)
5917 printf ("%04lx:", segment_selector);
5920 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
5921 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
5923 if (! do_debug_frames_interp && augmentation_data_len)
5927 printf (" Augmentation data: ");
5928 for (i = 0; i < augmentation_data_len; ++i)
5929 printf (" %02x", augmentation_data[i]);
5935 /* At this point, fc is the current chunk, cie (if any) is set, and
5936 we're about to interpret instructions for the chunk. */
5937 /* ??? At present we need to do this always, since this sizes the
5938 fc->col_type and fc->col_offset arrays, which we write into always.
5939 We should probably split the interpreted and non-interpreted bits
5940 into two different routines, since there's so much that doesn't
5941 really overlap between them. */
5942 if (1 || do_debug_frames_interp)
5944 /* Start by making a pass over the chunk, allocating storage
5945 and taking note of what registers are used. */
5946 unsigned char *tmp = start;
5948 while (start < block_end)
5950 unsigned int reg, op, opa;
5958 /* Warning: if you add any more cases to this switch, be
5959 sure to add them to the corresponding switch below. */
5962 case DW_CFA_advance_loc:
5966 if (frame_need_space (fc, opa) >= 0)
5967 fc->col_type[opa] = DW_CFA_undefined;
5969 case DW_CFA_restore:
5970 if (frame_need_space (fc, opa) >= 0)
5971 fc->col_type[opa] = DW_CFA_undefined;
5973 case DW_CFA_set_loc:
5974 start += encoded_ptr_size;
5976 case DW_CFA_advance_loc1:
5979 case DW_CFA_advance_loc2:
5982 case DW_CFA_advance_loc4:
5985 case DW_CFA_offset_extended:
5986 case DW_CFA_val_offset:
5987 reg = LEB (); LEB ();
5988 if (frame_need_space (fc, reg) >= 0)
5989 fc->col_type[reg] = DW_CFA_undefined;
5991 case DW_CFA_restore_extended:
5993 if (frame_need_space (fc, reg) >= 0)
5994 fc->col_type[reg] = DW_CFA_undefined;
5996 case DW_CFA_undefined:
5998 if (frame_need_space (fc, reg) >= 0)
5999 fc->col_type[reg] = DW_CFA_undefined;
6001 case DW_CFA_same_value:
6003 if (frame_need_space (fc, reg) >= 0)
6004 fc->col_type[reg] = DW_CFA_undefined;
6006 case DW_CFA_register:
6007 reg = LEB (); LEB ();
6008 if (frame_need_space (fc, reg) >= 0)
6009 fc->col_type[reg] = DW_CFA_undefined;
6011 case DW_CFA_def_cfa:
6014 case DW_CFA_def_cfa_register:
6017 case DW_CFA_def_cfa_offset:
6020 case DW_CFA_def_cfa_expression:
6022 if (start + temp < start)
6024 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
6030 case DW_CFA_expression:
6031 case DW_CFA_val_expression:
6034 if (start + temp < start)
6036 /* PR 17512: file:306-192417-0.005. */
6037 warn (_("Corrupt CFA expression value: %lu\n"), temp);
6042 if (frame_need_space (fc, reg) >= 0)
6043 fc->col_type[reg] = DW_CFA_undefined;
6045 case DW_CFA_offset_extended_sf:
6046 case DW_CFA_val_offset_sf:
6047 reg = LEB (); SLEB ();
6048 if (frame_need_space (fc, reg) >= 0)
6049 fc->col_type[reg] = DW_CFA_undefined;
6051 case DW_CFA_def_cfa_sf:
6054 case DW_CFA_def_cfa_offset_sf:
6057 case DW_CFA_MIPS_advance_loc8:
6060 case DW_CFA_GNU_args_size:
6063 case DW_CFA_GNU_negative_offset_extended:
6064 reg = LEB (); LEB ();
6065 if (frame_need_space (fc, reg) >= 0)
6066 fc->col_type[reg] = DW_CFA_undefined;
6075 /* Now we know what registers are used, make a second pass over
6076 the chunk, this time actually printing out the info. */
6078 while (start < block_end)
6081 unsigned long ul, reg, roffs;
6085 const char *reg_prefix = "";
6092 /* Warning: if you add any more cases to this switch, be
6093 sure to add them to the corresponding switch above. */
6096 case DW_CFA_advance_loc:
6097 if (do_debug_frames_interp)
6098 frame_display_row (fc, &need_col_headers, &max_regs);
6100 printf (" DW_CFA_advance_loc: %d to %s\n",
6101 opa * fc->code_factor,
6102 dwarf_vmatoa_1 (NULL,
6103 fc->pc_begin + opa * fc->code_factor,
6105 fc->pc_begin += opa * fc->code_factor;
6110 if (opa >= (unsigned int) fc->ncols)
6111 reg_prefix = bad_reg;
6112 if (! do_debug_frames_interp || *reg_prefix != '\0')
6113 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6114 reg_prefix, regname (opa, 0),
6115 roffs * fc->data_factor);
6116 if (*reg_prefix == '\0')
6118 fc->col_type[opa] = DW_CFA_offset;
6119 fc->col_offset[opa] = roffs * fc->data_factor;
6123 case DW_CFA_restore:
6124 if (opa >= (unsigned int) cie->ncols
6125 || opa >= (unsigned int) fc->ncols)
6126 reg_prefix = bad_reg;
6127 if (! do_debug_frames_interp || *reg_prefix != '\0')
6128 printf (" DW_CFA_restore: %s%s\n",
6129 reg_prefix, regname (opa, 0));
6130 if (*reg_prefix == '\0')
6132 fc->col_type[opa] = cie->col_type[opa];
6133 fc->col_offset[opa] = cie->col_offset[opa];
6134 if (do_debug_frames_interp
6135 && fc->col_type[opa] == DW_CFA_unreferenced)
6136 fc->col_type[opa] = DW_CFA_undefined;
6140 case DW_CFA_set_loc:
6141 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
6142 if (do_debug_frames_interp)
6143 frame_display_row (fc, &need_col_headers, &max_regs);
6145 printf (" DW_CFA_set_loc: %s\n",
6146 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
6150 case DW_CFA_advance_loc1:
6151 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
6152 if (do_debug_frames_interp)
6153 frame_display_row (fc, &need_col_headers, &max_regs);
6155 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6156 (unsigned long) (ofs * fc->code_factor),
6157 dwarf_vmatoa_1 (NULL,
6158 fc->pc_begin + ofs * fc->code_factor,
6160 fc->pc_begin += ofs * fc->code_factor;
6163 case DW_CFA_advance_loc2:
6164 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
6165 if (do_debug_frames_interp)
6166 frame_display_row (fc, &need_col_headers, &max_regs);
6168 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6169 (unsigned long) (ofs * fc->code_factor),
6170 dwarf_vmatoa_1 (NULL,
6171 fc->pc_begin + ofs * fc->code_factor,
6173 fc->pc_begin += ofs * fc->code_factor;
6176 case DW_CFA_advance_loc4:
6177 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
6178 if (do_debug_frames_interp)
6179 frame_display_row (fc, &need_col_headers, &max_regs);
6181 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6182 (unsigned long) (ofs * fc->code_factor),
6183 dwarf_vmatoa_1 (NULL,
6184 fc->pc_begin + ofs * fc->code_factor,
6186 fc->pc_begin += ofs * fc->code_factor;
6189 case DW_CFA_offset_extended:
6192 if (reg >= (unsigned int) fc->ncols)
6193 reg_prefix = bad_reg;
6194 if (! do_debug_frames_interp || *reg_prefix != '\0')
6195 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6196 reg_prefix, regname (reg, 0),
6197 roffs * fc->data_factor);
6198 if (*reg_prefix == '\0')
6200 fc->col_type[reg] = DW_CFA_offset;
6201 fc->col_offset[reg] = roffs * fc->data_factor;
6205 case DW_CFA_val_offset:
6208 if (reg >= (unsigned int) fc->ncols)
6209 reg_prefix = bad_reg;
6210 if (! do_debug_frames_interp || *reg_prefix != '\0')
6211 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6212 reg_prefix, regname (reg, 0),
6213 roffs * fc->data_factor);
6214 if (*reg_prefix == '\0')
6216 fc->col_type[reg] = DW_CFA_val_offset;
6217 fc->col_offset[reg] = roffs * fc->data_factor;
6221 case DW_CFA_restore_extended:
6223 if (reg >= (unsigned int) cie->ncols
6224 || reg >= (unsigned int) fc->ncols)
6225 reg_prefix = bad_reg;
6226 if (! do_debug_frames_interp || *reg_prefix != '\0')
6227 printf (" DW_CFA_restore_extended: %s%s\n",
6228 reg_prefix, regname (reg, 0));
6229 if (*reg_prefix == '\0')
6231 fc->col_type[reg] = cie->col_type[reg];
6232 fc->col_offset[reg] = cie->col_offset[reg];
6236 case DW_CFA_undefined:
6238 if (reg >= (unsigned int) fc->ncols)
6239 reg_prefix = bad_reg;
6240 if (! do_debug_frames_interp || *reg_prefix != '\0')
6241 printf (" DW_CFA_undefined: %s%s\n",
6242 reg_prefix, regname (reg, 0));
6243 if (*reg_prefix == '\0')
6245 fc->col_type[reg] = DW_CFA_undefined;
6246 fc->col_offset[reg] = 0;
6250 case DW_CFA_same_value:
6252 if (reg >= (unsigned int) fc->ncols)
6253 reg_prefix = bad_reg;
6254 if (! do_debug_frames_interp || *reg_prefix != '\0')
6255 printf (" DW_CFA_same_value: %s%s\n",
6256 reg_prefix, regname (reg, 0));
6257 if (*reg_prefix == '\0')
6259 fc->col_type[reg] = DW_CFA_same_value;
6260 fc->col_offset[reg] = 0;
6264 case DW_CFA_register:
6267 if (reg >= (unsigned int) fc->ncols)
6268 reg_prefix = bad_reg;
6269 if (! do_debug_frames_interp || *reg_prefix != '\0')
6271 printf (" DW_CFA_register: %s%s in ",
6272 reg_prefix, regname (reg, 0));
6273 puts (regname (roffs, 0));
6275 if (*reg_prefix == '\0')
6277 fc->col_type[reg] = DW_CFA_register;
6278 fc->col_offset[reg] = roffs;
6282 case DW_CFA_remember_state:
6283 if (! do_debug_frames_interp)
6284 printf (" DW_CFA_remember_state\n");
6285 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6286 rs->cfa_offset = fc->cfa_offset;
6287 rs->cfa_reg = fc->cfa_reg;
6289 rs->cfa_exp = fc->cfa_exp;
6290 rs->ncols = fc->ncols;
6291 rs->col_type = (short int *) xcmalloc (rs->ncols,
6292 sizeof (* rs->col_type));
6293 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
6294 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
6295 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
6296 rs->next = remembered_state;
6297 remembered_state = rs;
6300 case DW_CFA_restore_state:
6301 if (! do_debug_frames_interp)
6302 printf (" DW_CFA_restore_state\n");
6303 rs = remembered_state;
6306 remembered_state = rs->next;
6307 fc->cfa_offset = rs->cfa_offset;
6308 fc->cfa_reg = rs->cfa_reg;
6310 fc->cfa_exp = rs->cfa_exp;
6311 if (frame_need_space (fc, rs->ncols - 1) < 0)
6313 warn (_("Invalid column number in saved frame state\n"));
6317 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
6318 memcpy (fc->col_offset, rs->col_offset,
6319 rs->ncols * sizeof (* rs->col_offset));
6320 free (rs->col_type);
6321 free (rs->col_offset);
6324 else if (do_debug_frames_interp)
6325 printf ("Mismatched DW_CFA_restore_state\n");
6328 case DW_CFA_def_cfa:
6329 fc->cfa_reg = LEB ();
6330 fc->cfa_offset = LEB ();
6332 if (! do_debug_frames_interp)
6333 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6334 regname (fc->cfa_reg, 0), fc->cfa_offset);
6337 case DW_CFA_def_cfa_register:
6338 fc->cfa_reg = LEB ();
6340 if (! do_debug_frames_interp)
6341 printf (" DW_CFA_def_cfa_register: %s\n",
6342 regname (fc->cfa_reg, 0));
6345 case DW_CFA_def_cfa_offset:
6346 fc->cfa_offset = LEB ();
6347 if (! do_debug_frames_interp)
6348 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
6352 if (! do_debug_frames_interp)
6353 printf (" DW_CFA_nop\n");
6356 case DW_CFA_def_cfa_expression:
6358 if (start >= block_end || start + ul > block_end || start + ul < start)
6360 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6363 if (! do_debug_frames_interp)
6365 printf (" DW_CFA_def_cfa_expression (");
6366 decode_location_expression (start, eh_addr_size, 0, -1,
6374 case DW_CFA_expression:
6377 if (reg >= (unsigned int) fc->ncols)
6378 reg_prefix = bad_reg;
6379 /* PR 17512: file: 069-133014-0.006. */
6380 /* PR 17512: file: 98c02eb4. */
6381 if (start >= block_end || start + ul > block_end || start + ul < start)
6383 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6386 if (! do_debug_frames_interp || *reg_prefix != '\0')
6388 printf (" DW_CFA_expression: %s%s (",
6389 reg_prefix, regname (reg, 0));
6390 decode_location_expression (start, eh_addr_size, 0, -1,
6394 if (*reg_prefix == '\0')
6395 fc->col_type[reg] = DW_CFA_expression;
6399 case DW_CFA_val_expression:
6402 if (reg >= (unsigned int) fc->ncols)
6403 reg_prefix = bad_reg;
6404 if (start >= block_end || start + ul > block_end || start + ul < start)
6406 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6409 if (! do_debug_frames_interp || *reg_prefix != '\0')
6411 printf (" DW_CFA_val_expression: %s%s (",
6412 reg_prefix, regname (reg, 0));
6413 decode_location_expression (start, eh_addr_size, 0, -1,
6417 if (*reg_prefix == '\0')
6418 fc->col_type[reg] = DW_CFA_val_expression;
6422 case DW_CFA_offset_extended_sf:
6425 if (frame_need_space (fc, reg) < 0)
6426 reg_prefix = bad_reg;
6427 if (! do_debug_frames_interp || *reg_prefix != '\0')
6428 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6429 reg_prefix, regname (reg, 0),
6430 l * fc->data_factor);
6431 if (*reg_prefix == '\0')
6433 fc->col_type[reg] = DW_CFA_offset;
6434 fc->col_offset[reg] = l * fc->data_factor;
6438 case DW_CFA_val_offset_sf:
6441 if (frame_need_space (fc, reg) < 0)
6442 reg_prefix = bad_reg;
6443 if (! do_debug_frames_interp || *reg_prefix != '\0')
6444 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6445 reg_prefix, regname (reg, 0),
6446 l * fc->data_factor);
6447 if (*reg_prefix == '\0')
6449 fc->col_type[reg] = DW_CFA_val_offset;
6450 fc->col_offset[reg] = l * fc->data_factor;
6454 case DW_CFA_def_cfa_sf:
6455 fc->cfa_reg = LEB ();
6456 fc->cfa_offset = SLEB ();
6457 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6459 if (! do_debug_frames_interp)
6460 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6461 regname (fc->cfa_reg, 0), fc->cfa_offset);
6464 case DW_CFA_def_cfa_offset_sf:
6465 fc->cfa_offset = SLEB ();
6466 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6467 if (! do_debug_frames_interp)
6468 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
6471 case DW_CFA_MIPS_advance_loc8:
6472 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
6473 if (do_debug_frames_interp)
6474 frame_display_row (fc, &need_col_headers, &max_regs);
6476 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6477 (unsigned long) (ofs * fc->code_factor),
6478 dwarf_vmatoa_1 (NULL,
6479 fc->pc_begin + ofs * fc->code_factor,
6481 fc->pc_begin += ofs * fc->code_factor;
6484 case DW_CFA_GNU_window_save:
6485 if (! do_debug_frames_interp)
6486 printf (" DW_CFA_GNU_window_save\n");
6489 case DW_CFA_GNU_args_size:
6491 if (! do_debug_frames_interp)
6492 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6495 case DW_CFA_GNU_negative_offset_extended:
6498 if (frame_need_space (fc, reg) < 0)
6499 reg_prefix = bad_reg;
6500 if (! do_debug_frames_interp || *reg_prefix != '\0')
6501 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6502 reg_prefix, regname (reg, 0),
6503 l * fc->data_factor);
6504 if (*reg_prefix == '\0')
6506 fc->col_type[reg] = DW_CFA_offset;
6507 fc->col_offset[reg] = l * fc->data_factor;
6512 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6513 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6515 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6520 if (do_debug_frames_interp)
6521 frame_display_row (fc, &need_col_headers, &max_regs);
6524 eh_addr_size = saved_eh_addr_size;
6537 display_gdb_index (struct dwarf_section *section,
6538 void *file ATTRIBUTE_UNUSED)
6540 unsigned char *start = section->start;
6542 uint32_t cu_list_offset, tu_list_offset;
6543 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6544 unsigned int cu_list_elements, tu_list_elements;
6545 unsigned int address_table_size, symbol_table_slots;
6546 unsigned char *cu_list, *tu_list;
6547 unsigned char *address_table, *symbol_table, *constant_pool;
6550 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6552 printf (_("Contents of the %s section:\n"), section->name);
6554 if (section->size < 6 * sizeof (uint32_t))
6556 warn (_("Truncated header in the %s section.\n"), section->name);
6560 version = byte_get_little_endian (start, 4);
6561 printf (_("Version %ld\n"), (long) version);
6563 /* Prior versions are obsolete, and future versions may not be
6564 backwards compatible. */
6565 if (version < 3 || version > 8)
6567 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6571 warn (_("The address table data in version 3 may be wrong.\n"));
6573 warn (_("Version 4 does not support case insensitive lookups.\n"));
6575 warn (_("Version 5 does not include inlined functions.\n"));
6577 warn (_("Version 6 does not include symbol attributes.\n"));
6578 /* Version 7 indices generated by Gold have bad type unit references,
6579 PR binutils/15021. But we don't know if the index was generated by
6580 Gold or not, so to avoid worrying users with gdb-generated indices
6581 we say nothing for version 7 here. */
6583 cu_list_offset = byte_get_little_endian (start + 4, 4);
6584 tu_list_offset = byte_get_little_endian (start + 8, 4);
6585 address_table_offset = byte_get_little_endian (start + 12, 4);
6586 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6587 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6589 if (cu_list_offset > section->size
6590 || tu_list_offset > section->size
6591 || address_table_offset > section->size
6592 || symbol_table_offset > section->size
6593 || constant_pool_offset > section->size)
6595 warn (_("Corrupt header in the %s section.\n"), section->name);
6599 /* PR 17531: file: 418d0a8a. */
6600 if (tu_list_offset < cu_list_offset)
6602 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6603 tu_list_offset, cu_list_offset);
6607 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6609 if (address_table_offset < tu_list_offset)
6611 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6612 address_table_offset, tu_list_offset);
6616 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6618 /* PR 17531: file: 18a47d3d. */
6619 if (symbol_table_offset < address_table_offset)
6621 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6622 symbol_table_offset, address_table_offset);
6626 address_table_size = symbol_table_offset - address_table_offset;
6628 if (constant_pool_offset < symbol_table_offset)
6630 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6631 constant_pool_offset, symbol_table_offset);
6635 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6637 cu_list = start + cu_list_offset;
6638 tu_list = start + tu_list_offset;
6639 address_table = start + address_table_offset;
6640 symbol_table = start + symbol_table_offset;
6641 constant_pool = start + constant_pool_offset;
6643 if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
6645 warn (_("Address table extends beyond end of section.\n"));
6649 printf (_("\nCU table:\n"));
6650 for (i = 0; i < cu_list_elements; i += 2)
6652 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6653 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6655 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6656 (unsigned long) cu_offset,
6657 (unsigned long) (cu_offset + cu_length - 1));
6660 printf (_("\nTU table:\n"));
6661 for (i = 0; i < tu_list_elements; i += 3)
6663 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6664 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6665 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6667 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6668 (unsigned long) tu_offset,
6669 (unsigned long) type_offset);
6670 print_dwarf_vma (signature, 8);
6674 printf (_("\nAddress table:\n"));
6675 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
6678 uint64_t low = byte_get_little_endian (address_table + i, 8);
6679 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6680 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6682 print_dwarf_vma (low, 8);
6683 print_dwarf_vma (high, 8);
6684 printf (_("%lu\n"), (unsigned long) cu_index);
6687 printf (_("\nSymbol table:\n"));
6688 for (i = 0; i < symbol_table_slots; ++i)
6690 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6691 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6692 uint32_t num_cus, cu;
6694 if (name_offset != 0
6695 || cu_vector_offset != 0)
6699 /* PR 17531: file: 5b7b07ad. */
6700 if (constant_pool + name_offset < constant_pool
6701 || constant_pool + name_offset >= section->start + section->size)
6703 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
6704 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6708 printf ("[%3u] %.*s:", i,
6709 (int) (section->size - (constant_pool_offset + name_offset)),
6710 constant_pool + name_offset);
6712 if (constant_pool + cu_vector_offset < constant_pool
6713 || constant_pool + cu_vector_offset >= section->start + section->size - 3)
6715 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
6716 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6717 cu_vector_offset, i);
6721 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
6723 if (num_cus * 4 < num_cus
6724 || constant_pool + cu_vector_offset + 4 + num_cus * 4
6725 >= section->start + section->size
6726 || (constant_pool + cu_vector_offset + 4 + num_cus * 4) < constant_pool)
6728 printf ("<invalid number of CUs: %d>\n", num_cus);
6729 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6737 for (j = 0; j < num_cus; ++j)
6740 gdb_index_symbol_kind kind;
6742 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6743 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6744 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6745 cu = GDB_INDEX_CU_VALUE (cu);
6746 /* Convert to TU number if it's for a type unit. */
6747 if (cu >= cu_list_elements / 2)
6748 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6749 (unsigned long) (cu - cu_list_elements / 2));
6751 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6753 printf (" [%s, %s]",
6754 is_static ? _("static") : _("global"),
6755 get_gdb_index_symbol_kind_name (kind));
6767 /* Pre-allocate enough space for the CU/TU sets needed. */
6770 prealloc_cu_tu_list (unsigned int nshndx)
6772 if (shndx_pool == NULL)
6774 shndx_pool_size = nshndx;
6775 shndx_pool_used = 0;
6776 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6777 sizeof (unsigned int));
6781 shndx_pool_size = shndx_pool_used + nshndx;
6782 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6783 sizeof (unsigned int));
6788 add_shndx_to_cu_tu_entry (unsigned int shndx)
6790 if (shndx_pool_used >= shndx_pool_size)
6792 error (_("Internal error: out of space in the shndx pool.\n"));
6795 shndx_pool [shndx_pool_used++] = shndx;
6799 end_cu_tu_entry (void)
6801 if (shndx_pool_used >= shndx_pool_size)
6803 error (_("Internal error: out of space in the shndx pool.\n"));
6806 shndx_pool [shndx_pool_used++] = 0;
6809 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6812 get_DW_SECT_short_name (unsigned int dw_sect)
6814 static char buf[16];
6822 case DW_SECT_ABBREV:
6828 case DW_SECT_STR_OFFSETS:
6830 case DW_SECT_MACINFO:
6838 snprintf (buf, sizeof (buf), "%d", dw_sect);
6842 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6843 These sections are extensions for Fission.
6844 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6847 process_cu_tu_index (struct dwarf_section *section, int do_display)
6849 unsigned char *phdr = section->start;
6850 unsigned char *limit = phdr + section->size;
6851 unsigned char *phash;
6852 unsigned char *pindex;
6853 unsigned char *ppool;
6854 unsigned int version;
6855 unsigned int ncols = 0;
6857 unsigned int nslots;
6860 dwarf_vma signature_high;
6861 dwarf_vma signature_low;
6864 /* PR 17512: file: 002-168123-0.004. */
6867 warn (_("Section %s is empty\n"), section->name);
6870 /* PR 17512: file: 002-376-0.004. */
6871 if (section->size < 24)
6873 warn (_("Section %s is too small to contain a CU/TU header\n"),
6878 SAFE_BYTE_GET (version, phdr, 4, limit);
6880 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
6881 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
6882 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
6885 pindex = phash + nslots * 8;
6886 ppool = pindex + nslots * 4;
6888 /* PR 17531: file: 45d69832. */
6889 if (pindex < phash || ppool < phdr)
6891 warn (_("Section %s is too small for %d slots\n"),
6892 section->name, nslots);
6898 printf (_("Contents of the %s section:\n\n"), section->name);
6899 printf (_(" Version: %d\n"), version);
6901 printf (_(" Number of columns: %d\n"), ncols);
6902 printf (_(" Number of used entries: %d\n"), nused);
6903 printf (_(" Number of slots: %d\n\n"), nslots);
6908 warn (_("Section %s too small for %d hash table entries\n"),
6909 section->name, nslots);
6916 prealloc_cu_tu_list ((limit - ppool) / 4);
6917 for (i = 0; i < nslots; i++)
6919 unsigned char *shndx_list;
6922 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
6923 if (signature_high != 0 || signature_low != 0)
6925 SAFE_BYTE_GET (j, pindex, 4, limit);
6926 shndx_list = ppool + j * 4;
6927 /* PR 17531: file: 705e010d. */
6928 if (shndx_list < ppool)
6930 warn (_("Section index pool located before start of section\n"));
6935 printf (_(" [%3d] Signature: 0x%s Sections: "),
6936 i, dwarf_vmatoa64 (signature_high, signature_low,
6937 buf, sizeof (buf)));
6940 if (shndx_list >= limit)
6942 warn (_("Section %s too small for shndx pool\n"),
6946 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
6950 printf (" %d", shndx);
6952 add_shndx_to_cu_tu_entry (shndx);
6964 else if (version == 2)
6967 unsigned int dw_sect;
6968 unsigned char *ph = phash;
6969 unsigned char *pi = pindex;
6970 unsigned char *poffsets = ppool + ncols * 4;
6971 unsigned char *psizes = poffsets + nused * ncols * 4;
6972 unsigned char *pend = psizes + nused * ncols * 4;
6973 bfd_boolean is_tu_index;
6974 struct cu_tu_set *this_set = NULL;
6976 unsigned char *prow;
6978 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6982 warn (_("Section %s too small for offset and size tables\n"),
6989 printf (_(" Offset table\n"));
6990 printf (" slot %-16s ",
6991 is_tu_index ? _("signature") : _("dwo_id"));
6998 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7004 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7011 for (j = 0; j < ncols; j++)
7013 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7014 printf (" %8s", get_DW_SECT_short_name (dw_sect));
7019 for (i = 0; i < nslots; i++)
7021 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7023 SAFE_BYTE_GET (row, pi, 4, limit);
7026 /* PR 17531: file: a05f6ab3. */
7029 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
7035 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
7037 prow = poffsets + (row - 1) * ncols * 4;
7040 printf (_(" [%3d] 0x%s"),
7041 i, dwarf_vmatoa64 (signature_high, signature_low,
7042 buf, sizeof (buf)));
7043 for (j = 0; j < ncols; j++)
7045 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7047 printf (" %8d", val);
7050 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7052 /* PR 17531: file: 10796eb3. */
7053 if (dw_sect >= DW_SECT_MAX)
7054 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7056 this_set [row - 1].section_offsets [dw_sect] = val;
7072 printf (_(" Size table\n"));
7073 printf (" slot %-16s ",
7074 is_tu_index ? _("signature") : _("dwo_id"));
7077 for (j = 0; j < ncols; j++)
7079 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
7081 printf (" %8s", get_DW_SECT_short_name (val));
7087 for (i = 0; i < nslots; i++)
7089 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7091 SAFE_BYTE_GET (row, pi, 4, limit);
7094 prow = psizes + (row - 1) * ncols * 4;
7097 printf (_(" [%3d] 0x%s"),
7098 i, dwarf_vmatoa64 (signature_high, signature_low,
7099 buf, sizeof (buf)));
7101 for (j = 0; j < ncols; j++)
7103 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7105 printf (" %8d", val);
7108 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7109 if (dw_sect >= DW_SECT_MAX)
7110 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7112 this_set [row - 1].section_sizes [dw_sect] = val;
7124 else if (do_display)
7125 printf (_(" Unsupported version (%d)\n"), version);
7133 /* Load the CU and TU indexes if present. This will build a list of
7134 section sets that we can use to associate a .debug_info.dwo section
7135 with its associated .debug_abbrev.dwo section in a .dwp file. */
7138 load_cu_tu_indexes (void *file)
7140 /* If we have already loaded (or tried to load) the CU and TU indexes
7141 then do not bother to repeat the task. */
7142 if (cu_tu_indexes_read)
7145 if (load_debug_section (dwp_cu_index, file))
7146 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
7148 if (load_debug_section (dwp_tu_index, file))
7149 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
7151 cu_tu_indexes_read = 1;
7154 /* Find the set of sections that includes section SHNDX. */
7157 find_cu_tu_set (void *file, unsigned int shndx)
7161 load_cu_tu_indexes (file);
7163 /* Find SHNDX in the shndx pool. */
7164 for (i = 0; i < shndx_pool_used; i++)
7165 if (shndx_pool [i] == shndx)
7168 if (i >= shndx_pool_used)
7171 /* Now backup to find the first entry in the set. */
7172 while (i > 0 && shndx_pool [i - 1] != 0)
7175 return shndx_pool + i;
7178 /* Display a .debug_cu_index or .debug_tu_index section. */
7181 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
7183 return process_cu_tu_index (section, 1);
7187 display_debug_not_supported (struct dwarf_section *section,
7188 void *file ATTRIBUTE_UNUSED)
7190 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7196 /* Like malloc, but takes two parameters like calloc.
7197 Verifies that the first parameter is not too large.
7198 Note: does *not* initialise the allocated memory to zero. */
7200 cmalloc (size_t nmemb, size_t size)
7202 /* Check for overflow. */
7203 if (nmemb >= ~(size_t) 0 / size)
7206 return xmalloc (nmemb * size);
7209 /* Like xmalloc, but takes two parameters like calloc.
7210 Verifies that the first parameter is not too large.
7211 Note: does *not* initialise the allocated memory to zero. */
7213 xcmalloc (size_t nmemb, size_t size)
7215 /* Check for overflow. */
7216 if (nmemb >= ~(size_t) 0 / size)
7219 return xmalloc (nmemb * size);
7222 /* Like xrealloc, but takes three parameters.
7223 Verifies that the second parameter is not too large.
7224 Note: does *not* initialise any new memory to zero. */
7226 xcrealloc (void *ptr, size_t nmemb, size_t size)
7228 /* Check for overflow. */
7229 if (nmemb >= ~(size_t) 0 / size)
7232 return xrealloc (ptr, nmemb * size);
7235 /* Like xcalloc, but verifies that the first parameter is not too large. */
7237 xcalloc2 (size_t nmemb, size_t size)
7239 /* Check for overflow. */
7240 if (nmemb >= ~(size_t) 0 / size)
7243 return xcalloc (nmemb, size);
7247 free_debug_memory (void)
7253 for (i = 0; i < max; i++)
7254 free_debug_section ((enum dwarf_section_display_enum) i);
7256 if (debug_information != NULL)
7258 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
7260 for (i = 0; i < num_debug_info_entries; i++)
7262 if (!debug_information [i].max_loc_offsets)
7264 free (debug_information [i].loc_offsets);
7265 free (debug_information [i].have_frame_base);
7267 if (!debug_information [i].max_range_lists)
7268 free (debug_information [i].range_lists);
7271 free (debug_information);
7272 debug_information = NULL;
7273 alloc_num_debug_info_entries = num_debug_info_entries = 0;
7278 dwarf_select_sections_by_names (const char *names)
7282 const char * option;
7286 debug_dump_long_opts;
7288 static const debug_dump_long_opts opts_table [] =
7290 /* Please keep this table alpha- sorted. */
7291 { "Ranges", & do_debug_ranges, 1 },
7292 { "abbrev", & do_debug_abbrevs, 1 },
7293 { "addr", & do_debug_addr, 1 },
7294 { "aranges", & do_debug_aranges, 1 },
7295 { "cu_index", & do_debug_cu_index, 1 },
7296 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
7297 { "frames", & do_debug_frames, 1 },
7298 { "frames-interp", & do_debug_frames_interp, 1 },
7299 /* The special .gdb_index section. */
7300 { "gdb_index", & do_gdb_index, 1 },
7301 { "info", & do_debug_info, 1 },
7302 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
7303 { "loc", & do_debug_loc, 1 },
7304 { "macro", & do_debug_macinfo, 1 },
7305 { "pubnames", & do_debug_pubnames, 1 },
7306 { "pubtypes", & do_debug_pubtypes, 1 },
7307 /* This entry is for compatability
7308 with earlier versions of readelf. */
7309 { "ranges", & do_debug_aranges, 1 },
7310 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
7311 { "str", & do_debug_str, 1 },
7312 /* These trace_* sections are used by Itanium VMS. */
7313 { "trace_abbrev", & do_trace_abbrevs, 1 },
7314 { "trace_aranges", & do_trace_aranges, 1 },
7315 { "trace_info", & do_trace_info, 1 },
7324 const debug_dump_long_opts * entry;
7326 for (entry = opts_table; entry->option; entry++)
7328 size_t len = strlen (entry->option);
7330 if (strncmp (p, entry->option, len) == 0
7331 && (p[len] == ',' || p[len] == '\0'))
7333 * entry->variable |= entry->val;
7335 /* The --debug-dump=frames-interp option also
7336 enables the --debug-dump=frames option. */
7337 if (do_debug_frames_interp)
7338 do_debug_frames = 1;
7345 if (entry->option == NULL)
7347 warn (_("Unrecognized debug option '%s'\n"), p);
7348 p = strchr (p, ',');
7359 dwarf_select_sections_by_letters (const char *letters)
7361 unsigned int lindex = 0;
7363 while (letters[lindex])
7364 switch (letters[lindex++])
7371 do_debug_abbrevs = 1;
7375 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
7379 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
7383 do_debug_pubnames = 1;
7387 do_debug_pubtypes = 1;
7391 do_debug_aranges = 1;
7395 do_debug_ranges = 1;
7399 do_debug_frames_interp = 1;
7401 do_debug_frames = 1;
7405 do_debug_macinfo = 1;
7417 warn (_("Unrecognized debug option '%s'\n"), optarg);
7423 dwarf_select_sections_all (void)
7426 do_debug_abbrevs = 1;
7427 do_debug_lines = FLAG_DEBUG_LINES_RAW;
7428 do_debug_pubnames = 1;
7429 do_debug_pubtypes = 1;
7430 do_debug_aranges = 1;
7431 do_debug_ranges = 1;
7432 do_debug_frames = 1;
7433 do_debug_macinfo = 1;
7438 do_trace_abbrevs = 1;
7439 do_trace_aranges = 1;
7441 do_debug_cu_index = 1;
7444 struct dwarf_section_display debug_displays[] =
7446 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL },
7447 display_debug_abbrev, &do_debug_abbrevs, 0 },
7448 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL },
7449 display_debug_aranges, &do_debug_aranges, 1 },
7450 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL },
7451 display_debug_frames, &do_debug_frames, 1 },
7452 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL },
7453 display_debug_info, &do_debug_info, 1 },
7454 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL },
7455 display_debug_lines, &do_debug_lines, 1 },
7456 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL },
7457 display_debug_pubnames, &do_debug_pubnames, 0 },
7458 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL },
7459 display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
7460 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL },
7461 display_debug_frames, &do_debug_frames, 1 },
7462 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL },
7463 display_debug_macinfo, &do_debug_macinfo, 0 },
7464 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL },
7465 display_debug_macro, &do_debug_macinfo, 1 },
7466 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL },
7467 display_debug_str, &do_debug_str, 0 },
7468 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL },
7469 display_debug_loc, &do_debug_loc, 1 },
7470 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7471 display_debug_pubnames, &do_debug_pubtypes, 0 },
7472 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7473 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
7474 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL },
7475 display_debug_ranges, &do_debug_ranges, 1 },
7476 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL },
7477 display_debug_not_supported, NULL, 0 },
7478 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL },
7479 display_debug_not_supported, NULL, 0 },
7480 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL },
7481 display_debug_types, &do_debug_info, 1 },
7482 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL },
7483 display_debug_not_supported, NULL, 0 },
7484 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL },
7485 display_gdb_index, &do_gdb_index, 0 },
7486 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL },
7487 display_trace_info, &do_trace_info, 1 },
7488 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL },
7489 display_debug_abbrev, &do_trace_abbrevs, 0 },
7490 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL },
7491 display_debug_aranges, &do_trace_aranges, 0 },
7492 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7493 display_debug_info, &do_debug_info, 1 },
7494 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL },
7495 display_debug_abbrev, &do_debug_abbrevs, 0 },
7496 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7497 display_debug_types, &do_debug_info, 1 },
7498 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL },
7499 display_debug_lines, &do_debug_lines, 1 },
7500 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL },
7501 display_debug_loc, &do_debug_loc, 1 },
7502 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL },
7503 display_debug_macro, &do_debug_macinfo, 1 },
7504 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL },
7505 display_debug_macinfo, &do_debug_macinfo, 0 },
7506 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL },
7507 display_debug_str, &do_debug_str, 1 },
7508 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL },
7509 display_debug_str_offsets, NULL, 0 },
7510 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL },
7511 display_debug_str_offsets, NULL, 0 },
7512 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL },
7513 display_debug_addr, &do_debug_addr, 1 },
7514 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL },
7515 display_cu_index, &do_debug_cu_index, 0 },
7516 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL },
7517 display_cu_index, &do_debug_cu_index, 0 },