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 SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
317 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
319 #define READ_ULEB(var) \
324 (var) = _val = read_uleb128 (start, &length_return, end); \
326 error (_("Internal error: %s%d: LEB value (%#lx) too large for containing variable\n"), \
327 __FILE__, __LINE__, _val); \
328 start += length_return; \
332 #define READ_SLEB(var) \
335 dwarf_signed_vma _val; \
337 (var) = _val = read_sleb128 (start, &length_return, end); \
339 error (_("Internal error: %s%d: LEB value (%#lx) too large for containing variable\n"), \
340 __FILE__, __LINE__, _val); \
341 start += length_return; \
345 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
348 unsigned int amount = (AMOUNT); \
349 if (sizeof (VAL) < amount) \
351 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
352 amount, (int) sizeof (VAL)); \
353 amount = sizeof (VAL); \
355 if (((PTR) + amount) >= (END)) \
358 amount = (END) - (PTR); \
362 if (amount == 0 || amount > 8) \
365 VAL = byte_get ((PTR), amount); \
369 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
372 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
377 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
380 unsigned int amount = (AMOUNT); \
381 if (((PTR) + amount) >= (END)) \
384 amount = (END) - (PTR); \
389 VAL = byte_get_signed ((PTR), amount); \
395 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
398 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
403 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
406 if (((PTR) + 8) <= (END)) \
408 byte_get_64 ((PTR), (HIGH), (LOW)); \
412 * (LOW) = * (HIGH) = 0; \
417 typedef struct State_Machine_Registers
425 unsigned char op_index;
426 unsigned char end_sequence;
427 /* This variable hold the number of the last entry seen
428 in the File Table. */
429 unsigned int last_file_entry;
432 static SMR state_machine_regs;
435 reset_state_machine (int is_stmt)
437 state_machine_regs.address = 0;
438 state_machine_regs.op_index = 0;
439 state_machine_regs.file = 1;
440 state_machine_regs.line = 1;
441 state_machine_regs.column = 0;
442 state_machine_regs.is_stmt = is_stmt;
443 state_machine_regs.basic_block = 0;
444 state_machine_regs.end_sequence = 0;
445 state_machine_regs.last_file_entry = 0;
448 /* Handled an extend line op.
449 Returns the number of bytes read. */
452 process_extended_line_op (unsigned char * data,
456 unsigned char op_code;
457 unsigned int bytes_read;
460 unsigned char *orig_data = data;
463 len = read_uleb128 (data, & bytes_read, end);
466 if (len == 0 || data == end || len > (uintptr_t) (end - data))
468 warn (_("Badly formed extended line op encountered!\n"));
475 printf (_(" Extended opcode %d: "), op_code);
479 case DW_LNE_end_sequence:
480 printf (_("End of Sequence\n\n"));
481 reset_state_machine (is_stmt);
484 case DW_LNE_set_address:
485 /* PR 17512: file: 002-100480-0.004. */
486 if (len - bytes_read - 1 > 8)
488 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
489 len - bytes_read - 1);
493 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
494 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
495 state_machine_regs.address = adr;
496 state_machine_regs.op_index = 0;
499 case DW_LNE_define_file:
500 printf (_("define new File Table entry\n"));
501 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
502 printf (" %d\t", ++state_machine_regs.last_file_entry);
508 l = strnlen ((char *) data, end - data);
510 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
512 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
514 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
516 printf ("%.*s\n\n", (int) l, name);
519 if (((unsigned int) (data - orig_data) != len) || data == end)
520 warn (_("DW_LNE_define_file: Bad opcode length\n"));
523 case DW_LNE_set_discriminator:
524 printf (_("set Discriminator to %s\n"),
525 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
529 case DW_LNE_HP_negate_is_UV_update:
530 printf ("DW_LNE_HP_negate_is_UV_update\n");
532 case DW_LNE_HP_push_context:
533 printf ("DW_LNE_HP_push_context\n");
535 case DW_LNE_HP_pop_context:
536 printf ("DW_LNE_HP_pop_context\n");
538 case DW_LNE_HP_set_file_line_column:
539 printf ("DW_LNE_HP_set_file_line_column\n");
541 case DW_LNE_HP_set_routine_name:
542 printf ("DW_LNE_HP_set_routine_name\n");
544 case DW_LNE_HP_set_sequence:
545 printf ("DW_LNE_HP_set_sequence\n");
547 case DW_LNE_HP_negate_post_semantics:
548 printf ("DW_LNE_HP_negate_post_semantics\n");
550 case DW_LNE_HP_negate_function_exit:
551 printf ("DW_LNE_HP_negate_function_exit\n");
553 case DW_LNE_HP_negate_front_end_logical:
554 printf ("DW_LNE_HP_negate_front_end_logical\n");
556 case DW_LNE_HP_define_proc:
557 printf ("DW_LNE_HP_define_proc\n");
559 case DW_LNE_HP_source_file_correlation:
561 unsigned char *edata = data + len - bytes_read - 1;
563 printf ("DW_LNE_HP_source_file_correlation\n");
569 opc = read_uleb128 (data, & bytes_read, edata);
574 case DW_LNE_HP_SFC_formfeed:
575 printf (" DW_LNE_HP_SFC_formfeed\n");
577 case DW_LNE_HP_SFC_set_listing_line:
578 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
580 read_uleb128 (data, & bytes_read, edata)));
583 case DW_LNE_HP_SFC_associate:
584 printf (" DW_LNE_HP_SFC_associate ");
587 read_uleb128 (data, & bytes_read, edata)));
591 read_uleb128 (data, & bytes_read, edata)));
595 read_uleb128 (data, & bytes_read, edata)));
599 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
609 unsigned int rlen = len - bytes_read - 1;
611 if (op_code >= DW_LNE_lo_user
612 /* The test against DW_LNW_hi_user is redundant due to
613 the limited range of the unsigned char data type used
615 /*&& op_code <= DW_LNE_hi_user*/)
616 printf (_("user defined: "));
618 printf (_("UNKNOWN: "));
619 printf (_("length %d ["), rlen);
621 printf (" %02x", *data++);
630 static const unsigned char *
631 fetch_indirect_string (dwarf_vma offset)
633 struct dwarf_section *section = &debug_displays [str].section;
634 const unsigned char * ret;
636 if (section->start == NULL)
637 return (const unsigned char *) _("<no .debug_str section>");
639 if (offset >= section->size)
641 warn (_("DW_FORM_strp offset too big: %s\n"),
642 dwarf_vmatoa ("x", offset));
643 return (const unsigned char *) _("<offset is too big>");
646 ret = section->start + offset;
647 /* Unfortunately we cannot rely upon the .debug_str section ending with a
648 NUL byte. Since our caller is expecting to receive a well formed C
649 string we test for the lack of a terminating byte here. */
650 if (strnlen ((const char *) ret, section->size - offset)
651 == section->size - offset)
652 ret = (const unsigned char *)
653 _("<no NUL byte at end of .debug_str section>");
658 static const unsigned char *
659 fetch_indirect_line_string (dwarf_vma offset)
661 struct dwarf_section *section = &debug_displays [line_str].section;
662 const unsigned char * ret;
664 if (section->start == NULL)
665 return (const unsigned char *) _("<no .debug_line_str section>");
667 if (offset >= section->size)
669 warn (_("DW_FORM_line_strp offset too big: %s\n"),
670 dwarf_vmatoa ("x", offset));
671 return (const unsigned char *) _("<offset is too big>");
674 ret = section->start + offset;
675 /* Unfortunately we cannot rely upon the .debug_line_str section ending
676 with a NUL byte. Since our caller is expecting to receive a well formed
677 C string we test for the lack of a terminating byte here. */
678 if (strnlen ((const char *) ret, section->size - offset)
679 == section->size - offset)
680 ret = (const unsigned char *)
681 _("<no NUL byte at end of .debug_line_str section>");
687 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
688 dwarf_vma offset_size, int dwo)
690 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
691 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
692 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
693 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
694 dwarf_vma index_offset = idx * offset_size;
695 dwarf_vma str_offset;
698 if (index_section->start == NULL)
699 return (dwo ? _("<no .debug_str_offsets.dwo section>")
700 : _("<no .debug_str_offsets section>"));
702 if (this_set != NULL)
703 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
704 if (index_offset >= index_section->size)
706 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
707 dwarf_vmatoa ("x", index_offset));
708 return _("<index offset is too big>");
711 if (str_section->start == NULL)
712 return (dwo ? _("<no .debug_str.dwo section>")
713 : _("<no .debug_str section>"));
715 str_offset = byte_get (index_section->start + index_offset, offset_size);
716 str_offset -= str_section->address;
717 if (str_offset >= str_section->size)
719 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
720 dwarf_vmatoa ("x", str_offset));
721 return _("<indirect index offset is too big>");
724 ret = (const char *) str_section->start + str_offset;
725 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
726 Since our caller is expecting to receive a well formed C string we test
727 for the lack of a terminating byte here. */
728 if (strnlen (ret, str_section->size - str_offset)
729 == str_section->size - str_offset)
730 ret = (const char *) _("<no NUL byte at end of section>");
736 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
738 struct dwarf_section *section = &debug_displays [debug_addr].section;
740 if (section->start == NULL)
741 return (_("<no .debug_addr section>"));
743 if (offset + bytes > section->size)
745 warn (_("Offset into section %s too big: %s\n"),
746 section->name, dwarf_vmatoa ("x", offset));
747 return "<offset too big>";
750 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
754 /* FIXME: There are better and more efficient ways to handle
755 these structures. For now though, I just want something that
756 is simple to implement. */
757 typedef struct abbrev_attr
759 unsigned long attribute;
761 bfd_signed_vma implicit_const;
762 struct abbrev_attr *next;
766 typedef struct abbrev_entry
771 struct abbrev_attr *first_attr;
772 struct abbrev_attr *last_attr;
773 struct abbrev_entry *next;
777 static abbrev_entry *first_abbrev = NULL;
778 static abbrev_entry *last_abbrev = NULL;
785 for (abbrv = first_abbrev; abbrv;)
787 abbrev_entry *next_abbrev = abbrv->next;
790 for (attr = abbrv->first_attr; attr;)
792 abbrev_attr *next_attr = attr->next;
802 last_abbrev = first_abbrev = NULL;
806 add_abbrev (unsigned long number, unsigned long tag, int children)
810 entry = (abbrev_entry *) malloc (sizeof (*entry));
815 entry->entry = number;
817 entry->children = children;
818 entry->first_attr = NULL;
819 entry->last_attr = NULL;
822 if (first_abbrev == NULL)
823 first_abbrev = entry;
825 last_abbrev->next = entry;
831 add_abbrev_attr (unsigned long attribute, unsigned long form,
832 bfd_signed_vma implicit_const)
836 attr = (abbrev_attr *) malloc (sizeof (*attr));
841 attr->attribute = attribute;
843 attr->implicit_const = implicit_const;
846 if (last_abbrev->first_attr == NULL)
847 last_abbrev->first_attr = attr;
849 last_abbrev->last_attr->next = attr;
851 last_abbrev->last_attr = attr;
854 /* Processes the (partial) contents of a .debug_abbrev section.
855 Returns NULL if the end of the section was encountered.
856 Returns the address after the last byte read if the end of
857 an abbreviation set was found. */
859 static unsigned char *
860 process_abbrev_section (unsigned char *start, unsigned char *end)
862 if (first_abbrev != NULL)
867 unsigned int bytes_read;
870 unsigned long attribute;
873 entry = read_uleb128 (start, & bytes_read, end);
876 /* A single zero is supposed to end the section according
877 to the standard. If there's more, then signal that to
884 tag = read_uleb128 (start, & bytes_read, end);
891 add_abbrev (entry, tag, children);
896 /* Initialize it due to a false compiler warning. */
897 bfd_signed_vma implicit_const = -1;
899 attribute = read_uleb128 (start, & bytes_read, end);
904 form = read_uleb128 (start, & bytes_read, end);
909 if (form == DW_FORM_implicit_const)
911 implicit_const = read_sleb128 (start, & bytes_read, end);
917 add_abbrev_attr (attribute, form, implicit_const);
919 while (attribute != 0);
922 /* Report the missing single zero which ends the section. */
923 error (_(".debug_abbrev section not zero terminated\n"));
929 get_TAG_name (unsigned long tag)
931 const char *name = get_DW_TAG_name ((unsigned int)tag);
935 static char buffer[100];
937 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
945 get_FORM_name (unsigned long form)
950 return "DW_FORM value: 0";
952 name = get_DW_FORM_name (form);
955 static char buffer[100];
957 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
964 static unsigned char *
965 display_block (unsigned char *data,
967 const unsigned char * const end, char delimiter)
971 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
973 return (unsigned char *) end;
975 maxlen = (dwarf_vma) (end - data);
976 length = length > maxlen ? maxlen : length;
979 printf ("%lx ", (unsigned long) byte_get (data++, 1));
985 decode_location_expression (unsigned char * data,
986 unsigned int pointer_size,
987 unsigned int offset_size,
991 struct dwarf_section * section)
994 unsigned int bytes_read;
996 dwarf_signed_vma svalue;
997 unsigned char *end = data + length;
998 int need_frame_base = 0;
1007 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1008 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1011 printf ("DW_OP_deref");
1014 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1015 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1018 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1019 printf ("DW_OP_const1s: %ld", (long) svalue);
1022 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1023 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1026 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1027 printf ("DW_OP_const2s: %ld", (long) svalue);
1030 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1031 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1034 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1035 printf ("DW_OP_const4s: %ld", (long) svalue);
1038 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1039 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1040 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1041 printf ("%lu", (unsigned long) uvalue);
1044 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1045 printf ("DW_OP_const8s: %ld ", (long) svalue);
1046 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1047 printf ("%ld", (long) svalue);
1050 printf ("DW_OP_constu: %s",
1051 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1055 printf ("DW_OP_consts: %s",
1056 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1060 printf ("DW_OP_dup");
1063 printf ("DW_OP_drop");
1066 printf ("DW_OP_over");
1069 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1070 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1073 printf ("DW_OP_swap");
1076 printf ("DW_OP_rot");
1079 printf ("DW_OP_xderef");
1082 printf ("DW_OP_abs");
1085 printf ("DW_OP_and");
1088 printf ("DW_OP_div");
1091 printf ("DW_OP_minus");
1094 printf ("DW_OP_mod");
1097 printf ("DW_OP_mul");
1100 printf ("DW_OP_neg");
1103 printf ("DW_OP_not");
1106 printf ("DW_OP_or");
1109 printf ("DW_OP_plus");
1111 case DW_OP_plus_uconst:
1112 printf ("DW_OP_plus_uconst: %s",
1113 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1117 printf ("DW_OP_shl");
1120 printf ("DW_OP_shr");
1123 printf ("DW_OP_shra");
1126 printf ("DW_OP_xor");
1129 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1130 printf ("DW_OP_bra: %ld", (long) svalue);
1133 printf ("DW_OP_eq");
1136 printf ("DW_OP_ge");
1139 printf ("DW_OP_gt");
1142 printf ("DW_OP_le");
1145 printf ("DW_OP_lt");
1148 printf ("DW_OP_ne");
1151 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1152 printf ("DW_OP_skip: %ld", (long) svalue);
1187 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1222 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1223 regname (op - DW_OP_reg0, 1));
1258 printf ("DW_OP_breg%d (%s): %s",
1260 regname (op - DW_OP_breg0, 1),
1261 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1266 uvalue = read_uleb128 (data, &bytes_read, end);
1268 printf ("DW_OP_regx: %s (%s)",
1269 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1272 need_frame_base = 1;
1273 printf ("DW_OP_fbreg: %s",
1274 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1278 uvalue = read_uleb128 (data, &bytes_read, end);
1280 printf ("DW_OP_bregx: %s (%s) %s",
1281 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1282 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1286 printf ("DW_OP_piece: %s",
1287 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1290 case DW_OP_deref_size:
1291 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1292 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1294 case DW_OP_xderef_size:
1295 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1296 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1299 printf ("DW_OP_nop");
1302 /* DWARF 3 extensions. */
1303 case DW_OP_push_object_address:
1304 printf ("DW_OP_push_object_address");
1307 /* XXX: Strictly speaking for 64-bit DWARF3 files
1308 this ought to be an 8-byte wide computation. */
1309 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1310 printf ("DW_OP_call2: <0x%s>",
1311 dwarf_vmatoa ("x", svalue + cu_offset));
1314 /* XXX: Strictly speaking for 64-bit DWARF3 files
1315 this ought to be an 8-byte wide computation. */
1316 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1317 printf ("DW_OP_call4: <0x%s>",
1318 dwarf_vmatoa ("x", svalue + cu_offset));
1320 case DW_OP_call_ref:
1321 /* XXX: Strictly speaking for 64-bit DWARF3 files
1322 this ought to be an 8-byte wide computation. */
1323 if (dwarf_version == -1)
1325 printf (_("(DW_OP_call_ref in frame info)"));
1326 /* No way to tell where the next op is, so just bail. */
1327 return need_frame_base;
1329 if (dwarf_version == 2)
1331 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1335 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1337 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1339 case DW_OP_form_tls_address:
1340 printf ("DW_OP_form_tls_address");
1342 case DW_OP_call_frame_cfa:
1343 printf ("DW_OP_call_frame_cfa");
1345 case DW_OP_bit_piece:
1346 printf ("DW_OP_bit_piece: ");
1347 printf (_("size: %s "),
1348 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1350 printf (_("offset: %s "),
1351 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1355 /* DWARF 4 extensions. */
1356 case DW_OP_stack_value:
1357 printf ("DW_OP_stack_value");
1360 case DW_OP_implicit_value:
1361 printf ("DW_OP_implicit_value");
1362 uvalue = read_uleb128 (data, &bytes_read, end);
1364 data = display_block (data, uvalue, end, ' ');
1367 /* GNU extensions. */
1368 case DW_OP_GNU_push_tls_address:
1369 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1371 case DW_OP_GNU_uninit:
1372 printf ("DW_OP_GNU_uninit");
1373 /* FIXME: Is there data associated with this OP ? */
1375 case DW_OP_GNU_encoded_addr:
1382 addr = get_encoded_value (&data, encoding, section, end);
1384 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1385 print_dwarf_vma (addr, pointer_size);
1388 case DW_OP_implicit_pointer:
1389 case DW_OP_GNU_implicit_pointer:
1390 /* XXX: Strictly speaking for 64-bit DWARF3 files
1391 this ought to be an 8-byte wide computation. */
1392 if (dwarf_version == -1)
1394 printf (_("(%s in frame info)"),
1395 (op == DW_OP_implicit_pointer
1396 ? "DW_OP_implicit_pointer"
1397 : "DW_OP_GNU_implicit_pointer"));
1398 /* No way to tell where the next op is, so just bail. */
1399 return need_frame_base;
1401 if (dwarf_version == 2)
1403 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1407 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1409 printf ("%s: <0x%s> %s",
1410 (op == DW_OP_implicit_pointer
1411 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1412 dwarf_vmatoa ("x", uvalue),
1413 dwarf_vmatoa ("d", read_sleb128 (data,
1414 &bytes_read, end)));
1417 case DW_OP_entry_value:
1418 case DW_OP_GNU_entry_value:
1419 uvalue = read_uleb128 (data, &bytes_read, end);
1421 /* PR 17531: file: 0cc9cd00. */
1422 if (uvalue > (dwarf_vma) (end - data))
1423 uvalue = end - data;
1424 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1425 : "DW_OP_GNU_entry_value"));
1426 if (decode_location_expression (data, pointer_size, offset_size,
1427 dwarf_version, uvalue,
1428 cu_offset, section))
1429 need_frame_base = 1;
1435 case DW_OP_const_type:
1436 case DW_OP_GNU_const_type:
1437 uvalue = read_uleb128 (data, &bytes_read, end);
1439 printf ("%s: <0x%s> ",
1440 (op == DW_OP_const_type ? "DW_OP_const_type"
1441 : "DW_OP_GNU_const_type"),
1442 dwarf_vmatoa ("x", cu_offset + uvalue));
1443 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1444 data = display_block (data, uvalue, end, ' ');
1446 case DW_OP_regval_type:
1447 case DW_OP_GNU_regval_type:
1448 uvalue = read_uleb128 (data, &bytes_read, end);
1450 printf ("%s: %s (%s)",
1451 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1452 : "DW_OP_GNU_regval_type"),
1453 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1454 uvalue = read_uleb128 (data, &bytes_read, end);
1456 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1458 case DW_OP_deref_type:
1459 case DW_OP_GNU_deref_type:
1460 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1462 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1463 : "DW_OP_GNU_deref_type"),
1465 uvalue = read_uleb128 (data, &bytes_read, end);
1467 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1470 case DW_OP_GNU_convert:
1471 uvalue = read_uleb128 (data, &bytes_read, end);
1473 printf ("%s <0x%s>",
1474 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1475 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1477 case DW_OP_reinterpret:
1478 case DW_OP_GNU_reinterpret:
1479 uvalue = read_uleb128 (data, &bytes_read, end);
1481 printf ("%s <0x%s>",
1482 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1483 : "DW_OP_GNU_reinterpret"),
1484 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1486 case DW_OP_GNU_parameter_ref:
1487 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1488 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1489 dwarf_vmatoa ("x", cu_offset + uvalue));
1491 case DW_OP_GNU_addr_index:
1492 uvalue = read_uleb128 (data, &bytes_read, end);
1494 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1496 case DW_OP_GNU_const_index:
1497 uvalue = read_uleb128 (data, &bytes_read, end);
1499 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1502 /* HP extensions. */
1503 case DW_OP_HP_is_value:
1504 printf ("DW_OP_HP_is_value");
1505 /* FIXME: Is there data associated with this OP ? */
1507 case DW_OP_HP_fltconst4:
1508 printf ("DW_OP_HP_fltconst4");
1509 /* FIXME: Is there data associated with this OP ? */
1511 case DW_OP_HP_fltconst8:
1512 printf ("DW_OP_HP_fltconst8");
1513 /* FIXME: Is there data associated with this OP ? */
1515 case DW_OP_HP_mod_range:
1516 printf ("DW_OP_HP_mod_range");
1517 /* FIXME: Is there data associated with this OP ? */
1519 case DW_OP_HP_unmod_range:
1520 printf ("DW_OP_HP_unmod_range");
1521 /* FIXME: Is there data associated with this OP ? */
1524 printf ("DW_OP_HP_tls");
1525 /* FIXME: Is there data associated with this OP ? */
1528 /* PGI (STMicroelectronics) extensions. */
1529 case DW_OP_PGI_omp_thread_num:
1530 /* Pushes the thread number for the current thread as it would be
1531 returned by the standard OpenMP library function:
1532 omp_get_thread_num(). The "current thread" is the thread for
1533 which the expression is being evaluated. */
1534 printf ("DW_OP_PGI_omp_thread_num");
1538 if (op >= DW_OP_lo_user
1539 && op <= DW_OP_hi_user)
1540 printf (_("(User defined location op 0x%x)"), op);
1542 printf (_("(Unknown location op 0x%x)"), op);
1543 /* No way to tell where the next op is, so just bail. */
1544 return need_frame_base;
1547 /* Separate the ops. */
1552 return need_frame_base;
1555 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1556 This is used for DWARF package files. */
1558 static struct cu_tu_set *
1559 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1561 struct cu_tu_set *p;
1563 unsigned int dw_sect;
1569 dw_sect = DW_SECT_TYPES;
1575 dw_sect = DW_SECT_INFO;
1579 if (p->section_offsets [dw_sect] == cu_offset)
1587 /* Add INC to HIGH_BITS:LOW_BITS. */
1589 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1591 dwarf_vma tmp = * low_bits;
1595 /* FIXME: There is probably a better way of handling this:
1597 We need to cope with dwarf_vma being a 32-bit or 64-bit
1598 type. Plus regardless of its size LOW_BITS is meant to
1599 only hold 32-bits, so if there is overflow or wrap around
1600 we must propagate into HIGH_BITS. */
1601 if (tmp < * low_bits)
1605 else if (sizeof (tmp) > 8
1615 static unsigned char *
1616 read_and_display_attr_value (unsigned long attribute,
1618 dwarf_signed_vma implicit_const,
1619 unsigned char * data,
1620 unsigned char * end,
1621 dwarf_vma cu_offset,
1622 dwarf_vma pointer_size,
1623 dwarf_vma offset_size,
1625 debug_info * debug_info_p,
1627 struct dwarf_section * section,
1628 struct cu_tu_set * this_set, char delimiter)
1630 dwarf_vma uvalue = 0;
1631 unsigned char *block_start = NULL;
1632 unsigned char * orig_data = data;
1633 unsigned int bytes_read;
1635 if (data > end || (data == end && form != DW_FORM_flag_present))
1637 warn (_("Corrupt attribute\n"));
1646 case DW_FORM_ref_addr:
1647 if (dwarf_version == 2)
1648 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1649 else if (dwarf_version == 3 || dwarf_version == 4)
1650 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1652 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1657 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1661 case DW_FORM_line_strp:
1662 case DW_FORM_sec_offset:
1663 case DW_FORM_GNU_ref_alt:
1664 case DW_FORM_GNU_strp_alt:
1665 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1668 case DW_FORM_flag_present:
1675 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1680 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1685 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1689 uvalue = read_sleb128 (data, & bytes_read, end);
1693 case DW_FORM_GNU_str_index:
1694 uvalue = read_uleb128 (data, & bytes_read, end);
1698 case DW_FORM_ref_udata:
1700 uvalue = read_uleb128 (data, & bytes_read, end);
1704 case DW_FORM_indirect:
1705 form = read_uleb128 (data, & bytes_read, end);
1708 printf ("%c%s", delimiter, get_FORM_name (form));
1709 if (form == DW_FORM_implicit_const)
1711 implicit_const = read_sleb128 (data, & bytes_read, end);
1714 return read_and_display_attr_value (attribute, form, implicit_const, data,
1715 end, cu_offset, pointer_size,
1716 offset_size, dwarf_version,
1717 debug_info_p, do_loc,
1718 section, this_set, delimiter);
1719 case DW_FORM_GNU_addr_index:
1720 uvalue = read_uleb128 (data, & bytes_read, end);
1727 case DW_FORM_ref_addr:
1729 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1732 case DW_FORM_GNU_ref_alt:
1734 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1740 case DW_FORM_ref_udata:
1742 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1747 case DW_FORM_sec_offset:
1749 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1752 case DW_FORM_flag_present:
1759 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1762 case DW_FORM_implicit_const:
1764 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1771 dwarf_vma high_bits;
1775 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1777 if (form == DW_FORM_ref8)
1778 add64 (& high_bits, & utmp, cu_offset);
1779 printf ("%c0x%s", delimiter,
1780 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1783 if ((do_loc || do_debug_loc || do_debug_ranges)
1784 && num_debug_info_entries == 0)
1786 if (sizeof (uvalue) == 8)
1787 SAFE_BYTE_GET (uvalue, data, 8, end);
1789 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1795 case DW_FORM_data16:
1798 dwarf_vma left_high_bits, left_low_bits;
1799 dwarf_vma right_high_bits, right_low_bits;
1801 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1802 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1803 if (byte_get == byte_get_little_endian)
1806 left_high_bits ^= right_high_bits;
1807 right_high_bits ^= left_high_bits;
1808 left_high_bits ^= right_high_bits;
1809 left_low_bits ^= right_low_bits;
1810 right_low_bits ^= left_low_bits;
1811 left_low_bits ^= right_low_bits;
1813 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1814 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1815 left_high_bits, left_low_bits, right_high_bits,
1821 case DW_FORM_string:
1823 printf ("%c%.*s", delimiter, (int) (end - data), data);
1824 data += strnlen ((char *) data, end - data) + 1;
1828 case DW_FORM_exprloc:
1829 uvalue = read_uleb128 (data, & bytes_read, end);
1830 block_start = data + bytes_read;
1831 if (block_start >= end)
1833 warn (_("Block ends prematurely\n"));
1837 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1838 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1839 block_start + uvalue here. */
1840 data = block_start + uvalue;
1841 /* PR 17512: file: 008-103549-0.001:0.1. */
1842 if (block_start + uvalue > end || data < block_start)
1844 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1845 uvalue = end - block_start;
1848 data = block_start + uvalue;
1850 data = display_block (block_start, uvalue, end, delimiter);
1853 case DW_FORM_block1:
1854 SAFE_BYTE_GET (uvalue, data, 1, end);
1855 block_start = data + 1;
1856 if (block_start >= end)
1858 warn (_("Block ends prematurely\n"));
1862 data = block_start + uvalue;
1863 if (block_start + uvalue > end || data < block_start)
1865 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1866 uvalue = end - block_start;
1869 data = block_start + uvalue;
1871 data = display_block (block_start, uvalue, end, delimiter);
1874 case DW_FORM_block2:
1875 SAFE_BYTE_GET (uvalue, data, 2, end);
1876 block_start = data + 2;
1877 if (block_start >= end)
1879 warn (_("Block ends prematurely\n"));
1883 data = block_start + uvalue;
1884 if (block_start + uvalue > end || data < block_start)
1886 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1887 uvalue = end - block_start;
1890 data = block_start + uvalue;
1892 data = display_block (block_start, uvalue, end, delimiter);
1895 case DW_FORM_block4:
1896 SAFE_BYTE_GET (uvalue, data, 4, end);
1897 block_start = data + 4;
1898 /* PR 17512: file: 3371-3907-0.004. */
1899 if (block_start >= end)
1901 warn (_("Block ends prematurely\n"));
1905 data = block_start + uvalue;
1906 if (block_start + uvalue > end
1907 /* PR 17531: file: 5b5f0592. */
1908 || data < block_start)
1910 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1911 uvalue = end - block_start;
1914 data = block_start + uvalue;
1916 data = display_block (block_start, uvalue, end, delimiter);
1921 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1922 dwarf_vmatoa ("x", uvalue),
1923 fetch_indirect_string (uvalue));
1926 case DW_FORM_line_strp:
1928 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1929 dwarf_vmatoa ("x", uvalue),
1930 fetch_indirect_line_string (uvalue));
1933 case DW_FORM_GNU_str_index:
1936 const char *suffix = strrchr (section->name, '.');
1937 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1939 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1940 dwarf_vmatoa ("x", uvalue),
1941 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1945 case DW_FORM_GNU_strp_alt:
1947 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1948 dwarf_vmatoa ("x", uvalue));
1951 case DW_FORM_indirect:
1952 /* Handled above. */
1955 case DW_FORM_ref_sig8:
1958 dwarf_vma high_bits;
1961 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1962 printf ("%csignature: 0x%s", delimiter,
1963 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1968 case DW_FORM_GNU_addr_index:
1970 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
1971 dwarf_vmatoa ("x", uvalue),
1972 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1976 warn (_("Unrecognized form: %lu\n"), form);
1980 if ((do_loc || do_debug_loc || do_debug_ranges)
1981 && num_debug_info_entries == 0
1982 && debug_info_p != NULL)
1986 case DW_AT_frame_base:
1987 have_frame_base = 1;
1989 case DW_AT_location:
1990 case DW_AT_string_length:
1991 case DW_AT_return_addr:
1992 case DW_AT_data_member_location:
1993 case DW_AT_vtable_elem_location:
1995 case DW_AT_static_link:
1996 case DW_AT_use_location:
1997 case DW_AT_call_value:
1998 case DW_AT_GNU_call_site_value:
1999 case DW_AT_call_data_value:
2000 case DW_AT_GNU_call_site_data_value:
2001 case DW_AT_call_target:
2002 case DW_AT_GNU_call_site_target:
2003 case DW_AT_call_target_clobbered:
2004 case DW_AT_GNU_call_site_target_clobbered:
2005 if ((dwarf_version < 4
2006 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2007 || form == DW_FORM_sec_offset)
2009 /* Process location list. */
2010 unsigned int lmax = debug_info_p->max_loc_offsets;
2011 unsigned int num = debug_info_p->num_loc_offsets;
2013 if (lmax == 0 || num >= lmax)
2016 debug_info_p->loc_offsets = (dwarf_vma *)
2017 xcrealloc (debug_info_p->loc_offsets,
2018 lmax, sizeof (*debug_info_p->loc_offsets));
2019 debug_info_p->have_frame_base = (int *)
2020 xcrealloc (debug_info_p->have_frame_base,
2021 lmax, sizeof (*debug_info_p->have_frame_base));
2022 debug_info_p->max_loc_offsets = lmax;
2024 if (this_set != NULL)
2025 uvalue += this_set->section_offsets [DW_SECT_LOC];
2026 debug_info_p->loc_offsets [num] = uvalue;
2027 debug_info_p->have_frame_base [num] = have_frame_base;
2028 debug_info_p->num_loc_offsets++;
2033 if (need_base_address)
2034 debug_info_p->base_address = uvalue;
2037 case DW_AT_GNU_addr_base:
2038 debug_info_p->addr_base = uvalue;
2041 case DW_AT_GNU_ranges_base:
2042 debug_info_p->ranges_base = uvalue;
2046 if ((dwarf_version < 4
2047 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2048 || form == DW_FORM_sec_offset)
2050 /* Process range list. */
2051 unsigned int lmax = debug_info_p->max_range_lists;
2052 unsigned int num = debug_info_p->num_range_lists;
2054 if (lmax == 0 || num >= lmax)
2057 debug_info_p->range_lists = (dwarf_vma *)
2058 xcrealloc (debug_info_p->range_lists,
2059 lmax, sizeof (*debug_info_p->range_lists));
2060 debug_info_p->max_range_lists = lmax;
2062 debug_info_p->range_lists [num] = uvalue;
2063 debug_info_p->num_range_lists++;
2072 if (do_loc || attribute == 0)
2075 /* For some attributes we can display further information. */
2082 case DW_INL_not_inlined:
2083 printf (_("(not inlined)"));
2085 case DW_INL_inlined:
2086 printf (_("(inlined)"));
2088 case DW_INL_declared_not_inlined:
2089 printf (_("(declared as inline but ignored)"));
2091 case DW_INL_declared_inlined:
2092 printf (_("(declared as inline and inlined)"));
2095 printf (_(" (Unknown inline attribute value: %s)"),
2096 dwarf_vmatoa ("x", uvalue));
2101 case DW_AT_language:
2105 /* Ordered by the numeric value of these constants. */
2106 case DW_LANG_C89: printf ("(ANSI C)"); break;
2107 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2108 case DW_LANG_Ada83: printf ("(Ada)"); break;
2109 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2110 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2111 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2112 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2113 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2114 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2115 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2116 /* DWARF 2.1 values. */
2117 case DW_LANG_Java: printf ("(Java)"); break;
2118 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2119 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2120 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2121 /* DWARF 3 values. */
2122 case DW_LANG_PLI: printf ("(PLI)"); break;
2123 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2124 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2125 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2126 case DW_LANG_D: printf ("(D)"); break;
2127 /* DWARF 4 values. */
2128 case DW_LANG_Python: printf ("(Python)"); break;
2129 /* DWARF 5 values. */
2130 case DW_LANG_Go: printf ("(Go)"); break;
2131 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2132 case DW_LANG_C11: printf ("(C11)"); break;
2133 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2134 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2135 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2136 /* MIPS extension. */
2137 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2138 /* UPC extension. */
2139 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2141 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2142 printf (_("(implementation defined: %s)"),
2143 dwarf_vmatoa ("x", uvalue));
2145 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2150 case DW_AT_encoding:
2154 case DW_ATE_void: printf ("(void)"); break;
2155 case DW_ATE_address: printf ("(machine address)"); break;
2156 case DW_ATE_boolean: printf ("(boolean)"); break;
2157 case DW_ATE_complex_float: printf ("(complex float)"); break;
2158 case DW_ATE_float: printf ("(float)"); break;
2159 case DW_ATE_signed: printf ("(signed)"); break;
2160 case DW_ATE_signed_char: printf ("(signed char)"); break;
2161 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2162 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2163 /* DWARF 2.1 values: */
2164 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2165 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2166 /* DWARF 3 values: */
2167 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2168 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2169 case DW_ATE_edited: printf ("(edited)"); break;
2170 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2171 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2172 /* HP extensions: */
2173 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2174 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2175 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2176 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2177 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2178 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2179 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2180 /* DWARF 4 values: */
2181 case DW_ATE_UTF: printf ("(unicode string)"); break;
2184 if (uvalue >= DW_ATE_lo_user
2185 && uvalue <= DW_ATE_hi_user)
2186 printf (_("(user defined type)"));
2188 printf (_("(unknown type)"));
2193 case DW_AT_accessibility:
2197 case DW_ACCESS_public: printf ("(public)"); break;
2198 case DW_ACCESS_protected: printf ("(protected)"); break;
2199 case DW_ACCESS_private: printf ("(private)"); break;
2201 printf (_("(unknown accessibility)"));
2206 case DW_AT_visibility:
2210 case DW_VIS_local: printf ("(local)"); break;
2211 case DW_VIS_exported: printf ("(exported)"); break;
2212 case DW_VIS_qualified: printf ("(qualified)"); break;
2213 default: printf (_("(unknown visibility)")); break;
2217 case DW_AT_virtuality:
2221 case DW_VIRTUALITY_none: printf ("(none)"); break;
2222 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2223 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2224 default: printf (_("(unknown virtuality)")); break;
2228 case DW_AT_identifier_case:
2232 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2233 case DW_ID_up_case: printf ("(up_case)"); break;
2234 case DW_ID_down_case: printf ("(down_case)"); break;
2235 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2236 default: printf (_("(unknown case)")); break;
2240 case DW_AT_calling_convention:
2244 case DW_CC_normal: printf ("(normal)"); break;
2245 case DW_CC_program: printf ("(program)"); break;
2246 case DW_CC_nocall: printf ("(nocall)"); break;
2248 if (uvalue >= DW_CC_lo_user
2249 && uvalue <= DW_CC_hi_user)
2250 printf (_("(user defined)"));
2252 printf (_("(unknown convention)"));
2256 case DW_AT_ordering:
2260 case -1: printf (_("(undefined)")); break;
2261 case 0: printf ("(row major)"); break;
2262 case 1: printf ("(column major)"); break;
2266 case DW_AT_frame_base:
2267 have_frame_base = 1;
2269 case DW_AT_location:
2270 case DW_AT_string_length:
2271 case DW_AT_return_addr:
2272 case DW_AT_data_member_location:
2273 case DW_AT_vtable_elem_location:
2275 case DW_AT_static_link:
2276 case DW_AT_use_location:
2277 case DW_AT_call_value:
2278 case DW_AT_GNU_call_site_value:
2279 case DW_AT_call_data_value:
2280 case DW_AT_GNU_call_site_data_value:
2281 case DW_AT_call_target:
2282 case DW_AT_GNU_call_site_target:
2283 case DW_AT_call_target_clobbered:
2284 case DW_AT_GNU_call_site_target_clobbered:
2285 if ((dwarf_version < 4
2286 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2287 || form == DW_FORM_sec_offset)
2288 printf (_(" (location list)"));
2290 case DW_AT_allocated:
2291 case DW_AT_associated:
2292 case DW_AT_data_location:
2294 case DW_AT_upper_bound:
2295 case DW_AT_lower_bound:
2298 int need_frame_base;
2301 need_frame_base = decode_location_expression (block_start,
2306 cu_offset, section);
2308 if (need_frame_base && !have_frame_base)
2309 printf (_(" [without DW_AT_frame_base]"));
2315 if (form == DW_FORM_ref_sig8
2316 || form == DW_FORM_GNU_ref_alt)
2319 if (form == DW_FORM_ref1
2320 || form == DW_FORM_ref2
2321 || form == DW_FORM_ref4
2322 || form == DW_FORM_ref_udata)
2323 uvalue += cu_offset;
2325 if (uvalue >= section->size)
2326 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2327 dwarf_vmatoa ("x", uvalue),
2328 (unsigned long) (orig_data - section->start));
2331 unsigned long abbrev_number;
2332 abbrev_entry * entry;
2334 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2336 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2337 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2338 use different abbrev table, and we don't track .debug_info chunks
2340 if (form != DW_FORM_ref_addr)
2342 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2343 if (entry->entry == abbrev_number)
2346 printf (" (%s)", get_TAG_name (entry->tag));
2361 get_AT_name (unsigned long attribute)
2366 return "DW_AT value: 0";
2368 /* One value is shared by the MIPS and HP extensions: */
2369 if (attribute == DW_AT_MIPS_fde)
2370 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2372 name = get_DW_AT_name (attribute);
2376 static char buffer[100];
2378 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2386 static unsigned char *
2387 read_and_display_attr (unsigned long attribute,
2389 dwarf_signed_vma implicit_const,
2390 unsigned char * data,
2391 unsigned char * end,
2392 dwarf_vma cu_offset,
2393 dwarf_vma pointer_size,
2394 dwarf_vma offset_size,
2396 debug_info * debug_info_p,
2398 struct dwarf_section * section,
2399 struct cu_tu_set * this_set)
2402 printf (" %-18s:", get_AT_name (attribute));
2403 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2404 cu_offset, pointer_size, offset_size,
2405 dwarf_version, debug_info_p,
2406 do_loc, section, this_set, ' ');
2412 /* Process the contents of a .debug_info section. If do_loc is non-zero
2413 then we are scanning for location lists and we do not want to display
2414 anything to the user. If do_types is non-zero, we are processing
2415 a .debug_types section instead of a .debug_info section. */
2418 process_debug_info (struct dwarf_section *section,
2420 enum dwarf_section_display_enum abbrev_sec,
2424 unsigned char *start = section->start;
2425 unsigned char *end = start + section->size;
2426 unsigned char *section_begin;
2428 unsigned int num_units = 0;
2430 if ((do_loc || do_debug_loc || do_debug_ranges)
2431 && num_debug_info_entries == 0
2436 /* First scan the section to get the number of comp units. */
2437 for (section_begin = start, num_units = 0; section_begin < end;
2440 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2441 will be the length. For a 64-bit DWARF section, it'll be
2442 the escape code 0xffffffff followed by an 8 byte length. */
2443 SAFE_BYTE_GET (length, section_begin, 4, end);
2445 if (length == 0xffffffff)
2447 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2448 section_begin += length + 12;
2450 else if (length >= 0xfffffff0 && length < 0xffffffff)
2452 warn (_("Reserved length value (0x%s) found in section %s\n"),
2453 dwarf_vmatoa ("x", length), section->name);
2457 section_begin += length + 4;
2459 /* Negative values are illegal, they may even cause infinite
2460 looping. This can happen if we can't accurately apply
2461 relocations to an object file, or if the file is corrupt. */
2462 if ((signed long) length <= 0 || section_begin < start)
2464 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2465 dwarf_vmatoa ("x", length), section->name);
2472 error (_("No comp units in %s section ?\n"), section->name);
2476 /* Then allocate an array to hold the information. */
2477 debug_information = (debug_info *) cmalloc (num_units,
2478 sizeof (* debug_information));
2479 if (debug_information == NULL)
2481 error (_("Not enough memory for a debug info array of %u entries\n"),
2483 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2486 /* PR 17531: file: 92ca3797.
2487 We cannot rely upon the debug_information array being initialised
2488 before it is used. A corrupt file could easily contain references
2489 to a unit for which information has not been made available. So
2490 we ensure that the array is zeroed here. */
2491 memset (debug_information, 0, num_units * sizeof (*debug_information));
2493 alloc_num_debug_info_entries = num_units;
2498 if (dwarf_start_die == 0)
2499 printf (_("Contents of the %s section:\n\n"), section->name);
2501 load_debug_section (str, file);
2502 load_debug_section (line_str, file);
2503 load_debug_section (str_dwo, file);
2504 load_debug_section (str_index, file);
2505 load_debug_section (str_index_dwo, file);
2506 load_debug_section (debug_addr, file);
2509 load_debug_section (abbrev_sec, file);
2510 if (debug_displays [abbrev_sec].section.start == NULL)
2512 warn (_("Unable to locate %s section!\n"),
2513 debug_displays [abbrev_sec].section.name);
2517 for (section_begin = start, unit = 0; start < end; unit++)
2519 DWARF2_Internal_CompUnit compunit;
2520 unsigned char *hdrptr;
2521 unsigned char *tags;
2522 int level, last_level, saved_level;
2523 dwarf_vma cu_offset;
2524 unsigned int offset_size;
2525 int initial_length_size;
2526 dwarf_vma signature_high = 0;
2527 dwarf_vma signature_low = 0;
2528 dwarf_vma type_offset = 0;
2529 struct cu_tu_set *this_set;
2530 dwarf_vma abbrev_base;
2535 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2537 if (compunit.cu_length == 0xffffffff)
2539 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2541 initial_length_size = 12;
2546 initial_length_size = 4;
2549 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2551 cu_offset = start - section_begin;
2553 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2555 if (compunit.cu_version < 5)
2557 compunit.cu_unit_type = DW_UT_compile;
2558 /* Initialize it due to a false compiler warning. */
2559 compunit.cu_pointer_size = -1;
2563 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2564 do_types = (compunit.cu_unit_type == DW_UT_type);
2566 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2569 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2571 if (this_set == NULL)
2574 abbrev_size = debug_displays [abbrev_sec].section.size;
2578 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2579 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2582 if (compunit.cu_version < 5)
2583 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2585 /* PR 17512: file: 001-108546-0.001:0.1. */
2586 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2588 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2589 compunit.cu_pointer_size, offset_size);
2590 compunit.cu_pointer_size = offset_size;
2595 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2597 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2600 if ((do_loc || do_debug_loc || do_debug_ranges)
2601 && num_debug_info_entries == 0
2604 debug_information [unit].cu_offset = cu_offset;
2605 debug_information [unit].pointer_size
2606 = compunit.cu_pointer_size;
2607 debug_information [unit].offset_size = offset_size;
2608 debug_information [unit].dwarf_version = compunit.cu_version;
2609 debug_information [unit].base_address = 0;
2610 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2611 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2612 debug_information [unit].loc_offsets = NULL;
2613 debug_information [unit].have_frame_base = NULL;
2614 debug_information [unit].max_loc_offsets = 0;
2615 debug_information [unit].num_loc_offsets = 0;
2616 debug_information [unit].range_lists = NULL;
2617 debug_information [unit].max_range_lists= 0;
2618 debug_information [unit].num_range_lists = 0;
2621 if (!do_loc && dwarf_start_die == 0)
2623 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2624 dwarf_vmatoa ("x", cu_offset));
2625 printf (_(" Length: 0x%s (%s)\n"),
2626 dwarf_vmatoa ("x", compunit.cu_length),
2627 offset_size == 8 ? "64-bit" : "32-bit");
2628 printf (_(" Version: %d\n"), compunit.cu_version);
2629 printf (_(" Abbrev Offset: 0x%s\n"),
2630 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2631 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2636 printf (_(" Signature: 0x%s\n"),
2637 dwarf_vmatoa64 (signature_high, signature_low,
2638 buf, sizeof (buf)));
2639 printf (_(" Type Offset: 0x%s\n"),
2640 dwarf_vmatoa ("x", type_offset));
2642 if (this_set != NULL)
2644 dwarf_vma *offsets = this_set->section_offsets;
2645 size_t *sizes = this_set->section_sizes;
2647 printf (_(" Section contributions:\n"));
2648 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2649 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2650 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2651 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2652 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2653 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2654 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2655 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2656 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2657 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2658 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2659 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2663 if (cu_offset + compunit.cu_length + initial_length_size
2666 warn (_("Debug info is corrupted, length of CU at %s"
2667 " extends beyond end of section (length = %s)\n"),
2668 dwarf_vmatoa ("x", cu_offset),
2669 dwarf_vmatoa ("x", compunit.cu_length));
2674 start += compunit.cu_length + initial_length_size;
2678 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2679 dwarf_vmatoa ("x", cu_offset));
2683 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2685 warn (_("CU at offset %s contains corrupt or "
2686 "unsupported version number: %d.\n"),
2687 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2691 if (compunit.cu_unit_type != DW_UT_compile
2692 && compunit.cu_unit_type != DW_UT_type)
2694 warn (_("CU at offset %s contains corrupt or "
2695 "unsupported unit type: %d.\n"),
2696 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2702 /* Process the abbrevs used by this compilation unit. */
2703 if (compunit.cu_abbrev_offset >= abbrev_size)
2704 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2705 (unsigned long) compunit.cu_abbrev_offset,
2706 (unsigned long) abbrev_size);
2707 /* PR 17531: file:4bcd9ce9. */
2708 else if ((abbrev_base + abbrev_size)
2709 > debug_displays [abbrev_sec].section.size)
2710 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2711 (unsigned long) abbrev_base + abbrev_size,
2712 (unsigned long) debug_displays [abbrev_sec].section.size);
2714 process_abbrev_section
2715 (((unsigned char *) debug_displays [abbrev_sec].section.start
2716 + abbrev_base + compunit.cu_abbrev_offset),
2717 ((unsigned char *) debug_displays [abbrev_sec].section.start
2718 + abbrev_base + abbrev_size));
2723 while (tags < start)
2725 unsigned int bytes_read;
2726 unsigned long abbrev_number;
2727 unsigned long die_offset;
2728 abbrev_entry *entry;
2730 int do_printing = 1;
2732 die_offset = tags - section_begin;
2734 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2737 /* A null DIE marks the end of a list of siblings or it may also be
2738 a section padding. */
2739 if (abbrev_number == 0)
2741 /* Check if it can be a section padding for the last CU. */
2742 if (level == 0 && start == end)
2746 for (chk = tags; chk < start; chk++)
2753 if (!do_loc && die_offset >= dwarf_start_die
2754 && (dwarf_cutoff_level == -1
2755 || level < dwarf_cutoff_level))
2756 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2762 static unsigned num_bogus_warns = 0;
2764 if (num_bogus_warns < 3)
2766 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2767 die_offset, section->name);
2769 if (num_bogus_warns == 3)
2770 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2773 if (dwarf_start_die != 0 && level < saved_level)
2780 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2784 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2785 saved_level = level;
2786 do_printing = (dwarf_cutoff_level == -1
2787 || level < dwarf_cutoff_level);
2789 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2790 level, die_offset, abbrev_number);
2791 else if (dwarf_cutoff_level == -1
2792 || last_level < dwarf_cutoff_level)
2793 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2798 /* Scan through the abbreviation list until we reach the
2800 for (entry = first_abbrev;
2801 entry && entry->entry != abbrev_number;
2802 entry = entry->next)
2807 if (!do_loc && do_printing)
2812 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2813 die_offset, abbrev_number);
2817 if (!do_loc && do_printing)
2818 printf (" (%s)\n", get_TAG_name (entry->tag));
2823 need_base_address = 0;
2825 case DW_TAG_compile_unit:
2826 need_base_address = 1;
2828 case DW_TAG_entry_point:
2829 case DW_TAG_subprogram:
2830 need_base_address = 0;
2831 /* Assuming that there is no DW_AT_frame_base. */
2832 have_frame_base = 0;
2836 for (attr = entry->first_attr;
2837 attr && attr->attribute;
2842 if (! do_loc && do_printing)
2843 /* Show the offset from where the tag was extracted. */
2844 printf (" <%lx>", (unsigned long)(tags - section_begin));
2846 if (debug_information && unit < alloc_num_debug_info_entries)
2847 arg = debug_information + unit;
2851 tags = read_and_display_attr (attr->attribute,
2853 attr->implicit_const,
2857 compunit.cu_pointer_size,
2859 compunit.cu_version,
2861 do_loc || ! do_printing,
2866 if (entry->children)
2871 /* Set num_debug_info_entries here so that it can be used to check if
2872 we need to process .debug_loc and .debug_ranges sections. */
2873 if ((do_loc || do_debug_loc || do_debug_ranges)
2874 && num_debug_info_entries == 0
2877 if (num_units > alloc_num_debug_info_entries)
2878 num_debug_info_entries = alloc_num_debug_info_entries;
2880 num_debug_info_entries = num_units;
2889 /* Locate and scan the .debug_info section in the file and record the pointer
2890 sizes and offsets for the compilation units in it. Usually an executable
2891 will have just one pointer size, but this is not guaranteed, and so we try
2892 not to make any assumptions. Returns zero upon failure, or the number of
2893 compilation units upon success. */
2896 load_debug_info (void * file)
2898 /* Reset the last pointer size so that we can issue correct error
2899 messages if we are displaying the contents of more than one section. */
2900 last_pointer_size = 0;
2901 warned_about_missing_comp_units = FALSE;
2903 /* If we have already tried and failed to load the .debug_info
2904 section then do not bother to repeat the task. */
2905 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2908 /* If we already have the information there is nothing else to do. */
2909 if (num_debug_info_entries > 0)
2910 return num_debug_info_entries;
2912 /* If this is a DWARF package file, load the CU and TU indexes. */
2913 (void) load_cu_tu_indexes (file);
2915 if (load_debug_section (info, file)
2916 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2917 return num_debug_info_entries;
2919 if (load_debug_section (info_dwo, file)
2920 && process_debug_info (&debug_displays [info_dwo].section, file,
2922 return num_debug_info_entries;
2924 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2928 /* Read a DWARF .debug_line section header starting at DATA.
2929 Upon success returns an updated DATA pointer and the LINFO
2930 structure and the END_OF_SEQUENCE pointer will be filled in.
2931 Otherwise returns NULL. */
2933 static unsigned char *
2934 read_debug_line_header (struct dwarf_section * section,
2935 unsigned char * data,
2936 unsigned char * end,
2937 DWARF2_Internal_LineInfo * linfo,
2938 unsigned char ** end_of_sequence)
2940 unsigned char *hdrptr;
2941 unsigned int initial_length_size;
2942 unsigned char address_size, segment_selector_size;
2944 /* Extract information from the Line Number Program Header.
2945 (section 6.2.4 in the Dwarf3 doc). */
2948 /* Get and check the length of the block. */
2949 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2951 if (linfo->li_length == 0xffffffff)
2953 /* This section is 64-bit DWARF 3. */
2954 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2955 linfo->li_offset_size = 8;
2956 initial_length_size = 12;
2960 linfo->li_offset_size = 4;
2961 initial_length_size = 4;
2964 if (linfo->li_length + initial_length_size > section->size)
2966 /* If the length field has a relocation against it, then we should
2967 not complain if it is inaccurate (and probably negative). This
2968 happens in object files when the .debug_line section is actually
2969 comprised of several different .debug_line.* sections, (some of
2970 which may be removed by linker garbage collection), and a relocation
2971 is used to compute the correct length once that is done. */
2972 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
2974 linfo->li_length = (end - data) - initial_length_size;
2978 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2979 (long) linfo->li_length);
2984 /* Get and check the version number. */
2985 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2987 if (linfo->li_version != 2
2988 && linfo->li_version != 3
2989 && linfo->li_version != 4
2990 && linfo->li_version != 5)
2992 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
2993 "is currently supported.\n"));
2997 if (linfo->li_version >= 5)
2999 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3001 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3002 if (segment_selector_size != 0)
3004 warn (_("The %s section contains "
3005 "unsupported segment selector size: %d.\n"),
3006 section->name, segment_selector_size);
3011 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3012 linfo->li_offset_size, end);
3013 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3015 if (linfo->li_version >= 4)
3017 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3019 if (linfo->li_max_ops_per_insn == 0)
3021 warn (_("Invalid maximum operations per insn.\n"));
3026 linfo->li_max_ops_per_insn = 1;
3028 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3029 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3030 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3031 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3033 * end_of_sequence = data + linfo->li_length + initial_length_size;
3034 /* PR 17512: file:002-117414-0.004. */
3035 if (* end_of_sequence > end)
3037 warn (_("Line length %s extends beyond end of section\n"),
3038 dwarf_vmatoa ("u", linfo->li_length));
3039 * end_of_sequence = end;
3046 static unsigned char *
3047 display_formatted_table (unsigned char *data,
3048 unsigned char *start, unsigned char *end,
3049 const DWARF2_Internal_LineInfo *linfo,
3050 struct dwarf_section *section, const char *what)
3052 unsigned char *format_start, format_count, *format, formati;
3053 dwarf_vma data_count, datai;
3054 unsigned int bytes_read, namepass, last_entry = 0;
3056 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3057 format_start = data;
3058 for (formati = 0; formati < format_count; formati++)
3060 read_uleb128 (data, & bytes_read, end);
3062 read_uleb128 (data, & bytes_read, end);
3066 warn (_("Corrupt %s entry format table entry\n"), what);
3071 data_count = read_uleb128 (data, & bytes_read, end);
3075 warn (_("Corrupt %s list\n"), what);
3079 if (data_count == 0)
3081 printf (_("\n The %s Table is empty.\n"), what);
3085 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3086 (long)(data - start));
3088 printf (_(" Entry"));
3089 /* Delay displaying name as the last entry for better screen layout. */
3090 for (namepass = 0; namepass < 2; namepass++)
3092 format = format_start;
3093 for (formati = 0; formati < format_count; formati++)
3095 dwarf_vma content_type;
3097 content_type = read_uleb128 (format, & bytes_read, end);
3098 format += bytes_read;
3099 if ((content_type == DW_LNCT_path) == (namepass == 1))
3100 switch (content_type)
3103 printf (_("\tName"));
3105 case DW_LNCT_directory_index:
3106 printf (_("\tDir"));
3108 case DW_LNCT_timestamp:
3109 printf (_("\tTime"));
3112 printf (_("\tSize"));
3115 printf (_("\tMD5"));
3118 printf (_("\t(Unknown format content type %s)"),
3119 dwarf_vmatoa ("u", content_type));
3121 read_uleb128 (format, & bytes_read, end);
3122 format += bytes_read;
3127 for (datai = 0; datai < data_count; datai++)
3129 unsigned char *datapass = data;
3131 printf (" %d", last_entry++);
3132 /* Delay displaying name as the last entry for better screen layout. */
3133 for (namepass = 0; namepass < 2; namepass++)
3135 format = format_start;
3137 for (formati = 0; formati < format_count; formati++)
3139 dwarf_vma content_type, form;
3141 content_type = read_uleb128 (format, & bytes_read, end);
3142 format += bytes_read;
3143 form = read_uleb128 (format, & bytes_read, end);
3144 format += bytes_read;
3145 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3146 linfo->li_offset_size,
3147 linfo->li_version, NULL,
3148 ((content_type == DW_LNCT_path) != (namepass == 1)),
3149 section, NULL, '\t');
3154 warn (_("Corrupt %s entries list\n"), what);
3163 display_debug_lines_raw (struct dwarf_section *section,
3164 unsigned char *data,
3165 unsigned char *end, void *file)
3167 unsigned char *start = section->start;
3169 printf (_("Raw dump of debug contents of section %s:\n\n"),
3174 static DWARF2_Internal_LineInfo saved_linfo;
3175 DWARF2_Internal_LineInfo linfo;
3176 unsigned char *standard_opcodes;
3177 unsigned char *end_of_sequence;
3180 if (const_strneq (section->name, ".debug_line.")
3181 /* Note: the following does not apply to .debug_line.dwo sections.
3182 These are full debug_line sections. */
3183 && strcmp (section->name, ".debug_line.dwo") != 0)
3185 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3186 section containing just the Line Number Statements. They are
3187 created by the assembler and intended to be used alongside gcc's
3188 -ffunction-sections command line option. When the linker's
3189 garbage collection decides to discard a .text.<foo> section it
3190 can then also discard the line number information in .debug_line.<foo>.
3192 Since the section is a fragment it does not have the details
3193 needed to fill out a LineInfo structure, so instead we use the
3194 details from the last full debug_line section that we processed. */
3195 end_of_sequence = end;
3196 standard_opcodes = NULL;
3197 linfo = saved_linfo;
3198 /* PR 17531: file: 0522b371. */
3199 if (linfo.li_line_range == 0)
3201 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3204 reset_state_machine (linfo.li_default_is_stmt);
3208 unsigned char * hdrptr;
3210 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3211 & end_of_sequence)) == NULL)
3214 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3215 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3216 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3217 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3218 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3219 if (linfo.li_version >= 4)
3220 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3221 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3222 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3223 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3224 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3226 /* PR 17512: file: 1665-6428-0.004. */
3227 if (linfo.li_line_range == 0)
3229 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3230 linfo.li_line_range = 1;
3233 reset_state_machine (linfo.li_default_is_stmt);
3235 /* Display the contents of the Opcodes table. */
3236 standard_opcodes = hdrptr;
3238 /* PR 17512: file: 002-417945-0.004. */
3239 if (standard_opcodes + linfo.li_opcode_base >= end)
3241 warn (_("Line Base extends beyond end of section\n"));
3245 printf (_("\n Opcodes:\n"));
3247 for (i = 1; i < linfo.li_opcode_base; i++)
3248 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3250 /* Display the contents of the Directory table. */
3251 data = standard_opcodes + linfo.li_opcode_base - 1;
3253 if (linfo.li_version >= 5)
3255 load_debug_section (line_str, file);
3257 data = display_formatted_table (data, start, end, &linfo, section,
3259 data = display_formatted_table (data, start, end, &linfo, section,
3265 printf (_("\n The Directory Table is empty.\n"));
3268 unsigned int last_dir_entry = 0;
3270 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3271 (long)(data - start));
3273 while (data < end && *data != 0)
3275 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3277 data += strnlen ((char *) data, end - data) + 1;
3280 /* PR 17512: file: 002-132094-0.004. */
3281 if (data >= end - 1)
3285 /* Skip the NUL at the end of the table. */
3288 /* Display the contents of the File Name table. */
3290 printf (_("\n The File Name Table is empty.\n"));
3293 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3294 (long)(data - start));
3295 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3297 while (data < end && *data != 0)
3299 unsigned char *name;
3300 unsigned int bytes_read;
3302 printf (" %d\t", ++state_machine_regs.last_file_entry);
3304 data += strnlen ((char *) data, end - data) + 1;
3307 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3310 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3313 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3315 printf ("%.*s\n", (int)(end - name), name);
3319 warn (_("Corrupt file name table entry\n"));
3325 /* Skip the NUL at the end of the table. */
3330 saved_linfo = linfo;
3333 /* Now display the statements. */
3334 if (data >= end_of_sequence)
3335 printf (_(" No Line Number Statements.\n"));
3338 printf (_(" Line Number Statements:\n"));
3340 while (data < end_of_sequence)
3342 unsigned char op_code;
3343 dwarf_signed_vma adv;
3345 unsigned int bytes_read;
3347 printf (" [0x%08lx]", (long)(data - start));
3351 if (op_code >= linfo.li_opcode_base)
3353 op_code -= linfo.li_opcode_base;
3354 uladv = (op_code / linfo.li_line_range);
3355 if (linfo.li_max_ops_per_insn == 1)
3357 uladv *= linfo.li_min_insn_length;
3358 state_machine_regs.address += uladv;
3359 printf (_(" Special opcode %d: "
3360 "advance Address by %s to 0x%s"),
3361 op_code, dwarf_vmatoa ("u", uladv),
3362 dwarf_vmatoa ("x", state_machine_regs.address));
3366 state_machine_regs.address
3367 += ((state_machine_regs.op_index + uladv)
3368 / linfo.li_max_ops_per_insn)
3369 * linfo.li_min_insn_length;
3370 state_machine_regs.op_index
3371 = (state_machine_regs.op_index + uladv)
3372 % linfo.li_max_ops_per_insn;
3373 printf (_(" Special opcode %d: "
3374 "advance Address by %s to 0x%s[%d]"),
3375 op_code, dwarf_vmatoa ("u", uladv),
3376 dwarf_vmatoa ("x", state_machine_regs.address),
3377 state_machine_regs.op_index);
3379 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3380 state_machine_regs.line += adv;
3381 printf (_(" and Line by %s to %d\n"),
3382 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3384 else switch (op_code)
3386 case DW_LNS_extended_op:
3387 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3391 printf (_(" Copy\n"));
3394 case DW_LNS_advance_pc:
3395 uladv = read_uleb128 (data, & bytes_read, end);
3397 if (linfo.li_max_ops_per_insn == 1)
3399 uladv *= linfo.li_min_insn_length;
3400 state_machine_regs.address += uladv;
3401 printf (_(" Advance PC by %s to 0x%s\n"),
3402 dwarf_vmatoa ("u", uladv),
3403 dwarf_vmatoa ("x", state_machine_regs.address));
3407 state_machine_regs.address
3408 += ((state_machine_regs.op_index + uladv)
3409 / linfo.li_max_ops_per_insn)
3410 * linfo.li_min_insn_length;
3411 state_machine_regs.op_index
3412 = (state_machine_regs.op_index + uladv)
3413 % linfo.li_max_ops_per_insn;
3414 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3415 dwarf_vmatoa ("u", uladv),
3416 dwarf_vmatoa ("x", state_machine_regs.address),
3417 state_machine_regs.op_index);
3421 case DW_LNS_advance_line:
3422 adv = read_sleb128 (data, & bytes_read, end);
3424 state_machine_regs.line += adv;
3425 printf (_(" Advance Line by %s to %d\n"),
3426 dwarf_vmatoa ("d", adv),
3427 state_machine_regs.line);
3430 case DW_LNS_set_file:
3431 adv = read_uleb128 (data, & bytes_read, end);
3433 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3434 dwarf_vmatoa ("d", adv));
3435 state_machine_regs.file = adv;
3438 case DW_LNS_set_column:
3439 uladv = read_uleb128 (data, & bytes_read, end);
3441 printf (_(" Set column to %s\n"),
3442 dwarf_vmatoa ("u", uladv));
3443 state_machine_regs.column = uladv;
3446 case DW_LNS_negate_stmt:
3447 adv = state_machine_regs.is_stmt;
3449 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3450 state_machine_regs.is_stmt = adv;
3453 case DW_LNS_set_basic_block:
3454 printf (_(" Set basic block\n"));
3455 state_machine_regs.basic_block = 1;
3458 case DW_LNS_const_add_pc:
3459 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3460 if (linfo.li_max_ops_per_insn)
3462 uladv *= linfo.li_min_insn_length;
3463 state_machine_regs.address += uladv;
3464 printf (_(" Advance PC by constant %s to 0x%s\n"),
3465 dwarf_vmatoa ("u", uladv),
3466 dwarf_vmatoa ("x", state_machine_regs.address));
3470 state_machine_regs.address
3471 += ((state_machine_regs.op_index + uladv)
3472 / linfo.li_max_ops_per_insn)
3473 * linfo.li_min_insn_length;
3474 state_machine_regs.op_index
3475 = (state_machine_regs.op_index + uladv)
3476 % linfo.li_max_ops_per_insn;
3477 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3478 dwarf_vmatoa ("u", uladv),
3479 dwarf_vmatoa ("x", state_machine_regs.address),
3480 state_machine_regs.op_index);
3484 case DW_LNS_fixed_advance_pc:
3485 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3486 state_machine_regs.address += uladv;
3487 state_machine_regs.op_index = 0;
3488 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3489 dwarf_vmatoa ("u", uladv),
3490 dwarf_vmatoa ("x", state_machine_regs.address));
3493 case DW_LNS_set_prologue_end:
3494 printf (_(" Set prologue_end to true\n"));
3497 case DW_LNS_set_epilogue_begin:
3498 printf (_(" Set epilogue_begin to true\n"));
3501 case DW_LNS_set_isa:
3502 uladv = read_uleb128 (data, & bytes_read, end);
3504 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3508 printf (_(" Unknown opcode %d with operands: "), op_code);
3510 if (standard_opcodes != NULL)
3511 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3513 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3515 i == 1 ? "" : ", ");
3531 unsigned char *name;
3532 unsigned int directory_index;
3533 unsigned int modification_date;
3534 unsigned int length;
3537 /* Output a decoded representation of the .debug_line section. */
3540 display_debug_lines_decoded (struct dwarf_section *section,
3541 unsigned char *data,
3542 unsigned char *end, void *fileptr)
3544 static DWARF2_Internal_LineInfo saved_linfo;
3546 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3551 /* This loop amounts to one iteration per compilation unit. */
3552 DWARF2_Internal_LineInfo linfo;
3553 unsigned char *standard_opcodes;
3554 unsigned char *end_of_sequence;
3556 File_Entry *file_table = NULL;
3557 unsigned int n_files = 0;
3558 unsigned char **directory_table = NULL;
3559 dwarf_vma n_directories = 0;
3561 if (const_strneq (section->name, ".debug_line.")
3562 /* Note: the following does not apply to .debug_line.dwo sections.
3563 These are full debug_line sections. */
3564 && strcmp (section->name, ".debug_line.dwo") != 0)
3566 /* See comment in display_debug_lines_raw(). */
3567 end_of_sequence = end;
3568 standard_opcodes = NULL;
3569 linfo = saved_linfo;
3570 /* PR 17531: file: 0522b371. */
3571 if (linfo.li_line_range == 0)
3573 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3576 reset_state_machine (linfo.li_default_is_stmt);
3580 unsigned char *hdrptr;
3582 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3583 & end_of_sequence)) == NULL)
3586 /* PR 17531: file: 0522b371. */
3587 if (linfo.li_line_range == 0)
3589 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3590 linfo.li_line_range = 1;
3592 reset_state_machine (linfo.li_default_is_stmt);
3594 /* Save a pointer to the contents of the Opcodes table. */
3595 standard_opcodes = hdrptr;
3597 /* Traverse the Directory table just to count entries. */
3598 data = standard_opcodes + linfo.li_opcode_base - 1;
3602 warn (_("opcode base of %d extends beyond end of section\n"),
3603 linfo.li_opcode_base);
3607 if (linfo.li_version >= 5)
3609 unsigned char *format_start, format_count, *format;
3610 dwarf_vma formati, entryi;
3611 unsigned int bytes_read;
3613 load_debug_section (line_str, fileptr);
3615 /* Skip directories format. */
3616 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3617 format_start = data;
3618 for (formati = 0; formati < format_count; formati++)
3620 read_uleb128 (data, & bytes_read, end);
3622 read_uleb128 (data, & bytes_read, end);
3626 n_directories = read_uleb128 (data, & bytes_read, end);
3630 warn (_("Corrupt directories list\n"));
3634 directory_table = (unsigned char **)
3635 xmalloc (n_directories * sizeof (unsigned char *));
3637 for (entryi = 0; entryi < n_directories; entryi++)
3639 unsigned char **pathp = &directory_table[entryi];
3641 format = format_start;
3642 for (formati = 0; formati < format_count; formati++)
3644 dwarf_vma content_type, form;
3647 content_type = read_uleb128 (format, & bytes_read, end);
3648 format += bytes_read;
3649 form = read_uleb128 (format, & bytes_read, end);
3650 format += bytes_read;
3653 warn (_("Corrupt directories list\n"));
3656 switch (content_type)
3661 case DW_FORM_string:
3664 case DW_FORM_line_strp:
3665 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3667 /* Remove const by the cast. */
3668 *pathp = (unsigned char *)
3669 fetch_indirect_line_string (uvalue);
3674 data = read_and_display_attr_value (0, form, 0, data, end,
3676 linfo.li_offset_size,
3683 warn (_("Corrupt directories list\n"));
3688 /* Skip files format. */
3689 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3690 format_start = data;
3691 for (formati = 0; formati < format_count; formati++)
3693 read_uleb128 (data, & bytes_read, end);
3695 read_uleb128 (data, & bytes_read, end);
3699 n_files = read_uleb128 (data, & bytes_read, end);
3703 warn (_("Corrupt file name list\n"));
3707 file_table = (File_Entry *) xcalloc (1, n_files
3708 * sizeof (File_Entry));
3710 for (entryi = 0; entryi < n_files; entryi++)
3712 File_Entry *file = &file_table[entryi];
3714 format = format_start;
3715 for (formati = 0; formati < format_count; formati++)
3717 dwarf_vma content_type, form;
3720 content_type = read_uleb128 (format, & bytes_read, end);
3721 format += bytes_read;
3722 form = read_uleb128 (format, & bytes_read, end);
3723 format += bytes_read;
3726 warn (_("Corrupt file name list\n"));
3729 switch (content_type)
3734 case DW_FORM_string:
3737 case DW_FORM_line_strp:
3738 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3740 /* Remove const by the cast. */
3741 file->name = (unsigned char *)
3742 fetch_indirect_line_string (uvalue);
3746 case DW_LNCT_directory_index:
3750 SAFE_BYTE_GET (file->directory_index, data, 1,
3754 SAFE_BYTE_GET (file->directory_index, data, 2,
3758 file->directory_index = read_uleb128 (data, NULL,
3764 data = read_and_display_attr_value (0, form, 0, data, end,
3766 linfo.li_offset_size,
3773 warn (_("Corrupt file name list\n"));
3782 unsigned char *ptr_directory_table = data;
3784 while (data < end && *data != 0)
3786 data += strnlen ((char *) data, end - data) + 1;
3793 warn (_("directory table ends unexpectedly\n"));
3798 /* Go through the directory table again to save the directories. */
3799 directory_table = (unsigned char **)
3800 xmalloc (n_directories * sizeof (unsigned char *));
3803 while (*ptr_directory_table != 0)
3805 directory_table[i] = ptr_directory_table;
3806 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3807 ptr_directory_table - end) + 1;
3811 /* Skip the NUL at the end of the table. */
3814 /* Traverse the File Name table just to count the entries. */
3815 if (data < end && *data != 0)
3817 unsigned char *ptr_file_name_table = data;
3819 while (data < end && *data != 0)
3821 unsigned int bytes_read;
3823 /* Skip Name, directory index, last modification time and length
3825 data += strnlen ((char *) data, end - data) + 1;
3826 read_uleb128 (data, & bytes_read, end);
3828 read_uleb128 (data, & bytes_read, end);
3830 read_uleb128 (data, & bytes_read, end);
3838 warn (_("file table ends unexpectedly\n"));
3843 /* Go through the file table again to save the strings. */
3844 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3847 while (*ptr_file_name_table != 0)
3849 unsigned int bytes_read;
3851 file_table[i].name = ptr_file_name_table;
3852 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3853 end - ptr_file_name_table) + 1;
3855 /* We are not interested in directory, time or size. */
3856 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3858 ptr_file_name_table += bytes_read;
3859 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3861 ptr_file_name_table += bytes_read;
3862 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3863 ptr_file_name_table += bytes_read;
3869 /* Skip the NUL at the end of the table. */
3873 /* Print the Compilation Unit's name and a header. */
3874 if (file_table == NULL)
3876 else if (directory_table == NULL)
3877 printf (_("CU: %s:\n"), file_table[0].name);
3880 unsigned int ix = file_table[0].directory_index;
3881 const char *directory;
3886 else if (n_directories == 0)
3887 directory = _("<unknown>");
3888 else if (ix > n_directories)
3890 warn (_("directory index %u > number of directories %s\n"),
3891 ix, dwarf_vmatoa ("u", n_directories));
3892 directory = _("<corrupt>");
3895 directory = (char *) directory_table[ix - 1];
3897 if (do_wide || strlen (directory) < 76)
3898 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3900 printf ("%s:\n", file_table[0].name);
3903 printf (_("File name Line number Starting address\n"));
3904 saved_linfo = linfo;
3907 /* This loop iterates through the Dwarf Line Number Program. */
3908 while (data < end_of_sequence)
3910 unsigned char op_code;
3912 unsigned long int uladv;
3913 unsigned int bytes_read;
3914 int is_special_opcode = 0;
3918 if (op_code >= linfo.li_opcode_base)
3920 op_code -= linfo.li_opcode_base;
3921 uladv = (op_code / linfo.li_line_range);
3922 if (linfo.li_max_ops_per_insn == 1)
3924 uladv *= linfo.li_min_insn_length;
3925 state_machine_regs.address += uladv;
3929 state_machine_regs.address
3930 += ((state_machine_regs.op_index + uladv)
3931 / linfo.li_max_ops_per_insn)
3932 * linfo.li_min_insn_length;
3933 state_machine_regs.op_index
3934 = (state_machine_regs.op_index + uladv)
3935 % linfo.li_max_ops_per_insn;
3938 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3939 state_machine_regs.line += adv;
3940 is_special_opcode = 1;
3942 else switch (op_code)
3944 case DW_LNS_extended_op:
3946 unsigned int ext_op_code_len;
3947 unsigned char ext_op_code;
3948 unsigned char *op_code_data = data;
3950 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3952 op_code_data += bytes_read;
3954 if (ext_op_code_len == 0)
3956 warn (_("Badly formed extended line op encountered!\n"));
3959 ext_op_code_len += bytes_read;
3960 ext_op_code = *op_code_data++;
3962 switch (ext_op_code)
3964 case DW_LNE_end_sequence:
3965 reset_state_machine (linfo.li_default_is_stmt);
3967 case DW_LNE_set_address:
3968 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3970 ext_op_code_len - bytes_read - 1,
3972 state_machine_regs.op_index = 0;
3974 case DW_LNE_define_file:
3976 file_table = (File_Entry *) xrealloc
3977 (file_table, (n_files + 1) * sizeof (File_Entry));
3979 ++state_machine_regs.last_file_entry;
3980 /* Source file name. */
3981 file_table[n_files].name = op_code_data;
3982 op_code_data += strlen ((char *) op_code_data) + 1;
3983 /* Directory index. */
3984 file_table[n_files].directory_index =
3985 read_uleb128 (op_code_data, & bytes_read,
3987 op_code_data += bytes_read;
3988 /* Last modification time. */
3989 file_table[n_files].modification_date =
3990 read_uleb128 (op_code_data, & bytes_read,
3992 op_code_data += bytes_read;
3994 file_table[n_files].length =
3995 read_uleb128 (op_code_data, & bytes_read,
4001 case DW_LNE_set_discriminator:
4002 case DW_LNE_HP_set_sequence:
4003 /* Simply ignored. */
4007 printf (_("UNKNOWN (%u): length %d\n"),
4008 ext_op_code, ext_op_code_len - bytes_read);
4011 data += ext_op_code_len;
4017 case DW_LNS_advance_pc:
4018 uladv = read_uleb128 (data, & bytes_read, end);
4020 if (linfo.li_max_ops_per_insn == 1)
4022 uladv *= linfo.li_min_insn_length;
4023 state_machine_regs.address += uladv;
4027 state_machine_regs.address
4028 += ((state_machine_regs.op_index + uladv)
4029 / linfo.li_max_ops_per_insn)
4030 * linfo.li_min_insn_length;
4031 state_machine_regs.op_index
4032 = (state_machine_regs.op_index + uladv)
4033 % linfo.li_max_ops_per_insn;
4037 case DW_LNS_advance_line:
4038 adv = read_sleb128 (data, & bytes_read, end);
4040 state_machine_regs.line += adv;
4043 case DW_LNS_set_file:
4044 adv = read_uleb128 (data, & bytes_read, end);
4046 state_machine_regs.file = adv;
4049 unsigned file = state_machine_regs.file - 1;
4052 if (file_table == NULL || n_files == 0)
4053 printf (_("\n [Use file table entry %d]\n"), file);
4055 else if (file >= n_files)
4057 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4058 printf (_("\n <over large file table index %u>"), file);
4060 else if ((dir = file_table[file].directory_index) == 0)
4061 /* If directory index is 0, that means current directory. */
4062 printf ("\n./%s:[++]\n", file_table[file].name);
4063 else if (directory_table == NULL || n_directories == 0)
4064 printf (_("\n [Use file %s in directory table entry %d]\n"),
4065 file_table[file].name, dir);
4067 else if (dir > n_directories)
4069 warn (_("directory index %u > number of directories %s\n"),
4070 dir, dwarf_vmatoa ("u", n_directories));
4071 printf (_("\n <over large directory table entry %u>\n"), dir);
4074 printf ("\n%s/%s:\n",
4075 /* The directory index starts counting at 1. */
4076 directory_table[dir - 1], file_table[file].name);
4080 case DW_LNS_set_column:
4081 uladv = read_uleb128 (data, & bytes_read, end);
4083 state_machine_regs.column = uladv;
4086 case DW_LNS_negate_stmt:
4087 adv = state_machine_regs.is_stmt;
4089 state_machine_regs.is_stmt = adv;
4092 case DW_LNS_set_basic_block:
4093 state_machine_regs.basic_block = 1;
4096 case DW_LNS_const_add_pc:
4097 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4098 if (linfo.li_max_ops_per_insn == 1)
4100 uladv *= linfo.li_min_insn_length;
4101 state_machine_regs.address += uladv;
4105 state_machine_regs.address
4106 += ((state_machine_regs.op_index + uladv)
4107 / linfo.li_max_ops_per_insn)
4108 * linfo.li_min_insn_length;
4109 state_machine_regs.op_index
4110 = (state_machine_regs.op_index + uladv)
4111 % linfo.li_max_ops_per_insn;
4115 case DW_LNS_fixed_advance_pc:
4116 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4117 state_machine_regs.address += uladv;
4118 state_machine_regs.op_index = 0;
4121 case DW_LNS_set_prologue_end:
4124 case DW_LNS_set_epilogue_begin:
4127 case DW_LNS_set_isa:
4128 uladv = read_uleb128 (data, & bytes_read, end);
4130 printf (_(" Set ISA to %lu\n"), uladv);
4134 printf (_(" Unknown opcode %d with operands: "), op_code);
4136 if (standard_opcodes != NULL)
4137 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4139 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4141 i == 1 ? "" : ", ");
4148 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4149 to the DWARF address/line matrix. */
4150 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
4151 || (op_code == DW_LNS_copy))
4153 const unsigned int MAX_FILENAME_LENGTH = 35;
4155 char *newFileName = NULL;
4156 size_t fileNameLength;
4160 unsigned indx = state_machine_regs.file - 1;
4162 if (indx >= n_files)
4164 warn (_("corrupt file index %u encountered\n"), indx);
4165 fileName = _("<corrupt>");
4168 fileName = (char *) file_table[indx].name;
4171 fileName = _("<unknown>");
4173 fileNameLength = strlen (fileName);
4175 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4177 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4178 /* Truncate file name */
4179 strncpy (newFileName,
4180 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4181 MAX_FILENAME_LENGTH + 1);
4185 newFileName = (char *) xmalloc (fileNameLength + 1);
4186 strncpy (newFileName, fileName, fileNameLength + 1);
4189 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4191 if (linfo.li_max_ops_per_insn == 1)
4192 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
4193 newFileName, state_machine_regs.line,
4194 state_machine_regs.address);
4196 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4197 newFileName, state_machine_regs.line,
4198 state_machine_regs.address,
4199 state_machine_regs.op_index);
4203 if (linfo.li_max_ops_per_insn == 1)
4204 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
4205 newFileName, state_machine_regs.line,
4206 state_machine_regs.address);
4208 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4209 newFileName, state_machine_regs.line,
4210 state_machine_regs.address,
4211 state_machine_regs.op_index);
4214 if (op_code == DW_LNE_end_sequence)
4228 if (directory_table)
4230 free (directory_table);
4231 directory_table = NULL;
4242 display_debug_lines (struct dwarf_section *section, void *file)
4244 unsigned char *data = section->start;
4245 unsigned char *end = data + section->size;
4247 int retValDecoded = 1;
4249 if (do_debug_lines == 0)
4250 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4252 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4253 retValRaw = display_debug_lines_raw (section, data, end, file);
4255 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4256 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4258 if (!retValRaw || !retValDecoded)
4265 find_debug_info_for_offset (unsigned long offset)
4269 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4272 for (i = 0; i < num_debug_info_entries; i++)
4273 if (debug_information[i].cu_offset == offset)
4274 return debug_information + i;
4280 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4282 /* See gdb/gdb-index.h. */
4283 static const char * const kinds[] =
4295 return _ (kinds[kind]);
4299 display_debug_pubnames_worker (struct dwarf_section *section,
4300 void *file ATTRIBUTE_UNUSED,
4303 DWARF2_Internal_PubNames names;
4304 unsigned char *start = section->start;
4305 unsigned char *end = start + section->size;
4307 /* It does not matter if this load fails,
4308 we test for that later on. */
4309 load_debug_info (file);
4311 printf (_("Contents of the %s section:\n\n"), section->name);
4315 unsigned char *data;
4318 unsigned int offset_size, initial_length_size;
4322 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4323 if (names.pn_length == 0xffffffff)
4325 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4327 initial_length_size = 12;
4332 initial_length_size = 4;
4335 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4336 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4338 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4339 && num_debug_info_entries > 0
4340 && find_debug_info_for_offset (names.pn_offset) == NULL)
4341 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4342 (unsigned long) names.pn_offset, section->name);
4344 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4346 adr = start + names.pn_length + initial_length_size;
4347 /* PR 17531: file: 7615b6b2. */
4348 if ((dwarf_signed_vma) names.pn_length < 0
4349 /* PR 17531: file: a5dbeaa7. */
4352 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4358 printf (_(" Length: %ld\n"),
4359 (long) names.pn_length);
4360 printf (_(" Version: %d\n"),
4362 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4363 (unsigned long) names.pn_offset);
4364 printf (_(" Size of area in .debug_info section: %ld\n"),
4365 (long) names.pn_size);
4367 if (names.pn_version != 2 && names.pn_version != 3)
4369 static int warned = 0;
4373 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4381 printf (_("\n Offset Kind Name\n"));
4383 printf (_("\n Offset\tName\n"));
4387 bfd_size_type maxprint;
4389 SAFE_BYTE_GET (offset, data, offset_size, end);
4393 data += offset_size;
4396 maxprint = (end - data) - 1;
4400 unsigned int kind_data;
4401 gdb_index_symbol_kind kind;
4402 const char *kind_name;
4405 SAFE_BYTE_GET (kind_data, data, 1, end);
4408 /* GCC computes the kind as the upper byte in the CU index
4409 word, and then right shifts it by the CU index size.
4410 Left shift KIND to where the gdb-index.h accessor macros
4412 kind_data <<= GDB_INDEX_CU_BITSIZE;
4413 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4414 kind_name = get_gdb_index_symbol_kind_name (kind);
4415 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4416 printf (" %-6lx %s,%-10s %.*s\n",
4417 (unsigned long) offset, is_static ? _("s") : _("g"),
4418 kind_name, (int) maxprint, data);
4421 printf (" %-6lx\t%.*s\n",
4422 (unsigned long) offset, (int) maxprint, data);
4424 data += strnlen ((char *) data, maxprint) + 1;
4429 while (offset != 0);
4437 display_debug_pubnames (struct dwarf_section *section, void *file)
4439 return display_debug_pubnames_worker (section, file, 0);
4443 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4445 return display_debug_pubnames_worker (section, file, 1);
4449 display_debug_macinfo (struct dwarf_section *section,
4450 void *file ATTRIBUTE_UNUSED)
4452 unsigned char *start = section->start;
4453 unsigned char *end = start + section->size;
4454 unsigned char *curr = start;
4455 unsigned int bytes_read;
4456 enum dwarf_macinfo_record_type op;
4458 printf (_("Contents of the %s section:\n\n"), section->name);
4462 unsigned int lineno;
4463 const unsigned char *string;
4465 op = (enum dwarf_macinfo_record_type) *curr;
4470 case DW_MACINFO_start_file:
4472 unsigned int filenum;
4474 lineno = read_uleb128 (curr, & bytes_read, end);
4476 filenum = read_uleb128 (curr, & bytes_read, end);
4479 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4484 case DW_MACINFO_end_file:
4485 printf (_(" DW_MACINFO_end_file\n"));
4488 case DW_MACINFO_define:
4489 lineno = read_uleb128 (curr, & bytes_read, end);
4492 curr += strnlen ((char *) string, end - string) + 1;
4493 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4497 case DW_MACINFO_undef:
4498 lineno = read_uleb128 (curr, & bytes_read, end);
4501 curr += strnlen ((char *) string, end - string) + 1;
4502 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4506 case DW_MACINFO_vendor_ext:
4508 unsigned int constant;
4510 constant = read_uleb128 (curr, & bytes_read, end);
4513 curr += strnlen ((char *) string, end - string) + 1;
4514 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4524 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4525 filename and dirname corresponding to file name table entry with index
4526 FILEIDX. Return NULL on failure. */
4528 static unsigned char *
4529 get_line_filename_and_dirname (dwarf_vma line_offset,
4531 unsigned char **dir_name)
4533 struct dwarf_section *section = &debug_displays [line].section;
4534 unsigned char *hdrptr, *dirtable, *file_name;
4535 unsigned int offset_size, initial_length_size;
4536 unsigned int version, opcode_base, bytes_read;
4537 dwarf_vma length, diridx;
4538 const unsigned char * end;
4541 if (section->start == NULL
4542 || line_offset >= section->size
4546 hdrptr = section->start + line_offset;
4547 end = section->start + section->size;
4549 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4550 if (length == 0xffffffff)
4552 /* This section is 64-bit DWARF 3. */
4553 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4555 initial_length_size = 12;
4560 initial_length_size = 4;
4562 if (length + initial_length_size > section->size)
4565 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4566 if (version != 2 && version != 3 && version != 4)
4568 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4570 hdrptr++; /* Skip max_ops_per_insn. */
4571 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4573 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4574 if (opcode_base == 0)
4577 hdrptr += opcode_base - 1;
4579 /* Skip over dirname table. */
4580 while (*hdrptr != '\0')
4581 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4582 hdrptr++; /* Skip the NUL at the end of the table. */
4583 /* Now skip over preceding filename table entries. */
4584 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4586 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4587 read_uleb128 (hdrptr, &bytes_read, end);
4588 hdrptr += bytes_read;
4589 read_uleb128 (hdrptr, &bytes_read, end);
4590 hdrptr += bytes_read;
4591 read_uleb128 (hdrptr, &bytes_read, end);
4592 hdrptr += bytes_read;
4594 if (hdrptr == end || *hdrptr == '\0')
4597 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4598 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4601 for (; *dirtable != '\0' && diridx > 1; diridx--)
4602 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4603 if (*dirtable == '\0')
4605 *dir_name = dirtable;
4610 display_debug_macro (struct dwarf_section *section,
4613 unsigned char *start = section->start;
4614 unsigned char *end = start + section->size;
4615 unsigned char *curr = start;
4616 unsigned char *extended_op_buf[256];
4617 unsigned int bytes_read;
4619 load_debug_section (str, file);
4620 load_debug_section (line, file);
4622 printf (_("Contents of the %s section:\n\n"), section->name);
4626 unsigned int lineno, version, flags;
4627 unsigned int offset_size = 4;
4628 const unsigned char *string;
4629 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4630 unsigned char **extended_ops = NULL;
4632 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4633 if (version != 4 && version != 5)
4635 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4640 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4643 printf (_(" Offset: 0x%lx\n"),
4644 (unsigned long) sec_offset);
4645 printf (_(" Version: %d\n"), version);
4646 printf (_(" Offset size: %d\n"), offset_size);
4649 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4650 printf (_(" Offset into .debug_line: 0x%lx\n"),
4651 (unsigned long) line_offset);
4655 unsigned int i, count, op;
4658 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4660 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4661 extended_ops = extended_op_buf;
4664 printf (_(" Extension opcode arguments:\n"));
4665 for (i = 0; i < count; i++)
4667 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4668 extended_ops[op] = curr;
4669 nargs = read_uleb128 (curr, &bytes_read, end);
4672 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4675 printf (_(" DW_MACRO_%02x arguments: "), op);
4676 for (n = 0; n < nargs; n++)
4680 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4681 printf ("%s%s", get_FORM_name (form),
4682 n == nargs - 1 ? "\n" : ", ");
4692 case DW_FORM_block1:
4693 case DW_FORM_block2:
4694 case DW_FORM_block4:
4696 case DW_FORM_string:
4698 case DW_FORM_sec_offset:
4701 error (_("Invalid extension opcode form %s\n"),
4702 get_FORM_name (form));
4718 error (_(".debug_macro section not zero terminated\n"));
4722 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4728 case DW_MACRO_start_file:
4730 unsigned int filenum;
4731 unsigned char *file_name = NULL, *dir_name = NULL;
4733 lineno = read_uleb128 (curr, &bytes_read, end);
4735 filenum = read_uleb128 (curr, &bytes_read, end);
4738 if ((flags & 2) == 0)
4739 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4742 = get_line_filename_and_dirname (line_offset, filenum,
4744 if (file_name == NULL)
4745 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4748 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4750 dir_name != NULL ? (const char *) dir_name : "",
4751 dir_name != NULL ? "/" : "", file_name);
4755 case DW_MACRO_end_file:
4756 printf (_(" DW_MACRO_end_file\n"));
4759 case DW_MACRO_define:
4760 lineno = read_uleb128 (curr, &bytes_read, end);
4763 curr += strnlen ((char *) string, end - string) + 1;
4764 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4768 case DW_MACRO_undef:
4769 lineno = read_uleb128 (curr, &bytes_read, end);
4772 curr += strnlen ((char *) string, end - string) + 1;
4773 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4777 case DW_MACRO_define_strp:
4778 lineno = read_uleb128 (curr, &bytes_read, end);
4780 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4781 string = fetch_indirect_string (offset);
4782 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4786 case DW_MACRO_undef_strp:
4787 lineno = read_uleb128 (curr, &bytes_read, end);
4789 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4790 string = fetch_indirect_string (offset);
4791 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4795 case DW_MACRO_import:
4796 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4797 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4798 (unsigned long) offset);
4801 case DW_MACRO_define_sup:
4802 lineno = read_uleb128 (curr, &bytes_read, end);
4804 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4805 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4806 lineno, (unsigned long) offset);
4809 case DW_MACRO_undef_sup:
4810 lineno = read_uleb128 (curr, &bytes_read, end);
4812 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4813 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4814 lineno, (unsigned long) offset);
4817 case DW_MACRO_import_sup:
4818 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4819 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4820 (unsigned long) offset);
4824 if (extended_ops == NULL || extended_ops[op] == NULL)
4826 error (_(" Unknown macro opcode %02x seen\n"), op);
4831 /* Skip over unhandled opcodes. */
4833 unsigned char *desc = extended_ops[op];
4834 nargs = read_uleb128 (desc, &bytes_read, end);
4838 printf (_(" DW_MACRO_%02x\n"), op);
4841 printf (_(" DW_MACRO_%02x -"), op);
4842 for (n = 0; n < nargs; n++)
4846 /* DW_FORM_implicit_const is not expected here. */
4847 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4849 = read_and_display_attr_value (0, val, 0,
4850 curr, end, 0, 0, offset_size,
4851 version, NULL, 0, NULL,
4869 display_debug_abbrev (struct dwarf_section *section,
4870 void *file ATTRIBUTE_UNUSED)
4872 abbrev_entry *entry;
4873 unsigned char *start = section->start;
4874 unsigned char *end = start + section->size;
4876 printf (_("Contents of the %s section:\n\n"), section->name);
4880 unsigned char *last;
4885 start = process_abbrev_section (start, end);
4887 if (first_abbrev == NULL)
4890 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4892 for (entry = first_abbrev; entry; entry = entry->next)
4896 printf (" %ld %s [%s]\n",
4898 get_TAG_name (entry->tag),
4899 entry->children ? _("has children") : _("no children"));
4901 for (attr = entry->first_attr; attr; attr = attr->next)
4903 printf (" %-18s %s",
4904 get_AT_name (attr->attribute),
4905 get_FORM_name (attr->form));
4906 if (attr->form == DW_FORM_implicit_const)
4907 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
4919 /* Return true when ADDR is the maximum address, when addresses are
4920 POINTER_SIZE bytes long. */
4923 is_max_address (dwarf_vma addr, unsigned int pointer_size)
4925 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
4926 return ((addr & mask) == mask);
4929 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4932 display_loc_list (struct dwarf_section *section,
4933 unsigned char **start_ptr,
4934 unsigned int debug_info_entry,
4936 dwarf_vma base_address,
4939 unsigned char *start = *start_ptr;
4940 unsigned char *section_end = section->start + section->size;
4941 unsigned long cu_offset;
4942 unsigned int pointer_size;
4943 unsigned int offset_size;
4948 unsigned short length;
4949 int need_frame_base;
4951 if (debug_info_entry >= num_debug_info_entries)
4953 warn (_("No debug information available for loc lists of entry: %u\n"),
4958 cu_offset = debug_information [debug_info_entry].cu_offset;
4959 pointer_size = debug_information [debug_info_entry].pointer_size;
4960 offset_size = debug_information [debug_info_entry].offset_size;
4961 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4963 if (pointer_size < 2 || pointer_size > 8)
4965 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4966 pointer_size, debug_info_entry);
4972 dwarf_vma off = offset + (start - *start_ptr);
4974 if (start + 2 * pointer_size > section_end)
4976 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4977 (unsigned long) offset);
4981 printf (" %8.8lx ", (unsigned long) off);
4983 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4984 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4986 if (begin == 0 && end == 0)
4988 /* PR 18374: In a object file we can have a location list that
4989 starts with a begin and end of 0 because there are relocations
4990 that need to be applied to the addresses. Actually applying
4991 the relocations now does not help as they will probably resolve
4992 to 0, since the object file has not been fully linked. Real
4993 end of list markers will not have any relocations against them. */
4994 if (! reloc_at (section, off)
4995 && ! reloc_at (section, off + pointer_size))
4997 printf (_("<End of list>\n"));
5002 /* Check base address specifiers. */
5003 if (is_max_address (begin, pointer_size)
5004 && !is_max_address (end, pointer_size))
5007 print_dwarf_vma (begin, pointer_size);
5008 print_dwarf_vma (end, pointer_size);
5009 printf (_("(base address)\n"));
5013 if (start + 2 > section_end)
5015 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5016 (unsigned long) offset);
5020 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5022 if (start + length > section_end)
5024 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5025 (unsigned long) offset);
5029 print_dwarf_vma (begin + base_address, pointer_size);
5030 print_dwarf_vma (end + base_address, pointer_size);
5033 need_frame_base = decode_location_expression (start,
5038 cu_offset, section);
5041 if (need_frame_base && !has_frame_base)
5042 printf (_(" [without DW_AT_frame_base]"));
5045 fputs (_(" (start == end)"), stdout);
5046 else if (begin > end)
5047 fputs (_(" (start > end)"), stdout);
5057 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5060 display_loclists_list (struct dwarf_section *section,
5061 unsigned char **start_ptr,
5062 unsigned int debug_info_entry,
5064 dwarf_vma base_address,
5067 unsigned char *start = *start_ptr;
5068 unsigned char *section_end = section->start + section->size;
5069 unsigned long cu_offset;
5070 unsigned int pointer_size;
5071 unsigned int offset_size;
5073 unsigned int bytes_read;
5075 /* Initialize it due to a false compiler warning. */
5076 dwarf_vma begin = -1;
5079 int need_frame_base;
5081 if (debug_info_entry >= num_debug_info_entries)
5083 warn (_("No debug information available for "
5084 "loclists lists of entry: %u\n"),
5089 cu_offset = debug_information [debug_info_entry].cu_offset;
5090 pointer_size = debug_information [debug_info_entry].pointer_size;
5091 offset_size = debug_information [debug_info_entry].offset_size;
5092 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5094 if (pointer_size < 2 || pointer_size > 8)
5096 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5097 pointer_size, debug_info_entry);
5103 dwarf_vma off = offset + (start - *start_ptr);
5104 enum dwarf_location_list_entry_type llet;
5106 if (start + 1 > section_end)
5108 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5109 (unsigned long) offset);
5113 printf (" %8.8lx ", (unsigned long) off);
5115 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5119 case DW_LLE_end_of_list:
5120 printf (_("<End of list>\n"));
5122 case DW_LLE_offset_pair:
5123 begin = read_uleb128 (start, &bytes_read, section_end);
5124 start += bytes_read;
5125 end = read_uleb128 (start, &bytes_read, section_end);
5126 start += bytes_read;
5128 case DW_LLE_base_address:
5129 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5131 print_dwarf_vma (base_address, pointer_size);
5132 printf (_("(base address)\n"));
5135 error (_("Invalid location list entry type %d\n"), llet);
5138 if (llet == DW_LLE_end_of_list)
5140 if (llet != DW_LLE_offset_pair)
5143 if (start + 2 > section_end)
5145 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5146 (unsigned long) offset);
5150 length = read_uleb128 (start, &bytes_read, section_end);
5151 start += bytes_read;
5153 print_dwarf_vma (begin + base_address, pointer_size);
5154 print_dwarf_vma (end + base_address, pointer_size);
5157 need_frame_base = decode_location_expression (start,
5162 cu_offset, section);
5165 if (need_frame_base && !has_frame_base)
5166 printf (_(" [without DW_AT_frame_base]"));
5169 fputs (_(" (start == end)"), stdout);
5170 else if (begin > end)
5171 fputs (_(" (start > end)"), stdout);
5181 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5182 right-adjusted in a field of length LEN, and followed by a space. */
5185 print_addr_index (unsigned int idx, unsigned int len)
5187 static char buf[15];
5188 snprintf (buf, sizeof (buf), "[%d]", idx);
5189 printf ("%*s ", len, buf);
5192 /* Display a location list from a .dwo section. It uses address indexes rather
5193 than embedded addresses. This code closely follows display_loc_list, but the
5194 two are sufficiently different that combining things is very ugly. */
5197 display_loc_list_dwo (struct dwarf_section *section,
5198 unsigned char **start_ptr,
5199 unsigned int debug_info_entry,
5203 unsigned char *start = *start_ptr;
5204 unsigned char *section_end = section->start + section->size;
5205 unsigned long cu_offset;
5206 unsigned int pointer_size;
5207 unsigned int offset_size;
5210 unsigned short length;
5211 int need_frame_base;
5213 unsigned int bytes_read;
5215 if (debug_info_entry >= num_debug_info_entries)
5217 warn (_("No debug information for loc lists of entry: %u\n"),
5222 cu_offset = debug_information [debug_info_entry].cu_offset;
5223 pointer_size = debug_information [debug_info_entry].pointer_size;
5224 offset_size = debug_information [debug_info_entry].offset_size;
5225 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5227 if (pointer_size < 2 || pointer_size > 8)
5229 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5230 pointer_size, debug_info_entry);
5236 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5238 if (start >= section_end)
5240 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5241 (unsigned long) offset);
5245 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5248 case 0: /* A terminating entry. */
5250 printf (_("<End of list>\n"));
5252 case 1: /* A base-address entry. */
5253 idx = read_uleb128 (start, &bytes_read, section_end);
5254 start += bytes_read;
5255 print_addr_index (idx, 8);
5257 printf (_("(base address selection entry)\n"));
5259 case 2: /* A start/end entry. */
5260 idx = read_uleb128 (start, &bytes_read, section_end);
5261 start += bytes_read;
5262 print_addr_index (idx, 8);
5263 idx = read_uleb128 (start, &bytes_read, section_end);
5264 start += bytes_read;
5265 print_addr_index (idx, 8);
5267 case 3: /* A start/length entry. */
5268 idx = read_uleb128 (start, &bytes_read, section_end);
5269 start += bytes_read;
5270 print_addr_index (idx, 8);
5271 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5272 printf ("%08x ", idx);
5274 case 4: /* An offset pair entry. */
5275 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5276 printf ("%08x ", idx);
5277 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5278 printf ("%08x ", idx);
5281 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5286 if (start + 2 > section_end)
5288 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5289 (unsigned long) offset);
5293 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5294 if (start + length > section_end)
5296 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5297 (unsigned long) offset);
5302 need_frame_base = decode_location_expression (start,
5307 cu_offset, section);
5310 if (need_frame_base && !has_frame_base)
5311 printf (_(" [without DW_AT_frame_base]"));
5321 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5323 static dwarf_vma *loc_offsets;
5326 loc_offsets_compar (const void *ap, const void *bp)
5328 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5329 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5331 return (a > b) - (b > a);
5335 display_debug_loc (struct dwarf_section *section, void *file)
5337 unsigned char *start = section->start;
5338 unsigned long bytes;
5339 unsigned char *section_begin = start;
5340 unsigned int num_loc_list = 0;
5341 unsigned long last_offset = 0;
5342 unsigned int first = 0;
5345 int seen_first_offset = 0;
5346 int locs_sorted = 1;
5347 unsigned char *next;
5348 unsigned int *array = NULL;
5349 const char *suffix = strrchr (section->name, '.');
5351 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5352 dwarf_vma expected_start = 0;
5354 if (suffix && strcmp (suffix, ".dwo") == 0)
5357 bytes = section->size;
5361 printf (_("\nThe %s section is empty.\n"), section->name);
5367 unsigned char *hdrptr = section_begin;
5368 dwarf_vma ll_length;
5369 unsigned short ll_version;
5370 unsigned char *end = section_begin + section->size;
5371 unsigned char address_size, segment_selector_size;
5372 uint32_t offset_entry_count;
5374 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5375 if (ll_length == 0xffffffff)
5376 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5378 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5379 if (ll_version != 5)
5381 warn (_("The %s section contains corrupt or "
5382 "unsupported version number: %d.\n"),
5383 section->name, ll_version);
5387 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5389 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5390 if (segment_selector_size != 0)
5392 warn (_("The %s section contains "
5393 "unsupported segment selector size: %d.\n"),
5394 section->name, segment_selector_size);
5398 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5399 if (offset_entry_count != 0)
5401 warn (_("The %s section contains "
5402 "unsupported offset entry count: %d.\n"),
5403 section->name, offset_entry_count);
5407 expected_start = hdrptr - section_begin;
5410 if (load_debug_info (file) == 0)
5412 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5417 /* Check the order of location list in .debug_info section. If
5418 offsets of location lists are in the ascending order, we can
5419 use `debug_information' directly. */
5420 for (i = 0; i < num_debug_info_entries; i++)
5424 num = debug_information [i].num_loc_offsets;
5425 if (num > num_loc_list)
5428 /* Check if we can use `debug_information' directly. */
5429 if (locs_sorted && num != 0)
5431 if (!seen_first_offset)
5433 /* This is the first location list. */
5434 last_offset = debug_information [i].loc_offsets [0];
5436 seen_first_offset = 1;
5442 for (; j < num; j++)
5445 debug_information [i].loc_offsets [j])
5450 last_offset = debug_information [i].loc_offsets [j];
5455 if (!seen_first_offset)
5456 error (_("No location lists in .debug_info section!\n"));
5458 if (debug_information [first].num_loc_offsets > 0
5459 && debug_information [first].loc_offsets [0] != expected_start)
5460 warn (_("Location lists in %s section start at 0x%s\n"),
5462 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5465 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5466 printf (_("Contents of the %s section:\n\n"), section->name);
5467 if (reloc_at (section, 0))
5468 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5469 printf (_(" Offset Begin End Expression\n"));
5471 seen_first_offset = 0;
5472 for (i = first; i < num_debug_info_entries; i++)
5475 dwarf_vma base_address;
5481 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5483 loc_offsets = debug_information [i].loc_offsets;
5484 qsort (array, debug_information [i].num_loc_offsets,
5485 sizeof (*array), loc_offsets_compar);
5488 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5490 j = locs_sorted ? k : array[k];
5492 && debug_information [i].loc_offsets [locs_sorted
5493 ? k - 1 : array [k - 1]]
5494 == debug_information [i].loc_offsets [j])
5496 has_frame_base = debug_information [i].have_frame_base [j];
5497 offset = debug_information [i].loc_offsets [j];
5498 next = section_begin + offset;
5499 base_address = debug_information [i].base_address;
5501 if (!seen_first_offset)
5502 seen_first_offset = 1;
5506 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5507 (unsigned long) (start - section_begin),
5508 (unsigned long) offset);
5509 else if (start > next)
5510 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5511 (unsigned long) (start - section_begin),
5512 (unsigned long) offset);
5516 if (offset >= bytes)
5518 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5519 (unsigned long) offset);
5526 display_loc_list_dwo (section, &start, i, offset,
5529 display_loc_list (section, &start, i, offset, base_address,
5535 warn (_("DWO is not yet supported.\n"));
5537 display_loclists_list (section, &start, i, offset, base_address,
5543 if (start < section->start + section->size)
5544 warn (_("There are %ld unused bytes at the end of section %s\n"),
5545 (long) (section->start + section->size - start), section->name);
5552 display_debug_str (struct dwarf_section *section,
5553 void *file ATTRIBUTE_UNUSED)
5555 unsigned char *start = section->start;
5556 unsigned long bytes = section->size;
5557 dwarf_vma addr = section->address;
5561 printf (_("\nThe %s section is empty.\n"), section->name);
5565 printf (_("Contents of the %s section:\n\n"), section->name);
5573 lbytes = (bytes > 16 ? 16 : bytes);
5575 printf (" 0x%8.8lx ", (unsigned long) addr);
5577 for (j = 0; j < 16; j++)
5580 printf ("%2.2x", start[j]);
5588 for (j = 0; j < lbytes; j++)
5591 if (k >= ' ' && k < 0x80)
5610 display_debug_info (struct dwarf_section *section, void *file)
5612 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5616 display_debug_types (struct dwarf_section *section, void *file)
5618 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5622 display_trace_info (struct dwarf_section *section, void *file)
5624 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5628 display_debug_aranges (struct dwarf_section *section,
5629 void *file ATTRIBUTE_UNUSED)
5631 unsigned char *start = section->start;
5632 unsigned char *end = start + section->size;
5634 printf (_("Contents of the %s section:\n\n"), section->name);
5636 /* It does not matter if this load fails,
5637 we test for that later on. */
5638 load_debug_info (file);
5642 unsigned char *hdrptr;
5643 DWARF2_Internal_ARange arange;
5644 unsigned char *addr_ranges;
5647 unsigned char address_size;
5649 unsigned int offset_size;
5650 unsigned int initial_length_size;
5654 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
5655 if (arange.ar_length == 0xffffffff)
5657 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
5659 initial_length_size = 12;
5664 initial_length_size = 4;
5667 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
5668 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
5670 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5671 && num_debug_info_entries > 0
5672 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
5673 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5674 (unsigned long) arange.ar_info_offset, section->name);
5676 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
5677 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
5679 if (arange.ar_version != 2 && arange.ar_version != 3)
5681 /* PR 19872: A version number of 0 probably means that there is
5682 padding at the end of the .debug_aranges section. Gold puts
5683 it there when performing an incremental link, for example.
5684 So do not generate a warning in this case. */
5685 if (arange.ar_version)
5686 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5690 printf (_(" Length: %ld\n"),
5691 (long) arange.ar_length);
5692 printf (_(" Version: %d\n"), arange.ar_version);
5693 printf (_(" Offset into .debug_info: 0x%lx\n"),
5694 (unsigned long) arange.ar_info_offset);
5695 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5696 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5698 address_size = arange.ar_pointer_size + arange.ar_segment_size;
5700 /* PR 17512: file: 001-108546-0.001:0.1. */
5701 if (address_size == 0 || address_size > 8)
5703 error (_("Invalid address size in %s section!\n"),
5708 /* The DWARF spec does not require that the address size be a power
5709 of two, but we do. This will have to change if we ever encounter
5710 an uneven architecture. */
5711 if ((address_size & (address_size - 1)) != 0)
5713 warn (_("Pointer size + Segment size is not a power of two.\n"));
5717 if (address_size > 4)
5718 printf (_("\n Address Length\n"));
5720 printf (_("\n Address Length\n"));
5722 addr_ranges = hdrptr;
5724 /* Must pad to an alignment boundary that is twice the address size. */
5725 excess = (hdrptr - start) % (2 * address_size);
5727 addr_ranges += (2 * address_size) - excess;
5729 hdrptr = start + arange.ar_length + initial_length_size;
5730 if (hdrptr < start || hdrptr > end)
5732 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5737 while (addr_ranges + 2 * address_size <= start)
5739 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5740 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5743 print_dwarf_vma (address, address_size);
5744 print_dwarf_vma (length, address_size);
5754 /* Comparison function for qsort. */
5756 comp_addr_base (const void * v0, const void * v1)
5758 debug_info * info0 = (debug_info *) v0;
5759 debug_info * info1 = (debug_info *) v1;
5760 return info0->addr_base - info1->addr_base;
5763 /* Display the debug_addr section. */
5765 display_debug_addr (struct dwarf_section *section,
5768 debug_info **debug_addr_info;
5769 unsigned char *entry;
5774 if (section->size == 0)
5776 printf (_("\nThe %s section is empty.\n"), section->name);
5780 if (load_debug_info (file) == 0)
5782 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5787 printf (_("Contents of the %s section:\n\n"), section->name);
5789 /* PR 17531: file: cf38d01b.
5790 We use xcalloc because a corrupt file may not have initialised all of the
5791 fields in the debug_info structure, which means that the sort below might
5792 try to move uninitialised data. */
5793 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5794 sizeof (debug_info *));
5797 for (i = 0; i < num_debug_info_entries; i++)
5798 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5800 /* PR 17531: file: cf38d01b. */
5801 if (debug_information[i].addr_base >= section->size)
5802 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5803 (unsigned long) debug_information[i].addr_base, i);
5805 debug_addr_info [count++] = debug_information + i;
5808 /* Add a sentinel to make iteration convenient. */
5809 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5810 debug_addr_info [count]->addr_base = section->size;
5811 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5813 for (i = 0; i < count; i++)
5816 unsigned int address_size = debug_addr_info [i]->pointer_size;
5818 printf (_(" For compilation unit at offset 0x%s:\n"),
5819 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5821 printf (_("\tIndex\tAddress\n"));
5822 entry = section->start + debug_addr_info [i]->addr_base;
5823 end = section->start + debug_addr_info [i + 1]->addr_base;
5827 dwarf_vma base = byte_get (entry, address_size);
5828 printf (_("\t%d:\t"), idx);
5829 print_dwarf_vma (base, address_size);
5831 entry += address_size;
5837 free (debug_addr_info);
5841 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5843 display_debug_str_offsets (struct dwarf_section *section,
5844 void *file ATTRIBUTE_UNUSED)
5846 if (section->size == 0)
5848 printf (_("\nThe %s section is empty.\n"), section->name);
5851 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5852 what the offset size is for this section. */
5856 /* Each debug_information[x].range_lists[y] gets this representation for
5857 sorting purposes. */
5861 /* The debug_information[x].range_lists[y] value. */
5862 dwarf_vma ranges_offset;
5864 /* Original debug_information to find parameters of the data. */
5865 debug_info *debug_info_p;
5868 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5871 range_entry_compar (const void *ap, const void *bp)
5873 const struct range_entry *a_re = (const struct range_entry *) ap;
5874 const struct range_entry *b_re = (const struct range_entry *) bp;
5875 const dwarf_vma a = a_re->ranges_offset;
5876 const dwarf_vma b = b_re->ranges_offset;
5878 return (a > b) - (b > a);
5882 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
5883 unsigned int pointer_size, unsigned long offset,
5884 unsigned long base_address)
5886 while (start < finish)
5891 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5892 if (start >= finish)
5894 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5896 printf (" %8.8lx ", offset);
5898 if (begin == 0 && end == 0)
5900 printf (_("<End of list>\n"));
5904 /* Check base address specifiers. */
5905 if (is_max_address (begin, pointer_size)
5906 && !is_max_address (end, pointer_size))
5909 print_dwarf_vma (begin, pointer_size);
5910 print_dwarf_vma (end, pointer_size);
5911 printf ("(base address)\n");
5915 print_dwarf_vma (begin + base_address, pointer_size);
5916 print_dwarf_vma (end + base_address, pointer_size);
5919 fputs (_("(start == end)"), stdout);
5920 else if (begin > end)
5921 fputs (_("(start > end)"), stdout);
5928 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
5929 unsigned int pointer_size, unsigned long offset,
5930 unsigned long base_address)
5932 unsigned char *next = start;
5936 unsigned long off = offset + (start - next);
5937 enum dwarf_range_list_entry rlet;
5938 /* Initialize it due to a false compiler warning. */
5939 dwarf_vma begin = -1, length, end = -1;
5940 unsigned int bytes_read;
5942 if (start + 1 > finish)
5944 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
5949 printf (" %8.8lx ", off);
5951 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
5955 case DW_RLE_end_of_list:
5956 printf (_("<End of list>\n"));
5958 case DW_RLE_base_address:
5959 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
5960 print_dwarf_vma (base_address, pointer_size);
5961 printf (_("(base address)\n"));
5963 case DW_RLE_start_length:
5964 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5965 length = read_uleb128 (start, &bytes_read, finish);
5966 start += bytes_read;
5967 end = begin + length;
5969 case DW_RLE_offset_pair:
5970 begin = read_uleb128 (start, &bytes_read, finish);
5971 start += bytes_read;
5972 end = read_uleb128 (start, &bytes_read, finish);
5973 start += bytes_read;
5975 case DW_RLE_start_end:
5976 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5977 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5980 error (_("Invalid range list entry type %d\n"), rlet);
5981 rlet = DW_RLE_end_of_list;
5984 if (rlet == DW_RLE_end_of_list)
5986 if (rlet == DW_RLE_base_address)
5989 print_dwarf_vma (begin + base_address, pointer_size);
5990 print_dwarf_vma (end + base_address, pointer_size);
5993 fputs (_("(start == end)"), stdout);
5994 else if (begin > end)
5995 fputs (_("(start > end)"), stdout);
6002 display_debug_ranges (struct dwarf_section *section,
6003 void *file ATTRIBUTE_UNUSED)
6005 unsigned char *start = section->start;
6006 unsigned char *last_start = start;
6007 unsigned long bytes = section->size;
6008 unsigned char *section_begin = start;
6009 unsigned char *finish = start + bytes;
6010 unsigned int num_range_list, i;
6011 struct range_entry *range_entries, *range_entry_fill;
6012 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6013 /* Initialize it due to a false compiler warning. */
6014 unsigned char address_size = 0;
6018 printf (_("\nThe %s section is empty.\n"), section->name);
6024 dwarf_vma initial_length;
6025 unsigned int initial_length_size;
6026 unsigned char segment_selector_size;
6027 unsigned int offset_size, offset_entry_count;
6028 unsigned short version;
6030 /* Get and check the length of the block. */
6031 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6033 if (initial_length == 0xffffffff)
6035 /* This section is 64-bit DWARF 3. */
6036 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6038 initial_length_size = 12;
6043 initial_length_size = 4;
6046 if (initial_length + initial_length_size > section->size)
6048 /* If the length field has a relocation against it, then we should
6049 not complain if it is inaccurate (and probably negative).
6050 It is copied from .debug_line handling code. */
6051 if (reloc_at (section, (start - section->start) - offset_size))
6053 initial_length = (finish - start) - initial_length_size;
6057 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6058 (long) initial_length);
6063 /* Get and check the version number. */
6064 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6068 warn (_("Only DWARF version 5 debug_rnglists info "
6069 "is currently supported.\n"));
6073 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6075 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6076 if (segment_selector_size != 0)
6078 warn (_("The %s section contains "
6079 "unsupported segment selector size: %d.\n"),
6080 section->name, segment_selector_size);
6084 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6085 if (offset_entry_count != 0)
6087 warn (_("The %s section contains "
6088 "unsupported offset entry count: %u.\n"),
6089 section->name, offset_entry_count);
6094 if (load_debug_info (file) == 0)
6096 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6102 for (i = 0; i < num_debug_info_entries; i++)
6103 num_range_list += debug_information [i].num_range_lists;
6105 if (num_range_list == 0)
6107 /* This can happen when the file was compiled with -gsplit-debug
6108 which removes references to range lists from the primary .o file. */
6109 printf (_("No range lists in .debug_info section.\n"));
6113 range_entries = (struct range_entry *)
6114 xmalloc (sizeof (*range_entries) * num_range_list);
6115 range_entry_fill = range_entries;
6117 for (i = 0; i < num_debug_info_entries; i++)
6119 debug_info *debug_info_p = &debug_information[i];
6122 for (j = 0; j < debug_info_p->num_range_lists; j++)
6124 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6125 range_entry_fill->debug_info_p = debug_info_p;
6130 qsort (range_entries, num_range_list, sizeof (*range_entries),
6131 range_entry_compar);
6133 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6134 warn (_("Range lists in %s section start at 0x%lx\n"),
6135 section->name, (unsigned long) range_entries[0].ranges_offset);
6137 printf (_("Contents of the %s section:\n\n"), section->name);
6138 printf (_(" Offset Begin End\n"));
6140 for (i = 0; i < num_range_list; i++)
6142 struct range_entry *range_entry = &range_entries[i];
6143 debug_info *debug_info_p = range_entry->debug_info_p;
6144 unsigned int pointer_size;
6146 unsigned char *next;
6147 dwarf_vma base_address;
6149 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6150 offset = range_entry->ranges_offset;
6151 next = section_begin + offset;
6152 base_address = debug_info_p->base_address;
6154 /* PR 17512: file: 001-101485-0.001:0.1. */
6155 if (pointer_size < 2 || pointer_size > 8)
6157 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6158 pointer_size, (unsigned long) offset);
6162 if (dwarf_check != 0 && i > 0)
6165 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6166 (unsigned long) (start - section_begin),
6167 (unsigned long) (next - section_begin), section->name);
6168 else if (start > next)
6170 if (next == last_start)
6172 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6173 (unsigned long) (start - section_begin),
6174 (unsigned long) (next - section_begin), section->name);
6180 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6181 (start, finish, pointer_size, offset, base_address);
6185 free (range_entries);
6190 typedef struct Frame_Chunk
6192 struct Frame_Chunk *next;
6193 unsigned char *chunk_start;
6195 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6196 short int *col_type;
6199 unsigned int code_factor;
6204 dwarf_vma cfa_offset;
6206 unsigned char fde_encoding;
6207 unsigned char cfa_exp;
6208 unsigned char ptr_size;
6209 unsigned char segment_size;
6213 static const char *const *dwarf_regnames;
6214 static unsigned int dwarf_regnames_count;
6216 /* A marker for a col_type that means this column was never referenced
6217 in the frame info. */
6218 #define DW_CFA_unreferenced (-1)
6220 /* Return 0 if no more space is needed, 1 if more space is needed,
6221 -1 for invalid reg. */
6224 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6226 unsigned int prev = fc->ncols;
6228 if (reg < (unsigned int) fc->ncols)
6231 if (dwarf_regnames_count
6232 && reg > dwarf_regnames_count)
6235 fc->ncols = reg + 1;
6236 /* PR 17512: file: 10450-2643-0.004.
6237 If reg == -1 then this can happen... */
6241 /* PR 17512: file: 2844a11d. */
6242 if (fc->ncols > 1024)
6244 error (_("Unfeasibly large register number: %u\n"), reg);
6246 /* FIXME: 1024 is an arbitrary limit. Increase it if
6247 we ever encounter a valid binary that exceeds it. */
6251 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6252 sizeof (short int));
6253 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6254 /* PR 17512: file:002-10025-0.005. */
6255 if (fc->col_type == NULL || fc->col_offset == NULL)
6257 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6263 while (prev < fc->ncols)
6265 fc->col_type[prev] = DW_CFA_unreferenced;
6266 fc->col_offset[prev] = 0;
6272 static const char *const dwarf_regnames_i386[] =
6274 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6275 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6276 "eip", "eflags", NULL, /* 8 - 10 */
6277 "st0", "st1", "st2", "st3", /* 11 - 14 */
6278 "st4", "st5", "st6", "st7", /* 15 - 18 */
6279 NULL, NULL, /* 19 - 20 */
6280 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6281 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6282 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6283 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6284 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6285 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6286 "tr", "ldtr", /* 48 - 49 */
6287 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6288 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6289 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6290 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6291 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6292 NULL, NULL, NULL, /* 90 - 92 */
6293 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6296 static const char *const dwarf_regnames_iamcu[] =
6298 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6299 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6300 "eip", "eflags", NULL, /* 8 - 10 */
6301 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6302 NULL, NULL, /* 19 - 20 */
6303 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6304 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6305 NULL, NULL, NULL, /* 37 - 39 */
6306 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6307 "tr", "ldtr", /* 48 - 49 */
6308 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6309 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6310 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6311 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6312 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6313 NULL, NULL, NULL, /* 90 - 92 */
6314 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6318 init_dwarf_regnames_i386 (void)
6320 dwarf_regnames = dwarf_regnames_i386;
6321 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6325 init_dwarf_regnames_iamcu (void)
6327 dwarf_regnames = dwarf_regnames_iamcu;
6328 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6331 static const char *const dwarf_regnames_x86_64[] =
6333 "rax", "rdx", "rcx", "rbx",
6334 "rsi", "rdi", "rbp", "rsp",
6335 "r8", "r9", "r10", "r11",
6336 "r12", "r13", "r14", "r15",
6338 "xmm0", "xmm1", "xmm2", "xmm3",
6339 "xmm4", "xmm5", "xmm6", "xmm7",
6340 "xmm8", "xmm9", "xmm10", "xmm11",
6341 "xmm12", "xmm13", "xmm14", "xmm15",
6342 "st0", "st1", "st2", "st3",
6343 "st4", "st5", "st6", "st7",
6344 "mm0", "mm1", "mm2", "mm3",
6345 "mm4", "mm5", "mm6", "mm7",
6347 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6348 "fs.base", "gs.base", NULL, NULL,
6350 "mxcsr", "fcw", "fsw",
6351 "xmm16", "xmm17", "xmm18", "xmm19",
6352 "xmm20", "xmm21", "xmm22", "xmm23",
6353 "xmm24", "xmm25", "xmm26", "xmm27",
6354 "xmm28", "xmm29", "xmm30", "xmm31",
6355 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6356 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6357 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6358 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6359 NULL, NULL, NULL, /* 115 - 117 */
6360 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6364 init_dwarf_regnames_x86_64 (void)
6366 dwarf_regnames = dwarf_regnames_x86_64;
6367 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6370 static const char *const dwarf_regnames_aarch64[] =
6372 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6373 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6374 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6375 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6376 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6377 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6378 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6379 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6380 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6381 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6382 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6383 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6387 init_dwarf_regnames_aarch64 (void)
6389 dwarf_regnames = dwarf_regnames_aarch64;
6390 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6393 static const char *const dwarf_regnames_s390[] =
6395 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6396 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6397 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6398 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6399 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6400 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6401 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6402 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6403 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6406 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6407 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6411 init_dwarf_regnames_s390 (void)
6413 dwarf_regnames = dwarf_regnames_s390;
6414 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6418 init_dwarf_regnames (unsigned int e_machine)
6423 init_dwarf_regnames_i386 ();
6427 init_dwarf_regnames_iamcu ();
6433 init_dwarf_regnames_x86_64 ();
6437 init_dwarf_regnames_aarch64 ();
6441 init_dwarf_regnames_s390 ();
6450 regname (unsigned int regno, int row)
6452 static char reg[64];
6455 && regno < dwarf_regnames_count
6456 && dwarf_regnames [regno] != NULL)
6459 return dwarf_regnames [regno];
6460 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6461 dwarf_regnames [regno]);
6464 snprintf (reg, sizeof (reg), "r%d", regno);
6469 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6474 if (*max_regs != fc->ncols)
6475 *max_regs = fc->ncols;
6477 if (*need_col_headers)
6479 static const char *sloc = " LOC";
6481 *need_col_headers = 0;
6483 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6485 for (r = 0; r < *max_regs; r++)
6486 if (fc->col_type[r] != DW_CFA_unreferenced)
6491 printf ("%-5s ", regname (r, 1));
6497 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6499 strcpy (tmp, "exp");
6501 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6502 printf ("%-8s ", tmp);
6504 for (r = 0; r < fc->ncols; r++)
6506 if (fc->col_type[r] != DW_CFA_unreferenced)
6508 switch (fc->col_type[r])
6510 case DW_CFA_undefined:
6513 case DW_CFA_same_value:
6517 sprintf (tmp, "c%+d", fc->col_offset[r]);
6519 case DW_CFA_val_offset:
6520 sprintf (tmp, "v%+d", fc->col_offset[r]);
6522 case DW_CFA_register:
6523 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6525 case DW_CFA_expression:
6526 strcpy (tmp, "exp");
6528 case DW_CFA_val_expression:
6529 strcpy (tmp, "vexp");
6532 strcpy (tmp, "n/a");
6535 printf ("%-5s ", tmp);
6541 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6543 static unsigned char *
6544 read_cie (unsigned char *start, unsigned char *end,
6545 Frame_Chunk **p_cie, int *p_version,
6546 unsigned long *p_aug_len, unsigned char **p_aug)
6550 unsigned int length_return;
6551 unsigned char *augmentation_data = NULL;
6552 unsigned long augmentation_data_len = 0;
6555 /* PR 17512: file: 001-228113-0.004. */
6559 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6560 memset (fc, 0, sizeof (Frame_Chunk));
6562 fc->col_type = (short int *) xmalloc (sizeof (short int));
6563 fc->col_offset = (int *) xmalloc (sizeof (int));
6567 fc->augmentation = (char *) start;
6568 /* PR 17512: file: 001-228113-0.004.
6569 Skip past augmentation name, but avoid running off the end of the data. */
6571 if (* start ++ == '\0')
6575 warn (_("No terminator for augmentation name\n"));
6579 if (strcmp (fc->augmentation, "eh") == 0)
6580 start += eh_addr_size;
6584 GET (fc->ptr_size, 1);
6585 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6587 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6591 GET (fc->segment_size, 1);
6592 /* PR 17512: file: e99d2804. */
6593 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6595 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6599 eh_addr_size = fc->ptr_size;
6603 fc->ptr_size = eh_addr_size;
6604 fc->segment_size = 0;
6606 READ_ULEB (fc->code_factor);
6607 READ_SLEB (fc->data_factor);
6617 if (fc->augmentation[0] == 'z')
6619 READ_ULEB (augmentation_data_len);
6620 augmentation_data = start;
6621 start += augmentation_data_len;
6622 /* PR 17512: file: 11042-2589-0.004. */
6625 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
6626 augmentation_data_len, (long)((end - start) + augmentation_data_len));
6631 if (augmentation_data_len)
6635 unsigned char *qend;
6637 p = (unsigned char *) fc->augmentation + 1;
6638 q = augmentation_data;
6639 qend = q + augmentation_data_len;
6641 /* PR 17531: file: 015adfaa. */
6644 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
6645 augmentation_data_len = 0;
6648 while (p < end && q < augmentation_data + augmentation_data_len)
6653 q += 1 + size_of_encoded_value (*q);
6655 fc->fde_encoding = *q++;
6662 /* Note - it is OK if this loop terminates with q < qend.
6663 Padding may have been inserted to align the end of the CIE. */
6668 *p_version = version;
6671 *p_aug_len = augmentation_data_len;
6672 *p_aug = augmentation_data;
6678 display_debug_frames (struct dwarf_section *section,
6679 void *file ATTRIBUTE_UNUSED)
6681 unsigned char *start = section->start;
6682 unsigned char *end = start + section->size;
6683 unsigned char *section_start = start;
6684 Frame_Chunk *chunks = 0, *forward_refs = 0;
6685 Frame_Chunk *remembered_state = 0;
6687 int is_eh = strcmp (section->name, ".eh_frame") == 0;
6688 unsigned int length_return;
6689 unsigned int max_regs = 0;
6690 const char *bad_reg = _("bad register: ");
6691 unsigned int saved_eh_addr_size = eh_addr_size;
6693 printf (_("Contents of the %s section:\n"), section->name);
6697 unsigned char *saved_start;
6698 unsigned char *block_end;
6703 int need_col_headers = 1;
6704 unsigned char *augmentation_data = NULL;
6705 unsigned long augmentation_data_len = 0;
6706 unsigned int encoded_ptr_size = saved_eh_addr_size;
6707 unsigned int offset_size;
6708 unsigned int initial_length_size;
6709 bfd_boolean all_nops;
6711 saved_start = start;
6713 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
6717 printf ("\n%08lx ZERO terminator\n\n",
6718 (unsigned long)(saved_start - section_start));
6719 /* Skip any zero terminators that directly follow.
6720 A corrupt section size could have loaded a whole
6721 slew of zero filled memory bytes. eg
6722 PR 17512: file: 070-19381-0.004. */
6723 while (start < end && * start == 0)
6728 if (length == 0xffffffff)
6730 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
6732 initial_length_size = 12;
6737 initial_length_size = 4;
6740 block_end = saved_start + length + initial_length_size;
6741 if (block_end > end || block_end < start)
6743 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6744 dwarf_vmatoa_1 (NULL, length, offset_size),
6745 (unsigned long) (saved_start - section_start));
6749 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
6751 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
6752 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
6757 start = read_cie (start, end, &cie, &version,
6758 &augmentation_data_len, &augmentation_data);
6759 /* PR 17512: file: 027-135133-0.005. */
6766 fc->chunk_start = saved_start;
6767 mreg = max_regs > 0 ? max_regs - 1 : 0;
6770 if (frame_need_space (fc, mreg) < 0)
6772 if (fc->fde_encoding)
6773 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6775 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
6776 print_dwarf_vma (length, fc->ptr_size);
6777 print_dwarf_vma (cie_id, offset_size);
6779 if (do_debug_frames_interp)
6781 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
6782 fc->code_factor, fc->data_factor, fc->ra);
6787 printf (" Version: %d\n", version);
6788 printf (" Augmentation: \"%s\"\n", fc->augmentation);
6791 printf (" Pointer Size: %u\n", fc->ptr_size);
6792 printf (" Segment Size: %u\n", fc->segment_size);
6794 printf (" Code alignment factor: %u\n", fc->code_factor);
6795 printf (" Data alignment factor: %d\n", fc->data_factor);
6796 printf (" Return address column: %d\n", fc->ra);
6798 if (augmentation_data_len)
6802 printf (" Augmentation data: ");
6803 for (i = 0; i < augmentation_data_len; ++i)
6804 /* FIXME: If do_wide is FALSE, then we should
6805 add carriage returns at 80 columns... */
6806 printf (" %02x", augmentation_data[i]);
6814 unsigned char *look_for;
6815 static Frame_Chunk fde_fc;
6816 unsigned long segment_selector;
6820 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
6821 look_for = start - 4 - ((cie_id ^ sign) - sign);
6824 look_for = section_start + cie_id;
6826 if (look_for <= saved_start)
6828 for (cie = chunks; cie ; cie = cie->next)
6829 if (cie->chunk_start == look_for)
6834 for (cie = forward_refs; cie ; cie = cie->next)
6835 if (cie->chunk_start == look_for)
6839 unsigned int off_size;
6840 unsigned char *cie_scan;
6842 cie_scan = look_for;
6844 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
6845 if (length == 0xffffffff)
6847 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
6854 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
6857 : ((off_size == 4 && c_id == DW_CIE_ID)
6858 || (off_size == 8 && c_id == DW64_CIE_ID)))
6863 read_cie (cie_scan, end, &cie, &version,
6864 &augmentation_data_len, &augmentation_data);
6865 /* PR 17512: file: 3450-2098-0.004. */
6868 warn (_("Failed to read CIE information\n"));
6871 cie->next = forward_refs;
6873 cie->chunk_start = look_for;
6874 mreg = max_regs > 0 ? max_regs - 1 : 0;
6877 if (frame_need_space (cie, mreg) < 0)
6879 warn (_("Invalid max register\n"));
6882 if (cie->fde_encoding)
6884 = size_of_encoded_value (cie->fde_encoding);
6891 memset (fc, 0, sizeof (Frame_Chunk));
6895 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6896 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6897 (unsigned long) (saved_start - section_start));
6899 fc->col_type = (short int *) xmalloc (sizeof (short int));
6900 fc->col_offset = (int *) xmalloc (sizeof (int));
6901 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
6903 warn (_("Invalid max register\n"));
6907 fc->augmentation = "";
6908 fc->fde_encoding = 0;
6909 fc->ptr_size = eh_addr_size;
6910 fc->segment_size = 0;
6914 fc->ncols = cie->ncols;
6915 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
6916 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
6917 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6918 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6919 fc->augmentation = cie->augmentation;
6920 fc->ptr_size = cie->ptr_size;
6921 eh_addr_size = cie->ptr_size;
6922 fc->segment_size = cie->segment_size;
6923 fc->code_factor = cie->code_factor;
6924 fc->data_factor = cie->data_factor;
6925 fc->cfa_reg = cie->cfa_reg;
6926 fc->cfa_offset = cie->cfa_offset;
6928 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
6930 warn (_("Invalid max register\n"));
6933 fc->fde_encoding = cie->fde_encoding;
6936 if (fc->fde_encoding)
6937 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6939 segment_selector = 0;
6940 if (fc->segment_size)
6942 if (fc->segment_size > sizeof (segment_selector))
6944 /* PR 17512: file: 9e196b3e. */
6945 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
6946 fc->segment_size = 4;
6948 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
6951 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
6953 /* FIXME: It appears that sometimes the final pc_range value is
6954 encoded in less than encoded_ptr_size bytes. See the x86_64
6955 run of the "objcopy on compressed debug sections" test for an
6957 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
6959 if (cie->augmentation[0] == 'z')
6961 READ_ULEB (augmentation_data_len);
6962 augmentation_data = start;
6963 start += augmentation_data_len;
6964 /* PR 17512: file: 722-8446-0.004. */
6965 if (start >= end || ((signed long) augmentation_data_len) < 0)
6967 warn (_("Corrupt augmentation data length: %lx\n"),
6968 augmentation_data_len);
6970 augmentation_data = NULL;
6971 augmentation_data_len = 0;
6975 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6976 (unsigned long)(saved_start - section_start),
6977 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
6978 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6979 (unsigned long)(cie->chunk_start - section_start));
6981 if (fc->segment_size)
6982 printf ("%04lx:", segment_selector);
6985 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
6986 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
6988 if (! do_debug_frames_interp && augmentation_data_len)
6992 printf (" Augmentation data: ");
6993 for (i = 0; i < augmentation_data_len; ++i)
6994 printf (" %02x", augmentation_data[i]);
7000 /* At this point, fc is the current chunk, cie (if any) is set, and
7001 we're about to interpret instructions for the chunk. */
7002 /* ??? At present we need to do this always, since this sizes the
7003 fc->col_type and fc->col_offset arrays, which we write into always.
7004 We should probably split the interpreted and non-interpreted bits
7005 into two different routines, since there's so much that doesn't
7006 really overlap between them. */
7007 if (1 || do_debug_frames_interp)
7009 /* Start by making a pass over the chunk, allocating storage
7010 and taking note of what registers are used. */
7011 unsigned char *tmp = start;
7013 while (start < block_end)
7015 unsigned int reg, op, opa;
7017 unsigned char * new_start;
7024 /* Warning: if you add any more cases to this switch, be
7025 sure to add them to the corresponding switch below. */
7028 case DW_CFA_advance_loc:
7032 if (frame_need_space (fc, opa) >= 0)
7033 fc->col_type[opa] = DW_CFA_undefined;
7035 case DW_CFA_restore:
7036 if (frame_need_space (fc, opa) >= 0)
7037 fc->col_type[opa] = DW_CFA_undefined;
7039 case DW_CFA_set_loc:
7040 start += encoded_ptr_size;
7042 case DW_CFA_advance_loc1:
7045 case DW_CFA_advance_loc2:
7048 case DW_CFA_advance_loc4:
7051 case DW_CFA_offset_extended:
7052 case DW_CFA_val_offset:
7055 if (frame_need_space (fc, reg) >= 0)
7056 fc->col_type[reg] = DW_CFA_undefined;
7058 case DW_CFA_restore_extended:
7060 if (frame_need_space (fc, reg) >= 0)
7061 fc->col_type[reg] = DW_CFA_undefined;
7063 case DW_CFA_undefined:
7065 if (frame_need_space (fc, reg) >= 0)
7066 fc->col_type[reg] = DW_CFA_undefined;
7068 case DW_CFA_same_value:
7070 if (frame_need_space (fc, reg) >= 0)
7071 fc->col_type[reg] = DW_CFA_undefined;
7073 case DW_CFA_register:
7076 if (frame_need_space (fc, reg) >= 0)
7077 fc->col_type[reg] = DW_CFA_undefined;
7079 case DW_CFA_def_cfa:
7083 case DW_CFA_def_cfa_register:
7086 case DW_CFA_def_cfa_offset:
7089 case DW_CFA_def_cfa_expression:
7091 new_start = start + temp;
7092 if (new_start < start)
7094 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7100 case DW_CFA_expression:
7101 case DW_CFA_val_expression:
7104 new_start = start + temp;
7105 if (new_start < start)
7107 /* PR 17512: file:306-192417-0.005. */
7108 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7113 if (frame_need_space (fc, reg) >= 0)
7114 fc->col_type[reg] = DW_CFA_undefined;
7116 case DW_CFA_offset_extended_sf:
7117 case DW_CFA_val_offset_sf:
7120 if (frame_need_space (fc, reg) >= 0)
7121 fc->col_type[reg] = DW_CFA_undefined;
7123 case DW_CFA_def_cfa_sf:
7127 case DW_CFA_def_cfa_offset_sf:
7130 case DW_CFA_MIPS_advance_loc8:
7133 case DW_CFA_GNU_args_size:
7136 case DW_CFA_GNU_negative_offset_extended:
7139 if (frame_need_space (fc, reg) >= 0)
7140 fc->col_type[reg] = DW_CFA_undefined;
7151 /* Now we know what registers are used, make a second pass over
7152 the chunk, this time actually printing out the info. */
7154 while (start < block_end)
7156 unsigned char * tmp;
7158 unsigned long ul, roffs;
7159 /* Note: It is tempting to use an unsigned long for 'reg' but there
7160 are various functions, notably frame_space_needed() that assume that
7161 reg is an unsigned int. */
7166 const char *reg_prefix = "";
7173 /* Make a note if something other than DW_CFA_nop happens. */
7174 if (op != DW_CFA_nop)
7177 /* Warning: if you add any more cases to this switch, be
7178 sure to add them to the corresponding switch above. */
7181 case DW_CFA_advance_loc:
7182 if (do_debug_frames_interp)
7183 frame_display_row (fc, &need_col_headers, &max_regs);
7185 printf (" DW_CFA_advance_loc: %d to %s\n",
7186 opa * fc->code_factor,
7187 dwarf_vmatoa_1 (NULL,
7188 fc->pc_begin + opa * fc->code_factor,
7190 fc->pc_begin += opa * fc->code_factor;
7195 if (opa >= (unsigned int) fc->ncols)
7196 reg_prefix = bad_reg;
7197 if (! do_debug_frames_interp || *reg_prefix != '\0')
7198 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7199 reg_prefix, regname (opa, 0),
7200 roffs * fc->data_factor);
7201 if (*reg_prefix == '\0')
7203 fc->col_type[opa] = DW_CFA_offset;
7204 fc->col_offset[opa] = roffs * fc->data_factor;
7208 case DW_CFA_restore:
7209 if (opa >= (unsigned int) fc->ncols)
7210 reg_prefix = bad_reg;
7211 if (! do_debug_frames_interp || *reg_prefix != '\0')
7212 printf (" DW_CFA_restore: %s%s\n",
7213 reg_prefix, regname (opa, 0));
7214 if (*reg_prefix != '\0')
7217 if (opa >= (unsigned int) cie->ncols
7218 || (do_debug_frames_interp
7219 && cie->col_type[opa] == DW_CFA_unreferenced))
7221 fc->col_type[opa] = DW_CFA_undefined;
7222 fc->col_offset[opa] = 0;
7226 fc->col_type[opa] = cie->col_type[opa];
7227 fc->col_offset[opa] = cie->col_offset[opa];
7231 case DW_CFA_set_loc:
7232 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7233 if (do_debug_frames_interp)
7234 frame_display_row (fc, &need_col_headers, &max_regs);
7236 printf (" DW_CFA_set_loc: %s\n",
7237 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7241 case DW_CFA_advance_loc1:
7242 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7243 if (do_debug_frames_interp)
7244 frame_display_row (fc, &need_col_headers, &max_regs);
7246 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7247 (unsigned long) (ofs * fc->code_factor),
7248 dwarf_vmatoa_1 (NULL,
7249 fc->pc_begin + ofs * fc->code_factor,
7251 fc->pc_begin += ofs * fc->code_factor;
7254 case DW_CFA_advance_loc2:
7255 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7256 if (do_debug_frames_interp)
7257 frame_display_row (fc, &need_col_headers, &max_regs);
7259 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7260 (unsigned long) (ofs * fc->code_factor),
7261 dwarf_vmatoa_1 (NULL,
7262 fc->pc_begin + ofs * fc->code_factor,
7264 fc->pc_begin += ofs * fc->code_factor;
7267 case DW_CFA_advance_loc4:
7268 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7269 if (do_debug_frames_interp)
7270 frame_display_row (fc, &need_col_headers, &max_regs);
7272 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7273 (unsigned long) (ofs * fc->code_factor),
7274 dwarf_vmatoa_1 (NULL,
7275 fc->pc_begin + ofs * fc->code_factor,
7277 fc->pc_begin += ofs * fc->code_factor;
7280 case DW_CFA_offset_extended:
7283 if (reg >= (unsigned int) fc->ncols)
7284 reg_prefix = bad_reg;
7285 if (! do_debug_frames_interp || *reg_prefix != '\0')
7286 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7287 reg_prefix, regname (reg, 0),
7288 roffs * fc->data_factor);
7289 if (*reg_prefix == '\0')
7291 fc->col_type[reg] = DW_CFA_offset;
7292 fc->col_offset[reg] = roffs * fc->data_factor;
7296 case DW_CFA_val_offset:
7299 if (reg >= (unsigned int) fc->ncols)
7300 reg_prefix = bad_reg;
7301 if (! do_debug_frames_interp || *reg_prefix != '\0')
7302 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7303 reg_prefix, regname (reg, 0),
7304 roffs * fc->data_factor);
7305 if (*reg_prefix == '\0')
7307 fc->col_type[reg] = DW_CFA_val_offset;
7308 fc->col_offset[reg] = roffs * fc->data_factor;
7312 case DW_CFA_restore_extended:
7314 if (reg >= (unsigned int) fc->ncols)
7315 reg_prefix = bad_reg;
7316 if (! do_debug_frames_interp || *reg_prefix != '\0')
7317 printf (" DW_CFA_restore_extended: %s%s\n",
7318 reg_prefix, regname (reg, 0));
7319 if (*reg_prefix != '\0')
7322 if (reg >= (unsigned int) cie->ncols)
7324 fc->col_type[reg] = DW_CFA_undefined;
7325 fc->col_offset[reg] = 0;
7329 fc->col_type[reg] = cie->col_type[reg];
7330 fc->col_offset[reg] = cie->col_offset[reg];
7334 case DW_CFA_undefined:
7336 if (reg >= (unsigned int) fc->ncols)
7337 reg_prefix = bad_reg;
7338 if (! do_debug_frames_interp || *reg_prefix != '\0')
7339 printf (" DW_CFA_undefined: %s%s\n",
7340 reg_prefix, regname (reg, 0));
7341 if (*reg_prefix == '\0')
7343 fc->col_type[reg] = DW_CFA_undefined;
7344 fc->col_offset[reg] = 0;
7348 case DW_CFA_same_value:
7350 if (reg >= (unsigned int) fc->ncols)
7351 reg_prefix = bad_reg;
7352 if (! do_debug_frames_interp || *reg_prefix != '\0')
7353 printf (" DW_CFA_same_value: %s%s\n",
7354 reg_prefix, regname (reg, 0));
7355 if (*reg_prefix == '\0')
7357 fc->col_type[reg] = DW_CFA_same_value;
7358 fc->col_offset[reg] = 0;
7362 case DW_CFA_register:
7365 if (reg >= (unsigned int) fc->ncols)
7366 reg_prefix = bad_reg;
7367 if (! do_debug_frames_interp || *reg_prefix != '\0')
7369 printf (" DW_CFA_register: %s%s in ",
7370 reg_prefix, regname (reg, 0));
7371 puts (regname (roffs, 0));
7373 if (*reg_prefix == '\0')
7375 fc->col_type[reg] = DW_CFA_register;
7376 fc->col_offset[reg] = roffs;
7380 case DW_CFA_remember_state:
7381 if (! do_debug_frames_interp)
7382 printf (" DW_CFA_remember_state\n");
7383 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7384 rs->cfa_offset = fc->cfa_offset;
7385 rs->cfa_reg = fc->cfa_reg;
7387 rs->cfa_exp = fc->cfa_exp;
7388 rs->ncols = fc->ncols;
7389 rs->col_type = (short int *) xcmalloc (rs->ncols,
7390 sizeof (* rs->col_type));
7391 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7392 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7393 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7394 rs->next = remembered_state;
7395 remembered_state = rs;
7398 case DW_CFA_restore_state:
7399 if (! do_debug_frames_interp)
7400 printf (" DW_CFA_restore_state\n");
7401 rs = remembered_state;
7404 remembered_state = rs->next;
7405 fc->cfa_offset = rs->cfa_offset;
7406 fc->cfa_reg = rs->cfa_reg;
7408 fc->cfa_exp = rs->cfa_exp;
7409 if (frame_need_space (fc, rs->ncols - 1) < 0)
7411 warn (_("Invalid column number in saved frame state\n"));
7415 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7416 memcpy (fc->col_offset, rs->col_offset,
7417 rs->ncols * sizeof (* rs->col_offset));
7418 free (rs->col_type);
7419 free (rs->col_offset);
7422 else if (do_debug_frames_interp)
7423 printf ("Mismatched DW_CFA_restore_state\n");
7426 case DW_CFA_def_cfa:
7427 READ_SLEB (fc->cfa_reg);
7428 READ_ULEB (fc->cfa_offset);
7430 if (! do_debug_frames_interp)
7431 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7432 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7435 case DW_CFA_def_cfa_register:
7436 READ_SLEB (fc->cfa_reg);
7438 if (! do_debug_frames_interp)
7439 printf (" DW_CFA_def_cfa_register: %s\n",
7440 regname (fc->cfa_reg, 0));
7443 case DW_CFA_def_cfa_offset:
7444 READ_ULEB (fc->cfa_offset);
7445 if (! do_debug_frames_interp)
7446 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7450 if (! do_debug_frames_interp)
7451 printf (" DW_CFA_nop\n");
7454 case DW_CFA_def_cfa_expression:
7456 if (start >= block_end || ul > (unsigned long) (block_end - start))
7458 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7461 if (! do_debug_frames_interp)
7463 printf (" DW_CFA_def_cfa_expression (");
7464 decode_location_expression (start, eh_addr_size, 0, -1,
7472 case DW_CFA_expression:
7475 if (reg >= (unsigned int) fc->ncols)
7476 reg_prefix = bad_reg;
7477 /* PR 17512: file: 069-133014-0.006. */
7478 /* PR 17512: file: 98c02eb4. */
7480 if (start >= block_end || tmp > block_end || tmp < start)
7482 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7485 if (! do_debug_frames_interp || *reg_prefix != '\0')
7487 printf (" DW_CFA_expression: %s%s (",
7488 reg_prefix, regname (reg, 0));
7489 decode_location_expression (start, eh_addr_size, 0, -1,
7493 if (*reg_prefix == '\0')
7494 fc->col_type[reg] = DW_CFA_expression;
7498 case DW_CFA_val_expression:
7501 if (reg >= (unsigned int) fc->ncols)
7502 reg_prefix = bad_reg;
7504 if (start >= block_end || tmp > block_end || tmp < start)
7506 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7509 if (! do_debug_frames_interp || *reg_prefix != '\0')
7511 printf (" DW_CFA_val_expression: %s%s (",
7512 reg_prefix, regname (reg, 0));
7513 decode_location_expression (start, eh_addr_size, 0, -1,
7517 if (*reg_prefix == '\0')
7518 fc->col_type[reg] = DW_CFA_val_expression;
7522 case DW_CFA_offset_extended_sf:
7525 if (frame_need_space (fc, reg) < 0)
7526 reg_prefix = bad_reg;
7527 if (! do_debug_frames_interp || *reg_prefix != '\0')
7528 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7529 reg_prefix, regname (reg, 0),
7530 (long)(l * fc->data_factor));
7531 if (*reg_prefix == '\0')
7533 fc->col_type[reg] = DW_CFA_offset;
7534 fc->col_offset[reg] = l * fc->data_factor;
7538 case DW_CFA_val_offset_sf:
7541 if (frame_need_space (fc, reg) < 0)
7542 reg_prefix = bad_reg;
7543 if (! do_debug_frames_interp || *reg_prefix != '\0')
7544 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7545 reg_prefix, regname (reg, 0),
7546 (long)(l * fc->data_factor));
7547 if (*reg_prefix == '\0')
7549 fc->col_type[reg] = DW_CFA_val_offset;
7550 fc->col_offset[reg] = l * fc->data_factor;
7554 case DW_CFA_def_cfa_sf:
7555 READ_SLEB (fc->cfa_reg);
7556 READ_ULEB (fc->cfa_offset);
7557 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7559 if (! do_debug_frames_interp)
7560 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7561 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7564 case DW_CFA_def_cfa_offset_sf:
7565 READ_ULEB (fc->cfa_offset);
7566 fc->cfa_offset *= fc->data_factor;
7567 if (! do_debug_frames_interp)
7568 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7571 case DW_CFA_MIPS_advance_loc8:
7572 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7573 if (do_debug_frames_interp)
7574 frame_display_row (fc, &need_col_headers, &max_regs);
7576 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7577 (unsigned long) (ofs * fc->code_factor),
7578 dwarf_vmatoa_1 (NULL,
7579 fc->pc_begin + ofs * fc->code_factor,
7581 fc->pc_begin += ofs * fc->code_factor;
7584 case DW_CFA_GNU_window_save:
7585 if (! do_debug_frames_interp)
7586 printf (" DW_CFA_GNU_window_save\n");
7589 case DW_CFA_GNU_args_size:
7591 if (! do_debug_frames_interp)
7592 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7595 case DW_CFA_GNU_negative_offset_extended:
7599 if (frame_need_space (fc, reg) < 0)
7600 reg_prefix = bad_reg;
7601 if (! do_debug_frames_interp || *reg_prefix != '\0')
7602 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7603 reg_prefix, regname (reg, 0),
7604 (long)(l * fc->data_factor));
7605 if (*reg_prefix == '\0')
7607 fc->col_type[reg] = DW_CFA_offset;
7608 fc->col_offset[reg] = l * fc->data_factor;
7613 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7614 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7616 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7621 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7622 if (do_debug_frames_interp && ! all_nops)
7623 frame_display_row (fc, &need_col_headers, &max_regs);
7626 eh_addr_size = saved_eh_addr_size;
7637 display_gdb_index (struct dwarf_section *section,
7638 void *file ATTRIBUTE_UNUSED)
7640 unsigned char *start = section->start;
7642 uint32_t cu_list_offset, tu_list_offset;
7643 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
7644 unsigned int cu_list_elements, tu_list_elements;
7645 unsigned int address_table_size, symbol_table_slots;
7646 unsigned char *cu_list, *tu_list;
7647 unsigned char *address_table, *symbol_table, *constant_pool;
7650 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
7652 printf (_("Contents of the %s section:\n"), section->name);
7654 if (section->size < 6 * sizeof (uint32_t))
7656 warn (_("Truncated header in the %s section.\n"), section->name);
7660 version = byte_get_little_endian (start, 4);
7661 printf (_("Version %ld\n"), (long) version);
7663 /* Prior versions are obsolete, and future versions may not be
7664 backwards compatible. */
7665 if (version < 3 || version > 8)
7667 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
7671 warn (_("The address table data in version 3 may be wrong.\n"));
7673 warn (_("Version 4 does not support case insensitive lookups.\n"));
7675 warn (_("Version 5 does not include inlined functions.\n"));
7677 warn (_("Version 6 does not include symbol attributes.\n"));
7678 /* Version 7 indices generated by Gold have bad type unit references,
7679 PR binutils/15021. But we don't know if the index was generated by
7680 Gold or not, so to avoid worrying users with gdb-generated indices
7681 we say nothing for version 7 here. */
7683 cu_list_offset = byte_get_little_endian (start + 4, 4);
7684 tu_list_offset = byte_get_little_endian (start + 8, 4);
7685 address_table_offset = byte_get_little_endian (start + 12, 4);
7686 symbol_table_offset = byte_get_little_endian (start + 16, 4);
7687 constant_pool_offset = byte_get_little_endian (start + 20, 4);
7689 if (cu_list_offset > section->size
7690 || tu_list_offset > section->size
7691 || address_table_offset > section->size
7692 || symbol_table_offset > section->size
7693 || constant_pool_offset > section->size)
7695 warn (_("Corrupt header in the %s section.\n"), section->name);
7699 /* PR 17531: file: 418d0a8a. */
7700 if (tu_list_offset < cu_list_offset)
7702 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
7703 tu_list_offset, cu_list_offset);
7707 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
7709 if (address_table_offset < tu_list_offset)
7711 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
7712 address_table_offset, tu_list_offset);
7716 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
7718 /* PR 17531: file: 18a47d3d. */
7719 if (symbol_table_offset < address_table_offset)
7721 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
7722 symbol_table_offset, address_table_offset);
7726 address_table_size = symbol_table_offset - address_table_offset;
7728 if (constant_pool_offset < symbol_table_offset)
7730 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
7731 constant_pool_offset, symbol_table_offset);
7735 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
7737 cu_list = start + cu_list_offset;
7738 tu_list = start + tu_list_offset;
7739 address_table = start + address_table_offset;
7740 symbol_table = start + symbol_table_offset;
7741 constant_pool = start + constant_pool_offset;
7743 if (address_table + address_table_size > section->start + section->size)
7745 warn (_("Address table extends beyond end of section.\n"));
7749 printf (_("\nCU table:\n"));
7750 for (i = 0; i < cu_list_elements; i += 2)
7752 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
7753 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
7755 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
7756 (unsigned long) cu_offset,
7757 (unsigned long) (cu_offset + cu_length - 1));
7760 printf (_("\nTU table:\n"));
7761 for (i = 0; i < tu_list_elements; i += 3)
7763 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
7764 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
7765 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
7767 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
7768 (unsigned long) tu_offset,
7769 (unsigned long) type_offset);
7770 print_dwarf_vma (signature, 8);
7774 printf (_("\nAddress table:\n"));
7775 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
7778 uint64_t low = byte_get_little_endian (address_table + i, 8);
7779 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
7780 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
7782 print_dwarf_vma (low, 8);
7783 print_dwarf_vma (high, 8);
7784 printf (_("%lu\n"), (unsigned long) cu_index);
7787 printf (_("\nSymbol table:\n"));
7788 for (i = 0; i < symbol_table_slots; ++i)
7790 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
7791 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
7792 uint32_t num_cus, cu;
7794 if (name_offset != 0
7795 || cu_vector_offset != 0)
7798 unsigned char * adr;
7800 adr = constant_pool + name_offset;
7801 /* PR 17531: file: 5b7b07ad. */
7802 if (adr < constant_pool || adr >= section->start + section->size)
7804 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
7805 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
7809 printf ("[%3u] %.*s:", i,
7810 (int) (section->size - (constant_pool_offset + name_offset)),
7811 constant_pool + name_offset);
7813 adr = constant_pool + cu_vector_offset;
7814 if (adr < constant_pool || adr >= section->start + section->size - 3)
7816 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
7817 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
7818 cu_vector_offset, i);
7822 num_cus = byte_get_little_endian (adr, 4);
7824 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
7825 if (num_cus * 4 < num_cus
7826 || adr >= section->start + section->size
7827 || adr < constant_pool)
7829 printf ("<invalid number of CUs: %d>\n", num_cus);
7830 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
7838 for (j = 0; j < num_cus; ++j)
7841 gdb_index_symbol_kind kind;
7843 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7844 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
7845 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
7846 cu = GDB_INDEX_CU_VALUE (cu);
7847 /* Convert to TU number if it's for a type unit. */
7848 if (cu >= cu_list_elements / 2)
7849 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
7850 (unsigned long) (cu - cu_list_elements / 2));
7852 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
7854 printf (" [%s, %s]",
7855 is_static ? _("static") : _("global"),
7856 get_gdb_index_symbol_kind_name (kind));
7868 /* Pre-allocate enough space for the CU/TU sets needed. */
7871 prealloc_cu_tu_list (unsigned int nshndx)
7873 if (shndx_pool == NULL)
7875 shndx_pool_size = nshndx;
7876 shndx_pool_used = 0;
7877 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
7878 sizeof (unsigned int));
7882 shndx_pool_size = shndx_pool_used + nshndx;
7883 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
7884 sizeof (unsigned int));
7889 add_shndx_to_cu_tu_entry (unsigned int shndx)
7891 if (shndx_pool_used >= shndx_pool_size)
7893 error (_("Internal error: out of space in the shndx pool.\n"));
7896 shndx_pool [shndx_pool_used++] = shndx;
7900 end_cu_tu_entry (void)
7902 if (shndx_pool_used >= shndx_pool_size)
7904 error (_("Internal error: out of space in the shndx pool.\n"));
7907 shndx_pool [shndx_pool_used++] = 0;
7910 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7913 get_DW_SECT_short_name (unsigned int dw_sect)
7915 static char buf[16];
7923 case DW_SECT_ABBREV:
7929 case DW_SECT_STR_OFFSETS:
7931 case DW_SECT_MACINFO:
7939 snprintf (buf, sizeof (buf), "%d", dw_sect);
7943 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7944 These sections are extensions for Fission.
7945 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7948 process_cu_tu_index (struct dwarf_section *section, int do_display)
7950 unsigned char *phdr = section->start;
7951 unsigned char *limit = phdr + section->size;
7952 unsigned char *phash;
7953 unsigned char *pindex;
7954 unsigned char *ppool;
7955 unsigned int version;
7956 unsigned int ncols = 0;
7958 unsigned int nslots;
7961 dwarf_vma signature_high;
7962 dwarf_vma signature_low;
7965 /* PR 17512: file: 002-168123-0.004. */
7968 warn (_("Section %s is empty\n"), section->name);
7971 /* PR 17512: file: 002-376-0.004. */
7972 if (section->size < 24)
7974 warn (_("Section %s is too small to contain a CU/TU header\n"),
7979 SAFE_BYTE_GET (version, phdr, 4, limit);
7981 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
7982 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
7983 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
7986 pindex = phash + nslots * 8;
7987 ppool = pindex + nslots * 4;
7989 /* PR 17531: file: 45d69832. */
7990 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
7992 warn (_("Section %s is too small for %d slots\n"),
7993 section->name, nslots);
7999 printf (_("Contents of the %s section:\n\n"), section->name);
8000 printf (_(" Version: %d\n"), version);
8002 printf (_(" Number of columns: %d\n"), ncols);
8003 printf (_(" Number of used entries: %d\n"), nused);
8004 printf (_(" Number of slots: %d\n\n"), nslots);
8007 if (ppool > limit || ppool < phdr)
8009 warn (_("Section %s too small for %d hash table entries\n"),
8010 section->name, nslots);
8017 prealloc_cu_tu_list ((limit - ppool) / 4);
8018 for (i = 0; i < nslots; i++)
8020 unsigned char *shndx_list;
8023 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
8024 if (signature_high != 0 || signature_low != 0)
8026 SAFE_BYTE_GET (j, pindex, 4, limit);
8027 shndx_list = ppool + j * 4;
8028 /* PR 17531: file: 705e010d. */
8029 if (shndx_list < ppool)
8031 warn (_("Section index pool located before start of section\n"));
8036 printf (_(" [%3d] Signature: 0x%s Sections: "),
8037 i, dwarf_vmatoa64 (signature_high, signature_low,
8038 buf, sizeof (buf)));
8041 if (shndx_list >= limit)
8043 warn (_("Section %s too small for shndx pool\n"),
8047 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
8051 printf (" %d", shndx);
8053 add_shndx_to_cu_tu_entry (shndx);
8065 else if (version == 2)
8068 unsigned int dw_sect;
8069 unsigned char *ph = phash;
8070 unsigned char *pi = pindex;
8071 unsigned char *poffsets = ppool + ncols * 4;
8072 unsigned char *psizes = poffsets + nused * ncols * 4;
8073 unsigned char *pend = psizes + nused * ncols * 4;
8074 bfd_boolean is_tu_index;
8075 struct cu_tu_set *this_set = NULL;
8077 unsigned char *prow;
8079 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8081 /* PR 17531: file: 0dd159bf.
8082 Check for wraparound with an overlarge ncols value. */
8083 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
8085 warn (_("Overlarge number of columns: %x\n"), ncols);
8091 warn (_("Section %s too small for offset and size tables\n"),
8098 printf (_(" Offset table\n"));
8099 printf (" slot %-16s ",
8100 is_tu_index ? _("signature") : _("dwo_id"));
8107 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8113 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8120 for (j = 0; j < ncols; j++)
8122 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8123 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8128 for (i = 0; i < nslots; i++)
8130 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8132 SAFE_BYTE_GET (row, pi, 4, limit);
8135 /* PR 17531: file: a05f6ab3. */
8138 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8144 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8146 prow = poffsets + (row - 1) * ncols * 4;
8147 /* PR 17531: file: b8ce60a8. */
8148 if (prow < poffsets || prow > limit)
8150 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8156 printf (_(" [%3d] 0x%s"),
8157 i, dwarf_vmatoa64 (signature_high, signature_low,
8158 buf, sizeof (buf)));
8159 for (j = 0; j < ncols; j++)
8161 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8163 printf (" %8d", val);
8166 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8168 /* PR 17531: file: 10796eb3. */
8169 if (dw_sect >= DW_SECT_MAX)
8170 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8172 this_set [row - 1].section_offsets [dw_sect] = val;
8188 printf (_(" Size table\n"));
8189 printf (" slot %-16s ",
8190 is_tu_index ? _("signature") : _("dwo_id"));
8193 for (j = 0; j < ncols; j++)
8195 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8197 printf (" %8s", get_DW_SECT_short_name (val));
8203 for (i = 0; i < nslots; i++)
8205 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8207 SAFE_BYTE_GET (row, pi, 4, limit);
8210 prow = psizes + (row - 1) * ncols * 4;
8213 printf (_(" [%3d] 0x%s"),
8214 i, dwarf_vmatoa64 (signature_high, signature_low,
8215 buf, sizeof (buf)));
8217 for (j = 0; j < ncols; j++)
8219 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8221 printf (" %8d", val);
8224 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8225 if (dw_sect >= DW_SECT_MAX)
8226 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8228 this_set [row - 1].section_sizes [dw_sect] = val;
8240 else if (do_display)
8241 printf (_(" Unsupported version (%d)\n"), version);
8249 /* Load the CU and TU indexes if present. This will build a list of
8250 section sets that we can use to associate a .debug_info.dwo section
8251 with its associated .debug_abbrev.dwo section in a .dwp file. */
8254 load_cu_tu_indexes (void *file)
8256 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8258 /* If we have already loaded (or tried to load) the CU and TU indexes
8259 then do not bother to repeat the task. */
8260 if (cu_tu_indexes_read == -1)
8262 cu_tu_indexes_read = TRUE;
8264 if (load_debug_section (dwp_cu_index, file))
8265 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8266 cu_tu_indexes_read = FALSE;
8268 if (load_debug_section (dwp_tu_index, file))
8269 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8270 cu_tu_indexes_read = FALSE;
8273 return (bfd_boolean) cu_tu_indexes_read;
8276 /* Find the set of sections that includes section SHNDX. */
8279 find_cu_tu_set (void *file, unsigned int shndx)
8283 if (! load_cu_tu_indexes (file))
8286 /* Find SHNDX in the shndx pool. */
8287 for (i = 0; i < shndx_pool_used; i++)
8288 if (shndx_pool [i] == shndx)
8291 if (i >= shndx_pool_used)
8294 /* Now backup to find the first entry in the set. */
8295 while (i > 0 && shndx_pool [i - 1] != 0)
8298 return shndx_pool + i;
8301 /* Display a .debug_cu_index or .debug_tu_index section. */
8304 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
8306 return process_cu_tu_index (section, 1);
8310 display_debug_not_supported (struct dwarf_section *section,
8311 void *file ATTRIBUTE_UNUSED)
8313 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8319 /* Like malloc, but takes two parameters like calloc.
8320 Verifies that the first parameter is not too large.
8321 Note: does *not* initialise the allocated memory to zero. */
8323 cmalloc (size_t nmemb, size_t size)
8325 /* Check for overflow. */
8326 if (nmemb >= ~(size_t) 0 / size)
8329 return xmalloc (nmemb * size);
8332 /* Like xmalloc, but takes two parameters like calloc.
8333 Verifies that the first parameter is not too large.
8334 Note: does *not* initialise the allocated memory to zero. */
8336 xcmalloc (size_t nmemb, size_t size)
8338 /* Check for overflow. */
8339 if (nmemb >= ~(size_t) 0 / size)
8342 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8347 return xmalloc (nmemb * size);
8350 /* Like xrealloc, but takes three parameters.
8351 Verifies that the second parameter is not too large.
8352 Note: does *not* initialise any new memory to zero. */
8354 xcrealloc (void *ptr, size_t nmemb, size_t size)
8356 /* Check for overflow. */
8357 if (nmemb >= ~(size_t) 0 / size)
8360 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8365 return xrealloc (ptr, nmemb * size);
8368 /* Like xcalloc, but verifies that the first parameter is not too large. */
8370 xcalloc2 (size_t nmemb, size_t size)
8372 /* Check for overflow. */
8373 if (nmemb >= ~(size_t) 0 / size)
8376 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8381 return xcalloc (nmemb, size);
8385 free_debug_memory (void)
8391 for (i = 0; i < max; i++)
8392 free_debug_section ((enum dwarf_section_display_enum) i);
8394 if (debug_information != NULL)
8396 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
8398 for (i = 0; i < num_debug_info_entries; i++)
8400 if (!debug_information [i].max_loc_offsets)
8402 free (debug_information [i].loc_offsets);
8403 free (debug_information [i].have_frame_base);
8405 if (!debug_information [i].max_range_lists)
8406 free (debug_information [i].range_lists);
8409 free (debug_information);
8410 debug_information = NULL;
8411 alloc_num_debug_info_entries = num_debug_info_entries = 0;
8416 dwarf_select_sections_by_names (const char *names)
8420 const char * option;
8424 debug_dump_long_opts;
8426 static const debug_dump_long_opts opts_table [] =
8428 /* Please keep this table alpha- sorted. */
8429 { "Ranges", & do_debug_ranges, 1 },
8430 { "abbrev", & do_debug_abbrevs, 1 },
8431 { "addr", & do_debug_addr, 1 },
8432 { "aranges", & do_debug_aranges, 1 },
8433 { "cu_index", & do_debug_cu_index, 1 },
8434 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
8435 { "frames", & do_debug_frames, 1 },
8436 { "frames-interp", & do_debug_frames_interp, 1 },
8437 /* The special .gdb_index section. */
8438 { "gdb_index", & do_gdb_index, 1 },
8439 { "info", & do_debug_info, 1 },
8440 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
8441 { "loc", & do_debug_loc, 1 },
8442 { "macro", & do_debug_macinfo, 1 },
8443 { "pubnames", & do_debug_pubnames, 1 },
8444 { "pubtypes", & do_debug_pubtypes, 1 },
8445 /* This entry is for compatibility
8446 with earlier versions of readelf. */
8447 { "ranges", & do_debug_aranges, 1 },
8448 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
8449 { "str", & do_debug_str, 1 },
8450 /* These trace_* sections are used by Itanium VMS. */
8451 { "trace_abbrev", & do_trace_abbrevs, 1 },
8452 { "trace_aranges", & do_trace_aranges, 1 },
8453 { "trace_info", & do_trace_info, 1 },
8462 const debug_dump_long_opts * entry;
8464 for (entry = opts_table; entry->option; entry++)
8466 size_t len = strlen (entry->option);
8468 if (strncmp (p, entry->option, len) == 0
8469 && (p[len] == ',' || p[len] == '\0'))
8471 * entry->variable |= entry->val;
8473 /* The --debug-dump=frames-interp option also
8474 enables the --debug-dump=frames option. */
8475 if (do_debug_frames_interp)
8476 do_debug_frames = 1;
8483 if (entry->option == NULL)
8485 warn (_("Unrecognized debug option '%s'\n"), p);
8486 p = strchr (p, ',');
8497 dwarf_select_sections_by_letters (const char *letters)
8499 unsigned int lindex = 0;
8501 while (letters[lindex])
8502 switch (letters[lindex++])
8509 do_debug_abbrevs = 1;
8513 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
8517 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
8521 do_debug_pubnames = 1;
8525 do_debug_pubtypes = 1;
8529 do_debug_aranges = 1;
8533 do_debug_ranges = 1;
8537 do_debug_frames_interp = 1;
8540 do_debug_frames = 1;
8544 do_debug_macinfo = 1;
8556 warn (_("Unrecognized debug option '%s'\n"), letters);
8562 dwarf_select_sections_all (void)
8565 do_debug_abbrevs = 1;
8566 do_debug_lines = FLAG_DEBUG_LINES_RAW;
8567 do_debug_pubnames = 1;
8568 do_debug_pubtypes = 1;
8569 do_debug_aranges = 1;
8570 do_debug_ranges = 1;
8571 do_debug_frames = 1;
8572 do_debug_macinfo = 1;
8577 do_trace_abbrevs = 1;
8578 do_trace_aranges = 1;
8580 do_debug_cu_index = 1;
8583 struct dwarf_section_display debug_displays[] =
8585 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8586 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8587 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8588 display_debug_aranges, &do_debug_aranges, TRUE },
8589 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8590 display_debug_frames, &do_debug_frames, TRUE },
8591 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8592 display_debug_info, &do_debug_info, TRUE },
8593 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8594 display_debug_lines, &do_debug_lines, TRUE },
8595 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8596 display_debug_pubnames, &do_debug_pubnames, FALSE },
8597 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8598 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
8599 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8600 display_debug_frames, &do_debug_frames, TRUE },
8601 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8602 display_debug_macinfo, &do_debug_macinfo, FALSE },
8603 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8604 display_debug_macro, &do_debug_macinfo, TRUE },
8605 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8606 display_debug_str, &do_debug_str, FALSE },
8607 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8608 display_debug_str, &do_debug_str, FALSE },
8609 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8610 display_debug_loc, &do_debug_loc, TRUE },
8611 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8612 display_debug_loc, &do_debug_loc, TRUE },
8613 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8614 display_debug_pubnames, &do_debug_pubtypes, FALSE },
8615 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8616 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
8617 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8618 display_debug_ranges, &do_debug_ranges, TRUE },
8619 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8620 display_debug_ranges, &do_debug_ranges, TRUE },
8621 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8622 display_debug_not_supported, NULL, FALSE },
8623 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8624 display_debug_not_supported, NULL, FALSE },
8625 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8626 display_debug_types, &do_debug_info, TRUE },
8627 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8628 display_debug_not_supported, NULL, FALSE },
8629 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8630 display_gdb_index, &do_gdb_index, FALSE },
8631 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
8632 display_trace_info, &do_trace_info, TRUE },
8633 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8634 display_debug_abbrev, &do_trace_abbrevs, FALSE },
8635 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8636 display_debug_aranges, &do_trace_aranges, FALSE },
8637 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8638 display_debug_info, &do_debug_info, TRUE },
8639 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8640 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8641 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8642 display_debug_types, &do_debug_info, TRUE },
8643 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8644 display_debug_lines, &do_debug_lines, TRUE },
8645 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8646 display_debug_loc, &do_debug_loc, TRUE },
8647 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8648 display_debug_macro, &do_debug_macinfo, TRUE },
8649 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8650 display_debug_macinfo, &do_debug_macinfo, FALSE },
8651 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8652 display_debug_str, &do_debug_str, TRUE },
8653 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8654 display_debug_str_offsets, NULL, FALSE },
8655 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8656 display_debug_str_offsets, NULL, FALSE },
8657 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8658 display_debug_addr, &do_debug_addr, TRUE },
8659 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8660 display_cu_index, &do_debug_cu_index, FALSE },
8661 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8662 display_cu_index, &do_debug_cu_index, FALSE },
8665 /* A static assertion. */
8666 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];