1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2018 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"
31 #include "filenames.h"
36 #define MAX(a, b) ((a) > (b) ? (a) : (b))
37 #define MIN(a, b) ((a) < (b) ? (a) : (b))
39 static const char *regname (unsigned int regno, int row);
41 static int have_frame_base;
42 static int need_base_address;
44 static unsigned int num_debug_info_entries = 0;
45 static unsigned int alloc_num_debug_info_entries = 0;
46 static debug_info *debug_information = NULL;
47 /* Special value for num_debug_info_entries to indicate
48 that the .debug_info section could not be loaded/parsed. */
49 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 static const char * dwo_name;
52 static const char * dwo_dir;
53 static const unsigned char * dwo_id;
54 static bfd_size_type dwo_id_len;
55 static bfd_boolean need_dwo_info;
57 unsigned int eh_addr_size;
62 int do_debug_pubnames;
63 int do_debug_pubtypes;
67 int do_debug_frames_interp;
76 int do_debug_cu_index;
81 int dwarf_cutoff_level = -1;
82 unsigned long dwarf_start_die;
86 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
87 testing whether e.g. a locview list is present. */
88 static const dwarf_vma vm1 = -1;
90 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
91 sections. For version 1 package files, each set is stored in SHNDX_POOL
92 as a zero-terminated list of section indexes comprising one set of debug
93 sections from a .dwo file. */
95 static unsigned int *shndx_pool = NULL;
96 static unsigned int shndx_pool_size = 0;
97 static unsigned int shndx_pool_used = 0;
99 /* Pointer to a separate file containing extra debug information. */
100 static void * separate_debug_file = NULL;
101 static const char * separate_debug_filename = NULL;
103 /* For version 2 package files, each set contains an array of section offsets
104 and an array of section sizes, giving the offset and size of the
105 contribution from a CU or TU within one of the debug sections.
106 When displaying debug info from a package file, we need to use these
107 tables to locate the corresponding contributions to each section. */
112 dwarf_vma section_offsets[DW_SECT_MAX];
113 size_t section_sizes[DW_SECT_MAX];
116 static int cu_count = 0;
117 static int tu_count = 0;
118 static struct cu_tu_set *cu_sets = NULL;
119 static struct cu_tu_set *tu_sets = NULL;
121 static bfd_boolean load_cu_tu_indexes (void *);
123 /* Values for do_debug_lines. */
124 #define FLAG_DEBUG_LINES_RAW 1
125 #define FLAG_DEBUG_LINES_DECODED 2
128 size_of_encoded_value (int encoding)
130 switch (encoding & 0x7)
133 case 0: return eh_addr_size;
141 get_encoded_value (unsigned char **pdata,
143 struct dwarf_section *section,
146 unsigned char * data = * pdata;
147 unsigned int size = size_of_encoded_value (encoding);
150 if (data + size >= end)
152 warn (_("Encoded value extends past end of section\n"));
157 /* PR 17512: file: 002-829853-0.004. */
160 warn (_("Encoded size of %d is too large to read\n"), size);
165 /* PR 17512: file: 1085-5603-0.004. */
168 warn (_("Encoded size of 0 is too small to read\n"));
173 if (encoding & DW_EH_PE_signed)
174 val = byte_get_signed (data, size);
176 val = byte_get (data, size);
178 if ((encoding & 0x70) == DW_EH_PE_pcrel)
179 val += section->address + (data - section->start);
181 * pdata = data + size;
185 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
187 # define DWARF_VMA_FMT "ll"
188 # define DWARF_VMA_FMT_LONG "%16.16llx"
190 # define DWARF_VMA_FMT "I64"
191 # define DWARF_VMA_FMT_LONG "%016I64x"
194 # define DWARF_VMA_FMT "l"
195 # define DWARF_VMA_FMT_LONG "%16.16lx"
198 /* Convert a dwarf vma value into a string. Returns a pointer to a static
199 buffer containing the converted VALUE. The value is converted according
200 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
201 it specifies the maximum number of bytes to be displayed in the converted
202 value and FMTCH is ignored - hex is always used. */
205 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
207 /* As dwarf_vmatoa is used more then once in a printf call
208 for output, we are cycling through an fixed array of pointers
209 for return address. */
210 static int buf_pos = 0;
211 static struct dwarf_vmatoa_buf
217 ret = buf[buf_pos++].place;
218 buf_pos %= ARRAY_SIZE (buf);
222 /* Printf does not have a way of specifying a maximum field width for an
223 integer value, so we print the full value into a buffer and then select
224 the precision we need. */
225 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
228 return ret + (16 - 2 * num_bytes);
235 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
237 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
238 snprintf (ret, sizeof (buf[0].place), fmt, value);
243 static inline const char *
244 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
246 return dwarf_vmatoa_1 (fmtch, value, 0);
249 /* Print a dwarf_vma value (typically an address, offset or length) in
250 hexadecimal format, followed by a space. The length of the VALUE (and
251 hence the precision displayed) is determined by the NUM_BYTES parameter. */
254 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
256 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
259 /* Print a view number in hexadecimal value, with the same width
260 print_dwarf_vma would have printed it with the same num_bytes.
261 Print blanks for zero view, unless force is nonzero. */
264 print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
272 assert (value == (unsigned long) value);
274 printf ("v%0*lx ", len - 1, (unsigned long) value);
276 printf ("%*s", len + 1, "");
279 /* Format a 64-bit value, given as two 32-bit values, in hex.
280 For reentrancy, this uses a buffer provided by the caller. */
283 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
284 unsigned int buf_len)
289 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
292 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
293 snprintf (buf + len, buf_len - len,
294 "%08" DWARF_VMA_FMT "x", lvalue);
300 /* Read in a LEB128 encoded value starting at address DATA.
301 If SIGN is true, return a signed LEB128 value.
302 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
303 No bytes will be read at address END or beyond. */
306 read_leb128 (unsigned char *data,
307 unsigned int *length_return,
309 const unsigned char * const end)
311 dwarf_vma result = 0;
312 unsigned int num_read = 0;
313 unsigned int shift = 0;
314 unsigned char byte = 0;
321 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
324 if ((byte & 0x80) == 0)
327 /* PR 17512: file: 0ca183b8.
328 FIXME: Should we signal this error somehow ? */
329 if (shift >= sizeof (result) * 8)
333 if (length_return != NULL)
334 *length_return = num_read;
336 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
337 result |= -((dwarf_vma) 1 << shift);
342 /* Create a signed version to avoid painful typecasts. */
343 static inline dwarf_signed_vma
344 read_sleb128 (unsigned char * data,
345 unsigned int * length_return,
346 const unsigned char * const end)
348 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
351 static inline dwarf_vma
352 read_uleb128 (unsigned char * data,
353 unsigned int * length_return,
354 const unsigned char * const end)
356 return read_leb128 (data, length_return, FALSE, end);
359 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
360 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
362 #define READ_ULEB(var) \
367 (var) = _val = read_uleb128 (start, &length_return, end); \
369 error (_("Internal error: %s:%d: LEB value (%s) " \
370 "too large for containing variable\n"), \
371 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
372 start += length_return; \
376 #define READ_SLEB(var) \
379 dwarf_signed_vma _val; \
381 (var) = _val = read_sleb128 (start, &length_return, end); \
383 error (_("Internal error: %s:%d: LEB value (%s) " \
384 "too large for containing variable\n"), \
385 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
386 start += length_return; \
390 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
393 unsigned int amount = (AMOUNT); \
394 if (sizeof (VAL) < amount) \
396 error (ngettext ("internal error: attempt to read %d byte " \
397 "of data in to %d sized variable", \
398 "internal error: attempt to read %d bytes " \
399 "of data in to %d sized variable", \
401 amount, (int) sizeof (VAL)); \
402 amount = sizeof (VAL); \
404 if (((PTR) + amount) >= (END)) \
407 amount = (END) - (PTR); \
411 if (amount == 0 || amount > 8) \
414 VAL = byte_get ((PTR), amount); \
418 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
421 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
426 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
429 unsigned int amount = (AMOUNT); \
430 if (((PTR) + amount) >= (END)) \
433 amount = (END) - (PTR); \
438 VAL = byte_get_signed ((PTR), amount); \
444 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
447 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
452 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
455 if (((PTR) + 8) <= (END)) \
457 byte_get_64 ((PTR), (HIGH), (LOW)); \
461 * (LOW) = * (HIGH) = 0; \
466 typedef struct State_Machine_Registers
475 unsigned char op_index;
476 unsigned char end_sequence;
477 /* This variable hold the number of the last entry seen
478 in the File Table. */
479 unsigned int last_file_entry;
482 static SMR state_machine_regs;
485 reset_state_machine (int is_stmt)
487 state_machine_regs.address = 0;
488 state_machine_regs.view = 0;
489 state_machine_regs.op_index = 0;
490 state_machine_regs.file = 1;
491 state_machine_regs.line = 1;
492 state_machine_regs.column = 0;
493 state_machine_regs.is_stmt = is_stmt;
494 state_machine_regs.basic_block = 0;
495 state_machine_regs.end_sequence = 0;
496 state_machine_regs.last_file_entry = 0;
499 /* Handled an extend line op.
500 Returns the number of bytes read. */
503 process_extended_line_op (unsigned char * data,
507 unsigned char op_code;
508 unsigned int bytes_read;
511 unsigned char *orig_data = data;
514 len = read_uleb128 (data, & bytes_read, end);
517 if (len == 0 || data == end || len > (uintptr_t) (end - data))
519 warn (_("Badly formed extended line op encountered!\n"));
526 printf (_(" Extended opcode %d: "), op_code);
530 case DW_LNE_end_sequence:
531 printf (_("End of Sequence\n\n"));
532 reset_state_machine (is_stmt);
535 case DW_LNE_set_address:
536 /* PR 17512: file: 002-100480-0.004. */
537 if (len - bytes_read - 1 > 8)
539 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
540 len - bytes_read - 1);
544 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
545 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
546 state_machine_regs.address = adr;
547 state_machine_regs.view = 0;
548 state_machine_regs.op_index = 0;
551 case DW_LNE_define_file:
552 printf (_("define new File Table entry\n"));
553 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
554 printf (" %d\t", ++state_machine_regs.last_file_entry);
560 l = strnlen ((char *) data, end - data);
562 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
564 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
566 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
568 printf ("%.*s\n\n", (int) l, name);
571 if (((unsigned int) (data - orig_data) != len) || data == end)
572 warn (_("DW_LNE_define_file: Bad opcode length\n"));
575 case DW_LNE_set_discriminator:
576 printf (_("set Discriminator to %s\n"),
577 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
581 case DW_LNE_HP_negate_is_UV_update:
582 printf ("DW_LNE_HP_negate_is_UV_update\n");
584 case DW_LNE_HP_push_context:
585 printf ("DW_LNE_HP_push_context\n");
587 case DW_LNE_HP_pop_context:
588 printf ("DW_LNE_HP_pop_context\n");
590 case DW_LNE_HP_set_file_line_column:
591 printf ("DW_LNE_HP_set_file_line_column\n");
593 case DW_LNE_HP_set_routine_name:
594 printf ("DW_LNE_HP_set_routine_name\n");
596 case DW_LNE_HP_set_sequence:
597 printf ("DW_LNE_HP_set_sequence\n");
599 case DW_LNE_HP_negate_post_semantics:
600 printf ("DW_LNE_HP_negate_post_semantics\n");
602 case DW_LNE_HP_negate_function_exit:
603 printf ("DW_LNE_HP_negate_function_exit\n");
605 case DW_LNE_HP_negate_front_end_logical:
606 printf ("DW_LNE_HP_negate_front_end_logical\n");
608 case DW_LNE_HP_define_proc:
609 printf ("DW_LNE_HP_define_proc\n");
611 case DW_LNE_HP_source_file_correlation:
613 unsigned char *edata = data + len - bytes_read - 1;
615 printf ("DW_LNE_HP_source_file_correlation\n");
621 opc = read_uleb128 (data, & bytes_read, edata);
626 case DW_LNE_HP_SFC_formfeed:
627 printf (" DW_LNE_HP_SFC_formfeed\n");
629 case DW_LNE_HP_SFC_set_listing_line:
630 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
632 read_uleb128 (data, & bytes_read, edata)));
635 case DW_LNE_HP_SFC_associate:
636 printf (" DW_LNE_HP_SFC_associate ");
639 read_uleb128 (data, & bytes_read, edata)));
643 read_uleb128 (data, & bytes_read, edata)));
647 read_uleb128 (data, & bytes_read, edata)));
651 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
661 unsigned int rlen = len - bytes_read - 1;
663 if (op_code >= DW_LNE_lo_user
664 /* The test against DW_LNW_hi_user is redundant due to
665 the limited range of the unsigned char data type used
667 /*&& op_code <= DW_LNE_hi_user*/)
668 printf (_("user defined: "));
670 printf (_("UNKNOWN: "));
671 printf (_("length %d ["), rlen);
673 printf (" %02x", *data++);
682 static const unsigned char *
683 fetch_indirect_string (dwarf_vma offset)
685 struct dwarf_section *section = &debug_displays [str].section;
686 const unsigned char * ret;
688 if (section->start == NULL)
689 return (const unsigned char *) _("<no .debug_str section>");
691 if (offset >= section->size)
693 warn (_("DW_FORM_strp offset too big: %s\n"),
694 dwarf_vmatoa ("x", offset));
695 return (const unsigned char *) _("<offset is too big>");
698 ret = section->start + offset;
699 /* Unfortunately we cannot rely upon the .debug_str section ending with a
700 NUL byte. Since our caller is expecting to receive a well formed C
701 string we test for the lack of a terminating byte here. */
702 if (strnlen ((const char *) ret, section->size - offset)
703 == section->size - offset)
704 ret = (const unsigned char *)
705 _("<no NUL byte at end of .debug_str section>");
710 static const unsigned char *
711 fetch_indirect_line_string (dwarf_vma offset)
713 struct dwarf_section *section = &debug_displays [line_str].section;
714 const unsigned char * ret;
716 if (section->start == NULL)
717 return (const unsigned char *) _("<no .debug_line_str section>");
719 if (offset >= section->size)
721 warn (_("DW_FORM_line_strp offset too big: %s\n"),
722 dwarf_vmatoa ("x", offset));
723 return (const unsigned char *) _("<offset is too big>");
726 ret = section->start + offset;
727 /* Unfortunately we cannot rely upon the .debug_line_str section ending
728 with a NUL byte. Since our caller is expecting to receive a well formed
729 C string we test for the lack of a terminating byte here. */
730 if (strnlen ((const char *) ret, section->size - offset)
731 == section->size - offset)
732 ret = (const unsigned char *)
733 _("<no NUL byte at end of .debug_line_str section>");
739 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
740 dwarf_vma offset_size, bfd_boolean dwo)
742 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
743 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
744 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
745 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
746 dwarf_vma index_offset = idx * offset_size;
747 dwarf_vma str_offset;
750 if (index_section->start == NULL)
751 return (dwo ? _("<no .debug_str_offsets.dwo section>")
752 : _("<no .debug_str_offsets section>"));
754 if (this_set != NULL)
755 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
756 if (index_offset >= index_section->size)
758 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
759 dwarf_vmatoa ("x", index_offset));
760 return _("<index offset is too big>");
763 if (str_section->start == NULL)
764 return (dwo ? _("<no .debug_str.dwo section>")
765 : _("<no .debug_str section>"));
767 str_offset = byte_get (index_section->start + index_offset, offset_size);
768 str_offset -= str_section->address;
769 if (str_offset >= str_section->size)
771 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
772 dwarf_vmatoa ("x", str_offset));
773 return _("<indirect index offset is too big>");
776 ret = (const char *) str_section->start + str_offset;
777 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
778 Since our caller is expecting to receive a well formed C string we test
779 for the lack of a terminating byte here. */
780 if (strnlen (ret, str_section->size - str_offset)
781 == str_section->size - str_offset)
782 ret = (const char *) _("<no NUL byte at end of section>");
788 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
790 struct dwarf_section *section = &debug_displays [debug_addr].section;
792 if (section->start == NULL)
793 return (_("<no .debug_addr section>"));
795 if (offset + bytes > section->size)
797 warn (_("Offset into section %s too big: %s\n"),
798 section->name, dwarf_vmatoa ("x", offset));
799 return "<offset too big>";
802 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
806 /* FIXME: There are better and more efficient ways to handle
807 these structures. For now though, I just want something that
808 is simple to implement. */
809 typedef struct abbrev_attr
811 unsigned long attribute;
813 bfd_signed_vma implicit_const;
814 struct abbrev_attr *next;
818 typedef struct abbrev_entry
823 struct abbrev_attr *first_attr;
824 struct abbrev_attr *last_attr;
825 struct abbrev_entry *next;
829 static abbrev_entry *first_abbrev = NULL;
830 static abbrev_entry *last_abbrev = NULL;
837 for (abbrv = first_abbrev; abbrv;)
839 abbrev_entry *next_abbrev = abbrv->next;
842 for (attr = abbrv->first_attr; attr;)
844 abbrev_attr *next_attr = attr->next;
854 last_abbrev = first_abbrev = NULL;
858 add_abbrev (unsigned long number, unsigned long tag, int children)
862 entry = (abbrev_entry *) malloc (sizeof (*entry));
867 entry->entry = number;
869 entry->children = children;
870 entry->first_attr = NULL;
871 entry->last_attr = NULL;
874 if (first_abbrev == NULL)
875 first_abbrev = entry;
877 last_abbrev->next = entry;
883 add_abbrev_attr (unsigned long attribute, unsigned long form,
884 bfd_signed_vma implicit_const)
888 attr = (abbrev_attr *) malloc (sizeof (*attr));
893 attr->attribute = attribute;
895 attr->implicit_const = implicit_const;
898 if (last_abbrev->first_attr == NULL)
899 last_abbrev->first_attr = attr;
901 last_abbrev->last_attr->next = attr;
903 last_abbrev->last_attr = attr;
906 /* Processes the (partial) contents of a .debug_abbrev section.
907 Returns NULL if the end of the section was encountered.
908 Returns the address after the last byte read if the end of
909 an abbreviation set was found. */
911 static unsigned char *
912 process_abbrev_section (unsigned char *start, unsigned char *end)
914 if (first_abbrev != NULL)
919 unsigned int bytes_read;
922 unsigned long attribute;
925 entry = read_uleb128 (start, & bytes_read, end);
928 /* A single zero is supposed to end the section according
929 to the standard. If there's more, then signal that to
936 tag = read_uleb128 (start, & bytes_read, end);
943 add_abbrev (entry, tag, children);
948 /* Initialize it due to a false compiler warning. */
949 bfd_signed_vma implicit_const = -1;
951 attribute = read_uleb128 (start, & bytes_read, end);
956 form = read_uleb128 (start, & bytes_read, end);
961 if (form == DW_FORM_implicit_const)
963 implicit_const = read_sleb128 (start, & bytes_read, end);
969 add_abbrev_attr (attribute, form, implicit_const);
971 while (attribute != 0);
974 /* Report the missing single zero which ends the section. */
975 error (_(".debug_abbrev section not zero terminated\n"));
981 get_TAG_name (unsigned long tag)
983 const char *name = get_DW_TAG_name ((unsigned int) tag);
987 static char buffer[100];
989 if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
990 snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
992 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
1000 get_FORM_name (unsigned long form)
1005 return "DW_FORM value: 0";
1007 name = get_DW_FORM_name (form);
1010 static char buffer[100];
1012 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
1020 get_IDX_name (unsigned long idx)
1022 const char *name = get_DW_IDX_name ((unsigned int) idx);
1026 static char buffer[100];
1028 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
1035 static unsigned char *
1036 display_block (unsigned char *data,
1038 const unsigned char * const end, char delimiter)
1042 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
1044 return (unsigned char *) end;
1046 maxlen = (dwarf_vma) (end - data);
1047 length = length > maxlen ? maxlen : length;
1050 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1056 decode_location_expression (unsigned char * data,
1057 unsigned int pointer_size,
1058 unsigned int offset_size,
1061 dwarf_vma cu_offset,
1062 struct dwarf_section * section)
1065 unsigned int bytes_read;
1067 dwarf_signed_vma svalue;
1068 unsigned char *end = data + length;
1069 int need_frame_base = 0;
1078 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1079 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1082 printf ("DW_OP_deref");
1085 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1086 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1089 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1090 printf ("DW_OP_const1s: %ld", (long) svalue);
1093 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1094 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1097 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1098 printf ("DW_OP_const2s: %ld", (long) svalue);
1101 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1102 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1105 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1106 printf ("DW_OP_const4s: %ld", (long) svalue);
1109 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1110 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1111 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1112 printf ("%lu", (unsigned long) uvalue);
1115 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1116 printf ("DW_OP_const8s: %ld ", (long) svalue);
1117 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1118 printf ("%ld", (long) svalue);
1121 printf ("DW_OP_constu: %s",
1122 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1126 printf ("DW_OP_consts: %s",
1127 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1131 printf ("DW_OP_dup");
1134 printf ("DW_OP_drop");
1137 printf ("DW_OP_over");
1140 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1141 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1144 printf ("DW_OP_swap");
1147 printf ("DW_OP_rot");
1150 printf ("DW_OP_xderef");
1153 printf ("DW_OP_abs");
1156 printf ("DW_OP_and");
1159 printf ("DW_OP_div");
1162 printf ("DW_OP_minus");
1165 printf ("DW_OP_mod");
1168 printf ("DW_OP_mul");
1171 printf ("DW_OP_neg");
1174 printf ("DW_OP_not");
1177 printf ("DW_OP_or");
1180 printf ("DW_OP_plus");
1182 case DW_OP_plus_uconst:
1183 printf ("DW_OP_plus_uconst: %s",
1184 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1188 printf ("DW_OP_shl");
1191 printf ("DW_OP_shr");
1194 printf ("DW_OP_shra");
1197 printf ("DW_OP_xor");
1200 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1201 printf ("DW_OP_bra: %ld", (long) svalue);
1204 printf ("DW_OP_eq");
1207 printf ("DW_OP_ge");
1210 printf ("DW_OP_gt");
1213 printf ("DW_OP_le");
1216 printf ("DW_OP_lt");
1219 printf ("DW_OP_ne");
1222 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1223 printf ("DW_OP_skip: %ld", (long) svalue);
1258 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1293 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1294 regname (op - DW_OP_reg0, 1));
1329 printf ("DW_OP_breg%d (%s): %s",
1331 regname (op - DW_OP_breg0, 1),
1332 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1337 uvalue = read_uleb128 (data, &bytes_read, end);
1339 printf ("DW_OP_regx: %s (%s)",
1340 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1343 need_frame_base = 1;
1344 printf ("DW_OP_fbreg: %s",
1345 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1349 uvalue = read_uleb128 (data, &bytes_read, end);
1351 printf ("DW_OP_bregx: %s (%s) %s",
1352 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1353 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1357 printf ("DW_OP_piece: %s",
1358 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1361 case DW_OP_deref_size:
1362 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1363 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1365 case DW_OP_xderef_size:
1366 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1367 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1370 printf ("DW_OP_nop");
1373 /* DWARF 3 extensions. */
1374 case DW_OP_push_object_address:
1375 printf ("DW_OP_push_object_address");
1378 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1379 this ought to be an 8-byte wide computation. */
1380 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1381 printf ("DW_OP_call2: <0x%s>",
1382 dwarf_vmatoa ("x", svalue + cu_offset));
1385 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1386 this ought to be an 8-byte wide computation. */
1387 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1388 printf ("DW_OP_call4: <0x%s>",
1389 dwarf_vmatoa ("x", svalue + cu_offset));
1391 case DW_OP_call_ref:
1392 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1393 this ought to be an 8-byte wide computation. */
1394 if (dwarf_version == -1)
1396 printf (_("(DW_OP_call_ref in frame info)"));
1397 /* No way to tell where the next op is, so just bail. */
1398 return need_frame_base;
1400 if (dwarf_version == 2)
1402 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1406 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1408 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1410 case DW_OP_form_tls_address:
1411 printf ("DW_OP_form_tls_address");
1413 case DW_OP_call_frame_cfa:
1414 printf ("DW_OP_call_frame_cfa");
1416 case DW_OP_bit_piece:
1417 printf ("DW_OP_bit_piece: ");
1418 printf (_("size: %s "),
1419 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1421 printf (_("offset: %s "),
1422 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1426 /* DWARF 4 extensions. */
1427 case DW_OP_stack_value:
1428 printf ("DW_OP_stack_value");
1431 case DW_OP_implicit_value:
1432 printf ("DW_OP_implicit_value");
1433 uvalue = read_uleb128 (data, &bytes_read, end);
1435 data = display_block (data, uvalue, end, ' ');
1438 /* GNU extensions. */
1439 case DW_OP_GNU_push_tls_address:
1440 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1442 case DW_OP_GNU_uninit:
1443 printf ("DW_OP_GNU_uninit");
1444 /* FIXME: Is there data associated with this OP ? */
1446 case DW_OP_GNU_encoded_addr:
1453 addr = get_encoded_value (&data, encoding, section, end);
1455 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1456 print_dwarf_vma (addr, pointer_size);
1459 case DW_OP_implicit_pointer:
1460 case DW_OP_GNU_implicit_pointer:
1461 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1462 this ought to be an 8-byte wide computation. */
1463 if (dwarf_version == -1)
1465 printf (_("(%s in frame info)"),
1466 (op == DW_OP_implicit_pointer
1467 ? "DW_OP_implicit_pointer"
1468 : "DW_OP_GNU_implicit_pointer"));
1469 /* No way to tell where the next op is, so just bail. */
1470 return need_frame_base;
1472 if (dwarf_version == 2)
1474 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1478 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1480 printf ("%s: <0x%s> %s",
1481 (op == DW_OP_implicit_pointer
1482 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1483 dwarf_vmatoa ("x", uvalue),
1484 dwarf_vmatoa ("d", read_sleb128 (data,
1485 &bytes_read, end)));
1488 case DW_OP_entry_value:
1489 case DW_OP_GNU_entry_value:
1490 uvalue = read_uleb128 (data, &bytes_read, end);
1492 /* PR 17531: file: 0cc9cd00. */
1493 if (uvalue > (dwarf_vma) (end - data))
1494 uvalue = end - data;
1495 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1496 : "DW_OP_GNU_entry_value"));
1497 if (decode_location_expression (data, pointer_size, offset_size,
1498 dwarf_version, uvalue,
1499 cu_offset, section))
1500 need_frame_base = 1;
1506 case DW_OP_const_type:
1507 case DW_OP_GNU_const_type:
1508 uvalue = read_uleb128 (data, &bytes_read, end);
1510 printf ("%s: <0x%s> ",
1511 (op == DW_OP_const_type ? "DW_OP_const_type"
1512 : "DW_OP_GNU_const_type"),
1513 dwarf_vmatoa ("x", cu_offset + uvalue));
1514 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1515 data = display_block (data, uvalue, end, ' ');
1517 case DW_OP_regval_type:
1518 case DW_OP_GNU_regval_type:
1519 uvalue = read_uleb128 (data, &bytes_read, end);
1521 printf ("%s: %s (%s)",
1522 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1523 : "DW_OP_GNU_regval_type"),
1524 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1525 uvalue = read_uleb128 (data, &bytes_read, end);
1527 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1529 case DW_OP_deref_type:
1530 case DW_OP_GNU_deref_type:
1531 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1533 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1534 : "DW_OP_GNU_deref_type"),
1536 uvalue = read_uleb128 (data, &bytes_read, end);
1538 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1541 case DW_OP_GNU_convert:
1542 uvalue = read_uleb128 (data, &bytes_read, end);
1544 printf ("%s <0x%s>",
1545 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1546 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1548 case DW_OP_reinterpret:
1549 case DW_OP_GNU_reinterpret:
1550 uvalue = read_uleb128 (data, &bytes_read, end);
1552 printf ("%s <0x%s>",
1553 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1554 : "DW_OP_GNU_reinterpret"),
1555 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1557 case DW_OP_GNU_parameter_ref:
1558 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1559 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1560 dwarf_vmatoa ("x", cu_offset + uvalue));
1562 case DW_OP_GNU_addr_index:
1563 uvalue = read_uleb128 (data, &bytes_read, end);
1565 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1567 case DW_OP_GNU_const_index:
1568 uvalue = read_uleb128 (data, &bytes_read, end);
1570 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1573 /* HP extensions. */
1574 case DW_OP_HP_is_value:
1575 printf ("DW_OP_HP_is_value");
1576 /* FIXME: Is there data associated with this OP ? */
1578 case DW_OP_HP_fltconst4:
1579 printf ("DW_OP_HP_fltconst4");
1580 /* FIXME: Is there data associated with this OP ? */
1582 case DW_OP_HP_fltconst8:
1583 printf ("DW_OP_HP_fltconst8");
1584 /* FIXME: Is there data associated with this OP ? */
1586 case DW_OP_HP_mod_range:
1587 printf ("DW_OP_HP_mod_range");
1588 /* FIXME: Is there data associated with this OP ? */
1590 case DW_OP_HP_unmod_range:
1591 printf ("DW_OP_HP_unmod_range");
1592 /* FIXME: Is there data associated with this OP ? */
1595 printf ("DW_OP_HP_tls");
1596 /* FIXME: Is there data associated with this OP ? */
1599 /* PGI (STMicroelectronics) extensions. */
1600 case DW_OP_PGI_omp_thread_num:
1601 /* Pushes the thread number for the current thread as it would be
1602 returned by the standard OpenMP library function:
1603 omp_get_thread_num(). The "current thread" is the thread for
1604 which the expression is being evaluated. */
1605 printf ("DW_OP_PGI_omp_thread_num");
1609 if (op >= DW_OP_lo_user
1610 && op <= DW_OP_hi_user)
1611 printf (_("(User defined location op 0x%x)"), op);
1613 printf (_("(Unknown location op 0x%x)"), op);
1614 /* No way to tell where the next op is, so just bail. */
1615 return need_frame_base;
1618 /* Separate the ops. */
1623 return need_frame_base;
1626 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1627 This is used for DWARF package files. */
1629 static struct cu_tu_set *
1630 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1632 struct cu_tu_set *p;
1634 unsigned int dw_sect;
1640 dw_sect = DW_SECT_TYPES;
1646 dw_sect = DW_SECT_INFO;
1650 if (p->section_offsets [dw_sect] == cu_offset)
1658 /* Add INC to HIGH_BITS:LOW_BITS. */
1660 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1662 dwarf_vma tmp = * low_bits;
1666 /* FIXME: There is probably a better way of handling this:
1668 We need to cope with dwarf_vma being a 32-bit or 64-bit
1669 type. Plus regardless of its size LOW_BITS is meant to
1670 only hold 32-bits, so if there is overflow or wrap around
1671 we must propagate into HIGH_BITS. */
1672 if (tmp < * low_bits)
1676 else if (sizeof (tmp) > 8
1687 fetch_alt_indirect_string (dwarf_vma offset)
1689 struct dwarf_section * section;
1692 if (! do_follow_links)
1695 if (separate_debug_file == NULL)
1696 return _("<following link not possible>");
1698 if (! load_debug_section (separate_debug_str, separate_debug_file))
1699 return _("<could not load separate string section>");
1701 section = &debug_displays [separate_debug_str].section;
1702 if (section->start == NULL)
1703 return _("<no .debug_str section>");
1705 if (offset >= section->size)
1707 warn (_("DW_FORM_GNU_strp_alt offset too big: %s\n"), dwarf_vmatoa ("x", offset));
1708 return _("<offset is too big>");
1711 ret = (const char *) (section->start + offset);
1712 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1713 NUL byte. Since our caller is expecting to receive a well formed C
1714 string we test for the lack of a terminating byte here. */
1715 if (strnlen ((const char *) ret, section->size - offset)
1716 == section->size - offset)
1717 return _("<no NUL byte at end of .debug_str section>");
1723 get_AT_name (unsigned long attribute)
1728 return "DW_AT value: 0";
1730 /* One value is shared by the MIPS and HP extensions: */
1731 if (attribute == DW_AT_MIPS_fde)
1732 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1734 name = get_DW_AT_name (attribute);
1738 static char buffer[100];
1740 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1748 static unsigned char *
1749 read_and_display_attr_value (unsigned long attribute,
1751 dwarf_signed_vma implicit_const,
1752 unsigned char * data,
1753 unsigned char * end,
1754 dwarf_vma cu_offset,
1755 dwarf_vma pointer_size,
1756 dwarf_vma offset_size,
1758 debug_info * debug_info_p,
1760 struct dwarf_section * section,
1761 struct cu_tu_set * this_set,
1764 dwarf_vma uvalue = 0;
1765 unsigned char *block_start = NULL;
1766 unsigned char * orig_data = data;
1767 unsigned int bytes_read;
1769 if (data > end || (data == end && form != DW_FORM_flag_present))
1771 warn (_("Corrupt attribute\n"));
1780 case DW_FORM_ref_addr:
1781 if (dwarf_version == 2)
1782 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1783 else if (dwarf_version == 3 || dwarf_version == 4)
1784 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1786 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1791 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1795 case DW_FORM_line_strp:
1796 case DW_FORM_sec_offset:
1797 case DW_FORM_GNU_ref_alt:
1798 case DW_FORM_GNU_strp_alt:
1799 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1802 case DW_FORM_flag_present:
1809 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1814 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1819 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1823 uvalue = read_sleb128 (data, & bytes_read, end);
1827 case DW_FORM_GNU_str_index:
1828 uvalue = read_uleb128 (data, & bytes_read, end);
1832 case DW_FORM_ref_udata:
1834 uvalue = read_uleb128 (data, & bytes_read, end);
1838 case DW_FORM_indirect:
1839 form = read_uleb128 (data, & bytes_read, end);
1842 printf ("%c%s", delimiter, get_FORM_name (form));
1843 if (form == DW_FORM_implicit_const)
1845 implicit_const = read_sleb128 (data, & bytes_read, end);
1848 return read_and_display_attr_value (attribute, form, implicit_const, data,
1849 end, cu_offset, pointer_size,
1850 offset_size, dwarf_version,
1851 debug_info_p, do_loc,
1852 section, this_set, delimiter);
1853 case DW_FORM_GNU_addr_index:
1854 uvalue = read_uleb128 (data, & bytes_read, end);
1861 case DW_FORM_ref_addr:
1863 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1866 case DW_FORM_GNU_ref_alt:
1868 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1869 /* FIXME: Follow the reference... */
1875 case DW_FORM_ref_udata:
1877 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1882 case DW_FORM_sec_offset:
1884 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1887 case DW_FORM_flag_present:
1894 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1897 case DW_FORM_implicit_const:
1899 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1906 dwarf_vma high_bits;
1910 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1912 if (form == DW_FORM_ref8)
1913 add64 (& high_bits, & utmp, cu_offset);
1914 printf ("%c0x%s", delimiter,
1915 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1918 if ((do_loc || do_debug_loc || do_debug_ranges)
1919 && num_debug_info_entries == 0)
1921 if (sizeof (uvalue) == 8)
1922 SAFE_BYTE_GET (uvalue, data, 8, end);
1924 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1930 case DW_FORM_data16:
1933 dwarf_vma left_high_bits, left_low_bits;
1934 dwarf_vma right_high_bits, right_low_bits;
1936 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1937 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1938 if (byte_get == byte_get_little_endian)
1941 left_high_bits ^= right_high_bits;
1942 right_high_bits ^= left_high_bits;
1943 left_high_bits ^= right_high_bits;
1944 left_low_bits ^= right_low_bits;
1945 right_low_bits ^= left_low_bits;
1946 left_low_bits ^= right_low_bits;
1948 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1949 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1950 left_high_bits, left_low_bits, right_high_bits,
1956 case DW_FORM_string:
1958 printf ("%c%.*s", delimiter, (int) (end - data), data);
1959 data += strnlen ((char *) data, end - data) + 1;
1963 case DW_FORM_exprloc:
1964 uvalue = read_uleb128 (data, & bytes_read, end);
1965 block_start = data + bytes_read;
1966 if (block_start >= end)
1968 warn (_("Block ends prematurely\n"));
1972 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1973 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1974 block_start + uvalue here. */
1975 data = block_start + uvalue;
1976 /* PR 17512: file: 008-103549-0.001:0.1. */
1977 if (block_start + uvalue > end || data < block_start)
1979 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1980 uvalue = end - block_start;
1983 data = block_start + uvalue;
1985 data = display_block (block_start, uvalue, end, delimiter);
1988 case DW_FORM_block1:
1989 SAFE_BYTE_GET (uvalue, data, 1, end);
1990 block_start = data + 1;
1991 if (block_start >= end)
1993 warn (_("Block ends prematurely\n"));
1997 data = block_start + uvalue;
1998 if (block_start + uvalue > end || data < block_start)
2000 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
2001 uvalue = end - block_start;
2004 data = block_start + uvalue;
2006 data = display_block (block_start, uvalue, end, delimiter);
2009 case DW_FORM_block2:
2010 SAFE_BYTE_GET (uvalue, data, 2, end);
2011 block_start = data + 2;
2012 if (block_start >= end)
2014 warn (_("Block ends prematurely\n"));
2018 data = block_start + uvalue;
2019 if (block_start + uvalue > end || data < block_start)
2021 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
2022 uvalue = end - block_start;
2025 data = block_start + uvalue;
2027 data = display_block (block_start, uvalue, end, delimiter);
2030 case DW_FORM_block4:
2031 SAFE_BYTE_GET (uvalue, data, 4, end);
2032 block_start = data + 4;
2033 /* PR 17512: file: 3371-3907-0.004. */
2034 if (block_start >= end)
2036 warn (_("Block ends prematurely\n"));
2040 data = block_start + uvalue;
2041 if (block_start + uvalue > end
2042 /* PR 17531: file: 5b5f0592. */
2043 || data < block_start)
2045 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
2046 uvalue = end - block_start;
2049 data = block_start + uvalue;
2051 data = display_block (block_start, uvalue, end, delimiter);
2056 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
2057 dwarf_vmatoa ("x", uvalue),
2058 fetch_indirect_string (uvalue));
2061 case DW_FORM_line_strp:
2063 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
2064 dwarf_vmatoa ("x", uvalue),
2065 fetch_indirect_line_string (uvalue));
2068 case DW_FORM_GNU_str_index:
2071 const char * suffix = strrchr (section->name, '.');
2072 bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE;
2074 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
2075 dwarf_vmatoa ("x", uvalue),
2076 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
2080 case DW_FORM_GNU_strp_alt:
2083 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
2084 dwarf_vmatoa ("x", uvalue),
2085 fetch_alt_indirect_string (uvalue));
2089 case DW_FORM_indirect:
2090 /* Handled above. */
2093 case DW_FORM_ref_sig8:
2096 dwarf_vma high_bits;
2099 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
2100 printf ("%csignature: 0x%s", delimiter,
2101 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2106 case DW_FORM_GNU_addr_index:
2108 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
2109 dwarf_vmatoa ("x", uvalue),
2110 fetch_indexed_value (uvalue * pointer_size, pointer_size));
2114 warn (_("Unrecognized form: %lu\n"), form);
2118 if ((do_loc || do_debug_loc || do_debug_ranges)
2119 && num_debug_info_entries == 0
2120 && debug_info_p != NULL)
2124 case DW_AT_frame_base:
2125 have_frame_base = 1;
2127 case DW_AT_location:
2128 case DW_AT_GNU_locviews:
2129 case DW_AT_string_length:
2130 case DW_AT_return_addr:
2131 case DW_AT_data_member_location:
2132 case DW_AT_vtable_elem_location:
2134 case DW_AT_static_link:
2135 case DW_AT_use_location:
2136 case DW_AT_call_value:
2137 case DW_AT_GNU_call_site_value:
2138 case DW_AT_call_data_value:
2139 case DW_AT_GNU_call_site_data_value:
2140 case DW_AT_call_target:
2141 case DW_AT_GNU_call_site_target:
2142 case DW_AT_call_target_clobbered:
2143 case DW_AT_GNU_call_site_target_clobbered:
2144 if ((dwarf_version < 4
2145 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2146 || form == DW_FORM_sec_offset)
2148 /* Process location list. */
2149 unsigned int lmax = debug_info_p->max_loc_offsets;
2150 unsigned int num = debug_info_p->num_loc_offsets;
2152 if (lmax == 0 || num >= lmax)
2155 debug_info_p->loc_offsets = (dwarf_vma *)
2156 xcrealloc (debug_info_p->loc_offsets,
2157 lmax, sizeof (*debug_info_p->loc_offsets));
2158 debug_info_p->loc_views = (dwarf_vma *)
2159 xcrealloc (debug_info_p->loc_views,
2160 lmax, sizeof (*debug_info_p->loc_views));
2161 debug_info_p->have_frame_base = (int *)
2162 xcrealloc (debug_info_p->have_frame_base,
2163 lmax, sizeof (*debug_info_p->have_frame_base));
2164 debug_info_p->max_loc_offsets = lmax;
2166 if (this_set != NULL)
2167 uvalue += this_set->section_offsets [DW_SECT_LOC];
2168 debug_info_p->have_frame_base [num] = have_frame_base;
2169 if (attribute != DW_AT_GNU_locviews)
2171 debug_info_p->loc_offsets [num] = uvalue;
2172 debug_info_p->num_loc_offsets++;
2173 assert (debug_info_p->num_loc_offsets
2174 - debug_info_p->num_loc_views <= 1);
2178 assert (debug_info_p->num_loc_views <= num);
2179 num = debug_info_p->num_loc_views;
2180 debug_info_p->loc_views [num] = uvalue;
2181 debug_info_p->num_loc_views++;
2182 assert (debug_info_p->num_loc_views
2183 - debug_info_p->num_loc_offsets <= 1);
2189 if (need_base_address)
2190 debug_info_p->base_address = uvalue;
2193 case DW_AT_GNU_addr_base:
2194 debug_info_p->addr_base = uvalue;
2197 case DW_AT_GNU_ranges_base:
2198 debug_info_p->ranges_base = uvalue;
2202 if ((dwarf_version < 4
2203 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2204 || form == DW_FORM_sec_offset)
2206 /* Process range list. */
2207 unsigned int lmax = debug_info_p->max_range_lists;
2208 unsigned int num = debug_info_p->num_range_lists;
2210 if (lmax == 0 || num >= lmax)
2213 debug_info_p->range_lists = (dwarf_vma *)
2214 xcrealloc (debug_info_p->range_lists,
2215 lmax, sizeof (*debug_info_p->range_lists));
2216 debug_info_p->max_range_lists = lmax;
2218 debug_info_p->range_lists [num] = uvalue;
2219 debug_info_p->num_range_lists++;
2223 case DW_AT_GNU_dwo_name:
2224 case DW_AT_dwo_name:
2229 dwo_name = (const char *) fetch_indirect_string (uvalue);
2231 case DW_FORM_GNU_str_index:
2232 dwo_name = fetch_indexed_string (uvalue, this_set, offset_size, FALSE);
2234 case DW_FORM_string:
2235 dwo_name = (const char *) orig_data;
2238 warn (_("Unsupported form (%s) for attribute %s\n"),
2239 get_FORM_name (form), get_AT_name (attribute));
2240 dwo_name = _("<unknown>");
2245 case DW_AT_comp_dir:
2246 /* FIXME: Also extract a build-id in a CU/TU. */
2251 dwo_dir = (const char *) fetch_indirect_string (uvalue);
2253 case DW_FORM_line_strp:
2254 dwo_dir = (const char *) fetch_indirect_line_string (uvalue);
2256 case DW_FORM_GNU_str_index:
2257 dwo_dir = fetch_indexed_string (uvalue, this_set, offset_size, FALSE);
2259 case DW_FORM_string:
2260 dwo_dir = (const char *) orig_data;
2263 warn (_("Unsupported form (%s) for attribute %s\n"),
2264 get_FORM_name (form), get_AT_name (attribute));
2265 dwo_dir = _("<unknown>");
2270 case DW_AT_GNU_dwo_id:
2279 warn (_("Unsupported form (%s) for attribute %s\n"),
2280 get_FORM_name (form), get_AT_name (attribute));
2291 if (do_loc || attribute == 0)
2294 /* For some attributes we can display further information. */
2301 case DW_INL_not_inlined:
2302 printf (_("(not inlined)"));
2304 case DW_INL_inlined:
2305 printf (_("(inlined)"));
2307 case DW_INL_declared_not_inlined:
2308 printf (_("(declared as inline but ignored)"));
2310 case DW_INL_declared_inlined:
2311 printf (_("(declared as inline and inlined)"));
2314 printf (_(" (Unknown inline attribute value: %s)"),
2315 dwarf_vmatoa ("x", uvalue));
2320 case DW_AT_language:
2324 /* Ordered by the numeric value of these constants. */
2325 case DW_LANG_C89: printf ("(ANSI C)"); break;
2326 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2327 case DW_LANG_Ada83: printf ("(Ada)"); break;
2328 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2329 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2330 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2331 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2332 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2333 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2334 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2335 /* DWARF 2.1 values. */
2336 case DW_LANG_Java: printf ("(Java)"); break;
2337 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2338 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2339 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2340 /* DWARF 3 values. */
2341 case DW_LANG_PLI: printf ("(PLI)"); break;
2342 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2343 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2344 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2345 case DW_LANG_D: printf ("(D)"); break;
2346 /* DWARF 4 values. */
2347 case DW_LANG_Python: printf ("(Python)"); break;
2348 /* DWARF 5 values. */
2349 case DW_LANG_Go: printf ("(Go)"); break;
2350 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2351 case DW_LANG_C11: printf ("(C11)"); break;
2352 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2353 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2354 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2355 /* MIPS extension. */
2356 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2357 /* UPC extension. */
2358 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2360 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2361 printf (_("(implementation defined: %s)"),
2362 dwarf_vmatoa ("x", uvalue));
2364 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2369 case DW_AT_encoding:
2373 case DW_ATE_void: printf ("(void)"); break;
2374 case DW_ATE_address: printf ("(machine address)"); break;
2375 case DW_ATE_boolean: printf ("(boolean)"); break;
2376 case DW_ATE_complex_float: printf ("(complex float)"); break;
2377 case DW_ATE_float: printf ("(float)"); break;
2378 case DW_ATE_signed: printf ("(signed)"); break;
2379 case DW_ATE_signed_char: printf ("(signed char)"); break;
2380 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2381 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2382 /* DWARF 2.1 values: */
2383 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2384 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2385 /* DWARF 3 values: */
2386 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2387 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2388 case DW_ATE_edited: printf ("(edited)"); break;
2389 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2390 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2391 /* DWARF 4 values: */
2392 case DW_ATE_UTF: printf ("(unicode string)"); break;
2393 /* DWARF 5 values: */
2394 case DW_ATE_UCS: printf ("(UCS)"); break;
2395 case DW_ATE_ASCII: printf ("(ASCII)"); break;
2397 /* HP extensions: */
2398 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2399 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2400 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2401 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2402 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2403 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2404 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2407 if (uvalue >= DW_ATE_lo_user
2408 && uvalue <= DW_ATE_hi_user)
2409 printf (_("(user defined type)"));
2411 printf (_("(unknown type)"));
2416 case DW_AT_accessibility:
2420 case DW_ACCESS_public: printf ("(public)"); break;
2421 case DW_ACCESS_protected: printf ("(protected)"); break;
2422 case DW_ACCESS_private: printf ("(private)"); break;
2424 printf (_("(unknown accessibility)"));
2429 case DW_AT_visibility:
2433 case DW_VIS_local: printf ("(local)"); break;
2434 case DW_VIS_exported: printf ("(exported)"); break;
2435 case DW_VIS_qualified: printf ("(qualified)"); break;
2436 default: printf (_("(unknown visibility)")); break;
2440 case DW_AT_endianity:
2444 case DW_END_default: printf ("(default)"); break;
2445 case DW_END_big: printf ("(big)"); break;
2446 case DW_END_little: printf ("(little)"); break;
2448 if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
2449 printf (_("(user specified)"));
2451 printf (_("(unknown endianity)"));
2456 case DW_AT_virtuality:
2460 case DW_VIRTUALITY_none: printf ("(none)"); break;
2461 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2462 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2463 default: printf (_("(unknown virtuality)")); break;
2467 case DW_AT_identifier_case:
2471 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2472 case DW_ID_up_case: printf ("(up_case)"); break;
2473 case DW_ID_down_case: printf ("(down_case)"); break;
2474 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2475 default: printf (_("(unknown case)")); break;
2479 case DW_AT_calling_convention:
2483 case DW_CC_normal: printf ("(normal)"); break;
2484 case DW_CC_program: printf ("(program)"); break;
2485 case DW_CC_nocall: printf ("(nocall)"); break;
2486 case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
2487 case DW_CC_pass_by_value: printf ("(pass by value)"); break;
2488 case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
2489 case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break;
2491 if (uvalue >= DW_CC_lo_user
2492 && uvalue <= DW_CC_hi_user)
2493 printf (_("(user defined)"));
2495 printf (_("(unknown convention)"));
2499 case DW_AT_ordering:
2504 case -1: printf (_("(undefined)")); break;
2505 case 0: printf ("(row major)"); break;
2506 case 1: printf ("(column major)"); break;
2510 case DW_AT_decimal_sign:
2514 case DW_DS_unsigned: printf (_("(unsigned)")); break;
2515 case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
2516 case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
2517 case DW_DS_leading_separate: printf (_("(leading separate)")); break;
2518 case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
2519 default: printf (_("(unrecognised)")); break;
2523 case DW_AT_defaulted:
2527 case DW_DEFAULTED_no: printf (_("(no)")); break;
2528 case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
2529 case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
2530 default: printf (_("(unrecognised)")); break;
2534 case DW_AT_discr_list:
2538 case DW_DSC_label: printf (_("(label)")); break;
2539 case DW_DSC_range: printf (_("(range)")); break;
2540 default: printf (_("(unrecognised)")); break;
2544 case DW_AT_frame_base:
2545 have_frame_base = 1;
2547 case DW_AT_location:
2548 case DW_AT_string_length:
2549 case DW_AT_return_addr:
2550 case DW_AT_data_member_location:
2551 case DW_AT_vtable_elem_location:
2553 case DW_AT_static_link:
2554 case DW_AT_use_location:
2555 case DW_AT_call_value:
2556 case DW_AT_GNU_call_site_value:
2557 case DW_AT_call_data_value:
2558 case DW_AT_GNU_call_site_data_value:
2559 case DW_AT_call_target:
2560 case DW_AT_GNU_call_site_target:
2561 case DW_AT_call_target_clobbered:
2562 case DW_AT_GNU_call_site_target_clobbered:
2563 if ((dwarf_version < 4
2564 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2565 || form == DW_FORM_sec_offset)
2566 printf (_(" (location list)"));
2568 case DW_AT_allocated:
2569 case DW_AT_associated:
2570 case DW_AT_data_location:
2572 case DW_AT_upper_bound:
2573 case DW_AT_lower_bound:
2576 int need_frame_base;
2579 need_frame_base = decode_location_expression (block_start,
2584 cu_offset, section);
2586 if (need_frame_base && !have_frame_base)
2587 printf (_(" [without DW_AT_frame_base]"));
2591 case DW_AT_data_bit_offset:
2592 case DW_AT_byte_size:
2593 case DW_AT_bit_size:
2594 case DW_AT_string_length_byte_size:
2595 case DW_AT_string_length_bit_size:
2596 case DW_AT_bit_stride:
2597 if (form == DW_FORM_exprloc)
2600 (void) decode_location_expression (block_start, pointer_size,
2601 offset_size, dwarf_version,
2602 uvalue, cu_offset, section);
2609 if (form == DW_FORM_ref_sig8
2610 || form == DW_FORM_GNU_ref_alt)
2613 if (form == DW_FORM_ref1
2614 || form == DW_FORM_ref2
2615 || form == DW_FORM_ref4
2616 || form == DW_FORM_ref_udata)
2617 uvalue += cu_offset;
2619 if (uvalue >= section->size)
2620 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2621 dwarf_vmatoa ("x", uvalue),
2622 (unsigned long) (orig_data - section->start));
2625 unsigned long abbrev_number;
2626 abbrev_entry * entry;
2628 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2630 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2631 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2632 use different abbrev table, and we don't track .debug_info chunks
2634 if (form != DW_FORM_ref_addr)
2636 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2637 if (entry->entry == abbrev_number)
2640 printf (" (%s)", get_TAG_name (entry->tag));
2654 static unsigned char *
2655 read_and_display_attr (unsigned long attribute,
2657 dwarf_signed_vma implicit_const,
2658 unsigned char * data,
2659 unsigned char * end,
2660 dwarf_vma cu_offset,
2661 dwarf_vma pointer_size,
2662 dwarf_vma offset_size,
2664 debug_info * debug_info_p,
2666 struct dwarf_section * section,
2667 struct cu_tu_set * this_set)
2670 printf (" %-18s:", get_AT_name (attribute));
2671 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2672 cu_offset, pointer_size, offset_size,
2673 dwarf_version, debug_info_p,
2674 do_loc, section, this_set, ' ');
2680 /* Like load_debug_section, but if the ordinary call fails, and we are
2681 following debug links, and we have been able to load a separate debug
2682 info file, then attempt to load the requested section from the separate
2686 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
2689 if (load_debug_section (sec_enum, data))
2691 if (data == separate_debug_file)
2692 debug_displays[sec_enum].section.filename = separate_debug_filename;
2694 /* FIXME: We should check to see if there is a separate debug info file
2695 that also contains this section, and if so, issue a warning. */
2699 if (do_follow_links && separate_debug_file != NULL)
2700 if (load_debug_section (sec_enum, separate_debug_file))
2702 debug_displays[sec_enum].section.filename = separate_debug_filename;
2710 introduce (struct dwarf_section * section, bfd_boolean raw)
2714 if (do_follow_links && section->filename)
2715 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
2716 section->name, section->filename);
2718 printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
2722 if (do_follow_links && section->filename)
2723 printf (_("Contents of the %s section (loaded from %s):\n\n"),
2724 section->name, section->filename);
2726 printf (_("Contents of the %s section:\n\n"), section->name);
2730 /* Process the contents of a .debug_info section.
2731 If do_loc is TRUE then we are scanning for location lists and dwo tags
2732 and we do not want to display anything to the user.
2733 If do_types is TRUE, we are processing a .debug_types section instead of
2734 a .debug_info section.
2735 The information displayed is restricted by the values in DWARF_START_DIE
2736 and DWARF_CUTOFF_LEVEL.
2737 Returns TRUE upon success. Otherwise an error or warning message is
2738 printed and FALSE is returned. */
2741 process_debug_info (struct dwarf_section * section,
2743 enum dwarf_section_display_enum abbrev_sec,
2745 bfd_boolean do_types)
2747 unsigned char *start = section->start;
2748 unsigned char *end = start + section->size;
2749 unsigned char *section_begin;
2751 unsigned int num_units = 0;
2753 if ((do_loc || do_debug_loc || do_debug_ranges)
2754 && num_debug_info_entries == 0
2759 /* First scan the section to get the number of comp units. */
2760 for (section_begin = start, num_units = 0; section_begin < end;
2763 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2764 will be the length. For a 64-bit DWARF section, it'll be
2765 the escape code 0xffffffff followed by an 8 byte length. */
2766 SAFE_BYTE_GET (length, section_begin, 4, end);
2768 if (length == 0xffffffff)
2770 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2771 section_begin += length + 12;
2773 else if (length >= 0xfffffff0 && length < 0xffffffff)
2775 warn (_("Reserved length value (0x%s) found in section %s\n"),
2776 dwarf_vmatoa ("x", length), section->name);
2780 section_begin += length + 4;
2782 /* Negative values are illegal, they may even cause infinite
2783 looping. This can happen if we can't accurately apply
2784 relocations to an object file, or if the file is corrupt. */
2785 if ((signed long) length <= 0 || section_begin < start)
2787 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2788 dwarf_vmatoa ("x", length), section->name);
2795 error (_("No comp units in %s section ?\n"), section->name);
2799 /* Then allocate an array to hold the information. */
2800 debug_information = (debug_info *) cmalloc (num_units,
2801 sizeof (* debug_information));
2802 if (debug_information == NULL)
2804 error (_("Not enough memory for a debug info array of %u entries\n"),
2806 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2810 /* PR 17531: file: 92ca3797.
2811 We cannot rely upon the debug_information array being initialised
2812 before it is used. A corrupt file could easily contain references
2813 to a unit for which information has not been made available. So
2814 we ensure that the array is zeroed here. */
2815 memset (debug_information, 0, num_units * sizeof (*debug_information));
2817 alloc_num_debug_info_entries = num_units;
2822 load_debug_section_with_follow (str, file);
2823 load_debug_section_with_follow (line_str, file);
2824 load_debug_section_with_follow (str_dwo, file);
2825 load_debug_section_with_follow (str_index, file);
2826 load_debug_section_with_follow (str_index_dwo, file);
2827 load_debug_section_with_follow (debug_addr, file);
2830 load_debug_section_with_follow (abbrev_sec, file);
2831 if (debug_displays [abbrev_sec].section.start == NULL)
2833 warn (_("Unable to locate %s section!\n"),
2834 debug_displays [abbrev_sec].section.uncompressed_name);
2838 if (!do_loc && dwarf_start_die == 0)
2839 introduce (section, FALSE);
2841 for (section_begin = start, unit = 0; start < end; unit++)
2843 DWARF2_Internal_CompUnit compunit;
2844 unsigned char *hdrptr;
2845 unsigned char *tags;
2846 int level, last_level, saved_level;
2847 dwarf_vma cu_offset;
2848 unsigned long sec_off;
2849 unsigned int offset_size;
2850 unsigned int initial_length_size;
2851 dwarf_vma signature_high = 0;
2852 dwarf_vma signature_low = 0;
2853 dwarf_vma type_offset = 0;
2854 struct cu_tu_set *this_set;
2855 dwarf_vma abbrev_base;
2860 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2862 if (compunit.cu_length == 0xffffffff)
2864 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2866 initial_length_size = 12;
2871 initial_length_size = 4;
2874 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2876 cu_offset = start - section_begin;
2878 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2880 if (compunit.cu_version < 5)
2882 compunit.cu_unit_type = DW_UT_compile;
2883 /* Initialize it due to a false compiler warning. */
2884 compunit.cu_pointer_size = -1;
2888 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2889 do_types = (compunit.cu_unit_type == DW_UT_type);
2891 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2894 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2896 if (this_set == NULL)
2899 abbrev_size = debug_displays [abbrev_sec].section.size;
2903 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2904 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2907 if (compunit.cu_version < 5)
2908 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2910 /* PR 17512: file: 001-108546-0.001:0.1. */
2911 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2913 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2914 compunit.cu_pointer_size, offset_size);
2915 compunit.cu_pointer_size = offset_size;
2920 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2922 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2925 if (dwarf_start_die > (cu_offset + compunit.cu_length
2926 + initial_length_size))
2928 start = section_begin + cu_offset + compunit.cu_length
2929 + initial_length_size;
2933 if ((do_loc || do_debug_loc || do_debug_ranges)
2934 && num_debug_info_entries == 0
2937 debug_information [unit].cu_offset = cu_offset;
2938 debug_information [unit].pointer_size
2939 = compunit.cu_pointer_size;
2940 debug_information [unit].offset_size = offset_size;
2941 debug_information [unit].dwarf_version = compunit.cu_version;
2942 debug_information [unit].base_address = 0;
2943 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2944 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2945 debug_information [unit].loc_offsets = NULL;
2946 debug_information [unit].have_frame_base = NULL;
2947 debug_information [unit].max_loc_offsets = 0;
2948 debug_information [unit].num_loc_offsets = 0;
2949 debug_information [unit].range_lists = NULL;
2950 debug_information [unit].max_range_lists= 0;
2951 debug_information [unit].num_range_lists = 0;
2954 if (!do_loc && dwarf_start_die == 0)
2956 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2957 dwarf_vmatoa ("x", cu_offset));
2958 printf (_(" Length: 0x%s (%s)\n"),
2959 dwarf_vmatoa ("x", compunit.cu_length),
2960 offset_size == 8 ? "64-bit" : "32-bit");
2961 printf (_(" Version: %d\n"), compunit.cu_version);
2962 printf (_(" Abbrev Offset: 0x%s\n"),
2963 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2964 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2969 printf (_(" Signature: 0x%s\n"),
2970 dwarf_vmatoa64 (signature_high, signature_low,
2971 buf, sizeof (buf)));
2972 printf (_(" Type Offset: 0x%s\n"),
2973 dwarf_vmatoa ("x", type_offset));
2975 if (this_set != NULL)
2977 dwarf_vma *offsets = this_set->section_offsets;
2978 size_t *sizes = this_set->section_sizes;
2980 printf (_(" Section contributions:\n"));
2981 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2982 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2983 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2984 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2985 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2986 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2987 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2988 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2989 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2990 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2991 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2992 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2996 sec_off = cu_offset + initial_length_size;
2997 if (sec_off + compunit.cu_length < sec_off
2998 || sec_off + compunit.cu_length > section->size)
3000 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3002 (unsigned long) cu_offset,
3003 dwarf_vmatoa ("x", compunit.cu_length));
3009 start += compunit.cu_length + initial_length_size;
3011 if (compunit.cu_version < 2 || compunit.cu_version > 5)
3013 warn (_("CU at offset %s contains corrupt or "
3014 "unsupported version number: %d.\n"),
3015 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
3019 if (compunit.cu_unit_type != DW_UT_compile
3020 && compunit.cu_unit_type != DW_UT_type)
3022 warn (_("CU at offset %s contains corrupt or "
3023 "unsupported unit type: %d.\n"),
3024 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
3030 /* Process the abbrevs used by this compilation unit. */
3031 if (compunit.cu_abbrev_offset >= abbrev_size)
3032 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3033 (unsigned long) compunit.cu_abbrev_offset,
3034 (unsigned long) abbrev_size);
3035 /* PR 17531: file:4bcd9ce9. */
3036 else if ((abbrev_base + abbrev_size)
3037 > debug_displays [abbrev_sec].section.size)
3038 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3039 (unsigned long) abbrev_base + abbrev_size,
3040 (unsigned long) debug_displays [abbrev_sec].section.size);
3042 process_abbrev_section
3043 (((unsigned char *) debug_displays [abbrev_sec].section.start
3044 + abbrev_base + compunit.cu_abbrev_offset),
3045 ((unsigned char *) debug_displays [abbrev_sec].section.start
3046 + abbrev_base + abbrev_size));
3051 while (tags < start)
3053 unsigned int bytes_read;
3054 unsigned long abbrev_number;
3055 unsigned long die_offset;
3056 abbrev_entry *entry;
3058 int do_printing = 1;
3060 die_offset = tags - section_begin;
3062 abbrev_number = read_uleb128 (tags, & bytes_read, start);
3065 /* A null DIE marks the end of a list of siblings or it may also be
3066 a section padding. */
3067 if (abbrev_number == 0)
3069 /* Check if it can be a section padding for the last CU. */
3070 if (level == 0 && start == end)
3074 for (chk = tags; chk < start; chk++)
3081 if (!do_loc && die_offset >= dwarf_start_die
3082 && (dwarf_cutoff_level == -1
3083 || level < dwarf_cutoff_level))
3084 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3090 static unsigned num_bogus_warns = 0;
3092 if (num_bogus_warns < 3)
3094 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3095 die_offset, section->name);
3097 if (num_bogus_warns == 3)
3098 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3101 if (dwarf_start_die != 0 && level < saved_level)
3108 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
3112 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
3113 saved_level = level;
3114 do_printing = (dwarf_cutoff_level == -1
3115 || level < dwarf_cutoff_level);
3117 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3118 level, die_offset, abbrev_number);
3119 else if (dwarf_cutoff_level == -1
3120 || last_level < dwarf_cutoff_level)
3121 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
3126 /* Scan through the abbreviation list until we reach the
3128 for (entry = first_abbrev;
3129 entry && entry->entry != abbrev_number;
3130 entry = entry->next)
3135 if (!do_loc && do_printing)
3140 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3141 die_offset, abbrev_number);
3145 if (!do_loc && do_printing)
3146 printf (" (%s)\n", get_TAG_name (entry->tag));
3151 need_base_address = 0;
3153 case DW_TAG_compile_unit:
3154 need_base_address = 1;
3155 need_dwo_info = do_loc;
3157 case DW_TAG_entry_point:
3158 case DW_TAG_subprogram:
3159 need_base_address = 0;
3160 /* Assuming that there is no DW_AT_frame_base. */
3161 have_frame_base = 0;
3165 debug_info *debug_info_p =
3166 (debug_information && unit < alloc_num_debug_info_entries)
3167 ? debug_information + unit : NULL;
3169 assert (!debug_info_p
3170 || (debug_info_p->num_loc_offsets
3171 == debug_info_p->num_loc_views));
3173 for (attr = entry->first_attr;
3174 attr && attr->attribute;
3177 if (! do_loc && do_printing)
3178 /* Show the offset from where the tag was extracted. */
3179 printf (" <%lx>", (unsigned long)(tags - section_begin));
3181 tags = read_and_display_attr (attr->attribute,
3183 attr->implicit_const,
3187 compunit.cu_pointer_size,
3189 compunit.cu_version,
3191 do_loc || ! do_printing,
3196 /* If a locview attribute appears before a location one,
3197 make sure we don't associate it with an earlier
3200 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
3203 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
3204 debug_info_p->num_loc_views++;
3205 assert (debug_info_p->num_loc_views
3206 == debug_info_p->num_loc_offsets);
3213 warn(_("DIE has locviews without loclist\n"));
3214 debug_info_p->num_loc_views--;
3221 if (entry->children)
3226 /* Set num_debug_info_entries here so that it can be used to check if
3227 we need to process .debug_loc and .debug_ranges sections. */
3228 if ((do_loc || do_debug_loc || do_debug_ranges)
3229 && num_debug_info_entries == 0
3232 if (num_units > alloc_num_debug_info_entries)
3233 num_debug_info_entries = alloc_num_debug_info_entries;
3235 num_debug_info_entries = num_units;
3244 /* Locate and scan the .debug_info section in the file and record the pointer
3245 sizes and offsets for the compilation units in it. Usually an executable
3246 will have just one pointer size, but this is not guaranteed, and so we try
3247 not to make any assumptions. Returns zero upon failure, or the number of
3248 compilation units upon success. */
3251 load_debug_info (void * file)
3253 /* If we have already tried and failed to load the .debug_info
3254 section then do not bother to repeat the task. */
3255 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3258 /* If we already have the information there is nothing else to do. */
3259 if (num_debug_info_entries > 0)
3260 return num_debug_info_entries;
3262 /* If this is a DWARF package file, load the CU and TU indexes. */
3263 (void) load_cu_tu_indexes (file);
3265 if (load_debug_section_with_follow (info, file)
3266 && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE))
3267 return num_debug_info_entries;
3269 if (load_debug_section_with_follow (info_dwo, file)
3270 && process_debug_info (&debug_displays [info_dwo].section, file,
3271 abbrev_dwo, TRUE, FALSE))
3272 return num_debug_info_entries;
3274 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
3278 /* Read a DWARF .debug_line section header starting at DATA.
3279 Upon success returns an updated DATA pointer and the LINFO
3280 structure and the END_OF_SEQUENCE pointer will be filled in.
3281 Otherwise returns NULL. */
3283 static unsigned char *
3284 read_debug_line_header (struct dwarf_section * section,
3285 unsigned char * data,
3286 unsigned char * end,
3287 DWARF2_Internal_LineInfo * linfo,
3288 unsigned char ** end_of_sequence)
3290 unsigned char *hdrptr;
3291 unsigned int initial_length_size;
3292 unsigned char address_size, segment_selector_size;
3294 /* Extract information from the Line Number Program Header.
3295 (section 6.2.4 in the Dwarf3 doc). */
3298 /* Get and check the length of the block. */
3299 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
3301 if (linfo->li_length == 0xffffffff)
3303 /* This section is 64-bit DWARF 3. */
3304 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
3305 linfo->li_offset_size = 8;
3306 initial_length_size = 12;
3310 linfo->li_offset_size = 4;
3311 initial_length_size = 4;
3314 if (linfo->li_length + initial_length_size > section->size)
3316 /* If the length field has a relocation against it, then we should
3317 not complain if it is inaccurate (and probably negative). This
3318 happens in object files when the .debug_line section is actually
3319 comprised of several different .debug_line.* sections, (some of
3320 which may be removed by linker garbage collection), and a relocation
3321 is used to compute the correct length once that is done. */
3322 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
3324 linfo->li_length = (end - data) - initial_length_size;
3328 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3329 (long) linfo->li_length);
3334 /* Get and check the version number. */
3335 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3337 if (linfo->li_version != 2
3338 && linfo->li_version != 3
3339 && linfo->li_version != 4
3340 && linfo->li_version != 5)
3342 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3343 "is currently supported.\n"));
3347 if (linfo->li_version >= 5)
3349 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3351 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3352 if (segment_selector_size != 0)
3354 warn (_("The %s section contains "
3355 "unsupported segment selector size: %d.\n"),
3356 section->name, segment_selector_size);
3361 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3362 linfo->li_offset_size, end);
3363 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3365 if (linfo->li_version >= 4)
3367 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3369 if (linfo->li_max_ops_per_insn == 0)
3371 warn (_("Invalid maximum operations per insn.\n"));
3376 linfo->li_max_ops_per_insn = 1;
3378 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3379 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3380 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3381 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3383 * end_of_sequence = data + linfo->li_length + initial_length_size;
3384 /* PR 17512: file:002-117414-0.004. */
3385 if (* end_of_sequence > end)
3387 warn (_("Line length %s extends beyond end of section\n"),
3388 dwarf_vmatoa ("u", linfo->li_length));
3389 * end_of_sequence = end;
3396 static unsigned char *
3397 display_formatted_table (unsigned char * data,
3398 unsigned char * start,
3399 unsigned char * end,
3400 const DWARF2_Internal_LineInfo * linfo,
3401 struct dwarf_section * section,
3404 unsigned char *format_start, format_count, *format, formati;
3405 dwarf_vma data_count, datai;
3406 unsigned int bytes_read, namepass, last_entry = 0;
3408 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3409 format_start = data;
3410 for (formati = 0; formati < format_count; formati++)
3412 read_uleb128 (data, & bytes_read, end);
3414 read_uleb128 (data, & bytes_read, end);
3418 warn (_("Corrupt %s format table entry\n"), what);
3423 data_count = read_uleb128 (data, & bytes_read, end);
3427 warn (_("Corrupt %s list\n"), what);
3431 if (data_count == 0)
3433 printf (_("\n The %s Table is empty.\n"), what);
3437 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3438 (long)(data - start));
3440 printf (_(" Entry"));
3441 /* Delay displaying name as the last entry for better screen layout. */
3442 for (namepass = 0; namepass < 2; namepass++)
3444 format = format_start;
3445 for (formati = 0; formati < format_count; formati++)
3447 dwarf_vma content_type;
3449 content_type = read_uleb128 (format, & bytes_read, end);
3450 format += bytes_read;
3451 if ((content_type == DW_LNCT_path) == (namepass == 1))
3452 switch (content_type)
3455 printf (_("\tName"));
3457 case DW_LNCT_directory_index:
3458 printf (_("\tDir"));
3460 case DW_LNCT_timestamp:
3461 printf (_("\tTime"));
3464 printf (_("\tSize"));
3467 printf (_("\tMD5"));
3470 printf (_("\t(Unknown format content type %s)"),
3471 dwarf_vmatoa ("u", content_type));
3473 read_uleb128 (format, & bytes_read, end);
3474 format += bytes_read;
3479 for (datai = 0; datai < data_count; datai++)
3481 unsigned char *datapass = data;
3483 printf (" %d", last_entry++);
3484 /* Delay displaying name as the last entry for better screen layout. */
3485 for (namepass = 0; namepass < 2; namepass++)
3487 format = format_start;
3489 for (formati = 0; formati < format_count; formati++)
3491 dwarf_vma content_type, form;
3493 content_type = read_uleb128 (format, & bytes_read, end);
3494 format += bytes_read;
3495 form = read_uleb128 (format, & bytes_read, end);
3496 format += bytes_read;
3497 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3498 linfo->li_offset_size,
3499 linfo->li_version, NULL,
3500 ((content_type == DW_LNCT_path) != (namepass == 1)),
3501 section, NULL, '\t');
3506 warn (_("Corrupt %s entries list\n"), what);
3515 display_debug_lines_raw (struct dwarf_section * section,
3516 unsigned char * data,
3517 unsigned char * end,
3520 unsigned char *start = section->start;
3521 int verbose_view = 0;
3523 introduce (section, TRUE);
3527 static DWARF2_Internal_LineInfo saved_linfo;
3528 DWARF2_Internal_LineInfo linfo;
3529 unsigned char *standard_opcodes;
3530 unsigned char *end_of_sequence;
3533 if (const_strneq (section->name, ".debug_line.")
3534 /* Note: the following does not apply to .debug_line.dwo sections.
3535 These are full debug_line sections. */
3536 && strcmp (section->name, ".debug_line.dwo") != 0)
3538 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3539 section containing just the Line Number Statements. They are
3540 created by the assembler and intended to be used alongside gcc's
3541 -ffunction-sections command line option. When the linker's
3542 garbage collection decides to discard a .text.<foo> section it
3543 can then also discard the line number information in .debug_line.<foo>.
3545 Since the section is a fragment it does not have the details
3546 needed to fill out a LineInfo structure, so instead we use the
3547 details from the last full debug_line section that we processed. */
3548 end_of_sequence = end;
3549 standard_opcodes = NULL;
3550 linfo = saved_linfo;
3551 /* PR 17531: file: 0522b371. */
3552 if (linfo.li_line_range == 0)
3554 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3557 reset_state_machine (linfo.li_default_is_stmt);
3561 unsigned char * hdrptr;
3563 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3564 & end_of_sequence)) == NULL)
3567 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3568 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3569 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3570 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3571 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3572 if (linfo.li_version >= 4)
3573 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3574 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3575 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3576 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3577 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3579 /* PR 17512: file: 1665-6428-0.004. */
3580 if (linfo.li_line_range == 0)
3582 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3583 linfo.li_line_range = 1;
3586 reset_state_machine (linfo.li_default_is_stmt);
3588 /* Display the contents of the Opcodes table. */
3589 standard_opcodes = hdrptr;
3591 /* PR 17512: file: 002-417945-0.004. */
3592 if (standard_opcodes + linfo.li_opcode_base >= end)
3594 warn (_("Line Base extends beyond end of section\n"));
3598 printf (_("\n Opcodes:\n"));
3600 for (i = 1; i < linfo.li_opcode_base; i++)
3601 printf (ngettext (" Opcode %d has %d arg\n",
3602 " Opcode %d has %d args\n",
3603 standard_opcodes[i - 1]),
3604 i, standard_opcodes[i - 1]);
3606 /* Display the contents of the Directory table. */
3607 data = standard_opcodes + linfo.li_opcode_base - 1;
3609 if (linfo.li_version >= 5)
3611 load_debug_section_with_follow (line_str, file);
3613 data = display_formatted_table (data, start, end, &linfo, section,
3615 data = display_formatted_table (data, start, end, &linfo, section,
3621 printf (_("\n The Directory Table is empty.\n"));
3624 unsigned int last_dir_entry = 0;
3626 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3627 (long)(data - start));
3629 while (data < end && *data != 0)
3631 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3633 data += strnlen ((char *) data, end - data) + 1;
3636 /* PR 17512: file: 002-132094-0.004. */
3637 if (data >= end - 1)
3641 /* Skip the NUL at the end of the table. */
3644 /* Display the contents of the File Name table. */
3646 printf (_("\n The File Name Table is empty.\n"));
3649 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3650 (long)(data - start));
3651 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3653 while (data < end && *data != 0)
3655 unsigned char *name;
3656 unsigned int bytes_read;
3658 printf (" %d\t", ++state_machine_regs.last_file_entry);
3660 data += strnlen ((char *) data, end - data) + 1;
3663 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3666 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3669 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3671 printf ("%.*s\n", (int)(end - name), name);
3675 warn (_("Corrupt file name table entry\n"));
3681 /* Skip the NUL at the end of the table. */
3686 saved_linfo = linfo;
3689 /* Now display the statements. */
3690 if (data >= end_of_sequence)
3691 printf (_(" No Line Number Statements.\n"));
3694 printf (_(" Line Number Statements:\n"));
3696 while (data < end_of_sequence)
3698 unsigned char op_code;
3699 dwarf_signed_vma adv;
3701 unsigned int bytes_read;
3703 printf (" [0x%08lx]", (long)(data - start));
3707 if (op_code >= linfo.li_opcode_base)
3709 op_code -= linfo.li_opcode_base;
3710 uladv = (op_code / linfo.li_line_range);
3711 if (linfo.li_max_ops_per_insn == 1)
3713 uladv *= linfo.li_min_insn_length;
3714 state_machine_regs.address += uladv;
3716 state_machine_regs.view = 0;
3717 printf (_(" Special opcode %d: "
3718 "advance Address by %s to 0x%s%s"),
3719 op_code, dwarf_vmatoa ("u", uladv),
3720 dwarf_vmatoa ("x", state_machine_regs.address),
3721 verbose_view && uladv
3722 ? _(" (reset view)") : "");
3727 = ((state_machine_regs.op_index + uladv)
3728 / linfo.li_max_ops_per_insn)
3729 * linfo.li_min_insn_length;
3731 state_machine_regs.address += addrdelta;
3732 state_machine_regs.op_index
3733 = (state_machine_regs.op_index + uladv)
3734 % linfo.li_max_ops_per_insn;
3736 state_machine_regs.view = 0;
3737 printf (_(" Special opcode %d: "
3738 "advance Address by %s to 0x%s[%d]%s"),
3739 op_code, dwarf_vmatoa ("u", uladv),
3740 dwarf_vmatoa ("x", state_machine_regs.address),
3741 state_machine_regs.op_index,
3742 verbose_view && addrdelta
3743 ? _(" (reset view)") : "");
3745 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3746 state_machine_regs.line += adv;
3747 printf (_(" and Line by %s to %d"),
3748 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3749 if (verbose_view || state_machine_regs.view)
3750 printf (_(" (view %u)\n"), state_machine_regs.view);
3753 state_machine_regs.view++;
3755 else switch (op_code)
3757 case DW_LNS_extended_op:
3758 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3762 printf (_(" Copy"));
3763 if (verbose_view || state_machine_regs.view)
3764 printf (_(" (view %u)\n"), state_machine_regs.view);
3767 state_machine_regs.view++;
3770 case DW_LNS_advance_pc:
3771 uladv = read_uleb128 (data, & bytes_read, end);
3773 if (linfo.li_max_ops_per_insn == 1)
3775 uladv *= linfo.li_min_insn_length;
3776 state_machine_regs.address += uladv;
3778 state_machine_regs.view = 0;
3779 printf (_(" Advance PC by %s to 0x%s%s\n"),
3780 dwarf_vmatoa ("u", uladv),
3781 dwarf_vmatoa ("x", state_machine_regs.address),
3782 verbose_view && uladv
3783 ? _(" (reset view)") : "");
3788 = ((state_machine_regs.op_index + uladv)
3789 / linfo.li_max_ops_per_insn)
3790 * linfo.li_min_insn_length;
3791 state_machine_regs.address
3793 state_machine_regs.op_index
3794 = (state_machine_regs.op_index + uladv)
3795 % linfo.li_max_ops_per_insn;
3797 state_machine_regs.view = 0;
3798 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3799 dwarf_vmatoa ("u", uladv),
3800 dwarf_vmatoa ("x", state_machine_regs.address),
3801 state_machine_regs.op_index,
3802 verbose_view && addrdelta
3803 ? _(" (reset view)") : "");
3807 case DW_LNS_advance_line:
3808 adv = read_sleb128 (data, & bytes_read, end);
3810 state_machine_regs.line += adv;
3811 printf (_(" Advance Line by %s to %d\n"),
3812 dwarf_vmatoa ("d", adv),
3813 state_machine_regs.line);
3816 case DW_LNS_set_file:
3817 adv = read_uleb128 (data, & bytes_read, end);
3819 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3820 dwarf_vmatoa ("d", adv));
3821 state_machine_regs.file = adv;
3824 case DW_LNS_set_column:
3825 uladv = read_uleb128 (data, & bytes_read, end);
3827 printf (_(" Set column to %s\n"),
3828 dwarf_vmatoa ("u", uladv));
3829 state_machine_regs.column = uladv;
3832 case DW_LNS_negate_stmt:
3833 adv = state_machine_regs.is_stmt;
3835 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3836 state_machine_regs.is_stmt = adv;
3839 case DW_LNS_set_basic_block:
3840 printf (_(" Set basic block\n"));
3841 state_machine_regs.basic_block = 1;
3844 case DW_LNS_const_add_pc:
3845 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3846 if (linfo.li_max_ops_per_insn)
3848 uladv *= linfo.li_min_insn_length;
3849 state_machine_regs.address += uladv;
3851 state_machine_regs.view = 0;
3852 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3853 dwarf_vmatoa ("u", uladv),
3854 dwarf_vmatoa ("x", state_machine_regs.address),
3855 verbose_view && uladv
3856 ? _(" (reset view)") : "");
3861 = ((state_machine_regs.op_index + uladv)
3862 / linfo.li_max_ops_per_insn)
3863 * linfo.li_min_insn_length;
3864 state_machine_regs.address
3866 state_machine_regs.op_index
3867 = (state_machine_regs.op_index + uladv)
3868 % linfo.li_max_ops_per_insn;
3870 state_machine_regs.view = 0;
3871 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3872 dwarf_vmatoa ("u", uladv),
3873 dwarf_vmatoa ("x", state_machine_regs.address),
3874 state_machine_regs.op_index,
3875 verbose_view && addrdelta
3876 ? _(" (reset view)") : "");
3880 case DW_LNS_fixed_advance_pc:
3881 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3882 state_machine_regs.address += uladv;
3883 state_machine_regs.op_index = 0;
3884 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3885 dwarf_vmatoa ("u", uladv),
3886 dwarf_vmatoa ("x", state_machine_regs.address));
3887 /* Do NOT reset view. */
3890 case DW_LNS_set_prologue_end:
3891 printf (_(" Set prologue_end to true\n"));
3894 case DW_LNS_set_epilogue_begin:
3895 printf (_(" Set epilogue_begin to true\n"));
3898 case DW_LNS_set_isa:
3899 uladv = read_uleb128 (data, & bytes_read, end);
3901 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3905 printf (_(" Unknown opcode %d with operands: "), op_code);
3907 if (standard_opcodes != NULL)
3908 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3910 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3912 i == 1 ? "" : ", ");
3928 unsigned char *name;
3929 unsigned int directory_index;
3930 unsigned int modification_date;
3931 unsigned int length;
3934 /* Output a decoded representation of the .debug_line section. */
3937 display_debug_lines_decoded (struct dwarf_section * section,
3938 unsigned char * data,
3939 unsigned char * end,
3942 static DWARF2_Internal_LineInfo saved_linfo;
3944 introduce (section, FALSE);
3948 /* This loop amounts to one iteration per compilation unit. */
3949 DWARF2_Internal_LineInfo linfo;
3950 unsigned char *standard_opcodes;
3951 unsigned char *end_of_sequence;
3953 File_Entry *file_table = NULL;
3954 unsigned int n_files = 0;
3955 unsigned char **directory_table = NULL;
3956 dwarf_vma n_directories = 0;
3958 if (const_strneq (section->name, ".debug_line.")
3959 /* Note: the following does not apply to .debug_line.dwo sections.
3960 These are full debug_line sections. */
3961 && strcmp (section->name, ".debug_line.dwo") != 0)
3963 /* See comment in display_debug_lines_raw(). */
3964 end_of_sequence = end;
3965 standard_opcodes = NULL;
3966 linfo = saved_linfo;
3967 /* PR 17531: file: 0522b371. */
3968 if (linfo.li_line_range == 0)
3970 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3973 reset_state_machine (linfo.li_default_is_stmt);
3977 unsigned char *hdrptr;
3979 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3980 & end_of_sequence)) == NULL)
3983 /* PR 17531: file: 0522b371. */
3984 if (linfo.li_line_range == 0)
3986 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3987 linfo.li_line_range = 1;
3989 reset_state_machine (linfo.li_default_is_stmt);
3991 /* Save a pointer to the contents of the Opcodes table. */
3992 standard_opcodes = hdrptr;
3994 /* Traverse the Directory table just to count entries. */
3995 data = standard_opcodes + linfo.li_opcode_base - 1;
3999 warn (_("opcode base of %d extends beyond end of section\n"),
4000 linfo.li_opcode_base);
4004 if (linfo.li_version >= 5)
4006 unsigned char *format_start, format_count, *format;
4007 dwarf_vma formati, entryi;
4008 unsigned int bytes_read;
4010 load_debug_section_with_follow (line_str, fileptr);
4012 /* Skip directories format. */
4013 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
4014 format_start = data;
4015 for (formati = 0; formati < format_count; formati++)
4017 read_uleb128 (data, & bytes_read, end);
4019 read_uleb128 (data, & bytes_read, end);
4023 n_directories = read_uleb128 (data, & bytes_read, end);
4027 warn (_("Corrupt directories list\n"));
4031 directory_table = (unsigned char **)
4032 xmalloc (n_directories * sizeof (unsigned char *));
4034 for (entryi = 0; entryi < n_directories; entryi++)
4036 unsigned char **pathp = &directory_table[entryi];
4038 format = format_start;
4039 for (formati = 0; formati < format_count; formati++)
4041 dwarf_vma content_type, form;
4044 content_type = read_uleb128 (format, & bytes_read, end);
4045 format += bytes_read;
4046 form = read_uleb128 (format, & bytes_read, end);
4047 format += bytes_read;
4050 warn (_("Corrupt directories list\n"));
4053 switch (content_type)
4058 case DW_FORM_string:
4061 case DW_FORM_line_strp:
4062 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4064 /* Remove const by the cast. */
4065 *pathp = (unsigned char *)
4066 fetch_indirect_line_string (uvalue);
4071 data = read_and_display_attr_value (0, form, 0, data, end,
4073 linfo.li_offset_size,
4080 warn (_("Corrupt directories list\n"));
4085 /* Skip files format. */
4086 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
4087 format_start = data;
4088 for (formati = 0; formati < format_count; formati++)
4090 read_uleb128 (data, & bytes_read, end);
4092 read_uleb128 (data, & bytes_read, end);
4096 n_files = read_uleb128 (data, & bytes_read, end);
4100 warn (_("Corrupt file name list\n"));
4104 file_table = (File_Entry *) xcalloc (1, n_files
4105 * sizeof (File_Entry));
4107 for (entryi = 0; entryi < n_files; entryi++)
4109 File_Entry *file = &file_table[entryi];
4111 format = format_start;
4112 for (formati = 0; formati < format_count; formati++)
4114 dwarf_vma content_type, form;
4117 content_type = read_uleb128 (format, & bytes_read, end);
4118 format += bytes_read;
4119 form = read_uleb128 (format, & bytes_read, end);
4120 format += bytes_read;
4123 warn (_("Corrupt file name list\n"));
4126 switch (content_type)
4131 case DW_FORM_string:
4134 case DW_FORM_line_strp:
4135 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4137 /* Remove const by the cast. */
4138 file->name = (unsigned char *)
4139 fetch_indirect_line_string (uvalue);
4143 case DW_LNCT_directory_index:
4147 SAFE_BYTE_GET (file->directory_index, data, 1,
4151 SAFE_BYTE_GET (file->directory_index, data, 2,
4155 file->directory_index = read_uleb128 (data, NULL,
4161 data = read_and_display_attr_value (0, form, 0, data, end,
4163 linfo.li_offset_size,
4170 warn (_("Corrupt file name list\n"));
4179 unsigned char *ptr_directory_table = data;
4181 while (data < end && *data != 0)
4183 data += strnlen ((char *) data, end - data) + 1;
4190 warn (_("directory table ends unexpectedly\n"));
4195 /* Go through the directory table again to save the directories. */
4196 directory_table = (unsigned char **)
4197 xmalloc (n_directories * sizeof (unsigned char *));
4200 while (*ptr_directory_table != 0)
4202 directory_table[i] = ptr_directory_table;
4203 ptr_directory_table += strnlen ((char *) ptr_directory_table,
4204 ptr_directory_table - end) + 1;
4208 /* Skip the NUL at the end of the table. */
4211 /* Traverse the File Name table just to count the entries. */
4212 if (data < end && *data != 0)
4214 unsigned char *ptr_file_name_table = data;
4216 while (data < end && *data != 0)
4218 unsigned int bytes_read;
4220 /* Skip Name, directory index, last modification time and length
4222 data += strnlen ((char *) data, end - data) + 1;
4223 read_uleb128 (data, & bytes_read, end);
4225 read_uleb128 (data, & bytes_read, end);
4227 read_uleb128 (data, & bytes_read, end);
4235 warn (_("file table ends unexpectedly\n"));
4240 /* Go through the file table again to save the strings. */
4241 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
4244 while (*ptr_file_name_table != 0)
4246 unsigned int bytes_read;
4248 file_table[i].name = ptr_file_name_table;
4249 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
4250 end - ptr_file_name_table) + 1;
4252 /* We are not interested in directory, time or size. */
4253 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
4255 ptr_file_name_table += bytes_read;
4256 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
4258 ptr_file_name_table += bytes_read;
4259 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
4260 ptr_file_name_table += bytes_read;
4266 /* Skip the NUL at the end of the table. */
4270 /* Print the Compilation Unit's name and a header. */
4271 if (file_table == NULL)
4273 else if (directory_table == NULL)
4274 printf (_("CU: %s:\n"), file_table[0].name);
4277 unsigned int ix = file_table[0].directory_index;
4278 const char *directory;
4283 else if (n_directories == 0)
4284 directory = _("<unknown>");
4285 else if (ix > n_directories)
4287 warn (_("directory index %u > number of directories %s\n"),
4288 ix, dwarf_vmatoa ("u", n_directories));
4289 directory = _("<corrupt>");
4292 directory = (char *) directory_table[ix - 1];
4294 if (do_wide || strlen (directory) < 76)
4295 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4297 printf ("%s:\n", file_table[0].name);
4300 printf (_("File name Line number Starting address View\n"));
4301 saved_linfo = linfo;
4304 /* This loop iterates through the Dwarf Line Number Program. */
4305 while (data < end_of_sequence)
4307 unsigned char op_code;
4310 unsigned long int uladv;
4311 unsigned int bytes_read;
4312 int is_special_opcode = 0;
4317 if (op_code >= linfo.li_opcode_base)
4319 op_code -= linfo.li_opcode_base;
4320 uladv = (op_code / linfo.li_line_range);
4321 if (linfo.li_max_ops_per_insn == 1)
4323 uladv *= linfo.li_min_insn_length;
4324 state_machine_regs.address += uladv;
4326 state_machine_regs.view = 0;
4331 = ((state_machine_regs.op_index + uladv)
4332 / linfo.li_max_ops_per_insn)
4333 * linfo.li_min_insn_length;
4334 state_machine_regs.address
4336 state_machine_regs.op_index
4337 = (state_machine_regs.op_index + uladv)
4338 % linfo.li_max_ops_per_insn;
4340 state_machine_regs.view = 0;
4343 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4344 state_machine_regs.line += adv;
4345 is_special_opcode = 1;
4346 /* Increment view after printing this row. */
4348 else switch (op_code)
4350 case DW_LNS_extended_op:
4352 unsigned int ext_op_code_len;
4353 unsigned char ext_op_code;
4354 unsigned char *op_code_data = data;
4356 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4358 op_code_data += bytes_read;
4360 if (ext_op_code_len == 0)
4362 warn (_("Badly formed extended line op encountered!\n"));
4365 ext_op_code_len += bytes_read;
4366 ext_op_code = *op_code_data++;
4370 switch (ext_op_code)
4372 case DW_LNE_end_sequence:
4373 /* Reset stuff after printing this row. */
4375 case DW_LNE_set_address:
4376 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
4378 ext_op_code_len - bytes_read - 1,
4380 state_machine_regs.op_index = 0;
4381 state_machine_regs.view = 0;
4383 case DW_LNE_define_file:
4385 file_table = (File_Entry *) xrealloc
4386 (file_table, (n_files + 1) * sizeof (File_Entry));
4388 ++state_machine_regs.last_file_entry;
4389 /* Source file name. */
4390 file_table[n_files].name = op_code_data;
4391 op_code_data += strlen ((char *) op_code_data) + 1;
4392 /* Directory index. */
4393 file_table[n_files].directory_index =
4394 read_uleb128 (op_code_data, & bytes_read,
4396 op_code_data += bytes_read;
4397 /* Last modification time. */
4398 file_table[n_files].modification_date =
4399 read_uleb128 (op_code_data, & bytes_read,
4401 op_code_data += bytes_read;
4403 file_table[n_files].length =
4404 read_uleb128 (op_code_data, & bytes_read,
4410 case DW_LNE_set_discriminator:
4411 case DW_LNE_HP_set_sequence:
4412 /* Simply ignored. */
4416 printf (_("UNKNOWN (%u): length %d\n"),
4417 ext_op_code, ext_op_code_len - bytes_read);
4420 data += ext_op_code_len;
4424 /* Increment view after printing this row. */
4427 case DW_LNS_advance_pc:
4428 uladv = read_uleb128 (data, & bytes_read, end);
4430 if (linfo.li_max_ops_per_insn == 1)
4432 uladv *= linfo.li_min_insn_length;
4433 state_machine_regs.address += uladv;
4435 state_machine_regs.view = 0;
4440 = ((state_machine_regs.op_index + uladv)
4441 / linfo.li_max_ops_per_insn)
4442 * linfo.li_min_insn_length;
4443 state_machine_regs.address
4445 state_machine_regs.op_index
4446 = (state_machine_regs.op_index + uladv)
4447 % linfo.li_max_ops_per_insn;
4449 state_machine_regs.view = 0;
4453 case DW_LNS_advance_line:
4454 adv = read_sleb128 (data, & bytes_read, end);
4456 state_machine_regs.line += adv;
4459 case DW_LNS_set_file:
4460 adv = read_uleb128 (data, & bytes_read, end);
4462 state_machine_regs.file = adv;
4465 unsigned file = state_machine_regs.file - 1;
4468 if (file_table == NULL || n_files == 0)
4469 printf (_("\n [Use file table entry %d]\n"), file);
4471 else if (file >= n_files)
4473 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4474 printf (_("\n <over large file table index %u>"), file);
4476 else if ((dir = file_table[file].directory_index) == 0)
4477 /* If directory index is 0, that means current directory. */
4478 printf ("\n./%s:[++]\n", file_table[file].name);
4479 else if (directory_table == NULL || n_directories == 0)
4480 printf (_("\n [Use file %s in directory table entry %d]\n"),
4481 file_table[file].name, dir);
4483 else if (dir > n_directories)
4485 warn (_("directory index %u > number of directories %s\n"),
4486 dir, dwarf_vmatoa ("u", n_directories));
4487 printf (_("\n <over large directory table entry %u>\n"), dir);
4490 printf ("\n%s/%s:\n",
4491 /* The directory index starts counting at 1. */
4492 directory_table[dir - 1], file_table[file].name);
4496 case DW_LNS_set_column:
4497 uladv = read_uleb128 (data, & bytes_read, end);
4499 state_machine_regs.column = uladv;
4502 case DW_LNS_negate_stmt:
4503 adv = state_machine_regs.is_stmt;
4505 state_machine_regs.is_stmt = adv;
4508 case DW_LNS_set_basic_block:
4509 state_machine_regs.basic_block = 1;
4512 case DW_LNS_const_add_pc:
4513 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4514 if (linfo.li_max_ops_per_insn == 1)
4516 uladv *= linfo.li_min_insn_length;
4517 state_machine_regs.address += uladv;
4519 state_machine_regs.view = 0;
4524 = ((state_machine_regs.op_index + uladv)
4525 / linfo.li_max_ops_per_insn)
4526 * linfo.li_min_insn_length;
4527 state_machine_regs.address
4529 state_machine_regs.op_index
4530 = (state_machine_regs.op_index + uladv)
4531 % linfo.li_max_ops_per_insn;
4533 state_machine_regs.view = 0;
4537 case DW_LNS_fixed_advance_pc:
4538 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4539 state_machine_regs.address += uladv;
4540 state_machine_regs.op_index = 0;
4541 /* Do NOT reset view. */
4544 case DW_LNS_set_prologue_end:
4547 case DW_LNS_set_epilogue_begin:
4550 case DW_LNS_set_isa:
4551 uladv = read_uleb128 (data, & bytes_read, end);
4553 printf (_(" Set ISA to %lu\n"), uladv);
4557 printf (_(" Unknown opcode %d with operands: "), op_code);
4559 if (standard_opcodes != NULL)
4560 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4562 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4564 i == 1 ? "" : ", ");
4571 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4572 to the DWARF address/line matrix. */
4573 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4574 || (xop == DW_LNS_copy))
4576 const unsigned int MAX_FILENAME_LENGTH = 35;
4578 char *newFileName = NULL;
4579 size_t fileNameLength;
4583 unsigned indx = state_machine_regs.file - 1;
4585 if (indx >= n_files)
4587 warn (_("corrupt file index %u encountered\n"), indx);
4588 fileName = _("<corrupt>");
4591 fileName = (char *) file_table[indx].name;
4594 fileName = _("<unknown>");
4596 fileNameLength = strlen (fileName);
4598 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4600 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4601 /* Truncate file name */
4602 strncpy (newFileName,
4603 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4604 MAX_FILENAME_LENGTH + 1);
4608 newFileName = (char *) xmalloc (fileNameLength + 1);
4609 strncpy (newFileName, fileName, fileNameLength + 1);
4612 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4614 if (linfo.li_max_ops_per_insn == 1)
4615 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
4616 newFileName, state_machine_regs.line,
4617 state_machine_regs.address);
4619 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
4620 newFileName, state_machine_regs.line,
4621 state_machine_regs.address,
4622 state_machine_regs.op_index);
4626 if (linfo.li_max_ops_per_insn == 1)
4627 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
4628 newFileName, state_machine_regs.line,
4629 state_machine_regs.address);
4631 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
4632 newFileName, state_machine_regs.line,
4633 state_machine_regs.address,
4634 state_machine_regs.op_index);
4637 if (state_machine_regs.view)
4638 printf (" %6u\n", state_machine_regs.view);
4641 state_machine_regs.view++;
4643 if (xop == -DW_LNE_end_sequence)
4645 reset_state_machine (linfo.li_default_is_stmt);
4660 if (directory_table)
4662 free (directory_table);
4663 directory_table = NULL;
4674 display_debug_lines (struct dwarf_section *section, void *file)
4676 unsigned char *data = section->start;
4677 unsigned char *end = data + section->size;
4679 int retValDecoded = 1;
4681 if (do_debug_lines == 0)
4682 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4684 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4685 retValRaw = display_debug_lines_raw (section, data, end, file);
4687 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4688 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4690 if (!retValRaw || !retValDecoded)
4697 find_debug_info_for_offset (unsigned long offset)
4701 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4704 for (i = 0; i < num_debug_info_entries; i++)
4705 if (debug_information[i].cu_offset == offset)
4706 return debug_information + i;
4712 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4714 /* See gdb/gdb-index.h. */
4715 static const char * const kinds[] =
4727 return _ (kinds[kind]);
4731 display_debug_pubnames_worker (struct dwarf_section *section,
4732 void *file ATTRIBUTE_UNUSED,
4735 DWARF2_Internal_PubNames names;
4736 unsigned char *start = section->start;
4737 unsigned char *end = start + section->size;
4739 /* It does not matter if this load fails,
4740 we test for that later on. */
4741 load_debug_info (file);
4743 introduce (section, FALSE);
4747 unsigned char *data;
4748 unsigned long sec_off;
4749 unsigned int offset_size, initial_length_size;
4751 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
4752 if (names.pn_length == 0xffffffff)
4754 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
4756 initial_length_size = 12;
4761 initial_length_size = 4;
4764 sec_off = start - section->start;
4765 if (sec_off + names.pn_length < sec_off
4766 || sec_off + names.pn_length > section->size)
4768 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4770 sec_off - initial_length_size,
4771 dwarf_vmatoa ("x", names.pn_length));
4776 start += names.pn_length;
4778 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4779 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4781 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4782 && num_debug_info_entries > 0
4783 && find_debug_info_for_offset (names.pn_offset) == NULL)
4784 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4785 (unsigned long) names.pn_offset, section->name);
4787 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4789 printf (_(" Length: %ld\n"),
4790 (long) names.pn_length);
4791 printf (_(" Version: %d\n"),
4793 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4794 (unsigned long) names.pn_offset);
4795 printf (_(" Size of area in .debug_info section: %ld\n"),
4796 (long) names.pn_size);
4798 if (names.pn_version != 2 && names.pn_version != 3)
4800 static int warned = 0;
4804 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4812 printf (_("\n Offset Kind Name\n"));
4814 printf (_("\n Offset\tName\n"));
4818 bfd_size_type maxprint;
4821 SAFE_BYTE_GET (offset, data, offset_size, end);
4826 data += offset_size;
4829 maxprint = (end - data) - 1;
4833 unsigned int kind_data;
4834 gdb_index_symbol_kind kind;
4835 const char *kind_name;
4838 SAFE_BYTE_GET (kind_data, data, 1, end);
4841 /* GCC computes the kind as the upper byte in the CU index
4842 word, and then right shifts it by the CU index size.
4843 Left shift KIND to where the gdb-index.h accessor macros
4845 kind_data <<= GDB_INDEX_CU_BITSIZE;
4846 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4847 kind_name = get_gdb_index_symbol_kind_name (kind);
4848 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4849 printf (" %-6lx %s,%-10s %.*s\n",
4850 (unsigned long) offset, is_static ? _("s") : _("g"),
4851 kind_name, (int) maxprint, data);
4854 printf (" %-6lx\t%.*s\n",
4855 (unsigned long) offset, (int) maxprint, data);
4857 data += strnlen ((char *) data, maxprint) + 1;
4868 display_debug_pubnames (struct dwarf_section *section, void *file)
4870 return display_debug_pubnames_worker (section, file, 0);
4874 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4876 return display_debug_pubnames_worker (section, file, 1);
4880 display_debug_macinfo (struct dwarf_section *section,
4881 void *file ATTRIBUTE_UNUSED)
4883 unsigned char *start = section->start;
4884 unsigned char *end = start + section->size;
4885 unsigned char *curr = start;
4886 unsigned int bytes_read;
4887 enum dwarf_macinfo_record_type op;
4889 introduce (section, FALSE);
4893 unsigned int lineno;
4894 const unsigned char *string;
4896 op = (enum dwarf_macinfo_record_type) *curr;
4901 case DW_MACINFO_start_file:
4903 unsigned int filenum;
4905 lineno = read_uleb128 (curr, & bytes_read, end);
4907 filenum = read_uleb128 (curr, & bytes_read, end);
4910 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4915 case DW_MACINFO_end_file:
4916 printf (_(" DW_MACINFO_end_file\n"));
4919 case DW_MACINFO_define:
4920 lineno = read_uleb128 (curr, & bytes_read, end);
4923 curr += strnlen ((char *) string, end - string) + 1;
4924 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4928 case DW_MACINFO_undef:
4929 lineno = read_uleb128 (curr, & bytes_read, end);
4932 curr += strnlen ((char *) string, end - string) + 1;
4933 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4937 case DW_MACINFO_vendor_ext:
4939 unsigned int constant;
4941 constant = read_uleb128 (curr, & bytes_read, end);
4944 curr += strnlen ((char *) string, end - string) + 1;
4945 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4955 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4956 filename and dirname corresponding to file name table entry with index
4957 FILEIDX. Return NULL on failure. */
4959 static unsigned char *
4960 get_line_filename_and_dirname (dwarf_vma line_offset,
4962 unsigned char **dir_name)
4964 struct dwarf_section *section = &debug_displays [line].section;
4965 unsigned char *hdrptr, *dirtable, *file_name;
4966 unsigned int offset_size, initial_length_size;
4967 unsigned int version, opcode_base, bytes_read;
4968 dwarf_vma length, diridx;
4969 const unsigned char * end;
4972 if (section->start == NULL
4973 || line_offset >= section->size
4977 hdrptr = section->start + line_offset;
4978 end = section->start + section->size;
4980 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4981 if (length == 0xffffffff)
4983 /* This section is 64-bit DWARF 3. */
4984 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4986 initial_length_size = 12;
4991 initial_length_size = 4;
4993 if (length + initial_length_size < length
4994 || length + initial_length_size > section->size)
4997 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4998 if (version != 2 && version != 3 && version != 4)
5000 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
5002 hdrptr++; /* Skip max_ops_per_insn. */
5003 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
5005 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
5006 if (opcode_base == 0)
5009 hdrptr += opcode_base - 1;
5014 /* Skip over dirname table. */
5015 while (*hdrptr != '\0')
5017 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5021 hdrptr++; /* Skip the NUL at the end of the table. */
5023 /* Now skip over preceding filename table entries. */
5024 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
5026 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5027 read_uleb128 (hdrptr, &bytes_read, end);
5028 hdrptr += bytes_read;
5029 read_uleb128 (hdrptr, &bytes_read, end);
5030 hdrptr += bytes_read;
5031 read_uleb128 (hdrptr, &bytes_read, end);
5032 hdrptr += bytes_read;
5034 if (hdrptr >= end || *hdrptr == '\0')
5038 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5041 diridx = read_uleb128 (hdrptr, &bytes_read, end);
5044 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
5045 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
5046 if (dirtable >= end || *dirtable == '\0')
5048 *dir_name = dirtable;
5053 display_debug_macro (struct dwarf_section *section,
5056 unsigned char *start = section->start;
5057 unsigned char *end = start + section->size;
5058 unsigned char *curr = start;
5059 unsigned char *extended_op_buf[256];
5060 unsigned int bytes_read;
5062 load_debug_section_with_follow (str, file);
5063 load_debug_section_with_follow (line, file);
5065 introduce (section, FALSE);
5069 unsigned int lineno, version, flags;
5070 unsigned int offset_size = 4;
5071 const unsigned char *string;
5072 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
5073 unsigned char **extended_ops = NULL;
5075 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
5076 if (version != 4 && version != 5)
5078 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5083 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
5086 printf (_(" Offset: 0x%lx\n"),
5087 (unsigned long) sec_offset);
5088 printf (_(" Version: %d\n"), version);
5089 printf (_(" Offset size: %d\n"), offset_size);
5092 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
5093 printf (_(" Offset into .debug_line: 0x%lx\n"),
5094 (unsigned long) line_offset);
5098 unsigned int i, count, op;
5101 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
5103 memset (extended_op_buf, 0, sizeof (extended_op_buf));
5104 extended_ops = extended_op_buf;
5107 printf (_(" Extension opcode arguments:\n"));
5108 for (i = 0; i < count; i++)
5110 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5111 extended_ops[op] = curr;
5112 nargs = read_uleb128 (curr, &bytes_read, end);
5115 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
5118 printf (_(" DW_MACRO_%02x arguments: "), op);
5119 for (n = 0; n < nargs; n++)
5123 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
5124 printf ("%s%s", get_FORM_name (form),
5125 n == nargs - 1 ? "\n" : ", ");
5135 case DW_FORM_block1:
5136 case DW_FORM_block2:
5137 case DW_FORM_block4:
5139 case DW_FORM_string:
5141 case DW_FORM_sec_offset:
5144 error (_("Invalid extension opcode form %s\n"),
5145 get_FORM_name (form));
5161 error (_(".debug_macro section not zero terminated\n"));
5165 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5171 case DW_MACRO_start_file:
5173 unsigned int filenum;
5174 unsigned char *file_name = NULL, *dir_name = NULL;
5176 lineno = read_uleb128 (curr, &bytes_read, end);
5178 filenum = read_uleb128 (curr, &bytes_read, end);
5181 if ((flags & 2) == 0)
5182 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5185 = get_line_filename_and_dirname (line_offset, filenum,
5187 if (file_name == NULL)
5188 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5191 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5193 dir_name != NULL ? (const char *) dir_name : "",
5194 dir_name != NULL ? "/" : "", file_name);
5198 case DW_MACRO_end_file:
5199 printf (_(" DW_MACRO_end_file\n"));
5202 case DW_MACRO_define:
5203 lineno = read_uleb128 (curr, &bytes_read, end);
5206 curr += strnlen ((char *) string, end - string) + 1;
5207 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5211 case DW_MACRO_undef:
5212 lineno = read_uleb128 (curr, &bytes_read, end);
5215 curr += strnlen ((char *) string, end - string) + 1;
5216 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5220 case DW_MACRO_define_strp:
5221 lineno = read_uleb128 (curr, &bytes_read, end);
5223 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5224 string = fetch_indirect_string (offset);
5225 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5229 case DW_MACRO_undef_strp:
5230 lineno = read_uleb128 (curr, &bytes_read, end);
5232 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5233 string = fetch_indirect_string (offset);
5234 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5238 case DW_MACRO_import:
5239 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5240 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5241 (unsigned long) offset);
5244 case DW_MACRO_define_sup:
5245 lineno = read_uleb128 (curr, &bytes_read, end);
5247 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5248 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5249 lineno, (unsigned long) offset);
5252 case DW_MACRO_undef_sup:
5253 lineno = read_uleb128 (curr, &bytes_read, end);
5255 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5256 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5257 lineno, (unsigned long) offset);
5260 case DW_MACRO_import_sup:
5261 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5262 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5263 (unsigned long) offset);
5267 if (extended_ops == NULL || extended_ops[op] == NULL)
5269 error (_(" Unknown macro opcode %02x seen\n"), op);
5274 /* Skip over unhandled opcodes. */
5276 unsigned char *desc = extended_ops[op];
5277 nargs = read_uleb128 (desc, &bytes_read, end);
5281 printf (_(" DW_MACRO_%02x\n"), op);
5284 printf (_(" DW_MACRO_%02x -"), op);
5285 for (n = 0; n < nargs; n++)
5289 /* DW_FORM_implicit_const is not expected here. */
5290 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
5292 = read_and_display_attr_value (0, val, 0,
5293 curr, end, 0, 0, offset_size,
5294 version, NULL, 0, NULL,
5312 display_debug_abbrev (struct dwarf_section *section,
5313 void *file ATTRIBUTE_UNUSED)
5315 abbrev_entry *entry;
5316 unsigned char *start = section->start;
5317 unsigned char *end = start + section->size;
5319 introduce (section, FALSE);
5323 unsigned char *last;
5328 start = process_abbrev_section (start, end);
5330 if (first_abbrev == NULL)
5333 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
5335 for (entry = first_abbrev; entry; entry = entry->next)
5339 printf (" %ld %s [%s]\n",
5341 get_TAG_name (entry->tag),
5342 entry->children ? _("has children") : _("no children"));
5344 for (attr = entry->first_attr; attr; attr = attr->next)
5346 printf (" %-18s %s",
5347 get_AT_name (attr->attribute),
5348 get_FORM_name (attr->form));
5349 if (attr->form == DW_FORM_implicit_const)
5350 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5362 /* Return true when ADDR is the maximum address, when addresses are
5363 POINTER_SIZE bytes long. */
5366 is_max_address (dwarf_vma addr, unsigned int pointer_size)
5368 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5369 return ((addr & mask) == mask);
5372 /* Display a view pair list starting at *VSTART_PTR and ending at
5373 VLISTEND within SECTION. */
5376 display_view_pair_list (struct dwarf_section *section,
5377 unsigned char **vstart_ptr,
5378 unsigned int debug_info_entry,
5379 unsigned char *vlistend)
5381 unsigned char *vstart = *vstart_ptr;
5382 unsigned char *section_end = section->start + section->size;
5383 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5385 if (vlistend < section_end)
5386 section_end = vlistend;
5390 while (vstart < section_end)
5392 dwarf_vma off = vstart - section->start;
5393 dwarf_vma vbegin, vend;
5395 unsigned int bytes_read;
5396 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5397 vstart += bytes_read;
5398 if (vstart == section_end)
5400 vstart -= bytes_read;
5404 vend = read_uleb128 (vstart, &bytes_read, section_end);
5405 vstart += bytes_read;
5407 printf (" %8.8lx ", (unsigned long) off);
5409 print_dwarf_view (vbegin, pointer_size, 1);
5410 print_dwarf_view (vend, pointer_size, 1);
5411 printf (_("location view pair\n"));
5415 *vstart_ptr = vstart;
5418 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5421 display_loc_list (struct dwarf_section *section,
5422 unsigned char **start_ptr,
5423 unsigned int debug_info_entry,
5425 dwarf_vma base_address,
5426 unsigned char **vstart_ptr,
5429 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5430 unsigned char *section_end = section->start + section->size;
5431 unsigned long cu_offset;
5432 unsigned int pointer_size;
5433 unsigned int offset_size;
5438 unsigned short length;
5439 int need_frame_base;
5441 if (debug_info_entry >= num_debug_info_entries)
5443 warn (_("No debug information available for loc lists of entry: %u\n"),
5448 cu_offset = debug_information [debug_info_entry].cu_offset;
5449 pointer_size = debug_information [debug_info_entry].pointer_size;
5450 offset_size = debug_information [debug_info_entry].offset_size;
5451 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5453 if (pointer_size < 2 || pointer_size > 8)
5455 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5456 pointer_size, debug_info_entry);
5462 dwarf_vma off = offset + (start - *start_ptr);
5463 dwarf_vma vbegin = vm1, vend = vm1;
5465 if (start + 2 * pointer_size > section_end)
5467 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5468 (unsigned long) offset);
5472 printf (" %8.8lx ", (unsigned long) off);
5474 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5475 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5477 if (begin == 0 && end == 0)
5479 /* PR 18374: In a object file we can have a location list that
5480 starts with a begin and end of 0 because there are relocations
5481 that need to be applied to the addresses. Actually applying
5482 the relocations now does not help as they will probably resolve
5483 to 0, since the object file has not been fully linked. Real
5484 end of list markers will not have any relocations against them. */
5485 if (! reloc_at (section, off)
5486 && ! reloc_at (section, off + pointer_size))
5488 printf (_("<End of list>\n"));
5493 /* Check base address specifiers. */
5494 if (is_max_address (begin, pointer_size)
5495 && !is_max_address (end, pointer_size))
5498 print_dwarf_vma (begin, pointer_size);
5499 print_dwarf_vma (end, pointer_size);
5500 printf (_("(base address)\n"));
5506 unsigned int bytes_read;
5508 off = offset + (vstart - *start_ptr);
5510 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5511 vstart += bytes_read;
5512 print_dwarf_view (vbegin, pointer_size, 1);
5514 vend = read_uleb128 (vstart, &bytes_read, section_end);
5515 vstart += bytes_read;
5516 print_dwarf_view (vend, pointer_size, 1);
5518 printf (_("views at %8.8lx for:\n %*s "),
5519 (unsigned long) off, 8, "");
5522 if (start + 2 > section_end)
5524 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5525 (unsigned long) offset);
5529 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5531 if (start + length > section_end)
5533 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5534 (unsigned long) offset);
5538 print_dwarf_vma (begin + base_address, pointer_size);
5539 print_dwarf_vma (end + base_address, pointer_size);
5542 need_frame_base = decode_location_expression (start,
5547 cu_offset, section);
5550 if (need_frame_base && !has_frame_base)
5551 printf (_(" [without DW_AT_frame_base]"));
5553 if (begin == end && vbegin == vend)
5554 fputs (_(" (start == end)"), stdout);
5555 else if (begin > end || (begin == end && vbegin > vend))
5556 fputs (_(" (start > end)"), stdout);
5564 *vstart_ptr = vstart;
5567 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5570 display_loclists_list (struct dwarf_section *section,
5571 unsigned char **start_ptr,
5572 unsigned int debug_info_entry,
5574 dwarf_vma base_address,
5575 unsigned char **vstart_ptr,
5578 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5579 unsigned char *section_end = section->start + section->size;
5580 unsigned long cu_offset;
5581 unsigned int pointer_size;
5582 unsigned int offset_size;
5584 unsigned int bytes_read;
5586 /* Initialize it due to a false compiler warning. */
5587 dwarf_vma begin = -1, vbegin = -1;
5588 dwarf_vma end = -1, vend = -1;
5590 int need_frame_base;
5592 if (debug_info_entry >= num_debug_info_entries)
5594 warn (_("No debug information available for "
5595 "loclists lists of entry: %u\n"),
5600 cu_offset = debug_information [debug_info_entry].cu_offset;
5601 pointer_size = debug_information [debug_info_entry].pointer_size;
5602 offset_size = debug_information [debug_info_entry].offset_size;
5603 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5605 if (pointer_size < 2 || pointer_size > 8)
5607 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5608 pointer_size, debug_info_entry);
5614 dwarf_vma off = offset + (start - *start_ptr);
5615 enum dwarf_location_list_entry_type llet;
5617 if (start + 1 > section_end)
5619 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5620 (unsigned long) offset);
5624 printf (" %8.8lx ", (unsigned long) off);
5626 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5628 if (vstart && llet == DW_LLE_offset_pair)
5630 off = offset + (vstart - *start_ptr);
5632 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5633 vstart += bytes_read;
5634 print_dwarf_view (vbegin, pointer_size, 1);
5636 vend = read_uleb128 (vstart, &bytes_read, section_end);
5637 vstart += bytes_read;
5638 print_dwarf_view (vend, pointer_size, 1);
5640 printf (_("views at %8.8lx for:\n %*s "),
5641 (unsigned long) off, 8, "");
5646 case DW_LLE_end_of_list:
5647 printf (_("<End of list>\n"));
5649 case DW_LLE_offset_pair:
5650 begin = read_uleb128 (start, &bytes_read, section_end);
5651 start += bytes_read;
5652 end = read_uleb128 (start, &bytes_read, section_end);
5653 start += bytes_read;
5655 case DW_LLE_base_address:
5656 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5658 print_dwarf_vma (base_address, pointer_size);
5659 printf (_("(base address)\n"));
5661 #ifdef DW_LLE_view_pair
5662 case DW_LLE_view_pair:
5664 printf (_("View pair entry in loclist with locviews attribute\n"));
5665 vbegin = read_uleb128 (start, &bytes_read, section_end);
5666 start += bytes_read;
5667 print_dwarf_view (vbegin, pointer_size, 1);
5669 vend = read_uleb128 (start, &bytes_read, section_end);
5670 start += bytes_read;
5671 print_dwarf_view (vend, pointer_size, 1);
5673 printf (_("views for:\n"));
5677 error (_("Invalid location list entry type %d\n"), llet);
5680 if (llet == DW_LLE_end_of_list)
5682 if (llet != DW_LLE_offset_pair)
5685 if (start + 2 > section_end)
5687 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5688 (unsigned long) offset);
5692 length = read_uleb128 (start, &bytes_read, section_end);
5693 start += bytes_read;
5695 print_dwarf_vma (begin + base_address, pointer_size);
5696 print_dwarf_vma (end + base_address, pointer_size);
5699 need_frame_base = decode_location_expression (start,
5704 cu_offset, section);
5707 if (need_frame_base && !has_frame_base)
5708 printf (_(" [without DW_AT_frame_base]"));
5710 if (begin == end && vbegin == vend)
5711 fputs (_(" (start == end)"), stdout);
5712 else if (begin > end || (begin == end && vbegin > vend))
5713 fputs (_(" (start > end)"), stdout);
5721 if (vbegin != vm1 || vend != vm1)
5722 printf (_("Trailing view pair not used in a range"));
5725 *vstart_ptr = vstart;
5728 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5729 right-adjusted in a field of length LEN, and followed by a space. */
5732 print_addr_index (unsigned int idx, unsigned int len)
5734 static char buf[15];
5735 snprintf (buf, sizeof (buf), "[%d]", idx);
5736 printf ("%*s ", len, buf);
5739 /* Display a location list from a .dwo section. It uses address indexes rather
5740 than embedded addresses. This code closely follows display_loc_list, but the
5741 two are sufficiently different that combining things is very ugly. */
5744 display_loc_list_dwo (struct dwarf_section *section,
5745 unsigned char **start_ptr,
5746 unsigned int debug_info_entry,
5748 unsigned char **vstart_ptr,
5751 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5752 unsigned char *section_end = section->start + section->size;
5753 unsigned long cu_offset;
5754 unsigned int pointer_size;
5755 unsigned int offset_size;
5758 unsigned short length;
5759 int need_frame_base;
5761 unsigned int bytes_read;
5763 if (debug_info_entry >= num_debug_info_entries)
5765 warn (_("No debug information for loc lists of entry: %u\n"),
5770 cu_offset = debug_information [debug_info_entry].cu_offset;
5771 pointer_size = debug_information [debug_info_entry].pointer_size;
5772 offset_size = debug_information [debug_info_entry].offset_size;
5773 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5775 if (pointer_size < 2 || pointer_size > 8)
5777 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5778 pointer_size, debug_info_entry);
5784 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5786 if (start >= section_end)
5788 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5789 (unsigned long) offset);
5793 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5806 dwarf_vma off = offset + (vstart - *start_ptr);
5808 view = read_uleb128 (vstart, &bytes_read, section_end);
5809 vstart += bytes_read;
5810 print_dwarf_view (view, 8, 1);
5812 view = read_uleb128 (vstart, &bytes_read, section_end);
5813 vstart += bytes_read;
5814 print_dwarf_view (view, 8, 1);
5816 printf (_("views at %8.8lx for:\n %*s "),
5817 (unsigned long) off, 8, "");
5825 case 0: /* A terminating entry. */
5827 *vstart_ptr = vstart;
5828 printf (_("<End of list>\n"));
5830 case 1: /* A base-address entry. */
5831 idx = read_uleb128 (start, &bytes_read, section_end);
5832 start += bytes_read;
5833 print_addr_index (idx, 8);
5834 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
5835 printf (_("(base address selection entry)\n"));
5837 case 2: /* A start/end entry. */
5838 idx = read_uleb128 (start, &bytes_read, section_end);
5839 start += bytes_read;
5840 print_addr_index (idx, 8);
5841 idx = read_uleb128 (start, &bytes_read, section_end);
5842 start += bytes_read;
5843 print_addr_index (idx, 8);
5845 case 3: /* A start/length entry. */
5846 idx = read_uleb128 (start, &bytes_read, section_end);
5847 start += bytes_read;
5848 print_addr_index (idx, 8);
5849 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5850 printf ("%08x ", idx);
5852 case 4: /* An offset pair entry. */
5853 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5854 printf ("%08x ", idx);
5855 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5856 printf ("%08x ", idx);
5859 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5861 *vstart_ptr = vstart;
5865 if (start + 2 > section_end)
5867 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5868 (unsigned long) offset);
5872 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5873 if (start + length > section_end)
5875 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5876 (unsigned long) offset);
5881 need_frame_base = decode_location_expression (start,
5886 cu_offset, section);
5889 if (need_frame_base && !has_frame_base)
5890 printf (_(" [without DW_AT_frame_base]"));
5898 *vstart_ptr = vstart;
5901 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5904 static dwarf_vma *loc_offsets, *loc_views;
5907 loc_offsets_compar (const void *ap, const void *bp)
5909 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5910 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5912 int ret = (a > b) - (b > a);
5916 a = loc_views[*(const unsigned int *) ap];
5917 b = loc_views[*(const unsigned int *) bp];
5919 ret = (a > b) - (b > a);
5925 display_debug_loc (struct dwarf_section *section, void *file)
5927 unsigned char *start = section->start, *vstart = NULL;
5928 unsigned long bytes;
5929 unsigned char *section_begin = start;
5930 unsigned int num_loc_list = 0;
5931 unsigned long last_offset = 0;
5932 unsigned long last_view = 0;
5933 unsigned int first = 0;
5936 int seen_first_offset = 0;
5937 int locs_sorted = 1;
5938 unsigned char *next = start, *vnext = vstart;
5939 unsigned int *array = NULL;
5940 const char *suffix = strrchr (section->name, '.');
5942 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5943 dwarf_vma expected_start = 0;
5945 if (suffix && strcmp (suffix, ".dwo") == 0)
5948 bytes = section->size;
5952 printf (_("\nThe %s section is empty.\n"), section->name);
5958 unsigned char *hdrptr = section_begin;
5959 dwarf_vma ll_length;
5960 unsigned short ll_version;
5961 unsigned char *end = section_begin + section->size;
5962 unsigned char address_size, segment_selector_size;
5963 uint32_t offset_entry_count;
5965 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5966 if (ll_length == 0xffffffff)
5967 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5969 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5970 if (ll_version != 5)
5972 warn (_("The %s section contains corrupt or "
5973 "unsupported version number: %d.\n"),
5974 section->name, ll_version);
5978 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5980 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5981 if (segment_selector_size != 0)
5983 warn (_("The %s section contains "
5984 "unsupported segment selector size: %d.\n"),
5985 section->name, segment_selector_size);
5989 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5990 if (offset_entry_count != 0)
5992 warn (_("The %s section contains "
5993 "unsupported offset entry count: %d.\n"),
5994 section->name, offset_entry_count);
5998 expected_start = hdrptr - section_begin;
6001 if (load_debug_info (file) == 0)
6003 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6008 /* Check the order of location list in .debug_info section. If
6009 offsets of location lists are in the ascending order, we can
6010 use `debug_information' directly. */
6011 for (i = 0; i < num_debug_info_entries; i++)
6015 num = debug_information [i].num_loc_offsets;
6016 if (num > num_loc_list)
6019 /* Check if we can use `debug_information' directly. */
6020 if (locs_sorted && num != 0)
6022 if (!seen_first_offset)
6024 /* This is the first location list. */
6025 last_offset = debug_information [i].loc_offsets [0];
6026 last_view = debug_information [i].loc_views [0];
6028 seen_first_offset = 1;
6034 for (; j < num; j++)
6037 debug_information [i].loc_offsets [j]
6038 || (last_offset == debug_information [i].loc_offsets [j]
6039 && last_view > debug_information [i].loc_views [j]))
6044 last_offset = debug_information [i].loc_offsets [j];
6045 last_view = debug_information [i].loc_views [j];
6050 if (!seen_first_offset)
6051 error (_("No location lists in .debug_info section!\n"));
6053 if (debug_information [first].num_loc_offsets > 0
6054 && debug_information [first].loc_offsets [0] != expected_start
6055 && debug_information [first].loc_views [0] != expected_start)
6056 warn (_("Location lists in %s section start at 0x%s\n"),
6058 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
6061 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
6063 introduce (section, FALSE);
6065 if (reloc_at (section, 0))
6066 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6068 printf (_(" Offset Begin End Expression\n"));
6070 seen_first_offset = 0;
6071 for (i = first; i < num_debug_info_entries; i++)
6073 dwarf_vma offset, voffset;
6074 dwarf_vma base_address;
6080 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
6082 loc_offsets = debug_information [i].loc_offsets;
6083 loc_views = debug_information [i].loc_views;
6084 qsort (array, debug_information [i].num_loc_offsets,
6085 sizeof (*array), loc_offsets_compar);
6088 int adjacent_view_loclists = 1;
6089 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
6091 j = locs_sorted ? k : array[k];
6093 && (debug_information [i].loc_offsets [locs_sorted
6094 ? k - 1 : array [k - 1]]
6095 == debug_information [i].loc_offsets [j])
6096 && (debug_information [i].loc_views [locs_sorted
6097 ? k - 1 : array [k - 1]]
6098 == debug_information [i].loc_views [j]))
6100 has_frame_base = debug_information [i].have_frame_base [j];
6101 offset = debug_information [i].loc_offsets [j];
6102 next = section_begin + offset;
6103 voffset = debug_information [i].loc_views [j];
6105 vnext = section_begin + voffset;
6108 base_address = debug_information [i].base_address;
6110 if (vnext && vnext < next)
6113 display_view_pair_list (section, &vstart, i, next);
6118 if (!seen_first_offset || !adjacent_view_loclists)
6119 seen_first_offset = 1;
6123 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6124 (unsigned long) (start - section_begin),
6125 (unsigned long) offset);
6126 else if (start > next)
6127 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6128 (unsigned long) (start - section_begin),
6129 (unsigned long) offset);
6134 if (offset >= bytes)
6136 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6137 (unsigned long) offset);
6141 if (vnext && voffset >= bytes)
6143 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6144 (unsigned long) voffset);
6151 display_loc_list_dwo (section, &start, i, offset,
6152 &vstart, has_frame_base);
6154 display_loc_list (section, &start, i, offset, base_address,
6155 &vstart, has_frame_base);
6160 warn (_("DWO is not yet supported.\n"));
6162 display_loclists_list (section, &start, i, offset, base_address,
6163 &vstart, has_frame_base);
6166 /* FIXME: this arrangement is quite simplistic. Nothing
6167 requires locview lists to be adjacent to corresponding
6168 loclists, and a single loclist could be augmented by
6169 different locview lists, and vice-versa, unlikely as it
6170 is that it would make sense to do so. Hopefully we'll
6171 have view pair support built into loclists before we ever
6172 need to address all these possibilities. */
6173 if (adjacent_view_loclists && vnext
6174 && vnext != start && vstart != next)
6176 adjacent_view_loclists = 0;
6177 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6180 if (vnext && vnext == start)
6181 display_view_pair_list (section, &start, i, vstart);
6185 if (start < section->start + section->size)
6186 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6187 "There are %ld unused bytes at the end of section %s\n",
6188 (long) (section->start + section->size - start)),
6189 (long) (section->start + section->size - start), section->name);
6196 display_debug_str (struct dwarf_section *section,
6197 void *file ATTRIBUTE_UNUSED)
6199 unsigned char *start = section->start;
6200 unsigned long bytes = section->size;
6201 dwarf_vma addr = section->address;
6205 printf (_("\nThe %s section is empty.\n"), section->name);
6209 introduce (section, FALSE);
6217 lbytes = (bytes > 16 ? 16 : bytes);
6219 printf (" 0x%8.8lx ", (unsigned long) addr);
6221 for (j = 0; j < 16; j++)
6224 printf ("%2.2x", start[j]);
6232 for (j = 0; j < lbytes; j++)
6235 if (k >= ' ' && k < 0x80)
6254 display_debug_info (struct dwarf_section *section, void *file)
6256 return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE);
6260 display_debug_types (struct dwarf_section *section, void *file)
6262 return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE);
6266 display_trace_info (struct dwarf_section *section, void *file)
6268 return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE);
6272 display_debug_aranges (struct dwarf_section *section,
6273 void *file ATTRIBUTE_UNUSED)
6275 unsigned char *start = section->start;
6276 unsigned char *end = start + section->size;
6278 introduce (section, FALSE);
6280 /* It does not matter if this load fails,
6281 we test for that later on. */
6282 load_debug_info (file);
6286 unsigned char *hdrptr;
6287 DWARF2_Internal_ARange arange;
6288 unsigned char *addr_ranges;
6291 unsigned long sec_off;
6292 unsigned char address_size;
6294 unsigned int offset_size;
6295 unsigned int initial_length_size;
6299 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
6300 if (arange.ar_length == 0xffffffff)
6302 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
6304 initial_length_size = 12;
6309 initial_length_size = 4;
6312 sec_off = hdrptr - section->start;
6313 if (sec_off + arange.ar_length < sec_off
6314 || sec_off + arange.ar_length > section->size)
6316 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6318 sec_off - initial_length_size,
6319 dwarf_vmatoa ("x", arange.ar_length));
6323 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6324 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
6326 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6327 && num_debug_info_entries > 0
6328 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6329 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6330 (unsigned long) arange.ar_info_offset, section->name);
6332 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6333 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
6335 if (arange.ar_version != 2 && arange.ar_version != 3)
6337 /* PR 19872: A version number of 0 probably means that there is
6338 padding at the end of the .debug_aranges section. Gold puts
6339 it there when performing an incremental link, for example.
6340 So do not generate a warning in this case. */
6341 if (arange.ar_version)
6342 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6346 printf (_(" Length: %ld\n"),
6347 (long) arange.ar_length);
6348 printf (_(" Version: %d\n"), arange.ar_version);
6349 printf (_(" Offset into .debug_info: 0x%lx\n"),
6350 (unsigned long) arange.ar_info_offset);
6351 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6352 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6354 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6356 /* PR 17512: file: 001-108546-0.001:0.1. */
6357 if (address_size == 0 || address_size > 8)
6359 error (_("Invalid address size in %s section!\n"),
6364 /* The DWARF spec does not require that the address size be a power
6365 of two, but we do. This will have to change if we ever encounter
6366 an uneven architecture. */
6367 if ((address_size & (address_size - 1)) != 0)
6369 warn (_("Pointer size + Segment size is not a power of two.\n"));
6373 if (address_size > 4)
6374 printf (_("\n Address Length\n"));
6376 printf (_("\n Address Length\n"));
6378 addr_ranges = hdrptr;
6380 /* Must pad to an alignment boundary that is twice the address size. */
6381 excess = (hdrptr - start) % (2 * address_size);
6383 addr_ranges += (2 * address_size) - excess;
6385 start += arange.ar_length + initial_length_size;
6387 while (addr_ranges + 2 * address_size <= start)
6389 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6390 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
6393 print_dwarf_vma (address, address_size);
6394 print_dwarf_vma (length, address_size);
6404 /* Comparison function for qsort. */
6406 comp_addr_base (const void * v0, const void * v1)
6408 debug_info * info0 = (debug_info *) v0;
6409 debug_info * info1 = (debug_info *) v1;
6410 return info0->addr_base - info1->addr_base;
6413 /* Display the debug_addr section. */
6415 display_debug_addr (struct dwarf_section *section,
6418 debug_info **debug_addr_info;
6419 unsigned char *entry;
6424 if (section->size == 0)
6426 printf (_("\nThe %s section is empty.\n"), section->name);
6430 if (load_debug_info (file) == 0)
6432 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6437 introduce (section, FALSE);
6439 /* PR 17531: file: cf38d01b.
6440 We use xcalloc because a corrupt file may not have initialised all of the
6441 fields in the debug_info structure, which means that the sort below might
6442 try to move uninitialised data. */
6443 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
6444 sizeof (debug_info *));
6447 for (i = 0; i < num_debug_info_entries; i++)
6448 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
6450 /* PR 17531: file: cf38d01b. */
6451 if (debug_information[i].addr_base >= section->size)
6452 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6453 (unsigned long) debug_information[i].addr_base, i);
6455 debug_addr_info [count++] = debug_information + i;
6458 /* Add a sentinel to make iteration convenient. */
6459 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6460 debug_addr_info [count]->addr_base = section->size;
6461 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
6463 for (i = 0; i < count; i++)
6466 unsigned int address_size = debug_addr_info [i]->pointer_size;
6468 printf (_(" For compilation unit at offset 0x%s:\n"),
6469 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
6471 printf (_("\tIndex\tAddress\n"));
6472 entry = section->start + debug_addr_info [i]->addr_base;
6473 end = section->start + debug_addr_info [i + 1]->addr_base;
6477 dwarf_vma base = byte_get (entry, address_size);
6478 printf (_("\t%d:\t"), idx);
6479 print_dwarf_vma (base, address_size);
6481 entry += address_size;
6487 free (debug_addr_info);
6491 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6493 display_debug_str_offsets (struct dwarf_section *section,
6494 void *file ATTRIBUTE_UNUSED)
6496 if (section->size == 0)
6498 printf (_("\nThe %s section is empty.\n"), section->name);
6501 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6502 what the offset size is for this section. */
6506 /* Each debug_information[x].range_lists[y] gets this representation for
6507 sorting purposes. */
6511 /* The debug_information[x].range_lists[y] value. */
6512 dwarf_vma ranges_offset;
6514 /* Original debug_information to find parameters of the data. */
6515 debug_info *debug_info_p;
6518 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6521 range_entry_compar (const void *ap, const void *bp)
6523 const struct range_entry *a_re = (const struct range_entry *) ap;
6524 const struct range_entry *b_re = (const struct range_entry *) bp;
6525 const dwarf_vma a = a_re->ranges_offset;
6526 const dwarf_vma b = b_re->ranges_offset;
6528 return (a > b) - (b > a);
6532 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6533 unsigned int pointer_size, unsigned long offset,
6534 unsigned long base_address)
6536 while (start < finish)
6541 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6542 if (start >= finish)
6544 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6546 printf (" %8.8lx ", offset);
6548 if (begin == 0 && end == 0)
6550 printf (_("<End of list>\n"));
6554 /* Check base address specifiers. */
6555 if (is_max_address (begin, pointer_size)
6556 && !is_max_address (end, pointer_size))
6559 print_dwarf_vma (begin, pointer_size);
6560 print_dwarf_vma (end, pointer_size);
6561 printf ("(base address)\n");
6565 print_dwarf_vma (begin + base_address, pointer_size);
6566 print_dwarf_vma (end + base_address, pointer_size);
6569 fputs (_("(start == end)"), stdout);
6570 else if (begin > end)
6571 fputs (_("(start > end)"), stdout);
6578 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6579 unsigned int pointer_size, unsigned long offset,
6580 unsigned long base_address)
6582 unsigned char *next = start;
6586 unsigned long off = offset + (start - next);
6587 enum dwarf_range_list_entry rlet;
6588 /* Initialize it due to a false compiler warning. */
6589 dwarf_vma begin = -1, length, end = -1;
6590 unsigned int bytes_read;
6592 if (start + 1 > finish)
6594 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6599 printf (" %8.8lx ", off);
6601 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6605 case DW_RLE_end_of_list:
6606 printf (_("<End of list>\n"));
6608 case DW_RLE_base_address:
6609 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6610 print_dwarf_vma (base_address, pointer_size);
6611 printf (_("(base address)\n"));
6613 case DW_RLE_start_length:
6614 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6615 length = read_uleb128 (start, &bytes_read, finish);
6616 start += bytes_read;
6617 end = begin + length;
6619 case DW_RLE_offset_pair:
6620 begin = read_uleb128 (start, &bytes_read, finish);
6621 start += bytes_read;
6622 end = read_uleb128 (start, &bytes_read, finish);
6623 start += bytes_read;
6625 case DW_RLE_start_end:
6626 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6627 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6630 error (_("Invalid range list entry type %d\n"), rlet);
6631 rlet = DW_RLE_end_of_list;
6634 if (rlet == DW_RLE_end_of_list)
6636 if (rlet == DW_RLE_base_address)
6639 print_dwarf_vma (begin + base_address, pointer_size);
6640 print_dwarf_vma (end + base_address, pointer_size);
6643 fputs (_("(start == end)"), stdout);
6644 else if (begin > end)
6645 fputs (_("(start > end)"), stdout);
6652 display_debug_ranges (struct dwarf_section *section,
6653 void *file ATTRIBUTE_UNUSED)
6655 unsigned char *start = section->start;
6656 unsigned char *last_start = start;
6657 unsigned long bytes = section->size;
6658 unsigned char *section_begin = start;
6659 unsigned char *finish = start + bytes;
6660 unsigned int num_range_list, i;
6661 struct range_entry *range_entries, *range_entry_fill;
6662 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6663 /* Initialize it due to a false compiler warning. */
6664 unsigned char address_size = 0;
6668 printf (_("\nThe %s section is empty.\n"), section->name);
6674 dwarf_vma initial_length;
6675 unsigned int initial_length_size;
6676 unsigned char segment_selector_size;
6677 unsigned int offset_size, offset_entry_count;
6678 unsigned short version;
6680 /* Get and check the length of the block. */
6681 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6683 if (initial_length == 0xffffffff)
6685 /* This section is 64-bit DWARF 3. */
6686 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6688 initial_length_size = 12;
6693 initial_length_size = 4;
6696 if (initial_length + initial_length_size > section->size)
6698 /* If the length field has a relocation against it, then we should
6699 not complain if it is inaccurate (and probably negative).
6700 It is copied from .debug_line handling code. */
6701 if (reloc_at (section, (start - section->start) - offset_size))
6703 initial_length = (finish - start) - initial_length_size;
6707 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6708 (long) initial_length);
6713 /* Get and check the version number. */
6714 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6718 warn (_("Only DWARF version 5 debug_rnglists info "
6719 "is currently supported.\n"));
6723 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6725 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6726 if (segment_selector_size != 0)
6728 warn (_("The %s section contains "
6729 "unsupported segment selector size: %d.\n"),
6730 section->name, segment_selector_size);
6734 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6735 if (offset_entry_count != 0)
6737 warn (_("The %s section contains "
6738 "unsupported offset entry count: %u.\n"),
6739 section->name, offset_entry_count);
6744 if (load_debug_info (file) == 0)
6746 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6752 for (i = 0; i < num_debug_info_entries; i++)
6753 num_range_list += debug_information [i].num_range_lists;
6755 if (num_range_list == 0)
6757 /* This can happen when the file was compiled with -gsplit-debug
6758 which removes references to range lists from the primary .o file. */
6759 printf (_("No range lists in .debug_info section.\n"));
6763 range_entries = (struct range_entry *)
6764 xmalloc (sizeof (*range_entries) * num_range_list);
6765 range_entry_fill = range_entries;
6767 for (i = 0; i < num_debug_info_entries; i++)
6769 debug_info *debug_info_p = &debug_information[i];
6772 for (j = 0; j < debug_info_p->num_range_lists; j++)
6774 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6775 range_entry_fill->debug_info_p = debug_info_p;
6780 qsort (range_entries, num_range_list, sizeof (*range_entries),
6781 range_entry_compar);
6783 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6784 warn (_("Range lists in %s section start at 0x%lx\n"),
6785 section->name, (unsigned long) range_entries[0].ranges_offset);
6787 introduce (section, FALSE);
6789 printf (_(" Offset Begin End\n"));
6791 for (i = 0; i < num_range_list; i++)
6793 struct range_entry *range_entry = &range_entries[i];
6794 debug_info *debug_info_p = range_entry->debug_info_p;
6795 unsigned int pointer_size;
6797 unsigned char *next;
6798 dwarf_vma base_address;
6800 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6801 offset = range_entry->ranges_offset;
6802 next = section_begin + offset;
6803 base_address = debug_info_p->base_address;
6805 /* PR 17512: file: 001-101485-0.001:0.1. */
6806 if (pointer_size < 2 || pointer_size > 8)
6808 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6809 pointer_size, (unsigned long) offset);
6813 if (dwarf_check != 0 && i > 0)
6816 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6817 (unsigned long) (start - section_begin),
6818 (unsigned long) (next - section_begin), section->name);
6819 else if (start > next)
6821 if (next == last_start)
6823 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6824 (unsigned long) (start - section_begin),
6825 (unsigned long) (next - section_begin), section->name);
6831 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6832 (start, finish, pointer_size, offset, base_address);
6836 free (range_entries);
6841 typedef struct Frame_Chunk
6843 struct Frame_Chunk *next;
6844 unsigned char *chunk_start;
6846 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6847 short int *col_type;
6850 unsigned int code_factor;
6854 unsigned int cfa_reg;
6855 dwarf_vma cfa_offset;
6857 unsigned char fde_encoding;
6858 unsigned char cfa_exp;
6859 unsigned char ptr_size;
6860 unsigned char segment_size;
6864 static const char *const *dwarf_regnames;
6865 static unsigned int dwarf_regnames_count;
6867 /* A marker for a col_type that means this column was never referenced
6868 in the frame info. */
6869 #define DW_CFA_unreferenced (-1)
6871 /* Return 0 if no more space is needed, 1 if more space is needed,
6872 -1 for invalid reg. */
6875 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6877 unsigned int prev = fc->ncols;
6879 if (reg < (unsigned int) fc->ncols)
6882 if (dwarf_regnames_count
6883 && reg > dwarf_regnames_count)
6886 fc->ncols = reg + 1;
6887 /* PR 17512: file: 10450-2643-0.004.
6888 If reg == -1 then this can happen... */
6892 /* PR 17512: file: 2844a11d. */
6893 if (fc->ncols > 1024)
6895 error (_("Unfeasibly large register number: %u\n"), reg);
6897 /* FIXME: 1024 is an arbitrary limit. Increase it if
6898 we ever encounter a valid binary that exceeds it. */
6902 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6903 sizeof (short int));
6904 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6905 /* PR 17512: file:002-10025-0.005. */
6906 if (fc->col_type == NULL || fc->col_offset == NULL)
6908 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6914 while (prev < fc->ncols)
6916 fc->col_type[prev] = DW_CFA_unreferenced;
6917 fc->col_offset[prev] = 0;
6923 static const char *const dwarf_regnames_i386[] =
6925 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6926 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6927 "eip", "eflags", NULL, /* 8 - 10 */
6928 "st0", "st1", "st2", "st3", /* 11 - 14 */
6929 "st4", "st5", "st6", "st7", /* 15 - 18 */
6930 NULL, NULL, /* 19 - 20 */
6931 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6932 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6933 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6934 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6935 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6936 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6937 "tr", "ldtr", /* 48 - 49 */
6938 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6939 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6940 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6941 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6942 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6943 NULL, NULL, NULL, /* 90 - 92 */
6944 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6947 static const char *const dwarf_regnames_iamcu[] =
6949 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6950 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6951 "eip", "eflags", NULL, /* 8 - 10 */
6952 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6953 NULL, NULL, /* 19 - 20 */
6954 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6955 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6956 NULL, NULL, NULL, /* 37 - 39 */
6957 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6958 "tr", "ldtr", /* 48 - 49 */
6959 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6960 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6961 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6962 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6963 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6964 NULL, NULL, NULL, /* 90 - 92 */
6965 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6969 init_dwarf_regnames_i386 (void)
6971 dwarf_regnames = dwarf_regnames_i386;
6972 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6976 init_dwarf_regnames_iamcu (void)
6978 dwarf_regnames = dwarf_regnames_iamcu;
6979 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6982 static const char *const dwarf_regnames_x86_64[] =
6984 "rax", "rdx", "rcx", "rbx",
6985 "rsi", "rdi", "rbp", "rsp",
6986 "r8", "r9", "r10", "r11",
6987 "r12", "r13", "r14", "r15",
6989 "xmm0", "xmm1", "xmm2", "xmm3",
6990 "xmm4", "xmm5", "xmm6", "xmm7",
6991 "xmm8", "xmm9", "xmm10", "xmm11",
6992 "xmm12", "xmm13", "xmm14", "xmm15",
6993 "st0", "st1", "st2", "st3",
6994 "st4", "st5", "st6", "st7",
6995 "mm0", "mm1", "mm2", "mm3",
6996 "mm4", "mm5", "mm6", "mm7",
6998 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6999 "fs.base", "gs.base", NULL, NULL,
7001 "mxcsr", "fcw", "fsw",
7002 "xmm16", "xmm17", "xmm18", "xmm19",
7003 "xmm20", "xmm21", "xmm22", "xmm23",
7004 "xmm24", "xmm25", "xmm26", "xmm27",
7005 "xmm28", "xmm29", "xmm30", "xmm31",
7006 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
7007 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
7008 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
7009 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
7010 NULL, NULL, NULL, /* 115 - 117 */
7011 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7015 init_dwarf_regnames_x86_64 (void)
7017 dwarf_regnames = dwarf_regnames_x86_64;
7018 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
7021 static const char *const dwarf_regnames_aarch64[] =
7023 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7024 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7025 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7026 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7027 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
7028 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7029 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7030 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7031 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7032 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7033 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7034 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7038 init_dwarf_regnames_aarch64 (void)
7040 dwarf_regnames = dwarf_regnames_aarch64;
7041 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
7044 static const char *const dwarf_regnames_s390[] =
7046 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7047 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7048 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7049 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7050 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7051 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7052 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7053 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7054 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7057 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7058 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7062 init_dwarf_regnames_s390 (void)
7064 dwarf_regnames = dwarf_regnames_s390;
7065 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
7068 static const char *const dwarf_regnames_riscv[] =
7070 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7071 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7072 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7073 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7074 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7075 "fs0", "fs1", /* 40 - 41 */
7076 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7077 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7078 "fs10", "fs11", /* 58 - 59 */
7079 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7083 init_dwarf_regnames_riscv (void)
7085 dwarf_regnames = dwarf_regnames_riscv;
7086 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv);
7090 init_dwarf_regnames (unsigned int e_machine)
7095 init_dwarf_regnames_i386 ();
7099 init_dwarf_regnames_iamcu ();
7105 init_dwarf_regnames_x86_64 ();
7109 init_dwarf_regnames_aarch64 ();
7113 init_dwarf_regnames_s390 ();
7117 init_dwarf_regnames_riscv ();
7126 regname (unsigned int regno, int row)
7128 static char reg[64];
7131 && regno < dwarf_regnames_count
7132 && dwarf_regnames [regno] != NULL)
7135 return dwarf_regnames [regno];
7136 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
7137 dwarf_regnames [regno]);
7140 snprintf (reg, sizeof (reg), "r%d", regno);
7145 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
7150 if (*max_regs != fc->ncols)
7151 *max_regs = fc->ncols;
7153 if (*need_col_headers)
7155 static const char *sloc = " LOC";
7157 *need_col_headers = 0;
7159 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
7161 for (r = 0; r < *max_regs; r++)
7162 if (fc->col_type[r] != DW_CFA_unreferenced)
7167 printf ("%-5s ", regname (r, 1));
7173 print_dwarf_vma (fc->pc_begin, eh_addr_size);
7175 strcpy (tmp, "exp");
7177 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
7178 printf ("%-8s ", tmp);
7180 for (r = 0; r < fc->ncols; r++)
7182 if (fc->col_type[r] != DW_CFA_unreferenced)
7184 switch (fc->col_type[r])
7186 case DW_CFA_undefined:
7189 case DW_CFA_same_value:
7193 sprintf (tmp, "c%+d", fc->col_offset[r]);
7195 case DW_CFA_val_offset:
7196 sprintf (tmp, "v%+d", fc->col_offset[r]);
7198 case DW_CFA_register:
7199 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
7201 case DW_CFA_expression:
7202 strcpy (tmp, "exp");
7204 case DW_CFA_val_expression:
7205 strcpy (tmp, "vexp");
7208 strcpy (tmp, "n/a");
7211 printf ("%-5s ", tmp);
7217 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7219 static unsigned char *
7220 read_cie (unsigned char *start, unsigned char *end,
7221 Frame_Chunk **p_cie, int *p_version,
7222 bfd_size_type *p_aug_len, unsigned char **p_aug)
7226 unsigned int length_return;
7227 unsigned char *augmentation_data = NULL;
7228 bfd_size_type augmentation_data_len = 0;
7231 /* PR 17512: file: 001-228113-0.004. */
7235 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7236 memset (fc, 0, sizeof (Frame_Chunk));
7238 fc->col_type = (short int *) xmalloc (sizeof (short int));
7239 fc->col_offset = (int *) xmalloc (sizeof (int));
7243 fc->augmentation = (char *) start;
7244 /* PR 17512: file: 001-228113-0.004.
7245 Skip past augmentation name, but avoid running off the end of the data. */
7247 if (* start ++ == '\0')
7251 warn (_("No terminator for augmentation name\n"));
7255 if (strcmp (fc->augmentation, "eh") == 0)
7256 start += eh_addr_size;
7260 GET (fc->ptr_size, 1);
7261 if (fc->ptr_size < 1 || fc->ptr_size > 8)
7263 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
7267 GET (fc->segment_size, 1);
7268 /* PR 17512: file: e99d2804. */
7269 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
7271 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
7275 eh_addr_size = fc->ptr_size;
7279 fc->ptr_size = eh_addr_size;
7280 fc->segment_size = 0;
7282 READ_ULEB (fc->code_factor);
7283 READ_SLEB (fc->data_factor);
7293 if (fc->augmentation[0] == 'z')
7295 READ_ULEB (augmentation_data_len);
7296 augmentation_data = start;
7297 /* PR 17512: file: 11042-2589-0.004. */
7298 if (augmentation_data_len > (bfd_size_type) (end - start))
7300 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7301 dwarf_vmatoa ("x", augmentation_data_len),
7302 (unsigned long) (end - start));
7305 start += augmentation_data_len;
7308 if (augmentation_data_len)
7312 unsigned char *qend;
7314 p = (unsigned char *) fc->augmentation + 1;
7315 q = augmentation_data;
7316 qend = q + augmentation_data_len;
7318 while (p < end && q < qend)
7323 q += 1 + size_of_encoded_value (*q);
7325 fc->fde_encoding = *q++;
7332 /* Note - it is OK if this loop terminates with q < qend.
7333 Padding may have been inserted to align the end of the CIE. */
7338 *p_version = version;
7341 *p_aug_len = augmentation_data_len;
7342 *p_aug = augmentation_data;
7347 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7348 If do_wide is not enabled, then formats the output to fit into 80 columns.
7349 PRINTED contains the number of characters already written to the current
7353 display_data (bfd_size_type printed,
7354 const unsigned char * data,
7355 const bfd_size_type len)
7357 if (do_wide || len < ((80 - printed) / 3))
7358 for (printed = 0; printed < len; ++printed)
7359 printf (" %02x", data[printed]);
7362 for (printed = 0; printed < len; ++printed)
7364 if (printed % (80 / 3) == 0)
7366 printf (" %02x", data[printed]);
7371 /* Prints out the contents on the augmentation data array.
7372 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7375 display_augmentation_data (const unsigned char * data, const bfd_size_type len)
7379 i = printf (_(" Augmentation data: "));
7380 display_data (i, data, len);
7384 display_debug_frames (struct dwarf_section *section,
7385 void *file ATTRIBUTE_UNUSED)
7387 unsigned char *start = section->start;
7388 unsigned char *end = start + section->size;
7389 unsigned char *section_start = start;
7390 Frame_Chunk *chunks = 0, *forward_refs = 0;
7391 Frame_Chunk *remembered_state = 0;
7393 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7394 unsigned int length_return;
7395 unsigned int max_regs = 0;
7396 const char *bad_reg = _("bad register: ");
7397 unsigned int saved_eh_addr_size = eh_addr_size;
7399 introduce (section, FALSE);
7403 unsigned char *saved_start;
7404 unsigned char *block_end;
7409 int need_col_headers = 1;
7410 unsigned char *augmentation_data = NULL;
7411 bfd_size_type augmentation_data_len = 0;
7412 unsigned int encoded_ptr_size = saved_eh_addr_size;
7413 unsigned int offset_size;
7414 unsigned int initial_length_size;
7415 bfd_boolean all_nops;
7417 saved_start = start;
7419 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
7423 printf ("\n%08lx ZERO terminator\n\n",
7424 (unsigned long)(saved_start - section_start));
7425 /* Skip any zero terminators that directly follow.
7426 A corrupt section size could have loaded a whole
7427 slew of zero filled memory bytes. eg
7428 PR 17512: file: 070-19381-0.004. */
7429 while (start < end && * start == 0)
7434 if (length == 0xffffffff)
7436 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
7438 initial_length_size = 12;
7443 initial_length_size = 4;
7446 block_end = saved_start + length + initial_length_size;
7447 if (block_end > end || block_end < start)
7449 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7450 dwarf_vmatoa_1 (NULL, length, offset_size),
7451 (unsigned long) (saved_start - section_start));
7455 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
7457 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7458 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
7463 start = read_cie (start, end, &cie, &version,
7464 &augmentation_data_len, &augmentation_data);
7465 /* PR 17512: file: 027-135133-0.005. */
7472 fc->chunk_start = saved_start;
7473 mreg = max_regs > 0 ? max_regs - 1 : 0;
7476 if (frame_need_space (fc, mreg) < 0)
7478 if (fc->fde_encoding)
7479 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7481 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7482 print_dwarf_vma (length, fc->ptr_size);
7483 print_dwarf_vma (cie_id, offset_size);
7485 if (do_debug_frames_interp)
7487 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7488 fc->code_factor, fc->data_factor, fc->ra);
7493 printf (" Version: %d\n", version);
7494 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7497 printf (" Pointer Size: %u\n", fc->ptr_size);
7498 printf (" Segment Size: %u\n", fc->segment_size);
7500 printf (" Code alignment factor: %u\n", fc->code_factor);
7501 printf (" Data alignment factor: %d\n", fc->data_factor);
7502 printf (" Return address column: %d\n", fc->ra);
7504 if (augmentation_data_len)
7505 display_augmentation_data (augmentation_data, augmentation_data_len);
7512 unsigned char *look_for;
7513 static Frame_Chunk fde_fc;
7514 unsigned long segment_selector;
7518 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7519 look_for = start - 4 - ((cie_id ^ sign) - sign);
7522 look_for = section_start + cie_id;
7524 if (look_for <= saved_start)
7526 for (cie = chunks; cie ; cie = cie->next)
7527 if (cie->chunk_start == look_for)
7532 for (cie = forward_refs; cie ; cie = cie->next)
7533 if (cie->chunk_start == look_for)
7537 unsigned int off_size;
7538 unsigned char *cie_scan;
7540 cie_scan = look_for;
7542 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7543 if (length == 0xffffffff)
7545 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7552 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7555 : ((off_size == 4 && c_id == DW_CIE_ID)
7556 || (off_size == 8 && c_id == DW64_CIE_ID)))
7561 read_cie (cie_scan, end, &cie, &version,
7562 &augmentation_data_len, &augmentation_data);
7563 /* PR 17512: file: 3450-2098-0.004. */
7566 warn (_("Failed to read CIE information\n"));
7569 cie->next = forward_refs;
7571 cie->chunk_start = look_for;
7572 mreg = max_regs > 0 ? max_regs - 1 : 0;
7575 if (frame_need_space (cie, mreg) < 0)
7577 warn (_("Invalid max register\n"));
7580 if (cie->fde_encoding)
7582 = size_of_encoded_value (cie->fde_encoding);
7589 memset (fc, 0, sizeof (Frame_Chunk));
7593 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7594 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7595 (unsigned long) (saved_start - section_start));
7597 fc->col_type = (short int *) xmalloc (sizeof (short int));
7598 fc->col_offset = (int *) xmalloc (sizeof (int));
7599 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7601 warn (_("Invalid max register\n"));
7605 fc->augmentation = "";
7606 fc->fde_encoding = 0;
7607 fc->ptr_size = eh_addr_size;
7608 fc->segment_size = 0;
7612 fc->ncols = cie->ncols;
7613 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7614 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
7615 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7616 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7617 fc->augmentation = cie->augmentation;
7618 fc->ptr_size = cie->ptr_size;
7619 eh_addr_size = cie->ptr_size;
7620 fc->segment_size = cie->segment_size;
7621 fc->code_factor = cie->code_factor;
7622 fc->data_factor = cie->data_factor;
7623 fc->cfa_reg = cie->cfa_reg;
7624 fc->cfa_offset = cie->cfa_offset;
7626 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7628 warn (_("Invalid max register\n"));
7631 fc->fde_encoding = cie->fde_encoding;
7634 if (fc->fde_encoding)
7635 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7637 segment_selector = 0;
7638 if (fc->segment_size)
7640 if (fc->segment_size > sizeof (segment_selector))
7642 /* PR 17512: file: 9e196b3e. */
7643 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7644 fc->segment_size = 4;
7646 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7649 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
7651 /* FIXME: It appears that sometimes the final pc_range value is
7652 encoded in less than encoded_ptr_size bytes. See the x86_64
7653 run of the "objcopy on compressed debug sections" test for an
7655 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
7657 if (cie->augmentation[0] == 'z')
7659 READ_ULEB (augmentation_data_len);
7660 augmentation_data = start;
7661 start += augmentation_data_len;
7662 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7664 || ((bfd_signed_vma) augmentation_data_len) < 0
7665 || augmentation_data > start)
7667 warn (_("Corrupt augmentation data length: 0x%s\n"),
7668 dwarf_vmatoa ("x", augmentation_data_len));
7670 augmentation_data = NULL;
7671 augmentation_data_len = 0;
7675 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7676 (unsigned long)(saved_start - section_start),
7677 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7678 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7679 (unsigned long)(cie->chunk_start - section_start));
7681 if (fc->segment_size)
7682 printf ("%04lx:", segment_selector);
7685 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7686 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7688 if (! do_debug_frames_interp && augmentation_data_len)
7690 display_augmentation_data (augmentation_data, augmentation_data_len);
7695 /* At this point, fc is the current chunk, cie (if any) is set, and
7696 we're about to interpret instructions for the chunk. */
7697 /* ??? At present we need to do this always, since this sizes the
7698 fc->col_type and fc->col_offset arrays, which we write into always.
7699 We should probably split the interpreted and non-interpreted bits
7700 into two different routines, since there's so much that doesn't
7701 really overlap between them. */
7702 if (1 || do_debug_frames_interp)
7704 /* Start by making a pass over the chunk, allocating storage
7705 and taking note of what registers are used. */
7706 unsigned char *tmp = start;
7708 while (start < block_end)
7710 unsigned int reg, op, opa;
7712 unsigned char * new_start;
7719 /* Warning: if you add any more cases to this switch, be
7720 sure to add them to the corresponding switch below. */
7723 case DW_CFA_advance_loc:
7727 if (frame_need_space (fc, opa) >= 0)
7728 fc->col_type[opa] = DW_CFA_undefined;
7730 case DW_CFA_restore:
7731 if (frame_need_space (fc, opa) >= 0)
7732 fc->col_type[opa] = DW_CFA_undefined;
7734 case DW_CFA_set_loc:
7735 start += encoded_ptr_size;
7737 case DW_CFA_advance_loc1:
7740 case DW_CFA_advance_loc2:
7743 case DW_CFA_advance_loc4:
7746 case DW_CFA_offset_extended:
7747 case DW_CFA_val_offset:
7750 if (frame_need_space (fc, reg) >= 0)
7751 fc->col_type[reg] = DW_CFA_undefined;
7753 case DW_CFA_restore_extended:
7755 if (frame_need_space (fc, reg) >= 0)
7756 fc->col_type[reg] = DW_CFA_undefined;
7758 case DW_CFA_undefined:
7760 if (frame_need_space (fc, reg) >= 0)
7761 fc->col_type[reg] = DW_CFA_undefined;
7763 case DW_CFA_same_value:
7765 if (frame_need_space (fc, reg) >= 0)
7766 fc->col_type[reg] = DW_CFA_undefined;
7768 case DW_CFA_register:
7771 if (frame_need_space (fc, reg) >= 0)
7772 fc->col_type[reg] = DW_CFA_undefined;
7774 case DW_CFA_def_cfa:
7778 case DW_CFA_def_cfa_register:
7781 case DW_CFA_def_cfa_offset:
7784 case DW_CFA_def_cfa_expression:
7786 new_start = start + temp;
7787 if (new_start < start)
7789 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7795 case DW_CFA_expression:
7796 case DW_CFA_val_expression:
7799 new_start = start + temp;
7800 if (new_start < start)
7802 /* PR 17512: file:306-192417-0.005. */
7803 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7808 if (frame_need_space (fc, reg) >= 0)
7809 fc->col_type[reg] = DW_CFA_undefined;
7811 case DW_CFA_offset_extended_sf:
7812 case DW_CFA_val_offset_sf:
7815 if (frame_need_space (fc, reg) >= 0)
7816 fc->col_type[reg] = DW_CFA_undefined;
7818 case DW_CFA_def_cfa_sf:
7822 case DW_CFA_def_cfa_offset_sf:
7825 case DW_CFA_MIPS_advance_loc8:
7828 case DW_CFA_GNU_args_size:
7831 case DW_CFA_GNU_negative_offset_extended:
7834 if (frame_need_space (fc, reg) >= 0)
7835 fc->col_type[reg] = DW_CFA_undefined;
7846 /* Now we know what registers are used, make a second pass over
7847 the chunk, this time actually printing out the info. */
7849 while (start < block_end)
7851 unsigned char * tmp;
7853 unsigned long ul, roffs;
7854 /* Note: It is tempting to use an unsigned long for 'reg' but there
7855 are various functions, notably frame_space_needed() that assume that
7856 reg is an unsigned int. */
7861 const char *reg_prefix = "";
7868 /* Make a note if something other than DW_CFA_nop happens. */
7869 if (op != DW_CFA_nop)
7872 /* Warning: if you add any more cases to this switch, be
7873 sure to add them to the corresponding switch above. */
7876 case DW_CFA_advance_loc:
7877 if (do_debug_frames_interp)
7878 frame_display_row (fc, &need_col_headers, &max_regs);
7880 printf (" DW_CFA_advance_loc: %d to %s\n",
7881 opa * fc->code_factor,
7882 dwarf_vmatoa_1 (NULL,
7883 fc->pc_begin + opa * fc->code_factor,
7885 fc->pc_begin += opa * fc->code_factor;
7890 if (opa >= (unsigned int) fc->ncols)
7891 reg_prefix = bad_reg;
7892 if (! do_debug_frames_interp || *reg_prefix != '\0')
7893 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7894 reg_prefix, regname (opa, 0),
7895 roffs * fc->data_factor);
7896 if (*reg_prefix == '\0')
7898 fc->col_type[opa] = DW_CFA_offset;
7899 fc->col_offset[opa] = roffs * fc->data_factor;
7903 case DW_CFA_restore:
7904 if (opa >= (unsigned int) fc->ncols)
7905 reg_prefix = bad_reg;
7906 if (! do_debug_frames_interp || *reg_prefix != '\0')
7907 printf (" DW_CFA_restore: %s%s\n",
7908 reg_prefix, regname (opa, 0));
7909 if (*reg_prefix != '\0')
7912 if (opa >= (unsigned int) cie->ncols
7913 || (do_debug_frames_interp
7914 && cie->col_type[opa] == DW_CFA_unreferenced))
7916 fc->col_type[opa] = DW_CFA_undefined;
7917 fc->col_offset[opa] = 0;
7921 fc->col_type[opa] = cie->col_type[opa];
7922 fc->col_offset[opa] = cie->col_offset[opa];
7926 case DW_CFA_set_loc:
7927 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7928 if (do_debug_frames_interp)
7929 frame_display_row (fc, &need_col_headers, &max_regs);
7931 printf (" DW_CFA_set_loc: %s\n",
7932 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7936 case DW_CFA_advance_loc1:
7937 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7938 if (do_debug_frames_interp)
7939 frame_display_row (fc, &need_col_headers, &max_regs);
7941 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7942 (unsigned long) (ofs * fc->code_factor),
7943 dwarf_vmatoa_1 (NULL,
7944 fc->pc_begin + ofs * fc->code_factor,
7946 fc->pc_begin += ofs * fc->code_factor;
7949 case DW_CFA_advance_loc2:
7950 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7951 if (do_debug_frames_interp)
7952 frame_display_row (fc, &need_col_headers, &max_regs);
7954 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7955 (unsigned long) (ofs * fc->code_factor),
7956 dwarf_vmatoa_1 (NULL,
7957 fc->pc_begin + ofs * fc->code_factor,
7959 fc->pc_begin += ofs * fc->code_factor;
7962 case DW_CFA_advance_loc4:
7963 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7964 if (do_debug_frames_interp)
7965 frame_display_row (fc, &need_col_headers, &max_regs);
7967 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7968 (unsigned long) (ofs * fc->code_factor),
7969 dwarf_vmatoa_1 (NULL,
7970 fc->pc_begin + ofs * fc->code_factor,
7972 fc->pc_begin += ofs * fc->code_factor;
7975 case DW_CFA_offset_extended:
7978 if (reg >= (unsigned int) fc->ncols)
7979 reg_prefix = bad_reg;
7980 if (! do_debug_frames_interp || *reg_prefix != '\0')
7981 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7982 reg_prefix, regname (reg, 0),
7983 roffs * fc->data_factor);
7984 if (*reg_prefix == '\0')
7986 fc->col_type[reg] = DW_CFA_offset;
7987 fc->col_offset[reg] = roffs * fc->data_factor;
7991 case DW_CFA_val_offset:
7994 if (reg >= (unsigned int) fc->ncols)
7995 reg_prefix = bad_reg;
7996 if (! do_debug_frames_interp || *reg_prefix != '\0')
7997 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7998 reg_prefix, regname (reg, 0),
7999 roffs * fc->data_factor);
8000 if (*reg_prefix == '\0')
8002 fc->col_type[reg] = DW_CFA_val_offset;
8003 fc->col_offset[reg] = roffs * fc->data_factor;
8007 case DW_CFA_restore_extended:
8009 if (reg >= (unsigned int) fc->ncols)
8010 reg_prefix = bad_reg;
8011 if (! do_debug_frames_interp || *reg_prefix != '\0')
8012 printf (" DW_CFA_restore_extended: %s%s\n",
8013 reg_prefix, regname (reg, 0));
8014 if (*reg_prefix != '\0')
8017 if (reg >= (unsigned int) cie->ncols)
8019 fc->col_type[reg] = DW_CFA_undefined;
8020 fc->col_offset[reg] = 0;
8024 fc->col_type[reg] = cie->col_type[reg];
8025 fc->col_offset[reg] = cie->col_offset[reg];
8029 case DW_CFA_undefined:
8031 if (reg >= (unsigned int) fc->ncols)
8032 reg_prefix = bad_reg;
8033 if (! do_debug_frames_interp || *reg_prefix != '\0')
8034 printf (" DW_CFA_undefined: %s%s\n",
8035 reg_prefix, regname (reg, 0));
8036 if (*reg_prefix == '\0')
8038 fc->col_type[reg] = DW_CFA_undefined;
8039 fc->col_offset[reg] = 0;
8043 case DW_CFA_same_value:
8045 if (reg >= (unsigned int) fc->ncols)
8046 reg_prefix = bad_reg;
8047 if (! do_debug_frames_interp || *reg_prefix != '\0')
8048 printf (" DW_CFA_same_value: %s%s\n",
8049 reg_prefix, regname (reg, 0));
8050 if (*reg_prefix == '\0')
8052 fc->col_type[reg] = DW_CFA_same_value;
8053 fc->col_offset[reg] = 0;
8057 case DW_CFA_register:
8060 if (reg >= (unsigned int) fc->ncols)
8061 reg_prefix = bad_reg;
8062 if (! do_debug_frames_interp || *reg_prefix != '\0')
8064 printf (" DW_CFA_register: %s%s in ",
8065 reg_prefix, regname (reg, 0));
8066 puts (regname (roffs, 0));
8068 if (*reg_prefix == '\0')
8070 fc->col_type[reg] = DW_CFA_register;
8071 fc->col_offset[reg] = roffs;
8075 case DW_CFA_remember_state:
8076 if (! do_debug_frames_interp)
8077 printf (" DW_CFA_remember_state\n");
8078 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8079 rs->cfa_offset = fc->cfa_offset;
8080 rs->cfa_reg = fc->cfa_reg;
8082 rs->cfa_exp = fc->cfa_exp;
8083 rs->ncols = fc->ncols;
8084 rs->col_type = (short int *) xcmalloc (rs->ncols,
8085 sizeof (* rs->col_type));
8086 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
8087 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
8088 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
8089 rs->next = remembered_state;
8090 remembered_state = rs;
8093 case DW_CFA_restore_state:
8094 if (! do_debug_frames_interp)
8095 printf (" DW_CFA_restore_state\n");
8096 rs = remembered_state;
8099 remembered_state = rs->next;
8100 fc->cfa_offset = rs->cfa_offset;
8101 fc->cfa_reg = rs->cfa_reg;
8103 fc->cfa_exp = rs->cfa_exp;
8104 if (frame_need_space (fc, rs->ncols - 1) < 0)
8106 warn (_("Invalid column number in saved frame state\n"));
8110 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
8111 memcpy (fc->col_offset, rs->col_offset,
8112 rs->ncols * sizeof (* rs->col_offset));
8113 free (rs->col_type);
8114 free (rs->col_offset);
8117 else if (do_debug_frames_interp)
8118 printf ("Mismatched DW_CFA_restore_state\n");
8121 case DW_CFA_def_cfa:
8122 READ_ULEB (fc->cfa_reg);
8123 READ_ULEB (fc->cfa_offset);
8125 if (! do_debug_frames_interp)
8126 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8127 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8130 case DW_CFA_def_cfa_register:
8131 READ_ULEB (fc->cfa_reg);
8133 if (! do_debug_frames_interp)
8134 printf (" DW_CFA_def_cfa_register: %s\n",
8135 regname (fc->cfa_reg, 0));
8138 case DW_CFA_def_cfa_offset:
8139 READ_ULEB (fc->cfa_offset);
8140 if (! do_debug_frames_interp)
8141 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
8145 if (! do_debug_frames_interp)
8146 printf (" DW_CFA_nop\n");
8149 case DW_CFA_def_cfa_expression:
8151 if (start >= block_end || ul > (unsigned long) (block_end - start))
8153 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
8156 if (! do_debug_frames_interp)
8158 printf (" DW_CFA_def_cfa_expression (");
8159 decode_location_expression (start, eh_addr_size, 0, -1,
8167 case DW_CFA_expression:
8170 if (reg >= (unsigned int) fc->ncols)
8171 reg_prefix = bad_reg;
8172 /* PR 17512: file: 069-133014-0.006. */
8173 /* PR 17512: file: 98c02eb4. */
8175 if (start >= block_end || tmp > block_end || tmp < start)
8177 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
8180 if (! do_debug_frames_interp || *reg_prefix != '\0')
8182 printf (" DW_CFA_expression: %s%s (",
8183 reg_prefix, regname (reg, 0));
8184 decode_location_expression (start, eh_addr_size, 0, -1,
8188 if (*reg_prefix == '\0')
8189 fc->col_type[reg] = DW_CFA_expression;
8193 case DW_CFA_val_expression:
8196 if (reg >= (unsigned int) fc->ncols)
8197 reg_prefix = bad_reg;
8199 if (start >= block_end || tmp > block_end || tmp < start)
8201 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
8204 if (! do_debug_frames_interp || *reg_prefix != '\0')
8206 printf (" DW_CFA_val_expression: %s%s (",
8207 reg_prefix, regname (reg, 0));
8208 decode_location_expression (start, eh_addr_size, 0, -1,
8212 if (*reg_prefix == '\0')
8213 fc->col_type[reg] = DW_CFA_val_expression;
8217 case DW_CFA_offset_extended_sf:
8220 if (frame_need_space (fc, reg) < 0)
8221 reg_prefix = bad_reg;
8222 if (! do_debug_frames_interp || *reg_prefix != '\0')
8223 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8224 reg_prefix, regname (reg, 0),
8225 (long)(l * fc->data_factor));
8226 if (*reg_prefix == '\0')
8228 fc->col_type[reg] = DW_CFA_offset;
8229 fc->col_offset[reg] = l * fc->data_factor;
8233 case DW_CFA_val_offset_sf:
8236 if (frame_need_space (fc, reg) < 0)
8237 reg_prefix = bad_reg;
8238 if (! do_debug_frames_interp || *reg_prefix != '\0')
8239 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8240 reg_prefix, regname (reg, 0),
8241 (long)(l * fc->data_factor));
8242 if (*reg_prefix == '\0')
8244 fc->col_type[reg] = DW_CFA_val_offset;
8245 fc->col_offset[reg] = l * fc->data_factor;
8249 case DW_CFA_def_cfa_sf:
8250 READ_ULEB (fc->cfa_reg);
8251 READ_ULEB (fc->cfa_offset);
8252 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
8254 if (! do_debug_frames_interp)
8255 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8256 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8259 case DW_CFA_def_cfa_offset_sf:
8260 READ_ULEB (fc->cfa_offset);
8261 fc->cfa_offset *= fc->data_factor;
8262 if (! do_debug_frames_interp)
8263 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
8266 case DW_CFA_MIPS_advance_loc8:
8267 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
8268 if (do_debug_frames_interp)
8269 frame_display_row (fc, &need_col_headers, &max_regs);
8271 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8272 (unsigned long) (ofs * fc->code_factor),
8273 dwarf_vmatoa_1 (NULL,
8274 fc->pc_begin + ofs * fc->code_factor,
8276 fc->pc_begin += ofs * fc->code_factor;
8279 case DW_CFA_GNU_window_save:
8280 if (! do_debug_frames_interp)
8281 printf (" DW_CFA_GNU_window_save\n");
8284 case DW_CFA_GNU_args_size:
8286 if (! do_debug_frames_interp)
8287 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8290 case DW_CFA_GNU_negative_offset_extended:
8294 if (frame_need_space (fc, reg) < 0)
8295 reg_prefix = bad_reg;
8296 if (! do_debug_frames_interp || *reg_prefix != '\0')
8297 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8298 reg_prefix, regname (reg, 0),
8299 (long)(l * fc->data_factor));
8300 if (*reg_prefix == '\0')
8302 fc->col_type[reg] = DW_CFA_offset;
8303 fc->col_offset[reg] = l * fc->data_factor;
8308 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
8309 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
8311 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
8316 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8317 if (do_debug_frames_interp && ! all_nops)
8318 frame_display_row (fc, &need_col_headers, &max_regs);
8321 eh_addr_size = saved_eh_addr_size;
8332 display_debug_names (struct dwarf_section *section, void *file)
8334 unsigned char *hdrptr = section->start;
8335 dwarf_vma unit_length;
8336 unsigned char *unit_start;
8337 const unsigned char *const section_end = section->start + section->size;
8338 unsigned char *unit_end;
8340 introduce (section, FALSE);
8342 load_debug_section_with_follow (str, file);
8344 for (; hdrptr < section_end; hdrptr = unit_end)
8346 unsigned int offset_size;
8347 uint16_t dwarf_version, padding;
8348 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8349 uint32_t bucket_count, name_count, abbrev_table_size;
8350 uint32_t augmentation_string_size;
8352 unsigned long sec_off;
8354 unit_start = hdrptr;
8356 /* Get and check the length of the block. */
8357 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8359 if (unit_length == 0xffffffff)
8361 /* This section is 64-bit DWARF. */
8362 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8367 unit_end = hdrptr + unit_length;
8369 sec_off = hdrptr - section->start;
8370 if (sec_off + unit_length < sec_off
8371 || sec_off + unit_length > section->size)
8373 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8375 (unsigned long) (unit_start - section->start),
8376 dwarf_vmatoa ("x", unit_length));
8380 /* Get and check the version number. */
8381 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8382 printf (_("Version %ld\n"), (long) dwarf_version);
8384 /* Prior versions did not exist, and future versions may not be
8385 backwards compatible. */
8386 if (dwarf_version != 5)
8388 warn (_("Only DWARF version 5 .debug_names "
8389 "is currently supported.\n"));
8393 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8395 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8398 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8399 if (comp_unit_count == 0)
8400 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8402 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8403 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8404 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8405 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8406 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8408 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8409 if (augmentation_string_size % 4 != 0)
8411 warn (_("Augmentation string length %u must be rounded up "
8412 "to a multiple of 4 in .debug_names.\n"),
8413 augmentation_string_size);
8414 augmentation_string_size += (-augmentation_string_size) & 3;
8416 printf (_("Augmentation string:"));
8417 for (i = 0; i < augmentation_string_size; i++)
8421 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8422 printf (" %02x", uc);
8427 printf (_("CU table:\n"));
8428 for (i = 0; i < comp_unit_count; i++)
8432 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8433 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8437 printf (_("TU table:\n"));
8438 for (i = 0; i < local_type_unit_count; i++)
8442 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8443 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8447 printf (_("Foreign TU table:\n"));
8448 for (i = 0; i < foreign_type_unit_count; i++)
8452 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8453 printf (_("[%3u] "), i);
8454 print_dwarf_vma (signature, 8);
8459 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8460 hdrptr += bucket_count * sizeof (uint32_t);
8461 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8462 hdrptr += name_count * sizeof (uint32_t);
8463 unsigned char *const name_table_string_offsets = hdrptr;
8464 hdrptr += name_count * offset_size;
8465 unsigned char *const name_table_entry_offsets = hdrptr;
8466 hdrptr += name_count * offset_size;
8467 unsigned char *const abbrev_table = hdrptr;
8468 hdrptr += abbrev_table_size;
8469 const unsigned char *const abbrev_table_end = hdrptr;
8470 unsigned char *const entry_pool = hdrptr;
8471 if (hdrptr > unit_end)
8473 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8474 "for unit 0x%lx in the debug_names\n"),
8475 (long) (hdrptr - section->start),
8476 (long) (unit_end - section->start),
8477 (long) (unit_start - section->start));
8481 size_t buckets_filled = 0;
8483 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8485 const uint32_t bucket = hash_table_buckets[bucketi];
8490 printf (ngettext ("Used %zu of %lu bucket.\n",
8491 "Used %zu of %lu buckets.\n",
8493 buckets_filled, (unsigned long) bucket_count);
8495 uint32_t hash_prev = 0;
8496 size_t hash_clash_count = 0;
8497 size_t longest_clash = 0;
8498 size_t this_length = 0;
8500 for (hashi = 0; hashi < name_count; hashi++)
8502 const uint32_t hash_this = hash_table_hashes[hashi];
8506 if (hash_prev % bucket_count == hash_this % bucket_count)
8510 longest_clash = MAX (longest_clash, this_length);
8515 hash_prev = hash_this;
8517 printf (_("Out of %lu items there are %zu bucket clashes"
8518 " (longest of %zu entries).\n"),
8519 (unsigned long) name_count, hash_clash_count, longest_clash);
8520 assert (name_count == buckets_filled + hash_clash_count);
8522 struct abbrev_lookup_entry
8524 dwarf_vma abbrev_tag;
8525 unsigned char *abbrev_lookup_ptr;
8527 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8528 size_t abbrev_lookup_used = 0;
8529 size_t abbrev_lookup_allocated = 0;
8531 unsigned char *abbrevptr = abbrev_table;
8534 unsigned int bytes_read;
8535 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8537 abbrevptr += bytes_read;
8538 if (abbrev_tag == 0)
8540 if (abbrev_lookup_used == abbrev_lookup_allocated)
8542 abbrev_lookup_allocated = MAX (0x100,
8543 abbrev_lookup_allocated * 2);
8544 abbrev_lookup = xrealloc (abbrev_lookup,
8545 (abbrev_lookup_allocated
8546 * sizeof (*abbrev_lookup)));
8548 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8549 struct abbrev_lookup_entry *entry;
8550 for (entry = abbrev_lookup;
8551 entry < abbrev_lookup + abbrev_lookup_used;
8553 if (entry->abbrev_tag == abbrev_tag)
8555 warn (_("Duplicate abbreviation tag %lu "
8556 "in unit 0x%lx in the debug_names\n"),
8557 (long) abbrev_tag, (long) (unit_start - section->start));
8560 entry = &abbrev_lookup[abbrev_lookup_used++];
8561 entry->abbrev_tag = abbrev_tag;
8562 entry->abbrev_lookup_ptr = abbrevptr;
8564 /* Skip DWARF tag. */
8565 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8566 abbrevptr += bytes_read;
8569 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8572 abbrevptr += bytes_read;
8573 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8575 abbrevptr += bytes_read;
8576 if (xindex == 0 && form == 0)
8581 printf (_("\nSymbol table:\n"));
8583 for (namei = 0; namei < name_count; ++namei)
8585 uint64_t string_offset, entry_offset;
8587 SAFE_BYTE_GET (string_offset,
8588 name_table_string_offsets + namei * offset_size,
8589 offset_size, unit_end);
8590 SAFE_BYTE_GET (entry_offset,
8591 name_table_entry_offsets + namei * offset_size,
8592 offset_size, unit_end);
8594 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8595 fetch_indirect_string (string_offset));
8597 unsigned char *entryptr = entry_pool + entry_offset;
8599 // We need to scan first whether there is a single or multiple
8600 // entries. TAGNO is -2 for the first entry, it is -1 for the
8601 // initial tag read of the second entry, then it becomes 0 for the
8602 // first entry for real printing etc.
8604 /* Initialize it due to a false compiler warning. */
8605 dwarf_vma second_abbrev_tag = -1;
8608 unsigned int bytes_read;
8609 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8611 entryptr += bytes_read;
8614 second_abbrev_tag = abbrev_tag;
8616 entryptr = entry_pool + entry_offset;
8619 if (abbrev_tag == 0)
8623 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8624 (unsigned long) abbrev_tag);
8626 const struct abbrev_lookup_entry *entry;
8627 for (entry = abbrev_lookup;
8628 entry < abbrev_lookup + abbrev_lookup_used;
8630 if (entry->abbrev_tag == abbrev_tag)
8632 if (entry >= abbrev_lookup + abbrev_lookup_used)
8634 warn (_("Undefined abbreviation tag %lu "
8635 "in unit 0x%lx in the debug_names\n"),
8637 (long) (unit_start - section->start));
8640 abbrevptr = entry->abbrev_lookup_ptr;
8641 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8643 abbrevptr += bytes_read;
8645 printf (" %s", get_TAG_name (dwarf_tag));
8648 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8651 abbrevptr += bytes_read;
8652 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8654 abbrevptr += bytes_read;
8655 if (xindex == 0 && form == 0)
8659 printf (" %s", get_IDX_name (xindex));
8660 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8663 dwarf_version, NULL,
8670 printf (_(" <no entries>"));
8674 free (abbrev_lookup);
8681 display_debug_links (struct dwarf_section * section,
8682 void * file ATTRIBUTE_UNUSED)
8684 const unsigned char * filename;
8685 unsigned int filelen;
8687 introduce (section, FALSE);
8689 /* The .gnu_debuglink section is formatted as:
8690 (c-string) Filename.
8691 (padding) If needed to reach a 4 byte boundary.
8692 (uint32_t) CRC32 value.
8694 The .gun_debugaltlink section is formatted as:
8695 (c-string) Filename.
8696 (binary) Build-ID. */
8698 filename = section->start;
8699 filelen = strnlen ((const char *) filename, section->size);
8700 if (filelen == section->size)
8702 warn (_("The debuglink filename is corrupt/missing\n"));
8706 printf (_(" Separate debug info file: %s\n"), filename);
8708 if (const_strneq (section->name, ".gnu_debuglink"))
8711 unsigned int crc_offset;
8713 crc_offset = filelen + 1;
8714 crc_offset = (crc_offset + 3) & ~3;
8715 if (crc_offset + 4 > section->size)
8717 warn (_("CRC offset missing/truncated\n"));
8721 crc32 = byte_get (filename + crc_offset, 4);
8723 printf (_(" CRC value: %#x\n"), crc32);
8725 if (crc_offset + 4 < section->size)
8727 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
8728 (long)(section->size - (crc_offset + 4)));
8732 else /* const_strneq (section->name, ".gnu_debugaltlink") */
8734 const unsigned char * build_id = section->start + filelen + 1;
8735 bfd_size_type build_id_len = section->size - (filelen + 1);
8736 bfd_size_type printed;
8738 /* FIXME: Should we support smaller build-id notes ? */
8739 if (build_id_len < 0x14)
8741 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
8745 printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
8746 display_data (printed, build_id, build_id_len);
8755 display_gdb_index (struct dwarf_section *section,
8756 void *file ATTRIBUTE_UNUSED)
8758 unsigned char *start = section->start;
8760 uint32_t cu_list_offset, tu_list_offset;
8761 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8762 unsigned int cu_list_elements, tu_list_elements;
8763 unsigned int address_table_size, symbol_table_slots;
8764 unsigned char *cu_list, *tu_list;
8765 unsigned char *address_table, *symbol_table, *constant_pool;
8768 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8770 introduce (section, FALSE);
8772 if (section->size < 6 * sizeof (uint32_t))
8774 warn (_("Truncated header in the %s section.\n"), section->name);
8778 version = byte_get_little_endian (start, 4);
8779 printf (_("Version %ld\n"), (long) version);
8781 /* Prior versions are obsolete, and future versions may not be
8782 backwards compatible. */
8783 if (version < 3 || version > 8)
8785 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8789 warn (_("The address table data in version 3 may be wrong.\n"));
8791 warn (_("Version 4 does not support case insensitive lookups.\n"));
8793 warn (_("Version 5 does not include inlined functions.\n"));
8795 warn (_("Version 6 does not include symbol attributes.\n"));
8796 /* Version 7 indices generated by Gold have bad type unit references,
8797 PR binutils/15021. But we don't know if the index was generated by
8798 Gold or not, so to avoid worrying users with gdb-generated indices
8799 we say nothing for version 7 here. */
8801 cu_list_offset = byte_get_little_endian (start + 4, 4);
8802 tu_list_offset = byte_get_little_endian (start + 8, 4);
8803 address_table_offset = byte_get_little_endian (start + 12, 4);
8804 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8805 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8807 if (cu_list_offset > section->size
8808 || tu_list_offset > section->size
8809 || address_table_offset > section->size
8810 || symbol_table_offset > section->size
8811 || constant_pool_offset > section->size)
8813 warn (_("Corrupt header in the %s section.\n"), section->name);
8817 /* PR 17531: file: 418d0a8a. */
8818 if (tu_list_offset < cu_list_offset)
8820 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8821 tu_list_offset, cu_list_offset);
8825 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8827 if (address_table_offset < tu_list_offset)
8829 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8830 address_table_offset, tu_list_offset);
8834 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8836 /* PR 17531: file: 18a47d3d. */
8837 if (symbol_table_offset < address_table_offset)
8839 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8840 symbol_table_offset, address_table_offset);
8844 address_table_size = symbol_table_offset - address_table_offset;
8846 if (constant_pool_offset < symbol_table_offset)
8848 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8849 constant_pool_offset, symbol_table_offset);
8853 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8855 cu_list = start + cu_list_offset;
8856 tu_list = start + tu_list_offset;
8857 address_table = start + address_table_offset;
8858 symbol_table = start + symbol_table_offset;
8859 constant_pool = start + constant_pool_offset;
8861 if (address_table + address_table_size > section->start + section->size)
8863 warn (_("Address table extends beyond end of section.\n"));
8867 printf (_("\nCU table:\n"));
8868 for (i = 0; i < cu_list_elements; i += 2)
8870 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8871 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8873 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8874 (unsigned long) cu_offset,
8875 (unsigned long) (cu_offset + cu_length - 1));
8878 printf (_("\nTU table:\n"));
8879 for (i = 0; i < tu_list_elements; i += 3)
8881 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8882 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8883 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8885 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8886 (unsigned long) tu_offset,
8887 (unsigned long) type_offset);
8888 print_dwarf_vma (signature, 8);
8892 printf (_("\nAddress table:\n"));
8893 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8896 uint64_t low = byte_get_little_endian (address_table + i, 8);
8897 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8898 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8900 print_dwarf_vma (low, 8);
8901 print_dwarf_vma (high, 8);
8902 printf (_("%lu\n"), (unsigned long) cu_index);
8905 printf (_("\nSymbol table:\n"));
8906 for (i = 0; i < symbol_table_slots; ++i)
8908 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8909 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8910 uint32_t num_cus, cu;
8912 if (name_offset != 0
8913 || cu_vector_offset != 0)
8916 unsigned char * adr;
8918 adr = constant_pool + name_offset;
8919 /* PR 17531: file: 5b7b07ad. */
8920 if (adr < constant_pool || adr >= section->start + section->size)
8922 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8923 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8927 printf ("[%3u] %.*s:", i,
8928 (int) (section->size - (constant_pool_offset + name_offset)),
8929 constant_pool + name_offset);
8931 adr = constant_pool + cu_vector_offset;
8932 if (adr < constant_pool || adr >= section->start + section->size - 3)
8934 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8935 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8936 cu_vector_offset, i);
8940 num_cus = byte_get_little_endian (adr, 4);
8942 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8943 if (num_cus * 4 < num_cus
8944 || adr >= section->start + section->size
8945 || adr < constant_pool)
8947 printf ("<invalid number of CUs: %d>\n", num_cus);
8948 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8956 for (j = 0; j < num_cus; ++j)
8959 gdb_index_symbol_kind kind;
8961 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8962 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8963 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8964 cu = GDB_INDEX_CU_VALUE (cu);
8965 /* Convert to TU number if it's for a type unit. */
8966 if (cu >= cu_list_elements / 2)
8967 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8968 (unsigned long) (cu - cu_list_elements / 2));
8970 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8972 printf (" [%s, %s]",
8973 is_static ? _("static") : _("global"),
8974 get_gdb_index_symbol_kind_name (kind));
8986 /* Pre-allocate enough space for the CU/TU sets needed. */
8989 prealloc_cu_tu_list (unsigned int nshndx)
8991 if (shndx_pool == NULL)
8993 shndx_pool_size = nshndx;
8994 shndx_pool_used = 0;
8995 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8996 sizeof (unsigned int));
9000 shndx_pool_size = shndx_pool_used + nshndx;
9001 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
9002 sizeof (unsigned int));
9007 add_shndx_to_cu_tu_entry (unsigned int shndx)
9009 if (shndx_pool_used >= shndx_pool_size)
9011 error (_("Internal error: out of space in the shndx pool.\n"));
9014 shndx_pool [shndx_pool_used++] = shndx;
9018 end_cu_tu_entry (void)
9020 if (shndx_pool_used >= shndx_pool_size)
9022 error (_("Internal error: out of space in the shndx pool.\n"));
9025 shndx_pool [shndx_pool_used++] = 0;
9028 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9031 get_DW_SECT_short_name (unsigned int dw_sect)
9033 static char buf[16];
9041 case DW_SECT_ABBREV:
9047 case DW_SECT_STR_OFFSETS:
9049 case DW_SECT_MACINFO:
9057 snprintf (buf, sizeof (buf), "%d", dw_sect);
9061 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9062 These sections are extensions for Fission.
9063 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9066 process_cu_tu_index (struct dwarf_section *section, int do_display)
9068 unsigned char *phdr = section->start;
9069 unsigned char *limit = phdr + section->size;
9070 unsigned char *phash;
9071 unsigned char *pindex;
9072 unsigned char *ppool;
9073 unsigned int version;
9074 unsigned int ncols = 0;
9076 unsigned int nslots;
9079 dwarf_vma signature_high;
9080 dwarf_vma signature_low;
9083 /* PR 17512: file: 002-168123-0.004. */
9086 warn (_("Section %s is empty\n"), section->name);
9089 /* PR 17512: file: 002-376-0.004. */
9090 if (section->size < 24)
9092 warn (_("Section %s is too small to contain a CU/TU header\n"),
9097 SAFE_BYTE_GET (version, phdr, 4, limit);
9099 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
9100 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
9101 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
9104 pindex = phash + nslots * 8;
9105 ppool = pindex + nslots * 4;
9107 /* PR 17531: file: 45d69832. */
9108 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
9110 warn (ngettext ("Section %s is too small for %d slot\n",
9111 "Section %s is too small for %d slots\n",
9113 section->name, nslots);
9119 introduce (section, FALSE);
9121 printf (_(" Version: %d\n"), version);
9123 printf (_(" Number of columns: %d\n"), ncols);
9124 printf (_(" Number of used entries: %d\n"), nused);
9125 printf (_(" Number of slots: %d\n\n"), nslots);
9128 if (ppool > limit || ppool < phdr)
9130 warn (_("Section %s too small for %d hash table entries\n"),
9131 section->name, nslots);
9138 prealloc_cu_tu_list ((limit - ppool) / 4);
9139 for (i = 0; i < nslots; i++)
9141 unsigned char *shndx_list;
9144 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
9145 if (signature_high != 0 || signature_low != 0)
9147 SAFE_BYTE_GET (j, pindex, 4, limit);
9148 shndx_list = ppool + j * 4;
9149 /* PR 17531: file: 705e010d. */
9150 if (shndx_list < ppool)
9152 warn (_("Section index pool located before start of section\n"));
9157 printf (_(" [%3d] Signature: 0x%s Sections: "),
9158 i, dwarf_vmatoa64 (signature_high, signature_low,
9159 buf, sizeof (buf)));
9162 if (shndx_list >= limit)
9164 warn (_("Section %s too small for shndx pool\n"),
9168 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
9172 printf (" %d", shndx);
9174 add_shndx_to_cu_tu_entry (shndx);
9186 else if (version == 2)
9189 unsigned int dw_sect;
9190 unsigned char *ph = phash;
9191 unsigned char *pi = pindex;
9192 unsigned char *poffsets = ppool + ncols * 4;
9193 unsigned char *psizes = poffsets + nused * ncols * 4;
9194 unsigned char *pend = psizes + nused * ncols * 4;
9195 bfd_boolean is_tu_index;
9196 struct cu_tu_set *this_set = NULL;
9198 unsigned char *prow;
9200 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
9202 /* PR 17531: file: 0dd159bf.
9203 Check for wraparound with an overlarge ncols value. */
9204 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
9206 warn (_("Overlarge number of columns: %x\n"), ncols);
9212 warn (_("Section %s too small for offset and size tables\n"),
9219 printf (_(" Offset table\n"));
9220 printf (" slot %-16s ",
9221 is_tu_index ? _("signature") : _("dwo_id"));
9228 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9234 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9241 for (j = 0; j < ncols; j++)
9243 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9244 printf (" %8s", get_DW_SECT_short_name (dw_sect));
9249 for (i = 0; i < nslots; i++)
9251 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9253 SAFE_BYTE_GET (row, pi, 4, limit);
9256 /* PR 17531: file: a05f6ab3. */
9259 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9265 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
9267 prow = poffsets + (row - 1) * ncols * 4;
9268 /* PR 17531: file: b8ce60a8. */
9269 if (prow < poffsets || prow > limit)
9271 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9277 printf (_(" [%3d] 0x%s"),
9278 i, dwarf_vmatoa64 (signature_high, signature_low,
9279 buf, sizeof (buf)));
9280 for (j = 0; j < ncols; j++)
9282 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9284 printf (" %8d", val);
9287 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9289 /* PR 17531: file: 10796eb3. */
9290 if (dw_sect >= DW_SECT_MAX)
9291 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9293 this_set [row - 1].section_offsets [dw_sect] = val;
9309 printf (_(" Size table\n"));
9310 printf (" slot %-16s ",
9311 is_tu_index ? _("signature") : _("dwo_id"));
9314 for (j = 0; j < ncols; j++)
9316 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
9318 printf (" %8s", get_DW_SECT_short_name (val));
9324 for (i = 0; i < nslots; i++)
9326 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9328 SAFE_BYTE_GET (row, pi, 4, limit);
9331 prow = psizes + (row - 1) * ncols * 4;
9334 printf (_(" [%3d] 0x%s"),
9335 i, dwarf_vmatoa64 (signature_high, signature_low,
9336 buf, sizeof (buf)));
9338 for (j = 0; j < ncols; j++)
9340 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9342 printf (" %8d", val);
9345 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9346 if (dw_sect >= DW_SECT_MAX)
9347 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9349 this_set [row - 1].section_sizes [dw_sect] = val;
9361 else if (do_display)
9362 printf (_(" Unsupported version (%d)\n"), version);
9370 /* Load the CU and TU indexes if present. This will build a list of
9371 section sets that we can use to associate a .debug_info.dwo section
9372 with its associated .debug_abbrev.dwo section in a .dwp file. */
9375 load_cu_tu_indexes (void *file)
9377 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
9379 /* If we have already loaded (or tried to load) the CU and TU indexes
9380 then do not bother to repeat the task. */
9381 if (cu_tu_indexes_read == -1)
9383 cu_tu_indexes_read = TRUE;
9385 if (load_debug_section_with_follow (dwp_cu_index, file))
9386 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
9387 cu_tu_indexes_read = FALSE;
9389 if (load_debug_section_with_follow (dwp_tu_index, file))
9390 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
9391 cu_tu_indexes_read = FALSE;
9394 return (bfd_boolean) cu_tu_indexes_read;
9397 /* Find the set of sections that includes section SHNDX. */
9400 find_cu_tu_set (void *file, unsigned int shndx)
9404 if (! load_cu_tu_indexes (file))
9407 /* Find SHNDX in the shndx pool. */
9408 for (i = 0; i < shndx_pool_used; i++)
9409 if (shndx_pool [i] == shndx)
9412 if (i >= shndx_pool_used)
9415 /* Now backup to find the first entry in the set. */
9416 while (i > 0 && shndx_pool [i - 1] != 0)
9419 return shndx_pool + i;
9422 /* Display a .debug_cu_index or .debug_tu_index section. */
9425 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9427 return process_cu_tu_index (section, 1);
9431 display_debug_not_supported (struct dwarf_section *section,
9432 void *file ATTRIBUTE_UNUSED)
9434 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9440 /* Like malloc, but takes two parameters like calloc.
9441 Verifies that the first parameter is not too large.
9442 Note: does *not* initialise the allocated memory to zero. */
9445 cmalloc (size_t nmemb, size_t size)
9447 /* Check for overflow. */
9448 if (nmemb >= ~(size_t) 0 / size)
9451 return xmalloc (nmemb * size);
9454 /* Like xmalloc, but takes two parameters like calloc.
9455 Verifies that the first parameter is not too large.
9456 Note: does *not* initialise the allocated memory to zero. */
9459 xcmalloc (size_t nmemb, size_t size)
9461 /* Check for overflow. */
9462 if (nmemb >= ~(size_t) 0 / size)
9465 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9470 return xmalloc (nmemb * size);
9473 /* Like xrealloc, but takes three parameters.
9474 Verifies that the second parameter is not too large.
9475 Note: does *not* initialise any new memory to zero. */
9478 xcrealloc (void *ptr, size_t nmemb, size_t size)
9480 /* Check for overflow. */
9481 if (nmemb >= ~(size_t) 0 / size)
9483 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9488 return xrealloc (ptr, nmemb * size);
9491 /* Like xcalloc, but verifies that the first parameter is not too large. */
9494 xcalloc2 (size_t nmemb, size_t size)
9496 /* Check for overflow. */
9497 if (nmemb >= ~(size_t) 0 / size)
9499 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9504 return xcalloc (nmemb, size);
9507 static unsigned long
9508 calc_gnu_debuglink_crc32 (unsigned long crc,
9509 const unsigned char * buf,
9512 static const unsigned long crc32_table[256] =
9514 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9515 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9516 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9517 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9518 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9519 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9520 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9521 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9522 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9523 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9524 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9525 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9526 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9527 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9528 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9529 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9530 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9531 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9532 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9533 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9534 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9535 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9536 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9537 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9538 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9539 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9540 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9541 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9542 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9543 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9544 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9545 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9546 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9547 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9548 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9549 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
9550 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
9551 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
9552 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
9553 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
9554 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
9555 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
9556 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
9557 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
9558 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
9559 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
9560 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
9561 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
9562 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
9563 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
9564 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
9567 const unsigned char *end;
9569 crc = ~crc & 0xffffffff;
9570 for (end = buf + len; buf < end; ++ buf)
9571 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
9572 return ~crc & 0xffffffff;
9575 typedef bfd_boolean (* check_func_type) (const char *, void *);
9576 typedef const char * (* parse_func_type) (struct dwarf_section *, void *);
9579 check_gnu_debuglink (const char * pathname, void * crc_pointer)
9581 static unsigned char buffer [8 * 1024];
9583 bfd_size_type count;
9584 unsigned long crc = 0;
9587 sep_data = open_debug_file (pathname);
9588 if (sep_data == NULL)
9591 /* Yes - we are opening the file twice... */
9592 f = fopen (pathname, "rb");
9595 /* Paranoia: This should never happen. */
9596 close_debug_file (sep_data);
9597 warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
9601 while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
9602 crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
9606 if (crc != * (unsigned long *) crc_pointer)
9608 close_debug_file (sep_data);
9609 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
9618 parse_gnu_debuglink (struct dwarf_section * section, void * data)
9621 unsigned int crc_offset;
9622 unsigned long * crc32 = (unsigned long *) data;
9624 /* The name is first.
9625 The CRC value is stored after the filename, aligned up to 4 bytes. */
9626 name = (const char *) section->start;
9628 crc_offset = strnlen (name, section->size) + 1;
9629 crc_offset = (crc_offset + 3) & ~3;
9630 if (crc_offset + 4 > section->size)
9633 * crc32 = byte_get (section->start + crc_offset, 4);
9638 check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
9640 void * sep_data = open_debug_file (filename);
9642 if (sep_data == NULL)
9645 /* FIXME: We should now extract the build-id in the separate file
9651 typedef struct build_id_data
9654 const unsigned char * data;
9658 parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
9661 bfd_size_type namelen;
9662 bfd_size_type id_len;
9663 Build_id_data * build_id_data;
9665 /* The name is first.
9666 The build-id follows immediately, with no padding, up to the section's end. */
9668 name = (const char *) section->start;
9669 namelen = strnlen (name, section->size) + 1;
9670 if (namelen >= section->size)
9673 id_len = section->size - namelen;
9677 build_id_data = calloc (1, sizeof * build_id_data);
9678 if (build_id_data == NULL)
9681 build_id_data->len = id_len;
9682 build_id_data->data = section->start + namelen;
9684 * (Build_id_data **) data = build_id_data;
9690 load_separate_debug_info (const char * main_filename,
9691 struct dwarf_section * xlink,
9692 parse_func_type parse_func,
9693 check_func_type check_func,
9696 const char * separate_filename;
9699 size_t canon_dirlen;
9702 if ((separate_filename = parse_func (xlink, func_data)) == NULL)
9704 warn (_("Corrupt debuglink section: %s\n"),
9705 xlink->name ? xlink->name : xlink->uncompressed_name);
9709 /* Attempt to locate the separate file.
9710 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
9712 canon_dir = lrealpath (main_filename);
9714 for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
9715 if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
9717 canon_dir[canon_dirlen] = '\0';
9720 #define DEBUGDIR "/lib/debug"
9722 #ifndef EXTRA_DEBUG_ROOT1
9723 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
9725 #ifndef EXTRA_DEBUG_ROOT2
9726 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
9729 debugfile = (char *) malloc (strlen (DEBUGDIR) + 1
9731 + strlen (".debug/")
9732 #ifdef EXTRA_DEBUG_ROOT1
9733 + strlen (EXTRA_DEBUG_ROOT1)
9735 #ifdef EXTRA_DEBUG_ROOT2
9736 + strlen (EXTRA_DEBUG_ROOT2)
9738 + strlen (separate_filename)
9740 if (debugfile == NULL)
9742 warn (_("Out of memory"));
9746 /* First try in the current directory. */
9747 sprintf (debugfile, "%s", separate_filename);
9748 if (check_func (debugfile, func_data))
9751 /* Then try in a subdirectory called .debug. */
9752 sprintf (debugfile, ".debug/%s", separate_filename);
9753 if (check_func (debugfile, func_data))
9756 /* Then try in the same directory as the original file. */
9757 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9758 if (check_func (debugfile, func_data))
9761 /* And the .debug subdirectory of that directory. */
9762 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9763 if (check_func (debugfile, func_data))
9766 #ifdef EXTRA_DEBUG_ROOT1
9767 /* Try the first extra debug file root. */
9768 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9769 if (check_func (debugfile, func_data))
9773 #ifdef EXTRA_DEBUG_ROOT2
9774 /* Try the second extra debug file root. */
9775 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9776 if (check_func (debugfile, func_data))
9780 /* Then try in the global debugfile directory. */
9781 strcpy (debugfile, DEBUGDIR);
9782 dirlen = strlen (DEBUGDIR) - 1;
9783 if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
9784 strcat (debugfile, "/");
9785 strcat (debugfile, (const char *) separate_filename);
9787 if (check_func (debugfile, func_data))
9790 /* Failed to find the file. */
9791 warn (_("could not find separate debug file '%s'\n"), separate_filename);
9792 warn (_("tried: %s\n"), debugfile);
9794 #ifdef EXTRA_DEBUG_ROOT2
9795 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9796 warn (_("tried: %s\n"), debugfile);
9799 #ifdef EXTRA_DEBUG_ROOT1
9800 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9801 warn (_("tried: %s\n"), debugfile);
9804 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9805 warn (_("tried: %s\n"), debugfile);
9807 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9808 warn (_("tried: %s\n"), debugfile);
9810 sprintf (debugfile, ".debug/%s", separate_filename);
9811 warn (_("tried: %s\n"), debugfile);
9813 sprintf (debugfile, "%s", separate_filename);
9814 warn (_("tried: %s\n"), debugfile);
9823 /* Now open the file.... */
9824 if ((separate_debug_file = open_debug_file (debugfile)) == NULL)
9826 warn (_("failed to open separate debug file: %s\n"), debugfile);
9831 /* FIXME: We do not check to see if there are any other separate debug info
9832 files that would also match. */
9834 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debugfile);
9835 separate_debug_filename = debugfile;
9837 /* Do not free debugfile - it might be referenced inside
9838 the structure returned by open_debug_file(). */
9839 return separate_debug_file;
9842 /* Attempt to load a separate dwarf object file. */
9845 load_dwo_file (const char * main_filename)
9849 /* FIXME: Skip adding / if dwo_dir ends in /. */
9850 filename = concat (dwo_dir, "/", dwo_name, NULL);
9851 if (filename == NULL)
9853 warn (_("Out of memory allocating dwo filename\n"));
9857 if ((separate_debug_file = open_debug_file (filename)) == NULL)
9859 warn (_("Unable to load dwo file: %s\n"), filename);
9864 /* FIXME: We should check the dwo_id. */
9866 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, filename);
9867 separate_debug_filename = filename;
9868 return separate_debug_file;
9871 /* Load a separate debug info file, if it exists.
9872 Returns the data pointer that is the result of calling open_debug_file
9873 on the separate debug info file, or NULL if there were problems or there
9877 load_separate_debug_file (void * file, const char * filename)
9879 /* Skip this operation if we are not interested in debug links. */
9880 if (! do_follow_links && ! do_debug_links)
9883 /* See if there is a dwo link. */
9884 if (load_debug_section (str, file)
9885 && load_debug_section (abbrev, file)
9886 && load_debug_section (info, file))
9888 dwo_name = dwo_dir = NULL;
9892 if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE))
9894 if (dwo_name != NULL)
9898 printf (_("The %s section contains a link to a dwo file:\n"),
9899 debug_displays [info].section.uncompressed_name);
9900 printf (_(" Name: %s\n"), dwo_name);
9901 printf (_(" Directory: %s\n"), dwo_dir ? dwo_dir : _("<not-found>"));
9903 display_data (printf (_(" ID: ")), dwo_id, dwo_id_len);
9905 printf (_(" ID: <unknown>\n"));
9909 /* FIXME: We do not check to see if there are any more dwo links in the file... */
9910 if (do_follow_links)
9911 return load_dwo_file (filename);
9916 if (! do_follow_links)
9917 /* The other debug links will be displayed by display_debug_links()
9918 so we do not need to do any further processing here. */
9921 /* FIXME: We do not check for the presence of both link sections in the same file. */
9922 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
9923 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
9924 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
9926 if (load_debug_section (gnu_debugaltlink, file))
9928 Build_id_data * build_id_data;
9930 return load_separate_debug_info (filename,
9931 & debug_displays[gnu_debugaltlink].section,
9932 parse_gnu_debugaltlink,
9933 check_gnu_debugaltlink,
9937 if (load_debug_section (gnu_debuglink, file))
9939 unsigned long crc32;
9941 return load_separate_debug_info (filename,
9942 & debug_displays[gnu_debuglink].section,
9943 parse_gnu_debuglink,
9944 check_gnu_debuglink,
9948 do_follow_links = 0;
9953 free_debug_memory (void)
9959 for (i = 0; i < max; i++)
9960 free_debug_section ((enum dwarf_section_display_enum) i);
9962 if (debug_information != NULL)
9964 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
9966 for (i = 0; i < num_debug_info_entries; i++)
9968 if (!debug_information [i].max_loc_offsets)
9970 free (debug_information [i].loc_offsets);
9971 free (debug_information [i].have_frame_base);
9973 if (!debug_information [i].max_range_lists)
9974 free (debug_information [i].range_lists);
9977 free (debug_information);
9978 debug_information = NULL;
9979 alloc_num_debug_info_entries = num_debug_info_entries = 0;
9982 if (separate_debug_file != NULL)
9984 close_debug_file (separate_debug_file);
9985 separate_debug_file = NULL;
9987 free ((void *) separate_debug_filename);
9988 separate_debug_filename = NULL;
9993 dwarf_select_sections_by_names (const char *names)
9997 const char * option;
10001 debug_dump_long_opts;
10003 static const debug_dump_long_opts opts_table [] =
10005 /* Please keep this table alpha- sorted. */
10006 { "Ranges", & do_debug_ranges, 1 },
10007 { "abbrev", & do_debug_abbrevs, 1 },
10008 { "addr", & do_debug_addr, 1 },
10009 { "aranges", & do_debug_aranges, 1 },
10010 { "cu_index", & do_debug_cu_index, 1 },
10011 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
10012 { "follow-links", & do_follow_links, 1 },
10013 { "frames", & do_debug_frames, 1 },
10014 { "frames-interp", & do_debug_frames_interp, 1 },
10015 /* The special .gdb_index section. */
10016 { "gdb_index", & do_gdb_index, 1 },
10017 { "info", & do_debug_info, 1 },
10018 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
10019 { "links", & do_debug_links, 1 },
10020 { "loc", & do_debug_loc, 1 },
10021 { "macro", & do_debug_macinfo, 1 },
10022 { "pubnames", & do_debug_pubnames, 1 },
10023 { "pubtypes", & do_debug_pubtypes, 1 },
10024 /* This entry is for compatibility
10025 with earlier versions of readelf. */
10026 { "ranges", & do_debug_aranges, 1 },
10027 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
10028 { "str", & do_debug_str, 1 },
10029 /* These trace_* sections are used by Itanium VMS. */
10030 { "trace_abbrev", & do_trace_abbrevs, 1 },
10031 { "trace_aranges", & do_trace_aranges, 1 },
10032 { "trace_info", & do_trace_info, 1 },
10041 const debug_dump_long_opts * entry;
10043 for (entry = opts_table; entry->option; entry++)
10045 size_t len = strlen (entry->option);
10047 if (strncmp (p, entry->option, len) == 0
10048 && (p[len] == ',' || p[len] == '\0'))
10050 * entry->variable |= entry->val;
10052 /* The --debug-dump=frames-interp option also
10053 enables the --debug-dump=frames option. */
10054 if (do_debug_frames_interp)
10055 do_debug_frames = 1;
10062 if (entry->option == NULL)
10064 warn (_("Unrecognized debug option '%s'\n"), p);
10065 p = strchr (p, ',');
10076 dwarf_select_sections_by_letters (const char *letters)
10078 unsigned int lindex = 0;
10080 while (letters[lindex])
10081 switch (letters[lindex++])
10083 case 'A': do_debug_addr = 1; break;
10084 case 'a': do_debug_abbrevs = 1; break;
10085 case 'c': do_debug_cu_index = 1; break;
10086 case 'F': do_debug_frames_interp = 1; /* Fall through. */
10087 case 'f': do_debug_frames = 1; break;
10088 case 'g': do_gdb_index = 1; break;
10089 case 'i': do_debug_info = 1; break;
10090 case 'K': do_follow_links = 1; break;
10091 case 'k': do_debug_links = 1; break;
10092 case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
10093 case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
10094 case 'm': do_debug_macinfo = 1; break;
10095 case 'o': do_debug_loc = 1; break;
10096 case 'p': do_debug_pubnames = 1; break;
10097 case 'R': do_debug_ranges = 1; break;
10098 case 'r': do_debug_aranges = 1; break;
10099 case 's': do_debug_str = 1; break;
10100 case 'T': do_trace_aranges = 1; break;
10101 case 't': do_debug_pubtypes = 1; break;
10102 case 'U': do_trace_info = 1; break;
10103 case 'u': do_trace_abbrevs = 1; break;
10106 warn (_("Unrecognized debug option '%s'\n"), letters);
10112 dwarf_select_sections_all (void)
10115 do_debug_abbrevs = 1;
10116 do_debug_lines = FLAG_DEBUG_LINES_RAW;
10117 do_debug_pubnames = 1;
10118 do_debug_pubtypes = 1;
10119 do_debug_aranges = 1;
10120 do_debug_ranges = 1;
10121 do_debug_frames = 1;
10122 do_debug_macinfo = 1;
10127 do_trace_abbrevs = 1;
10128 do_trace_aranges = 1;
10130 do_debug_cu_index = 1;
10131 do_follow_links = 1;
10132 do_debug_links = 1;
10135 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10136 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10138 /* N.B. The order here must match the order in section_display_enum. */
10140 struct dwarf_section_display debug_displays[] =
10142 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
10143 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE },
10144 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
10145 { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE },
10146 { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
10147 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE },
10148 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
10149 { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
10150 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
10151 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
10152 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10153 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10154 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10155 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10156 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE },
10157 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
10158 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
10159 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
10160 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10161 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10162 { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE },
10163 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10164 { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE },
10165 { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE },
10166 { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE },
10167 { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE },
10168 { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE },
10169 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE },
10170 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
10171 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE },
10172 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
10173 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10174 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
10175 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
10176 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE },
10177 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
10178 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
10179 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE },
10180 { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
10181 { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
10182 { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
10183 { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
10184 /* Separate debug info files can containt their own .debug_str section,
10185 and this might be in *addition* to a .debug_str section already present
10186 in the main file. Hence we need to have two entries for .debug_str. */
10187 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10190 /* A static assertion. */
10191 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];