1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2017 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
47 unsigned int eh_addr_size;
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 unsigned int *shndx_pool = NULL;
80 static unsigned int shndx_pool_size = 0;
81 static unsigned int shndx_pool_used = 0;
83 /* For version 2 package files, each set contains an array of section offsets
84 and an array of section sizes, giving the offset and size of the
85 contribution from a CU or TU within one of the debug sections.
86 When displaying debug info from a package file, we need to use these
87 tables to locate the corresponding contributions to each section. */
92 dwarf_vma section_offsets[DW_SECT_MAX];
93 size_t section_sizes[DW_SECT_MAX];
96 static int cu_count = 0;
97 static int tu_count = 0;
98 static struct cu_tu_set *cu_sets = NULL;
99 static struct cu_tu_set *tu_sets = NULL;
101 static bfd_boolean load_cu_tu_indexes (void *);
103 /* Values for do_debug_lines. */
104 #define FLAG_DEBUG_LINES_RAW 1
105 #define FLAG_DEBUG_LINES_DECODED 2
108 size_of_encoded_value (int encoding)
110 switch (encoding & 0x7)
113 case 0: return eh_addr_size;
121 get_encoded_value (unsigned char **pdata,
123 struct dwarf_section *section,
126 unsigned char * data = * pdata;
127 unsigned int size = size_of_encoded_value (encoding);
130 if (data + size >= end)
132 warn (_("Encoded value extends past end of section\n"));
137 /* PR 17512: file: 002-829853-0.004. */
140 warn (_("Encoded size of %d is too large to read\n"), size);
145 /* PR 17512: file: 1085-5603-0.004. */
148 warn (_("Encoded size of 0 is too small to read\n"));
153 if (encoding & DW_EH_PE_signed)
154 val = byte_get_signed (data, size);
156 val = byte_get (data, size);
158 if ((encoding & 0x70) == DW_EH_PE_pcrel)
159 val += section->address + (data - section->start);
161 * pdata = data + size;
165 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
167 # define DWARF_VMA_FMT "ll"
168 # define DWARF_VMA_FMT_LONG "%16.16llx"
170 # define DWARF_VMA_FMT "I64"
171 # define DWARF_VMA_FMT_LONG "%016I64x"
174 # define DWARF_VMA_FMT "l"
175 # define DWARF_VMA_FMT_LONG "%16.16lx"
178 /* Convert a dwarf vma value into a string. Returns a pointer to a static
179 buffer containing the converted VALUE. The value is converted according
180 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
181 it specifies the maximum number of bytes to be displayed in the converted
182 value and FMTCH is ignored - hex is always used. */
185 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
187 /* As dwarf_vmatoa is used more then once in a printf call
188 for output, we are cycling through an fixed array of pointers
189 for return address. */
190 static int buf_pos = 0;
191 static struct dwarf_vmatoa_buf
197 ret = buf[buf_pos++].place;
198 buf_pos %= ARRAY_SIZE (buf);
202 /* Printf does not have a way of specifying a maximum field width for an
203 integer value, so we print the full value into a buffer and then select
204 the precision we need. */
205 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
208 return ret + (16 - 2 * num_bytes);
214 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
215 snprintf (ret, sizeof (buf[0].place), fmt, value);
220 static inline const char *
221 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
223 return dwarf_vmatoa_1 (fmtch, value, 0);
226 /* Print a dwarf_vma value (typically an address, offset or length) in
227 hexadecimal format, followed by a space. The length of the VALUE (and
228 hence the precision displayed) is determined by the NUM_BYTES parameter. */
231 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
233 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
236 /* Format a 64-bit value, given as two 32-bit values, in hex.
237 For reentrancy, this uses a buffer provided by the caller. */
240 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
241 unsigned int buf_len)
246 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
249 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
250 snprintf (buf + len, buf_len - len,
251 "%08" DWARF_VMA_FMT "x", lvalue);
257 /* Read in a LEB128 encoded value starting at address DATA.
258 If SIGN is true, return a signed LEB128 value.
259 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
260 No bytes will be read at address END or beyond. */
263 read_leb128 (unsigned char *data,
264 unsigned int *length_return,
266 const unsigned char * const end)
268 dwarf_vma result = 0;
269 unsigned int num_read = 0;
270 unsigned int shift = 0;
271 unsigned char byte = 0;
278 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
281 if ((byte & 0x80) == 0)
284 /* PR 17512: file: 0ca183b8.
285 FIXME: Should we signal this error somehow ? */
286 if (shift >= sizeof (result) * 8)
290 if (length_return != NULL)
291 *length_return = num_read;
293 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
294 result |= -((dwarf_vma) 1 << shift);
299 /* Create a signed version to avoid painful typecasts. */
300 static inline dwarf_signed_vma
301 read_sleb128 (unsigned char * data,
302 unsigned int * length_return,
303 const unsigned char * const end)
305 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
308 static inline dwarf_vma
309 read_uleb128 (unsigned char * data,
310 unsigned int * length_return,
311 const unsigned char * const end)
313 return read_leb128 (data, length_return, FALSE, end);
316 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
319 unsigned int amount = (AMOUNT); \
320 if (sizeof (VAL) < amount) \
322 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
323 amount, (int) sizeof (VAL)); \
324 amount = sizeof (VAL); \
326 if (((PTR) + amount) >= (END)) \
329 amount = (END) - (PTR); \
333 if (amount == 0 || amount > 8) \
336 VAL = byte_get ((PTR), amount); \
340 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
343 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
348 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
351 unsigned int amount = (AMOUNT); \
352 if (((PTR) + amount) >= (END)) \
355 amount = (END) - (PTR); \
360 VAL = byte_get_signed ((PTR), amount); \
366 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
369 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
374 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
377 if (((PTR) + 8) <= (END)) \
379 byte_get_64 ((PTR), (HIGH), (LOW)); \
383 * (LOW) = * (HIGH) = 0; \
388 typedef struct State_Machine_Registers
396 unsigned char op_index;
397 unsigned char end_sequence;
398 /* This variable hold the number of the last entry seen
399 in the File Table. */
400 unsigned int last_file_entry;
403 static SMR state_machine_regs;
406 reset_state_machine (int is_stmt)
408 state_machine_regs.address = 0;
409 state_machine_regs.op_index = 0;
410 state_machine_regs.file = 1;
411 state_machine_regs.line = 1;
412 state_machine_regs.column = 0;
413 state_machine_regs.is_stmt = is_stmt;
414 state_machine_regs.basic_block = 0;
415 state_machine_regs.end_sequence = 0;
416 state_machine_regs.last_file_entry = 0;
419 /* Handled an extend line op.
420 Returns the number of bytes read. */
423 process_extended_line_op (unsigned char * data,
427 unsigned char op_code;
428 unsigned int bytes_read;
431 unsigned char *orig_data = data;
434 len = read_uleb128 (data, & bytes_read, end);
437 if (len == 0 || data == end || len > (uintptr_t) (end - data))
439 warn (_("Badly formed extended line op encountered!\n"));
446 printf (_(" Extended opcode %d: "), op_code);
450 case DW_LNE_end_sequence:
451 printf (_("End of Sequence\n\n"));
452 reset_state_machine (is_stmt);
455 case DW_LNE_set_address:
456 /* PR 17512: file: 002-100480-0.004. */
457 if (len - bytes_read - 1 > 8)
459 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
460 len - bytes_read - 1);
464 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
465 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
466 state_machine_regs.address = adr;
467 state_machine_regs.op_index = 0;
470 case DW_LNE_define_file:
471 printf (_("define new File Table entry\n"));
472 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
473 printf (" %d\t", ++state_machine_regs.last_file_entry);
476 data += strnlen ((char *) data, end - data) + 1;
477 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
479 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
481 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
483 printf ("%s\n\n", name);
485 if (((unsigned int) (data - orig_data) != len) || data == end)
486 warn (_("DW_LNE_define_file: Bad opcode length\n"));
489 case DW_LNE_set_discriminator:
490 printf (_("set Discriminator to %s\n"),
491 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
495 case DW_LNE_HP_negate_is_UV_update:
496 printf ("DW_LNE_HP_negate_is_UV_update\n");
498 case DW_LNE_HP_push_context:
499 printf ("DW_LNE_HP_push_context\n");
501 case DW_LNE_HP_pop_context:
502 printf ("DW_LNE_HP_pop_context\n");
504 case DW_LNE_HP_set_file_line_column:
505 printf ("DW_LNE_HP_set_file_line_column\n");
507 case DW_LNE_HP_set_routine_name:
508 printf ("DW_LNE_HP_set_routine_name\n");
510 case DW_LNE_HP_set_sequence:
511 printf ("DW_LNE_HP_set_sequence\n");
513 case DW_LNE_HP_negate_post_semantics:
514 printf ("DW_LNE_HP_negate_post_semantics\n");
516 case DW_LNE_HP_negate_function_exit:
517 printf ("DW_LNE_HP_negate_function_exit\n");
519 case DW_LNE_HP_negate_front_end_logical:
520 printf ("DW_LNE_HP_negate_front_end_logical\n");
522 case DW_LNE_HP_define_proc:
523 printf ("DW_LNE_HP_define_proc\n");
525 case DW_LNE_HP_source_file_correlation:
527 unsigned char *edata = data + len - bytes_read - 1;
529 printf ("DW_LNE_HP_source_file_correlation\n");
535 opc = read_uleb128 (data, & bytes_read, edata);
540 case DW_LNE_HP_SFC_formfeed:
541 printf (" DW_LNE_HP_SFC_formfeed\n");
543 case DW_LNE_HP_SFC_set_listing_line:
544 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
546 read_uleb128 (data, & bytes_read, edata)));
549 case DW_LNE_HP_SFC_associate:
550 printf (" DW_LNE_HP_SFC_associate ");
553 read_uleb128 (data, & bytes_read, edata)));
557 read_uleb128 (data, & bytes_read, edata)));
561 read_uleb128 (data, & bytes_read, edata)));
565 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
575 unsigned int rlen = len - bytes_read - 1;
577 if (op_code >= DW_LNE_lo_user
578 /* The test against DW_LNW_hi_user is redundant due to
579 the limited range of the unsigned char data type used
581 /*&& op_code <= DW_LNE_hi_user*/)
582 printf (_("user defined: "));
584 printf (_("UNKNOWN: "));
585 printf (_("length %d ["), rlen);
587 printf (" %02x", *data++);
596 static const unsigned char *
597 fetch_indirect_string (dwarf_vma offset)
599 struct dwarf_section *section = &debug_displays [str].section;
601 if (section->start == NULL)
602 return (const unsigned char *) _("<no .debug_str section>");
604 if (offset > section->size)
606 warn (_("DW_FORM_strp offset too big: %s\n"),
607 dwarf_vmatoa ("x", offset));
608 return (const unsigned char *) _("<offset is too big>");
611 return (const unsigned char *) section->start + offset;
614 static const unsigned char *
615 fetch_indirect_line_string (dwarf_vma offset)
617 struct dwarf_section *section = &debug_displays [line_str].section;
619 if (section->start == NULL)
620 return (const unsigned char *) _("<no .debug_line_str section>");
622 if (offset > section->size)
624 warn (_("DW_FORM_line_strp offset too big: %s\n"),
625 dwarf_vmatoa ("x", offset));
626 return (const unsigned char *) _("<offset is too big>");
629 return (const unsigned char *) section->start + offset;
633 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
634 dwarf_vma offset_size, int dwo)
636 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
637 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
638 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
639 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
640 dwarf_vma index_offset = idx * offset_size;
641 dwarf_vma str_offset;
643 if (index_section->start == NULL)
644 return (dwo ? _("<no .debug_str_offsets.dwo section>")
645 : _("<no .debug_str_offsets section>"));
647 if (this_set != NULL)
648 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
649 if (index_offset > index_section->size)
651 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
652 dwarf_vmatoa ("x", index_offset));
653 return _("<index offset is too big>");
656 if (str_section->start == NULL)
657 return (dwo ? _("<no .debug_str.dwo section>")
658 : _("<no .debug_str section>"));
660 str_offset = byte_get (index_section->start + index_offset, offset_size);
661 str_offset -= str_section->address;
662 if (str_offset > str_section->size)
664 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
665 dwarf_vmatoa ("x", str_offset));
666 return _("<indirect index offset is too big>");
669 return (const char *) str_section->start + str_offset;
673 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
675 struct dwarf_section *section = &debug_displays [debug_addr].section;
677 if (section->start == NULL)
678 return (_("<no .debug_addr section>"));
680 if (offset + bytes > section->size)
682 warn (_("Offset into section %s too big: %s\n"),
683 section->name, dwarf_vmatoa ("x", offset));
684 return "<offset too big>";
687 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
691 /* FIXME: There are better and more efficient ways to handle
692 these structures. For now though, I just want something that
693 is simple to implement. */
694 typedef struct abbrev_attr
696 unsigned long attribute;
698 bfd_signed_vma implicit_const;
699 struct abbrev_attr *next;
703 typedef struct abbrev_entry
708 struct abbrev_attr *first_attr;
709 struct abbrev_attr *last_attr;
710 struct abbrev_entry *next;
714 static abbrev_entry *first_abbrev = NULL;
715 static abbrev_entry *last_abbrev = NULL;
722 for (abbrv = first_abbrev; abbrv;)
724 abbrev_entry *next_abbrev = abbrv->next;
727 for (attr = abbrv->first_attr; attr;)
729 abbrev_attr *next_attr = attr->next;
739 last_abbrev = first_abbrev = NULL;
743 add_abbrev (unsigned long number, unsigned long tag, int children)
747 entry = (abbrev_entry *) malloc (sizeof (*entry));
752 entry->entry = number;
754 entry->children = children;
755 entry->first_attr = NULL;
756 entry->last_attr = NULL;
759 if (first_abbrev == NULL)
760 first_abbrev = entry;
762 last_abbrev->next = entry;
768 add_abbrev_attr (unsigned long attribute, unsigned long form,
769 bfd_signed_vma implicit_const)
773 attr = (abbrev_attr *) malloc (sizeof (*attr));
778 attr->attribute = attribute;
780 attr->implicit_const = implicit_const;
783 if (last_abbrev->first_attr == NULL)
784 last_abbrev->first_attr = attr;
786 last_abbrev->last_attr->next = attr;
788 last_abbrev->last_attr = attr;
791 /* Processes the (partial) contents of a .debug_abbrev section.
792 Returns NULL if the end of the section was encountered.
793 Returns the address after the last byte read if the end of
794 an abbreviation set was found. */
796 static unsigned char *
797 process_abbrev_section (unsigned char *start, unsigned char *end)
799 if (first_abbrev != NULL)
804 unsigned int bytes_read;
807 unsigned long attribute;
810 entry = read_uleb128 (start, & bytes_read, end);
813 /* A single zero is supposed to end the section according
814 to the standard. If there's more, then signal that to
821 tag = read_uleb128 (start, & bytes_read, end);
828 add_abbrev (entry, tag, children);
833 /* Initialize it due to a false compiler warning. */
834 bfd_signed_vma implicit_const = -1;
836 attribute = read_uleb128 (start, & bytes_read, end);
841 form = read_uleb128 (start, & bytes_read, end);
846 if (form == DW_FORM_implicit_const)
848 implicit_const = read_sleb128 (start, & bytes_read, end);
854 add_abbrev_attr (attribute, form, implicit_const);
856 while (attribute != 0);
859 /* Report the missing single zero which ends the section. */
860 error (_(".debug_abbrev section not zero terminated\n"));
866 get_TAG_name (unsigned long tag)
868 const char *name = get_DW_TAG_name ((unsigned int)tag);
872 static char buffer[100];
874 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
882 get_FORM_name (unsigned long form)
887 return "DW_FORM value: 0";
889 name = get_DW_FORM_name (form);
892 static char buffer[100];
894 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
901 static unsigned char *
902 display_block (unsigned char *data,
904 const unsigned char * const end, char delimiter)
908 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
910 return (unsigned char *) end;
912 maxlen = (dwarf_vma) (end - data);
913 length = length > maxlen ? maxlen : length;
916 printf ("%lx ", (unsigned long) byte_get (data++, 1));
922 decode_location_expression (unsigned char * data,
923 unsigned int pointer_size,
924 unsigned int offset_size,
928 struct dwarf_section * section)
931 unsigned int bytes_read;
933 dwarf_signed_vma svalue;
934 unsigned char *end = data + length;
935 int need_frame_base = 0;
944 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
945 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
948 printf ("DW_OP_deref");
951 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
952 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
955 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
956 printf ("DW_OP_const1s: %ld", (long) svalue);
959 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
960 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
963 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
964 printf ("DW_OP_const2s: %ld", (long) svalue);
967 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
968 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
971 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
972 printf ("DW_OP_const4s: %ld", (long) svalue);
975 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
976 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
977 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
978 printf ("%lu", (unsigned long) uvalue);
981 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
982 printf ("DW_OP_const8s: %ld ", (long) svalue);
983 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
984 printf ("%ld", (long) svalue);
987 printf ("DW_OP_constu: %s",
988 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
992 printf ("DW_OP_consts: %s",
993 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
997 printf ("DW_OP_dup");
1000 printf ("DW_OP_drop");
1003 printf ("DW_OP_over");
1006 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1007 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1010 printf ("DW_OP_swap");
1013 printf ("DW_OP_rot");
1016 printf ("DW_OP_xderef");
1019 printf ("DW_OP_abs");
1022 printf ("DW_OP_and");
1025 printf ("DW_OP_div");
1028 printf ("DW_OP_minus");
1031 printf ("DW_OP_mod");
1034 printf ("DW_OP_mul");
1037 printf ("DW_OP_neg");
1040 printf ("DW_OP_not");
1043 printf ("DW_OP_or");
1046 printf ("DW_OP_plus");
1048 case DW_OP_plus_uconst:
1049 printf ("DW_OP_plus_uconst: %s",
1050 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1054 printf ("DW_OP_shl");
1057 printf ("DW_OP_shr");
1060 printf ("DW_OP_shra");
1063 printf ("DW_OP_xor");
1066 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1067 printf ("DW_OP_bra: %ld", (long) svalue);
1070 printf ("DW_OP_eq");
1073 printf ("DW_OP_ge");
1076 printf ("DW_OP_gt");
1079 printf ("DW_OP_le");
1082 printf ("DW_OP_lt");
1085 printf ("DW_OP_ne");
1088 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1089 printf ("DW_OP_skip: %ld", (long) svalue);
1124 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1159 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1160 regname (op - DW_OP_reg0, 1));
1195 printf ("DW_OP_breg%d (%s): %s",
1197 regname (op - DW_OP_breg0, 1),
1198 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1203 uvalue = read_uleb128 (data, &bytes_read, end);
1205 printf ("DW_OP_regx: %s (%s)",
1206 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1209 need_frame_base = 1;
1210 printf ("DW_OP_fbreg: %s",
1211 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1215 uvalue = read_uleb128 (data, &bytes_read, end);
1217 printf ("DW_OP_bregx: %s (%s) %s",
1218 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1219 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1223 printf ("DW_OP_piece: %s",
1224 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1227 case DW_OP_deref_size:
1228 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1229 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1231 case DW_OP_xderef_size:
1232 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1233 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1236 printf ("DW_OP_nop");
1239 /* DWARF 3 extensions. */
1240 case DW_OP_push_object_address:
1241 printf ("DW_OP_push_object_address");
1244 /* XXX: Strictly speaking for 64-bit DWARF3 files
1245 this ought to be an 8-byte wide computation. */
1246 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1247 printf ("DW_OP_call2: <0x%s>",
1248 dwarf_vmatoa ("x", svalue + cu_offset));
1251 /* XXX: Strictly speaking for 64-bit DWARF3 files
1252 this ought to be an 8-byte wide computation. */
1253 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1254 printf ("DW_OP_call4: <0x%s>",
1255 dwarf_vmatoa ("x", svalue + cu_offset));
1257 case DW_OP_call_ref:
1258 /* XXX: Strictly speaking for 64-bit DWARF3 files
1259 this ought to be an 8-byte wide computation. */
1260 if (dwarf_version == -1)
1262 printf (_("(DW_OP_call_ref in frame info)"));
1263 /* No way to tell where the next op is, so just bail. */
1264 return need_frame_base;
1266 if (dwarf_version == 2)
1268 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1272 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1274 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1276 case DW_OP_form_tls_address:
1277 printf ("DW_OP_form_tls_address");
1279 case DW_OP_call_frame_cfa:
1280 printf ("DW_OP_call_frame_cfa");
1282 case DW_OP_bit_piece:
1283 printf ("DW_OP_bit_piece: ");
1284 printf (_("size: %s "),
1285 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1287 printf (_("offset: %s "),
1288 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1292 /* DWARF 4 extensions. */
1293 case DW_OP_stack_value:
1294 printf ("DW_OP_stack_value");
1297 case DW_OP_implicit_value:
1298 printf ("DW_OP_implicit_value");
1299 uvalue = read_uleb128 (data, &bytes_read, end);
1301 data = display_block (data, uvalue, end, ' ');
1304 /* GNU extensions. */
1305 case DW_OP_GNU_push_tls_address:
1306 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1308 case DW_OP_GNU_uninit:
1309 printf ("DW_OP_GNU_uninit");
1310 /* FIXME: Is there data associated with this OP ? */
1312 case DW_OP_GNU_encoded_addr:
1319 addr = get_encoded_value (&data, encoding, section, end);
1321 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1322 print_dwarf_vma (addr, pointer_size);
1325 case DW_OP_implicit_pointer:
1326 case DW_OP_GNU_implicit_pointer:
1327 /* XXX: Strictly speaking for 64-bit DWARF3 files
1328 this ought to be an 8-byte wide computation. */
1329 if (dwarf_version == -1)
1331 printf (_("(%s in frame info)"),
1332 (op == DW_OP_implicit_pointer
1333 ? "DW_OP_implicit_pointer"
1334 : "DW_OP_GNU_implicit_pointer"));
1335 /* No way to tell where the next op is, so just bail. */
1336 return need_frame_base;
1338 if (dwarf_version == 2)
1340 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1344 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1346 printf ("%s: <0x%s> %s",
1347 (op == DW_OP_implicit_pointer
1348 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1349 dwarf_vmatoa ("x", uvalue),
1350 dwarf_vmatoa ("d", read_sleb128 (data,
1351 &bytes_read, end)));
1354 case DW_OP_entry_value:
1355 case DW_OP_GNU_entry_value:
1356 uvalue = read_uleb128 (data, &bytes_read, end);
1358 /* PR 17531: file: 0cc9cd00. */
1359 if (uvalue > (dwarf_vma) (end - data))
1360 uvalue = end - data;
1361 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1362 : "DW_OP_GNU_entry_value"));
1363 if (decode_location_expression (data, pointer_size, offset_size,
1364 dwarf_version, uvalue,
1365 cu_offset, section))
1366 need_frame_base = 1;
1372 case DW_OP_const_type:
1373 case DW_OP_GNU_const_type:
1374 uvalue = read_uleb128 (data, &bytes_read, end);
1376 printf ("%s: <0x%s> ",
1377 (op == DW_OP_const_type ? "DW_OP_const_type"
1378 : "DW_OP_GNU_const_type"),
1379 dwarf_vmatoa ("x", cu_offset + uvalue));
1380 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1381 data = display_block (data, uvalue, end, ' ');
1383 case DW_OP_regval_type:
1384 case DW_OP_GNU_regval_type:
1385 uvalue = read_uleb128 (data, &bytes_read, end);
1387 printf ("%s: %s (%s)",
1388 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1389 : "DW_OP_GNU_regval_type"),
1390 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1391 uvalue = read_uleb128 (data, &bytes_read, end);
1393 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1395 case DW_OP_deref_type:
1396 case DW_OP_GNU_deref_type:
1397 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1399 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1400 : "DW_OP_GNU_deref_type"),
1402 uvalue = read_uleb128 (data, &bytes_read, end);
1404 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1407 case DW_OP_GNU_convert:
1408 uvalue = read_uleb128 (data, &bytes_read, end);
1410 printf ("%s <0x%s>",
1411 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1412 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1414 case DW_OP_reinterpret:
1415 case DW_OP_GNU_reinterpret:
1416 uvalue = read_uleb128 (data, &bytes_read, end);
1418 printf ("%s <0x%s>",
1419 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1420 : "DW_OP_GNU_reinterpret"),
1421 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1423 case DW_OP_GNU_parameter_ref:
1424 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1425 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1426 dwarf_vmatoa ("x", cu_offset + uvalue));
1428 case DW_OP_GNU_addr_index:
1429 uvalue = read_uleb128 (data, &bytes_read, end);
1431 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1433 case DW_OP_GNU_const_index:
1434 uvalue = read_uleb128 (data, &bytes_read, end);
1436 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1439 /* HP extensions. */
1440 case DW_OP_HP_is_value:
1441 printf ("DW_OP_HP_is_value");
1442 /* FIXME: Is there data associated with this OP ? */
1444 case DW_OP_HP_fltconst4:
1445 printf ("DW_OP_HP_fltconst4");
1446 /* FIXME: Is there data associated with this OP ? */
1448 case DW_OP_HP_fltconst8:
1449 printf ("DW_OP_HP_fltconst8");
1450 /* FIXME: Is there data associated with this OP ? */
1452 case DW_OP_HP_mod_range:
1453 printf ("DW_OP_HP_mod_range");
1454 /* FIXME: Is there data associated with this OP ? */
1456 case DW_OP_HP_unmod_range:
1457 printf ("DW_OP_HP_unmod_range");
1458 /* FIXME: Is there data associated with this OP ? */
1461 printf ("DW_OP_HP_tls");
1462 /* FIXME: Is there data associated with this OP ? */
1465 /* PGI (STMicroelectronics) extensions. */
1466 case DW_OP_PGI_omp_thread_num:
1467 /* Pushes the thread number for the current thread as it would be
1468 returned by the standard OpenMP library function:
1469 omp_get_thread_num(). The "current thread" is the thread for
1470 which the expression is being evaluated. */
1471 printf ("DW_OP_PGI_omp_thread_num");
1475 if (op >= DW_OP_lo_user
1476 && op <= DW_OP_hi_user)
1477 printf (_("(User defined location op 0x%x)"), op);
1479 printf (_("(Unknown location op 0x%x)"), op);
1480 /* No way to tell where the next op is, so just bail. */
1481 return need_frame_base;
1484 /* Separate the ops. */
1489 return need_frame_base;
1492 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1493 This is used for DWARF package files. */
1495 static struct cu_tu_set *
1496 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1498 struct cu_tu_set *p;
1500 unsigned int dw_sect;
1506 dw_sect = DW_SECT_TYPES;
1512 dw_sect = DW_SECT_INFO;
1516 if (p->section_offsets [dw_sect] == cu_offset)
1524 /* Add INC to HIGH_BITS:LOW_BITS. */
1526 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1528 dwarf_vma tmp = * low_bits;
1532 /* FIXME: There is probably a better way of handling this:
1534 We need to cope with dwarf_vma being a 32-bit or 64-bit
1535 type. Plus regardless of its size LOW_BITS is meant to
1536 only hold 32-bits, so if there is overflow or wrap around
1537 we must propagate into HIGH_BITS. */
1538 if (tmp < * low_bits)
1542 else if (sizeof (tmp) > 8
1552 static unsigned char *
1553 read_and_display_attr_value (unsigned long attribute,
1555 dwarf_signed_vma implicit_const,
1556 unsigned char * data,
1557 unsigned char * end,
1558 dwarf_vma cu_offset,
1559 dwarf_vma pointer_size,
1560 dwarf_vma offset_size,
1562 debug_info * debug_info_p,
1564 struct dwarf_section * section,
1565 struct cu_tu_set * this_set, char delimiter)
1567 dwarf_vma uvalue = 0;
1568 unsigned char *block_start = NULL;
1569 unsigned char * orig_data = data;
1570 unsigned int bytes_read;
1572 if (data > end || (data == end && form != DW_FORM_flag_present))
1574 warn (_("Corrupt attribute\n"));
1583 case DW_FORM_ref_addr:
1584 if (dwarf_version == 2)
1585 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1586 else if (dwarf_version == 3 || dwarf_version == 4)
1587 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1589 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1594 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1598 case DW_FORM_line_strp:
1599 case DW_FORM_sec_offset:
1600 case DW_FORM_GNU_ref_alt:
1601 case DW_FORM_GNU_strp_alt:
1602 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1605 case DW_FORM_flag_present:
1612 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1617 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1622 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1626 uvalue = read_sleb128 (data, & bytes_read, end);
1630 case DW_FORM_GNU_str_index:
1631 uvalue = read_uleb128 (data, & bytes_read, end);
1635 case DW_FORM_ref_udata:
1637 uvalue = read_uleb128 (data, & bytes_read, end);
1641 case DW_FORM_indirect:
1642 form = read_uleb128 (data, & bytes_read, end);
1645 printf ("%c%s", delimiter, get_FORM_name (form));
1646 if (form == DW_FORM_implicit_const)
1648 implicit_const = read_sleb128 (data, & bytes_read, end);
1651 return read_and_display_attr_value (attribute, form, implicit_const, data,
1652 end, cu_offset, pointer_size,
1653 offset_size, dwarf_version,
1654 debug_info_p, do_loc,
1655 section, this_set, delimiter);
1656 case DW_FORM_GNU_addr_index:
1657 uvalue = read_uleb128 (data, & bytes_read, end);
1664 case DW_FORM_ref_addr:
1666 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1669 case DW_FORM_GNU_ref_alt:
1671 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1677 case DW_FORM_ref_udata:
1679 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1684 case DW_FORM_sec_offset:
1686 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1689 case DW_FORM_flag_present:
1696 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1699 case DW_FORM_implicit_const:
1701 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1708 dwarf_vma high_bits;
1712 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1714 if (form == DW_FORM_ref8)
1715 add64 (& high_bits, & utmp, cu_offset);
1716 printf ("%c0x%s", delimiter,
1717 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1720 if ((do_loc || do_debug_loc || do_debug_ranges)
1721 && num_debug_info_entries == 0)
1723 if (sizeof (uvalue) == 8)
1724 SAFE_BYTE_GET (uvalue, data, 8, end);
1726 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1732 case DW_FORM_string:
1734 printf ("%c%.*s", delimiter, (int) (end - data), data);
1735 data += strnlen ((char *) data, end - data) + 1;
1739 case DW_FORM_exprloc:
1740 uvalue = read_uleb128 (data, & bytes_read, end);
1741 block_start = data + bytes_read;
1742 if (block_start >= end)
1744 warn (_("Block ends prematurely\n"));
1748 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1749 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1750 block_start + uvalue here. */
1751 data = block_start + uvalue;
1752 /* PR 17512: file: 008-103549-0.001:0.1. */
1753 if (block_start + uvalue > end || data < block_start)
1755 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1756 uvalue = end - block_start;
1759 data = block_start + uvalue;
1761 data = display_block (block_start, uvalue, end, delimiter);
1764 case DW_FORM_block1:
1765 SAFE_BYTE_GET (uvalue, data, 1, end);
1766 block_start = data + 1;
1767 if (block_start >= end)
1769 warn (_("Block ends prematurely\n"));
1773 data = block_start + uvalue;
1774 if (block_start + uvalue > end || data < block_start)
1776 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1777 uvalue = end - block_start;
1780 data = block_start + uvalue;
1782 data = display_block (block_start, uvalue, end, delimiter);
1785 case DW_FORM_block2:
1786 SAFE_BYTE_GET (uvalue, data, 2, end);
1787 block_start = data + 2;
1788 if (block_start >= end)
1790 warn (_("Block ends prematurely\n"));
1794 data = block_start + uvalue;
1795 if (block_start + uvalue > end || data < block_start)
1797 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1798 uvalue = end - block_start;
1801 data = block_start + uvalue;
1803 data = display_block (block_start, uvalue, end, delimiter);
1806 case DW_FORM_block4:
1807 SAFE_BYTE_GET (uvalue, data, 4, end);
1808 block_start = data + 4;
1809 /* PR 17512: file: 3371-3907-0.004. */
1810 if (block_start >= end)
1812 warn (_("Block ends prematurely\n"));
1816 data = block_start + uvalue;
1817 if (block_start + uvalue > end
1818 /* PR 17531: file: 5b5f0592. */
1819 || data < block_start)
1821 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1822 uvalue = end - block_start;
1825 data = block_start + uvalue;
1827 data = display_block (block_start, uvalue, end, delimiter);
1832 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1833 dwarf_vmatoa ("x", uvalue),
1834 fetch_indirect_string (uvalue));
1837 case DW_FORM_line_strp:
1839 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1840 dwarf_vmatoa ("x", uvalue),
1841 fetch_indirect_line_string (uvalue));
1844 case DW_FORM_GNU_str_index:
1847 const char *suffix = strrchr (section->name, '.');
1848 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1850 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1851 dwarf_vmatoa ("x", uvalue),
1852 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1856 case DW_FORM_GNU_strp_alt:
1858 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1859 dwarf_vmatoa ("x", uvalue));
1862 case DW_FORM_indirect:
1863 /* Handled above. */
1866 case DW_FORM_ref_sig8:
1869 dwarf_vma high_bits;
1872 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1873 printf ("%csignature: 0x%s", delimiter,
1874 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1879 case DW_FORM_GNU_addr_index:
1881 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
1882 dwarf_vmatoa ("x", uvalue),
1883 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1887 warn (_("Unrecognized form: %lu\n"), form);
1891 if ((do_loc || do_debug_loc || do_debug_ranges)
1892 && num_debug_info_entries == 0
1893 && debug_info_p != NULL)
1897 case DW_AT_frame_base:
1898 have_frame_base = 1;
1900 case DW_AT_location:
1901 case DW_AT_string_length:
1902 case DW_AT_return_addr:
1903 case DW_AT_data_member_location:
1904 case DW_AT_vtable_elem_location:
1906 case DW_AT_static_link:
1907 case DW_AT_use_location:
1908 case DW_AT_call_value:
1909 case DW_AT_GNU_call_site_value:
1910 case DW_AT_call_data_value:
1911 case DW_AT_GNU_call_site_data_value:
1912 case DW_AT_call_target:
1913 case DW_AT_GNU_call_site_target:
1914 case DW_AT_call_target_clobbered:
1915 case DW_AT_GNU_call_site_target_clobbered:
1916 if ((dwarf_version < 4
1917 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1918 || form == DW_FORM_sec_offset)
1920 /* Process location list. */
1921 unsigned int lmax = debug_info_p->max_loc_offsets;
1922 unsigned int num = debug_info_p->num_loc_offsets;
1924 if (lmax == 0 || num >= lmax)
1927 debug_info_p->loc_offsets = (dwarf_vma *)
1928 xcrealloc (debug_info_p->loc_offsets,
1929 lmax, sizeof (*debug_info_p->loc_offsets));
1930 debug_info_p->have_frame_base = (int *)
1931 xcrealloc (debug_info_p->have_frame_base,
1932 lmax, sizeof (*debug_info_p->have_frame_base));
1933 debug_info_p->max_loc_offsets = lmax;
1935 if (this_set != NULL)
1936 uvalue += this_set->section_offsets [DW_SECT_LOC];
1937 debug_info_p->loc_offsets [num] = uvalue;
1938 debug_info_p->have_frame_base [num] = have_frame_base;
1939 debug_info_p->num_loc_offsets++;
1944 if (need_base_address)
1945 debug_info_p->base_address = uvalue;
1948 case DW_AT_GNU_addr_base:
1949 debug_info_p->addr_base = uvalue;
1952 case DW_AT_GNU_ranges_base:
1953 debug_info_p->ranges_base = uvalue;
1957 if ((dwarf_version < 4
1958 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1959 || form == DW_FORM_sec_offset)
1961 /* Process range list. */
1962 unsigned int lmax = debug_info_p->max_range_lists;
1963 unsigned int num = debug_info_p->num_range_lists;
1965 if (lmax == 0 || num >= lmax)
1968 debug_info_p->range_lists = (dwarf_vma *)
1969 xcrealloc (debug_info_p->range_lists,
1970 lmax, sizeof (*debug_info_p->range_lists));
1971 debug_info_p->max_range_lists = lmax;
1973 debug_info_p->range_lists [num] = uvalue;
1974 debug_info_p->num_range_lists++;
1983 if (do_loc || attribute == 0)
1986 /* For some attributes we can display further information. */
1993 case DW_INL_not_inlined:
1994 printf (_("(not inlined)"));
1996 case DW_INL_inlined:
1997 printf (_("(inlined)"));
1999 case DW_INL_declared_not_inlined:
2000 printf (_("(declared as inline but ignored)"));
2002 case DW_INL_declared_inlined:
2003 printf (_("(declared as inline and inlined)"));
2006 printf (_(" (Unknown inline attribute value: %s)"),
2007 dwarf_vmatoa ("x", uvalue));
2012 case DW_AT_language:
2016 /* Ordered by the numeric value of these constants. */
2017 case DW_LANG_C89: printf ("(ANSI C)"); break;
2018 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2019 case DW_LANG_Ada83: printf ("(Ada)"); break;
2020 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2021 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2022 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2023 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2024 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2025 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2026 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2027 /* DWARF 2.1 values. */
2028 case DW_LANG_Java: printf ("(Java)"); break;
2029 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2030 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2031 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2032 /* DWARF 3 values. */
2033 case DW_LANG_PLI: printf ("(PLI)"); break;
2034 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2035 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2036 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2037 case DW_LANG_D: printf ("(D)"); break;
2038 /* DWARF 4 values. */
2039 case DW_LANG_Python: printf ("(Python)"); break;
2040 /* DWARF 5 values. */
2041 case DW_LANG_Go: printf ("(Go)"); break;
2042 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2043 case DW_LANG_C11: printf ("(C11)"); break;
2044 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2045 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2046 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2047 /* MIPS extension. */
2048 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2049 /* UPC extension. */
2050 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2052 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2053 printf (_("(implementation defined: %s)"),
2054 dwarf_vmatoa ("x", uvalue));
2056 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2061 case DW_AT_encoding:
2065 case DW_ATE_void: printf ("(void)"); break;
2066 case DW_ATE_address: printf ("(machine address)"); break;
2067 case DW_ATE_boolean: printf ("(boolean)"); break;
2068 case DW_ATE_complex_float: printf ("(complex float)"); break;
2069 case DW_ATE_float: printf ("(float)"); break;
2070 case DW_ATE_signed: printf ("(signed)"); break;
2071 case DW_ATE_signed_char: printf ("(signed char)"); break;
2072 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2073 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2074 /* DWARF 2.1 values: */
2075 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2076 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2077 /* DWARF 3 values: */
2078 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2079 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2080 case DW_ATE_edited: printf ("(edited)"); break;
2081 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2082 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2083 /* HP extensions: */
2084 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2085 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2086 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2087 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2088 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2089 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2090 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2091 /* DWARF 4 values: */
2092 case DW_ATE_UTF: printf ("(unicode string)"); break;
2095 if (uvalue >= DW_ATE_lo_user
2096 && uvalue <= DW_ATE_hi_user)
2097 printf (_("(user defined type)"));
2099 printf (_("(unknown type)"));
2104 case DW_AT_accessibility:
2108 case DW_ACCESS_public: printf ("(public)"); break;
2109 case DW_ACCESS_protected: printf ("(protected)"); break;
2110 case DW_ACCESS_private: printf ("(private)"); break;
2112 printf (_("(unknown accessibility)"));
2117 case DW_AT_visibility:
2121 case DW_VIS_local: printf ("(local)"); break;
2122 case DW_VIS_exported: printf ("(exported)"); break;
2123 case DW_VIS_qualified: printf ("(qualified)"); break;
2124 default: printf (_("(unknown visibility)")); break;
2128 case DW_AT_virtuality:
2132 case DW_VIRTUALITY_none: printf ("(none)"); break;
2133 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2134 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2135 default: printf (_("(unknown virtuality)")); break;
2139 case DW_AT_identifier_case:
2143 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2144 case DW_ID_up_case: printf ("(up_case)"); break;
2145 case DW_ID_down_case: printf ("(down_case)"); break;
2146 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2147 default: printf (_("(unknown case)")); break;
2151 case DW_AT_calling_convention:
2155 case DW_CC_normal: printf ("(normal)"); break;
2156 case DW_CC_program: printf ("(program)"); break;
2157 case DW_CC_nocall: printf ("(nocall)"); break;
2159 if (uvalue >= DW_CC_lo_user
2160 && uvalue <= DW_CC_hi_user)
2161 printf (_("(user defined)"));
2163 printf (_("(unknown convention)"));
2167 case DW_AT_ordering:
2171 case -1: printf (_("(undefined)")); break;
2172 case 0: printf ("(row major)"); break;
2173 case 1: printf ("(column major)"); break;
2177 case DW_AT_frame_base:
2178 have_frame_base = 1;
2180 case DW_AT_location:
2181 case DW_AT_string_length:
2182 case DW_AT_return_addr:
2183 case DW_AT_data_member_location:
2184 case DW_AT_vtable_elem_location:
2186 case DW_AT_static_link:
2187 case DW_AT_use_location:
2188 case DW_AT_call_value:
2189 case DW_AT_GNU_call_site_value:
2190 case DW_AT_call_data_value:
2191 case DW_AT_GNU_call_site_data_value:
2192 case DW_AT_call_target:
2193 case DW_AT_GNU_call_site_target:
2194 case DW_AT_call_target_clobbered:
2195 case DW_AT_GNU_call_site_target_clobbered:
2196 if ((dwarf_version < 4
2197 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2198 || form == DW_FORM_sec_offset)
2199 printf (_(" (location list)"));
2201 case DW_AT_allocated:
2202 case DW_AT_associated:
2203 case DW_AT_data_location:
2205 case DW_AT_upper_bound:
2206 case DW_AT_lower_bound:
2209 int need_frame_base;
2212 need_frame_base = decode_location_expression (block_start,
2217 cu_offset, section);
2219 if (need_frame_base && !have_frame_base)
2220 printf (_(" [without DW_AT_frame_base]"));
2226 if (form == DW_FORM_ref_sig8
2227 || form == DW_FORM_GNU_ref_alt)
2230 if (form == DW_FORM_ref1
2231 || form == DW_FORM_ref2
2232 || form == DW_FORM_ref4
2233 || form == DW_FORM_ref_udata)
2234 uvalue += cu_offset;
2236 if (uvalue >= section->size)
2237 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2238 dwarf_vmatoa ("x", uvalue),
2239 (unsigned long) (orig_data - section->start));
2242 unsigned long abbrev_number;
2243 abbrev_entry * entry;
2245 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2247 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2248 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2249 use different abbrev table, and we don't track .debug_info chunks
2251 if (form != DW_FORM_ref_addr)
2253 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2254 if (entry->entry == abbrev_number)
2257 printf (" (%s)", get_TAG_name (entry->tag));
2272 get_AT_name (unsigned long attribute)
2277 return "DW_AT value: 0";
2279 /* One value is shared by the MIPS and HP extensions: */
2280 if (attribute == DW_AT_MIPS_fde)
2281 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2283 name = get_DW_AT_name (attribute);
2287 static char buffer[100];
2289 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2297 static unsigned char *
2298 read_and_display_attr (unsigned long attribute,
2300 dwarf_signed_vma implicit_const,
2301 unsigned char * data,
2302 unsigned char * end,
2303 dwarf_vma cu_offset,
2304 dwarf_vma pointer_size,
2305 dwarf_vma offset_size,
2307 debug_info * debug_info_p,
2309 struct dwarf_section * section,
2310 struct cu_tu_set * this_set)
2313 printf (" %-18s:", get_AT_name (attribute));
2314 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2315 cu_offset, pointer_size, offset_size,
2316 dwarf_version, debug_info_p,
2317 do_loc, section, this_set, ' ');
2323 /* Process the contents of a .debug_info section. If do_loc is non-zero
2324 then we are scanning for location lists and we do not want to display
2325 anything to the user. If do_types is non-zero, we are processing
2326 a .debug_types section instead of a .debug_info section. */
2329 process_debug_info (struct dwarf_section *section,
2331 enum dwarf_section_display_enum abbrev_sec,
2335 unsigned char *start = section->start;
2336 unsigned char *end = start + section->size;
2337 unsigned char *section_begin;
2339 unsigned int num_units = 0;
2341 if ((do_loc || do_debug_loc || do_debug_ranges)
2342 && num_debug_info_entries == 0
2347 /* First scan the section to get the number of comp units. */
2348 for (section_begin = start, num_units = 0; section_begin < end;
2351 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2352 will be the length. For a 64-bit DWARF section, it'll be
2353 the escape code 0xffffffff followed by an 8 byte length. */
2354 SAFE_BYTE_GET (length, section_begin, 4, end);
2356 if (length == 0xffffffff)
2358 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2359 section_begin += length + 12;
2361 else if (length >= 0xfffffff0 && length < 0xffffffff)
2363 warn (_("Reserved length value (0x%s) found in section %s\n"),
2364 dwarf_vmatoa ("x", length), section->name);
2368 section_begin += length + 4;
2370 /* Negative values are illegal, they may even cause infinite
2371 looping. This can happen if we can't accurately apply
2372 relocations to an object file, or if the file is corrupt. */
2373 if ((signed long) length <= 0 || section_begin < start)
2375 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2376 dwarf_vmatoa ("x", length), section->name);
2383 error (_("No comp units in %s section ?\n"), section->name);
2387 /* Then allocate an array to hold the information. */
2388 debug_information = (debug_info *) cmalloc (num_units,
2389 sizeof (* debug_information));
2390 if (debug_information == NULL)
2392 error (_("Not enough memory for a debug info array of %u entries\n"),
2394 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2397 /* PR 17531: file: 92ca3797.
2398 We cannot rely upon the debug_information array being initialised
2399 before it is used. A corrupt file could easily contain references
2400 to a unit for which information has not been made available. So
2401 we ensure that the array is zeroed here. */
2402 memset (debug_information, 0, num_units * sizeof (*debug_information));
2404 alloc_num_debug_info_entries = num_units;
2409 if (dwarf_start_die == 0)
2410 printf (_("Contents of the %s section:\n\n"), section->name);
2412 load_debug_section (str, file);
2413 load_debug_section (line_str, file);
2414 load_debug_section (str_dwo, file);
2415 load_debug_section (str_index, file);
2416 load_debug_section (str_index_dwo, file);
2417 load_debug_section (debug_addr, file);
2420 load_debug_section (abbrev_sec, file);
2421 if (debug_displays [abbrev_sec].section.start == NULL)
2423 warn (_("Unable to locate %s section!\n"),
2424 debug_displays [abbrev_sec].section.name);
2428 for (section_begin = start, unit = 0; start < end; unit++)
2430 DWARF2_Internal_CompUnit compunit;
2431 unsigned char *hdrptr;
2432 unsigned char *tags;
2433 int level, last_level, saved_level;
2434 dwarf_vma cu_offset;
2435 unsigned int offset_size;
2436 int initial_length_size;
2437 dwarf_vma signature_high = 0;
2438 dwarf_vma signature_low = 0;
2439 dwarf_vma type_offset = 0;
2440 struct cu_tu_set *this_set;
2441 dwarf_vma abbrev_base;
2446 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2448 if (compunit.cu_length == 0xffffffff)
2450 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2452 initial_length_size = 12;
2457 initial_length_size = 4;
2460 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2462 cu_offset = start - section_begin;
2464 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2466 if (compunit.cu_version < 5)
2468 compunit.cu_unit_type = DW_UT_compile;
2469 /* Initialize it due to a false compiler warning. */
2470 compunit.cu_pointer_size = -1;
2474 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2475 do_types = (compunit.cu_unit_type == DW_UT_type);
2477 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2480 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2482 if (this_set == NULL)
2485 abbrev_size = debug_displays [abbrev_sec].section.size;
2489 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2490 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2493 if (compunit.cu_version < 5)
2494 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2496 /* PR 17512: file: 001-108546-0.001:0.1. */
2497 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2499 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2500 compunit.cu_pointer_size, offset_size);
2501 compunit.cu_pointer_size = offset_size;
2506 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2508 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2511 if ((do_loc || do_debug_loc || do_debug_ranges)
2512 && num_debug_info_entries == 0
2515 debug_information [unit].cu_offset = cu_offset;
2516 debug_information [unit].pointer_size
2517 = compunit.cu_pointer_size;
2518 debug_information [unit].offset_size = offset_size;
2519 debug_information [unit].dwarf_version = compunit.cu_version;
2520 debug_information [unit].base_address = 0;
2521 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2522 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2523 debug_information [unit].loc_offsets = NULL;
2524 debug_information [unit].have_frame_base = NULL;
2525 debug_information [unit].max_loc_offsets = 0;
2526 debug_information [unit].num_loc_offsets = 0;
2527 debug_information [unit].range_lists = NULL;
2528 debug_information [unit].max_range_lists= 0;
2529 debug_information [unit].num_range_lists = 0;
2532 if (!do_loc && dwarf_start_die == 0)
2534 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2535 dwarf_vmatoa ("x", cu_offset));
2536 printf (_(" Length: 0x%s (%s)\n"),
2537 dwarf_vmatoa ("x", compunit.cu_length),
2538 offset_size == 8 ? "64-bit" : "32-bit");
2539 printf (_(" Version: %d\n"), compunit.cu_version);
2540 printf (_(" Abbrev Offset: 0x%s\n"),
2541 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2542 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2547 printf (_(" Signature: 0x%s\n"),
2548 dwarf_vmatoa64 (signature_high, signature_low,
2549 buf, sizeof (buf)));
2550 printf (_(" Type Offset: 0x%s\n"),
2551 dwarf_vmatoa ("x", type_offset));
2553 if (this_set != NULL)
2555 dwarf_vma *offsets = this_set->section_offsets;
2556 size_t *sizes = this_set->section_sizes;
2558 printf (_(" Section contributions:\n"));
2559 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2560 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2561 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2562 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2563 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2564 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2565 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2566 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2567 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2568 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2569 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2570 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2574 if (cu_offset + compunit.cu_length + initial_length_size
2577 warn (_("Debug info is corrupted, length of CU at %s"
2578 " extends beyond end of section (length = %s)\n"),
2579 dwarf_vmatoa ("x", cu_offset),
2580 dwarf_vmatoa ("x", compunit.cu_length));
2585 start += compunit.cu_length + initial_length_size;
2589 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2590 dwarf_vmatoa ("x", cu_offset));
2594 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2596 warn (_("CU at offset %s contains corrupt or "
2597 "unsupported version number: %d.\n"),
2598 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2602 if (compunit.cu_unit_type != DW_UT_compile
2603 && compunit.cu_unit_type != DW_UT_type)
2605 warn (_("CU at offset %s contains corrupt or "
2606 "unsupported unit type: %d.\n"),
2607 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2613 /* Process the abbrevs used by this compilation unit. */
2614 if (compunit.cu_abbrev_offset >= abbrev_size)
2615 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2616 (unsigned long) compunit.cu_abbrev_offset,
2617 (unsigned long) abbrev_size);
2618 /* PR 17531: file:4bcd9ce9. */
2619 else if ((abbrev_base + abbrev_size)
2620 > debug_displays [abbrev_sec].section.size)
2621 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2622 (unsigned long) abbrev_base + abbrev_size,
2623 (unsigned long) debug_displays [abbrev_sec].section.size);
2625 process_abbrev_section
2626 (((unsigned char *) debug_displays [abbrev_sec].section.start
2627 + abbrev_base + compunit.cu_abbrev_offset),
2628 ((unsigned char *) debug_displays [abbrev_sec].section.start
2629 + abbrev_base + abbrev_size));
2634 while (tags < start)
2636 unsigned int bytes_read;
2637 unsigned long abbrev_number;
2638 unsigned long die_offset;
2639 abbrev_entry *entry;
2641 int do_printing = 1;
2643 die_offset = tags - section_begin;
2645 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2648 /* A null DIE marks the end of a list of siblings or it may also be
2649 a section padding. */
2650 if (abbrev_number == 0)
2652 /* Check if it can be a section padding for the last CU. */
2653 if (level == 0 && start == end)
2657 for (chk = tags; chk < start; chk++)
2664 if (!do_loc && die_offset >= dwarf_start_die
2665 && (dwarf_cutoff_level == -1
2666 || level < dwarf_cutoff_level))
2667 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2673 static unsigned num_bogus_warns = 0;
2675 if (num_bogus_warns < 3)
2677 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2678 die_offset, section->name);
2680 if (num_bogus_warns == 3)
2681 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2684 if (dwarf_start_die != 0 && level < saved_level)
2691 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2695 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2696 saved_level = level;
2697 do_printing = (dwarf_cutoff_level == -1
2698 || level < dwarf_cutoff_level);
2700 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2701 level, die_offset, abbrev_number);
2702 else if (dwarf_cutoff_level == -1
2703 || last_level < dwarf_cutoff_level)
2704 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2709 /* Scan through the abbreviation list until we reach the
2711 for (entry = first_abbrev;
2712 entry && entry->entry != abbrev_number;
2713 entry = entry->next)
2718 if (!do_loc && do_printing)
2723 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2724 die_offset, abbrev_number);
2728 if (!do_loc && do_printing)
2729 printf (" (%s)\n", get_TAG_name (entry->tag));
2734 need_base_address = 0;
2736 case DW_TAG_compile_unit:
2737 need_base_address = 1;
2739 case DW_TAG_entry_point:
2740 case DW_TAG_subprogram:
2741 need_base_address = 0;
2742 /* Assuming that there is no DW_AT_frame_base. */
2743 have_frame_base = 0;
2747 for (attr = entry->first_attr;
2748 attr && attr->attribute;
2753 if (! do_loc && do_printing)
2754 /* Show the offset from where the tag was extracted. */
2755 printf (" <%lx>", (unsigned long)(tags - section_begin));
2757 if (debug_information && unit < alloc_num_debug_info_entries)
2758 arg = debug_information + unit;
2762 tags = read_and_display_attr (attr->attribute,
2764 attr->implicit_const,
2768 compunit.cu_pointer_size,
2770 compunit.cu_version,
2772 do_loc || ! do_printing,
2777 if (entry->children)
2782 /* Set num_debug_info_entries here so that it can be used to check if
2783 we need to process .debug_loc and .debug_ranges sections. */
2784 if ((do_loc || do_debug_loc || do_debug_ranges)
2785 && num_debug_info_entries == 0
2788 if (num_units > alloc_num_debug_info_entries)
2789 num_debug_info_entries = alloc_num_debug_info_entries;
2791 num_debug_info_entries = num_units;
2800 /* Locate and scan the .debug_info section in the file and record the pointer
2801 sizes and offsets for the compilation units in it. Usually an executable
2802 will have just one pointer size, but this is not guaranteed, and so we try
2803 not to make any assumptions. Returns zero upon failure, or the number of
2804 compilation units upon success. */
2807 load_debug_info (void * file)
2809 /* Reset the last pointer size so that we can issue correct error
2810 messages if we are displaying the contents of more than one section. */
2811 last_pointer_size = 0;
2812 warned_about_missing_comp_units = FALSE;
2814 /* If we have already tried and failed to load the .debug_info
2815 section then do not bother to repeat the task. */
2816 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2819 /* If we already have the information there is nothing else to do. */
2820 if (num_debug_info_entries > 0)
2821 return num_debug_info_entries;
2823 /* If this is a DWARF package file, load the CU and TU indexes. */
2824 (void) load_cu_tu_indexes (file);
2826 if (load_debug_section (info, file)
2827 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2828 return num_debug_info_entries;
2830 if (load_debug_section (info_dwo, file)
2831 && process_debug_info (&debug_displays [info_dwo].section, file,
2833 return num_debug_info_entries;
2835 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2839 /* Read a DWARF .debug_line section header starting at DATA.
2840 Upon success returns an updated DATA pointer and the LINFO
2841 structure and the END_OF_SEQUENCE pointer will be filled in.
2842 Otherwise returns NULL. */
2844 static unsigned char *
2845 read_debug_line_header (struct dwarf_section * section,
2846 unsigned char * data,
2847 unsigned char * end,
2848 DWARF2_Internal_LineInfo * linfo,
2849 unsigned char ** end_of_sequence)
2851 unsigned char *hdrptr;
2852 unsigned int initial_length_size;
2853 unsigned char address_size, segment_selector_size;
2855 /* Extract information from the Line Number Program Header.
2856 (section 6.2.4 in the Dwarf3 doc). */
2859 /* Get and check the length of the block. */
2860 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2862 if (linfo->li_length == 0xffffffff)
2864 /* This section is 64-bit DWARF 3. */
2865 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2866 linfo->li_offset_size = 8;
2867 initial_length_size = 12;
2871 linfo->li_offset_size = 4;
2872 initial_length_size = 4;
2875 if (linfo->li_length + initial_length_size > section->size)
2877 /* If the length field has a relocation against it, then we should
2878 not complain if it is inaccurate (and probably negative). This
2879 happens in object files when the .debug_line section is actually
2880 comprised of several different .debug_line.* sections, (some of
2881 which may be removed by linker garbage collection), and a relocation
2882 is used to compute the correct length once that is done. */
2883 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
2885 linfo->li_length = (end - data) - initial_length_size;
2889 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2890 (long) linfo->li_length);
2895 /* Get and check the version number. */
2896 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2898 if (linfo->li_version != 2
2899 && linfo->li_version != 3
2900 && linfo->li_version != 4
2901 && linfo->li_version != 5)
2903 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
2904 "is currently supported.\n"));
2908 if (linfo->li_version >= 5)
2910 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
2912 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
2913 if (segment_selector_size != 0)
2915 warn (_("The %s section contains "
2916 "unsupported segment selector size: %d.\n"),
2917 section->name, segment_selector_size);
2922 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
2923 linfo->li_offset_size, end);
2924 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2926 if (linfo->li_version >= 4)
2928 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2930 if (linfo->li_max_ops_per_insn == 0)
2932 warn (_("Invalid maximum operations per insn.\n"));
2937 linfo->li_max_ops_per_insn = 1;
2939 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2940 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2941 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2942 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2944 * end_of_sequence = data + linfo->li_length + initial_length_size;
2945 /* PR 17512: file:002-117414-0.004. */
2946 if (* end_of_sequence > end)
2948 warn (_("Line length %s extends beyond end of section\n"),
2949 dwarf_vmatoa ("u", linfo->li_length));
2950 * end_of_sequence = end;
2957 static unsigned char *
2958 display_formatted_table (unsigned char *data,
2959 unsigned char *start, unsigned char *end,
2960 const DWARF2_Internal_LineInfo *linfo,
2961 struct dwarf_section *section, const char *what)
2963 unsigned char *format_start, format_count, *format, formati;
2964 dwarf_vma data_count, datai;
2965 unsigned int bytes_read, namepass, last_entry = 0;
2967 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
2968 format_start = data;
2969 for (formati = 0; formati < format_count; formati++)
2971 read_uleb128 (data, & bytes_read, end);
2973 read_uleb128 (data, & bytes_read, end);
2977 warn (_("Corrupt %s entry format table entry\n"), what);
2982 data_count = read_uleb128 (data, & bytes_read, end);
2986 warn (_("Corrupt %s list\n"), what);
2990 if (data_count == 0)
2992 printf (_("\n The %s Table is empty.\n"), what);
2996 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
2997 (long)(data - start));
2999 printf (_(" Entry"));
3000 /* Delay displaying name as the last entry for better screen layout. */
3001 for (namepass = 0; namepass < 2; namepass++)
3003 format = format_start;
3004 for (formati = 0; formati < format_count; formati++)
3006 dwarf_vma content_type;
3008 content_type = read_uleb128 (format, & bytes_read, end);
3009 format += bytes_read;
3010 if ((content_type == DW_LNCT_path) == (namepass == 1))
3011 switch (content_type)
3014 printf (_("\tName"));
3016 case DW_LNCT_directory_index:
3017 printf (_("\tDir"));
3019 case DW_LNCT_timestamp:
3020 printf (_("\tTime"));
3023 printf (_("\tSize"));
3026 printf (_("\tMD5"));
3029 printf (_("\t(Unknown format content type %s)"),
3030 dwarf_vmatoa ("u", content_type));
3032 read_uleb128 (format, & bytes_read, end);
3033 format += bytes_read;
3038 for (datai = 0; datai < data_count; datai++)
3040 unsigned char *datapass = data;
3042 printf (" %d", last_entry++);
3043 /* Delay displaying name as the last entry for better screen layout. */
3044 for (namepass = 0; namepass < 2; namepass++)
3046 format = format_start;
3048 for (formati = 0; formati < format_count; formati++)
3050 dwarf_vma content_type, form;
3052 content_type = read_uleb128 (format, & bytes_read, end);
3053 format += bytes_read;
3054 form = read_uleb128 (format, & bytes_read, end);
3055 format += bytes_read;
3056 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3057 linfo->li_offset_size,
3058 linfo->li_version, NULL,
3059 ((content_type == DW_LNCT_path) != (namepass == 1)),
3060 section, NULL, '\t');
3065 warn (_("Corrupt %s entries list\n"), what);
3074 display_debug_lines_raw (struct dwarf_section *section,
3075 unsigned char *data,
3076 unsigned char *end, void *file)
3078 unsigned char *start = section->start;
3080 printf (_("Raw dump of debug contents of section %s:\n\n"),
3085 static DWARF2_Internal_LineInfo saved_linfo;
3086 DWARF2_Internal_LineInfo linfo;
3087 unsigned char *standard_opcodes;
3088 unsigned char *end_of_sequence;
3091 if (const_strneq (section->name, ".debug_line.")
3092 /* Note: the following does not apply to .debug_line.dwo sections.
3093 These are full debug_line sections. */
3094 && strcmp (section->name, ".debug_line.dwo") != 0)
3096 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3097 section containing just the Line Number Statements. They are
3098 created by the assembler and intended to be used alongside gcc's
3099 -ffunction-sections command line option. When the linker's
3100 garbage collection decides to discard a .text.<foo> section it
3101 can then also discard the line number information in .debug_line.<foo>.
3103 Since the section is a fragment it does not have the details
3104 needed to fill out a LineInfo structure, so instead we use the
3105 details from the last full debug_line section that we processed. */
3106 end_of_sequence = end;
3107 standard_opcodes = NULL;
3108 linfo = saved_linfo;
3109 /* PR 17531: file: 0522b371. */
3110 if (linfo.li_line_range == 0)
3112 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3115 reset_state_machine (linfo.li_default_is_stmt);
3119 unsigned char * hdrptr;
3121 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3122 & end_of_sequence)) == NULL)
3125 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3126 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3127 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3128 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3129 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3130 if (linfo.li_version >= 4)
3131 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3132 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3133 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3134 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3135 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3137 /* PR 17512: file: 1665-6428-0.004. */
3138 if (linfo.li_line_range == 0)
3140 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3141 linfo.li_line_range = 1;
3144 reset_state_machine (linfo.li_default_is_stmt);
3146 /* Display the contents of the Opcodes table. */
3147 standard_opcodes = hdrptr;
3149 /* PR 17512: file: 002-417945-0.004. */
3150 if (standard_opcodes + linfo.li_opcode_base >= end)
3152 warn (_("Line Base extends beyond end of section\n"));
3156 printf (_("\n Opcodes:\n"));
3158 for (i = 1; i < linfo.li_opcode_base; i++)
3159 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3161 /* Display the contents of the Directory table. */
3162 data = standard_opcodes + linfo.li_opcode_base - 1;
3164 if (linfo.li_version >= 5)
3166 load_debug_section (line_str, file);
3168 data = display_formatted_table (data, start, end, &linfo, section,
3170 data = display_formatted_table (data, start, end, &linfo, section,
3176 printf (_("\n The Directory Table is empty.\n"));
3179 unsigned int last_dir_entry = 0;
3181 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3182 (long)(data - start));
3184 while (data < end && *data != 0)
3186 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3188 data += strnlen ((char *) data, end - data) + 1;
3191 /* PR 17512: file: 002-132094-0.004. */
3192 if (data >= end - 1)
3196 /* Skip the NUL at the end of the table. */
3199 /* Display the contents of the File Name table. */
3201 printf (_("\n The File Name Table is empty.\n"));
3204 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3205 (long)(data - start));
3206 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3208 while (data < end && *data != 0)
3210 unsigned char *name;
3211 unsigned int bytes_read;
3213 printf (" %d\t", ++state_machine_regs.last_file_entry);
3215 data += strnlen ((char *) data, end - data) + 1;
3218 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3221 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3224 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3226 printf ("%.*s\n", (int)(end - name), name);
3230 warn (_("Corrupt file name table entry\n"));
3236 /* Skip the NUL at the end of the table. */
3241 saved_linfo = linfo;
3244 /* Now display the statements. */
3245 if (data >= end_of_sequence)
3246 printf (_(" No Line Number Statements.\n"));
3249 printf (_(" Line Number Statements:\n"));
3251 while (data < end_of_sequence)
3253 unsigned char op_code;
3254 dwarf_signed_vma adv;
3256 unsigned int bytes_read;
3258 printf (" [0x%08lx]", (long)(data - start));
3262 if (op_code >= linfo.li_opcode_base)
3264 op_code -= linfo.li_opcode_base;
3265 uladv = (op_code / linfo.li_line_range);
3266 if (linfo.li_max_ops_per_insn == 1)
3268 uladv *= linfo.li_min_insn_length;
3269 state_machine_regs.address += uladv;
3270 printf (_(" Special opcode %d: "
3271 "advance Address by %s to 0x%s"),
3272 op_code, dwarf_vmatoa ("u", uladv),
3273 dwarf_vmatoa ("x", state_machine_regs.address));
3277 state_machine_regs.address
3278 += ((state_machine_regs.op_index + uladv)
3279 / linfo.li_max_ops_per_insn)
3280 * linfo.li_min_insn_length;
3281 state_machine_regs.op_index
3282 = (state_machine_regs.op_index + uladv)
3283 % linfo.li_max_ops_per_insn;
3284 printf (_(" Special opcode %d: "
3285 "advance Address by %s to 0x%s[%d]"),
3286 op_code, dwarf_vmatoa ("u", uladv),
3287 dwarf_vmatoa ("x", state_machine_regs.address),
3288 state_machine_regs.op_index);
3290 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3291 state_machine_regs.line += adv;
3292 printf (_(" and Line by %s to %d\n"),
3293 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3295 else switch (op_code)
3297 case DW_LNS_extended_op:
3298 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3302 printf (_(" Copy\n"));
3305 case DW_LNS_advance_pc:
3306 uladv = read_uleb128 (data, & bytes_read, end);
3308 if (linfo.li_max_ops_per_insn == 1)
3310 uladv *= linfo.li_min_insn_length;
3311 state_machine_regs.address += uladv;
3312 printf (_(" Advance PC by %s to 0x%s\n"),
3313 dwarf_vmatoa ("u", uladv),
3314 dwarf_vmatoa ("x", state_machine_regs.address));
3318 state_machine_regs.address
3319 += ((state_machine_regs.op_index + uladv)
3320 / linfo.li_max_ops_per_insn)
3321 * linfo.li_min_insn_length;
3322 state_machine_regs.op_index
3323 = (state_machine_regs.op_index + uladv)
3324 % linfo.li_max_ops_per_insn;
3325 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3326 dwarf_vmatoa ("u", uladv),
3327 dwarf_vmatoa ("x", state_machine_regs.address),
3328 state_machine_regs.op_index);
3332 case DW_LNS_advance_line:
3333 adv = read_sleb128 (data, & bytes_read, end);
3335 state_machine_regs.line += adv;
3336 printf (_(" Advance Line by %s to %d\n"),
3337 dwarf_vmatoa ("d", adv),
3338 state_machine_regs.line);
3341 case DW_LNS_set_file:
3342 adv = read_uleb128 (data, & bytes_read, end);
3344 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3345 dwarf_vmatoa ("d", adv));
3346 state_machine_regs.file = adv;
3349 case DW_LNS_set_column:
3350 uladv = read_uleb128 (data, & bytes_read, end);
3352 printf (_(" Set column to %s\n"),
3353 dwarf_vmatoa ("u", uladv));
3354 state_machine_regs.column = uladv;
3357 case DW_LNS_negate_stmt:
3358 adv = state_machine_regs.is_stmt;
3360 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3361 state_machine_regs.is_stmt = adv;
3364 case DW_LNS_set_basic_block:
3365 printf (_(" Set basic block\n"));
3366 state_machine_regs.basic_block = 1;
3369 case DW_LNS_const_add_pc:
3370 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3371 if (linfo.li_max_ops_per_insn)
3373 uladv *= linfo.li_min_insn_length;
3374 state_machine_regs.address += uladv;
3375 printf (_(" Advance PC by constant %s to 0x%s\n"),
3376 dwarf_vmatoa ("u", uladv),
3377 dwarf_vmatoa ("x", state_machine_regs.address));
3381 state_machine_regs.address
3382 += ((state_machine_regs.op_index + uladv)
3383 / linfo.li_max_ops_per_insn)
3384 * linfo.li_min_insn_length;
3385 state_machine_regs.op_index
3386 = (state_machine_regs.op_index + uladv)
3387 % linfo.li_max_ops_per_insn;
3388 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3389 dwarf_vmatoa ("u", uladv),
3390 dwarf_vmatoa ("x", state_machine_regs.address),
3391 state_machine_regs.op_index);
3395 case DW_LNS_fixed_advance_pc:
3396 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3397 state_machine_regs.address += uladv;
3398 state_machine_regs.op_index = 0;
3399 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3400 dwarf_vmatoa ("u", uladv),
3401 dwarf_vmatoa ("x", state_machine_regs.address));
3404 case DW_LNS_set_prologue_end:
3405 printf (_(" Set prologue_end to true\n"));
3408 case DW_LNS_set_epilogue_begin:
3409 printf (_(" Set epilogue_begin to true\n"));
3412 case DW_LNS_set_isa:
3413 uladv = read_uleb128 (data, & bytes_read, end);
3415 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3419 printf (_(" Unknown opcode %d with operands: "), op_code);
3421 if (standard_opcodes != NULL)
3422 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3424 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3426 i == 1 ? "" : ", ");
3442 unsigned char *name;
3443 unsigned int directory_index;
3444 unsigned int modification_date;
3445 unsigned int length;
3448 /* Output a decoded representation of the .debug_line section. */
3451 display_debug_lines_decoded (struct dwarf_section *section,
3452 unsigned char *data,
3453 unsigned char *end, void *fileptr)
3455 static DWARF2_Internal_LineInfo saved_linfo;
3457 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3462 /* This loop amounts to one iteration per compilation unit. */
3463 DWARF2_Internal_LineInfo linfo;
3464 unsigned char *standard_opcodes;
3465 unsigned char *end_of_sequence;
3467 File_Entry *file_table = NULL;
3468 unsigned int n_files = 0;
3469 unsigned char **directory_table = NULL;
3470 dwarf_vma n_directories = 0;
3472 if (const_strneq (section->name, ".debug_line.")
3473 /* Note: the following does not apply to .debug_line.dwo sections.
3474 These are full debug_line sections. */
3475 && strcmp (section->name, ".debug_line.dwo") != 0)
3477 /* See comment in display_debug_lines_raw(). */
3478 end_of_sequence = end;
3479 standard_opcodes = NULL;
3480 linfo = saved_linfo;
3481 /* PR 17531: file: 0522b371. */
3482 if (linfo.li_line_range == 0)
3484 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3487 reset_state_machine (linfo.li_default_is_stmt);
3491 unsigned char *hdrptr;
3493 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3494 & end_of_sequence)) == NULL)
3497 /* PR 17531: file: 0522b371. */
3498 if (linfo.li_line_range == 0)
3500 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3501 linfo.li_line_range = 1;
3503 reset_state_machine (linfo.li_default_is_stmt);
3505 /* Save a pointer to the contents of the Opcodes table. */
3506 standard_opcodes = hdrptr;
3508 /* Traverse the Directory table just to count entries. */
3509 data = standard_opcodes + linfo.li_opcode_base - 1;
3513 warn (_("opcode base of %d extends beyond end of section\n"),
3514 linfo.li_opcode_base);
3518 if (linfo.li_version >= 5)
3520 unsigned char *format_start, format_count, *format;
3521 dwarf_vma formati, entryi;
3522 unsigned int bytes_read;
3524 load_debug_section (line_str, fileptr);
3526 /* Skip directories format. */
3527 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3528 format_start = data;
3529 for (formati = 0; formati < format_count; formati++)
3531 read_uleb128 (data, & bytes_read, end);
3533 read_uleb128 (data, & bytes_read, end);
3537 n_directories = read_uleb128 (data, & bytes_read, end);
3541 warn (_("Corrupt directories list\n"));
3545 directory_table = (unsigned char **)
3546 xmalloc (n_directories * sizeof (unsigned char *));
3548 for (entryi = 0; entryi < n_directories; entryi++)
3550 unsigned char **pathp = &directory_table[entryi];
3552 format = format_start;
3553 for (formati = 0; formati < format_count; formati++)
3555 dwarf_vma content_type, form;
3558 content_type = read_uleb128 (format, & bytes_read, end);
3559 format += bytes_read;
3560 form = read_uleb128 (format, & bytes_read, end);
3561 format += bytes_read;
3564 warn (_("Corrupt directories list\n"));
3567 switch (content_type)
3572 case DW_FORM_string:
3575 case DW_FORM_line_strp:
3576 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3578 /* Remove const by the cast. */
3579 *pathp = (unsigned char *)
3580 fetch_indirect_line_string (uvalue);
3585 data = read_and_display_attr_value (0, form, 0, data, end,
3587 linfo.li_offset_size,
3594 warn (_("Corrupt directories list\n"));
3599 /* Skip files format. */
3600 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3601 format_start = data;
3602 for (formati = 0; formati < format_count; formati++)
3604 read_uleb128 (data, & bytes_read, end);
3606 read_uleb128 (data, & bytes_read, end);
3610 n_files = read_uleb128 (data, & bytes_read, end);
3614 warn (_("Corrupt file name list\n"));
3618 file_table = (File_Entry *) xcalloc (1, n_files
3619 * sizeof (File_Entry));
3621 for (entryi = 0; entryi < n_files; entryi++)
3623 File_Entry *file = &file_table[entryi];
3625 format = format_start;
3626 for (formati = 0; formati < format_count; formati++)
3628 dwarf_vma content_type, form;
3631 content_type = read_uleb128 (format, & bytes_read, end);
3632 format += bytes_read;
3633 form = read_uleb128 (format, & bytes_read, end);
3634 format += bytes_read;
3637 warn (_("Corrupt file name list\n"));
3640 switch (content_type)
3645 case DW_FORM_string:
3648 case DW_FORM_line_strp:
3649 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3651 /* Remove const by the cast. */
3652 file->name = (unsigned char *)
3653 fetch_indirect_line_string (uvalue);
3657 case DW_LNCT_directory_index:
3661 SAFE_BYTE_GET (file->directory_index, data, 1,
3665 SAFE_BYTE_GET (file->directory_index, data, 2,
3669 file->directory_index = read_uleb128 (data, NULL,
3675 data = read_and_display_attr_value (0, form, 0, data, end,
3677 linfo.li_offset_size,
3684 warn (_("Corrupt file name list\n"));
3693 unsigned char *ptr_directory_table = data;
3695 while (data < end && *data != 0)
3697 data += strnlen ((char *) data, end - data) + 1;
3704 warn (_("directory table ends unexpectedly\n"));
3709 /* Go through the directory table again to save the directories. */
3710 directory_table = (unsigned char **)
3711 xmalloc (n_directories * sizeof (unsigned char *));
3714 while (*ptr_directory_table != 0)
3716 directory_table[i] = ptr_directory_table;
3717 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3718 ptr_directory_table - end) + 1;
3722 /* Skip the NUL at the end of the table. */
3725 /* Traverse the File Name table just to count the entries. */
3726 if (data < end && *data != 0)
3728 unsigned char *ptr_file_name_table = data;
3730 while (data < end && *data != 0)
3732 unsigned int bytes_read;
3734 /* Skip Name, directory index, last modification time and length
3736 data += strnlen ((char *) data, end - data) + 1;
3737 read_uleb128 (data, & bytes_read, end);
3739 read_uleb128 (data, & bytes_read, end);
3741 read_uleb128 (data, & bytes_read, end);
3749 warn (_("file table ends unexpectedly\n"));
3754 /* Go through the file table again to save the strings. */
3755 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3758 while (*ptr_file_name_table != 0)
3760 unsigned int bytes_read;
3762 file_table[i].name = ptr_file_name_table;
3763 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3764 end - ptr_file_name_table) + 1;
3766 /* We are not interested in directory, time or size. */
3767 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3769 ptr_file_name_table += bytes_read;
3770 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3772 ptr_file_name_table += bytes_read;
3773 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3774 ptr_file_name_table += bytes_read;
3780 /* Skip the NUL at the end of the table. */
3784 /* Print the Compilation Unit's name and a header. */
3785 if (directory_table == NULL)
3787 printf (_("CU: %s:\n"), file_table[0].name);
3788 printf (_("File name Line number Starting address\n"));
3792 unsigned int ix = file_table[0].directory_index;
3793 const char *directory;
3798 else if (n_directories == 0)
3799 directory = _("<unknown>");
3800 else if (ix > n_directories)
3802 warn (_("directory index %u > number of directories %s\n"),
3803 ix, dwarf_vmatoa ("u", n_directories));
3804 directory = _("<corrupt>");
3807 directory = (char *) directory_table[ix - 1];
3809 if (do_wide || strlen (directory) < 76)
3810 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3812 printf ("%s:\n", file_table[0].name);
3814 printf (_("File name Line number Starting address\n"));
3817 saved_linfo = linfo;
3820 /* This loop iterates through the Dwarf Line Number Program. */
3821 while (data < end_of_sequence)
3823 unsigned char op_code;
3825 unsigned long int uladv;
3826 unsigned int bytes_read;
3827 int is_special_opcode = 0;
3831 if (op_code >= linfo.li_opcode_base)
3833 op_code -= linfo.li_opcode_base;
3834 uladv = (op_code / linfo.li_line_range);
3835 if (linfo.li_max_ops_per_insn == 1)
3837 uladv *= linfo.li_min_insn_length;
3838 state_machine_regs.address += uladv;
3842 state_machine_regs.address
3843 += ((state_machine_regs.op_index + uladv)
3844 / linfo.li_max_ops_per_insn)
3845 * linfo.li_min_insn_length;
3846 state_machine_regs.op_index
3847 = (state_machine_regs.op_index + uladv)
3848 % linfo.li_max_ops_per_insn;
3851 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3852 state_machine_regs.line += adv;
3853 is_special_opcode = 1;
3855 else switch (op_code)
3857 case DW_LNS_extended_op:
3859 unsigned int ext_op_code_len;
3860 unsigned char ext_op_code;
3861 unsigned char *op_code_data = data;
3863 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3865 op_code_data += bytes_read;
3867 if (ext_op_code_len == 0)
3869 warn (_("Badly formed extended line op encountered!\n"));
3872 ext_op_code_len += bytes_read;
3873 ext_op_code = *op_code_data++;
3875 switch (ext_op_code)
3877 case DW_LNE_end_sequence:
3878 reset_state_machine (linfo.li_default_is_stmt);
3880 case DW_LNE_set_address:
3881 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3883 ext_op_code_len - bytes_read - 1,
3885 state_machine_regs.op_index = 0;
3887 case DW_LNE_define_file:
3889 file_table = (File_Entry *) xrealloc
3890 (file_table, (n_files + 1) * sizeof (File_Entry));
3892 ++state_machine_regs.last_file_entry;
3893 /* Source file name. */
3894 file_table[n_files].name = op_code_data;
3895 op_code_data += strlen ((char *) op_code_data) + 1;
3896 /* Directory index. */
3897 file_table[n_files].directory_index =
3898 read_uleb128 (op_code_data, & bytes_read,
3900 op_code_data += bytes_read;
3901 /* Last modification time. */
3902 file_table[n_files].modification_date =
3903 read_uleb128 (op_code_data, & bytes_read,
3905 op_code_data += bytes_read;
3907 file_table[n_files].length =
3908 read_uleb128 (op_code_data, & bytes_read,
3914 case DW_LNE_set_discriminator:
3915 case DW_LNE_HP_set_sequence:
3916 /* Simply ignored. */
3920 printf (_("UNKNOWN (%u): length %d\n"),
3921 ext_op_code, ext_op_code_len - bytes_read);
3924 data += ext_op_code_len;
3930 case DW_LNS_advance_pc:
3931 uladv = read_uleb128 (data, & bytes_read, end);
3933 if (linfo.li_max_ops_per_insn == 1)
3935 uladv *= linfo.li_min_insn_length;
3936 state_machine_regs.address += uladv;
3940 state_machine_regs.address
3941 += ((state_machine_regs.op_index + uladv)
3942 / linfo.li_max_ops_per_insn)
3943 * linfo.li_min_insn_length;
3944 state_machine_regs.op_index
3945 = (state_machine_regs.op_index + uladv)
3946 % linfo.li_max_ops_per_insn;
3950 case DW_LNS_advance_line:
3951 adv = read_sleb128 (data, & bytes_read, end);
3953 state_machine_regs.line += adv;
3956 case DW_LNS_set_file:
3957 adv = read_uleb128 (data, & bytes_read, end);
3959 state_machine_regs.file = adv;
3962 unsigned file = state_machine_regs.file - 1;
3965 if (file_table == NULL || n_files == 0)
3966 printf (_("\n [Use file table entry %d]\n"), file);
3968 else if (file >= n_files)
3970 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
3971 printf (_("\n <over large file table index %u>"), file);
3973 else if ((dir = file_table[file].directory_index) == 0)
3974 /* If directory index is 0, that means current directory. */
3975 printf ("\n./%s:[++]\n", file_table[file].name);
3976 else if (directory_table == NULL || n_directories == 0)
3977 printf (_("\n [Use file %s in directory table entry %d]\n"),
3978 file_table[file].name, dir);
3980 else if (dir > n_directories)
3982 warn (_("directory index %u > number of directories %s\n"),
3983 dir, dwarf_vmatoa ("u", n_directories));
3984 printf (_("\n <over large directory table entry %u>\n"), dir);
3987 printf ("\n%s/%s:\n",
3988 /* The directory index starts counting at 1. */
3989 directory_table[dir - 1], file_table[file].name);
3993 case DW_LNS_set_column:
3994 uladv = read_uleb128 (data, & bytes_read, end);
3996 state_machine_regs.column = uladv;
3999 case DW_LNS_negate_stmt:
4000 adv = state_machine_regs.is_stmt;
4002 state_machine_regs.is_stmt = adv;
4005 case DW_LNS_set_basic_block:
4006 state_machine_regs.basic_block = 1;
4009 case DW_LNS_const_add_pc:
4010 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4011 if (linfo.li_max_ops_per_insn == 1)
4013 uladv *= linfo.li_min_insn_length;
4014 state_machine_regs.address += uladv;
4018 state_machine_regs.address
4019 += ((state_machine_regs.op_index + uladv)
4020 / linfo.li_max_ops_per_insn)
4021 * linfo.li_min_insn_length;
4022 state_machine_regs.op_index
4023 = (state_machine_regs.op_index + uladv)
4024 % linfo.li_max_ops_per_insn;
4028 case DW_LNS_fixed_advance_pc:
4029 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4030 state_machine_regs.address += uladv;
4031 state_machine_regs.op_index = 0;
4034 case DW_LNS_set_prologue_end:
4037 case DW_LNS_set_epilogue_begin:
4040 case DW_LNS_set_isa:
4041 uladv = read_uleb128 (data, & bytes_read, end);
4043 printf (_(" Set ISA to %lu\n"), uladv);
4047 printf (_(" Unknown opcode %d with operands: "), op_code);
4049 if (standard_opcodes != NULL)
4050 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4052 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4054 i == 1 ? "" : ", ");
4061 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4062 to the DWARF address/line matrix. */
4063 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
4064 || (op_code == DW_LNS_copy))
4066 const unsigned int MAX_FILENAME_LENGTH = 35;
4068 char *newFileName = NULL;
4069 size_t fileNameLength;
4073 unsigned indx = state_machine_regs.file - 1;
4075 if (indx >= n_files)
4077 warn (_("corrupt file index %u encountered\n"), indx);
4078 fileName = _("<corrupt>");
4081 fileName = (char *) file_table[indx].name;
4084 fileName = _("<unknown>");
4086 fileNameLength = strlen (fileName);
4088 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4090 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4091 /* Truncate file name */
4092 strncpy (newFileName,
4093 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4094 MAX_FILENAME_LENGTH + 1);
4098 newFileName = (char *) xmalloc (fileNameLength + 1);
4099 strncpy (newFileName, fileName, fileNameLength + 1);
4102 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4104 if (linfo.li_max_ops_per_insn == 1)
4105 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
4106 newFileName, state_machine_regs.line,
4107 state_machine_regs.address);
4109 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4110 newFileName, state_machine_regs.line,
4111 state_machine_regs.address,
4112 state_machine_regs.op_index);
4116 if (linfo.li_max_ops_per_insn == 1)
4117 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
4118 newFileName, state_machine_regs.line,
4119 state_machine_regs.address);
4121 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4122 newFileName, state_machine_regs.line,
4123 state_machine_regs.address,
4124 state_machine_regs.op_index);
4127 if (op_code == DW_LNE_end_sequence)
4141 if (directory_table)
4143 free (directory_table);
4144 directory_table = NULL;
4155 display_debug_lines (struct dwarf_section *section, void *file)
4157 unsigned char *data = section->start;
4158 unsigned char *end = data + section->size;
4160 int retValDecoded = 1;
4162 if (do_debug_lines == 0)
4163 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4165 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4166 retValRaw = display_debug_lines_raw (section, data, end, file);
4168 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4169 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4171 if (!retValRaw || !retValDecoded)
4178 find_debug_info_for_offset (unsigned long offset)
4182 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4185 for (i = 0; i < num_debug_info_entries; i++)
4186 if (debug_information[i].cu_offset == offset)
4187 return debug_information + i;
4193 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4195 /* See gdb/gdb-index.h. */
4196 static const char * const kinds[] =
4208 return _ (kinds[kind]);
4212 display_debug_pubnames_worker (struct dwarf_section *section,
4213 void *file ATTRIBUTE_UNUSED,
4216 DWARF2_Internal_PubNames names;
4217 unsigned char *start = section->start;
4218 unsigned char *end = start + section->size;
4220 /* It does not matter if this load fails,
4221 we test for that later on. */
4222 load_debug_info (file);
4224 printf (_("Contents of the %s section:\n\n"), section->name);
4228 unsigned char *data;
4231 unsigned int offset_size, initial_length_size;
4235 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4236 if (names.pn_length == 0xffffffff)
4238 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4240 initial_length_size = 12;
4245 initial_length_size = 4;
4248 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4249 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4251 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4252 && num_debug_info_entries > 0
4253 && find_debug_info_for_offset (names.pn_offset) == NULL)
4254 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4255 (unsigned long) names.pn_offset, section->name);
4257 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4259 adr = start + names.pn_length + initial_length_size;
4260 /* PR 17531: file: 7615b6b2. */
4261 if ((dwarf_signed_vma) names.pn_length < 0
4262 /* PR 17531: file: a5dbeaa7. */
4265 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4271 printf (_(" Length: %ld\n"),
4272 (long) names.pn_length);
4273 printf (_(" Version: %d\n"),
4275 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4276 (unsigned long) names.pn_offset);
4277 printf (_(" Size of area in .debug_info section: %ld\n"),
4278 (long) names.pn_size);
4280 if (names.pn_version != 2 && names.pn_version != 3)
4282 static int warned = 0;
4286 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4294 printf (_("\n Offset Kind Name\n"));
4296 printf (_("\n Offset\tName\n"));
4300 bfd_size_type maxprint;
4302 SAFE_BYTE_GET (offset, data, offset_size, end);
4306 data += offset_size;
4309 maxprint = (end - data) - 1;
4313 unsigned int kind_data;
4314 gdb_index_symbol_kind kind;
4315 const char *kind_name;
4318 SAFE_BYTE_GET (kind_data, data, 1, end);
4321 /* GCC computes the kind as the upper byte in the CU index
4322 word, and then right shifts it by the CU index size.
4323 Left shift KIND to where the gdb-index.h accessor macros
4325 kind_data <<= GDB_INDEX_CU_BITSIZE;
4326 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4327 kind_name = get_gdb_index_symbol_kind_name (kind);
4328 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4329 printf (" %-6lx %s,%-10s %.*s\n",
4330 (unsigned long) offset, is_static ? _("s") : _("g"),
4331 kind_name, (int) maxprint, data);
4334 printf (" %-6lx\t%.*s\n",
4335 (unsigned long) offset, (int) maxprint, data);
4337 data += strnlen ((char *) data, maxprint) + 1;
4342 while (offset != 0);
4350 display_debug_pubnames (struct dwarf_section *section, void *file)
4352 return display_debug_pubnames_worker (section, file, 0);
4356 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4358 return display_debug_pubnames_worker (section, file, 1);
4362 display_debug_macinfo (struct dwarf_section *section,
4363 void *file ATTRIBUTE_UNUSED)
4365 unsigned char *start = section->start;
4366 unsigned char *end = start + section->size;
4367 unsigned char *curr = start;
4368 unsigned int bytes_read;
4369 enum dwarf_macinfo_record_type op;
4371 printf (_("Contents of the %s section:\n\n"), section->name);
4375 unsigned int lineno;
4376 const unsigned char *string;
4378 op = (enum dwarf_macinfo_record_type) *curr;
4383 case DW_MACINFO_start_file:
4385 unsigned int filenum;
4387 lineno = read_uleb128 (curr, & bytes_read, end);
4389 filenum = read_uleb128 (curr, & bytes_read, end);
4392 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4397 case DW_MACINFO_end_file:
4398 printf (_(" DW_MACINFO_end_file\n"));
4401 case DW_MACINFO_define:
4402 lineno = read_uleb128 (curr, & bytes_read, end);
4405 curr += strnlen ((char *) string, end - string) + 1;
4406 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4410 case DW_MACINFO_undef:
4411 lineno = read_uleb128 (curr, & bytes_read, end);
4414 curr += strnlen ((char *) string, end - string) + 1;
4415 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4419 case DW_MACINFO_vendor_ext:
4421 unsigned int constant;
4423 constant = read_uleb128 (curr, & bytes_read, end);
4426 curr += strnlen ((char *) string, end - string) + 1;
4427 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4437 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4438 filename and dirname corresponding to file name table entry with index
4439 FILEIDX. Return NULL on failure. */
4441 static unsigned char *
4442 get_line_filename_and_dirname (dwarf_vma line_offset,
4444 unsigned char **dir_name)
4446 struct dwarf_section *section = &debug_displays [line].section;
4447 unsigned char *hdrptr, *dirtable, *file_name;
4448 unsigned int offset_size, initial_length_size;
4449 unsigned int version, opcode_base, bytes_read;
4450 dwarf_vma length, diridx;
4451 const unsigned char * end;
4454 if (section->start == NULL
4455 || line_offset >= section->size
4459 hdrptr = section->start + line_offset;
4460 end = section->start + section->size;
4462 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4463 if (length == 0xffffffff)
4465 /* This section is 64-bit DWARF 3. */
4466 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4468 initial_length_size = 12;
4473 initial_length_size = 4;
4475 if (length + initial_length_size > section->size)
4478 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4479 if (version != 2 && version != 3 && version != 4)
4481 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4483 hdrptr++; /* Skip max_ops_per_insn. */
4484 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4486 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4487 if (opcode_base == 0)
4490 hdrptr += opcode_base - 1;
4492 /* Skip over dirname table. */
4493 while (*hdrptr != '\0')
4494 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4495 hdrptr++; /* Skip the NUL at the end of the table. */
4496 /* Now skip over preceding filename table entries. */
4497 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4499 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4500 read_uleb128 (hdrptr, &bytes_read, end);
4501 hdrptr += bytes_read;
4502 read_uleb128 (hdrptr, &bytes_read, end);
4503 hdrptr += bytes_read;
4504 read_uleb128 (hdrptr, &bytes_read, end);
4505 hdrptr += bytes_read;
4507 if (hdrptr == end || *hdrptr == '\0')
4510 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4511 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4514 for (; *dirtable != '\0' && diridx > 1; diridx--)
4515 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4516 if (*dirtable == '\0')
4518 *dir_name = dirtable;
4523 display_debug_macro (struct dwarf_section *section,
4526 unsigned char *start = section->start;
4527 unsigned char *end = start + section->size;
4528 unsigned char *curr = start;
4529 unsigned char *extended_op_buf[256];
4530 unsigned int bytes_read;
4532 load_debug_section (str, file);
4533 load_debug_section (line, file);
4535 printf (_("Contents of the %s section:\n\n"), section->name);
4539 unsigned int lineno, version, flags;
4540 unsigned int offset_size = 4;
4541 const unsigned char *string;
4542 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4543 unsigned char **extended_ops = NULL;
4545 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4546 if (version != 4 && version != 5)
4548 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4553 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4556 printf (_(" Offset: 0x%lx\n"),
4557 (unsigned long) sec_offset);
4558 printf (_(" Version: %d\n"), version);
4559 printf (_(" Offset size: %d\n"), offset_size);
4562 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4563 printf (_(" Offset into .debug_line: 0x%lx\n"),
4564 (unsigned long) line_offset);
4568 unsigned int i, count, op;
4571 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4573 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4574 extended_ops = extended_op_buf;
4577 printf (_(" Extension opcode arguments:\n"));
4578 for (i = 0; i < count; i++)
4580 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4581 extended_ops[op] = curr;
4582 nargs = read_uleb128 (curr, &bytes_read, end);
4585 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4588 printf (_(" DW_MACRO_%02x arguments: "), op);
4589 for (n = 0; n < nargs; n++)
4593 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4594 printf ("%s%s", get_FORM_name (form),
4595 n == nargs - 1 ? "\n" : ", ");
4605 case DW_FORM_block1:
4606 case DW_FORM_block2:
4607 case DW_FORM_block4:
4609 case DW_FORM_string:
4611 case DW_FORM_sec_offset:
4614 error (_("Invalid extension opcode form %s\n"),
4615 get_FORM_name (form));
4631 error (_(".debug_macro section not zero terminated\n"));
4635 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4641 case DW_MACRO_start_file:
4643 unsigned int filenum;
4644 unsigned char *file_name = NULL, *dir_name = NULL;
4646 lineno = read_uleb128 (curr, &bytes_read, end);
4648 filenum = read_uleb128 (curr, &bytes_read, end);
4651 if ((flags & 2) == 0)
4652 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4655 = get_line_filename_and_dirname (line_offset, filenum,
4657 if (file_name == NULL)
4658 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4661 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4663 dir_name != NULL ? (const char *) dir_name : "",
4664 dir_name != NULL ? "/" : "", file_name);
4668 case DW_MACRO_end_file:
4669 printf (_(" DW_MACRO_end_file\n"));
4672 case DW_MACRO_define:
4673 lineno = read_uleb128 (curr, &bytes_read, end);
4676 curr += strnlen ((char *) string, end - string) + 1;
4677 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4681 case DW_MACRO_undef:
4682 lineno = read_uleb128 (curr, &bytes_read, end);
4685 curr += strnlen ((char *) string, end - string) + 1;
4686 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4690 case DW_MACRO_define_strp:
4691 lineno = read_uleb128 (curr, &bytes_read, end);
4693 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4694 string = fetch_indirect_string (offset);
4695 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4699 case DW_MACRO_undef_strp:
4700 lineno = read_uleb128 (curr, &bytes_read, end);
4702 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4703 string = fetch_indirect_string (offset);
4704 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4708 case DW_MACRO_import:
4709 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4710 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4711 (unsigned long) offset);
4714 case DW_MACRO_define_sup:
4715 lineno = read_uleb128 (curr, &bytes_read, end);
4717 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4718 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4719 lineno, (unsigned long) offset);
4722 case DW_MACRO_undef_sup:
4723 lineno = read_uleb128 (curr, &bytes_read, end);
4725 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4726 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4727 lineno, (unsigned long) offset);
4730 case DW_MACRO_import_sup:
4731 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4732 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4733 (unsigned long) offset);
4737 if (extended_ops == NULL || extended_ops[op] == NULL)
4739 error (_(" Unknown macro opcode %02x seen\n"), op);
4744 /* Skip over unhandled opcodes. */
4746 unsigned char *desc = extended_ops[op];
4747 nargs = read_uleb128 (desc, &bytes_read, end);
4751 printf (_(" DW_MACRO_%02x\n"), op);
4754 printf (_(" DW_MACRO_%02x -"), op);
4755 for (n = 0; n < nargs; n++)
4759 /* DW_FORM_implicit_const is not expected here. */
4760 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4762 = read_and_display_attr_value (0, val, 0,
4763 curr, end, 0, 0, offset_size,
4764 version, NULL, 0, NULL,
4782 display_debug_abbrev (struct dwarf_section *section,
4783 void *file ATTRIBUTE_UNUSED)
4785 abbrev_entry *entry;
4786 unsigned char *start = section->start;
4787 unsigned char *end = start + section->size;
4789 printf (_("Contents of the %s section:\n\n"), section->name);
4793 unsigned char *last;
4798 start = process_abbrev_section (start, end);
4800 if (first_abbrev == NULL)
4803 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4805 for (entry = first_abbrev; entry; entry = entry->next)
4809 printf (" %ld %s [%s]\n",
4811 get_TAG_name (entry->tag),
4812 entry->children ? _("has children") : _("no children"));
4814 for (attr = entry->first_attr; attr; attr = attr->next)
4816 printf (" %-18s %s",
4817 get_AT_name (attr->attribute),
4818 get_FORM_name (attr->form));
4819 if (attr->form == DW_FORM_implicit_const)
4820 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
4832 /* Return true when ADDR is the maximum address, when addresses are
4833 POINTER_SIZE bytes long. */
4836 is_max_address (dwarf_vma addr, unsigned int pointer_size)
4838 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
4839 return ((addr & mask) == mask);
4842 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4845 display_loc_list (struct dwarf_section *section,
4846 unsigned char **start_ptr,
4847 unsigned int debug_info_entry,
4849 dwarf_vma base_address,
4852 unsigned char *start = *start_ptr;
4853 unsigned char *section_end = section->start + section->size;
4854 unsigned long cu_offset;
4855 unsigned int pointer_size;
4856 unsigned int offset_size;
4861 unsigned short length;
4862 int need_frame_base;
4864 if (debug_info_entry >= num_debug_info_entries)
4866 warn (_("No debug information available for loc lists of entry: %u\n"),
4871 cu_offset = debug_information [debug_info_entry].cu_offset;
4872 pointer_size = debug_information [debug_info_entry].pointer_size;
4873 offset_size = debug_information [debug_info_entry].offset_size;
4874 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4876 if (pointer_size < 2 || pointer_size > 8)
4878 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4879 pointer_size, debug_info_entry);
4885 dwarf_vma off = offset + (start - *start_ptr);
4887 if (start + 2 * pointer_size > section_end)
4889 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4890 (unsigned long) offset);
4894 printf (" %8.8lx ", (unsigned long) off);
4896 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4897 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4899 if (begin == 0 && end == 0)
4901 /* PR 18374: In a object file we can have a location list that
4902 starts with a begin and end of 0 because there are relocations
4903 that need to be applied to the addresses. Actually applying
4904 the relocations now does not help as they will probably resolve
4905 to 0, since the object file has not been fully linked. Real
4906 end of list markers will not have any relocations against them. */
4907 if (! reloc_at (section, off)
4908 && ! reloc_at (section, off + pointer_size))
4910 printf (_("<End of list>\n"));
4915 /* Check base address specifiers. */
4916 if (is_max_address (begin, pointer_size)
4917 && !is_max_address (end, pointer_size))
4920 print_dwarf_vma (begin, pointer_size);
4921 print_dwarf_vma (end, pointer_size);
4922 printf (_("(base address)\n"));
4926 if (start + 2 > section_end)
4928 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4929 (unsigned long) offset);
4933 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4935 if (start + length > section_end)
4937 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4938 (unsigned long) offset);
4942 print_dwarf_vma (begin + base_address, pointer_size);
4943 print_dwarf_vma (end + base_address, pointer_size);
4946 need_frame_base = decode_location_expression (start,
4951 cu_offset, section);
4954 if (need_frame_base && !has_frame_base)
4955 printf (_(" [without DW_AT_frame_base]"));
4958 fputs (_(" (start == end)"), stdout);
4959 else if (begin > end)
4960 fputs (_(" (start > end)"), stdout);
4970 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
4973 display_loclists_list (struct dwarf_section *section,
4974 unsigned char **start_ptr,
4975 unsigned int debug_info_entry,
4977 dwarf_vma base_address,
4980 unsigned char *start = *start_ptr;
4981 unsigned char *section_end = section->start + section->size;
4982 unsigned long cu_offset;
4983 unsigned int pointer_size;
4984 unsigned int offset_size;
4986 unsigned int bytes_read;
4991 int need_frame_base;
4993 if (debug_info_entry >= num_debug_info_entries)
4995 warn (_("No debug information available for "
4996 "loclists lists of entry: %u\n"),
5001 cu_offset = debug_information [debug_info_entry].cu_offset;
5002 pointer_size = debug_information [debug_info_entry].pointer_size;
5003 offset_size = debug_information [debug_info_entry].offset_size;
5004 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5006 if (pointer_size < 2 || pointer_size > 8)
5008 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5009 pointer_size, debug_info_entry);
5015 dwarf_vma off = offset + (start - *start_ptr);
5016 enum dwarf_location_list_entry_type llet;
5018 if (start + 1 > section_end)
5020 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5021 (unsigned long) offset);
5025 printf (" %8.8lx ", (unsigned long) off);
5027 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5031 case DW_LLE_end_of_list:
5032 printf (_("<End of list>\n"));
5034 case DW_LLE_offset_pair:
5035 begin = read_uleb128 (start, &bytes_read, section_end);
5036 start += bytes_read;
5037 end = read_uleb128 (start, &bytes_read, section_end);
5038 start += bytes_read;
5040 case DW_LLE_base_address:
5041 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5043 print_dwarf_vma (base_address, pointer_size);
5044 printf (_("(base address)\n"));
5047 error (_("Invalid location list entry type %d\n"), llet);
5050 if (llet == DW_LLE_end_of_list)
5052 if (llet != DW_LLE_offset_pair)
5055 if (start + 2 > section_end)
5057 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5058 (unsigned long) offset);
5062 length = read_uleb128 (start, &bytes_read, section_end);
5063 start += bytes_read;
5065 print_dwarf_vma (begin + base_address, pointer_size);
5066 print_dwarf_vma (end + base_address, pointer_size);
5069 need_frame_base = decode_location_expression (start,
5074 cu_offset, section);
5077 if (need_frame_base && !has_frame_base)
5078 printf (_(" [without DW_AT_frame_base]"));
5081 fputs (_(" (start == end)"), stdout);
5082 else if (begin > end)
5083 fputs (_(" (start > end)"), stdout);
5093 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5094 right-adjusted in a field of length LEN, and followed by a space. */
5097 print_addr_index (unsigned int idx, unsigned int len)
5099 static char buf[15];
5100 snprintf (buf, sizeof (buf), "[%d]", idx);
5101 printf ("%*s ", len, buf);
5104 /* Display a location list from a .dwo section. It uses address indexes rather
5105 than embedded addresses. This code closely follows display_loc_list, but the
5106 two are sufficiently different that combining things is very ugly. */
5109 display_loc_list_dwo (struct dwarf_section *section,
5110 unsigned char **start_ptr,
5111 unsigned int debug_info_entry,
5115 unsigned char *start = *start_ptr;
5116 unsigned char *section_end = section->start + section->size;
5117 unsigned long cu_offset;
5118 unsigned int pointer_size;
5119 unsigned int offset_size;
5122 unsigned short length;
5123 int need_frame_base;
5125 unsigned int bytes_read;
5127 if (debug_info_entry >= num_debug_info_entries)
5129 warn (_("No debug information for loc lists of entry: %u\n"),
5134 cu_offset = debug_information [debug_info_entry].cu_offset;
5135 pointer_size = debug_information [debug_info_entry].pointer_size;
5136 offset_size = debug_information [debug_info_entry].offset_size;
5137 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5139 if (pointer_size < 2 || pointer_size > 8)
5141 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5142 pointer_size, debug_info_entry);
5148 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5150 if (start >= section_end)
5152 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5153 (unsigned long) offset);
5157 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5160 case 0: /* A terminating entry. */
5162 printf (_("<End of list>\n"));
5164 case 1: /* A base-address entry. */
5165 idx = read_uleb128 (start, &bytes_read, section_end);
5166 start += bytes_read;
5167 print_addr_index (idx, 8);
5169 printf (_("(base address selection entry)\n"));
5171 case 2: /* A start/end entry. */
5172 idx = read_uleb128 (start, &bytes_read, section_end);
5173 start += bytes_read;
5174 print_addr_index (idx, 8);
5175 idx = read_uleb128 (start, &bytes_read, section_end);
5176 start += bytes_read;
5177 print_addr_index (idx, 8);
5179 case 3: /* A start/length entry. */
5180 idx = read_uleb128 (start, &bytes_read, section_end);
5181 start += bytes_read;
5182 print_addr_index (idx, 8);
5183 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5184 printf ("%08x ", idx);
5186 case 4: /* An offset pair entry. */
5187 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5188 printf ("%08x ", idx);
5189 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5190 printf ("%08x ", idx);
5193 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5198 if (start + 2 > section_end)
5200 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5201 (unsigned long) offset);
5205 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5206 if (start + length > section_end)
5208 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5209 (unsigned long) offset);
5214 need_frame_base = decode_location_expression (start,
5219 cu_offset, section);
5222 if (need_frame_base && !has_frame_base)
5223 printf (_(" [without DW_AT_frame_base]"));
5233 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5235 static dwarf_vma *loc_offsets;
5238 loc_offsets_compar (const void *ap, const void *bp)
5240 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5241 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5243 return (a > b) - (b > a);
5247 display_debug_loc (struct dwarf_section *section, void *file)
5249 unsigned char *start = section->start;
5250 unsigned long bytes;
5251 unsigned char *section_begin = start;
5252 unsigned int num_loc_list = 0;
5253 unsigned long last_offset = 0;
5254 unsigned int first = 0;
5257 int seen_first_offset = 0;
5258 int locs_sorted = 1;
5259 unsigned char *next;
5260 unsigned int *array = NULL;
5261 const char *suffix = strrchr (section->name, '.');
5263 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5264 dwarf_vma expected_start = 0;
5266 if (suffix && strcmp (suffix, ".dwo") == 0)
5269 bytes = section->size;
5273 printf (_("\nThe %s section is empty.\n"), section->name);
5279 unsigned char *hdrptr = section_begin;
5280 dwarf_vma ll_length;
5281 unsigned short ll_version;
5282 unsigned char *end = section_begin + section->size;
5283 unsigned char address_size, segment_selector_size;
5284 uint32_t offset_entry_count;
5286 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5287 if (ll_length == 0xffffffff)
5288 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5290 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5291 if (ll_version != 5)
5293 warn (_("The %s section contains corrupt or "
5294 "unsupported version number: %d.\n"),
5295 section->name, ll_version);
5299 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5301 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5302 if (segment_selector_size != 0)
5304 warn (_("The %s section contains "
5305 "unsupported segment selector size: %d.\n"),
5306 section->name, segment_selector_size);
5310 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5311 if (offset_entry_count != 0)
5313 warn (_("The %s section contains "
5314 "unsupported offset entry count: %d.\n"),
5315 section->name, offset_entry_count);
5319 expected_start = hdrptr - section_begin;
5322 if (load_debug_info (file) == 0)
5324 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5329 /* Check the order of location list in .debug_info section. If
5330 offsets of location lists are in the ascending order, we can
5331 use `debug_information' directly. */
5332 for (i = 0; i < num_debug_info_entries; i++)
5336 num = debug_information [i].num_loc_offsets;
5337 if (num > num_loc_list)
5340 /* Check if we can use `debug_information' directly. */
5341 if (locs_sorted && num != 0)
5343 if (!seen_first_offset)
5345 /* This is the first location list. */
5346 last_offset = debug_information [i].loc_offsets [0];
5348 seen_first_offset = 1;
5354 for (; j < num; j++)
5357 debug_information [i].loc_offsets [j])
5362 last_offset = debug_information [i].loc_offsets [j];
5367 if (!seen_first_offset)
5368 error (_("No location lists in .debug_info section!\n"));
5370 if (debug_information [first].num_loc_offsets > 0
5371 && debug_information [first].loc_offsets [0] != expected_start)
5372 warn (_("Location lists in %s section start at 0x%s\n"),
5374 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5377 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5378 printf (_("Contents of the %s section:\n\n"), section->name);
5379 if (reloc_at (section, 0))
5380 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5381 printf (_(" Offset Begin End Expression\n"));
5383 seen_first_offset = 0;
5384 for (i = first; i < num_debug_info_entries; i++)
5387 dwarf_vma base_address;
5393 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5395 loc_offsets = debug_information [i].loc_offsets;
5396 qsort (array, debug_information [i].num_loc_offsets,
5397 sizeof (*array), loc_offsets_compar);
5400 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5402 j = locs_sorted ? k : array[k];
5404 && debug_information [i].loc_offsets [locs_sorted
5405 ? k - 1 : array [k - 1]]
5406 == debug_information [i].loc_offsets [j])
5408 has_frame_base = debug_information [i].have_frame_base [j];
5409 offset = debug_information [i].loc_offsets [j];
5410 next = section_begin + offset;
5411 base_address = debug_information [i].base_address;
5413 if (!seen_first_offset)
5414 seen_first_offset = 1;
5418 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5419 (unsigned long) (start - section_begin),
5420 (unsigned long) offset);
5421 else if (start > next)
5422 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5423 (unsigned long) (start - section_begin),
5424 (unsigned long) offset);
5428 if (offset >= bytes)
5430 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5431 (unsigned long) offset);
5438 display_loc_list_dwo (section, &start, i, offset,
5441 display_loc_list (section, &start, i, offset, base_address,
5447 warn (_("DWO is not yet supported.\n"));
5449 display_loclists_list (section, &start, i, offset, base_address,
5455 if (start < section->start + section->size)
5456 warn (_("There are %ld unused bytes at the end of section %s\n"),
5457 (long) (section->start + section->size - start), section->name);
5464 display_debug_str (struct dwarf_section *section,
5465 void *file ATTRIBUTE_UNUSED)
5467 unsigned char *start = section->start;
5468 unsigned long bytes = section->size;
5469 dwarf_vma addr = section->address;
5473 printf (_("\nThe %s section is empty.\n"), section->name);
5477 printf (_("Contents of the %s section:\n\n"), section->name);
5485 lbytes = (bytes > 16 ? 16 : bytes);
5487 printf (" 0x%8.8lx ", (unsigned long) addr);
5489 for (j = 0; j < 16; j++)
5492 printf ("%2.2x", start[j]);
5500 for (j = 0; j < lbytes; j++)
5503 if (k >= ' ' && k < 0x80)
5522 display_debug_info (struct dwarf_section *section, void *file)
5524 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5528 display_debug_types (struct dwarf_section *section, void *file)
5530 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5534 display_trace_info (struct dwarf_section *section, void *file)
5536 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5540 display_debug_aranges (struct dwarf_section *section,
5541 void *file ATTRIBUTE_UNUSED)
5543 unsigned char *start = section->start;
5544 unsigned char *end = start + section->size;
5546 printf (_("Contents of the %s section:\n\n"), section->name);
5548 /* It does not matter if this load fails,
5549 we test for that later on. */
5550 load_debug_info (file);
5554 unsigned char *hdrptr;
5555 DWARF2_Internal_ARange arange;
5556 unsigned char *addr_ranges;
5559 unsigned char address_size;
5561 unsigned int offset_size;
5562 unsigned int initial_length_size;
5566 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
5567 if (arange.ar_length == 0xffffffff)
5569 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
5571 initial_length_size = 12;
5576 initial_length_size = 4;
5579 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
5580 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
5582 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5583 && num_debug_info_entries > 0
5584 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
5585 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5586 (unsigned long) arange.ar_info_offset, section->name);
5588 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
5589 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
5591 if (arange.ar_version != 2 && arange.ar_version != 3)
5593 /* PR 19872: A version number of 0 probably means that there is
5594 padding at the end of the .debug_aranges section. Gold puts
5595 it there when performing an incremental link, for example.
5596 So do not generate a warning in this case. */
5597 if (arange.ar_version)
5598 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5602 printf (_(" Length: %ld\n"),
5603 (long) arange.ar_length);
5604 printf (_(" Version: %d\n"), arange.ar_version);
5605 printf (_(" Offset into .debug_info: 0x%lx\n"),
5606 (unsigned long) arange.ar_info_offset);
5607 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5608 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5610 address_size = arange.ar_pointer_size + arange.ar_segment_size;
5612 /* PR 17512: file: 001-108546-0.001:0.1. */
5613 if (address_size == 0 || address_size > 8)
5615 error (_("Invalid address size in %s section!\n"),
5620 /* The DWARF spec does not require that the address size be a power
5621 of two, but we do. This will have to change if we ever encounter
5622 an uneven architecture. */
5623 if ((address_size & (address_size - 1)) != 0)
5625 warn (_("Pointer size + Segment size is not a power of two.\n"));
5629 if (address_size > 4)
5630 printf (_("\n Address Length\n"));
5632 printf (_("\n Address Length\n"));
5634 addr_ranges = hdrptr;
5636 /* Must pad to an alignment boundary that is twice the address size. */
5637 excess = (hdrptr - start) % (2 * address_size);
5639 addr_ranges += (2 * address_size) - excess;
5641 hdrptr = start + arange.ar_length + initial_length_size;
5642 if (hdrptr < start || hdrptr > end)
5644 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5649 while (addr_ranges + 2 * address_size <= start)
5651 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5652 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5655 print_dwarf_vma (address, address_size);
5656 print_dwarf_vma (length, address_size);
5666 /* Comparison function for qsort. */
5668 comp_addr_base (const void * v0, const void * v1)
5670 debug_info * info0 = (debug_info *) v0;
5671 debug_info * info1 = (debug_info *) v1;
5672 return info0->addr_base - info1->addr_base;
5675 /* Display the debug_addr section. */
5677 display_debug_addr (struct dwarf_section *section,
5680 debug_info **debug_addr_info;
5681 unsigned char *entry;
5686 if (section->size == 0)
5688 printf (_("\nThe %s section is empty.\n"), section->name);
5692 if (load_debug_info (file) == 0)
5694 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5699 printf (_("Contents of the %s section:\n\n"), section->name);
5701 /* PR 17531: file: cf38d01b.
5702 We use xcalloc because a corrupt file may not have initialised all of the
5703 fields in the debug_info structure, which means that the sort below might
5704 try to move uninitialised data. */
5705 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5706 sizeof (debug_info *));
5709 for (i = 0; i < num_debug_info_entries; i++)
5710 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5712 /* PR 17531: file: cf38d01b. */
5713 if (debug_information[i].addr_base >= section->size)
5714 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5715 (unsigned long) debug_information[i].addr_base, i);
5717 debug_addr_info [count++] = debug_information + i;
5720 /* Add a sentinel to make iteration convenient. */
5721 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5722 debug_addr_info [count]->addr_base = section->size;
5723 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5725 for (i = 0; i < count; i++)
5728 unsigned int address_size = debug_addr_info [i]->pointer_size;
5730 printf (_(" For compilation unit at offset 0x%s:\n"),
5731 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5733 printf (_("\tIndex\tAddress\n"));
5734 entry = section->start + debug_addr_info [i]->addr_base;
5735 end = section->start + debug_addr_info [i + 1]->addr_base;
5739 dwarf_vma base = byte_get (entry, address_size);
5740 printf (_("\t%d:\t"), idx);
5741 print_dwarf_vma (base, address_size);
5743 entry += address_size;
5749 free (debug_addr_info);
5753 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5755 display_debug_str_offsets (struct dwarf_section *section,
5756 void *file ATTRIBUTE_UNUSED)
5758 if (section->size == 0)
5760 printf (_("\nThe %s section is empty.\n"), section->name);
5763 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5764 what the offset size is for this section. */
5768 /* Each debug_information[x].range_lists[y] gets this representation for
5769 sorting purposes. */
5773 /* The debug_information[x].range_lists[y] value. */
5774 dwarf_vma ranges_offset;
5776 /* Original debug_information to find parameters of the data. */
5777 debug_info *debug_info_p;
5780 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5783 range_entry_compar (const void *ap, const void *bp)
5785 const struct range_entry *a_re = (const struct range_entry *) ap;
5786 const struct range_entry *b_re = (const struct range_entry *) bp;
5787 const dwarf_vma a = a_re->ranges_offset;
5788 const dwarf_vma b = b_re->ranges_offset;
5790 return (a > b) - (b > a);
5794 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
5795 unsigned int pointer_size, unsigned long offset,
5796 unsigned long base_address)
5798 while (start < finish)
5803 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5804 if (start >= finish)
5806 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5808 printf (" %8.8lx ", offset);
5810 if (begin == 0 && end == 0)
5812 printf (_("<End of list>\n"));
5816 /* Check base address specifiers. */
5817 if (is_max_address (begin, pointer_size)
5818 && !is_max_address (end, pointer_size))
5821 print_dwarf_vma (begin, pointer_size);
5822 print_dwarf_vma (end, pointer_size);
5823 printf ("(base address)\n");
5827 print_dwarf_vma (begin + base_address, pointer_size);
5828 print_dwarf_vma (end + base_address, pointer_size);
5831 fputs (_("(start == end)"), stdout);
5832 else if (begin > end)
5833 fputs (_("(start > end)"), stdout);
5840 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
5841 unsigned int pointer_size, unsigned long offset,
5842 unsigned long base_address)
5844 unsigned char *next = start;
5848 unsigned long off = offset + (start - next);
5849 enum dwarf_range_list_entry rlet;
5850 dwarf_vma begin, length, end;
5851 unsigned int bytes_read;
5853 if (start + 1 > finish)
5855 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
5860 printf (" %8.8lx ", off);
5862 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
5866 case DW_RLE_end_of_list:
5867 printf (_("<End of list>\n"));
5869 case DW_RLE_base_address:
5870 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
5871 print_dwarf_vma (base_address, pointer_size);
5872 printf (_("(base address)\n"));
5874 case DW_RLE_start_length:
5875 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5876 length = read_uleb128 (start, &bytes_read, finish);
5877 start += bytes_read;
5878 end = begin + length;
5880 case DW_RLE_offset_pair:
5881 begin = read_uleb128 (start, &bytes_read, finish);
5882 start += bytes_read;
5883 end = read_uleb128 (start, &bytes_read, finish);
5884 start += bytes_read;
5886 case DW_RLE_start_end:
5887 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5888 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5891 error (_("Invalid range list entry type %d\n"), rlet);
5892 rlet = DW_RLE_end_of_list;
5895 if (rlet == DW_RLE_end_of_list)
5897 if (rlet == DW_RLE_base_address)
5900 print_dwarf_vma (begin + base_address, pointer_size);
5901 print_dwarf_vma (end + base_address, pointer_size);
5904 fputs (_("(start == end)"), stdout);
5905 else if (begin > end)
5906 fputs (_("(start > end)"), stdout);
5913 display_debug_ranges (struct dwarf_section *section,
5914 void *file ATTRIBUTE_UNUSED)
5916 unsigned char *start = section->start;
5917 unsigned char *last_start = start;
5918 unsigned long bytes = section->size;
5919 unsigned char *section_begin = start;
5920 unsigned char *finish = start + bytes;
5921 unsigned int num_range_list, i;
5922 struct range_entry *range_entries, *range_entry_fill;
5923 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
5924 /* Initialize it due to a false compiler warning. */
5925 unsigned char address_size = 0;
5929 printf (_("\nThe %s section is empty.\n"), section->name);
5935 dwarf_vma initial_length;
5936 unsigned int initial_length_size;
5937 unsigned char segment_selector_size;
5938 unsigned int offset_size, offset_entry_count;
5939 unsigned short version;
5941 /* Get and check the length of the block. */
5942 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
5944 if (initial_length == 0xffffffff)
5946 /* This section is 64-bit DWARF 3. */
5947 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
5949 initial_length_size = 12;
5954 initial_length_size = 4;
5957 if (initial_length + initial_length_size > section->size)
5959 /* If the length field has a relocation against it, then we should
5960 not complain if it is inaccurate (and probably negative).
5961 It is copied from .debug_line handling code. */
5962 if (reloc_at (section, (start - section->start) - offset_size))
5964 initial_length = (finish - start) - initial_length_size;
5968 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
5969 (long) initial_length);
5974 /* Get and check the version number. */
5975 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
5979 warn (_("Only DWARF version 5 debug_rnglists info "
5980 "is currently supported.\n"));
5984 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
5986 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
5987 if (segment_selector_size != 0)
5989 warn (_("The %s section contains "
5990 "unsupported segment selector size: %d.\n"),
5991 section->name, segment_selector_size);
5995 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
5996 if (offset_entry_count != 0)
5998 warn (_("The %s section contains "
5999 "unsupported offset entry count: %u.\n"),
6000 section->name, offset_entry_count);
6005 if (load_debug_info (file) == 0)
6007 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6013 for (i = 0; i < num_debug_info_entries; i++)
6014 num_range_list += debug_information [i].num_range_lists;
6016 if (num_range_list == 0)
6018 /* This can happen when the file was compiled with -gsplit-debug
6019 which removes references to range lists from the primary .o file. */
6020 printf (_("No range lists in .debug_info section.\n"));
6024 range_entries = (struct range_entry *)
6025 xmalloc (sizeof (*range_entries) * num_range_list);
6026 range_entry_fill = range_entries;
6028 for (i = 0; i < num_debug_info_entries; i++)
6030 debug_info *debug_info_p = &debug_information[i];
6033 for (j = 0; j < debug_info_p->num_range_lists; j++)
6035 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6036 range_entry_fill->debug_info_p = debug_info_p;
6041 qsort (range_entries, num_range_list, sizeof (*range_entries),
6042 range_entry_compar);
6044 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6045 warn (_("Range lists in %s section start at 0x%lx\n"),
6046 section->name, (unsigned long) range_entries[0].ranges_offset);
6048 printf (_("Contents of the %s section:\n\n"), section->name);
6049 printf (_(" Offset Begin End\n"));
6051 for (i = 0; i < num_range_list; i++)
6053 struct range_entry *range_entry = &range_entries[i];
6054 debug_info *debug_info_p = range_entry->debug_info_p;
6055 unsigned int pointer_size;
6057 unsigned char *next;
6058 dwarf_vma base_address;
6060 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6061 offset = range_entry->ranges_offset;
6062 next = section_begin + offset;
6063 base_address = debug_info_p->base_address;
6065 /* PR 17512: file: 001-101485-0.001:0.1. */
6066 if (pointer_size < 2 || pointer_size > 8)
6068 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6069 pointer_size, (unsigned long) offset);
6073 if (dwarf_check != 0 && i > 0)
6076 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6077 (unsigned long) (start - section_begin),
6078 (unsigned long) (next - section_begin), section->name);
6079 else if (start > next)
6081 if (next == last_start)
6083 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6084 (unsigned long) (start - section_begin),
6085 (unsigned long) (next - section_begin), section->name);
6091 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6092 (start, finish, pointer_size, offset, base_address);
6096 free (range_entries);
6101 typedef struct Frame_Chunk
6103 struct Frame_Chunk *next;
6104 unsigned char *chunk_start;
6106 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6107 short int *col_type;
6110 unsigned int code_factor;
6115 dwarf_vma cfa_offset;
6117 unsigned char fde_encoding;
6118 unsigned char cfa_exp;
6119 unsigned char ptr_size;
6120 unsigned char segment_size;
6124 static const char *const *dwarf_regnames;
6125 static unsigned int dwarf_regnames_count;
6127 /* A marker for a col_type that means this column was never referenced
6128 in the frame info. */
6129 #define DW_CFA_unreferenced (-1)
6131 /* Return 0 if no more space is needed, 1 if more space is needed,
6132 -1 for invalid reg. */
6135 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6137 unsigned int prev = fc->ncols;
6139 if (reg < (unsigned int) fc->ncols)
6142 if (dwarf_regnames_count
6143 && reg > dwarf_regnames_count)
6146 fc->ncols = reg + 1;
6147 /* PR 17512: file: 10450-2643-0.004.
6148 If reg == -1 then this can happen... */
6152 /* PR 17512: file: 2844a11d. */
6153 if (fc->ncols > 1024)
6155 error (_("Unfeasibly large register number: %u\n"), reg);
6157 /* FIXME: 1024 is an arbitrary limit. Increase it if
6158 we ever encounter a valid binary that exceeds it. */
6162 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6163 sizeof (short int));
6164 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6165 /* PR 17512: file:002-10025-0.005. */
6166 if (fc->col_type == NULL || fc->col_offset == NULL)
6168 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6174 while (prev < fc->ncols)
6176 fc->col_type[prev] = DW_CFA_unreferenced;
6177 fc->col_offset[prev] = 0;
6183 static const char *const dwarf_regnames_i386[] =
6185 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6186 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6187 "eip", "eflags", NULL, /* 8 - 10 */
6188 "st0", "st1", "st2", "st3", /* 11 - 14 */
6189 "st4", "st5", "st6", "st7", /* 15 - 18 */
6190 NULL, NULL, /* 19 - 20 */
6191 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6192 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6193 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6194 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6195 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6196 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6197 "tr", "ldtr", /* 48 - 49 */
6198 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6199 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6200 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6201 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6202 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6203 NULL, NULL, NULL, /* 90 - 92 */
6204 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6207 static const char *const dwarf_regnames_iamcu[] =
6209 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6210 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6211 "eip", "eflags", NULL, /* 8 - 10 */
6212 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6213 NULL, NULL, /* 19 - 20 */
6214 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6215 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6216 NULL, NULL, NULL, /* 37 - 39 */
6217 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6218 "tr", "ldtr", /* 48 - 49 */
6219 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6220 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6221 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6222 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6223 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6224 NULL, NULL, NULL, /* 90 - 92 */
6225 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6229 init_dwarf_regnames_i386 (void)
6231 dwarf_regnames = dwarf_regnames_i386;
6232 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6236 init_dwarf_regnames_iamcu (void)
6238 dwarf_regnames = dwarf_regnames_iamcu;
6239 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6242 static const char *const dwarf_regnames_x86_64[] =
6244 "rax", "rdx", "rcx", "rbx",
6245 "rsi", "rdi", "rbp", "rsp",
6246 "r8", "r9", "r10", "r11",
6247 "r12", "r13", "r14", "r15",
6249 "xmm0", "xmm1", "xmm2", "xmm3",
6250 "xmm4", "xmm5", "xmm6", "xmm7",
6251 "xmm8", "xmm9", "xmm10", "xmm11",
6252 "xmm12", "xmm13", "xmm14", "xmm15",
6253 "st0", "st1", "st2", "st3",
6254 "st4", "st5", "st6", "st7",
6255 "mm0", "mm1", "mm2", "mm3",
6256 "mm4", "mm5", "mm6", "mm7",
6258 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6259 "fs.base", "gs.base", NULL, NULL,
6261 "mxcsr", "fcw", "fsw",
6262 "xmm16", "xmm17", "xmm18", "xmm19",
6263 "xmm20", "xmm21", "xmm22", "xmm23",
6264 "xmm24", "xmm25", "xmm26", "xmm27",
6265 "xmm28", "xmm29", "xmm30", "xmm31",
6266 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6267 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6268 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6269 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6270 NULL, NULL, NULL, /* 115 - 117 */
6271 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6275 init_dwarf_regnames_x86_64 (void)
6277 dwarf_regnames = dwarf_regnames_x86_64;
6278 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6281 static const char *const dwarf_regnames_aarch64[] =
6283 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6284 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6285 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6286 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6287 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6288 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6289 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6290 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6291 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6292 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6293 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6294 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6298 init_dwarf_regnames_aarch64 (void)
6300 dwarf_regnames = dwarf_regnames_aarch64;
6301 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6304 static const char *const dwarf_regnames_s390[] =
6306 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6307 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6308 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6309 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6310 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6311 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6312 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6313 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6314 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6317 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6318 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6322 init_dwarf_regnames_s390 (void)
6324 dwarf_regnames = dwarf_regnames_s390;
6325 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6329 init_dwarf_regnames (unsigned int e_machine)
6334 init_dwarf_regnames_i386 ();
6338 init_dwarf_regnames_iamcu ();
6344 init_dwarf_regnames_x86_64 ();
6348 init_dwarf_regnames_aarch64 ();
6352 init_dwarf_regnames_s390 ();
6361 regname (unsigned int regno, int row)
6363 static char reg[64];
6365 && regno < dwarf_regnames_count
6366 && dwarf_regnames [regno] != NULL)
6369 return dwarf_regnames [regno];
6370 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6371 dwarf_regnames [regno]);
6374 snprintf (reg, sizeof (reg), "r%d", regno);
6379 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6384 if (*max_regs != fc->ncols)
6385 *max_regs = fc->ncols;
6387 if (*need_col_headers)
6389 static const char *sloc = " LOC";
6391 *need_col_headers = 0;
6393 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6395 for (r = 0; r < *max_regs; r++)
6396 if (fc->col_type[r] != DW_CFA_unreferenced)
6401 printf ("%-5s ", regname (r, 1));
6407 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6409 strcpy (tmp, "exp");
6411 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6412 printf ("%-8s ", tmp);
6414 for (r = 0; r < fc->ncols; r++)
6416 if (fc->col_type[r] != DW_CFA_unreferenced)
6418 switch (fc->col_type[r])
6420 case DW_CFA_undefined:
6423 case DW_CFA_same_value:
6427 sprintf (tmp, "c%+d", fc->col_offset[r]);
6429 case DW_CFA_val_offset:
6430 sprintf (tmp, "v%+d", fc->col_offset[r]);
6432 case DW_CFA_register:
6433 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6435 case DW_CFA_expression:
6436 strcpy (tmp, "exp");
6438 case DW_CFA_val_expression:
6439 strcpy (tmp, "vexp");
6442 strcpy (tmp, "n/a");
6445 printf ("%-5s ", tmp);
6451 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6452 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
6453 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
6455 static unsigned char *
6456 read_cie (unsigned char *start, unsigned char *end,
6457 Frame_Chunk **p_cie, int *p_version,
6458 unsigned long *p_aug_len, unsigned char **p_aug)
6462 unsigned int length_return;
6463 unsigned char *augmentation_data = NULL;
6464 unsigned long augmentation_data_len = 0;
6467 /* PR 17512: file: 001-228113-0.004. */
6471 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6472 memset (fc, 0, sizeof (Frame_Chunk));
6474 fc->col_type = (short int *) xmalloc (sizeof (short int));
6475 fc->col_offset = (int *) xmalloc (sizeof (int));
6479 fc->augmentation = (char *) start;
6480 /* PR 17512: file: 001-228113-0.004.
6481 Skip past augmentation name, but avoid running off the end of the data. */
6483 if (* start ++ == '\0')
6487 warn (_("No terminator for augmentation name\n"));
6491 if (strcmp (fc->augmentation, "eh") == 0)
6492 start += eh_addr_size;
6496 GET (fc->ptr_size, 1);
6497 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6499 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6503 GET (fc->segment_size, 1);
6504 /* PR 17512: file: e99d2804. */
6505 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6507 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6511 eh_addr_size = fc->ptr_size;
6515 fc->ptr_size = eh_addr_size;
6516 fc->segment_size = 0;
6518 fc->code_factor = LEB ();
6519 fc->data_factor = SLEB ();
6529 if (fc->augmentation[0] == 'z')
6531 augmentation_data_len = LEB ();
6532 augmentation_data = start;
6533 start += augmentation_data_len;
6534 /* PR 17512: file: 11042-2589-0.004. */
6537 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
6542 if (augmentation_data_len)
6546 unsigned char *qend;
6548 p = (unsigned char *) fc->augmentation + 1;
6549 q = augmentation_data;
6550 qend = q + augmentation_data_len;
6552 /* PR 17531: file: 015adfaa. */
6555 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
6556 augmentation_data_len = 0;
6559 while (p < end && q < augmentation_data + augmentation_data_len)
6564 q += 1 + size_of_encoded_value (*q);
6566 fc->fde_encoding = *q++;
6573 /* Note - it is OK if this loop terminates with q < qend.
6574 Padding may have been inserted to align the end of the CIE. */
6579 *p_version = version;
6582 *p_aug_len = augmentation_data_len;
6583 *p_aug = augmentation_data;
6589 display_debug_frames (struct dwarf_section *section,
6590 void *file ATTRIBUTE_UNUSED)
6592 unsigned char *start = section->start;
6593 unsigned char *end = start + section->size;
6594 unsigned char *section_start = start;
6595 Frame_Chunk *chunks = 0, *forward_refs = 0;
6596 Frame_Chunk *remembered_state = 0;
6598 int is_eh = strcmp (section->name, ".eh_frame") == 0;
6599 unsigned int length_return;
6600 unsigned int max_regs = 0;
6601 const char *bad_reg = _("bad register: ");
6602 unsigned int saved_eh_addr_size = eh_addr_size;
6604 printf (_("Contents of the %s section:\n"), section->name);
6608 unsigned char *saved_start;
6609 unsigned char *block_end;
6614 int need_col_headers = 1;
6615 unsigned char *augmentation_data = NULL;
6616 unsigned long augmentation_data_len = 0;
6617 unsigned int encoded_ptr_size = saved_eh_addr_size;
6618 unsigned int offset_size;
6619 unsigned int initial_length_size;
6620 bfd_boolean all_nops;
6622 saved_start = start;
6624 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
6628 printf ("\n%08lx ZERO terminator\n\n",
6629 (unsigned long)(saved_start - section_start));
6630 /* Skip any zero terminators that directly follow.
6631 A corrupt section size could have loaded a whole
6632 slew of zero filled memory bytes. eg
6633 PR 17512: file: 070-19381-0.004. */
6634 while (start < end && * start == 0)
6639 if (length == 0xffffffff)
6641 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
6643 initial_length_size = 12;
6648 initial_length_size = 4;
6651 block_end = saved_start + length + initial_length_size;
6652 if (block_end > end || block_end < start)
6654 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6655 dwarf_vmatoa_1 (NULL, length, offset_size),
6656 (unsigned long) (saved_start - section_start));
6660 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
6662 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
6663 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
6668 start = read_cie (start, end, &cie, &version,
6669 &augmentation_data_len, &augmentation_data);
6670 /* PR 17512: file: 027-135133-0.005. */
6677 fc->chunk_start = saved_start;
6678 mreg = max_regs > 0 ? max_regs - 1 : 0;
6681 if (frame_need_space (fc, mreg) < 0)
6683 if (fc->fde_encoding)
6684 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6686 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
6687 print_dwarf_vma (length, fc->ptr_size);
6688 print_dwarf_vma (cie_id, offset_size);
6690 if (do_debug_frames_interp)
6692 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
6693 fc->code_factor, fc->data_factor, fc->ra);
6698 printf (" Version: %d\n", version);
6699 printf (" Augmentation: \"%s\"\n", fc->augmentation);
6702 printf (" Pointer Size: %u\n", fc->ptr_size);
6703 printf (" Segment Size: %u\n", fc->segment_size);
6705 printf (" Code alignment factor: %u\n", fc->code_factor);
6706 printf (" Data alignment factor: %d\n", fc->data_factor);
6707 printf (" Return address column: %d\n", fc->ra);
6709 if (augmentation_data_len)
6713 printf (" Augmentation data: ");
6714 for (i = 0; i < augmentation_data_len; ++i)
6715 /* FIXME: If do_wide is FALSE, then we should
6716 add carriage returns at 80 columns... */
6717 printf (" %02x", augmentation_data[i]);
6725 unsigned char *look_for;
6726 static Frame_Chunk fde_fc;
6727 unsigned long segment_selector;
6731 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
6732 look_for = start - 4 - ((cie_id ^ sign) - sign);
6735 look_for = section_start + cie_id;
6737 if (look_for <= saved_start)
6739 for (cie = chunks; cie ; cie = cie->next)
6740 if (cie->chunk_start == look_for)
6745 for (cie = forward_refs; cie ; cie = cie->next)
6746 if (cie->chunk_start == look_for)
6750 unsigned int off_size;
6751 unsigned char *cie_scan;
6753 cie_scan = look_for;
6755 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
6756 if (length == 0xffffffff)
6758 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
6765 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
6768 : ((off_size == 4 && c_id == DW_CIE_ID)
6769 || (off_size == 8 && c_id == DW64_CIE_ID)))
6774 read_cie (cie_scan, end, &cie, &version,
6775 &augmentation_data_len, &augmentation_data);
6776 /* PR 17512: file: 3450-2098-0.004. */
6779 warn (_("Failed to read CIE information\n"));
6782 cie->next = forward_refs;
6784 cie->chunk_start = look_for;
6785 mreg = max_regs > 0 ? max_regs - 1 : 0;
6788 if (frame_need_space (cie, mreg) < 0)
6790 warn (_("Invalid max register\n"));
6793 if (cie->fde_encoding)
6795 = size_of_encoded_value (cie->fde_encoding);
6802 memset (fc, 0, sizeof (Frame_Chunk));
6806 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6807 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6808 (unsigned long) (saved_start - section_start));
6810 fc->col_type = (short int *) xmalloc (sizeof (short int));
6811 fc->col_offset = (int *) xmalloc (sizeof (int));
6812 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
6814 warn (_("Invalid max register\n"));
6818 fc->augmentation = "";
6819 fc->fde_encoding = 0;
6820 fc->ptr_size = eh_addr_size;
6821 fc->segment_size = 0;
6825 fc->ncols = cie->ncols;
6826 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
6827 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
6828 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6829 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6830 fc->augmentation = cie->augmentation;
6831 fc->ptr_size = cie->ptr_size;
6832 eh_addr_size = cie->ptr_size;
6833 fc->segment_size = cie->segment_size;
6834 fc->code_factor = cie->code_factor;
6835 fc->data_factor = cie->data_factor;
6836 fc->cfa_reg = cie->cfa_reg;
6837 fc->cfa_offset = cie->cfa_offset;
6839 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
6841 warn (_("Invalid max register\n"));
6844 fc->fde_encoding = cie->fde_encoding;
6847 if (fc->fde_encoding)
6848 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6850 segment_selector = 0;
6851 if (fc->segment_size)
6853 if (fc->segment_size > sizeof (segment_selector))
6855 /* PR 17512: file: 9e196b3e. */
6856 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
6857 fc->segment_size = 4;
6859 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
6862 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
6864 /* FIXME: It appears that sometimes the final pc_range value is
6865 encoded in less than encoded_ptr_size bytes. See the x86_64
6866 run of the "objcopy on compressed debug sections" test for an
6868 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
6870 if (cie->augmentation[0] == 'z')
6872 augmentation_data_len = LEB ();
6873 augmentation_data = start;
6874 start += augmentation_data_len;
6875 /* PR 17512: file: 722-8446-0.004. */
6876 if (start >= end || ((signed long) augmentation_data_len) < 0)
6878 warn (_("Corrupt augmentation data length: %lx\n"),
6879 augmentation_data_len);
6881 augmentation_data = NULL;
6882 augmentation_data_len = 0;
6886 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6887 (unsigned long)(saved_start - section_start),
6888 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
6889 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6890 (unsigned long)(cie->chunk_start - section_start));
6892 if (fc->segment_size)
6893 printf ("%04lx:", segment_selector);
6896 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
6897 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
6899 if (! do_debug_frames_interp && augmentation_data_len)
6903 printf (" Augmentation data: ");
6904 for (i = 0; i < augmentation_data_len; ++i)
6905 printf (" %02x", augmentation_data[i]);
6911 /* At this point, fc is the current chunk, cie (if any) is set, and
6912 we're about to interpret instructions for the chunk. */
6913 /* ??? At present we need to do this always, since this sizes the
6914 fc->col_type and fc->col_offset arrays, which we write into always.
6915 We should probably split the interpreted and non-interpreted bits
6916 into two different routines, since there's so much that doesn't
6917 really overlap between them. */
6918 if (1 || do_debug_frames_interp)
6920 /* Start by making a pass over the chunk, allocating storage
6921 and taking note of what registers are used. */
6922 unsigned char *tmp = start;
6924 while (start < block_end)
6926 unsigned int reg, op, opa;
6928 unsigned char * new_start;
6935 /* Warning: if you add any more cases to this switch, be
6936 sure to add them to the corresponding switch below. */
6939 case DW_CFA_advance_loc:
6943 if (frame_need_space (fc, opa) >= 0)
6944 fc->col_type[opa] = DW_CFA_undefined;
6946 case DW_CFA_restore:
6947 if (frame_need_space (fc, opa) >= 0)
6948 fc->col_type[opa] = DW_CFA_undefined;
6950 case DW_CFA_set_loc:
6951 start += encoded_ptr_size;
6953 case DW_CFA_advance_loc1:
6956 case DW_CFA_advance_loc2:
6959 case DW_CFA_advance_loc4:
6962 case DW_CFA_offset_extended:
6963 case DW_CFA_val_offset:
6964 reg = LEB (); LEB ();
6965 if (frame_need_space (fc, reg) >= 0)
6966 fc->col_type[reg] = DW_CFA_undefined;
6968 case DW_CFA_restore_extended:
6970 if (frame_need_space (fc, reg) >= 0)
6971 fc->col_type[reg] = DW_CFA_undefined;
6973 case DW_CFA_undefined:
6975 if (frame_need_space (fc, reg) >= 0)
6976 fc->col_type[reg] = DW_CFA_undefined;
6978 case DW_CFA_same_value:
6980 if (frame_need_space (fc, reg) >= 0)
6981 fc->col_type[reg] = DW_CFA_undefined;
6983 case DW_CFA_register:
6984 reg = LEB (); LEB ();
6985 if (frame_need_space (fc, reg) >= 0)
6986 fc->col_type[reg] = DW_CFA_undefined;
6988 case DW_CFA_def_cfa:
6991 case DW_CFA_def_cfa_register:
6994 case DW_CFA_def_cfa_offset:
6997 case DW_CFA_def_cfa_expression:
6999 new_start = start + temp;
7000 if (new_start < start)
7002 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7008 case DW_CFA_expression:
7009 case DW_CFA_val_expression:
7012 new_start = start + temp;
7013 if (new_start < start)
7015 /* PR 17512: file:306-192417-0.005. */
7016 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7021 if (frame_need_space (fc, reg) >= 0)
7022 fc->col_type[reg] = DW_CFA_undefined;
7024 case DW_CFA_offset_extended_sf:
7025 case DW_CFA_val_offset_sf:
7026 reg = LEB (); SLEB ();
7027 if (frame_need_space (fc, reg) >= 0)
7028 fc->col_type[reg] = DW_CFA_undefined;
7030 case DW_CFA_def_cfa_sf:
7033 case DW_CFA_def_cfa_offset_sf:
7036 case DW_CFA_MIPS_advance_loc8:
7039 case DW_CFA_GNU_args_size:
7042 case DW_CFA_GNU_negative_offset_extended:
7043 reg = LEB (); LEB ();
7044 if (frame_need_space (fc, reg) >= 0)
7045 fc->col_type[reg] = DW_CFA_undefined;
7056 /* Now we know what registers are used, make a second pass over
7057 the chunk, this time actually printing out the info. */
7059 while (start < block_end)
7061 unsigned char * tmp;
7063 unsigned long ul, reg, roffs;
7067 const char *reg_prefix = "";
7074 /* Make a note if something other than DW_CFA_nop happens. */
7075 if (op != DW_CFA_nop)
7078 /* Warning: if you add any more cases to this switch, be
7079 sure to add them to the corresponding switch above. */
7082 case DW_CFA_advance_loc:
7083 if (do_debug_frames_interp)
7084 frame_display_row (fc, &need_col_headers, &max_regs);
7086 printf (" DW_CFA_advance_loc: %d to %s\n",
7087 opa * fc->code_factor,
7088 dwarf_vmatoa_1 (NULL,
7089 fc->pc_begin + opa * fc->code_factor,
7091 fc->pc_begin += opa * fc->code_factor;
7096 if (opa >= (unsigned int) fc->ncols)
7097 reg_prefix = bad_reg;
7098 if (! do_debug_frames_interp || *reg_prefix != '\0')
7099 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7100 reg_prefix, regname (opa, 0),
7101 roffs * fc->data_factor);
7102 if (*reg_prefix == '\0')
7104 fc->col_type[opa] = DW_CFA_offset;
7105 fc->col_offset[opa] = roffs * fc->data_factor;
7109 case DW_CFA_restore:
7110 if (opa >= (unsigned int) fc->ncols)
7111 reg_prefix = bad_reg;
7112 if (! do_debug_frames_interp || *reg_prefix != '\0')
7113 printf (" DW_CFA_restore: %s%s\n",
7114 reg_prefix, regname (opa, 0));
7115 if (*reg_prefix != '\0')
7118 if (opa >= (unsigned int) cie->ncols
7119 || (do_debug_frames_interp
7120 && cie->col_type[opa] == DW_CFA_unreferenced))
7122 fc->col_type[opa] = DW_CFA_undefined;
7123 fc->col_offset[opa] = 0;
7127 fc->col_type[opa] = cie->col_type[opa];
7128 fc->col_offset[opa] = cie->col_offset[opa];
7132 case DW_CFA_set_loc:
7133 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7134 if (do_debug_frames_interp)
7135 frame_display_row (fc, &need_col_headers, &max_regs);
7137 printf (" DW_CFA_set_loc: %s\n",
7138 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7142 case DW_CFA_advance_loc1:
7143 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7144 if (do_debug_frames_interp)
7145 frame_display_row (fc, &need_col_headers, &max_regs);
7147 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7148 (unsigned long) (ofs * fc->code_factor),
7149 dwarf_vmatoa_1 (NULL,
7150 fc->pc_begin + ofs * fc->code_factor,
7152 fc->pc_begin += ofs * fc->code_factor;
7155 case DW_CFA_advance_loc2:
7156 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7157 if (do_debug_frames_interp)
7158 frame_display_row (fc, &need_col_headers, &max_regs);
7160 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7161 (unsigned long) (ofs * fc->code_factor),
7162 dwarf_vmatoa_1 (NULL,
7163 fc->pc_begin + ofs * fc->code_factor,
7165 fc->pc_begin += ofs * fc->code_factor;
7168 case DW_CFA_advance_loc4:
7169 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7170 if (do_debug_frames_interp)
7171 frame_display_row (fc, &need_col_headers, &max_regs);
7173 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7174 (unsigned long) (ofs * fc->code_factor),
7175 dwarf_vmatoa_1 (NULL,
7176 fc->pc_begin + ofs * fc->code_factor,
7178 fc->pc_begin += ofs * fc->code_factor;
7181 case DW_CFA_offset_extended:
7184 if (reg >= (unsigned int) fc->ncols)
7185 reg_prefix = bad_reg;
7186 if (! do_debug_frames_interp || *reg_prefix != '\0')
7187 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7188 reg_prefix, regname (reg, 0),
7189 roffs * fc->data_factor);
7190 if (*reg_prefix == '\0')
7192 fc->col_type[reg] = DW_CFA_offset;
7193 fc->col_offset[reg] = roffs * fc->data_factor;
7197 case DW_CFA_val_offset:
7200 if (reg >= (unsigned int) fc->ncols)
7201 reg_prefix = bad_reg;
7202 if (! do_debug_frames_interp || *reg_prefix != '\0')
7203 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7204 reg_prefix, regname (reg, 0),
7205 roffs * fc->data_factor);
7206 if (*reg_prefix == '\0')
7208 fc->col_type[reg] = DW_CFA_val_offset;
7209 fc->col_offset[reg] = roffs * fc->data_factor;
7213 case DW_CFA_restore_extended:
7215 if (reg >= (unsigned int) fc->ncols)
7216 reg_prefix = bad_reg;
7217 if (! do_debug_frames_interp || *reg_prefix != '\0')
7218 printf (" DW_CFA_restore_extended: %s%s\n",
7219 reg_prefix, regname (reg, 0));
7220 if (*reg_prefix != '\0')
7223 if (reg >= (unsigned int) cie->ncols)
7225 fc->col_type[reg] = DW_CFA_undefined;
7226 fc->col_offset[reg] = 0;
7230 fc->col_type[reg] = cie->col_type[reg];
7231 fc->col_offset[reg] = cie->col_offset[reg];
7235 case DW_CFA_undefined:
7237 if (reg >= (unsigned int) fc->ncols)
7238 reg_prefix = bad_reg;
7239 if (! do_debug_frames_interp || *reg_prefix != '\0')
7240 printf (" DW_CFA_undefined: %s%s\n",
7241 reg_prefix, regname (reg, 0));
7242 if (*reg_prefix == '\0')
7244 fc->col_type[reg] = DW_CFA_undefined;
7245 fc->col_offset[reg] = 0;
7249 case DW_CFA_same_value:
7251 if (reg >= (unsigned int) fc->ncols)
7252 reg_prefix = bad_reg;
7253 if (! do_debug_frames_interp || *reg_prefix != '\0')
7254 printf (" DW_CFA_same_value: %s%s\n",
7255 reg_prefix, regname (reg, 0));
7256 if (*reg_prefix == '\0')
7258 fc->col_type[reg] = DW_CFA_same_value;
7259 fc->col_offset[reg] = 0;
7263 case DW_CFA_register:
7266 if (reg >= (unsigned int) fc->ncols)
7267 reg_prefix = bad_reg;
7268 if (! do_debug_frames_interp || *reg_prefix != '\0')
7270 printf (" DW_CFA_register: %s%s in ",
7271 reg_prefix, regname (reg, 0));
7272 puts (regname (roffs, 0));
7274 if (*reg_prefix == '\0')
7276 fc->col_type[reg] = DW_CFA_register;
7277 fc->col_offset[reg] = roffs;
7281 case DW_CFA_remember_state:
7282 if (! do_debug_frames_interp)
7283 printf (" DW_CFA_remember_state\n");
7284 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7285 rs->cfa_offset = fc->cfa_offset;
7286 rs->cfa_reg = fc->cfa_reg;
7288 rs->cfa_exp = fc->cfa_exp;
7289 rs->ncols = fc->ncols;
7290 rs->col_type = (short int *) xcmalloc (rs->ncols,
7291 sizeof (* rs->col_type));
7292 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7293 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7294 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7295 rs->next = remembered_state;
7296 remembered_state = rs;
7299 case DW_CFA_restore_state:
7300 if (! do_debug_frames_interp)
7301 printf (" DW_CFA_restore_state\n");
7302 rs = remembered_state;
7305 remembered_state = rs->next;
7306 fc->cfa_offset = rs->cfa_offset;
7307 fc->cfa_reg = rs->cfa_reg;
7309 fc->cfa_exp = rs->cfa_exp;
7310 if (frame_need_space (fc, rs->ncols - 1) < 0)
7312 warn (_("Invalid column number in saved frame state\n"));
7316 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7317 memcpy (fc->col_offset, rs->col_offset,
7318 rs->ncols * sizeof (* rs->col_offset));
7319 free (rs->col_type);
7320 free (rs->col_offset);
7323 else if (do_debug_frames_interp)
7324 printf ("Mismatched DW_CFA_restore_state\n");
7327 case DW_CFA_def_cfa:
7328 fc->cfa_reg = LEB ();
7329 fc->cfa_offset = LEB ();
7331 if (! do_debug_frames_interp)
7332 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7333 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7336 case DW_CFA_def_cfa_register:
7337 fc->cfa_reg = LEB ();
7339 if (! do_debug_frames_interp)
7340 printf (" DW_CFA_def_cfa_register: %s\n",
7341 regname (fc->cfa_reg, 0));
7344 case DW_CFA_def_cfa_offset:
7345 fc->cfa_offset = LEB ();
7346 if (! do_debug_frames_interp)
7347 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7351 if (! do_debug_frames_interp)
7352 printf (" DW_CFA_nop\n");
7355 case DW_CFA_def_cfa_expression:
7357 if (start >= block_end || ul > (unsigned long) (block_end - start))
7359 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7362 if (! do_debug_frames_interp)
7364 printf (" DW_CFA_def_cfa_expression (");
7365 decode_location_expression (start, eh_addr_size, 0, -1,
7373 case DW_CFA_expression:
7376 if (reg >= (unsigned int) fc->ncols)
7377 reg_prefix = bad_reg;
7378 /* PR 17512: file: 069-133014-0.006. */
7379 /* PR 17512: file: 98c02eb4. */
7381 if (start >= block_end || tmp > block_end || tmp < start)
7383 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7386 if (! do_debug_frames_interp || *reg_prefix != '\0')
7388 printf (" DW_CFA_expression: %s%s (",
7389 reg_prefix, regname (reg, 0));
7390 decode_location_expression (start, eh_addr_size, 0, -1,
7394 if (*reg_prefix == '\0')
7395 fc->col_type[reg] = DW_CFA_expression;
7399 case DW_CFA_val_expression:
7402 if (reg >= (unsigned int) fc->ncols)
7403 reg_prefix = bad_reg;
7405 if (start >= block_end || tmp > block_end || tmp < start)
7407 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7410 if (! do_debug_frames_interp || *reg_prefix != '\0')
7412 printf (" DW_CFA_val_expression: %s%s (",
7413 reg_prefix, regname (reg, 0));
7414 decode_location_expression (start, eh_addr_size, 0, -1,
7418 if (*reg_prefix == '\0')
7419 fc->col_type[reg] = DW_CFA_val_expression;
7423 case DW_CFA_offset_extended_sf:
7426 if (frame_need_space (fc, reg) < 0)
7427 reg_prefix = bad_reg;
7428 if (! do_debug_frames_interp || *reg_prefix != '\0')
7429 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7430 reg_prefix, regname (reg, 0),
7431 (long)(l * fc->data_factor));
7432 if (*reg_prefix == '\0')
7434 fc->col_type[reg] = DW_CFA_offset;
7435 fc->col_offset[reg] = l * fc->data_factor;
7439 case DW_CFA_val_offset_sf:
7442 if (frame_need_space (fc, reg) < 0)
7443 reg_prefix = bad_reg;
7444 if (! do_debug_frames_interp || *reg_prefix != '\0')
7445 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7446 reg_prefix, regname (reg, 0),
7447 (long)(l * fc->data_factor));
7448 if (*reg_prefix == '\0')
7450 fc->col_type[reg] = DW_CFA_val_offset;
7451 fc->col_offset[reg] = l * fc->data_factor;
7455 case DW_CFA_def_cfa_sf:
7456 fc->cfa_reg = LEB ();
7457 fc->cfa_offset = SLEB ();
7458 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7460 if (! do_debug_frames_interp)
7461 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7462 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7465 case DW_CFA_def_cfa_offset_sf:
7466 fc->cfa_offset = SLEB ();
7467 fc->cfa_offset *= fc->data_factor;
7468 if (! do_debug_frames_interp)
7469 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7472 case DW_CFA_MIPS_advance_loc8:
7473 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7474 if (do_debug_frames_interp)
7475 frame_display_row (fc, &need_col_headers, &max_regs);
7477 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7478 (unsigned long) (ofs * fc->code_factor),
7479 dwarf_vmatoa_1 (NULL,
7480 fc->pc_begin + ofs * fc->code_factor,
7482 fc->pc_begin += ofs * fc->code_factor;
7485 case DW_CFA_GNU_window_save:
7486 if (! do_debug_frames_interp)
7487 printf (" DW_CFA_GNU_window_save\n");
7490 case DW_CFA_GNU_args_size:
7492 if (! do_debug_frames_interp)
7493 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7496 case DW_CFA_GNU_negative_offset_extended:
7499 if (frame_need_space (fc, reg) < 0)
7500 reg_prefix = bad_reg;
7501 if (! do_debug_frames_interp || *reg_prefix != '\0')
7502 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7503 reg_prefix, regname (reg, 0),
7504 (long)(l * fc->data_factor));
7505 if (*reg_prefix == '\0')
7507 fc->col_type[reg] = DW_CFA_offset;
7508 fc->col_offset[reg] = l * fc->data_factor;
7513 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7514 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7516 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7521 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7522 if (do_debug_frames_interp && ! all_nops)
7523 frame_display_row (fc, &need_col_headers, &max_regs);
7526 eh_addr_size = saved_eh_addr_size;
7539 display_gdb_index (struct dwarf_section *section,
7540 void *file ATTRIBUTE_UNUSED)
7542 unsigned char *start = section->start;
7544 uint32_t cu_list_offset, tu_list_offset;
7545 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
7546 unsigned int cu_list_elements, tu_list_elements;
7547 unsigned int address_table_size, symbol_table_slots;
7548 unsigned char *cu_list, *tu_list;
7549 unsigned char *address_table, *symbol_table, *constant_pool;
7552 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
7554 printf (_("Contents of the %s section:\n"), section->name);
7556 if (section->size < 6 * sizeof (uint32_t))
7558 warn (_("Truncated header in the %s section.\n"), section->name);
7562 version = byte_get_little_endian (start, 4);
7563 printf (_("Version %ld\n"), (long) version);
7565 /* Prior versions are obsolete, and future versions may not be
7566 backwards compatible. */
7567 if (version < 3 || version > 8)
7569 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
7573 warn (_("The address table data in version 3 may be wrong.\n"));
7575 warn (_("Version 4 does not support case insensitive lookups.\n"));
7577 warn (_("Version 5 does not include inlined functions.\n"));
7579 warn (_("Version 6 does not include symbol attributes.\n"));
7580 /* Version 7 indices generated by Gold have bad type unit references,
7581 PR binutils/15021. But we don't know if the index was generated by
7582 Gold or not, so to avoid worrying users with gdb-generated indices
7583 we say nothing for version 7 here. */
7585 cu_list_offset = byte_get_little_endian (start + 4, 4);
7586 tu_list_offset = byte_get_little_endian (start + 8, 4);
7587 address_table_offset = byte_get_little_endian (start + 12, 4);
7588 symbol_table_offset = byte_get_little_endian (start + 16, 4);
7589 constant_pool_offset = byte_get_little_endian (start + 20, 4);
7591 if (cu_list_offset > section->size
7592 || tu_list_offset > section->size
7593 || address_table_offset > section->size
7594 || symbol_table_offset > section->size
7595 || constant_pool_offset > section->size)
7597 warn (_("Corrupt header in the %s section.\n"), section->name);
7601 /* PR 17531: file: 418d0a8a. */
7602 if (tu_list_offset < cu_list_offset)
7604 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
7605 tu_list_offset, cu_list_offset);
7609 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
7611 if (address_table_offset < tu_list_offset)
7613 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
7614 address_table_offset, tu_list_offset);
7618 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
7620 /* PR 17531: file: 18a47d3d. */
7621 if (symbol_table_offset < address_table_offset)
7623 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
7624 symbol_table_offset, address_table_offset);
7628 address_table_size = symbol_table_offset - address_table_offset;
7630 if (constant_pool_offset < symbol_table_offset)
7632 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
7633 constant_pool_offset, symbol_table_offset);
7637 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
7639 cu_list = start + cu_list_offset;
7640 tu_list = start + tu_list_offset;
7641 address_table = start + address_table_offset;
7642 symbol_table = start + symbol_table_offset;
7643 constant_pool = start + constant_pool_offset;
7645 if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
7647 warn (_("Address table extends beyond end of section.\n"));
7651 printf (_("\nCU table:\n"));
7652 for (i = 0; i < cu_list_elements; i += 2)
7654 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
7655 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
7657 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
7658 (unsigned long) cu_offset,
7659 (unsigned long) (cu_offset + cu_length - 1));
7662 printf (_("\nTU table:\n"));
7663 for (i = 0; i < tu_list_elements; i += 3)
7665 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
7666 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
7667 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
7669 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
7670 (unsigned long) tu_offset,
7671 (unsigned long) type_offset);
7672 print_dwarf_vma (signature, 8);
7676 printf (_("\nAddress table:\n"));
7677 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
7680 uint64_t low = byte_get_little_endian (address_table + i, 8);
7681 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
7682 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
7684 print_dwarf_vma (low, 8);
7685 print_dwarf_vma (high, 8);
7686 printf (_("%lu\n"), (unsigned long) cu_index);
7689 printf (_("\nSymbol table:\n"));
7690 for (i = 0; i < symbol_table_slots; ++i)
7692 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
7693 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
7694 uint32_t num_cus, cu;
7696 if (name_offset != 0
7697 || cu_vector_offset != 0)
7700 unsigned char * adr;
7702 adr = constant_pool + name_offset;
7703 /* PR 17531: file: 5b7b07ad. */
7704 if (adr < constant_pool || adr >= section->start + section->size)
7706 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
7707 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
7711 printf ("[%3u] %.*s:", i,
7712 (int) (section->size - (constant_pool_offset + name_offset)),
7713 constant_pool + name_offset);
7715 adr = constant_pool + cu_vector_offset;
7716 if (adr < constant_pool || adr >= section->start + section->size - 3)
7718 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
7719 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
7720 cu_vector_offset, i);
7724 num_cus = byte_get_little_endian (adr, 4);
7726 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
7727 if (num_cus * 4 < num_cus
7728 || adr >= section->start + section->size
7729 || adr < constant_pool)
7731 printf ("<invalid number of CUs: %d>\n", num_cus);
7732 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
7740 for (j = 0; j < num_cus; ++j)
7743 gdb_index_symbol_kind kind;
7745 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7746 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
7747 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
7748 cu = GDB_INDEX_CU_VALUE (cu);
7749 /* Convert to TU number if it's for a type unit. */
7750 if (cu >= cu_list_elements / 2)
7751 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
7752 (unsigned long) (cu - cu_list_elements / 2));
7754 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
7756 printf (" [%s, %s]",
7757 is_static ? _("static") : _("global"),
7758 get_gdb_index_symbol_kind_name (kind));
7770 /* Pre-allocate enough space for the CU/TU sets needed. */
7773 prealloc_cu_tu_list (unsigned int nshndx)
7775 if (shndx_pool == NULL)
7777 shndx_pool_size = nshndx;
7778 shndx_pool_used = 0;
7779 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
7780 sizeof (unsigned int));
7784 shndx_pool_size = shndx_pool_used + nshndx;
7785 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
7786 sizeof (unsigned int));
7791 add_shndx_to_cu_tu_entry (unsigned int shndx)
7793 if (shndx_pool_used >= shndx_pool_size)
7795 error (_("Internal error: out of space in the shndx pool.\n"));
7798 shndx_pool [shndx_pool_used++] = shndx;
7802 end_cu_tu_entry (void)
7804 if (shndx_pool_used >= shndx_pool_size)
7806 error (_("Internal error: out of space in the shndx pool.\n"));
7809 shndx_pool [shndx_pool_used++] = 0;
7812 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7815 get_DW_SECT_short_name (unsigned int dw_sect)
7817 static char buf[16];
7825 case DW_SECT_ABBREV:
7831 case DW_SECT_STR_OFFSETS:
7833 case DW_SECT_MACINFO:
7841 snprintf (buf, sizeof (buf), "%d", dw_sect);
7845 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7846 These sections are extensions for Fission.
7847 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7850 process_cu_tu_index (struct dwarf_section *section, int do_display)
7852 unsigned char *phdr = section->start;
7853 unsigned char *limit = phdr + section->size;
7854 unsigned char *phash;
7855 unsigned char *pindex;
7856 unsigned char *ppool;
7857 unsigned int version;
7858 unsigned int ncols = 0;
7860 unsigned int nslots;
7863 dwarf_vma signature_high;
7864 dwarf_vma signature_low;
7867 /* PR 17512: file: 002-168123-0.004. */
7870 warn (_("Section %s is empty\n"), section->name);
7873 /* PR 17512: file: 002-376-0.004. */
7874 if (section->size < 24)
7876 warn (_("Section %s is too small to contain a CU/TU header\n"),
7881 SAFE_BYTE_GET (version, phdr, 4, limit);
7883 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
7884 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
7885 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
7888 pindex = phash + nslots * 8;
7889 ppool = pindex + nslots * 4;
7891 /* PR 17531: file: 45d69832. */
7892 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
7894 warn (_("Section %s is too small for %d slots\n"),
7895 section->name, nslots);
7901 printf (_("Contents of the %s section:\n\n"), section->name);
7902 printf (_(" Version: %d\n"), version);
7904 printf (_(" Number of columns: %d\n"), ncols);
7905 printf (_(" Number of used entries: %d\n"), nused);
7906 printf (_(" Number of slots: %d\n\n"), nslots);
7909 if (ppool > limit || ppool < phdr)
7911 warn (_("Section %s too small for %d hash table entries\n"),
7912 section->name, nslots);
7919 prealloc_cu_tu_list ((limit - ppool) / 4);
7920 for (i = 0; i < nslots; i++)
7922 unsigned char *shndx_list;
7925 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
7926 if (signature_high != 0 || signature_low != 0)
7928 SAFE_BYTE_GET (j, pindex, 4, limit);
7929 shndx_list = ppool + j * 4;
7930 /* PR 17531: file: 705e010d. */
7931 if (shndx_list < ppool)
7933 warn (_("Section index pool located before start of section\n"));
7938 printf (_(" [%3d] Signature: 0x%s Sections: "),
7939 i, dwarf_vmatoa64 (signature_high, signature_low,
7940 buf, sizeof (buf)));
7943 if (shndx_list >= limit)
7945 warn (_("Section %s too small for shndx pool\n"),
7949 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
7953 printf (" %d", shndx);
7955 add_shndx_to_cu_tu_entry (shndx);
7967 else if (version == 2)
7970 unsigned int dw_sect;
7971 unsigned char *ph = phash;
7972 unsigned char *pi = pindex;
7973 unsigned char *poffsets = ppool + ncols * 4;
7974 unsigned char *psizes = poffsets + nused * ncols * 4;
7975 unsigned char *pend = psizes + nused * ncols * 4;
7976 bfd_boolean is_tu_index;
7977 struct cu_tu_set *this_set = NULL;
7979 unsigned char *prow;
7981 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
7983 /* PR 17531: file: 0dd159bf.
7984 Check for wraparound with an overlarge ncols value. */
7985 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
7987 warn (_("Overlarge number of columns: %x\n"), ncols);
7993 warn (_("Section %s too small for offset and size tables\n"),
8000 printf (_(" Offset table\n"));
8001 printf (" slot %-16s ",
8002 is_tu_index ? _("signature") : _("dwo_id"));
8009 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8015 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8022 for (j = 0; j < ncols; j++)
8024 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8025 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8030 for (i = 0; i < nslots; i++)
8032 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8034 SAFE_BYTE_GET (row, pi, 4, limit);
8037 /* PR 17531: file: a05f6ab3. */
8040 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8046 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8048 prow = poffsets + (row - 1) * ncols * 4;
8049 /* PR 17531: file: b8ce60a8. */
8050 if (prow < poffsets || prow > limit)
8052 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8058 printf (_(" [%3d] 0x%s"),
8059 i, dwarf_vmatoa64 (signature_high, signature_low,
8060 buf, sizeof (buf)));
8061 for (j = 0; j < ncols; j++)
8063 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8065 printf (" %8d", val);
8068 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8070 /* PR 17531: file: 10796eb3. */
8071 if (dw_sect >= DW_SECT_MAX)
8072 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8074 this_set [row - 1].section_offsets [dw_sect] = val;
8090 printf (_(" Size table\n"));
8091 printf (" slot %-16s ",
8092 is_tu_index ? _("signature") : _("dwo_id"));
8095 for (j = 0; j < ncols; j++)
8097 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8099 printf (" %8s", get_DW_SECT_short_name (val));
8105 for (i = 0; i < nslots; i++)
8107 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8109 SAFE_BYTE_GET (row, pi, 4, limit);
8112 prow = psizes + (row - 1) * ncols * 4;
8115 printf (_(" [%3d] 0x%s"),
8116 i, dwarf_vmatoa64 (signature_high, signature_low,
8117 buf, sizeof (buf)));
8119 for (j = 0; j < ncols; j++)
8121 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8123 printf (" %8d", val);
8126 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8127 if (dw_sect >= DW_SECT_MAX)
8128 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8130 this_set [row - 1].section_sizes [dw_sect] = val;
8142 else if (do_display)
8143 printf (_(" Unsupported version (%d)\n"), version);
8151 /* Load the CU and TU indexes if present. This will build a list of
8152 section sets that we can use to associate a .debug_info.dwo section
8153 with its associated .debug_abbrev.dwo section in a .dwp file. */
8156 load_cu_tu_indexes (void *file)
8158 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8160 /* If we have already loaded (or tried to load) the CU and TU indexes
8161 then do not bother to repeat the task. */
8162 if (cu_tu_indexes_read == -1)
8164 cu_tu_indexes_read = TRUE;
8166 if (load_debug_section (dwp_cu_index, file))
8167 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8168 cu_tu_indexes_read = FALSE;
8170 if (load_debug_section (dwp_tu_index, file))
8171 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8172 cu_tu_indexes_read = FALSE;
8175 return (bfd_boolean) cu_tu_indexes_read;
8178 /* Find the set of sections that includes section SHNDX. */
8181 find_cu_tu_set (void *file, unsigned int shndx)
8185 if (! load_cu_tu_indexes (file))
8188 /* Find SHNDX in the shndx pool. */
8189 for (i = 0; i < shndx_pool_used; i++)
8190 if (shndx_pool [i] == shndx)
8193 if (i >= shndx_pool_used)
8196 /* Now backup to find the first entry in the set. */
8197 while (i > 0 && shndx_pool [i - 1] != 0)
8200 return shndx_pool + i;
8203 /* Display a .debug_cu_index or .debug_tu_index section. */
8206 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
8208 return process_cu_tu_index (section, 1);
8212 display_debug_not_supported (struct dwarf_section *section,
8213 void *file ATTRIBUTE_UNUSED)
8215 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8221 /* Like malloc, but takes two parameters like calloc.
8222 Verifies that the first parameter is not too large.
8223 Note: does *not* initialise the allocated memory to zero. */
8225 cmalloc (size_t nmemb, size_t size)
8227 /* Check for overflow. */
8228 if (nmemb >= ~(size_t) 0 / size)
8231 return xmalloc (nmemb * size);
8234 /* Like xmalloc, but takes two parameters like calloc.
8235 Verifies that the first parameter is not too large.
8236 Note: does *not* initialise the allocated memory to zero. */
8238 xcmalloc (size_t nmemb, size_t size)
8240 /* Check for overflow. */
8241 if (nmemb >= ~(size_t) 0 / size)
8244 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8249 return xmalloc (nmemb * size);
8252 /* Like xrealloc, but takes three parameters.
8253 Verifies that the second parameter is not too large.
8254 Note: does *not* initialise any new memory to zero. */
8256 xcrealloc (void *ptr, size_t nmemb, size_t size)
8258 /* Check for overflow. */
8259 if (nmemb >= ~(size_t) 0 / size)
8262 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8267 return xrealloc (ptr, nmemb * size);
8270 /* Like xcalloc, but verifies that the first parameter is not too large. */
8272 xcalloc2 (size_t nmemb, size_t size)
8274 /* Check for overflow. */
8275 if (nmemb >= ~(size_t) 0 / size)
8278 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8283 return xcalloc (nmemb, size);
8287 free_debug_memory (void)
8293 for (i = 0; i < max; i++)
8294 free_debug_section ((enum dwarf_section_display_enum) i);
8296 if (debug_information != NULL)
8298 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
8300 for (i = 0; i < num_debug_info_entries; i++)
8302 if (!debug_information [i].max_loc_offsets)
8304 free (debug_information [i].loc_offsets);
8305 free (debug_information [i].have_frame_base);
8307 if (!debug_information [i].max_range_lists)
8308 free (debug_information [i].range_lists);
8311 free (debug_information);
8312 debug_information = NULL;
8313 alloc_num_debug_info_entries = num_debug_info_entries = 0;
8318 dwarf_select_sections_by_names (const char *names)
8322 const char * option;
8326 debug_dump_long_opts;
8328 static const debug_dump_long_opts opts_table [] =
8330 /* Please keep this table alpha- sorted. */
8331 { "Ranges", & do_debug_ranges, 1 },
8332 { "abbrev", & do_debug_abbrevs, 1 },
8333 { "addr", & do_debug_addr, 1 },
8334 { "aranges", & do_debug_aranges, 1 },
8335 { "cu_index", & do_debug_cu_index, 1 },
8336 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
8337 { "frames", & do_debug_frames, 1 },
8338 { "frames-interp", & do_debug_frames_interp, 1 },
8339 /* The special .gdb_index section. */
8340 { "gdb_index", & do_gdb_index, 1 },
8341 { "info", & do_debug_info, 1 },
8342 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
8343 { "loc", & do_debug_loc, 1 },
8344 { "macro", & do_debug_macinfo, 1 },
8345 { "pubnames", & do_debug_pubnames, 1 },
8346 { "pubtypes", & do_debug_pubtypes, 1 },
8347 /* This entry is for compatibility
8348 with earlier versions of readelf. */
8349 { "ranges", & do_debug_aranges, 1 },
8350 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
8351 { "str", & do_debug_str, 1 },
8352 /* These trace_* sections are used by Itanium VMS. */
8353 { "trace_abbrev", & do_trace_abbrevs, 1 },
8354 { "trace_aranges", & do_trace_aranges, 1 },
8355 { "trace_info", & do_trace_info, 1 },
8364 const debug_dump_long_opts * entry;
8366 for (entry = opts_table; entry->option; entry++)
8368 size_t len = strlen (entry->option);
8370 if (strncmp (p, entry->option, len) == 0
8371 && (p[len] == ',' || p[len] == '\0'))
8373 * entry->variable |= entry->val;
8375 /* The --debug-dump=frames-interp option also
8376 enables the --debug-dump=frames option. */
8377 if (do_debug_frames_interp)
8378 do_debug_frames = 1;
8385 if (entry->option == NULL)
8387 warn (_("Unrecognized debug option '%s'\n"), p);
8388 p = strchr (p, ',');
8399 dwarf_select_sections_by_letters (const char *letters)
8401 unsigned int lindex = 0;
8403 while (letters[lindex])
8404 switch (letters[lindex++])
8411 do_debug_abbrevs = 1;
8415 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
8419 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
8423 do_debug_pubnames = 1;
8427 do_debug_pubtypes = 1;
8431 do_debug_aranges = 1;
8435 do_debug_ranges = 1;
8439 do_debug_frames_interp = 1;
8442 do_debug_frames = 1;
8446 do_debug_macinfo = 1;
8458 warn (_("Unrecognized debug option '%s'\n"), letters);
8464 dwarf_select_sections_all (void)
8467 do_debug_abbrevs = 1;
8468 do_debug_lines = FLAG_DEBUG_LINES_RAW;
8469 do_debug_pubnames = 1;
8470 do_debug_pubtypes = 1;
8471 do_debug_aranges = 1;
8472 do_debug_ranges = 1;
8473 do_debug_frames = 1;
8474 do_debug_macinfo = 1;
8479 do_trace_abbrevs = 1;
8480 do_trace_aranges = 1;
8482 do_debug_cu_index = 1;
8485 struct dwarf_section_display debug_displays[] =
8487 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8488 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8489 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8490 display_debug_aranges, &do_debug_aranges, TRUE },
8491 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8492 display_debug_frames, &do_debug_frames, TRUE },
8493 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8494 display_debug_info, &do_debug_info, TRUE },
8495 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8496 display_debug_lines, &do_debug_lines, TRUE },
8497 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8498 display_debug_pubnames, &do_debug_pubnames, FALSE },
8499 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8500 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
8501 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8502 display_debug_frames, &do_debug_frames, TRUE },
8503 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8504 display_debug_macinfo, &do_debug_macinfo, FALSE },
8505 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8506 display_debug_macro, &do_debug_macinfo, TRUE },
8507 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8508 display_debug_str, &do_debug_str, FALSE },
8509 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8510 display_debug_str, &do_debug_str, FALSE },
8511 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8512 display_debug_loc, &do_debug_loc, TRUE },
8513 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8514 display_debug_loc, &do_debug_loc, TRUE },
8515 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8516 display_debug_pubnames, &do_debug_pubtypes, FALSE },
8517 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8518 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
8519 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8520 display_debug_ranges, &do_debug_ranges, TRUE },
8521 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8522 display_debug_ranges, &do_debug_ranges, TRUE },
8523 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8524 display_debug_not_supported, NULL, FALSE },
8525 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8526 display_debug_not_supported, NULL, FALSE },
8527 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8528 display_debug_types, &do_debug_info, TRUE },
8529 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8530 display_debug_not_supported, NULL, FALSE },
8531 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8532 display_gdb_index, &do_gdb_index, FALSE },
8533 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
8534 display_trace_info, &do_trace_info, TRUE },
8535 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8536 display_debug_abbrev, &do_trace_abbrevs, FALSE },
8537 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8538 display_debug_aranges, &do_trace_aranges, FALSE },
8539 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8540 display_debug_info, &do_debug_info, TRUE },
8541 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8542 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8543 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8544 display_debug_types, &do_debug_info, TRUE },
8545 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8546 display_debug_lines, &do_debug_lines, TRUE },
8547 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8548 display_debug_loc, &do_debug_loc, TRUE },
8549 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8550 display_debug_macro, &do_debug_macinfo, TRUE },
8551 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8552 display_debug_macinfo, &do_debug_macinfo, FALSE },
8553 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8554 display_debug_str, &do_debug_str, TRUE },
8555 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8556 display_debug_str_offsets, NULL, FALSE },
8557 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8558 display_debug_str_offsets, NULL, FALSE },
8559 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8560 display_debug_addr, &do_debug_addr, TRUE },
8561 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8562 display_cu_index, &do_debug_cu_index, FALSE },
8563 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8564 display_cu_index, &do_debug_cu_index, FALSE },