1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2017 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
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]"));
2593 if (form == DW_FORM_ref_sig8
2594 || form == DW_FORM_GNU_ref_alt)
2597 if (form == DW_FORM_ref1
2598 || form == DW_FORM_ref2
2599 || form == DW_FORM_ref4
2600 || form == DW_FORM_ref_udata)
2601 uvalue += cu_offset;
2603 if (uvalue >= section->size)
2604 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2605 dwarf_vmatoa ("x", uvalue),
2606 (unsigned long) (orig_data - section->start));
2609 unsigned long abbrev_number;
2610 abbrev_entry * entry;
2612 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2614 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2615 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2616 use different abbrev table, and we don't track .debug_info chunks
2618 if (form != DW_FORM_ref_addr)
2620 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2621 if (entry->entry == abbrev_number)
2624 printf (" (%s)", get_TAG_name (entry->tag));
2638 static unsigned char *
2639 read_and_display_attr (unsigned long attribute,
2641 dwarf_signed_vma implicit_const,
2642 unsigned char * data,
2643 unsigned char * end,
2644 dwarf_vma cu_offset,
2645 dwarf_vma pointer_size,
2646 dwarf_vma offset_size,
2648 debug_info * debug_info_p,
2650 struct dwarf_section * section,
2651 struct cu_tu_set * this_set)
2654 printf (" %-18s:", get_AT_name (attribute));
2655 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2656 cu_offset, pointer_size, offset_size,
2657 dwarf_version, debug_info_p,
2658 do_loc, section, this_set, ' ');
2664 /* Like load_debug_section, but if the ordinary call fails, and we are
2665 following debug links, and we have been able to load a separate debug
2666 info file, then attempt to load the requested section from the separate
2670 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
2673 if (load_debug_section (sec_enum, data))
2675 if (data == separate_debug_file)
2676 debug_displays[sec_enum].section.filename = separate_debug_filename;
2678 /* FIXME: We should check to see if there is a separate debug info file
2679 that also contains this section, and if so, issue a warning. */
2683 if (do_follow_links && separate_debug_file != NULL)
2684 if (load_debug_section (sec_enum, separate_debug_file))
2686 debug_displays[sec_enum].section.filename = separate_debug_filename;
2694 introduce (struct dwarf_section * section, bfd_boolean raw)
2698 if (do_follow_links && section->filename)
2699 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
2700 section->name, section->filename);
2702 printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
2706 if (do_follow_links && section->filename)
2707 printf (_("Contents of the %s section (loaded from %s):\n\n"),
2708 section->name, section->filename);
2710 printf (_("Contents of the %s section:\n\n"), section->name);
2714 /* Process the contents of a .debug_info section.
2715 If do_loc is TRUE then we are scanning for location lists and dwo tags
2716 and we do not want to display anything to the user.
2717 If do_types is TRUE, we are processing a .debug_types section instead of
2718 a .debug_info section.
2719 The information displayed is restricted by the values in DWARF_START_DIE
2720 and DWARF_CUTOFF_LEVEL.
2721 Returns TRUE upon success. Otherwise an error or warning message is
2722 printed and FALSE is returned. */
2725 process_debug_info (struct dwarf_section * section,
2727 enum dwarf_section_display_enum abbrev_sec,
2729 bfd_boolean do_types)
2731 unsigned char *start = section->start;
2732 unsigned char *end = start + section->size;
2733 unsigned char *section_begin;
2735 unsigned int num_units = 0;
2737 if ((do_loc || do_debug_loc || do_debug_ranges)
2738 && num_debug_info_entries == 0
2743 /* First scan the section to get the number of comp units. */
2744 for (section_begin = start, num_units = 0; section_begin < end;
2747 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2748 will be the length. For a 64-bit DWARF section, it'll be
2749 the escape code 0xffffffff followed by an 8 byte length. */
2750 SAFE_BYTE_GET (length, section_begin, 4, end);
2752 if (length == 0xffffffff)
2754 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2755 section_begin += length + 12;
2757 else if (length >= 0xfffffff0 && length < 0xffffffff)
2759 warn (_("Reserved length value (0x%s) found in section %s\n"),
2760 dwarf_vmatoa ("x", length), section->name);
2764 section_begin += length + 4;
2766 /* Negative values are illegal, they may even cause infinite
2767 looping. This can happen if we can't accurately apply
2768 relocations to an object file, or if the file is corrupt. */
2769 if ((signed long) length <= 0 || section_begin < start)
2771 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2772 dwarf_vmatoa ("x", length), section->name);
2779 error (_("No comp units in %s section ?\n"), section->name);
2783 /* Then allocate an array to hold the information. */
2784 debug_information = (debug_info *) cmalloc (num_units,
2785 sizeof (* debug_information));
2786 if (debug_information == NULL)
2788 error (_("Not enough memory for a debug info array of %u entries\n"),
2790 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2794 /* PR 17531: file: 92ca3797.
2795 We cannot rely upon the debug_information array being initialised
2796 before it is used. A corrupt file could easily contain references
2797 to a unit for which information has not been made available. So
2798 we ensure that the array is zeroed here. */
2799 memset (debug_information, 0, num_units * sizeof (*debug_information));
2801 alloc_num_debug_info_entries = num_units;
2806 load_debug_section_with_follow (str, file);
2807 load_debug_section_with_follow (line_str, file);
2808 load_debug_section_with_follow (str_dwo, file);
2809 load_debug_section_with_follow (str_index, file);
2810 load_debug_section_with_follow (str_index_dwo, file);
2811 load_debug_section_with_follow (debug_addr, file);
2814 load_debug_section_with_follow (abbrev_sec, file);
2815 if (debug_displays [abbrev_sec].section.start == NULL)
2817 warn (_("Unable to locate %s section!\n"),
2818 debug_displays [abbrev_sec].section.uncompressed_name);
2822 if (!do_loc && dwarf_start_die == 0)
2823 introduce (section, FALSE);
2825 for (section_begin = start, unit = 0; start < end; unit++)
2827 DWARF2_Internal_CompUnit compunit;
2828 unsigned char *hdrptr;
2829 unsigned char *tags;
2830 int level, last_level, saved_level;
2831 dwarf_vma cu_offset;
2832 unsigned long sec_off;
2833 unsigned int offset_size;
2834 unsigned int initial_length_size;
2835 dwarf_vma signature_high = 0;
2836 dwarf_vma signature_low = 0;
2837 dwarf_vma type_offset = 0;
2838 struct cu_tu_set *this_set;
2839 dwarf_vma abbrev_base;
2844 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2846 if (compunit.cu_length == 0xffffffff)
2848 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2850 initial_length_size = 12;
2855 initial_length_size = 4;
2858 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2860 cu_offset = start - section_begin;
2862 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2864 if (compunit.cu_version < 5)
2866 compunit.cu_unit_type = DW_UT_compile;
2867 /* Initialize it due to a false compiler warning. */
2868 compunit.cu_pointer_size = -1;
2872 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2873 do_types = (compunit.cu_unit_type == DW_UT_type);
2875 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2878 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2880 if (this_set == NULL)
2883 abbrev_size = debug_displays [abbrev_sec].section.size;
2887 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2888 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2891 if (compunit.cu_version < 5)
2892 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2894 /* PR 17512: file: 001-108546-0.001:0.1. */
2895 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2897 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2898 compunit.cu_pointer_size, offset_size);
2899 compunit.cu_pointer_size = offset_size;
2904 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2906 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2909 if (dwarf_start_die > (cu_offset + compunit.cu_length
2910 + initial_length_size))
2912 start = section_begin + cu_offset + compunit.cu_length
2913 + initial_length_size;
2917 if ((do_loc || do_debug_loc || do_debug_ranges)
2918 && num_debug_info_entries == 0
2921 debug_information [unit].cu_offset = cu_offset;
2922 debug_information [unit].pointer_size
2923 = compunit.cu_pointer_size;
2924 debug_information [unit].offset_size = offset_size;
2925 debug_information [unit].dwarf_version = compunit.cu_version;
2926 debug_information [unit].base_address = 0;
2927 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2928 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2929 debug_information [unit].loc_offsets = NULL;
2930 debug_information [unit].have_frame_base = NULL;
2931 debug_information [unit].max_loc_offsets = 0;
2932 debug_information [unit].num_loc_offsets = 0;
2933 debug_information [unit].range_lists = NULL;
2934 debug_information [unit].max_range_lists= 0;
2935 debug_information [unit].num_range_lists = 0;
2938 if (!do_loc && dwarf_start_die == 0)
2940 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2941 dwarf_vmatoa ("x", cu_offset));
2942 printf (_(" Length: 0x%s (%s)\n"),
2943 dwarf_vmatoa ("x", compunit.cu_length),
2944 offset_size == 8 ? "64-bit" : "32-bit");
2945 printf (_(" Version: %d\n"), compunit.cu_version);
2946 printf (_(" Abbrev Offset: 0x%s\n"),
2947 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2948 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2953 printf (_(" Signature: 0x%s\n"),
2954 dwarf_vmatoa64 (signature_high, signature_low,
2955 buf, sizeof (buf)));
2956 printf (_(" Type Offset: 0x%s\n"),
2957 dwarf_vmatoa ("x", type_offset));
2959 if (this_set != NULL)
2961 dwarf_vma *offsets = this_set->section_offsets;
2962 size_t *sizes = this_set->section_sizes;
2964 printf (_(" Section contributions:\n"));
2965 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2966 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2967 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2968 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2969 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2970 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2971 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2972 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2973 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2974 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2975 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2976 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2980 sec_off = cu_offset + initial_length_size;
2981 if (sec_off + compunit.cu_length < sec_off
2982 || sec_off + compunit.cu_length > section->size)
2984 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
2986 (unsigned long) cu_offset,
2987 dwarf_vmatoa ("x", compunit.cu_length));
2993 start += compunit.cu_length + initial_length_size;
2995 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2997 warn (_("CU at offset %s contains corrupt or "
2998 "unsupported version number: %d.\n"),
2999 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
3003 if (compunit.cu_unit_type != DW_UT_compile
3004 && compunit.cu_unit_type != DW_UT_type)
3006 warn (_("CU at offset %s contains corrupt or "
3007 "unsupported unit type: %d.\n"),
3008 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
3014 /* Process the abbrevs used by this compilation unit. */
3015 if (compunit.cu_abbrev_offset >= abbrev_size)
3016 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3017 (unsigned long) compunit.cu_abbrev_offset,
3018 (unsigned long) abbrev_size);
3019 /* PR 17531: file:4bcd9ce9. */
3020 else if ((abbrev_base + abbrev_size)
3021 > debug_displays [abbrev_sec].section.size)
3022 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3023 (unsigned long) abbrev_base + abbrev_size,
3024 (unsigned long) debug_displays [abbrev_sec].section.size);
3026 process_abbrev_section
3027 (((unsigned char *) debug_displays [abbrev_sec].section.start
3028 + abbrev_base + compunit.cu_abbrev_offset),
3029 ((unsigned char *) debug_displays [abbrev_sec].section.start
3030 + abbrev_base + abbrev_size));
3035 while (tags < start)
3037 unsigned int bytes_read;
3038 unsigned long abbrev_number;
3039 unsigned long die_offset;
3040 abbrev_entry *entry;
3042 int do_printing = 1;
3044 die_offset = tags - section_begin;
3046 abbrev_number = read_uleb128 (tags, & bytes_read, start);
3049 /* A null DIE marks the end of a list of siblings or it may also be
3050 a section padding. */
3051 if (abbrev_number == 0)
3053 /* Check if it can be a section padding for the last CU. */
3054 if (level == 0 && start == end)
3058 for (chk = tags; chk < start; chk++)
3065 if (!do_loc && die_offset >= dwarf_start_die
3066 && (dwarf_cutoff_level == -1
3067 || level < dwarf_cutoff_level))
3068 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3074 static unsigned num_bogus_warns = 0;
3076 if (num_bogus_warns < 3)
3078 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3079 die_offset, section->name);
3081 if (num_bogus_warns == 3)
3082 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3085 if (dwarf_start_die != 0 && level < saved_level)
3092 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
3096 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
3097 saved_level = level;
3098 do_printing = (dwarf_cutoff_level == -1
3099 || level < dwarf_cutoff_level);
3101 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3102 level, die_offset, abbrev_number);
3103 else if (dwarf_cutoff_level == -1
3104 || last_level < dwarf_cutoff_level)
3105 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
3110 /* Scan through the abbreviation list until we reach the
3112 for (entry = first_abbrev;
3113 entry && entry->entry != abbrev_number;
3114 entry = entry->next)
3119 if (!do_loc && do_printing)
3124 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3125 die_offset, abbrev_number);
3129 if (!do_loc && do_printing)
3130 printf (" (%s)\n", get_TAG_name (entry->tag));
3135 need_base_address = 0;
3137 case DW_TAG_compile_unit:
3138 need_base_address = 1;
3139 need_dwo_info = do_loc;
3141 case DW_TAG_entry_point:
3142 case DW_TAG_subprogram:
3143 need_base_address = 0;
3144 /* Assuming that there is no DW_AT_frame_base. */
3145 have_frame_base = 0;
3149 debug_info *debug_info_p =
3150 (debug_information && unit < alloc_num_debug_info_entries)
3151 ? debug_information + unit : NULL;
3153 assert (!debug_info_p
3154 || (debug_info_p->num_loc_offsets
3155 == debug_info_p->num_loc_views));
3157 for (attr = entry->first_attr;
3158 attr && attr->attribute;
3161 if (! do_loc && do_printing)
3162 /* Show the offset from where the tag was extracted. */
3163 printf (" <%lx>", (unsigned long)(tags - section_begin));
3165 tags = read_and_display_attr (attr->attribute,
3167 attr->implicit_const,
3171 compunit.cu_pointer_size,
3173 compunit.cu_version,
3175 do_loc || ! do_printing,
3180 /* If a locview attribute appears before a location one,
3181 make sure we don't associate it with an earlier
3184 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
3187 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
3188 debug_info_p->num_loc_views++;
3189 assert (debug_info_p->num_loc_views
3190 == debug_info_p->num_loc_offsets);
3197 warn(_("DIE has locviews without loclist\n"));
3198 debug_info_p->num_loc_views--;
3205 if (entry->children)
3210 /* Set num_debug_info_entries here so that it can be used to check if
3211 we need to process .debug_loc and .debug_ranges sections. */
3212 if ((do_loc || do_debug_loc || do_debug_ranges)
3213 && num_debug_info_entries == 0
3216 if (num_units > alloc_num_debug_info_entries)
3217 num_debug_info_entries = alloc_num_debug_info_entries;
3219 num_debug_info_entries = num_units;
3228 /* Locate and scan the .debug_info section in the file and record the pointer
3229 sizes and offsets for the compilation units in it. Usually an executable
3230 will have just one pointer size, but this is not guaranteed, and so we try
3231 not to make any assumptions. Returns zero upon failure, or the number of
3232 compilation units upon success. */
3235 load_debug_info (void * file)
3237 /* If we have already tried and failed to load the .debug_info
3238 section then do not bother to repeat the task. */
3239 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3242 /* If we already have the information there is nothing else to do. */
3243 if (num_debug_info_entries > 0)
3244 return num_debug_info_entries;
3246 /* If this is a DWARF package file, load the CU and TU indexes. */
3247 (void) load_cu_tu_indexes (file);
3249 if (load_debug_section_with_follow (info, file)
3250 && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE))
3251 return num_debug_info_entries;
3253 if (load_debug_section_with_follow (info_dwo, file)
3254 && process_debug_info (&debug_displays [info_dwo].section, file,
3255 abbrev_dwo, TRUE, FALSE))
3256 return num_debug_info_entries;
3258 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
3262 /* Read a DWARF .debug_line section header starting at DATA.
3263 Upon success returns an updated DATA pointer and the LINFO
3264 structure and the END_OF_SEQUENCE pointer will be filled in.
3265 Otherwise returns NULL. */
3267 static unsigned char *
3268 read_debug_line_header (struct dwarf_section * section,
3269 unsigned char * data,
3270 unsigned char * end,
3271 DWARF2_Internal_LineInfo * linfo,
3272 unsigned char ** end_of_sequence)
3274 unsigned char *hdrptr;
3275 unsigned int initial_length_size;
3276 unsigned char address_size, segment_selector_size;
3278 /* Extract information from the Line Number Program Header.
3279 (section 6.2.4 in the Dwarf3 doc). */
3282 /* Get and check the length of the block. */
3283 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
3285 if (linfo->li_length == 0xffffffff)
3287 /* This section is 64-bit DWARF 3. */
3288 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
3289 linfo->li_offset_size = 8;
3290 initial_length_size = 12;
3294 linfo->li_offset_size = 4;
3295 initial_length_size = 4;
3298 if (linfo->li_length + initial_length_size > section->size)
3300 /* If the length field has a relocation against it, then we should
3301 not complain if it is inaccurate (and probably negative). This
3302 happens in object files when the .debug_line section is actually
3303 comprised of several different .debug_line.* sections, (some of
3304 which may be removed by linker garbage collection), and a relocation
3305 is used to compute the correct length once that is done. */
3306 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
3308 linfo->li_length = (end - data) - initial_length_size;
3312 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3313 (long) linfo->li_length);
3318 /* Get and check the version number. */
3319 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3321 if (linfo->li_version != 2
3322 && linfo->li_version != 3
3323 && linfo->li_version != 4
3324 && linfo->li_version != 5)
3326 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3327 "is currently supported.\n"));
3331 if (linfo->li_version >= 5)
3333 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3335 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3336 if (segment_selector_size != 0)
3338 warn (_("The %s section contains "
3339 "unsupported segment selector size: %d.\n"),
3340 section->name, segment_selector_size);
3345 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3346 linfo->li_offset_size, end);
3347 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3349 if (linfo->li_version >= 4)
3351 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3353 if (linfo->li_max_ops_per_insn == 0)
3355 warn (_("Invalid maximum operations per insn.\n"));
3360 linfo->li_max_ops_per_insn = 1;
3362 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3363 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3364 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3365 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3367 * end_of_sequence = data + linfo->li_length + initial_length_size;
3368 /* PR 17512: file:002-117414-0.004. */
3369 if (* end_of_sequence > end)
3371 warn (_("Line length %s extends beyond end of section\n"),
3372 dwarf_vmatoa ("u", linfo->li_length));
3373 * end_of_sequence = end;
3380 static unsigned char *
3381 display_formatted_table (unsigned char * data,
3382 unsigned char * start,
3383 unsigned char * end,
3384 const DWARF2_Internal_LineInfo * linfo,
3385 struct dwarf_section * section,
3388 unsigned char *format_start, format_count, *format, formati;
3389 dwarf_vma data_count, datai;
3390 unsigned int bytes_read, namepass, last_entry = 0;
3392 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3393 format_start = data;
3394 for (formati = 0; formati < format_count; formati++)
3396 read_uleb128 (data, & bytes_read, end);
3398 read_uleb128 (data, & bytes_read, end);
3402 warn (_("Corrupt %s format table entry\n"), what);
3407 data_count = read_uleb128 (data, & bytes_read, end);
3411 warn (_("Corrupt %s list\n"), what);
3415 if (data_count == 0)
3417 printf (_("\n The %s Table is empty.\n"), what);
3421 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3422 (long)(data - start));
3424 printf (_(" Entry"));
3425 /* Delay displaying name as the last entry for better screen layout. */
3426 for (namepass = 0; namepass < 2; namepass++)
3428 format = format_start;
3429 for (formati = 0; formati < format_count; formati++)
3431 dwarf_vma content_type;
3433 content_type = read_uleb128 (format, & bytes_read, end);
3434 format += bytes_read;
3435 if ((content_type == DW_LNCT_path) == (namepass == 1))
3436 switch (content_type)
3439 printf (_("\tName"));
3441 case DW_LNCT_directory_index:
3442 printf (_("\tDir"));
3444 case DW_LNCT_timestamp:
3445 printf (_("\tTime"));
3448 printf (_("\tSize"));
3451 printf (_("\tMD5"));
3454 printf (_("\t(Unknown format content type %s)"),
3455 dwarf_vmatoa ("u", content_type));
3457 read_uleb128 (format, & bytes_read, end);
3458 format += bytes_read;
3463 for (datai = 0; datai < data_count; datai++)
3465 unsigned char *datapass = data;
3467 printf (" %d", last_entry++);
3468 /* Delay displaying name as the last entry for better screen layout. */
3469 for (namepass = 0; namepass < 2; namepass++)
3471 format = format_start;
3473 for (formati = 0; formati < format_count; formati++)
3475 dwarf_vma content_type, form;
3477 content_type = read_uleb128 (format, & bytes_read, end);
3478 format += bytes_read;
3479 form = read_uleb128 (format, & bytes_read, end);
3480 format += bytes_read;
3481 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3482 linfo->li_offset_size,
3483 linfo->li_version, NULL,
3484 ((content_type == DW_LNCT_path) != (namepass == 1)),
3485 section, NULL, '\t');
3490 warn (_("Corrupt %s entries list\n"), what);
3499 display_debug_lines_raw (struct dwarf_section * section,
3500 unsigned char * data,
3501 unsigned char * end,
3504 unsigned char *start = section->start;
3505 int verbose_view = 0;
3507 introduce (section, TRUE);
3511 static DWARF2_Internal_LineInfo saved_linfo;
3512 DWARF2_Internal_LineInfo linfo;
3513 unsigned char *standard_opcodes;
3514 unsigned char *end_of_sequence;
3517 if (const_strneq (section->name, ".debug_line.")
3518 /* Note: the following does not apply to .debug_line.dwo sections.
3519 These are full debug_line sections. */
3520 && strcmp (section->name, ".debug_line.dwo") != 0)
3522 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3523 section containing just the Line Number Statements. They are
3524 created by the assembler and intended to be used alongside gcc's
3525 -ffunction-sections command line option. When the linker's
3526 garbage collection decides to discard a .text.<foo> section it
3527 can then also discard the line number information in .debug_line.<foo>.
3529 Since the section is a fragment it does not have the details
3530 needed to fill out a LineInfo structure, so instead we use the
3531 details from the last full debug_line section that we processed. */
3532 end_of_sequence = end;
3533 standard_opcodes = NULL;
3534 linfo = saved_linfo;
3535 /* PR 17531: file: 0522b371. */
3536 if (linfo.li_line_range == 0)
3538 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3541 reset_state_machine (linfo.li_default_is_stmt);
3545 unsigned char * hdrptr;
3547 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3548 & end_of_sequence)) == NULL)
3551 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3552 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3553 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3554 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3555 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3556 if (linfo.li_version >= 4)
3557 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3558 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3559 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3560 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3561 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3563 /* PR 17512: file: 1665-6428-0.004. */
3564 if (linfo.li_line_range == 0)
3566 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3567 linfo.li_line_range = 1;
3570 reset_state_machine (linfo.li_default_is_stmt);
3572 /* Display the contents of the Opcodes table. */
3573 standard_opcodes = hdrptr;
3575 /* PR 17512: file: 002-417945-0.004. */
3576 if (standard_opcodes + linfo.li_opcode_base >= end)
3578 warn (_("Line Base extends beyond end of section\n"));
3582 printf (_("\n Opcodes:\n"));
3584 for (i = 1; i < linfo.li_opcode_base; i++)
3585 printf (ngettext (" Opcode %d has %d arg\n",
3586 " Opcode %d has %d args\n",
3587 standard_opcodes[i - 1]),
3588 i, standard_opcodes[i - 1]);
3590 /* Display the contents of the Directory table. */
3591 data = standard_opcodes + linfo.li_opcode_base - 1;
3593 if (linfo.li_version >= 5)
3595 load_debug_section_with_follow (line_str, file);
3597 data = display_formatted_table (data, start, end, &linfo, section,
3599 data = display_formatted_table (data, start, end, &linfo, section,
3605 printf (_("\n The Directory Table is empty.\n"));
3608 unsigned int last_dir_entry = 0;
3610 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3611 (long)(data - start));
3613 while (data < end && *data != 0)
3615 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3617 data += strnlen ((char *) data, end - data) + 1;
3620 /* PR 17512: file: 002-132094-0.004. */
3621 if (data >= end - 1)
3625 /* Skip the NUL at the end of the table. */
3628 /* Display the contents of the File Name table. */
3630 printf (_("\n The File Name Table is empty.\n"));
3633 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3634 (long)(data - start));
3635 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3637 while (data < end && *data != 0)
3639 unsigned char *name;
3640 unsigned int bytes_read;
3642 printf (" %d\t", ++state_machine_regs.last_file_entry);
3644 data += strnlen ((char *) data, end - data) + 1;
3647 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3650 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3653 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3655 printf ("%.*s\n", (int)(end - name), name);
3659 warn (_("Corrupt file name table entry\n"));
3665 /* Skip the NUL at the end of the table. */
3670 saved_linfo = linfo;
3673 /* Now display the statements. */
3674 if (data >= end_of_sequence)
3675 printf (_(" No Line Number Statements.\n"));
3678 printf (_(" Line Number Statements:\n"));
3680 while (data < end_of_sequence)
3682 unsigned char op_code;
3683 dwarf_signed_vma adv;
3685 unsigned int bytes_read;
3687 printf (" [0x%08lx]", (long)(data - start));
3691 if (op_code >= linfo.li_opcode_base)
3693 op_code -= linfo.li_opcode_base;
3694 uladv = (op_code / linfo.li_line_range);
3695 if (linfo.li_max_ops_per_insn == 1)
3697 uladv *= linfo.li_min_insn_length;
3698 state_machine_regs.address += uladv;
3700 state_machine_regs.view = 0;
3701 printf (_(" Special opcode %d: "
3702 "advance Address by %s to 0x%s%s"),
3703 op_code, dwarf_vmatoa ("u", uladv),
3704 dwarf_vmatoa ("x", state_machine_regs.address),
3705 verbose_view && uladv
3706 ? _(" (reset view)") : "");
3711 = ((state_machine_regs.op_index + uladv)
3712 / linfo.li_max_ops_per_insn)
3713 * linfo.li_min_insn_length;
3715 state_machine_regs.address += addrdelta;
3716 state_machine_regs.op_index
3717 = (state_machine_regs.op_index + uladv)
3718 % linfo.li_max_ops_per_insn;
3720 state_machine_regs.view = 0;
3721 printf (_(" Special opcode %d: "
3722 "advance Address by %s to 0x%s[%d]%s"),
3723 op_code, dwarf_vmatoa ("u", uladv),
3724 dwarf_vmatoa ("x", state_machine_regs.address),
3725 state_machine_regs.op_index,
3726 verbose_view && addrdelta
3727 ? _(" (reset view)") : "");
3729 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3730 state_machine_regs.line += adv;
3731 printf (_(" and Line by %s to %d"),
3732 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3733 if (verbose_view || state_machine_regs.view)
3734 printf (_(" (view %u)\n"), state_machine_regs.view);
3737 state_machine_regs.view++;
3739 else switch (op_code)
3741 case DW_LNS_extended_op:
3742 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3746 printf (_(" Copy"));
3747 if (verbose_view || state_machine_regs.view)
3748 printf (_(" (view %u)\n"), state_machine_regs.view);
3751 state_machine_regs.view++;
3754 case DW_LNS_advance_pc:
3755 uladv = read_uleb128 (data, & bytes_read, end);
3757 if (linfo.li_max_ops_per_insn == 1)
3759 uladv *= linfo.li_min_insn_length;
3760 state_machine_regs.address += uladv;
3762 state_machine_regs.view = 0;
3763 printf (_(" Advance PC by %s to 0x%s%s\n"),
3764 dwarf_vmatoa ("u", uladv),
3765 dwarf_vmatoa ("x", state_machine_regs.address),
3766 verbose_view && uladv
3767 ? _(" (reset view)") : "");
3772 = ((state_machine_regs.op_index + uladv)
3773 / linfo.li_max_ops_per_insn)
3774 * linfo.li_min_insn_length;
3775 state_machine_regs.address
3777 state_machine_regs.op_index
3778 = (state_machine_regs.op_index + uladv)
3779 % linfo.li_max_ops_per_insn;
3781 state_machine_regs.view = 0;
3782 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3783 dwarf_vmatoa ("u", uladv),
3784 dwarf_vmatoa ("x", state_machine_regs.address),
3785 state_machine_regs.op_index,
3786 verbose_view && addrdelta
3787 ? _(" (reset view)") : "");
3791 case DW_LNS_advance_line:
3792 adv = read_sleb128 (data, & bytes_read, end);
3794 state_machine_regs.line += adv;
3795 printf (_(" Advance Line by %s to %d\n"),
3796 dwarf_vmatoa ("d", adv),
3797 state_machine_regs.line);
3800 case DW_LNS_set_file:
3801 adv = read_uleb128 (data, & bytes_read, end);
3803 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3804 dwarf_vmatoa ("d", adv));
3805 state_machine_regs.file = adv;
3808 case DW_LNS_set_column:
3809 uladv = read_uleb128 (data, & bytes_read, end);
3811 printf (_(" Set column to %s\n"),
3812 dwarf_vmatoa ("u", uladv));
3813 state_machine_regs.column = uladv;
3816 case DW_LNS_negate_stmt:
3817 adv = state_machine_regs.is_stmt;
3819 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3820 state_machine_regs.is_stmt = adv;
3823 case DW_LNS_set_basic_block:
3824 printf (_(" Set basic block\n"));
3825 state_machine_regs.basic_block = 1;
3828 case DW_LNS_const_add_pc:
3829 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3830 if (linfo.li_max_ops_per_insn)
3832 uladv *= linfo.li_min_insn_length;
3833 state_machine_regs.address += uladv;
3835 state_machine_regs.view = 0;
3836 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3837 dwarf_vmatoa ("u", uladv),
3838 dwarf_vmatoa ("x", state_machine_regs.address),
3839 verbose_view && uladv
3840 ? _(" (reset view)") : "");
3845 = ((state_machine_regs.op_index + uladv)
3846 / linfo.li_max_ops_per_insn)
3847 * linfo.li_min_insn_length;
3848 state_machine_regs.address
3850 state_machine_regs.op_index
3851 = (state_machine_regs.op_index + uladv)
3852 % linfo.li_max_ops_per_insn;
3854 state_machine_regs.view = 0;
3855 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3856 dwarf_vmatoa ("u", uladv),
3857 dwarf_vmatoa ("x", state_machine_regs.address),
3858 state_machine_regs.op_index,
3859 verbose_view && addrdelta
3860 ? _(" (reset view)") : "");
3864 case DW_LNS_fixed_advance_pc:
3865 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3866 state_machine_regs.address += uladv;
3867 state_machine_regs.op_index = 0;
3868 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3869 dwarf_vmatoa ("u", uladv),
3870 dwarf_vmatoa ("x", state_machine_regs.address));
3871 /* Do NOT reset view. */
3874 case DW_LNS_set_prologue_end:
3875 printf (_(" Set prologue_end to true\n"));
3878 case DW_LNS_set_epilogue_begin:
3879 printf (_(" Set epilogue_begin to true\n"));
3882 case DW_LNS_set_isa:
3883 uladv = read_uleb128 (data, & bytes_read, end);
3885 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3889 printf (_(" Unknown opcode %d with operands: "), op_code);
3891 if (standard_opcodes != NULL)
3892 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3894 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3896 i == 1 ? "" : ", ");
3912 unsigned char *name;
3913 unsigned int directory_index;
3914 unsigned int modification_date;
3915 unsigned int length;
3918 /* Output a decoded representation of the .debug_line section. */
3921 display_debug_lines_decoded (struct dwarf_section * section,
3922 unsigned char * data,
3923 unsigned char * end,
3926 static DWARF2_Internal_LineInfo saved_linfo;
3928 introduce (section, FALSE);
3932 /* This loop amounts to one iteration per compilation unit. */
3933 DWARF2_Internal_LineInfo linfo;
3934 unsigned char *standard_opcodes;
3935 unsigned char *end_of_sequence;
3937 File_Entry *file_table = NULL;
3938 unsigned int n_files = 0;
3939 unsigned char **directory_table = NULL;
3940 dwarf_vma n_directories = 0;
3942 if (const_strneq (section->name, ".debug_line.")
3943 /* Note: the following does not apply to .debug_line.dwo sections.
3944 These are full debug_line sections. */
3945 && strcmp (section->name, ".debug_line.dwo") != 0)
3947 /* See comment in display_debug_lines_raw(). */
3948 end_of_sequence = end;
3949 standard_opcodes = NULL;
3950 linfo = saved_linfo;
3951 /* PR 17531: file: 0522b371. */
3952 if (linfo.li_line_range == 0)
3954 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3957 reset_state_machine (linfo.li_default_is_stmt);
3961 unsigned char *hdrptr;
3963 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3964 & end_of_sequence)) == NULL)
3967 /* PR 17531: file: 0522b371. */
3968 if (linfo.li_line_range == 0)
3970 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3971 linfo.li_line_range = 1;
3973 reset_state_machine (linfo.li_default_is_stmt);
3975 /* Save a pointer to the contents of the Opcodes table. */
3976 standard_opcodes = hdrptr;
3978 /* Traverse the Directory table just to count entries. */
3979 data = standard_opcodes + linfo.li_opcode_base - 1;
3983 warn (_("opcode base of %d extends beyond end of section\n"),
3984 linfo.li_opcode_base);
3988 if (linfo.li_version >= 5)
3990 unsigned char *format_start, format_count, *format;
3991 dwarf_vma formati, entryi;
3992 unsigned int bytes_read;
3994 load_debug_section_with_follow (line_str, fileptr);
3996 /* Skip directories format. */
3997 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3998 format_start = data;
3999 for (formati = 0; formati < format_count; formati++)
4001 read_uleb128 (data, & bytes_read, end);
4003 read_uleb128 (data, & bytes_read, end);
4007 n_directories = read_uleb128 (data, & bytes_read, end);
4011 warn (_("Corrupt directories list\n"));
4015 directory_table = (unsigned char **)
4016 xmalloc (n_directories * sizeof (unsigned char *));
4018 for (entryi = 0; entryi < n_directories; entryi++)
4020 unsigned char **pathp = &directory_table[entryi];
4022 format = format_start;
4023 for (formati = 0; formati < format_count; formati++)
4025 dwarf_vma content_type, form;
4028 content_type = read_uleb128 (format, & bytes_read, end);
4029 format += bytes_read;
4030 form = read_uleb128 (format, & bytes_read, end);
4031 format += bytes_read;
4034 warn (_("Corrupt directories list\n"));
4037 switch (content_type)
4042 case DW_FORM_string:
4045 case DW_FORM_line_strp:
4046 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4048 /* Remove const by the cast. */
4049 *pathp = (unsigned char *)
4050 fetch_indirect_line_string (uvalue);
4055 data = read_and_display_attr_value (0, form, 0, data, end,
4057 linfo.li_offset_size,
4064 warn (_("Corrupt directories list\n"));
4069 /* Skip files format. */
4070 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
4071 format_start = data;
4072 for (formati = 0; formati < format_count; formati++)
4074 read_uleb128 (data, & bytes_read, end);
4076 read_uleb128 (data, & bytes_read, end);
4080 n_files = read_uleb128 (data, & bytes_read, end);
4084 warn (_("Corrupt file name list\n"));
4088 file_table = (File_Entry *) xcalloc (1, n_files
4089 * sizeof (File_Entry));
4091 for (entryi = 0; entryi < n_files; entryi++)
4093 File_Entry *file = &file_table[entryi];
4095 format = format_start;
4096 for (formati = 0; formati < format_count; formati++)
4098 dwarf_vma content_type, form;
4101 content_type = read_uleb128 (format, & bytes_read, end);
4102 format += bytes_read;
4103 form = read_uleb128 (format, & bytes_read, end);
4104 format += bytes_read;
4107 warn (_("Corrupt file name list\n"));
4110 switch (content_type)
4115 case DW_FORM_string:
4118 case DW_FORM_line_strp:
4119 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4121 /* Remove const by the cast. */
4122 file->name = (unsigned char *)
4123 fetch_indirect_line_string (uvalue);
4127 case DW_LNCT_directory_index:
4131 SAFE_BYTE_GET (file->directory_index, data, 1,
4135 SAFE_BYTE_GET (file->directory_index, data, 2,
4139 file->directory_index = read_uleb128 (data, NULL,
4145 data = read_and_display_attr_value (0, form, 0, data, end,
4147 linfo.li_offset_size,
4154 warn (_("Corrupt file name list\n"));
4163 unsigned char *ptr_directory_table = data;
4165 while (data < end && *data != 0)
4167 data += strnlen ((char *) data, end - data) + 1;
4174 warn (_("directory table ends unexpectedly\n"));
4179 /* Go through the directory table again to save the directories. */
4180 directory_table = (unsigned char **)
4181 xmalloc (n_directories * sizeof (unsigned char *));
4184 while (*ptr_directory_table != 0)
4186 directory_table[i] = ptr_directory_table;
4187 ptr_directory_table += strnlen ((char *) ptr_directory_table,
4188 ptr_directory_table - end) + 1;
4192 /* Skip the NUL at the end of the table. */
4195 /* Traverse the File Name table just to count the entries. */
4196 if (data < end && *data != 0)
4198 unsigned char *ptr_file_name_table = data;
4200 while (data < end && *data != 0)
4202 unsigned int bytes_read;
4204 /* Skip Name, directory index, last modification time and length
4206 data += strnlen ((char *) data, end - data) + 1;
4207 read_uleb128 (data, & bytes_read, end);
4209 read_uleb128 (data, & bytes_read, end);
4211 read_uleb128 (data, & bytes_read, end);
4219 warn (_("file table ends unexpectedly\n"));
4224 /* Go through the file table again to save the strings. */
4225 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
4228 while (*ptr_file_name_table != 0)
4230 unsigned int bytes_read;
4232 file_table[i].name = ptr_file_name_table;
4233 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
4234 end - ptr_file_name_table) + 1;
4236 /* We are not interested in directory, time or size. */
4237 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
4239 ptr_file_name_table += bytes_read;
4240 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
4242 ptr_file_name_table += bytes_read;
4243 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
4244 ptr_file_name_table += bytes_read;
4250 /* Skip the NUL at the end of the table. */
4254 /* Print the Compilation Unit's name and a header. */
4255 if (file_table == NULL)
4257 else if (directory_table == NULL)
4258 printf (_("CU: %s:\n"), file_table[0].name);
4261 unsigned int ix = file_table[0].directory_index;
4262 const char *directory;
4267 else if (n_directories == 0)
4268 directory = _("<unknown>");
4269 else if (ix > n_directories)
4271 warn (_("directory index %u > number of directories %s\n"),
4272 ix, dwarf_vmatoa ("u", n_directories));
4273 directory = _("<corrupt>");
4276 directory = (char *) directory_table[ix - 1];
4278 if (do_wide || strlen (directory) < 76)
4279 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4281 printf ("%s:\n", file_table[0].name);
4284 printf (_("File name Line number Starting address View\n"));
4285 saved_linfo = linfo;
4288 /* This loop iterates through the Dwarf Line Number Program. */
4289 while (data < end_of_sequence)
4291 unsigned char op_code;
4294 unsigned long int uladv;
4295 unsigned int bytes_read;
4296 int is_special_opcode = 0;
4301 if (op_code >= linfo.li_opcode_base)
4303 op_code -= linfo.li_opcode_base;
4304 uladv = (op_code / linfo.li_line_range);
4305 if (linfo.li_max_ops_per_insn == 1)
4307 uladv *= linfo.li_min_insn_length;
4308 state_machine_regs.address += uladv;
4310 state_machine_regs.view = 0;
4315 = ((state_machine_regs.op_index + uladv)
4316 / linfo.li_max_ops_per_insn)
4317 * linfo.li_min_insn_length;
4318 state_machine_regs.address
4320 state_machine_regs.op_index
4321 = (state_machine_regs.op_index + uladv)
4322 % linfo.li_max_ops_per_insn;
4324 state_machine_regs.view = 0;
4327 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4328 state_machine_regs.line += adv;
4329 is_special_opcode = 1;
4330 /* Increment view after printing this row. */
4332 else switch (op_code)
4334 case DW_LNS_extended_op:
4336 unsigned int ext_op_code_len;
4337 unsigned char ext_op_code;
4338 unsigned char *op_code_data = data;
4340 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4342 op_code_data += bytes_read;
4344 if (ext_op_code_len == 0)
4346 warn (_("Badly formed extended line op encountered!\n"));
4349 ext_op_code_len += bytes_read;
4350 ext_op_code = *op_code_data++;
4354 switch (ext_op_code)
4356 case DW_LNE_end_sequence:
4357 /* Reset stuff after printing this row. */
4359 case DW_LNE_set_address:
4360 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
4362 ext_op_code_len - bytes_read - 1,
4364 state_machine_regs.op_index = 0;
4365 state_machine_regs.view = 0;
4367 case DW_LNE_define_file:
4369 file_table = (File_Entry *) xrealloc
4370 (file_table, (n_files + 1) * sizeof (File_Entry));
4372 ++state_machine_regs.last_file_entry;
4373 /* Source file name. */
4374 file_table[n_files].name = op_code_data;
4375 op_code_data += strlen ((char *) op_code_data) + 1;
4376 /* Directory index. */
4377 file_table[n_files].directory_index =
4378 read_uleb128 (op_code_data, & bytes_read,
4380 op_code_data += bytes_read;
4381 /* Last modification time. */
4382 file_table[n_files].modification_date =
4383 read_uleb128 (op_code_data, & bytes_read,
4385 op_code_data += bytes_read;
4387 file_table[n_files].length =
4388 read_uleb128 (op_code_data, & bytes_read,
4394 case DW_LNE_set_discriminator:
4395 case DW_LNE_HP_set_sequence:
4396 /* Simply ignored. */
4400 printf (_("UNKNOWN (%u): length %d\n"),
4401 ext_op_code, ext_op_code_len - bytes_read);
4404 data += ext_op_code_len;
4408 /* Increment view after printing this row. */
4411 case DW_LNS_advance_pc:
4412 uladv = read_uleb128 (data, & bytes_read, end);
4414 if (linfo.li_max_ops_per_insn == 1)
4416 uladv *= linfo.li_min_insn_length;
4417 state_machine_regs.address += uladv;
4419 state_machine_regs.view = 0;
4424 = ((state_machine_regs.op_index + uladv)
4425 / linfo.li_max_ops_per_insn)
4426 * linfo.li_min_insn_length;
4427 state_machine_regs.address
4429 state_machine_regs.op_index
4430 = (state_machine_regs.op_index + uladv)
4431 % linfo.li_max_ops_per_insn;
4433 state_machine_regs.view = 0;
4437 case DW_LNS_advance_line:
4438 adv = read_sleb128 (data, & bytes_read, end);
4440 state_machine_regs.line += adv;
4443 case DW_LNS_set_file:
4444 adv = read_uleb128 (data, & bytes_read, end);
4446 state_machine_regs.file = adv;
4449 unsigned file = state_machine_regs.file - 1;
4452 if (file_table == NULL || n_files == 0)
4453 printf (_("\n [Use file table entry %d]\n"), file);
4455 else if (file >= n_files)
4457 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4458 printf (_("\n <over large file table index %u>"), file);
4460 else if ((dir = file_table[file].directory_index) == 0)
4461 /* If directory index is 0, that means current directory. */
4462 printf ("\n./%s:[++]\n", file_table[file].name);
4463 else if (directory_table == NULL || n_directories == 0)
4464 printf (_("\n [Use file %s in directory table entry %d]\n"),
4465 file_table[file].name, dir);
4467 else if (dir > n_directories)
4469 warn (_("directory index %u > number of directories %s\n"),
4470 dir, dwarf_vmatoa ("u", n_directories));
4471 printf (_("\n <over large directory table entry %u>\n"), dir);
4474 printf ("\n%s/%s:\n",
4475 /* The directory index starts counting at 1. */
4476 directory_table[dir - 1], file_table[file].name);
4480 case DW_LNS_set_column:
4481 uladv = read_uleb128 (data, & bytes_read, end);
4483 state_machine_regs.column = uladv;
4486 case DW_LNS_negate_stmt:
4487 adv = state_machine_regs.is_stmt;
4489 state_machine_regs.is_stmt = adv;
4492 case DW_LNS_set_basic_block:
4493 state_machine_regs.basic_block = 1;
4496 case DW_LNS_const_add_pc:
4497 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4498 if (linfo.li_max_ops_per_insn == 1)
4500 uladv *= linfo.li_min_insn_length;
4501 state_machine_regs.address += uladv;
4503 state_machine_regs.view = 0;
4508 = ((state_machine_regs.op_index + uladv)
4509 / linfo.li_max_ops_per_insn)
4510 * linfo.li_min_insn_length;
4511 state_machine_regs.address
4513 state_machine_regs.op_index
4514 = (state_machine_regs.op_index + uladv)
4515 % linfo.li_max_ops_per_insn;
4517 state_machine_regs.view = 0;
4521 case DW_LNS_fixed_advance_pc:
4522 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4523 state_machine_regs.address += uladv;
4524 state_machine_regs.op_index = 0;
4525 /* Do NOT reset view. */
4528 case DW_LNS_set_prologue_end:
4531 case DW_LNS_set_epilogue_begin:
4534 case DW_LNS_set_isa:
4535 uladv = read_uleb128 (data, & bytes_read, end);
4537 printf (_(" Set ISA to %lu\n"), uladv);
4541 printf (_(" Unknown opcode %d with operands: "), op_code);
4543 if (standard_opcodes != NULL)
4544 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4546 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4548 i == 1 ? "" : ", ");
4555 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4556 to the DWARF address/line matrix. */
4557 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4558 || (xop == DW_LNS_copy))
4560 const unsigned int MAX_FILENAME_LENGTH = 35;
4562 char *newFileName = NULL;
4563 size_t fileNameLength;
4567 unsigned indx = state_machine_regs.file - 1;
4569 if (indx >= n_files)
4571 warn (_("corrupt file index %u encountered\n"), indx);
4572 fileName = _("<corrupt>");
4575 fileName = (char *) file_table[indx].name;
4578 fileName = _("<unknown>");
4580 fileNameLength = strlen (fileName);
4582 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4584 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4585 /* Truncate file name */
4586 strncpy (newFileName,
4587 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4588 MAX_FILENAME_LENGTH + 1);
4592 newFileName = (char *) xmalloc (fileNameLength + 1);
4593 strncpy (newFileName, fileName, fileNameLength + 1);
4596 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4598 if (linfo.li_max_ops_per_insn == 1)
4599 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
4600 newFileName, state_machine_regs.line,
4601 state_machine_regs.address);
4603 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
4604 newFileName, state_machine_regs.line,
4605 state_machine_regs.address,
4606 state_machine_regs.op_index);
4610 if (linfo.li_max_ops_per_insn == 1)
4611 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
4612 newFileName, state_machine_regs.line,
4613 state_machine_regs.address);
4615 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
4616 newFileName, state_machine_regs.line,
4617 state_machine_regs.address,
4618 state_machine_regs.op_index);
4621 if (state_machine_regs.view)
4622 printf (" %6u\n", state_machine_regs.view);
4625 state_machine_regs.view++;
4627 if (xop == -DW_LNE_end_sequence)
4629 reset_state_machine (linfo.li_default_is_stmt);
4644 if (directory_table)
4646 free (directory_table);
4647 directory_table = NULL;
4658 display_debug_lines (struct dwarf_section *section, void *file)
4660 unsigned char *data = section->start;
4661 unsigned char *end = data + section->size;
4663 int retValDecoded = 1;
4665 if (do_debug_lines == 0)
4666 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4668 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4669 retValRaw = display_debug_lines_raw (section, data, end, file);
4671 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4672 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4674 if (!retValRaw || !retValDecoded)
4681 find_debug_info_for_offset (unsigned long offset)
4685 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4688 for (i = 0; i < num_debug_info_entries; i++)
4689 if (debug_information[i].cu_offset == offset)
4690 return debug_information + i;
4696 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4698 /* See gdb/gdb-index.h. */
4699 static const char * const kinds[] =
4711 return _ (kinds[kind]);
4715 display_debug_pubnames_worker (struct dwarf_section *section,
4716 void *file ATTRIBUTE_UNUSED,
4719 DWARF2_Internal_PubNames names;
4720 unsigned char *start = section->start;
4721 unsigned char *end = start + section->size;
4723 /* It does not matter if this load fails,
4724 we test for that later on. */
4725 load_debug_info (file);
4727 introduce (section, FALSE);
4731 unsigned char *data;
4732 unsigned long sec_off;
4733 unsigned int offset_size, initial_length_size;
4735 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
4736 if (names.pn_length == 0xffffffff)
4738 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
4740 initial_length_size = 12;
4745 initial_length_size = 4;
4748 sec_off = start - section->start;
4749 if (sec_off + names.pn_length < sec_off
4750 || sec_off + names.pn_length > section->size)
4752 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4754 sec_off - initial_length_size,
4755 dwarf_vmatoa ("x", names.pn_length));
4760 start += names.pn_length;
4762 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4763 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4765 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4766 && num_debug_info_entries > 0
4767 && find_debug_info_for_offset (names.pn_offset) == NULL)
4768 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4769 (unsigned long) names.pn_offset, section->name);
4771 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4773 printf (_(" Length: %ld\n"),
4774 (long) names.pn_length);
4775 printf (_(" Version: %d\n"),
4777 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4778 (unsigned long) names.pn_offset);
4779 printf (_(" Size of area in .debug_info section: %ld\n"),
4780 (long) names.pn_size);
4782 if (names.pn_version != 2 && names.pn_version != 3)
4784 static int warned = 0;
4788 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4796 printf (_("\n Offset Kind Name\n"));
4798 printf (_("\n Offset\tName\n"));
4802 bfd_size_type maxprint;
4805 SAFE_BYTE_GET (offset, data, offset_size, end);
4810 data += offset_size;
4813 maxprint = (end - data) - 1;
4817 unsigned int kind_data;
4818 gdb_index_symbol_kind kind;
4819 const char *kind_name;
4822 SAFE_BYTE_GET (kind_data, data, 1, end);
4825 /* GCC computes the kind as the upper byte in the CU index
4826 word, and then right shifts it by the CU index size.
4827 Left shift KIND to where the gdb-index.h accessor macros
4829 kind_data <<= GDB_INDEX_CU_BITSIZE;
4830 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4831 kind_name = get_gdb_index_symbol_kind_name (kind);
4832 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4833 printf (" %-6lx %s,%-10s %.*s\n",
4834 (unsigned long) offset, is_static ? _("s") : _("g"),
4835 kind_name, (int) maxprint, data);
4838 printf (" %-6lx\t%.*s\n",
4839 (unsigned long) offset, (int) maxprint, data);
4841 data += strnlen ((char *) data, maxprint) + 1;
4852 display_debug_pubnames (struct dwarf_section *section, void *file)
4854 return display_debug_pubnames_worker (section, file, 0);
4858 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4860 return display_debug_pubnames_worker (section, file, 1);
4864 display_debug_macinfo (struct dwarf_section *section,
4865 void *file ATTRIBUTE_UNUSED)
4867 unsigned char *start = section->start;
4868 unsigned char *end = start + section->size;
4869 unsigned char *curr = start;
4870 unsigned int bytes_read;
4871 enum dwarf_macinfo_record_type op;
4873 introduce (section, FALSE);
4877 unsigned int lineno;
4878 const unsigned char *string;
4880 op = (enum dwarf_macinfo_record_type) *curr;
4885 case DW_MACINFO_start_file:
4887 unsigned int filenum;
4889 lineno = read_uleb128 (curr, & bytes_read, end);
4891 filenum = read_uleb128 (curr, & bytes_read, end);
4894 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4899 case DW_MACINFO_end_file:
4900 printf (_(" DW_MACINFO_end_file\n"));
4903 case DW_MACINFO_define:
4904 lineno = read_uleb128 (curr, & bytes_read, end);
4907 curr += strnlen ((char *) string, end - string) + 1;
4908 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4912 case DW_MACINFO_undef:
4913 lineno = read_uleb128 (curr, & bytes_read, end);
4916 curr += strnlen ((char *) string, end - string) + 1;
4917 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4921 case DW_MACINFO_vendor_ext:
4923 unsigned int constant;
4925 constant = read_uleb128 (curr, & bytes_read, end);
4928 curr += strnlen ((char *) string, end - string) + 1;
4929 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4939 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4940 filename and dirname corresponding to file name table entry with index
4941 FILEIDX. Return NULL on failure. */
4943 static unsigned char *
4944 get_line_filename_and_dirname (dwarf_vma line_offset,
4946 unsigned char **dir_name)
4948 struct dwarf_section *section = &debug_displays [line].section;
4949 unsigned char *hdrptr, *dirtable, *file_name;
4950 unsigned int offset_size, initial_length_size;
4951 unsigned int version, opcode_base, bytes_read;
4952 dwarf_vma length, diridx;
4953 const unsigned char * end;
4956 if (section->start == NULL
4957 || line_offset >= section->size
4961 hdrptr = section->start + line_offset;
4962 end = section->start + section->size;
4964 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4965 if (length == 0xffffffff)
4967 /* This section is 64-bit DWARF 3. */
4968 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4970 initial_length_size = 12;
4975 initial_length_size = 4;
4977 if (length + initial_length_size < length
4978 || length + initial_length_size > section->size)
4981 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4982 if (version != 2 && version != 3 && version != 4)
4984 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4986 hdrptr++; /* Skip max_ops_per_insn. */
4987 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4989 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4990 if (opcode_base == 0)
4993 hdrptr += opcode_base - 1;
4998 /* Skip over dirname table. */
4999 while (*hdrptr != '\0')
5001 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5005 hdrptr++; /* Skip the NUL at the end of the table. */
5007 /* Now skip over preceding filename table entries. */
5008 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
5010 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5011 read_uleb128 (hdrptr, &bytes_read, end);
5012 hdrptr += bytes_read;
5013 read_uleb128 (hdrptr, &bytes_read, end);
5014 hdrptr += bytes_read;
5015 read_uleb128 (hdrptr, &bytes_read, end);
5016 hdrptr += bytes_read;
5018 if (hdrptr >= end || *hdrptr == '\0')
5022 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5025 diridx = read_uleb128 (hdrptr, &bytes_read, end);
5028 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
5029 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
5030 if (dirtable >= end || *dirtable == '\0')
5032 *dir_name = dirtable;
5037 display_debug_macro (struct dwarf_section *section,
5040 unsigned char *start = section->start;
5041 unsigned char *end = start + section->size;
5042 unsigned char *curr = start;
5043 unsigned char *extended_op_buf[256];
5044 unsigned int bytes_read;
5046 load_debug_section_with_follow (str, file);
5047 load_debug_section_with_follow (line, file);
5049 introduce (section, FALSE);
5053 unsigned int lineno, version, flags;
5054 unsigned int offset_size = 4;
5055 const unsigned char *string;
5056 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
5057 unsigned char **extended_ops = NULL;
5059 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
5060 if (version != 4 && version != 5)
5062 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5067 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
5070 printf (_(" Offset: 0x%lx\n"),
5071 (unsigned long) sec_offset);
5072 printf (_(" Version: %d\n"), version);
5073 printf (_(" Offset size: %d\n"), offset_size);
5076 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
5077 printf (_(" Offset into .debug_line: 0x%lx\n"),
5078 (unsigned long) line_offset);
5082 unsigned int i, count, op;
5085 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
5087 memset (extended_op_buf, 0, sizeof (extended_op_buf));
5088 extended_ops = extended_op_buf;
5091 printf (_(" Extension opcode arguments:\n"));
5092 for (i = 0; i < count; i++)
5094 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5095 extended_ops[op] = curr;
5096 nargs = read_uleb128 (curr, &bytes_read, end);
5099 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
5102 printf (_(" DW_MACRO_%02x arguments: "), op);
5103 for (n = 0; n < nargs; n++)
5107 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
5108 printf ("%s%s", get_FORM_name (form),
5109 n == nargs - 1 ? "\n" : ", ");
5119 case DW_FORM_block1:
5120 case DW_FORM_block2:
5121 case DW_FORM_block4:
5123 case DW_FORM_string:
5125 case DW_FORM_sec_offset:
5128 error (_("Invalid extension opcode form %s\n"),
5129 get_FORM_name (form));
5145 error (_(".debug_macro section not zero terminated\n"));
5149 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5155 case DW_MACRO_start_file:
5157 unsigned int filenum;
5158 unsigned char *file_name = NULL, *dir_name = NULL;
5160 lineno = read_uleb128 (curr, &bytes_read, end);
5162 filenum = read_uleb128 (curr, &bytes_read, end);
5165 if ((flags & 2) == 0)
5166 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5169 = get_line_filename_and_dirname (line_offset, filenum,
5171 if (file_name == NULL)
5172 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5175 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5177 dir_name != NULL ? (const char *) dir_name : "",
5178 dir_name != NULL ? "/" : "", file_name);
5182 case DW_MACRO_end_file:
5183 printf (_(" DW_MACRO_end_file\n"));
5186 case DW_MACRO_define:
5187 lineno = read_uleb128 (curr, &bytes_read, end);
5190 curr += strnlen ((char *) string, end - string) + 1;
5191 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5195 case DW_MACRO_undef:
5196 lineno = read_uleb128 (curr, &bytes_read, end);
5199 curr += strnlen ((char *) string, end - string) + 1;
5200 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5204 case DW_MACRO_define_strp:
5205 lineno = read_uleb128 (curr, &bytes_read, end);
5207 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5208 string = fetch_indirect_string (offset);
5209 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5213 case DW_MACRO_undef_strp:
5214 lineno = read_uleb128 (curr, &bytes_read, end);
5216 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5217 string = fetch_indirect_string (offset);
5218 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5222 case DW_MACRO_import:
5223 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5224 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5225 (unsigned long) offset);
5228 case DW_MACRO_define_sup:
5229 lineno = read_uleb128 (curr, &bytes_read, end);
5231 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5232 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5233 lineno, (unsigned long) offset);
5236 case DW_MACRO_undef_sup:
5237 lineno = read_uleb128 (curr, &bytes_read, end);
5239 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5240 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5241 lineno, (unsigned long) offset);
5244 case DW_MACRO_import_sup:
5245 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5246 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5247 (unsigned long) offset);
5251 if (extended_ops == NULL || extended_ops[op] == NULL)
5253 error (_(" Unknown macro opcode %02x seen\n"), op);
5258 /* Skip over unhandled opcodes. */
5260 unsigned char *desc = extended_ops[op];
5261 nargs = read_uleb128 (desc, &bytes_read, end);
5265 printf (_(" DW_MACRO_%02x\n"), op);
5268 printf (_(" DW_MACRO_%02x -"), op);
5269 for (n = 0; n < nargs; n++)
5273 /* DW_FORM_implicit_const is not expected here. */
5274 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
5276 = read_and_display_attr_value (0, val, 0,
5277 curr, end, 0, 0, offset_size,
5278 version, NULL, 0, NULL,
5296 display_debug_abbrev (struct dwarf_section *section,
5297 void *file ATTRIBUTE_UNUSED)
5299 abbrev_entry *entry;
5300 unsigned char *start = section->start;
5301 unsigned char *end = start + section->size;
5303 introduce (section, FALSE);
5307 unsigned char *last;
5312 start = process_abbrev_section (start, end);
5314 if (first_abbrev == NULL)
5317 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
5319 for (entry = first_abbrev; entry; entry = entry->next)
5323 printf (" %ld %s [%s]\n",
5325 get_TAG_name (entry->tag),
5326 entry->children ? _("has children") : _("no children"));
5328 for (attr = entry->first_attr; attr; attr = attr->next)
5330 printf (" %-18s %s",
5331 get_AT_name (attr->attribute),
5332 get_FORM_name (attr->form));
5333 if (attr->form == DW_FORM_implicit_const)
5334 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5346 /* Return true when ADDR is the maximum address, when addresses are
5347 POINTER_SIZE bytes long. */
5350 is_max_address (dwarf_vma addr, unsigned int pointer_size)
5352 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5353 return ((addr & mask) == mask);
5356 /* Display a view pair list starting at *VSTART_PTR and ending at
5357 VLISTEND within SECTION. */
5360 display_view_pair_list (struct dwarf_section *section,
5361 unsigned char **vstart_ptr,
5362 unsigned int debug_info_entry,
5363 unsigned char *vlistend)
5365 unsigned char *vstart = *vstart_ptr;
5366 unsigned char *section_end = section->start + section->size;
5367 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5369 if (vlistend < section_end)
5370 section_end = vlistend;
5374 while (vstart < section_end)
5376 dwarf_vma off = vstart - section->start;
5377 dwarf_vma vbegin, vend;
5379 unsigned int bytes_read;
5380 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5381 vstart += bytes_read;
5382 if (vstart == section_end)
5384 vstart -= bytes_read;
5388 vend = read_uleb128 (vstart, &bytes_read, section_end);
5389 vstart += bytes_read;
5391 printf (" %8.8lx ", (unsigned long) off);
5393 print_dwarf_view (vbegin, pointer_size, 1);
5394 print_dwarf_view (vend, pointer_size, 1);
5395 printf (_("location view pair\n"));
5399 *vstart_ptr = vstart;
5402 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5405 display_loc_list (struct dwarf_section *section,
5406 unsigned char **start_ptr,
5407 unsigned int debug_info_entry,
5409 dwarf_vma base_address,
5410 unsigned char **vstart_ptr,
5413 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5414 unsigned char *section_end = section->start + section->size;
5415 unsigned long cu_offset;
5416 unsigned int pointer_size;
5417 unsigned int offset_size;
5422 unsigned short length;
5423 int need_frame_base;
5425 if (debug_info_entry >= num_debug_info_entries)
5427 warn (_("No debug information available for loc lists of entry: %u\n"),
5432 cu_offset = debug_information [debug_info_entry].cu_offset;
5433 pointer_size = debug_information [debug_info_entry].pointer_size;
5434 offset_size = debug_information [debug_info_entry].offset_size;
5435 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5437 if (pointer_size < 2 || pointer_size > 8)
5439 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5440 pointer_size, debug_info_entry);
5446 dwarf_vma off = offset + (start - *start_ptr);
5447 dwarf_vma vbegin = vm1, vend = vm1;
5449 if (start + 2 * pointer_size > section_end)
5451 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5452 (unsigned long) offset);
5456 printf (" %8.8lx ", (unsigned long) off);
5458 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5459 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5461 if (begin == 0 && end == 0)
5463 /* PR 18374: In a object file we can have a location list that
5464 starts with a begin and end of 0 because there are relocations
5465 that need to be applied to the addresses. Actually applying
5466 the relocations now does not help as they will probably resolve
5467 to 0, since the object file has not been fully linked. Real
5468 end of list markers will not have any relocations against them. */
5469 if (! reloc_at (section, off)
5470 && ! reloc_at (section, off + pointer_size))
5472 printf (_("<End of list>\n"));
5477 /* Check base address specifiers. */
5478 if (is_max_address (begin, pointer_size)
5479 && !is_max_address (end, pointer_size))
5482 print_dwarf_vma (begin, pointer_size);
5483 print_dwarf_vma (end, pointer_size);
5484 printf (_("(base address)\n"));
5490 unsigned int bytes_read;
5492 off = offset + (vstart - *start_ptr);
5494 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5495 vstart += bytes_read;
5496 print_dwarf_view (vbegin, pointer_size, 1);
5498 vend = read_uleb128 (vstart, &bytes_read, section_end);
5499 vstart += bytes_read;
5500 print_dwarf_view (vend, pointer_size, 1);
5502 printf (_("views at %8.8lx for:\n %*s "),
5503 (unsigned long) off, 8, "");
5506 if (start + 2 > section_end)
5508 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5509 (unsigned long) offset);
5513 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5515 if (start + length > section_end)
5517 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5518 (unsigned long) offset);
5522 print_dwarf_vma (begin + base_address, pointer_size);
5523 print_dwarf_vma (end + base_address, pointer_size);
5526 need_frame_base = decode_location_expression (start,
5531 cu_offset, section);
5534 if (need_frame_base && !has_frame_base)
5535 printf (_(" [without DW_AT_frame_base]"));
5537 if (begin == end && vbegin == vend)
5538 fputs (_(" (start == end)"), stdout);
5539 else if (begin > end || (begin == end && vbegin > vend))
5540 fputs (_(" (start > end)"), stdout);
5548 *vstart_ptr = vstart;
5551 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5554 display_loclists_list (struct dwarf_section *section,
5555 unsigned char **start_ptr,
5556 unsigned int debug_info_entry,
5558 dwarf_vma base_address,
5559 unsigned char **vstart_ptr,
5562 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5563 unsigned char *section_end = section->start + section->size;
5564 unsigned long cu_offset;
5565 unsigned int pointer_size;
5566 unsigned int offset_size;
5568 unsigned int bytes_read;
5570 /* Initialize it due to a false compiler warning. */
5571 dwarf_vma begin = -1, vbegin = -1;
5572 dwarf_vma end = -1, vend = -1;
5574 int need_frame_base;
5576 if (debug_info_entry >= num_debug_info_entries)
5578 warn (_("No debug information available for "
5579 "loclists lists of entry: %u\n"),
5584 cu_offset = debug_information [debug_info_entry].cu_offset;
5585 pointer_size = debug_information [debug_info_entry].pointer_size;
5586 offset_size = debug_information [debug_info_entry].offset_size;
5587 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5589 if (pointer_size < 2 || pointer_size > 8)
5591 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5592 pointer_size, debug_info_entry);
5598 dwarf_vma off = offset + (start - *start_ptr);
5599 enum dwarf_location_list_entry_type llet;
5601 if (start + 1 > section_end)
5603 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5604 (unsigned long) offset);
5608 printf (" %8.8lx ", (unsigned long) off);
5610 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5612 if (vstart && llet == DW_LLE_offset_pair)
5614 off = offset + (vstart - *start_ptr);
5616 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5617 vstart += bytes_read;
5618 print_dwarf_view (vbegin, pointer_size, 1);
5620 vend = read_uleb128 (vstart, &bytes_read, section_end);
5621 vstart += bytes_read;
5622 print_dwarf_view (vend, pointer_size, 1);
5624 printf (_("views at %8.8lx for:\n %*s "),
5625 (unsigned long) off, 8, "");
5630 case DW_LLE_end_of_list:
5631 printf (_("<End of list>\n"));
5633 case DW_LLE_offset_pair:
5634 begin = read_uleb128 (start, &bytes_read, section_end);
5635 start += bytes_read;
5636 end = read_uleb128 (start, &bytes_read, section_end);
5637 start += bytes_read;
5639 case DW_LLE_base_address:
5640 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5642 print_dwarf_vma (base_address, pointer_size);
5643 printf (_("(base address)\n"));
5645 #ifdef DW_LLE_view_pair
5646 case DW_LLE_view_pair:
5648 printf (_("View pair entry in loclist with locviews attribute\n"));
5649 vbegin = read_uleb128 (start, &bytes_read, section_end);
5650 start += bytes_read;
5651 print_dwarf_view (vbegin, pointer_size, 1);
5653 vend = read_uleb128 (start, &bytes_read, section_end);
5654 start += bytes_read;
5655 print_dwarf_view (vend, pointer_size, 1);
5657 printf (_("views for:\n"));
5661 error (_("Invalid location list entry type %d\n"), llet);
5664 if (llet == DW_LLE_end_of_list)
5666 if (llet != DW_LLE_offset_pair)
5669 if (start + 2 > section_end)
5671 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5672 (unsigned long) offset);
5676 length = read_uleb128 (start, &bytes_read, section_end);
5677 start += bytes_read;
5679 print_dwarf_vma (begin + base_address, pointer_size);
5680 print_dwarf_vma (end + base_address, pointer_size);
5683 need_frame_base = decode_location_expression (start,
5688 cu_offset, section);
5691 if (need_frame_base && !has_frame_base)
5692 printf (_(" [without DW_AT_frame_base]"));
5694 if (begin == end && vbegin == vend)
5695 fputs (_(" (start == end)"), stdout);
5696 else if (begin > end || (begin == end && vbegin > vend))
5697 fputs (_(" (start > end)"), stdout);
5705 if (vbegin != vm1 || vend != vm1)
5706 printf (_("Trailing view pair not used in a range"));
5709 *vstart_ptr = vstart;
5712 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5713 right-adjusted in a field of length LEN, and followed by a space. */
5716 print_addr_index (unsigned int idx, unsigned int len)
5718 static char buf[15];
5719 snprintf (buf, sizeof (buf), "[%d]", idx);
5720 printf ("%*s ", len, buf);
5723 /* Display a location list from a .dwo section. It uses address indexes rather
5724 than embedded addresses. This code closely follows display_loc_list, but the
5725 two are sufficiently different that combining things is very ugly. */
5728 display_loc_list_dwo (struct dwarf_section *section,
5729 unsigned char **start_ptr,
5730 unsigned int debug_info_entry,
5732 unsigned char **vstart_ptr,
5735 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5736 unsigned char *section_end = section->start + section->size;
5737 unsigned long cu_offset;
5738 unsigned int pointer_size;
5739 unsigned int offset_size;
5742 unsigned short length;
5743 int need_frame_base;
5745 unsigned int bytes_read;
5747 if (debug_info_entry >= num_debug_info_entries)
5749 warn (_("No debug information for loc lists of entry: %u\n"),
5754 cu_offset = debug_information [debug_info_entry].cu_offset;
5755 pointer_size = debug_information [debug_info_entry].pointer_size;
5756 offset_size = debug_information [debug_info_entry].offset_size;
5757 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5759 if (pointer_size < 2 || pointer_size > 8)
5761 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5762 pointer_size, debug_info_entry);
5768 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5770 if (start >= section_end)
5772 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5773 (unsigned long) offset);
5777 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5790 dwarf_vma off = offset + (vstart - *start_ptr);
5792 view = read_uleb128 (vstart, &bytes_read, section_end);
5793 vstart += bytes_read;
5794 print_dwarf_view (view, 8, 1);
5796 view = read_uleb128 (vstart, &bytes_read, section_end);
5797 vstart += bytes_read;
5798 print_dwarf_view (view, 8, 1);
5800 printf (_("views at %8.8lx for:\n %*s "),
5801 (unsigned long) off, 8, "");
5809 case 0: /* A terminating entry. */
5811 *vstart_ptr = vstart;
5812 printf (_("<End of list>\n"));
5814 case 1: /* A base-address entry. */
5815 idx = read_uleb128 (start, &bytes_read, section_end);
5816 start += bytes_read;
5817 print_addr_index (idx, 8);
5818 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
5819 printf (_("(base address selection entry)\n"));
5821 case 2: /* A start/end entry. */
5822 idx = read_uleb128 (start, &bytes_read, section_end);
5823 start += bytes_read;
5824 print_addr_index (idx, 8);
5825 idx = read_uleb128 (start, &bytes_read, section_end);
5826 start += bytes_read;
5827 print_addr_index (idx, 8);
5829 case 3: /* A start/length entry. */
5830 idx = read_uleb128 (start, &bytes_read, section_end);
5831 start += bytes_read;
5832 print_addr_index (idx, 8);
5833 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5834 printf ("%08x ", idx);
5836 case 4: /* An offset pair entry. */
5837 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5838 printf ("%08x ", idx);
5839 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5840 printf ("%08x ", idx);
5843 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5845 *vstart_ptr = vstart;
5849 if (start + 2 > section_end)
5851 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5852 (unsigned long) offset);
5856 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5857 if (start + length > section_end)
5859 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5860 (unsigned long) offset);
5865 need_frame_base = decode_location_expression (start,
5870 cu_offset, section);
5873 if (need_frame_base && !has_frame_base)
5874 printf (_(" [without DW_AT_frame_base]"));
5882 *vstart_ptr = vstart;
5885 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5888 static dwarf_vma *loc_offsets, *loc_views;
5891 loc_offsets_compar (const void *ap, const void *bp)
5893 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5894 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5896 int ret = (a > b) - (b > a);
5900 a = loc_views[*(const unsigned int *) ap];
5901 b = loc_views[*(const unsigned int *) bp];
5903 ret = (a > b) - (b > a);
5909 display_debug_loc (struct dwarf_section *section, void *file)
5911 unsigned char *start = section->start, *vstart = NULL;
5912 unsigned long bytes;
5913 unsigned char *section_begin = start;
5914 unsigned int num_loc_list = 0;
5915 unsigned long last_offset = 0;
5916 unsigned long last_view = 0;
5917 unsigned int first = 0;
5920 int seen_first_offset = 0;
5921 int locs_sorted = 1;
5922 unsigned char *next = start, *vnext = vstart;
5923 unsigned int *array = NULL;
5924 const char *suffix = strrchr (section->name, '.');
5926 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5927 dwarf_vma expected_start = 0;
5929 if (suffix && strcmp (suffix, ".dwo") == 0)
5932 bytes = section->size;
5936 printf (_("\nThe %s section is empty.\n"), section->name);
5942 unsigned char *hdrptr = section_begin;
5943 dwarf_vma ll_length;
5944 unsigned short ll_version;
5945 unsigned char *end = section_begin + section->size;
5946 unsigned char address_size, segment_selector_size;
5947 uint32_t offset_entry_count;
5949 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5950 if (ll_length == 0xffffffff)
5951 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5953 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5954 if (ll_version != 5)
5956 warn (_("The %s section contains corrupt or "
5957 "unsupported version number: %d.\n"),
5958 section->name, ll_version);
5962 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5964 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5965 if (segment_selector_size != 0)
5967 warn (_("The %s section contains "
5968 "unsupported segment selector size: %d.\n"),
5969 section->name, segment_selector_size);
5973 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5974 if (offset_entry_count != 0)
5976 warn (_("The %s section contains "
5977 "unsupported offset entry count: %d.\n"),
5978 section->name, offset_entry_count);
5982 expected_start = hdrptr - section_begin;
5985 if (load_debug_info (file) == 0)
5987 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5992 /* Check the order of location list in .debug_info section. If
5993 offsets of location lists are in the ascending order, we can
5994 use `debug_information' directly. */
5995 for (i = 0; i < num_debug_info_entries; i++)
5999 num = debug_information [i].num_loc_offsets;
6000 if (num > num_loc_list)
6003 /* Check if we can use `debug_information' directly. */
6004 if (locs_sorted && num != 0)
6006 if (!seen_first_offset)
6008 /* This is the first location list. */
6009 last_offset = debug_information [i].loc_offsets [0];
6010 last_view = debug_information [i].loc_views [0];
6012 seen_first_offset = 1;
6018 for (; j < num; j++)
6021 debug_information [i].loc_offsets [j]
6022 || (last_offset == debug_information [i].loc_offsets [j]
6023 && last_view > debug_information [i].loc_views [j]))
6028 last_offset = debug_information [i].loc_offsets [j];
6029 last_view = debug_information [i].loc_views [j];
6034 if (!seen_first_offset)
6035 error (_("No location lists in .debug_info section!\n"));
6037 if (debug_information [first].num_loc_offsets > 0
6038 && debug_information [first].loc_offsets [0] != expected_start
6039 && debug_information [first].loc_views [0] != expected_start)
6040 warn (_("Location lists in %s section start at 0x%s\n"),
6042 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
6045 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
6047 introduce (section, FALSE);
6049 if (reloc_at (section, 0))
6050 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6052 printf (_(" Offset Begin End Expression\n"));
6054 seen_first_offset = 0;
6055 for (i = first; i < num_debug_info_entries; i++)
6057 dwarf_vma offset, voffset;
6058 dwarf_vma base_address;
6064 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
6066 loc_offsets = debug_information [i].loc_offsets;
6067 loc_views = debug_information [i].loc_views;
6068 qsort (array, debug_information [i].num_loc_offsets,
6069 sizeof (*array), loc_offsets_compar);
6072 int adjacent_view_loclists = 1;
6073 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
6075 j = locs_sorted ? k : array[k];
6077 && (debug_information [i].loc_offsets [locs_sorted
6078 ? k - 1 : array [k - 1]]
6079 == debug_information [i].loc_offsets [j])
6080 && (debug_information [i].loc_views [locs_sorted
6081 ? k - 1 : array [k - 1]]
6082 == debug_information [i].loc_views [j]))
6084 has_frame_base = debug_information [i].have_frame_base [j];
6085 offset = debug_information [i].loc_offsets [j];
6086 next = section_begin + offset;
6087 voffset = debug_information [i].loc_views [j];
6089 vnext = section_begin + voffset;
6092 base_address = debug_information [i].base_address;
6094 if (vnext && vnext < next)
6097 display_view_pair_list (section, &vstart, i, next);
6102 if (!seen_first_offset || !adjacent_view_loclists)
6103 seen_first_offset = 1;
6107 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6108 (unsigned long) (start - section_begin),
6109 (unsigned long) offset);
6110 else if (start > next)
6111 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6112 (unsigned long) (start - section_begin),
6113 (unsigned long) offset);
6118 if (offset >= bytes)
6120 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6121 (unsigned long) offset);
6125 if (vnext && voffset >= bytes)
6127 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6128 (unsigned long) voffset);
6135 display_loc_list_dwo (section, &start, i, offset,
6136 &vstart, has_frame_base);
6138 display_loc_list (section, &start, i, offset, base_address,
6139 &vstart, has_frame_base);
6144 warn (_("DWO is not yet supported.\n"));
6146 display_loclists_list (section, &start, i, offset, base_address,
6147 &vstart, has_frame_base);
6150 /* FIXME: this arrangement is quite simplistic. Nothing
6151 requires locview lists to be adjacent to corresponding
6152 loclists, and a single loclist could be augmented by
6153 different locview lists, and vice-versa, unlikely as it
6154 is that it would make sense to do so. Hopefully we'll
6155 have view pair support built into loclists before we ever
6156 need to address all these possibilities. */
6157 if (adjacent_view_loclists && vnext
6158 && vnext != start && vstart != next)
6160 adjacent_view_loclists = 0;
6161 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6164 if (vnext && vnext == start)
6165 display_view_pair_list (section, &start, i, vstart);
6169 if (start < section->start + section->size)
6170 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6171 "There are %ld unused bytes at the end of section %s\n",
6172 (long) (section->start + section->size - start)),
6173 (long) (section->start + section->size - start), section->name);
6180 display_debug_str (struct dwarf_section *section,
6181 void *file ATTRIBUTE_UNUSED)
6183 unsigned char *start = section->start;
6184 unsigned long bytes = section->size;
6185 dwarf_vma addr = section->address;
6189 printf (_("\nThe %s section is empty.\n"), section->name);
6193 introduce (section, FALSE);
6201 lbytes = (bytes > 16 ? 16 : bytes);
6203 printf (" 0x%8.8lx ", (unsigned long) addr);
6205 for (j = 0; j < 16; j++)
6208 printf ("%2.2x", start[j]);
6216 for (j = 0; j < lbytes; j++)
6219 if (k >= ' ' && k < 0x80)
6238 display_debug_info (struct dwarf_section *section, void *file)
6240 return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE);
6244 display_debug_types (struct dwarf_section *section, void *file)
6246 return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE);
6250 display_trace_info (struct dwarf_section *section, void *file)
6252 return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE);
6256 display_debug_aranges (struct dwarf_section *section,
6257 void *file ATTRIBUTE_UNUSED)
6259 unsigned char *start = section->start;
6260 unsigned char *end = start + section->size;
6262 introduce (section, FALSE);
6264 /* It does not matter if this load fails,
6265 we test for that later on. */
6266 load_debug_info (file);
6270 unsigned char *hdrptr;
6271 DWARF2_Internal_ARange arange;
6272 unsigned char *addr_ranges;
6275 unsigned long sec_off;
6276 unsigned char address_size;
6278 unsigned int offset_size;
6279 unsigned int initial_length_size;
6283 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
6284 if (arange.ar_length == 0xffffffff)
6286 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
6288 initial_length_size = 12;
6293 initial_length_size = 4;
6296 sec_off = hdrptr - section->start;
6297 if (sec_off + arange.ar_length < sec_off
6298 || sec_off + arange.ar_length > section->size)
6300 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6302 sec_off - initial_length_size,
6303 dwarf_vmatoa ("x", arange.ar_length));
6307 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6308 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
6310 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6311 && num_debug_info_entries > 0
6312 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6313 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6314 (unsigned long) arange.ar_info_offset, section->name);
6316 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6317 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
6319 if (arange.ar_version != 2 && arange.ar_version != 3)
6321 /* PR 19872: A version number of 0 probably means that there is
6322 padding at the end of the .debug_aranges section. Gold puts
6323 it there when performing an incremental link, for example.
6324 So do not generate a warning in this case. */
6325 if (arange.ar_version)
6326 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6330 printf (_(" Length: %ld\n"),
6331 (long) arange.ar_length);
6332 printf (_(" Version: %d\n"), arange.ar_version);
6333 printf (_(" Offset into .debug_info: 0x%lx\n"),
6334 (unsigned long) arange.ar_info_offset);
6335 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6336 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6338 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6340 /* PR 17512: file: 001-108546-0.001:0.1. */
6341 if (address_size == 0 || address_size > 8)
6343 error (_("Invalid address size in %s section!\n"),
6348 /* The DWARF spec does not require that the address size be a power
6349 of two, but we do. This will have to change if we ever encounter
6350 an uneven architecture. */
6351 if ((address_size & (address_size - 1)) != 0)
6353 warn (_("Pointer size + Segment size is not a power of two.\n"));
6357 if (address_size > 4)
6358 printf (_("\n Address Length\n"));
6360 printf (_("\n Address Length\n"));
6362 addr_ranges = hdrptr;
6364 /* Must pad to an alignment boundary that is twice the address size. */
6365 excess = (hdrptr - start) % (2 * address_size);
6367 addr_ranges += (2 * address_size) - excess;
6369 start += arange.ar_length + initial_length_size;
6371 while (addr_ranges + 2 * address_size <= start)
6373 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6374 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
6377 print_dwarf_vma (address, address_size);
6378 print_dwarf_vma (length, address_size);
6388 /* Comparison function for qsort. */
6390 comp_addr_base (const void * v0, const void * v1)
6392 debug_info * info0 = (debug_info *) v0;
6393 debug_info * info1 = (debug_info *) v1;
6394 return info0->addr_base - info1->addr_base;
6397 /* Display the debug_addr section. */
6399 display_debug_addr (struct dwarf_section *section,
6402 debug_info **debug_addr_info;
6403 unsigned char *entry;
6408 if (section->size == 0)
6410 printf (_("\nThe %s section is empty.\n"), section->name);
6414 if (load_debug_info (file) == 0)
6416 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6421 introduce (section, FALSE);
6423 /* PR 17531: file: cf38d01b.
6424 We use xcalloc because a corrupt file may not have initialised all of the
6425 fields in the debug_info structure, which means that the sort below might
6426 try to move uninitialised data. */
6427 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
6428 sizeof (debug_info *));
6431 for (i = 0; i < num_debug_info_entries; i++)
6432 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
6434 /* PR 17531: file: cf38d01b. */
6435 if (debug_information[i].addr_base >= section->size)
6436 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6437 (unsigned long) debug_information[i].addr_base, i);
6439 debug_addr_info [count++] = debug_information + i;
6442 /* Add a sentinel to make iteration convenient. */
6443 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6444 debug_addr_info [count]->addr_base = section->size;
6445 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
6447 for (i = 0; i < count; i++)
6450 unsigned int address_size = debug_addr_info [i]->pointer_size;
6452 printf (_(" For compilation unit at offset 0x%s:\n"),
6453 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
6455 printf (_("\tIndex\tAddress\n"));
6456 entry = section->start + debug_addr_info [i]->addr_base;
6457 end = section->start + debug_addr_info [i + 1]->addr_base;
6461 dwarf_vma base = byte_get (entry, address_size);
6462 printf (_("\t%d:\t"), idx);
6463 print_dwarf_vma (base, address_size);
6465 entry += address_size;
6471 free (debug_addr_info);
6475 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6477 display_debug_str_offsets (struct dwarf_section *section,
6478 void *file ATTRIBUTE_UNUSED)
6480 if (section->size == 0)
6482 printf (_("\nThe %s section is empty.\n"), section->name);
6485 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6486 what the offset size is for this section. */
6490 /* Each debug_information[x].range_lists[y] gets this representation for
6491 sorting purposes. */
6495 /* The debug_information[x].range_lists[y] value. */
6496 dwarf_vma ranges_offset;
6498 /* Original debug_information to find parameters of the data. */
6499 debug_info *debug_info_p;
6502 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6505 range_entry_compar (const void *ap, const void *bp)
6507 const struct range_entry *a_re = (const struct range_entry *) ap;
6508 const struct range_entry *b_re = (const struct range_entry *) bp;
6509 const dwarf_vma a = a_re->ranges_offset;
6510 const dwarf_vma b = b_re->ranges_offset;
6512 return (a > b) - (b > a);
6516 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6517 unsigned int pointer_size, unsigned long offset,
6518 unsigned long base_address)
6520 while (start < finish)
6525 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6526 if (start >= finish)
6528 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6530 printf (" %8.8lx ", offset);
6532 if (begin == 0 && end == 0)
6534 printf (_("<End of list>\n"));
6538 /* Check base address specifiers. */
6539 if (is_max_address (begin, pointer_size)
6540 && !is_max_address (end, pointer_size))
6543 print_dwarf_vma (begin, pointer_size);
6544 print_dwarf_vma (end, pointer_size);
6545 printf ("(base address)\n");
6549 print_dwarf_vma (begin + base_address, pointer_size);
6550 print_dwarf_vma (end + base_address, pointer_size);
6553 fputs (_("(start == end)"), stdout);
6554 else if (begin > end)
6555 fputs (_("(start > end)"), stdout);
6562 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6563 unsigned int pointer_size, unsigned long offset,
6564 unsigned long base_address)
6566 unsigned char *next = start;
6570 unsigned long off = offset + (start - next);
6571 enum dwarf_range_list_entry rlet;
6572 /* Initialize it due to a false compiler warning. */
6573 dwarf_vma begin = -1, length, end = -1;
6574 unsigned int bytes_read;
6576 if (start + 1 > finish)
6578 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6583 printf (" %8.8lx ", off);
6585 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6589 case DW_RLE_end_of_list:
6590 printf (_("<End of list>\n"));
6592 case DW_RLE_base_address:
6593 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6594 print_dwarf_vma (base_address, pointer_size);
6595 printf (_("(base address)\n"));
6597 case DW_RLE_start_length:
6598 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6599 length = read_uleb128 (start, &bytes_read, finish);
6600 start += bytes_read;
6601 end = begin + length;
6603 case DW_RLE_offset_pair:
6604 begin = read_uleb128 (start, &bytes_read, finish);
6605 start += bytes_read;
6606 end = read_uleb128 (start, &bytes_read, finish);
6607 start += bytes_read;
6609 case DW_RLE_start_end:
6610 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6611 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6614 error (_("Invalid range list entry type %d\n"), rlet);
6615 rlet = DW_RLE_end_of_list;
6618 if (rlet == DW_RLE_end_of_list)
6620 if (rlet == DW_RLE_base_address)
6623 print_dwarf_vma (begin + base_address, pointer_size);
6624 print_dwarf_vma (end + base_address, pointer_size);
6627 fputs (_("(start == end)"), stdout);
6628 else if (begin > end)
6629 fputs (_("(start > end)"), stdout);
6636 display_debug_ranges (struct dwarf_section *section,
6637 void *file ATTRIBUTE_UNUSED)
6639 unsigned char *start = section->start;
6640 unsigned char *last_start = start;
6641 unsigned long bytes = section->size;
6642 unsigned char *section_begin = start;
6643 unsigned char *finish = start + bytes;
6644 unsigned int num_range_list, i;
6645 struct range_entry *range_entries, *range_entry_fill;
6646 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6647 /* Initialize it due to a false compiler warning. */
6648 unsigned char address_size = 0;
6652 printf (_("\nThe %s section is empty.\n"), section->name);
6658 dwarf_vma initial_length;
6659 unsigned int initial_length_size;
6660 unsigned char segment_selector_size;
6661 unsigned int offset_size, offset_entry_count;
6662 unsigned short version;
6664 /* Get and check the length of the block. */
6665 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6667 if (initial_length == 0xffffffff)
6669 /* This section is 64-bit DWARF 3. */
6670 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6672 initial_length_size = 12;
6677 initial_length_size = 4;
6680 if (initial_length + initial_length_size > section->size)
6682 /* If the length field has a relocation against it, then we should
6683 not complain if it is inaccurate (and probably negative).
6684 It is copied from .debug_line handling code. */
6685 if (reloc_at (section, (start - section->start) - offset_size))
6687 initial_length = (finish - start) - initial_length_size;
6691 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6692 (long) initial_length);
6697 /* Get and check the version number. */
6698 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6702 warn (_("Only DWARF version 5 debug_rnglists info "
6703 "is currently supported.\n"));
6707 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6709 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6710 if (segment_selector_size != 0)
6712 warn (_("The %s section contains "
6713 "unsupported segment selector size: %d.\n"),
6714 section->name, segment_selector_size);
6718 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6719 if (offset_entry_count != 0)
6721 warn (_("The %s section contains "
6722 "unsupported offset entry count: %u.\n"),
6723 section->name, offset_entry_count);
6728 if (load_debug_info (file) == 0)
6730 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6736 for (i = 0; i < num_debug_info_entries; i++)
6737 num_range_list += debug_information [i].num_range_lists;
6739 if (num_range_list == 0)
6741 /* This can happen when the file was compiled with -gsplit-debug
6742 which removes references to range lists from the primary .o file. */
6743 printf (_("No range lists in .debug_info section.\n"));
6747 range_entries = (struct range_entry *)
6748 xmalloc (sizeof (*range_entries) * num_range_list);
6749 range_entry_fill = range_entries;
6751 for (i = 0; i < num_debug_info_entries; i++)
6753 debug_info *debug_info_p = &debug_information[i];
6756 for (j = 0; j < debug_info_p->num_range_lists; j++)
6758 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6759 range_entry_fill->debug_info_p = debug_info_p;
6764 qsort (range_entries, num_range_list, sizeof (*range_entries),
6765 range_entry_compar);
6767 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6768 warn (_("Range lists in %s section start at 0x%lx\n"),
6769 section->name, (unsigned long) range_entries[0].ranges_offset);
6771 introduce (section, FALSE);
6773 printf (_(" Offset Begin End\n"));
6775 for (i = 0; i < num_range_list; i++)
6777 struct range_entry *range_entry = &range_entries[i];
6778 debug_info *debug_info_p = range_entry->debug_info_p;
6779 unsigned int pointer_size;
6781 unsigned char *next;
6782 dwarf_vma base_address;
6784 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6785 offset = range_entry->ranges_offset;
6786 next = section_begin + offset;
6787 base_address = debug_info_p->base_address;
6789 /* PR 17512: file: 001-101485-0.001:0.1. */
6790 if (pointer_size < 2 || pointer_size > 8)
6792 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6793 pointer_size, (unsigned long) offset);
6797 if (dwarf_check != 0 && i > 0)
6800 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6801 (unsigned long) (start - section_begin),
6802 (unsigned long) (next - section_begin), section->name);
6803 else if (start > next)
6805 if (next == last_start)
6807 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6808 (unsigned long) (start - section_begin),
6809 (unsigned long) (next - section_begin), section->name);
6815 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6816 (start, finish, pointer_size, offset, base_address);
6820 free (range_entries);
6825 typedef struct Frame_Chunk
6827 struct Frame_Chunk *next;
6828 unsigned char *chunk_start;
6830 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6831 short int *col_type;
6834 unsigned int code_factor;
6838 unsigned int cfa_reg;
6839 dwarf_vma cfa_offset;
6841 unsigned char fde_encoding;
6842 unsigned char cfa_exp;
6843 unsigned char ptr_size;
6844 unsigned char segment_size;
6848 static const char *const *dwarf_regnames;
6849 static unsigned int dwarf_regnames_count;
6851 /* A marker for a col_type that means this column was never referenced
6852 in the frame info. */
6853 #define DW_CFA_unreferenced (-1)
6855 /* Return 0 if no more space is needed, 1 if more space is needed,
6856 -1 for invalid reg. */
6859 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6861 unsigned int prev = fc->ncols;
6863 if (reg < (unsigned int) fc->ncols)
6866 if (dwarf_regnames_count
6867 && reg > dwarf_regnames_count)
6870 fc->ncols = reg + 1;
6871 /* PR 17512: file: 10450-2643-0.004.
6872 If reg == -1 then this can happen... */
6876 /* PR 17512: file: 2844a11d. */
6877 if (fc->ncols > 1024)
6879 error (_("Unfeasibly large register number: %u\n"), reg);
6881 /* FIXME: 1024 is an arbitrary limit. Increase it if
6882 we ever encounter a valid binary that exceeds it. */
6886 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6887 sizeof (short int));
6888 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6889 /* PR 17512: file:002-10025-0.005. */
6890 if (fc->col_type == NULL || fc->col_offset == NULL)
6892 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6898 while (prev < fc->ncols)
6900 fc->col_type[prev] = DW_CFA_unreferenced;
6901 fc->col_offset[prev] = 0;
6907 static const char *const dwarf_regnames_i386[] =
6909 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6910 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6911 "eip", "eflags", NULL, /* 8 - 10 */
6912 "st0", "st1", "st2", "st3", /* 11 - 14 */
6913 "st4", "st5", "st6", "st7", /* 15 - 18 */
6914 NULL, NULL, /* 19 - 20 */
6915 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6916 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6917 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6918 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6919 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6920 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6921 "tr", "ldtr", /* 48 - 49 */
6922 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6923 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6924 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6925 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6926 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6927 NULL, NULL, NULL, /* 90 - 92 */
6928 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6931 static const char *const dwarf_regnames_iamcu[] =
6933 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6934 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6935 "eip", "eflags", NULL, /* 8 - 10 */
6936 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6937 NULL, NULL, /* 19 - 20 */
6938 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6939 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6940 NULL, NULL, NULL, /* 37 - 39 */
6941 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6942 "tr", "ldtr", /* 48 - 49 */
6943 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6944 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6945 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6946 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6947 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6948 NULL, NULL, NULL, /* 90 - 92 */
6949 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6953 init_dwarf_regnames_i386 (void)
6955 dwarf_regnames = dwarf_regnames_i386;
6956 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6960 init_dwarf_regnames_iamcu (void)
6962 dwarf_regnames = dwarf_regnames_iamcu;
6963 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6966 static const char *const dwarf_regnames_x86_64[] =
6968 "rax", "rdx", "rcx", "rbx",
6969 "rsi", "rdi", "rbp", "rsp",
6970 "r8", "r9", "r10", "r11",
6971 "r12", "r13", "r14", "r15",
6973 "xmm0", "xmm1", "xmm2", "xmm3",
6974 "xmm4", "xmm5", "xmm6", "xmm7",
6975 "xmm8", "xmm9", "xmm10", "xmm11",
6976 "xmm12", "xmm13", "xmm14", "xmm15",
6977 "st0", "st1", "st2", "st3",
6978 "st4", "st5", "st6", "st7",
6979 "mm0", "mm1", "mm2", "mm3",
6980 "mm4", "mm5", "mm6", "mm7",
6982 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6983 "fs.base", "gs.base", NULL, NULL,
6985 "mxcsr", "fcw", "fsw",
6986 "xmm16", "xmm17", "xmm18", "xmm19",
6987 "xmm20", "xmm21", "xmm22", "xmm23",
6988 "xmm24", "xmm25", "xmm26", "xmm27",
6989 "xmm28", "xmm29", "xmm30", "xmm31",
6990 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6991 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6992 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6993 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6994 NULL, NULL, NULL, /* 115 - 117 */
6995 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6999 init_dwarf_regnames_x86_64 (void)
7001 dwarf_regnames = dwarf_regnames_x86_64;
7002 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
7005 static const char *const dwarf_regnames_aarch64[] =
7007 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7008 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7009 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7010 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7011 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
7012 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7013 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7014 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7015 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7016 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7017 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7018 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7022 init_dwarf_regnames_aarch64 (void)
7024 dwarf_regnames = dwarf_regnames_aarch64;
7025 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
7028 static const char *const dwarf_regnames_s390[] =
7030 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7031 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7032 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7033 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7034 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7035 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7036 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7037 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7038 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7041 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7042 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7046 init_dwarf_regnames_s390 (void)
7048 dwarf_regnames = dwarf_regnames_s390;
7049 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
7053 init_dwarf_regnames (unsigned int e_machine)
7058 init_dwarf_regnames_i386 ();
7062 init_dwarf_regnames_iamcu ();
7068 init_dwarf_regnames_x86_64 ();
7072 init_dwarf_regnames_aarch64 ();
7076 init_dwarf_regnames_s390 ();
7085 regname (unsigned int regno, int row)
7087 static char reg[64];
7090 && regno < dwarf_regnames_count
7091 && dwarf_regnames [regno] != NULL)
7094 return dwarf_regnames [regno];
7095 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
7096 dwarf_regnames [regno]);
7099 snprintf (reg, sizeof (reg), "r%d", regno);
7104 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
7109 if (*max_regs != fc->ncols)
7110 *max_regs = fc->ncols;
7112 if (*need_col_headers)
7114 static const char *sloc = " LOC";
7116 *need_col_headers = 0;
7118 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
7120 for (r = 0; r < *max_regs; r++)
7121 if (fc->col_type[r] != DW_CFA_unreferenced)
7126 printf ("%-5s ", regname (r, 1));
7132 print_dwarf_vma (fc->pc_begin, eh_addr_size);
7134 strcpy (tmp, "exp");
7136 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
7137 printf ("%-8s ", tmp);
7139 for (r = 0; r < fc->ncols; r++)
7141 if (fc->col_type[r] != DW_CFA_unreferenced)
7143 switch (fc->col_type[r])
7145 case DW_CFA_undefined:
7148 case DW_CFA_same_value:
7152 sprintf (tmp, "c%+d", fc->col_offset[r]);
7154 case DW_CFA_val_offset:
7155 sprintf (tmp, "v%+d", fc->col_offset[r]);
7157 case DW_CFA_register:
7158 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
7160 case DW_CFA_expression:
7161 strcpy (tmp, "exp");
7163 case DW_CFA_val_expression:
7164 strcpy (tmp, "vexp");
7167 strcpy (tmp, "n/a");
7170 printf ("%-5s ", tmp);
7176 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7178 static unsigned char *
7179 read_cie (unsigned char *start, unsigned char *end,
7180 Frame_Chunk **p_cie, int *p_version,
7181 bfd_size_type *p_aug_len, unsigned char **p_aug)
7185 unsigned int length_return;
7186 unsigned char *augmentation_data = NULL;
7187 bfd_size_type augmentation_data_len = 0;
7190 /* PR 17512: file: 001-228113-0.004. */
7194 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7195 memset (fc, 0, sizeof (Frame_Chunk));
7197 fc->col_type = (short int *) xmalloc (sizeof (short int));
7198 fc->col_offset = (int *) xmalloc (sizeof (int));
7202 fc->augmentation = (char *) start;
7203 /* PR 17512: file: 001-228113-0.004.
7204 Skip past augmentation name, but avoid running off the end of the data. */
7206 if (* start ++ == '\0')
7210 warn (_("No terminator for augmentation name\n"));
7214 if (strcmp (fc->augmentation, "eh") == 0)
7215 start += eh_addr_size;
7219 GET (fc->ptr_size, 1);
7220 if (fc->ptr_size < 1 || fc->ptr_size > 8)
7222 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
7226 GET (fc->segment_size, 1);
7227 /* PR 17512: file: e99d2804. */
7228 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
7230 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
7234 eh_addr_size = fc->ptr_size;
7238 fc->ptr_size = eh_addr_size;
7239 fc->segment_size = 0;
7241 READ_ULEB (fc->code_factor);
7242 READ_SLEB (fc->data_factor);
7252 if (fc->augmentation[0] == 'z')
7254 READ_ULEB (augmentation_data_len);
7255 augmentation_data = start;
7256 /* PR 17512: file: 11042-2589-0.004. */
7257 if (augmentation_data_len > (bfd_size_type) (end - start))
7259 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7260 dwarf_vmatoa ("x", augmentation_data_len),
7261 (unsigned long) (end - start));
7264 start += augmentation_data_len;
7267 if (augmentation_data_len)
7271 unsigned char *qend;
7273 p = (unsigned char *) fc->augmentation + 1;
7274 q = augmentation_data;
7275 qend = q + augmentation_data_len;
7277 while (p < end && q < qend)
7282 q += 1 + size_of_encoded_value (*q);
7284 fc->fde_encoding = *q++;
7291 /* Note - it is OK if this loop terminates with q < qend.
7292 Padding may have been inserted to align the end of the CIE. */
7297 *p_version = version;
7300 *p_aug_len = augmentation_data_len;
7301 *p_aug = augmentation_data;
7306 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7307 If do_wide is not enabled, then formats the output to fit into 80 columns.
7308 PRINTED contains the number of characters already written to the current
7312 display_data (bfd_size_type printed,
7313 const unsigned char * data,
7314 const bfd_size_type len)
7316 if (do_wide || len < ((80 - printed) / 3))
7317 for (printed = 0; printed < len; ++printed)
7318 printf (" %02x", data[printed]);
7321 for (printed = 0; printed < len; ++printed)
7323 if (printed % (80 / 3) == 0)
7325 printf (" %02x", data[printed]);
7330 /* Prints out the contents on the augmentation data array.
7331 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7334 display_augmentation_data (const unsigned char * data, const bfd_size_type len)
7338 i = printf (_(" Augmentation data: "));
7339 display_data (i, data, len);
7343 display_debug_frames (struct dwarf_section *section,
7344 void *file ATTRIBUTE_UNUSED)
7346 unsigned char *start = section->start;
7347 unsigned char *end = start + section->size;
7348 unsigned char *section_start = start;
7349 Frame_Chunk *chunks = 0, *forward_refs = 0;
7350 Frame_Chunk *remembered_state = 0;
7352 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7353 unsigned int length_return;
7354 unsigned int max_regs = 0;
7355 const char *bad_reg = _("bad register: ");
7356 unsigned int saved_eh_addr_size = eh_addr_size;
7358 introduce (section, FALSE);
7362 unsigned char *saved_start;
7363 unsigned char *block_end;
7368 int need_col_headers = 1;
7369 unsigned char *augmentation_data = NULL;
7370 bfd_size_type augmentation_data_len = 0;
7371 unsigned int encoded_ptr_size = saved_eh_addr_size;
7372 unsigned int offset_size;
7373 unsigned int initial_length_size;
7374 bfd_boolean all_nops;
7376 saved_start = start;
7378 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
7382 printf ("\n%08lx ZERO terminator\n\n",
7383 (unsigned long)(saved_start - section_start));
7384 /* Skip any zero terminators that directly follow.
7385 A corrupt section size could have loaded a whole
7386 slew of zero filled memory bytes. eg
7387 PR 17512: file: 070-19381-0.004. */
7388 while (start < end && * start == 0)
7393 if (length == 0xffffffff)
7395 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
7397 initial_length_size = 12;
7402 initial_length_size = 4;
7405 block_end = saved_start + length + initial_length_size;
7406 if (block_end > end || block_end < start)
7408 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7409 dwarf_vmatoa_1 (NULL, length, offset_size),
7410 (unsigned long) (saved_start - section_start));
7414 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
7416 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7417 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
7422 start = read_cie (start, end, &cie, &version,
7423 &augmentation_data_len, &augmentation_data);
7424 /* PR 17512: file: 027-135133-0.005. */
7431 fc->chunk_start = saved_start;
7432 mreg = max_regs > 0 ? max_regs - 1 : 0;
7435 if (frame_need_space (fc, mreg) < 0)
7437 if (fc->fde_encoding)
7438 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7440 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7441 print_dwarf_vma (length, fc->ptr_size);
7442 print_dwarf_vma (cie_id, offset_size);
7444 if (do_debug_frames_interp)
7446 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7447 fc->code_factor, fc->data_factor, fc->ra);
7452 printf (" Version: %d\n", version);
7453 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7456 printf (" Pointer Size: %u\n", fc->ptr_size);
7457 printf (" Segment Size: %u\n", fc->segment_size);
7459 printf (" Code alignment factor: %u\n", fc->code_factor);
7460 printf (" Data alignment factor: %d\n", fc->data_factor);
7461 printf (" Return address column: %d\n", fc->ra);
7463 if (augmentation_data_len)
7464 display_augmentation_data (augmentation_data, augmentation_data_len);
7471 unsigned char *look_for;
7472 static Frame_Chunk fde_fc;
7473 unsigned long segment_selector;
7477 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7478 look_for = start - 4 - ((cie_id ^ sign) - sign);
7481 look_for = section_start + cie_id;
7483 if (look_for <= saved_start)
7485 for (cie = chunks; cie ; cie = cie->next)
7486 if (cie->chunk_start == look_for)
7491 for (cie = forward_refs; cie ; cie = cie->next)
7492 if (cie->chunk_start == look_for)
7496 unsigned int off_size;
7497 unsigned char *cie_scan;
7499 cie_scan = look_for;
7501 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7502 if (length == 0xffffffff)
7504 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7511 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7514 : ((off_size == 4 && c_id == DW_CIE_ID)
7515 || (off_size == 8 && c_id == DW64_CIE_ID)))
7520 read_cie (cie_scan, end, &cie, &version,
7521 &augmentation_data_len, &augmentation_data);
7522 /* PR 17512: file: 3450-2098-0.004. */
7525 warn (_("Failed to read CIE information\n"));
7528 cie->next = forward_refs;
7530 cie->chunk_start = look_for;
7531 mreg = max_regs > 0 ? max_regs - 1 : 0;
7534 if (frame_need_space (cie, mreg) < 0)
7536 warn (_("Invalid max register\n"));
7539 if (cie->fde_encoding)
7541 = size_of_encoded_value (cie->fde_encoding);
7548 memset (fc, 0, sizeof (Frame_Chunk));
7552 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7553 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7554 (unsigned long) (saved_start - section_start));
7556 fc->col_type = (short int *) xmalloc (sizeof (short int));
7557 fc->col_offset = (int *) xmalloc (sizeof (int));
7558 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7560 warn (_("Invalid max register\n"));
7564 fc->augmentation = "";
7565 fc->fde_encoding = 0;
7566 fc->ptr_size = eh_addr_size;
7567 fc->segment_size = 0;
7571 fc->ncols = cie->ncols;
7572 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7573 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
7574 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7575 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7576 fc->augmentation = cie->augmentation;
7577 fc->ptr_size = cie->ptr_size;
7578 eh_addr_size = cie->ptr_size;
7579 fc->segment_size = cie->segment_size;
7580 fc->code_factor = cie->code_factor;
7581 fc->data_factor = cie->data_factor;
7582 fc->cfa_reg = cie->cfa_reg;
7583 fc->cfa_offset = cie->cfa_offset;
7585 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7587 warn (_("Invalid max register\n"));
7590 fc->fde_encoding = cie->fde_encoding;
7593 if (fc->fde_encoding)
7594 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7596 segment_selector = 0;
7597 if (fc->segment_size)
7599 if (fc->segment_size > sizeof (segment_selector))
7601 /* PR 17512: file: 9e196b3e. */
7602 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7603 fc->segment_size = 4;
7605 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7608 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
7610 /* FIXME: It appears that sometimes the final pc_range value is
7611 encoded in less than encoded_ptr_size bytes. See the x86_64
7612 run of the "objcopy on compressed debug sections" test for an
7614 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
7616 if (cie->augmentation[0] == 'z')
7618 READ_ULEB (augmentation_data_len);
7619 augmentation_data = start;
7620 start += augmentation_data_len;
7621 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7623 || ((bfd_signed_vma) augmentation_data_len) < 0
7624 || augmentation_data > start)
7626 warn (_("Corrupt augmentation data length: 0x%s\n"),
7627 dwarf_vmatoa ("x", augmentation_data_len));
7629 augmentation_data = NULL;
7630 augmentation_data_len = 0;
7634 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7635 (unsigned long)(saved_start - section_start),
7636 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7637 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7638 (unsigned long)(cie->chunk_start - section_start));
7640 if (fc->segment_size)
7641 printf ("%04lx:", segment_selector);
7644 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7645 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7647 if (! do_debug_frames_interp && augmentation_data_len)
7649 display_augmentation_data (augmentation_data, augmentation_data_len);
7654 /* At this point, fc is the current chunk, cie (if any) is set, and
7655 we're about to interpret instructions for the chunk. */
7656 /* ??? At present we need to do this always, since this sizes the
7657 fc->col_type and fc->col_offset arrays, which we write into always.
7658 We should probably split the interpreted and non-interpreted bits
7659 into two different routines, since there's so much that doesn't
7660 really overlap between them. */
7661 if (1 || do_debug_frames_interp)
7663 /* Start by making a pass over the chunk, allocating storage
7664 and taking note of what registers are used. */
7665 unsigned char *tmp = start;
7667 while (start < block_end)
7669 unsigned int reg, op, opa;
7671 unsigned char * new_start;
7678 /* Warning: if you add any more cases to this switch, be
7679 sure to add them to the corresponding switch below. */
7682 case DW_CFA_advance_loc:
7686 if (frame_need_space (fc, opa) >= 0)
7687 fc->col_type[opa] = DW_CFA_undefined;
7689 case DW_CFA_restore:
7690 if (frame_need_space (fc, opa) >= 0)
7691 fc->col_type[opa] = DW_CFA_undefined;
7693 case DW_CFA_set_loc:
7694 start += encoded_ptr_size;
7696 case DW_CFA_advance_loc1:
7699 case DW_CFA_advance_loc2:
7702 case DW_CFA_advance_loc4:
7705 case DW_CFA_offset_extended:
7706 case DW_CFA_val_offset:
7709 if (frame_need_space (fc, reg) >= 0)
7710 fc->col_type[reg] = DW_CFA_undefined;
7712 case DW_CFA_restore_extended:
7714 if (frame_need_space (fc, reg) >= 0)
7715 fc->col_type[reg] = DW_CFA_undefined;
7717 case DW_CFA_undefined:
7719 if (frame_need_space (fc, reg) >= 0)
7720 fc->col_type[reg] = DW_CFA_undefined;
7722 case DW_CFA_same_value:
7724 if (frame_need_space (fc, reg) >= 0)
7725 fc->col_type[reg] = DW_CFA_undefined;
7727 case DW_CFA_register:
7730 if (frame_need_space (fc, reg) >= 0)
7731 fc->col_type[reg] = DW_CFA_undefined;
7733 case DW_CFA_def_cfa:
7737 case DW_CFA_def_cfa_register:
7740 case DW_CFA_def_cfa_offset:
7743 case DW_CFA_def_cfa_expression:
7745 new_start = start + temp;
7746 if (new_start < start)
7748 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7754 case DW_CFA_expression:
7755 case DW_CFA_val_expression:
7758 new_start = start + temp;
7759 if (new_start < start)
7761 /* PR 17512: file:306-192417-0.005. */
7762 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7767 if (frame_need_space (fc, reg) >= 0)
7768 fc->col_type[reg] = DW_CFA_undefined;
7770 case DW_CFA_offset_extended_sf:
7771 case DW_CFA_val_offset_sf:
7774 if (frame_need_space (fc, reg) >= 0)
7775 fc->col_type[reg] = DW_CFA_undefined;
7777 case DW_CFA_def_cfa_sf:
7781 case DW_CFA_def_cfa_offset_sf:
7784 case DW_CFA_MIPS_advance_loc8:
7787 case DW_CFA_GNU_args_size:
7790 case DW_CFA_GNU_negative_offset_extended:
7793 if (frame_need_space (fc, reg) >= 0)
7794 fc->col_type[reg] = DW_CFA_undefined;
7805 /* Now we know what registers are used, make a second pass over
7806 the chunk, this time actually printing out the info. */
7808 while (start < block_end)
7810 unsigned char * tmp;
7812 unsigned long ul, roffs;
7813 /* Note: It is tempting to use an unsigned long for 'reg' but there
7814 are various functions, notably frame_space_needed() that assume that
7815 reg is an unsigned int. */
7820 const char *reg_prefix = "";
7827 /* Make a note if something other than DW_CFA_nop happens. */
7828 if (op != DW_CFA_nop)
7831 /* Warning: if you add any more cases to this switch, be
7832 sure to add them to the corresponding switch above. */
7835 case DW_CFA_advance_loc:
7836 if (do_debug_frames_interp)
7837 frame_display_row (fc, &need_col_headers, &max_regs);
7839 printf (" DW_CFA_advance_loc: %d to %s\n",
7840 opa * fc->code_factor,
7841 dwarf_vmatoa_1 (NULL,
7842 fc->pc_begin + opa * fc->code_factor,
7844 fc->pc_begin += opa * fc->code_factor;
7849 if (opa >= (unsigned int) fc->ncols)
7850 reg_prefix = bad_reg;
7851 if (! do_debug_frames_interp || *reg_prefix != '\0')
7852 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7853 reg_prefix, regname (opa, 0),
7854 roffs * fc->data_factor);
7855 if (*reg_prefix == '\0')
7857 fc->col_type[opa] = DW_CFA_offset;
7858 fc->col_offset[opa] = roffs * fc->data_factor;
7862 case DW_CFA_restore:
7863 if (opa >= (unsigned int) fc->ncols)
7864 reg_prefix = bad_reg;
7865 if (! do_debug_frames_interp || *reg_prefix != '\0')
7866 printf (" DW_CFA_restore: %s%s\n",
7867 reg_prefix, regname (opa, 0));
7868 if (*reg_prefix != '\0')
7871 if (opa >= (unsigned int) cie->ncols
7872 || (do_debug_frames_interp
7873 && cie->col_type[opa] == DW_CFA_unreferenced))
7875 fc->col_type[opa] = DW_CFA_undefined;
7876 fc->col_offset[opa] = 0;
7880 fc->col_type[opa] = cie->col_type[opa];
7881 fc->col_offset[opa] = cie->col_offset[opa];
7885 case DW_CFA_set_loc:
7886 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7887 if (do_debug_frames_interp)
7888 frame_display_row (fc, &need_col_headers, &max_regs);
7890 printf (" DW_CFA_set_loc: %s\n",
7891 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7895 case DW_CFA_advance_loc1:
7896 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7897 if (do_debug_frames_interp)
7898 frame_display_row (fc, &need_col_headers, &max_regs);
7900 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7901 (unsigned long) (ofs * fc->code_factor),
7902 dwarf_vmatoa_1 (NULL,
7903 fc->pc_begin + ofs * fc->code_factor,
7905 fc->pc_begin += ofs * fc->code_factor;
7908 case DW_CFA_advance_loc2:
7909 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7910 if (do_debug_frames_interp)
7911 frame_display_row (fc, &need_col_headers, &max_regs);
7913 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7914 (unsigned long) (ofs * fc->code_factor),
7915 dwarf_vmatoa_1 (NULL,
7916 fc->pc_begin + ofs * fc->code_factor,
7918 fc->pc_begin += ofs * fc->code_factor;
7921 case DW_CFA_advance_loc4:
7922 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7923 if (do_debug_frames_interp)
7924 frame_display_row (fc, &need_col_headers, &max_regs);
7926 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7927 (unsigned long) (ofs * fc->code_factor),
7928 dwarf_vmatoa_1 (NULL,
7929 fc->pc_begin + ofs * fc->code_factor,
7931 fc->pc_begin += ofs * fc->code_factor;
7934 case DW_CFA_offset_extended:
7937 if (reg >= (unsigned int) fc->ncols)
7938 reg_prefix = bad_reg;
7939 if (! do_debug_frames_interp || *reg_prefix != '\0')
7940 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7941 reg_prefix, regname (reg, 0),
7942 roffs * fc->data_factor);
7943 if (*reg_prefix == '\0')
7945 fc->col_type[reg] = DW_CFA_offset;
7946 fc->col_offset[reg] = roffs * fc->data_factor;
7950 case DW_CFA_val_offset:
7953 if (reg >= (unsigned int) fc->ncols)
7954 reg_prefix = bad_reg;
7955 if (! do_debug_frames_interp || *reg_prefix != '\0')
7956 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7957 reg_prefix, regname (reg, 0),
7958 roffs * fc->data_factor);
7959 if (*reg_prefix == '\0')
7961 fc->col_type[reg] = DW_CFA_val_offset;
7962 fc->col_offset[reg] = roffs * fc->data_factor;
7966 case DW_CFA_restore_extended:
7968 if (reg >= (unsigned int) fc->ncols)
7969 reg_prefix = bad_reg;
7970 if (! do_debug_frames_interp || *reg_prefix != '\0')
7971 printf (" DW_CFA_restore_extended: %s%s\n",
7972 reg_prefix, regname (reg, 0));
7973 if (*reg_prefix != '\0')
7976 if (reg >= (unsigned int) cie->ncols)
7978 fc->col_type[reg] = DW_CFA_undefined;
7979 fc->col_offset[reg] = 0;
7983 fc->col_type[reg] = cie->col_type[reg];
7984 fc->col_offset[reg] = cie->col_offset[reg];
7988 case DW_CFA_undefined:
7990 if (reg >= (unsigned int) fc->ncols)
7991 reg_prefix = bad_reg;
7992 if (! do_debug_frames_interp || *reg_prefix != '\0')
7993 printf (" DW_CFA_undefined: %s%s\n",
7994 reg_prefix, regname (reg, 0));
7995 if (*reg_prefix == '\0')
7997 fc->col_type[reg] = DW_CFA_undefined;
7998 fc->col_offset[reg] = 0;
8002 case DW_CFA_same_value:
8004 if (reg >= (unsigned int) fc->ncols)
8005 reg_prefix = bad_reg;
8006 if (! do_debug_frames_interp || *reg_prefix != '\0')
8007 printf (" DW_CFA_same_value: %s%s\n",
8008 reg_prefix, regname (reg, 0));
8009 if (*reg_prefix == '\0')
8011 fc->col_type[reg] = DW_CFA_same_value;
8012 fc->col_offset[reg] = 0;
8016 case DW_CFA_register:
8019 if (reg >= (unsigned int) fc->ncols)
8020 reg_prefix = bad_reg;
8021 if (! do_debug_frames_interp || *reg_prefix != '\0')
8023 printf (" DW_CFA_register: %s%s in ",
8024 reg_prefix, regname (reg, 0));
8025 puts (regname (roffs, 0));
8027 if (*reg_prefix == '\0')
8029 fc->col_type[reg] = DW_CFA_register;
8030 fc->col_offset[reg] = roffs;
8034 case DW_CFA_remember_state:
8035 if (! do_debug_frames_interp)
8036 printf (" DW_CFA_remember_state\n");
8037 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8038 rs->cfa_offset = fc->cfa_offset;
8039 rs->cfa_reg = fc->cfa_reg;
8041 rs->cfa_exp = fc->cfa_exp;
8042 rs->ncols = fc->ncols;
8043 rs->col_type = (short int *) xcmalloc (rs->ncols,
8044 sizeof (* rs->col_type));
8045 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
8046 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
8047 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
8048 rs->next = remembered_state;
8049 remembered_state = rs;
8052 case DW_CFA_restore_state:
8053 if (! do_debug_frames_interp)
8054 printf (" DW_CFA_restore_state\n");
8055 rs = remembered_state;
8058 remembered_state = rs->next;
8059 fc->cfa_offset = rs->cfa_offset;
8060 fc->cfa_reg = rs->cfa_reg;
8062 fc->cfa_exp = rs->cfa_exp;
8063 if (frame_need_space (fc, rs->ncols - 1) < 0)
8065 warn (_("Invalid column number in saved frame state\n"));
8069 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
8070 memcpy (fc->col_offset, rs->col_offset,
8071 rs->ncols * sizeof (* rs->col_offset));
8072 free (rs->col_type);
8073 free (rs->col_offset);
8076 else if (do_debug_frames_interp)
8077 printf ("Mismatched DW_CFA_restore_state\n");
8080 case DW_CFA_def_cfa:
8081 READ_ULEB (fc->cfa_reg);
8082 READ_ULEB (fc->cfa_offset);
8084 if (! do_debug_frames_interp)
8085 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8086 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8089 case DW_CFA_def_cfa_register:
8090 READ_ULEB (fc->cfa_reg);
8092 if (! do_debug_frames_interp)
8093 printf (" DW_CFA_def_cfa_register: %s\n",
8094 regname (fc->cfa_reg, 0));
8097 case DW_CFA_def_cfa_offset:
8098 READ_ULEB (fc->cfa_offset);
8099 if (! do_debug_frames_interp)
8100 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
8104 if (! do_debug_frames_interp)
8105 printf (" DW_CFA_nop\n");
8108 case DW_CFA_def_cfa_expression:
8110 if (start >= block_end || ul > (unsigned long) (block_end - start))
8112 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
8115 if (! do_debug_frames_interp)
8117 printf (" DW_CFA_def_cfa_expression (");
8118 decode_location_expression (start, eh_addr_size, 0, -1,
8126 case DW_CFA_expression:
8129 if (reg >= (unsigned int) fc->ncols)
8130 reg_prefix = bad_reg;
8131 /* PR 17512: file: 069-133014-0.006. */
8132 /* PR 17512: file: 98c02eb4. */
8134 if (start >= block_end || tmp > block_end || tmp < start)
8136 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
8139 if (! do_debug_frames_interp || *reg_prefix != '\0')
8141 printf (" DW_CFA_expression: %s%s (",
8142 reg_prefix, regname (reg, 0));
8143 decode_location_expression (start, eh_addr_size, 0, -1,
8147 if (*reg_prefix == '\0')
8148 fc->col_type[reg] = DW_CFA_expression;
8152 case DW_CFA_val_expression:
8155 if (reg >= (unsigned int) fc->ncols)
8156 reg_prefix = bad_reg;
8158 if (start >= block_end || tmp > block_end || tmp < start)
8160 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
8163 if (! do_debug_frames_interp || *reg_prefix != '\0')
8165 printf (" DW_CFA_val_expression: %s%s (",
8166 reg_prefix, regname (reg, 0));
8167 decode_location_expression (start, eh_addr_size, 0, -1,
8171 if (*reg_prefix == '\0')
8172 fc->col_type[reg] = DW_CFA_val_expression;
8176 case DW_CFA_offset_extended_sf:
8179 if (frame_need_space (fc, reg) < 0)
8180 reg_prefix = bad_reg;
8181 if (! do_debug_frames_interp || *reg_prefix != '\0')
8182 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8183 reg_prefix, regname (reg, 0),
8184 (long)(l * fc->data_factor));
8185 if (*reg_prefix == '\0')
8187 fc->col_type[reg] = DW_CFA_offset;
8188 fc->col_offset[reg] = l * fc->data_factor;
8192 case DW_CFA_val_offset_sf:
8195 if (frame_need_space (fc, reg) < 0)
8196 reg_prefix = bad_reg;
8197 if (! do_debug_frames_interp || *reg_prefix != '\0')
8198 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8199 reg_prefix, regname (reg, 0),
8200 (long)(l * fc->data_factor));
8201 if (*reg_prefix == '\0')
8203 fc->col_type[reg] = DW_CFA_val_offset;
8204 fc->col_offset[reg] = l * fc->data_factor;
8208 case DW_CFA_def_cfa_sf:
8209 READ_ULEB (fc->cfa_reg);
8210 READ_ULEB (fc->cfa_offset);
8211 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
8213 if (! do_debug_frames_interp)
8214 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8215 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8218 case DW_CFA_def_cfa_offset_sf:
8219 READ_ULEB (fc->cfa_offset);
8220 fc->cfa_offset *= fc->data_factor;
8221 if (! do_debug_frames_interp)
8222 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
8225 case DW_CFA_MIPS_advance_loc8:
8226 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
8227 if (do_debug_frames_interp)
8228 frame_display_row (fc, &need_col_headers, &max_regs);
8230 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8231 (unsigned long) (ofs * fc->code_factor),
8232 dwarf_vmatoa_1 (NULL,
8233 fc->pc_begin + ofs * fc->code_factor,
8235 fc->pc_begin += ofs * fc->code_factor;
8238 case DW_CFA_GNU_window_save:
8239 if (! do_debug_frames_interp)
8240 printf (" DW_CFA_GNU_window_save\n");
8243 case DW_CFA_GNU_args_size:
8245 if (! do_debug_frames_interp)
8246 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8249 case DW_CFA_GNU_negative_offset_extended:
8253 if (frame_need_space (fc, reg) < 0)
8254 reg_prefix = bad_reg;
8255 if (! do_debug_frames_interp || *reg_prefix != '\0')
8256 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8257 reg_prefix, regname (reg, 0),
8258 (long)(l * fc->data_factor));
8259 if (*reg_prefix == '\0')
8261 fc->col_type[reg] = DW_CFA_offset;
8262 fc->col_offset[reg] = l * fc->data_factor;
8267 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
8268 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
8270 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
8275 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8276 if (do_debug_frames_interp && ! all_nops)
8277 frame_display_row (fc, &need_col_headers, &max_regs);
8280 eh_addr_size = saved_eh_addr_size;
8291 display_debug_names (struct dwarf_section *section, void *file)
8293 unsigned char *hdrptr = section->start;
8294 dwarf_vma unit_length;
8295 unsigned char *unit_start;
8296 const unsigned char *const section_end = section->start + section->size;
8297 unsigned char *unit_end;
8299 introduce (section, FALSE);
8301 load_debug_section_with_follow (str, file);
8303 for (; hdrptr < section_end; hdrptr = unit_end)
8305 unsigned int offset_size;
8306 uint16_t dwarf_version, padding;
8307 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8308 uint32_t bucket_count, name_count, abbrev_table_size;
8309 uint32_t augmentation_string_size;
8311 unsigned long sec_off;
8313 unit_start = hdrptr;
8315 /* Get and check the length of the block. */
8316 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8318 if (unit_length == 0xffffffff)
8320 /* This section is 64-bit DWARF. */
8321 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8326 unit_end = hdrptr + unit_length;
8328 sec_off = hdrptr - section->start;
8329 if (sec_off + unit_length < sec_off
8330 || sec_off + unit_length > section->size)
8332 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8334 (unsigned long) (unit_start - section->start),
8335 dwarf_vmatoa ("x", unit_length));
8339 /* Get and check the version number. */
8340 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8341 printf (_("Version %ld\n"), (long) dwarf_version);
8343 /* Prior versions did not exist, and future versions may not be
8344 backwards compatible. */
8345 if (dwarf_version != 5)
8347 warn (_("Only DWARF version 5 .debug_names "
8348 "is currently supported.\n"));
8352 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8354 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8357 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8358 if (comp_unit_count == 0)
8359 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8361 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8362 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8363 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8364 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8365 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8367 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8368 if (augmentation_string_size % 4 != 0)
8370 warn (_("Augmentation string length %u must be rounded up "
8371 "to a multiple of 4 in .debug_names.\n"),
8372 augmentation_string_size);
8373 augmentation_string_size += (-augmentation_string_size) & 3;
8375 printf (_("Augmentation string:"));
8376 for (i = 0; i < augmentation_string_size; i++)
8380 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8381 printf (" %02x", uc);
8386 printf (_("CU table:\n"));
8387 for (i = 0; i < comp_unit_count; i++)
8391 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8392 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8396 printf (_("TU table:\n"));
8397 for (i = 0; i < local_type_unit_count; i++)
8401 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8402 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8406 printf (_("Foreign TU table:\n"));
8407 for (i = 0; i < foreign_type_unit_count; i++)
8411 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8412 printf (_("[%3u] "), i);
8413 print_dwarf_vma (signature, 8);
8418 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8419 hdrptr += bucket_count * sizeof (uint32_t);
8420 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8421 hdrptr += name_count * sizeof (uint32_t);
8422 unsigned char *const name_table_string_offsets = hdrptr;
8423 hdrptr += name_count * offset_size;
8424 unsigned char *const name_table_entry_offsets = hdrptr;
8425 hdrptr += name_count * offset_size;
8426 unsigned char *const abbrev_table = hdrptr;
8427 hdrptr += abbrev_table_size;
8428 const unsigned char *const abbrev_table_end = hdrptr;
8429 unsigned char *const entry_pool = hdrptr;
8430 if (hdrptr > unit_end)
8432 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8433 "for unit 0x%lx in the debug_names\n"),
8434 (long) (hdrptr - section->start),
8435 (long) (unit_end - section->start),
8436 (long) (unit_start - section->start));
8440 size_t buckets_filled = 0;
8442 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8444 const uint32_t bucket = hash_table_buckets[bucketi];
8449 printf (ngettext ("Used %zu of %lu bucket.\n",
8450 "Used %zu of %lu buckets.\n",
8452 buckets_filled, (unsigned long) bucket_count);
8454 uint32_t hash_prev = 0;
8455 size_t hash_clash_count = 0;
8456 size_t longest_clash = 0;
8457 size_t this_length = 0;
8459 for (hashi = 0; hashi < name_count; hashi++)
8461 const uint32_t hash_this = hash_table_hashes[hashi];
8465 if (hash_prev % bucket_count == hash_this % bucket_count)
8469 longest_clash = MAX (longest_clash, this_length);
8474 hash_prev = hash_this;
8476 printf (_("Out of %lu items there are %zu bucket clashes"
8477 " (longest of %zu entries).\n"),
8478 (unsigned long) name_count, hash_clash_count, longest_clash);
8479 assert (name_count == buckets_filled + hash_clash_count);
8481 struct abbrev_lookup_entry
8483 dwarf_vma abbrev_tag;
8484 unsigned char *abbrev_lookup_ptr;
8486 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8487 size_t abbrev_lookup_used = 0;
8488 size_t abbrev_lookup_allocated = 0;
8490 unsigned char *abbrevptr = abbrev_table;
8493 unsigned int bytes_read;
8494 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8496 abbrevptr += bytes_read;
8497 if (abbrev_tag == 0)
8499 if (abbrev_lookup_used == abbrev_lookup_allocated)
8501 abbrev_lookup_allocated = MAX (0x100,
8502 abbrev_lookup_allocated * 2);
8503 abbrev_lookup = xrealloc (abbrev_lookup,
8504 (abbrev_lookup_allocated
8505 * sizeof (*abbrev_lookup)));
8507 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8508 struct abbrev_lookup_entry *entry;
8509 for (entry = abbrev_lookup;
8510 entry < abbrev_lookup + abbrev_lookup_used;
8512 if (entry->abbrev_tag == abbrev_tag)
8514 warn (_("Duplicate abbreviation tag %lu "
8515 "in unit 0x%lx in the debug_names\n"),
8516 (long) abbrev_tag, (long) (unit_start - section->start));
8519 entry = &abbrev_lookup[abbrev_lookup_used++];
8520 entry->abbrev_tag = abbrev_tag;
8521 entry->abbrev_lookup_ptr = abbrevptr;
8523 /* Skip DWARF tag. */
8524 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8525 abbrevptr += bytes_read;
8528 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8531 abbrevptr += bytes_read;
8532 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8534 abbrevptr += bytes_read;
8535 if (xindex == 0 && form == 0)
8540 printf (_("\nSymbol table:\n"));
8542 for (namei = 0; namei < name_count; ++namei)
8544 uint64_t string_offset, entry_offset;
8546 SAFE_BYTE_GET (string_offset,
8547 name_table_string_offsets + namei * offset_size,
8548 offset_size, unit_end);
8549 SAFE_BYTE_GET (entry_offset,
8550 name_table_entry_offsets + namei * offset_size,
8551 offset_size, unit_end);
8553 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8554 fetch_indirect_string (string_offset));
8556 unsigned char *entryptr = entry_pool + entry_offset;
8558 // We need to scan first whether there is a single or multiple
8559 // entries. TAGNO is -2 for the first entry, it is -1 for the
8560 // initial tag read of the second entry, then it becomes 0 for the
8561 // first entry for real printing etc.
8563 /* Initialize it due to a false compiler warning. */
8564 dwarf_vma second_abbrev_tag = -1;
8567 unsigned int bytes_read;
8568 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8570 entryptr += bytes_read;
8573 second_abbrev_tag = abbrev_tag;
8575 entryptr = entry_pool + entry_offset;
8578 if (abbrev_tag == 0)
8582 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8583 (unsigned long) abbrev_tag);
8585 const struct abbrev_lookup_entry *entry;
8586 for (entry = abbrev_lookup;
8587 entry < abbrev_lookup + abbrev_lookup_used;
8589 if (entry->abbrev_tag == abbrev_tag)
8591 if (entry >= abbrev_lookup + abbrev_lookup_used)
8593 warn (_("Undefined abbreviation tag %lu "
8594 "in unit 0x%lx in the debug_names\n"),
8596 (long) (unit_start - section->start));
8599 abbrevptr = entry->abbrev_lookup_ptr;
8600 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8602 abbrevptr += bytes_read;
8604 printf (" %s", get_TAG_name (dwarf_tag));
8607 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8610 abbrevptr += bytes_read;
8611 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8613 abbrevptr += bytes_read;
8614 if (xindex == 0 && form == 0)
8618 printf (" %s", get_IDX_name (xindex));
8619 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8622 dwarf_version, NULL,
8629 printf (_(" <no entries>"));
8633 free (abbrev_lookup);
8640 display_debug_links (struct dwarf_section * section,
8641 void * file ATTRIBUTE_UNUSED)
8643 const unsigned char * filename;
8644 unsigned int filelen;
8646 introduce (section, FALSE);
8648 /* The .gnu_debuglink section is formatted as:
8649 (c-string) Filename.
8650 (padding) If needed to reach a 4 byte boundary.
8651 (uint32_t) CRC32 value.
8653 The .gun_debugaltlink section is formatted as:
8654 (c-string) Filename.
8655 (binary) Build-ID. */
8657 filename = section->start;
8658 filelen = strnlen ((const char *) filename, section->size);
8659 if (filelen == section->size)
8661 warn (_("The debuglink filename is corrupt/missing\n"));
8665 printf (_(" Separate debug info file: %s\n"), filename);
8667 if (const_strneq (section->name, ".gnu_debuglink"))
8670 unsigned int crc_offset;
8672 crc_offset = filelen + 1;
8673 crc_offset = (crc_offset + 3) & ~3;
8674 if (crc_offset + 4 > section->size)
8676 warn (_("CRC offset missing/truncated\n"));
8680 crc32 = byte_get (filename + crc_offset, 4);
8682 printf (_(" CRC value: %#x\n"), crc32);
8684 if (crc_offset + 4 < section->size)
8686 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
8687 (long)(section->size - (crc_offset + 4)));
8691 else /* const_strneq (section->name, ".gnu_debugaltlink") */
8693 const unsigned char * build_id = section->start + filelen + 1;
8694 bfd_size_type build_id_len = section->size - (filelen + 1);
8695 bfd_size_type printed;
8697 /* FIXME: Should we support smaller build-id notes ? */
8698 if (build_id_len < 0x14)
8700 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
8704 printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
8705 display_data (printed, build_id, build_id_len);
8714 display_gdb_index (struct dwarf_section *section,
8715 void *file ATTRIBUTE_UNUSED)
8717 unsigned char *start = section->start;
8719 uint32_t cu_list_offset, tu_list_offset;
8720 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8721 unsigned int cu_list_elements, tu_list_elements;
8722 unsigned int address_table_size, symbol_table_slots;
8723 unsigned char *cu_list, *tu_list;
8724 unsigned char *address_table, *symbol_table, *constant_pool;
8727 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8729 introduce (section, FALSE);
8731 if (section->size < 6 * sizeof (uint32_t))
8733 warn (_("Truncated header in the %s section.\n"), section->name);
8737 version = byte_get_little_endian (start, 4);
8738 printf (_("Version %ld\n"), (long) version);
8740 /* Prior versions are obsolete, and future versions may not be
8741 backwards compatible. */
8742 if (version < 3 || version > 8)
8744 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8748 warn (_("The address table data in version 3 may be wrong.\n"));
8750 warn (_("Version 4 does not support case insensitive lookups.\n"));
8752 warn (_("Version 5 does not include inlined functions.\n"));
8754 warn (_("Version 6 does not include symbol attributes.\n"));
8755 /* Version 7 indices generated by Gold have bad type unit references,
8756 PR binutils/15021. But we don't know if the index was generated by
8757 Gold or not, so to avoid worrying users with gdb-generated indices
8758 we say nothing for version 7 here. */
8760 cu_list_offset = byte_get_little_endian (start + 4, 4);
8761 tu_list_offset = byte_get_little_endian (start + 8, 4);
8762 address_table_offset = byte_get_little_endian (start + 12, 4);
8763 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8764 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8766 if (cu_list_offset > section->size
8767 || tu_list_offset > section->size
8768 || address_table_offset > section->size
8769 || symbol_table_offset > section->size
8770 || constant_pool_offset > section->size)
8772 warn (_("Corrupt header in the %s section.\n"), section->name);
8776 /* PR 17531: file: 418d0a8a. */
8777 if (tu_list_offset < cu_list_offset)
8779 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8780 tu_list_offset, cu_list_offset);
8784 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8786 if (address_table_offset < tu_list_offset)
8788 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8789 address_table_offset, tu_list_offset);
8793 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8795 /* PR 17531: file: 18a47d3d. */
8796 if (symbol_table_offset < address_table_offset)
8798 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8799 symbol_table_offset, address_table_offset);
8803 address_table_size = symbol_table_offset - address_table_offset;
8805 if (constant_pool_offset < symbol_table_offset)
8807 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8808 constant_pool_offset, symbol_table_offset);
8812 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8814 cu_list = start + cu_list_offset;
8815 tu_list = start + tu_list_offset;
8816 address_table = start + address_table_offset;
8817 symbol_table = start + symbol_table_offset;
8818 constant_pool = start + constant_pool_offset;
8820 if (address_table + address_table_size > section->start + section->size)
8822 warn (_("Address table extends beyond end of section.\n"));
8826 printf (_("\nCU table:\n"));
8827 for (i = 0; i < cu_list_elements; i += 2)
8829 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8830 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8832 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8833 (unsigned long) cu_offset,
8834 (unsigned long) (cu_offset + cu_length - 1));
8837 printf (_("\nTU table:\n"));
8838 for (i = 0; i < tu_list_elements; i += 3)
8840 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8841 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8842 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8844 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8845 (unsigned long) tu_offset,
8846 (unsigned long) type_offset);
8847 print_dwarf_vma (signature, 8);
8851 printf (_("\nAddress table:\n"));
8852 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8855 uint64_t low = byte_get_little_endian (address_table + i, 8);
8856 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8857 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8859 print_dwarf_vma (low, 8);
8860 print_dwarf_vma (high, 8);
8861 printf (_("%lu\n"), (unsigned long) cu_index);
8864 printf (_("\nSymbol table:\n"));
8865 for (i = 0; i < symbol_table_slots; ++i)
8867 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8868 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8869 uint32_t num_cus, cu;
8871 if (name_offset != 0
8872 || cu_vector_offset != 0)
8875 unsigned char * adr;
8877 adr = constant_pool + name_offset;
8878 /* PR 17531: file: 5b7b07ad. */
8879 if (adr < constant_pool || adr >= section->start + section->size)
8881 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8882 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8886 printf ("[%3u] %.*s:", i,
8887 (int) (section->size - (constant_pool_offset + name_offset)),
8888 constant_pool + name_offset);
8890 adr = constant_pool + cu_vector_offset;
8891 if (adr < constant_pool || adr >= section->start + section->size - 3)
8893 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8894 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8895 cu_vector_offset, i);
8899 num_cus = byte_get_little_endian (adr, 4);
8901 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8902 if (num_cus * 4 < num_cus
8903 || adr >= section->start + section->size
8904 || adr < constant_pool)
8906 printf ("<invalid number of CUs: %d>\n", num_cus);
8907 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8915 for (j = 0; j < num_cus; ++j)
8918 gdb_index_symbol_kind kind;
8920 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8921 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8922 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8923 cu = GDB_INDEX_CU_VALUE (cu);
8924 /* Convert to TU number if it's for a type unit. */
8925 if (cu >= cu_list_elements / 2)
8926 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8927 (unsigned long) (cu - cu_list_elements / 2));
8929 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8931 printf (" [%s, %s]",
8932 is_static ? _("static") : _("global"),
8933 get_gdb_index_symbol_kind_name (kind));
8945 /* Pre-allocate enough space for the CU/TU sets needed. */
8948 prealloc_cu_tu_list (unsigned int nshndx)
8950 if (shndx_pool == NULL)
8952 shndx_pool_size = nshndx;
8953 shndx_pool_used = 0;
8954 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8955 sizeof (unsigned int));
8959 shndx_pool_size = shndx_pool_used + nshndx;
8960 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8961 sizeof (unsigned int));
8966 add_shndx_to_cu_tu_entry (unsigned int shndx)
8968 if (shndx_pool_used >= shndx_pool_size)
8970 error (_("Internal error: out of space in the shndx pool.\n"));
8973 shndx_pool [shndx_pool_used++] = shndx;
8977 end_cu_tu_entry (void)
8979 if (shndx_pool_used >= shndx_pool_size)
8981 error (_("Internal error: out of space in the shndx pool.\n"));
8984 shndx_pool [shndx_pool_used++] = 0;
8987 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8990 get_DW_SECT_short_name (unsigned int dw_sect)
8992 static char buf[16];
9000 case DW_SECT_ABBREV:
9006 case DW_SECT_STR_OFFSETS:
9008 case DW_SECT_MACINFO:
9016 snprintf (buf, sizeof (buf), "%d", dw_sect);
9020 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9021 These sections are extensions for Fission.
9022 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9025 process_cu_tu_index (struct dwarf_section *section, int do_display)
9027 unsigned char *phdr = section->start;
9028 unsigned char *limit = phdr + section->size;
9029 unsigned char *phash;
9030 unsigned char *pindex;
9031 unsigned char *ppool;
9032 unsigned int version;
9033 unsigned int ncols = 0;
9035 unsigned int nslots;
9038 dwarf_vma signature_high;
9039 dwarf_vma signature_low;
9042 /* PR 17512: file: 002-168123-0.004. */
9045 warn (_("Section %s is empty\n"), section->name);
9048 /* PR 17512: file: 002-376-0.004. */
9049 if (section->size < 24)
9051 warn (_("Section %s is too small to contain a CU/TU header\n"),
9056 SAFE_BYTE_GET (version, phdr, 4, limit);
9058 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
9059 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
9060 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
9063 pindex = phash + nslots * 8;
9064 ppool = pindex + nslots * 4;
9066 /* PR 17531: file: 45d69832. */
9067 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
9069 warn (ngettext ("Section %s is too small for %d slot\n",
9070 "Section %s is too small for %d slots\n",
9072 section->name, nslots);
9078 introduce (section, FALSE);
9080 printf (_(" Version: %d\n"), version);
9082 printf (_(" Number of columns: %d\n"), ncols);
9083 printf (_(" Number of used entries: %d\n"), nused);
9084 printf (_(" Number of slots: %d\n\n"), nslots);
9087 if (ppool > limit || ppool < phdr)
9089 warn (_("Section %s too small for %d hash table entries\n"),
9090 section->name, nslots);
9097 prealloc_cu_tu_list ((limit - ppool) / 4);
9098 for (i = 0; i < nslots; i++)
9100 unsigned char *shndx_list;
9103 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
9104 if (signature_high != 0 || signature_low != 0)
9106 SAFE_BYTE_GET (j, pindex, 4, limit);
9107 shndx_list = ppool + j * 4;
9108 /* PR 17531: file: 705e010d. */
9109 if (shndx_list < ppool)
9111 warn (_("Section index pool located before start of section\n"));
9116 printf (_(" [%3d] Signature: 0x%s Sections: "),
9117 i, dwarf_vmatoa64 (signature_high, signature_low,
9118 buf, sizeof (buf)));
9121 if (shndx_list >= limit)
9123 warn (_("Section %s too small for shndx pool\n"),
9127 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
9131 printf (" %d", shndx);
9133 add_shndx_to_cu_tu_entry (shndx);
9145 else if (version == 2)
9148 unsigned int dw_sect;
9149 unsigned char *ph = phash;
9150 unsigned char *pi = pindex;
9151 unsigned char *poffsets = ppool + ncols * 4;
9152 unsigned char *psizes = poffsets + nused * ncols * 4;
9153 unsigned char *pend = psizes + nused * ncols * 4;
9154 bfd_boolean is_tu_index;
9155 struct cu_tu_set *this_set = NULL;
9157 unsigned char *prow;
9159 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
9161 /* PR 17531: file: 0dd159bf.
9162 Check for wraparound with an overlarge ncols value. */
9163 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
9165 warn (_("Overlarge number of columns: %x\n"), ncols);
9171 warn (_("Section %s too small for offset and size tables\n"),
9178 printf (_(" Offset table\n"));
9179 printf (" slot %-16s ",
9180 is_tu_index ? _("signature") : _("dwo_id"));
9187 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9193 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9200 for (j = 0; j < ncols; j++)
9202 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9203 printf (" %8s", get_DW_SECT_short_name (dw_sect));
9208 for (i = 0; i < nslots; i++)
9210 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9212 SAFE_BYTE_GET (row, pi, 4, limit);
9215 /* PR 17531: file: a05f6ab3. */
9218 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9224 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
9226 prow = poffsets + (row - 1) * ncols * 4;
9227 /* PR 17531: file: b8ce60a8. */
9228 if (prow < poffsets || prow > limit)
9230 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9236 printf (_(" [%3d] 0x%s"),
9237 i, dwarf_vmatoa64 (signature_high, signature_low,
9238 buf, sizeof (buf)));
9239 for (j = 0; j < ncols; j++)
9241 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9243 printf (" %8d", val);
9246 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9248 /* PR 17531: file: 10796eb3. */
9249 if (dw_sect >= DW_SECT_MAX)
9250 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9252 this_set [row - 1].section_offsets [dw_sect] = val;
9268 printf (_(" Size table\n"));
9269 printf (" slot %-16s ",
9270 is_tu_index ? _("signature") : _("dwo_id"));
9273 for (j = 0; j < ncols; j++)
9275 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
9277 printf (" %8s", get_DW_SECT_short_name (val));
9283 for (i = 0; i < nslots; i++)
9285 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9287 SAFE_BYTE_GET (row, pi, 4, limit);
9290 prow = psizes + (row - 1) * ncols * 4;
9293 printf (_(" [%3d] 0x%s"),
9294 i, dwarf_vmatoa64 (signature_high, signature_low,
9295 buf, sizeof (buf)));
9297 for (j = 0; j < ncols; j++)
9299 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9301 printf (" %8d", val);
9304 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9305 if (dw_sect >= DW_SECT_MAX)
9306 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9308 this_set [row - 1].section_sizes [dw_sect] = val;
9320 else if (do_display)
9321 printf (_(" Unsupported version (%d)\n"), version);
9329 /* Load the CU and TU indexes if present. This will build a list of
9330 section sets that we can use to associate a .debug_info.dwo section
9331 with its associated .debug_abbrev.dwo section in a .dwp file. */
9334 load_cu_tu_indexes (void *file)
9336 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
9338 /* If we have already loaded (or tried to load) the CU and TU indexes
9339 then do not bother to repeat the task. */
9340 if (cu_tu_indexes_read == -1)
9342 cu_tu_indexes_read = TRUE;
9344 if (load_debug_section_with_follow (dwp_cu_index, file))
9345 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
9346 cu_tu_indexes_read = FALSE;
9348 if (load_debug_section_with_follow (dwp_tu_index, file))
9349 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
9350 cu_tu_indexes_read = FALSE;
9353 return (bfd_boolean) cu_tu_indexes_read;
9356 /* Find the set of sections that includes section SHNDX. */
9359 find_cu_tu_set (void *file, unsigned int shndx)
9363 if (! load_cu_tu_indexes (file))
9366 /* Find SHNDX in the shndx pool. */
9367 for (i = 0; i < shndx_pool_used; i++)
9368 if (shndx_pool [i] == shndx)
9371 if (i >= shndx_pool_used)
9374 /* Now backup to find the first entry in the set. */
9375 while (i > 0 && shndx_pool [i - 1] != 0)
9378 return shndx_pool + i;
9381 /* Display a .debug_cu_index or .debug_tu_index section. */
9384 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9386 return process_cu_tu_index (section, 1);
9390 display_debug_not_supported (struct dwarf_section *section,
9391 void *file ATTRIBUTE_UNUSED)
9393 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9399 /* Like malloc, but takes two parameters like calloc.
9400 Verifies that the first parameter is not too large.
9401 Note: does *not* initialise the allocated memory to zero. */
9404 cmalloc (size_t nmemb, size_t size)
9406 /* Check for overflow. */
9407 if (nmemb >= ~(size_t) 0 / size)
9410 return xmalloc (nmemb * size);
9413 /* Like xmalloc, but takes two parameters like calloc.
9414 Verifies that the first parameter is not too large.
9415 Note: does *not* initialise the allocated memory to zero. */
9418 xcmalloc (size_t nmemb, size_t size)
9420 /* Check for overflow. */
9421 if (nmemb >= ~(size_t) 0 / size)
9424 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9429 return xmalloc (nmemb * size);
9432 /* Like xrealloc, but takes three parameters.
9433 Verifies that the second parameter is not too large.
9434 Note: does *not* initialise any new memory to zero. */
9437 xcrealloc (void *ptr, size_t nmemb, size_t size)
9439 /* Check for overflow. */
9440 if (nmemb >= ~(size_t) 0 / size)
9442 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9447 return xrealloc (ptr, nmemb * size);
9450 /* Like xcalloc, but verifies that the first parameter is not too large. */
9453 xcalloc2 (size_t nmemb, size_t size)
9455 /* Check for overflow. */
9456 if (nmemb >= ~(size_t) 0 / size)
9458 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9463 return xcalloc (nmemb, size);
9466 static unsigned long
9467 calc_gnu_debuglink_crc32 (unsigned long crc,
9468 const unsigned char * buf,
9471 static const unsigned long crc32_table[256] =
9473 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9474 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9475 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9476 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9477 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9478 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9479 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9480 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9481 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9482 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9483 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9484 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9485 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9486 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9487 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9488 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9489 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9490 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9491 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9492 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9493 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9494 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9495 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9496 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9497 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9498 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9499 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9500 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9501 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9502 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9503 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9504 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9505 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9506 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9507 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9508 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
9509 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
9510 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
9511 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
9512 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
9513 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
9514 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
9515 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
9516 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
9517 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
9518 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
9519 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
9520 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
9521 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
9522 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
9523 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
9526 const unsigned char *end;
9528 crc = ~crc & 0xffffffff;
9529 for (end = buf + len; buf < end; ++ buf)
9530 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
9531 return ~crc & 0xffffffff;
9534 typedef bfd_boolean (* check_func_type) (const char *, void *);
9535 typedef const char * (* parse_func_type) (struct dwarf_section *, void *);
9538 check_gnu_debuglink (const char * pathname, void * crc_pointer)
9540 static unsigned char buffer [8 * 1024];
9542 bfd_size_type count;
9543 unsigned long crc = 0;
9546 sep_data = open_debug_file (pathname);
9547 if (sep_data == NULL)
9550 /* Yes - we are opening the file twice... */
9551 f = fopen (pathname, "rb");
9554 /* Paranoia: This should never happen. */
9555 close_debug_file (sep_data);
9556 warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
9560 while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
9561 crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
9565 if (crc != * (unsigned long *) crc_pointer)
9567 close_debug_file (sep_data);
9568 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
9577 parse_gnu_debuglink (struct dwarf_section * section, void * data)
9580 unsigned int crc_offset;
9581 unsigned long * crc32 = (unsigned long *) data;
9583 /* The name is first.
9584 The CRC value is stored after the filename, aligned up to 4 bytes. */
9585 name = (const char *) section->start;
9587 crc_offset = strnlen (name, section->size) + 1;
9588 crc_offset = (crc_offset + 3) & ~3;
9589 if (crc_offset + 4 > section->size)
9592 * crc32 = byte_get (section->start + crc_offset, 4);
9597 check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
9599 void * sep_data = open_debug_file (filename);
9601 if (sep_data == NULL)
9604 /* FIXME: We should now extract the build-id in the separate file
9610 typedef struct build_id_data
9613 const unsigned char * data;
9617 parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
9620 bfd_size_type namelen;
9621 bfd_size_type id_len;
9622 Build_id_data * build_id_data;
9624 /* The name is first.
9625 The build-id follows immediately, with no padding, up to the section's end. */
9627 name = (const char *) section->start;
9628 namelen = strnlen (name, section->size) + 1;
9629 if (namelen >= section->size)
9632 id_len = section->size - namelen;
9636 build_id_data = calloc (1, sizeof * build_id_data);
9637 if (build_id_data == NULL)
9640 build_id_data->len = id_len;
9641 build_id_data->data = section->start + namelen;
9643 * (Build_id_data **) data = build_id_data;
9649 load_separate_debug_info (const char * main_filename,
9650 struct dwarf_section * link,
9651 parse_func_type parse_func,
9652 check_func_type check_func,
9655 const char * separate_filename;
9658 size_t canon_dirlen;
9661 if ((separate_filename = parse_func (link, func_data)) == NULL)
9663 warn (_("Corrupt debuglink section: %s\n"),
9664 link->name ? link->name : link->uncompressed_name);
9668 /* Attempt to locate the separate file.
9669 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
9671 canon_dir = lrealpath (main_filename);
9673 for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
9674 if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
9676 canon_dir[canon_dirlen] = '\0';
9679 #define DEBUGDIR "/lib/debug"
9681 #ifndef EXTRA_DEBUG_ROOT1
9682 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
9684 #ifndef EXTRA_DEBUG_ROOT2
9685 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
9688 debugfile = (char *) malloc (strlen (DEBUGDIR) + 1
9690 + strlen (".debug/")
9691 #ifdef EXTRA_DEBUG_ROOT1
9692 + strlen (EXTRA_DEBUG_ROOT1)
9694 #ifdef EXTRA_DEBUG_ROOT2
9695 + strlen (EXTRA_DEBUG_ROOT2)
9697 + strlen (separate_filename)
9699 if (debugfile == NULL)
9701 warn (_("Out of memory"));
9705 /* First try in the current directory. */
9706 sprintf (debugfile, "%s", separate_filename);
9707 if (check_func (debugfile, func_data))
9710 /* Then try in a subdirectory called .debug. */
9711 sprintf (debugfile, ".debug/%s", separate_filename);
9712 if (check_func (debugfile, func_data))
9715 /* Then try in the same directory as the original file. */
9716 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9717 if (check_func (debugfile, func_data))
9720 /* And the .debug subdirectory of that directory. */
9721 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9722 if (check_func (debugfile, func_data))
9725 #ifdef EXTRA_DEBUG_ROOT1
9726 /* Try the first extra debug file root. */
9727 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9728 if (check_func (debugfile, func_data))
9732 #ifdef EXTRA_DEBUG_ROOT2
9733 /* Try the second extra debug file root. */
9734 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9735 if (check_func (debugfile, func_data))
9739 /* Then try in the global debugfile directory. */
9740 strcpy (debugfile, DEBUGDIR);
9741 dirlen = strlen (DEBUGDIR) - 1;
9742 if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
9743 strcat (debugfile, "/");
9744 strcat (debugfile, (const char *) separate_filename);
9746 if (check_func (debugfile, func_data))
9749 /* Failed to find the file. */
9750 warn (_("could not find separate debug file '%s'\n"), separate_filename);
9751 warn (_("tried: %s\n"), debugfile);
9753 #ifdef EXTRA_DEBUG_ROOT2
9754 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9755 warn (_("tried: %s\n"), debugfile);
9758 #ifdef EXTRA_DEBUG_ROOT1
9759 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9760 warn (_("tried: %s\n"), debugfile);
9763 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9764 warn (_("tried: %s\n"), debugfile);
9766 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9767 warn (_("tried: %s\n"), debugfile);
9769 sprintf (debugfile, ".debug/%s", separate_filename);
9770 warn (_("tried: %s\n"), debugfile);
9772 sprintf (debugfile, "%s", separate_filename);
9773 warn (_("tried: %s\n"), debugfile);
9782 /* Now open the file.... */
9783 if ((separate_debug_file = open_debug_file (debugfile)) == NULL)
9785 warn (_("failed to open separate debug file: %s\n"), debugfile);
9790 /* FIXME: We do not check to see if there are any other separate debug info
9791 files that would also match. */
9793 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debugfile);
9794 separate_debug_filename = debugfile;
9796 /* Do not free debugfile - it might be referenced inside
9797 the structure returned by open_debug_file(). */
9798 return separate_debug_file;
9801 /* Attempt to load a separate dwarf object file. */
9804 load_dwo_file (const char * main_filename)
9808 /* FIXME: Skip adding / if dwo_dir ends in /. */
9809 filename = concat (dwo_dir, "/", dwo_name, NULL);
9810 if (filename == NULL)
9812 warn (_("Out of memory allocating dwo filename\n"));
9816 if ((separate_debug_file = open_debug_file (filename)) == NULL)
9818 warn (_("Unable to load dwo file: %s\n"), filename);
9823 /* FIXME: We should check the dwo_id. */
9825 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, filename);
9826 separate_debug_filename = filename;
9827 return separate_debug_file;
9830 /* Load a separate debug info file, if it exists.
9831 Returns the data pointer that is the result of calling open_debug_file
9832 on the separate debug info file, or NULL if there were problems or there
9836 load_separate_debug_file (void * file, const char * filename)
9838 /* See if there is a dwo link. */
9839 if (load_debug_section (str, file)
9840 && load_debug_section (abbrev, file)
9841 && load_debug_section (info, file))
9843 dwo_name = dwo_dir = NULL;
9847 if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE))
9849 if (dwo_name != NULL)
9853 printf (_("The %s section contains a link to a dwo file:\n"),
9854 debug_displays [info].section.uncompressed_name);
9855 printf (_(" Name: %s\n"), dwo_name);
9856 printf (_(" Directory: %s\n"), dwo_dir ? dwo_dir : _("<not-found>"));
9858 display_data (printf (_(" ID: ")), dwo_id, dwo_id_len);
9860 printf (_(" ID: <unknown>\n"));
9864 /* FIXME: We do not check to see if there are any more dwo links in the file... */
9865 if (do_follow_links)
9866 return load_dwo_file (filename);
9871 if (! do_follow_links)
9874 /* FIXME: We do not check for the presence of both link sections in the same file. */
9875 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
9876 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
9877 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
9879 if (load_debug_section (gnu_debugaltlink, file))
9881 Build_id_data * build_id_data;
9883 return load_separate_debug_info (filename,
9884 & debug_displays[gnu_debugaltlink].section,
9885 parse_gnu_debugaltlink,
9886 check_gnu_debugaltlink,
9890 if (load_debug_section (gnu_debuglink, file))
9892 unsigned long crc32;
9894 return load_separate_debug_info (filename,
9895 & debug_displays[gnu_debuglink].section,
9896 parse_gnu_debuglink,
9897 check_gnu_debuglink,
9901 do_follow_links = 0;
9906 free_debug_memory (void)
9912 for (i = 0; i < max; i++)
9913 free_debug_section ((enum dwarf_section_display_enum) i);
9915 if (debug_information != NULL)
9917 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
9919 for (i = 0; i < num_debug_info_entries; i++)
9921 if (!debug_information [i].max_loc_offsets)
9923 free (debug_information [i].loc_offsets);
9924 free (debug_information [i].have_frame_base);
9926 if (!debug_information [i].max_range_lists)
9927 free (debug_information [i].range_lists);
9930 free (debug_information);
9931 debug_information = NULL;
9932 alloc_num_debug_info_entries = num_debug_info_entries = 0;
9935 if (separate_debug_file != NULL)
9937 close_debug_file (separate_debug_file);
9938 separate_debug_file = NULL;
9940 free ((void *) separate_debug_filename);
9941 separate_debug_filename = NULL;
9946 dwarf_select_sections_by_names (const char *names)
9950 const char * option;
9954 debug_dump_long_opts;
9956 static const debug_dump_long_opts opts_table [] =
9958 /* Please keep this table alpha- sorted. */
9959 { "Ranges", & do_debug_ranges, 1 },
9960 { "abbrev", & do_debug_abbrevs, 1 },
9961 { "addr", & do_debug_addr, 1 },
9962 { "aranges", & do_debug_aranges, 1 },
9963 { "cu_index", & do_debug_cu_index, 1 },
9964 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
9965 { "follow-links", & do_follow_links, 1 },
9966 { "frames", & do_debug_frames, 1 },
9967 { "frames-interp", & do_debug_frames_interp, 1 },
9968 /* The special .gdb_index section. */
9969 { "gdb_index", & do_gdb_index, 1 },
9970 { "info", & do_debug_info, 1 },
9971 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
9972 { "links", & do_debug_links, 1 },
9973 { "loc", & do_debug_loc, 1 },
9974 { "macro", & do_debug_macinfo, 1 },
9975 { "pubnames", & do_debug_pubnames, 1 },
9976 { "pubtypes", & do_debug_pubtypes, 1 },
9977 /* This entry is for compatibility
9978 with earlier versions of readelf. */
9979 { "ranges", & do_debug_aranges, 1 },
9980 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
9981 { "str", & do_debug_str, 1 },
9982 /* These trace_* sections are used by Itanium VMS. */
9983 { "trace_abbrev", & do_trace_abbrevs, 1 },
9984 { "trace_aranges", & do_trace_aranges, 1 },
9985 { "trace_info", & do_trace_info, 1 },
9994 const debug_dump_long_opts * entry;
9996 for (entry = opts_table; entry->option; entry++)
9998 size_t len = strlen (entry->option);
10000 if (strncmp (p, entry->option, len) == 0
10001 && (p[len] == ',' || p[len] == '\0'))
10003 * entry->variable |= entry->val;
10005 /* The --debug-dump=frames-interp option also
10006 enables the --debug-dump=frames option. */
10007 if (do_debug_frames_interp)
10008 do_debug_frames = 1;
10015 if (entry->option == NULL)
10017 warn (_("Unrecognized debug option '%s'\n"), p);
10018 p = strchr (p, ',');
10029 dwarf_select_sections_by_letters (const char *letters)
10031 unsigned int lindex = 0;
10033 while (letters[lindex])
10034 switch (letters[lindex++])
10036 case 'A': do_debug_addr = 1; break;
10037 case 'a': do_debug_abbrevs = 1; break;
10038 case 'c': do_debug_cu_index = 1; break;
10039 case 'F': do_debug_frames_interp = 1; /* Fall through. */
10040 case 'f': do_debug_frames = 1; break;
10041 case 'g': do_gdb_index = 1; break;
10042 case 'i': do_debug_info = 1; break;
10043 case 'K': do_follow_links = 1; break;
10044 case 'k': do_debug_links = 1; break;
10045 case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
10046 case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
10047 case 'm': do_debug_macinfo = 1; break;
10048 case 'o': do_debug_loc = 1; break;
10049 case 'p': do_debug_pubnames = 1; break;
10050 case 'R': do_debug_ranges = 1; break;
10051 case 'r': do_debug_aranges = 1; break;
10052 case 's': do_debug_str = 1; break;
10053 case 'T': do_trace_aranges = 1; break;
10054 case 't': do_debug_pubtypes = 1; break;
10055 case 'U': do_trace_info = 1; break;
10056 case 'u': do_trace_abbrevs = 1; break;
10059 warn (_("Unrecognized debug option '%s'\n"), letters);
10065 dwarf_select_sections_all (void)
10068 do_debug_abbrevs = 1;
10069 do_debug_lines = FLAG_DEBUG_LINES_RAW;
10070 do_debug_pubnames = 1;
10071 do_debug_pubtypes = 1;
10072 do_debug_aranges = 1;
10073 do_debug_ranges = 1;
10074 do_debug_frames = 1;
10075 do_debug_macinfo = 1;
10080 do_trace_abbrevs = 1;
10081 do_trace_aranges = 1;
10083 do_debug_cu_index = 1;
10084 do_follow_links = 1;
10085 do_debug_links = 1;
10088 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10089 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10091 /* N.B. The order here must match the order in section_display_enum. */
10093 struct dwarf_section_display debug_displays[] =
10095 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
10096 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE },
10097 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
10098 { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE },
10099 { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
10100 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE },
10101 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
10102 { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
10103 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
10104 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
10105 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10106 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10107 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10108 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10109 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE },
10110 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
10111 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
10112 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
10113 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10114 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10115 { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE },
10116 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
10117 { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE },
10118 { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE },
10119 { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE },
10120 { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE },
10121 { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE },
10122 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE },
10123 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
10124 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE },
10125 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
10126 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
10127 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
10128 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
10129 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE },
10130 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
10131 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
10132 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE },
10133 { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
10134 { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
10135 { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
10136 { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
10137 /* Separate debug info files can containt their own .debug_str section,
10138 and this might be in *addition* to a .debug_str section already present
10139 in the main file. Hence we need to have two entries for .debug_str. */
10140 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10143 /* A static assertion. */
10144 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];