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 unsigned int eh_addr_size;
56 int do_debug_pubnames;
57 int do_debug_pubtypes;
61 int do_debug_frames_interp;
70 int do_debug_cu_index;
75 int dwarf_cutoff_level = -1;
76 unsigned long dwarf_start_die;
80 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
81 testing whether e.g. a locview list is present. */
82 static const dwarf_vma vm1 = -1;
84 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
85 sections. For version 1 package files, each set is stored in SHNDX_POOL
86 as a zero-terminated list of section indexes comprising one set of debug
87 sections from a .dwo file. */
89 static unsigned int *shndx_pool = NULL;
90 static unsigned int shndx_pool_size = 0;
91 static unsigned int shndx_pool_used = 0;
93 /* Pointer to a separate file containing extra debug information. */
94 static void * separate_debug_file = NULL;
95 static const char * separate_debug_filename = NULL;
97 /* For version 2 package files, each set contains an array of section offsets
98 and an array of section sizes, giving the offset and size of the
99 contribution from a CU or TU within one of the debug sections.
100 When displaying debug info from a package file, we need to use these
101 tables to locate the corresponding contributions to each section. */
106 dwarf_vma section_offsets[DW_SECT_MAX];
107 size_t section_sizes[DW_SECT_MAX];
110 static int cu_count = 0;
111 static int tu_count = 0;
112 static struct cu_tu_set *cu_sets = NULL;
113 static struct cu_tu_set *tu_sets = NULL;
115 static bfd_boolean load_cu_tu_indexes (void *);
117 /* Values for do_debug_lines. */
118 #define FLAG_DEBUG_LINES_RAW 1
119 #define FLAG_DEBUG_LINES_DECODED 2
122 size_of_encoded_value (int encoding)
124 switch (encoding & 0x7)
127 case 0: return eh_addr_size;
135 get_encoded_value (unsigned char **pdata,
137 struct dwarf_section *section,
140 unsigned char * data = * pdata;
141 unsigned int size = size_of_encoded_value (encoding);
144 if (data + size >= end)
146 warn (_("Encoded value extends past end of section\n"));
151 /* PR 17512: file: 002-829853-0.004. */
154 warn (_("Encoded size of %d is too large to read\n"), size);
159 /* PR 17512: file: 1085-5603-0.004. */
162 warn (_("Encoded size of 0 is too small to read\n"));
167 if (encoding & DW_EH_PE_signed)
168 val = byte_get_signed (data, size);
170 val = byte_get (data, size);
172 if ((encoding & 0x70) == DW_EH_PE_pcrel)
173 val += section->address + (data - section->start);
175 * pdata = data + size;
179 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
181 # define DWARF_VMA_FMT "ll"
182 # define DWARF_VMA_FMT_LONG "%16.16llx"
184 # define DWARF_VMA_FMT "I64"
185 # define DWARF_VMA_FMT_LONG "%016I64x"
188 # define DWARF_VMA_FMT "l"
189 # define DWARF_VMA_FMT_LONG "%16.16lx"
192 /* Convert a dwarf vma value into a string. Returns a pointer to a static
193 buffer containing the converted VALUE. The value is converted according
194 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
195 it specifies the maximum number of bytes to be displayed in the converted
196 value and FMTCH is ignored - hex is always used. */
199 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
201 /* As dwarf_vmatoa is used more then once in a printf call
202 for output, we are cycling through an fixed array of pointers
203 for return address. */
204 static int buf_pos = 0;
205 static struct dwarf_vmatoa_buf
211 ret = buf[buf_pos++].place;
212 buf_pos %= ARRAY_SIZE (buf);
216 /* Printf does not have a way of specifying a maximum field width for an
217 integer value, so we print the full value into a buffer and then select
218 the precision we need. */
219 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
222 return ret + (16 - 2 * num_bytes);
229 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
231 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
232 snprintf (ret, sizeof (buf[0].place), fmt, value);
237 static inline const char *
238 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
240 return dwarf_vmatoa_1 (fmtch, value, 0);
243 /* Print a dwarf_vma value (typically an address, offset or length) in
244 hexadecimal format, followed by a space. The length of the VALUE (and
245 hence the precision displayed) is determined by the NUM_BYTES parameter. */
248 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
250 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
253 /* Print a view number in hexadecimal value, with the same width
254 print_dwarf_vma would have printed it with the same num_bytes.
255 Print blanks for zero view, unless force is nonzero. */
258 print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
266 assert (value == (unsigned long) value);
268 printf ("v%0*lx ", len - 1, (unsigned long) value);
270 printf ("%*s", len + 1, "");
273 /* Format a 64-bit value, given as two 32-bit values, in hex.
274 For reentrancy, this uses a buffer provided by the caller. */
277 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
278 unsigned int buf_len)
283 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
286 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
287 snprintf (buf + len, buf_len - len,
288 "%08" DWARF_VMA_FMT "x", lvalue);
294 /* Read in a LEB128 encoded value starting at address DATA.
295 If SIGN is true, return a signed LEB128 value.
296 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
297 No bytes will be read at address END or beyond. */
300 read_leb128 (unsigned char *data,
301 unsigned int *length_return,
303 const unsigned char * const end)
305 dwarf_vma result = 0;
306 unsigned int num_read = 0;
307 unsigned int shift = 0;
308 unsigned char byte = 0;
315 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
318 if ((byte & 0x80) == 0)
321 /* PR 17512: file: 0ca183b8.
322 FIXME: Should we signal this error somehow ? */
323 if (shift >= sizeof (result) * 8)
327 if (length_return != NULL)
328 *length_return = num_read;
330 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
331 result |= -((dwarf_vma) 1 << shift);
336 /* Create a signed version to avoid painful typecasts. */
337 static inline dwarf_signed_vma
338 read_sleb128 (unsigned char * data,
339 unsigned int * length_return,
340 const unsigned char * const end)
342 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
345 static inline dwarf_vma
346 read_uleb128 (unsigned char * data,
347 unsigned int * length_return,
348 const unsigned char * const end)
350 return read_leb128 (data, length_return, FALSE, end);
353 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
354 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
356 #define READ_ULEB(var) \
361 (var) = _val = read_uleb128 (start, &length_return, end); \
363 error (_("Internal error: %s:%d: LEB value (%s) " \
364 "too large for containing variable\n"), \
365 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
366 start += length_return; \
370 #define READ_SLEB(var) \
373 dwarf_signed_vma _val; \
375 (var) = _val = read_sleb128 (start, &length_return, end); \
377 error (_("Internal error: %s:%d: LEB value (%s) " \
378 "too large for containing variable\n"), \
379 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
380 start += length_return; \
384 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
387 unsigned int amount = (AMOUNT); \
388 if (sizeof (VAL) < amount) \
390 error (ngettext ("internal error: attempt to read %d byte " \
391 "of data in to %d sized variable", \
392 "internal error: attempt to read %d bytes " \
393 "of data in to %d sized variable", \
395 amount, (int) sizeof (VAL)); \
396 amount = sizeof (VAL); \
398 if (((PTR) + amount) >= (END)) \
401 amount = (END) - (PTR); \
405 if (amount == 0 || amount > 8) \
408 VAL = byte_get ((PTR), amount); \
412 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
415 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
420 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
423 unsigned int amount = (AMOUNT); \
424 if (((PTR) + amount) >= (END)) \
427 amount = (END) - (PTR); \
432 VAL = byte_get_signed ((PTR), amount); \
438 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
441 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
446 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
449 if (((PTR) + 8) <= (END)) \
451 byte_get_64 ((PTR), (HIGH), (LOW)); \
455 * (LOW) = * (HIGH) = 0; \
460 typedef struct State_Machine_Registers
469 unsigned char op_index;
470 unsigned char end_sequence;
471 /* This variable hold the number of the last entry seen
472 in the File Table. */
473 unsigned int last_file_entry;
476 static SMR state_machine_regs;
479 reset_state_machine (int is_stmt)
481 state_machine_regs.address = 0;
482 state_machine_regs.view = 0;
483 state_machine_regs.op_index = 0;
484 state_machine_regs.file = 1;
485 state_machine_regs.line = 1;
486 state_machine_regs.column = 0;
487 state_machine_regs.is_stmt = is_stmt;
488 state_machine_regs.basic_block = 0;
489 state_machine_regs.end_sequence = 0;
490 state_machine_regs.last_file_entry = 0;
493 /* Handled an extend line op.
494 Returns the number of bytes read. */
497 process_extended_line_op (unsigned char * data,
501 unsigned char op_code;
502 unsigned int bytes_read;
505 unsigned char *orig_data = data;
508 len = read_uleb128 (data, & bytes_read, end);
511 if (len == 0 || data == end || len > (uintptr_t) (end - data))
513 warn (_("Badly formed extended line op encountered!\n"));
520 printf (_(" Extended opcode %d: "), op_code);
524 case DW_LNE_end_sequence:
525 printf (_("End of Sequence\n\n"));
526 reset_state_machine (is_stmt);
529 case DW_LNE_set_address:
530 /* PR 17512: file: 002-100480-0.004. */
531 if (len - bytes_read - 1 > 8)
533 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
534 len - bytes_read - 1);
538 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
539 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
540 state_machine_regs.address = adr;
541 state_machine_regs.view = 0;
542 state_machine_regs.op_index = 0;
545 case DW_LNE_define_file:
546 printf (_("define new File Table entry\n"));
547 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
548 printf (" %d\t", ++state_machine_regs.last_file_entry);
554 l = strnlen ((char *) data, end - data);
556 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
558 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
560 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
562 printf ("%.*s\n\n", (int) l, name);
565 if (((unsigned int) (data - orig_data) != len) || data == end)
566 warn (_("DW_LNE_define_file: Bad opcode length\n"));
569 case DW_LNE_set_discriminator:
570 printf (_("set Discriminator to %s\n"),
571 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
575 case DW_LNE_HP_negate_is_UV_update:
576 printf ("DW_LNE_HP_negate_is_UV_update\n");
578 case DW_LNE_HP_push_context:
579 printf ("DW_LNE_HP_push_context\n");
581 case DW_LNE_HP_pop_context:
582 printf ("DW_LNE_HP_pop_context\n");
584 case DW_LNE_HP_set_file_line_column:
585 printf ("DW_LNE_HP_set_file_line_column\n");
587 case DW_LNE_HP_set_routine_name:
588 printf ("DW_LNE_HP_set_routine_name\n");
590 case DW_LNE_HP_set_sequence:
591 printf ("DW_LNE_HP_set_sequence\n");
593 case DW_LNE_HP_negate_post_semantics:
594 printf ("DW_LNE_HP_negate_post_semantics\n");
596 case DW_LNE_HP_negate_function_exit:
597 printf ("DW_LNE_HP_negate_function_exit\n");
599 case DW_LNE_HP_negate_front_end_logical:
600 printf ("DW_LNE_HP_negate_front_end_logical\n");
602 case DW_LNE_HP_define_proc:
603 printf ("DW_LNE_HP_define_proc\n");
605 case DW_LNE_HP_source_file_correlation:
607 unsigned char *edata = data + len - bytes_read - 1;
609 printf ("DW_LNE_HP_source_file_correlation\n");
615 opc = read_uleb128 (data, & bytes_read, edata);
620 case DW_LNE_HP_SFC_formfeed:
621 printf (" DW_LNE_HP_SFC_formfeed\n");
623 case DW_LNE_HP_SFC_set_listing_line:
624 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
626 read_uleb128 (data, & bytes_read, edata)));
629 case DW_LNE_HP_SFC_associate:
630 printf (" DW_LNE_HP_SFC_associate ");
633 read_uleb128 (data, & bytes_read, edata)));
637 read_uleb128 (data, & bytes_read, edata)));
641 read_uleb128 (data, & bytes_read, edata)));
645 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
655 unsigned int rlen = len - bytes_read - 1;
657 if (op_code >= DW_LNE_lo_user
658 /* The test against DW_LNW_hi_user is redundant due to
659 the limited range of the unsigned char data type used
661 /*&& op_code <= DW_LNE_hi_user*/)
662 printf (_("user defined: "));
664 printf (_("UNKNOWN: "));
665 printf (_("length %d ["), rlen);
667 printf (" %02x", *data++);
676 static const unsigned char *
677 fetch_indirect_string (dwarf_vma offset)
679 struct dwarf_section *section = &debug_displays [str].section;
680 const unsigned char * ret;
682 if (section->start == NULL)
683 return (const unsigned char *) _("<no .debug_str section>");
685 if (offset >= section->size)
687 warn (_("DW_FORM_strp offset too big: %s\n"),
688 dwarf_vmatoa ("x", offset));
689 return (const unsigned char *) _("<offset is too big>");
692 ret = section->start + offset;
693 /* Unfortunately we cannot rely upon the .debug_str section ending with a
694 NUL byte. Since our caller is expecting to receive a well formed C
695 string we test for the lack of a terminating byte here. */
696 if (strnlen ((const char *) ret, section->size - offset)
697 == section->size - offset)
698 ret = (const unsigned char *)
699 _("<no NUL byte at end of .debug_str section>");
704 static const unsigned char *
705 fetch_indirect_line_string (dwarf_vma offset)
707 struct dwarf_section *section = &debug_displays [line_str].section;
708 const unsigned char * ret;
710 if (section->start == NULL)
711 return (const unsigned char *) _("<no .debug_line_str section>");
713 if (offset >= section->size)
715 warn (_("DW_FORM_line_strp offset too big: %s\n"),
716 dwarf_vmatoa ("x", offset));
717 return (const unsigned char *) _("<offset is too big>");
720 ret = section->start + offset;
721 /* Unfortunately we cannot rely upon the .debug_line_str section ending
722 with a NUL byte. Since our caller is expecting to receive a well formed
723 C string we test for the lack of a terminating byte here. */
724 if (strnlen ((const char *) ret, section->size - offset)
725 == section->size - offset)
726 ret = (const unsigned char *)
727 _("<no NUL byte at end of .debug_line_str section>");
733 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
734 dwarf_vma offset_size, int dwo)
736 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
737 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
738 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
739 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
740 dwarf_vma index_offset = idx * offset_size;
741 dwarf_vma str_offset;
744 if (index_section->start == NULL)
745 return (dwo ? _("<no .debug_str_offsets.dwo section>")
746 : _("<no .debug_str_offsets section>"));
748 if (this_set != NULL)
749 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
750 if (index_offset >= index_section->size)
752 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
753 dwarf_vmatoa ("x", index_offset));
754 return _("<index offset is too big>");
757 if (str_section->start == NULL)
758 return (dwo ? _("<no .debug_str.dwo section>")
759 : _("<no .debug_str section>"));
761 str_offset = byte_get (index_section->start + index_offset, offset_size);
762 str_offset -= str_section->address;
763 if (str_offset >= str_section->size)
765 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
766 dwarf_vmatoa ("x", str_offset));
767 return _("<indirect index offset is too big>");
770 ret = (const char *) str_section->start + str_offset;
771 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
772 Since our caller is expecting to receive a well formed C string we test
773 for the lack of a terminating byte here. */
774 if (strnlen (ret, str_section->size - str_offset)
775 == str_section->size - str_offset)
776 ret = (const char *) _("<no NUL byte at end of section>");
782 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
784 struct dwarf_section *section = &debug_displays [debug_addr].section;
786 if (section->start == NULL)
787 return (_("<no .debug_addr section>"));
789 if (offset + bytes > section->size)
791 warn (_("Offset into section %s too big: %s\n"),
792 section->name, dwarf_vmatoa ("x", offset));
793 return "<offset too big>";
796 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
800 /* FIXME: There are better and more efficient ways to handle
801 these structures. For now though, I just want something that
802 is simple to implement. */
803 typedef struct abbrev_attr
805 unsigned long attribute;
807 bfd_signed_vma implicit_const;
808 struct abbrev_attr *next;
812 typedef struct abbrev_entry
817 struct abbrev_attr *first_attr;
818 struct abbrev_attr *last_attr;
819 struct abbrev_entry *next;
823 static abbrev_entry *first_abbrev = NULL;
824 static abbrev_entry *last_abbrev = NULL;
831 for (abbrv = first_abbrev; abbrv;)
833 abbrev_entry *next_abbrev = abbrv->next;
836 for (attr = abbrv->first_attr; attr;)
838 abbrev_attr *next_attr = attr->next;
848 last_abbrev = first_abbrev = NULL;
852 add_abbrev (unsigned long number, unsigned long tag, int children)
856 entry = (abbrev_entry *) malloc (sizeof (*entry));
861 entry->entry = number;
863 entry->children = children;
864 entry->first_attr = NULL;
865 entry->last_attr = NULL;
868 if (first_abbrev == NULL)
869 first_abbrev = entry;
871 last_abbrev->next = entry;
877 add_abbrev_attr (unsigned long attribute, unsigned long form,
878 bfd_signed_vma implicit_const)
882 attr = (abbrev_attr *) malloc (sizeof (*attr));
887 attr->attribute = attribute;
889 attr->implicit_const = implicit_const;
892 if (last_abbrev->first_attr == NULL)
893 last_abbrev->first_attr = attr;
895 last_abbrev->last_attr->next = attr;
897 last_abbrev->last_attr = attr;
900 /* Processes the (partial) contents of a .debug_abbrev section.
901 Returns NULL if the end of the section was encountered.
902 Returns the address after the last byte read if the end of
903 an abbreviation set was found. */
905 static unsigned char *
906 process_abbrev_section (unsigned char *start, unsigned char *end)
908 if (first_abbrev != NULL)
913 unsigned int bytes_read;
916 unsigned long attribute;
919 entry = read_uleb128 (start, & bytes_read, end);
922 /* A single zero is supposed to end the section according
923 to the standard. If there's more, then signal that to
930 tag = read_uleb128 (start, & bytes_read, end);
937 add_abbrev (entry, tag, children);
942 /* Initialize it due to a false compiler warning. */
943 bfd_signed_vma implicit_const = -1;
945 attribute = read_uleb128 (start, & bytes_read, end);
950 form = read_uleb128 (start, & bytes_read, end);
955 if (form == DW_FORM_implicit_const)
957 implicit_const = read_sleb128 (start, & bytes_read, end);
963 add_abbrev_attr (attribute, form, implicit_const);
965 while (attribute != 0);
968 /* Report the missing single zero which ends the section. */
969 error (_(".debug_abbrev section not zero terminated\n"));
975 get_TAG_name (unsigned long tag)
977 const char *name = get_DW_TAG_name ((unsigned int) tag);
981 static char buffer[100];
983 if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
984 snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
986 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
994 get_FORM_name (unsigned long form)
999 return "DW_FORM value: 0";
1001 name = get_DW_FORM_name (form);
1004 static char buffer[100];
1006 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
1014 get_IDX_name (unsigned long idx)
1016 const char *name = get_DW_IDX_name ((unsigned int) idx);
1020 static char buffer[100];
1022 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
1029 static unsigned char *
1030 display_block (unsigned char *data,
1032 const unsigned char * const end, char delimiter)
1036 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
1038 return (unsigned char *) end;
1040 maxlen = (dwarf_vma) (end - data);
1041 length = length > maxlen ? maxlen : length;
1044 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1050 decode_location_expression (unsigned char * data,
1051 unsigned int pointer_size,
1052 unsigned int offset_size,
1055 dwarf_vma cu_offset,
1056 struct dwarf_section * section)
1059 unsigned int bytes_read;
1061 dwarf_signed_vma svalue;
1062 unsigned char *end = data + length;
1063 int need_frame_base = 0;
1072 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1073 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1076 printf ("DW_OP_deref");
1079 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1080 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1083 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1084 printf ("DW_OP_const1s: %ld", (long) svalue);
1087 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1088 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1091 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1092 printf ("DW_OP_const2s: %ld", (long) svalue);
1095 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1096 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1099 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1100 printf ("DW_OP_const4s: %ld", (long) svalue);
1103 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1104 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1105 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1106 printf ("%lu", (unsigned long) uvalue);
1109 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1110 printf ("DW_OP_const8s: %ld ", (long) svalue);
1111 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1112 printf ("%ld", (long) svalue);
1115 printf ("DW_OP_constu: %s",
1116 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1120 printf ("DW_OP_consts: %s",
1121 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1125 printf ("DW_OP_dup");
1128 printf ("DW_OP_drop");
1131 printf ("DW_OP_over");
1134 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1135 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1138 printf ("DW_OP_swap");
1141 printf ("DW_OP_rot");
1144 printf ("DW_OP_xderef");
1147 printf ("DW_OP_abs");
1150 printf ("DW_OP_and");
1153 printf ("DW_OP_div");
1156 printf ("DW_OP_minus");
1159 printf ("DW_OP_mod");
1162 printf ("DW_OP_mul");
1165 printf ("DW_OP_neg");
1168 printf ("DW_OP_not");
1171 printf ("DW_OP_or");
1174 printf ("DW_OP_plus");
1176 case DW_OP_plus_uconst:
1177 printf ("DW_OP_plus_uconst: %s",
1178 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1182 printf ("DW_OP_shl");
1185 printf ("DW_OP_shr");
1188 printf ("DW_OP_shra");
1191 printf ("DW_OP_xor");
1194 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1195 printf ("DW_OP_bra: %ld", (long) svalue);
1198 printf ("DW_OP_eq");
1201 printf ("DW_OP_ge");
1204 printf ("DW_OP_gt");
1207 printf ("DW_OP_le");
1210 printf ("DW_OP_lt");
1213 printf ("DW_OP_ne");
1216 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1217 printf ("DW_OP_skip: %ld", (long) svalue);
1252 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1287 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1288 regname (op - DW_OP_reg0, 1));
1323 printf ("DW_OP_breg%d (%s): %s",
1325 regname (op - DW_OP_breg0, 1),
1326 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1331 uvalue = read_uleb128 (data, &bytes_read, end);
1333 printf ("DW_OP_regx: %s (%s)",
1334 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1337 need_frame_base = 1;
1338 printf ("DW_OP_fbreg: %s",
1339 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1343 uvalue = read_uleb128 (data, &bytes_read, end);
1345 printf ("DW_OP_bregx: %s (%s) %s",
1346 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1347 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1351 printf ("DW_OP_piece: %s",
1352 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1355 case DW_OP_deref_size:
1356 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1357 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1359 case DW_OP_xderef_size:
1360 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1361 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1364 printf ("DW_OP_nop");
1367 /* DWARF 3 extensions. */
1368 case DW_OP_push_object_address:
1369 printf ("DW_OP_push_object_address");
1372 /* XXX: Strictly speaking for 64-bit DWARF3 files
1373 this ought to be an 8-byte wide computation. */
1374 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1375 printf ("DW_OP_call2: <0x%s>",
1376 dwarf_vmatoa ("x", svalue + cu_offset));
1379 /* XXX: Strictly speaking for 64-bit DWARF3 files
1380 this ought to be an 8-byte wide computation. */
1381 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1382 printf ("DW_OP_call4: <0x%s>",
1383 dwarf_vmatoa ("x", svalue + cu_offset));
1385 case DW_OP_call_ref:
1386 /* XXX: Strictly speaking for 64-bit DWARF3 files
1387 this ought to be an 8-byte wide computation. */
1388 if (dwarf_version == -1)
1390 printf (_("(DW_OP_call_ref in frame info)"));
1391 /* No way to tell where the next op is, so just bail. */
1392 return need_frame_base;
1394 if (dwarf_version == 2)
1396 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1400 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1402 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1404 case DW_OP_form_tls_address:
1405 printf ("DW_OP_form_tls_address");
1407 case DW_OP_call_frame_cfa:
1408 printf ("DW_OP_call_frame_cfa");
1410 case DW_OP_bit_piece:
1411 printf ("DW_OP_bit_piece: ");
1412 printf (_("size: %s "),
1413 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1415 printf (_("offset: %s "),
1416 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1420 /* DWARF 4 extensions. */
1421 case DW_OP_stack_value:
1422 printf ("DW_OP_stack_value");
1425 case DW_OP_implicit_value:
1426 printf ("DW_OP_implicit_value");
1427 uvalue = read_uleb128 (data, &bytes_read, end);
1429 data = display_block (data, uvalue, end, ' ');
1432 /* GNU extensions. */
1433 case DW_OP_GNU_push_tls_address:
1434 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1436 case DW_OP_GNU_uninit:
1437 printf ("DW_OP_GNU_uninit");
1438 /* FIXME: Is there data associated with this OP ? */
1440 case DW_OP_GNU_encoded_addr:
1447 addr = get_encoded_value (&data, encoding, section, end);
1449 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1450 print_dwarf_vma (addr, pointer_size);
1453 case DW_OP_implicit_pointer:
1454 case DW_OP_GNU_implicit_pointer:
1455 /* XXX: Strictly speaking for 64-bit DWARF3 files
1456 this ought to be an 8-byte wide computation. */
1457 if (dwarf_version == -1)
1459 printf (_("(%s in frame info)"),
1460 (op == DW_OP_implicit_pointer
1461 ? "DW_OP_implicit_pointer"
1462 : "DW_OP_GNU_implicit_pointer"));
1463 /* No way to tell where the next op is, so just bail. */
1464 return need_frame_base;
1466 if (dwarf_version == 2)
1468 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1472 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1474 printf ("%s: <0x%s> %s",
1475 (op == DW_OP_implicit_pointer
1476 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1477 dwarf_vmatoa ("x", uvalue),
1478 dwarf_vmatoa ("d", read_sleb128 (data,
1479 &bytes_read, end)));
1482 case DW_OP_entry_value:
1483 case DW_OP_GNU_entry_value:
1484 uvalue = read_uleb128 (data, &bytes_read, end);
1486 /* PR 17531: file: 0cc9cd00. */
1487 if (uvalue > (dwarf_vma) (end - data))
1488 uvalue = end - data;
1489 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1490 : "DW_OP_GNU_entry_value"));
1491 if (decode_location_expression (data, pointer_size, offset_size,
1492 dwarf_version, uvalue,
1493 cu_offset, section))
1494 need_frame_base = 1;
1500 case DW_OP_const_type:
1501 case DW_OP_GNU_const_type:
1502 uvalue = read_uleb128 (data, &bytes_read, end);
1504 printf ("%s: <0x%s> ",
1505 (op == DW_OP_const_type ? "DW_OP_const_type"
1506 : "DW_OP_GNU_const_type"),
1507 dwarf_vmatoa ("x", cu_offset + uvalue));
1508 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1509 data = display_block (data, uvalue, end, ' ');
1511 case DW_OP_regval_type:
1512 case DW_OP_GNU_regval_type:
1513 uvalue = read_uleb128 (data, &bytes_read, end);
1515 printf ("%s: %s (%s)",
1516 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1517 : "DW_OP_GNU_regval_type"),
1518 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1519 uvalue = read_uleb128 (data, &bytes_read, end);
1521 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1523 case DW_OP_deref_type:
1524 case DW_OP_GNU_deref_type:
1525 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1527 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1528 : "DW_OP_GNU_deref_type"),
1530 uvalue = read_uleb128 (data, &bytes_read, end);
1532 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1535 case DW_OP_GNU_convert:
1536 uvalue = read_uleb128 (data, &bytes_read, end);
1538 printf ("%s <0x%s>",
1539 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1540 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1542 case DW_OP_reinterpret:
1543 case DW_OP_GNU_reinterpret:
1544 uvalue = read_uleb128 (data, &bytes_read, end);
1546 printf ("%s <0x%s>",
1547 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1548 : "DW_OP_GNU_reinterpret"),
1549 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1551 case DW_OP_GNU_parameter_ref:
1552 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1553 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1554 dwarf_vmatoa ("x", cu_offset + uvalue));
1556 case DW_OP_GNU_addr_index:
1557 uvalue = read_uleb128 (data, &bytes_read, end);
1559 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1561 case DW_OP_GNU_const_index:
1562 uvalue = read_uleb128 (data, &bytes_read, end);
1564 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1567 /* HP extensions. */
1568 case DW_OP_HP_is_value:
1569 printf ("DW_OP_HP_is_value");
1570 /* FIXME: Is there data associated with this OP ? */
1572 case DW_OP_HP_fltconst4:
1573 printf ("DW_OP_HP_fltconst4");
1574 /* FIXME: Is there data associated with this OP ? */
1576 case DW_OP_HP_fltconst8:
1577 printf ("DW_OP_HP_fltconst8");
1578 /* FIXME: Is there data associated with this OP ? */
1580 case DW_OP_HP_mod_range:
1581 printf ("DW_OP_HP_mod_range");
1582 /* FIXME: Is there data associated with this OP ? */
1584 case DW_OP_HP_unmod_range:
1585 printf ("DW_OP_HP_unmod_range");
1586 /* FIXME: Is there data associated with this OP ? */
1589 printf ("DW_OP_HP_tls");
1590 /* FIXME: Is there data associated with this OP ? */
1593 /* PGI (STMicroelectronics) extensions. */
1594 case DW_OP_PGI_omp_thread_num:
1595 /* Pushes the thread number for the current thread as it would be
1596 returned by the standard OpenMP library function:
1597 omp_get_thread_num(). The "current thread" is the thread for
1598 which the expression is being evaluated. */
1599 printf ("DW_OP_PGI_omp_thread_num");
1603 if (op >= DW_OP_lo_user
1604 && op <= DW_OP_hi_user)
1605 printf (_("(User defined location op 0x%x)"), op);
1607 printf (_("(Unknown location op 0x%x)"), op);
1608 /* No way to tell where the next op is, so just bail. */
1609 return need_frame_base;
1612 /* Separate the ops. */
1617 return need_frame_base;
1620 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1621 This is used for DWARF package files. */
1623 static struct cu_tu_set *
1624 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1626 struct cu_tu_set *p;
1628 unsigned int dw_sect;
1634 dw_sect = DW_SECT_TYPES;
1640 dw_sect = DW_SECT_INFO;
1644 if (p->section_offsets [dw_sect] == cu_offset)
1652 /* Add INC to HIGH_BITS:LOW_BITS. */
1654 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1656 dwarf_vma tmp = * low_bits;
1660 /* FIXME: There is probably a better way of handling this:
1662 We need to cope with dwarf_vma being a 32-bit or 64-bit
1663 type. Plus regardless of its size LOW_BITS is meant to
1664 only hold 32-bits, so if there is overflow or wrap around
1665 we must propagate into HIGH_BITS. */
1666 if (tmp < * low_bits)
1670 else if (sizeof (tmp) > 8
1681 fetch_alt_indirect_string (dwarf_vma offset)
1683 struct dwarf_section * section;
1686 if (! do_follow_links)
1689 if (separate_debug_file == NULL)
1690 return _("<following link not possible>");
1692 if (! load_debug_section (separate_debug_str, separate_debug_file))
1693 return _("<could not load separate string section>");
1695 section = &debug_displays [separate_debug_str].section;
1696 if (section->start == NULL)
1697 return _("<no .debug_str section>");
1699 if (offset >= section->size)
1701 warn (_("DW_FORM_GNU_strp_alt offset too big: %s\n"), dwarf_vmatoa ("x", offset));
1702 return _("<offset is too big>");
1705 ret = (const char *) (section->start + offset);
1706 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1707 NUL byte. Since our caller is expecting to receive a well formed C
1708 string we test for the lack of a terminating byte here. */
1709 if (strnlen ((const char *) ret, section->size - offset)
1710 == section->size - offset)
1711 return _("<no NUL byte at end of .debug_str section>");
1716 static unsigned char *
1717 read_and_display_attr_value (unsigned long attribute,
1719 dwarf_signed_vma implicit_const,
1720 unsigned char * data,
1721 unsigned char * end,
1722 dwarf_vma cu_offset,
1723 dwarf_vma pointer_size,
1724 dwarf_vma offset_size,
1726 debug_info * debug_info_p,
1728 struct dwarf_section * section,
1729 struct cu_tu_set * this_set,
1732 dwarf_vma uvalue = 0;
1733 unsigned char *block_start = NULL;
1734 unsigned char * orig_data = data;
1735 unsigned int bytes_read;
1737 if (data > end || (data == end && form != DW_FORM_flag_present))
1739 warn (_("Corrupt attribute\n"));
1748 case DW_FORM_ref_addr:
1749 if (dwarf_version == 2)
1750 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1751 else if (dwarf_version == 3 || dwarf_version == 4)
1752 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1754 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1759 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1763 case DW_FORM_line_strp:
1764 case DW_FORM_sec_offset:
1765 case DW_FORM_GNU_ref_alt:
1766 case DW_FORM_GNU_strp_alt:
1767 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1770 case DW_FORM_flag_present:
1777 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1782 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1787 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1791 uvalue = read_sleb128 (data, & bytes_read, end);
1795 case DW_FORM_GNU_str_index:
1796 uvalue = read_uleb128 (data, & bytes_read, end);
1800 case DW_FORM_ref_udata:
1802 uvalue = read_uleb128 (data, & bytes_read, end);
1806 case DW_FORM_indirect:
1807 form = read_uleb128 (data, & bytes_read, end);
1810 printf ("%c%s", delimiter, get_FORM_name (form));
1811 if (form == DW_FORM_implicit_const)
1813 implicit_const = read_sleb128 (data, & bytes_read, end);
1816 return read_and_display_attr_value (attribute, form, implicit_const, data,
1817 end, cu_offset, pointer_size,
1818 offset_size, dwarf_version,
1819 debug_info_p, do_loc,
1820 section, this_set, delimiter);
1821 case DW_FORM_GNU_addr_index:
1822 uvalue = read_uleb128 (data, & bytes_read, end);
1829 case DW_FORM_ref_addr:
1831 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1834 case DW_FORM_GNU_ref_alt:
1836 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1837 /* FIXME: Follow the reference... */
1843 case DW_FORM_ref_udata:
1845 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1850 case DW_FORM_sec_offset:
1852 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1855 case DW_FORM_flag_present:
1862 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1865 case DW_FORM_implicit_const:
1867 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1874 dwarf_vma high_bits;
1878 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1880 if (form == DW_FORM_ref8)
1881 add64 (& high_bits, & utmp, cu_offset);
1882 printf ("%c0x%s", delimiter,
1883 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1886 if ((do_loc || do_debug_loc || do_debug_ranges)
1887 && num_debug_info_entries == 0)
1889 if (sizeof (uvalue) == 8)
1890 SAFE_BYTE_GET (uvalue, data, 8, end);
1892 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1898 case DW_FORM_data16:
1901 dwarf_vma left_high_bits, left_low_bits;
1902 dwarf_vma right_high_bits, right_low_bits;
1904 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1905 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1906 if (byte_get == byte_get_little_endian)
1909 left_high_bits ^= right_high_bits;
1910 right_high_bits ^= left_high_bits;
1911 left_high_bits ^= right_high_bits;
1912 left_low_bits ^= right_low_bits;
1913 right_low_bits ^= left_low_bits;
1914 left_low_bits ^= right_low_bits;
1916 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1917 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1918 left_high_bits, left_low_bits, right_high_bits,
1924 case DW_FORM_string:
1926 printf ("%c%.*s", delimiter, (int) (end - data), data);
1927 data += strnlen ((char *) data, end - data) + 1;
1931 case DW_FORM_exprloc:
1932 uvalue = read_uleb128 (data, & bytes_read, end);
1933 block_start = data + bytes_read;
1934 if (block_start >= end)
1936 warn (_("Block ends prematurely\n"));
1940 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1941 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1942 block_start + uvalue here. */
1943 data = block_start + uvalue;
1944 /* PR 17512: file: 008-103549-0.001:0.1. */
1945 if (block_start + uvalue > end || data < block_start)
1947 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1948 uvalue = end - block_start;
1951 data = block_start + uvalue;
1953 data = display_block (block_start, uvalue, end, delimiter);
1956 case DW_FORM_block1:
1957 SAFE_BYTE_GET (uvalue, data, 1, end);
1958 block_start = data + 1;
1959 if (block_start >= end)
1961 warn (_("Block ends prematurely\n"));
1965 data = block_start + uvalue;
1966 if (block_start + uvalue > end || data < block_start)
1968 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1969 uvalue = end - block_start;
1972 data = block_start + uvalue;
1974 data = display_block (block_start, uvalue, end, delimiter);
1977 case DW_FORM_block2:
1978 SAFE_BYTE_GET (uvalue, data, 2, end);
1979 block_start = data + 2;
1980 if (block_start >= end)
1982 warn (_("Block ends prematurely\n"));
1986 data = block_start + uvalue;
1987 if (block_start + uvalue > end || data < block_start)
1989 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1990 uvalue = end - block_start;
1993 data = block_start + uvalue;
1995 data = display_block (block_start, uvalue, end, delimiter);
1998 case DW_FORM_block4:
1999 SAFE_BYTE_GET (uvalue, data, 4, end);
2000 block_start = data + 4;
2001 /* PR 17512: file: 3371-3907-0.004. */
2002 if (block_start >= end)
2004 warn (_("Block ends prematurely\n"));
2008 data = block_start + uvalue;
2009 if (block_start + uvalue > end
2010 /* PR 17531: file: 5b5f0592. */
2011 || data < block_start)
2013 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
2014 uvalue = end - block_start;
2017 data = block_start + uvalue;
2019 data = display_block (block_start, uvalue, end, delimiter);
2024 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
2025 dwarf_vmatoa ("x", uvalue),
2026 fetch_indirect_string (uvalue));
2029 case DW_FORM_line_strp:
2031 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
2032 dwarf_vmatoa ("x", uvalue),
2033 fetch_indirect_line_string (uvalue));
2036 case DW_FORM_GNU_str_index:
2039 const char *suffix = strrchr (section->name, '.');
2040 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
2042 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
2043 dwarf_vmatoa ("x", uvalue),
2044 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
2048 case DW_FORM_GNU_strp_alt:
2051 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
2052 dwarf_vmatoa ("x", uvalue),
2053 fetch_alt_indirect_string (uvalue));
2057 case DW_FORM_indirect:
2058 /* Handled above. */
2061 case DW_FORM_ref_sig8:
2064 dwarf_vma high_bits;
2067 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
2068 printf ("%csignature: 0x%s", delimiter,
2069 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2074 case DW_FORM_GNU_addr_index:
2076 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
2077 dwarf_vmatoa ("x", uvalue),
2078 fetch_indexed_value (uvalue * pointer_size, pointer_size));
2082 warn (_("Unrecognized form: %lu\n"), form);
2086 if ((do_loc || do_debug_loc || do_debug_ranges)
2087 && num_debug_info_entries == 0
2088 && debug_info_p != NULL)
2092 case DW_AT_frame_base:
2093 have_frame_base = 1;
2095 case DW_AT_location:
2096 case DW_AT_GNU_locviews:
2097 case DW_AT_string_length:
2098 case DW_AT_return_addr:
2099 case DW_AT_data_member_location:
2100 case DW_AT_vtable_elem_location:
2102 case DW_AT_static_link:
2103 case DW_AT_use_location:
2104 case DW_AT_call_value:
2105 case DW_AT_GNU_call_site_value:
2106 case DW_AT_call_data_value:
2107 case DW_AT_GNU_call_site_data_value:
2108 case DW_AT_call_target:
2109 case DW_AT_GNU_call_site_target:
2110 case DW_AT_call_target_clobbered:
2111 case DW_AT_GNU_call_site_target_clobbered:
2112 if ((dwarf_version < 4
2113 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2114 || form == DW_FORM_sec_offset)
2116 /* Process location list. */
2117 unsigned int lmax = debug_info_p->max_loc_offsets;
2118 unsigned int num = debug_info_p->num_loc_offsets;
2120 if (lmax == 0 || num >= lmax)
2123 debug_info_p->loc_offsets = (dwarf_vma *)
2124 xcrealloc (debug_info_p->loc_offsets,
2125 lmax, sizeof (*debug_info_p->loc_offsets));
2126 debug_info_p->loc_views = (dwarf_vma *)
2127 xcrealloc (debug_info_p->loc_views,
2128 lmax, sizeof (*debug_info_p->loc_views));
2129 debug_info_p->have_frame_base = (int *)
2130 xcrealloc (debug_info_p->have_frame_base,
2131 lmax, sizeof (*debug_info_p->have_frame_base));
2132 debug_info_p->max_loc_offsets = lmax;
2134 if (this_set != NULL)
2135 uvalue += this_set->section_offsets [DW_SECT_LOC];
2136 debug_info_p->have_frame_base [num] = have_frame_base;
2137 if (attribute != DW_AT_GNU_locviews)
2139 debug_info_p->loc_offsets [num] = uvalue;
2140 debug_info_p->num_loc_offsets++;
2141 assert (debug_info_p->num_loc_offsets
2142 - debug_info_p->num_loc_views <= 1);
2146 assert (debug_info_p->num_loc_views <= num);
2147 num = debug_info_p->num_loc_views;
2148 debug_info_p->loc_views [num] = uvalue;
2149 debug_info_p->num_loc_views++;
2150 assert (debug_info_p->num_loc_views
2151 - debug_info_p->num_loc_offsets <= 1);
2157 if (need_base_address)
2158 debug_info_p->base_address = uvalue;
2161 case DW_AT_GNU_addr_base:
2162 debug_info_p->addr_base = uvalue;
2165 case DW_AT_GNU_ranges_base:
2166 debug_info_p->ranges_base = uvalue;
2170 if ((dwarf_version < 4
2171 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2172 || form == DW_FORM_sec_offset)
2174 /* Process range list. */
2175 unsigned int lmax = debug_info_p->max_range_lists;
2176 unsigned int num = debug_info_p->num_range_lists;
2178 if (lmax == 0 || num >= lmax)
2181 debug_info_p->range_lists = (dwarf_vma *)
2182 xcrealloc (debug_info_p->range_lists,
2183 lmax, sizeof (*debug_info_p->range_lists));
2184 debug_info_p->max_range_lists = lmax;
2186 debug_info_p->range_lists [num] = uvalue;
2187 debug_info_p->num_range_lists++;
2196 if (do_loc || attribute == 0)
2199 /* For some attributes we can display further information. */
2206 case DW_INL_not_inlined:
2207 printf (_("(not inlined)"));
2209 case DW_INL_inlined:
2210 printf (_("(inlined)"));
2212 case DW_INL_declared_not_inlined:
2213 printf (_("(declared as inline but ignored)"));
2215 case DW_INL_declared_inlined:
2216 printf (_("(declared as inline and inlined)"));
2219 printf (_(" (Unknown inline attribute value: %s)"),
2220 dwarf_vmatoa ("x", uvalue));
2225 case DW_AT_language:
2229 /* Ordered by the numeric value of these constants. */
2230 case DW_LANG_C89: printf ("(ANSI C)"); break;
2231 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2232 case DW_LANG_Ada83: printf ("(Ada)"); break;
2233 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2234 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2235 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2236 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2237 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2238 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2239 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2240 /* DWARF 2.1 values. */
2241 case DW_LANG_Java: printf ("(Java)"); break;
2242 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2243 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2244 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2245 /* DWARF 3 values. */
2246 case DW_LANG_PLI: printf ("(PLI)"); break;
2247 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2248 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2249 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2250 case DW_LANG_D: printf ("(D)"); break;
2251 /* DWARF 4 values. */
2252 case DW_LANG_Python: printf ("(Python)"); break;
2253 /* DWARF 5 values. */
2254 case DW_LANG_Go: printf ("(Go)"); break;
2255 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2256 case DW_LANG_C11: printf ("(C11)"); break;
2257 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2258 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2259 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2260 /* MIPS extension. */
2261 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2262 /* UPC extension. */
2263 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2265 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2266 printf (_("(implementation defined: %s)"),
2267 dwarf_vmatoa ("x", uvalue));
2269 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2274 case DW_AT_encoding:
2278 case DW_ATE_void: printf ("(void)"); break;
2279 case DW_ATE_address: printf ("(machine address)"); break;
2280 case DW_ATE_boolean: printf ("(boolean)"); break;
2281 case DW_ATE_complex_float: printf ("(complex float)"); break;
2282 case DW_ATE_float: printf ("(float)"); break;
2283 case DW_ATE_signed: printf ("(signed)"); break;
2284 case DW_ATE_signed_char: printf ("(signed char)"); break;
2285 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2286 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2287 /* DWARF 2.1 values: */
2288 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2289 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2290 /* DWARF 3 values: */
2291 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2292 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2293 case DW_ATE_edited: printf ("(edited)"); break;
2294 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2295 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2296 /* DWARF 4 values: */
2297 case DW_ATE_UTF: printf ("(unicode string)"); break;
2298 /* DWARF 5 values: */
2299 case DW_ATE_UCS: printf ("(UCS)"); break;
2300 case DW_ATE_ASCII: printf ("(ASCII)"); break;
2302 /* HP extensions: */
2303 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2304 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2305 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2306 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2307 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2308 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2309 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2312 if (uvalue >= DW_ATE_lo_user
2313 && uvalue <= DW_ATE_hi_user)
2314 printf (_("(user defined type)"));
2316 printf (_("(unknown type)"));
2321 case DW_AT_accessibility:
2325 case DW_ACCESS_public: printf ("(public)"); break;
2326 case DW_ACCESS_protected: printf ("(protected)"); break;
2327 case DW_ACCESS_private: printf ("(private)"); break;
2329 printf (_("(unknown accessibility)"));
2334 case DW_AT_visibility:
2338 case DW_VIS_local: printf ("(local)"); break;
2339 case DW_VIS_exported: printf ("(exported)"); break;
2340 case DW_VIS_qualified: printf ("(qualified)"); break;
2341 default: printf (_("(unknown visibility)")); break;
2345 case DW_AT_endianity:
2349 case DW_END_default: printf ("(default)"); break;
2350 case DW_END_big: printf ("(big)"); break;
2351 case DW_END_little: printf ("(little)"); break;
2353 if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
2354 printf (_("(user specified)"));
2356 printf (_("(unknown endianity)"));
2361 case DW_AT_virtuality:
2365 case DW_VIRTUALITY_none: printf ("(none)"); break;
2366 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2367 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2368 default: printf (_("(unknown virtuality)")); break;
2372 case DW_AT_identifier_case:
2376 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2377 case DW_ID_up_case: printf ("(up_case)"); break;
2378 case DW_ID_down_case: printf ("(down_case)"); break;
2379 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2380 default: printf (_("(unknown case)")); break;
2384 case DW_AT_calling_convention:
2388 case DW_CC_normal: printf ("(normal)"); break;
2389 case DW_CC_program: printf ("(program)"); break;
2390 case DW_CC_nocall: printf ("(nocall)"); break;
2391 case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
2392 case DW_CC_pass_by_value: printf ("(pass by value)"); break;
2393 case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
2394 case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break;
2396 if (uvalue >= DW_CC_lo_user
2397 && uvalue <= DW_CC_hi_user)
2398 printf (_("(user defined)"));
2400 printf (_("(unknown convention)"));
2404 case DW_AT_ordering:
2409 case -1: printf (_("(undefined)")); break;
2410 case 0: printf ("(row major)"); break;
2411 case 1: printf ("(column major)"); break;
2415 case DW_AT_decimal_sign:
2419 case DW_DS_unsigned: printf (_("(unsigned)")); break;
2420 case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
2421 case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
2422 case DW_DS_leading_separate: printf (_("(leading separate)")); break;
2423 case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
2424 default: printf (_("(unrecognised)")); break;
2428 case DW_AT_defaulted:
2432 case DW_DEFAULTED_no: printf (_("(no)")); break;
2433 case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
2434 case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
2435 default: printf (_("(unrecognised)")); break;
2439 case DW_AT_discr_list:
2443 case DW_DSC_label: printf (_("(label)")); break;
2444 case DW_DSC_range: printf (_("(range)")); break;
2445 default: printf (_("(unrecognised)")); break;
2449 case DW_AT_frame_base:
2450 have_frame_base = 1;
2452 case DW_AT_location:
2453 case DW_AT_string_length:
2454 case DW_AT_return_addr:
2455 case DW_AT_data_member_location:
2456 case DW_AT_vtable_elem_location:
2458 case DW_AT_static_link:
2459 case DW_AT_use_location:
2460 case DW_AT_call_value:
2461 case DW_AT_GNU_call_site_value:
2462 case DW_AT_call_data_value:
2463 case DW_AT_GNU_call_site_data_value:
2464 case DW_AT_call_target:
2465 case DW_AT_GNU_call_site_target:
2466 case DW_AT_call_target_clobbered:
2467 case DW_AT_GNU_call_site_target_clobbered:
2468 if ((dwarf_version < 4
2469 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2470 || form == DW_FORM_sec_offset)
2471 printf (_(" (location list)"));
2473 case DW_AT_allocated:
2474 case DW_AT_associated:
2475 case DW_AT_data_location:
2477 case DW_AT_upper_bound:
2478 case DW_AT_lower_bound:
2481 int need_frame_base;
2484 need_frame_base = decode_location_expression (block_start,
2489 cu_offset, section);
2491 if (need_frame_base && !have_frame_base)
2492 printf (_(" [without DW_AT_frame_base]"));
2498 if (form == DW_FORM_ref_sig8
2499 || form == DW_FORM_GNU_ref_alt)
2502 if (form == DW_FORM_ref1
2503 || form == DW_FORM_ref2
2504 || form == DW_FORM_ref4
2505 || form == DW_FORM_ref_udata)
2506 uvalue += cu_offset;
2508 if (uvalue >= section->size)
2509 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2510 dwarf_vmatoa ("x", uvalue),
2511 (unsigned long) (orig_data - section->start));
2514 unsigned long abbrev_number;
2515 abbrev_entry * entry;
2517 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2519 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2520 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2521 use different abbrev table, and we don't track .debug_info chunks
2523 if (form != DW_FORM_ref_addr)
2525 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2526 if (entry->entry == abbrev_number)
2529 printf (" (%s)", get_TAG_name (entry->tag));
2544 get_AT_name (unsigned long attribute)
2549 return "DW_AT value: 0";
2551 /* One value is shared by the MIPS and HP extensions: */
2552 if (attribute == DW_AT_MIPS_fde)
2553 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2555 name = get_DW_AT_name (attribute);
2559 static char buffer[100];
2561 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2569 static unsigned char *
2570 read_and_display_attr (unsigned long attribute,
2572 dwarf_signed_vma implicit_const,
2573 unsigned char * data,
2574 unsigned char * end,
2575 dwarf_vma cu_offset,
2576 dwarf_vma pointer_size,
2577 dwarf_vma offset_size,
2579 debug_info * debug_info_p,
2581 struct dwarf_section * section,
2582 struct cu_tu_set * this_set)
2585 printf (" %-18s:", get_AT_name (attribute));
2586 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2587 cu_offset, pointer_size, offset_size,
2588 dwarf_version, debug_info_p,
2589 do_loc, section, this_set, ' ');
2595 /* Like load_debug_section, but if the ordinary call fails, and we are
2596 following debug links, and we have been able to load a separate debug
2597 info file, then attempt to load the requested section from the separate
2601 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
2604 if (load_debug_section (sec_enum, data))
2606 if (data == separate_debug_file)
2607 debug_displays[sec_enum].section.filename = separate_debug_filename;
2609 /* FIXME: We should check to see if there is a separate debug info file
2610 that also contains this section, and if so, issue a warning. */
2614 if (do_follow_links && separate_debug_file != NULL)
2615 if (load_debug_section (sec_enum, separate_debug_file))
2617 debug_displays[sec_enum].section.filename = separate_debug_filename;
2625 introduce (struct dwarf_section * section, bfd_boolean raw)
2629 if (do_follow_links && section->filename)
2630 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
2631 section->name, section->filename);
2633 printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
2637 if (do_follow_links && section->filename)
2638 printf (_("Contents of the %s section (loaded from %s):\n\n"),
2639 section->name, section->filename);
2641 printf (_("Contents of the %s section:\n\n"), section->name);
2645 /* Process the contents of a .debug_info section. If do_loc is non-zero
2646 then we are scanning for location lists and we do not want to display
2647 anything to the user. If do_types is non-zero, we are processing
2648 a .debug_types section instead of a .debug_info section. */
2651 process_debug_info (struct dwarf_section *section,
2653 enum dwarf_section_display_enum abbrev_sec,
2657 unsigned char *start = section->start;
2658 unsigned char *end = start + section->size;
2659 unsigned char *section_begin;
2661 unsigned int num_units = 0;
2663 if ((do_loc || do_debug_loc || do_debug_ranges)
2664 && num_debug_info_entries == 0
2669 /* First scan the section to get the number of comp units. */
2670 for (section_begin = start, num_units = 0; section_begin < end;
2673 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2674 will be the length. For a 64-bit DWARF section, it'll be
2675 the escape code 0xffffffff followed by an 8 byte length. */
2676 SAFE_BYTE_GET (length, section_begin, 4, end);
2678 if (length == 0xffffffff)
2680 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2681 section_begin += length + 12;
2683 else if (length >= 0xfffffff0 && length < 0xffffffff)
2685 warn (_("Reserved length value (0x%s) found in section %s\n"),
2686 dwarf_vmatoa ("x", length), section->name);
2690 section_begin += length + 4;
2692 /* Negative values are illegal, they may even cause infinite
2693 looping. This can happen if we can't accurately apply
2694 relocations to an object file, or if the file is corrupt. */
2695 if ((signed long) length <= 0 || section_begin < start)
2697 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2698 dwarf_vmatoa ("x", length), section->name);
2705 error (_("No comp units in %s section ?\n"), section->name);
2709 /* Then allocate an array to hold the information. */
2710 debug_information = (debug_info *) cmalloc (num_units,
2711 sizeof (* debug_information));
2712 if (debug_information == NULL)
2714 error (_("Not enough memory for a debug info array of %u entries\n"),
2716 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2719 /* PR 17531: file: 92ca3797.
2720 We cannot rely upon the debug_information array being initialised
2721 before it is used. A corrupt file could easily contain references
2722 to a unit for which information has not been made available. So
2723 we ensure that the array is zeroed here. */
2724 memset (debug_information, 0, num_units * sizeof (*debug_information));
2726 alloc_num_debug_info_entries = num_units;
2731 load_debug_section_with_follow (str, file);
2732 load_debug_section_with_follow (line_str, file);
2733 load_debug_section_with_follow (str_dwo, file);
2734 load_debug_section_with_follow (str_index, file);
2735 load_debug_section_with_follow (str_index_dwo, file);
2736 load_debug_section_with_follow (debug_addr, file);
2739 load_debug_section_with_follow (abbrev_sec, file);
2740 if (debug_displays [abbrev_sec].section.start == NULL)
2742 warn (_("Unable to locate %s section!\n"),
2743 debug_displays [abbrev_sec].section.uncompressed_name);
2747 if (!do_loc && dwarf_start_die == 0)
2748 introduce (section, FALSE);
2750 for (section_begin = start, unit = 0; start < end; unit++)
2752 DWARF2_Internal_CompUnit compunit;
2753 unsigned char *hdrptr;
2754 unsigned char *tags;
2755 int level, last_level, saved_level;
2756 dwarf_vma cu_offset;
2757 unsigned long sec_off;
2758 unsigned int offset_size;
2759 unsigned int initial_length_size;
2760 dwarf_vma signature_high = 0;
2761 dwarf_vma signature_low = 0;
2762 dwarf_vma type_offset = 0;
2763 struct cu_tu_set *this_set;
2764 dwarf_vma abbrev_base;
2769 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2771 if (compunit.cu_length == 0xffffffff)
2773 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2775 initial_length_size = 12;
2780 initial_length_size = 4;
2783 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2785 cu_offset = start - section_begin;
2787 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2789 if (compunit.cu_version < 5)
2791 compunit.cu_unit_type = DW_UT_compile;
2792 /* Initialize it due to a false compiler warning. */
2793 compunit.cu_pointer_size = -1;
2797 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2798 do_types = (compunit.cu_unit_type == DW_UT_type);
2800 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2803 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2805 if (this_set == NULL)
2808 abbrev_size = debug_displays [abbrev_sec].section.size;
2812 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2813 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2816 if (compunit.cu_version < 5)
2817 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2819 /* PR 17512: file: 001-108546-0.001:0.1. */
2820 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2822 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2823 compunit.cu_pointer_size, offset_size);
2824 compunit.cu_pointer_size = offset_size;
2829 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2831 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2834 if (dwarf_start_die > (cu_offset + compunit.cu_length
2835 + initial_length_size))
2837 start = section_begin + cu_offset + compunit.cu_length
2838 + initial_length_size;
2842 if ((do_loc || do_debug_loc || do_debug_ranges)
2843 && num_debug_info_entries == 0
2846 debug_information [unit].cu_offset = cu_offset;
2847 debug_information [unit].pointer_size
2848 = compunit.cu_pointer_size;
2849 debug_information [unit].offset_size = offset_size;
2850 debug_information [unit].dwarf_version = compunit.cu_version;
2851 debug_information [unit].base_address = 0;
2852 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2853 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2854 debug_information [unit].loc_offsets = NULL;
2855 debug_information [unit].have_frame_base = NULL;
2856 debug_information [unit].max_loc_offsets = 0;
2857 debug_information [unit].num_loc_offsets = 0;
2858 debug_information [unit].range_lists = NULL;
2859 debug_information [unit].max_range_lists= 0;
2860 debug_information [unit].num_range_lists = 0;
2863 if (!do_loc && dwarf_start_die == 0)
2865 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2866 dwarf_vmatoa ("x", cu_offset));
2867 printf (_(" Length: 0x%s (%s)\n"),
2868 dwarf_vmatoa ("x", compunit.cu_length),
2869 offset_size == 8 ? "64-bit" : "32-bit");
2870 printf (_(" Version: %d\n"), compunit.cu_version);
2871 printf (_(" Abbrev Offset: 0x%s\n"),
2872 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2873 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2878 printf (_(" Signature: 0x%s\n"),
2879 dwarf_vmatoa64 (signature_high, signature_low,
2880 buf, sizeof (buf)));
2881 printf (_(" Type Offset: 0x%s\n"),
2882 dwarf_vmatoa ("x", type_offset));
2884 if (this_set != NULL)
2886 dwarf_vma *offsets = this_set->section_offsets;
2887 size_t *sizes = this_set->section_sizes;
2889 printf (_(" Section contributions:\n"));
2890 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2891 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2892 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2893 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2894 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2895 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2896 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2897 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2898 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2899 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2900 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2901 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2905 sec_off = cu_offset + initial_length_size;
2906 if (sec_off + compunit.cu_length < sec_off
2907 || sec_off + compunit.cu_length > section->size)
2909 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
2911 (unsigned long) cu_offset,
2912 dwarf_vmatoa ("x", compunit.cu_length));
2918 start += compunit.cu_length + initial_length_size;
2920 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2922 warn (_("CU at offset %s contains corrupt or "
2923 "unsupported version number: %d.\n"),
2924 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2928 if (compunit.cu_unit_type != DW_UT_compile
2929 && compunit.cu_unit_type != DW_UT_type)
2931 warn (_("CU at offset %s contains corrupt or "
2932 "unsupported unit type: %d.\n"),
2933 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2939 /* Process the abbrevs used by this compilation unit. */
2940 if (compunit.cu_abbrev_offset >= abbrev_size)
2941 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2942 (unsigned long) compunit.cu_abbrev_offset,
2943 (unsigned long) abbrev_size);
2944 /* PR 17531: file:4bcd9ce9. */
2945 else if ((abbrev_base + abbrev_size)
2946 > debug_displays [abbrev_sec].section.size)
2947 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2948 (unsigned long) abbrev_base + abbrev_size,
2949 (unsigned long) debug_displays [abbrev_sec].section.size);
2951 process_abbrev_section
2952 (((unsigned char *) debug_displays [abbrev_sec].section.start
2953 + abbrev_base + compunit.cu_abbrev_offset),
2954 ((unsigned char *) debug_displays [abbrev_sec].section.start
2955 + abbrev_base + abbrev_size));
2960 while (tags < start)
2962 unsigned int bytes_read;
2963 unsigned long abbrev_number;
2964 unsigned long die_offset;
2965 abbrev_entry *entry;
2967 int do_printing = 1;
2969 die_offset = tags - section_begin;
2971 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2974 /* A null DIE marks the end of a list of siblings or it may also be
2975 a section padding. */
2976 if (abbrev_number == 0)
2978 /* Check if it can be a section padding for the last CU. */
2979 if (level == 0 && start == end)
2983 for (chk = tags; chk < start; chk++)
2990 if (!do_loc && die_offset >= dwarf_start_die
2991 && (dwarf_cutoff_level == -1
2992 || level < dwarf_cutoff_level))
2993 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2999 static unsigned num_bogus_warns = 0;
3001 if (num_bogus_warns < 3)
3003 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3004 die_offset, section->name);
3006 if (num_bogus_warns == 3)
3007 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3010 if (dwarf_start_die != 0 && level < saved_level)
3017 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
3021 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
3022 saved_level = level;
3023 do_printing = (dwarf_cutoff_level == -1
3024 || level < dwarf_cutoff_level);
3026 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3027 level, die_offset, abbrev_number);
3028 else if (dwarf_cutoff_level == -1
3029 || last_level < dwarf_cutoff_level)
3030 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
3035 /* Scan through the abbreviation list until we reach the
3037 for (entry = first_abbrev;
3038 entry && entry->entry != abbrev_number;
3039 entry = entry->next)
3044 if (!do_loc && do_printing)
3049 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3050 die_offset, abbrev_number);
3054 if (!do_loc && do_printing)
3055 printf (" (%s)\n", get_TAG_name (entry->tag));
3060 need_base_address = 0;
3062 case DW_TAG_compile_unit:
3063 need_base_address = 1;
3065 case DW_TAG_entry_point:
3066 case DW_TAG_subprogram:
3067 need_base_address = 0;
3068 /* Assuming that there is no DW_AT_frame_base. */
3069 have_frame_base = 0;
3073 debug_info *debug_info_p =
3074 (debug_information && unit < alloc_num_debug_info_entries)
3075 ? debug_information + unit : NULL;
3077 assert (!debug_info_p
3078 || (debug_info_p->num_loc_offsets
3079 == debug_info_p->num_loc_views));
3081 for (attr = entry->first_attr;
3082 attr && attr->attribute;
3085 if (! do_loc && do_printing)
3086 /* Show the offset from where the tag was extracted. */
3087 printf (" <%lx>", (unsigned long)(tags - section_begin));
3089 tags = read_and_display_attr (attr->attribute,
3091 attr->implicit_const,
3095 compunit.cu_pointer_size,
3097 compunit.cu_version,
3099 do_loc || ! do_printing,
3104 /* If a locview attribute appears before a location one,
3105 make sure we don't associate it with an earlier
3108 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
3111 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
3112 debug_info_p->num_loc_views++;
3113 assert (debug_info_p->num_loc_views
3114 == debug_info_p->num_loc_offsets);
3121 warn(_("DIE has locviews without loclist\n"));
3122 debug_info_p->num_loc_views--;
3129 if (entry->children)
3134 /* Set num_debug_info_entries here so that it can be used to check if
3135 we need to process .debug_loc and .debug_ranges sections. */
3136 if ((do_loc || do_debug_loc || do_debug_ranges)
3137 && num_debug_info_entries == 0
3140 if (num_units > alloc_num_debug_info_entries)
3141 num_debug_info_entries = alloc_num_debug_info_entries;
3143 num_debug_info_entries = num_units;
3152 /* Locate and scan the .debug_info section in the file and record the pointer
3153 sizes and offsets for the compilation units in it. Usually an executable
3154 will have just one pointer size, but this is not guaranteed, and so we try
3155 not to make any assumptions. Returns zero upon failure, or the number of
3156 compilation units upon success. */
3159 load_debug_info (void * file)
3161 /* If we have already tried and failed to load the .debug_info
3162 section then do not bother to repeat the task. */
3163 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3166 /* If we already have the information there is nothing else to do. */
3167 if (num_debug_info_entries > 0)
3168 return num_debug_info_entries;
3170 /* If this is a DWARF package file, load the CU and TU indexes. */
3171 (void) load_cu_tu_indexes (file);
3173 if (load_debug_section_with_follow (info, file)
3174 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
3175 return num_debug_info_entries;
3177 if (load_debug_section_with_follow (info_dwo, file)
3178 && process_debug_info (&debug_displays [info_dwo].section, file,
3180 return num_debug_info_entries;
3182 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
3186 /* Read a DWARF .debug_line section header starting at DATA.
3187 Upon success returns an updated DATA pointer and the LINFO
3188 structure and the END_OF_SEQUENCE pointer will be filled in.
3189 Otherwise returns NULL. */
3191 static unsigned char *
3192 read_debug_line_header (struct dwarf_section * section,
3193 unsigned char * data,
3194 unsigned char * end,
3195 DWARF2_Internal_LineInfo * linfo,
3196 unsigned char ** end_of_sequence)
3198 unsigned char *hdrptr;
3199 unsigned int initial_length_size;
3200 unsigned char address_size, segment_selector_size;
3202 /* Extract information from the Line Number Program Header.
3203 (section 6.2.4 in the Dwarf3 doc). */
3206 /* Get and check the length of the block. */
3207 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
3209 if (linfo->li_length == 0xffffffff)
3211 /* This section is 64-bit DWARF 3. */
3212 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
3213 linfo->li_offset_size = 8;
3214 initial_length_size = 12;
3218 linfo->li_offset_size = 4;
3219 initial_length_size = 4;
3222 if (linfo->li_length + initial_length_size > section->size)
3224 /* If the length field has a relocation against it, then we should
3225 not complain if it is inaccurate (and probably negative). This
3226 happens in object files when the .debug_line section is actually
3227 comprised of several different .debug_line.* sections, (some of
3228 which may be removed by linker garbage collection), and a relocation
3229 is used to compute the correct length once that is done. */
3230 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
3232 linfo->li_length = (end - data) - initial_length_size;
3236 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3237 (long) linfo->li_length);
3242 /* Get and check the version number. */
3243 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3245 if (linfo->li_version != 2
3246 && linfo->li_version != 3
3247 && linfo->li_version != 4
3248 && linfo->li_version != 5)
3250 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3251 "is currently supported.\n"));
3255 if (linfo->li_version >= 5)
3257 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3259 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3260 if (segment_selector_size != 0)
3262 warn (_("The %s section contains "
3263 "unsupported segment selector size: %d.\n"),
3264 section->name, segment_selector_size);
3269 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3270 linfo->li_offset_size, end);
3271 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3273 if (linfo->li_version >= 4)
3275 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3277 if (linfo->li_max_ops_per_insn == 0)
3279 warn (_("Invalid maximum operations per insn.\n"));
3284 linfo->li_max_ops_per_insn = 1;
3286 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3287 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3288 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3289 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3291 * end_of_sequence = data + linfo->li_length + initial_length_size;
3292 /* PR 17512: file:002-117414-0.004. */
3293 if (* end_of_sequence > end)
3295 warn (_("Line length %s extends beyond end of section\n"),
3296 dwarf_vmatoa ("u", linfo->li_length));
3297 * end_of_sequence = end;
3304 static unsigned char *
3305 display_formatted_table (unsigned char * data,
3306 unsigned char * start,
3307 unsigned char * end,
3308 const DWARF2_Internal_LineInfo * linfo,
3309 struct dwarf_section * section,
3312 unsigned char *format_start, format_count, *format, formati;
3313 dwarf_vma data_count, datai;
3314 unsigned int bytes_read, namepass, last_entry = 0;
3316 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3317 format_start = data;
3318 for (formati = 0; formati < format_count; formati++)
3320 read_uleb128 (data, & bytes_read, end);
3322 read_uleb128 (data, & bytes_read, end);
3326 warn (_("Corrupt %s format table entry\n"), what);
3331 data_count = read_uleb128 (data, & bytes_read, end);
3335 warn (_("Corrupt %s list\n"), what);
3339 if (data_count == 0)
3341 printf (_("\n The %s Table is empty.\n"), what);
3345 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3346 (long)(data - start));
3348 printf (_(" Entry"));
3349 /* Delay displaying name as the last entry for better screen layout. */
3350 for (namepass = 0; namepass < 2; namepass++)
3352 format = format_start;
3353 for (formati = 0; formati < format_count; formati++)
3355 dwarf_vma content_type;
3357 content_type = read_uleb128 (format, & bytes_read, end);
3358 format += bytes_read;
3359 if ((content_type == DW_LNCT_path) == (namepass == 1))
3360 switch (content_type)
3363 printf (_("\tName"));
3365 case DW_LNCT_directory_index:
3366 printf (_("\tDir"));
3368 case DW_LNCT_timestamp:
3369 printf (_("\tTime"));
3372 printf (_("\tSize"));
3375 printf (_("\tMD5"));
3378 printf (_("\t(Unknown format content type %s)"),
3379 dwarf_vmatoa ("u", content_type));
3381 read_uleb128 (format, & bytes_read, end);
3382 format += bytes_read;
3387 for (datai = 0; datai < data_count; datai++)
3389 unsigned char *datapass = data;
3391 printf (" %d", last_entry++);
3392 /* Delay displaying name as the last entry for better screen layout. */
3393 for (namepass = 0; namepass < 2; namepass++)
3395 format = format_start;
3397 for (formati = 0; formati < format_count; formati++)
3399 dwarf_vma content_type, form;
3401 content_type = read_uleb128 (format, & bytes_read, end);
3402 format += bytes_read;
3403 form = read_uleb128 (format, & bytes_read, end);
3404 format += bytes_read;
3405 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3406 linfo->li_offset_size,
3407 linfo->li_version, NULL,
3408 ((content_type == DW_LNCT_path) != (namepass == 1)),
3409 section, NULL, '\t');
3414 warn (_("Corrupt %s entries list\n"), what);
3423 display_debug_lines_raw (struct dwarf_section * section,
3424 unsigned char * data,
3425 unsigned char * end,
3428 unsigned char *start = section->start;
3429 int verbose_view = 0;
3431 introduce (section, TRUE);
3435 static DWARF2_Internal_LineInfo saved_linfo;
3436 DWARF2_Internal_LineInfo linfo;
3437 unsigned char *standard_opcodes;
3438 unsigned char *end_of_sequence;
3441 if (const_strneq (section->name, ".debug_line.")
3442 /* Note: the following does not apply to .debug_line.dwo sections.
3443 These are full debug_line sections. */
3444 && strcmp (section->name, ".debug_line.dwo") != 0)
3446 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3447 section containing just the Line Number Statements. They are
3448 created by the assembler and intended to be used alongside gcc's
3449 -ffunction-sections command line option. When the linker's
3450 garbage collection decides to discard a .text.<foo> section it
3451 can then also discard the line number information in .debug_line.<foo>.
3453 Since the section is a fragment it does not have the details
3454 needed to fill out a LineInfo structure, so instead we use the
3455 details from the last full debug_line section that we processed. */
3456 end_of_sequence = end;
3457 standard_opcodes = NULL;
3458 linfo = saved_linfo;
3459 /* PR 17531: file: 0522b371. */
3460 if (linfo.li_line_range == 0)
3462 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3465 reset_state_machine (linfo.li_default_is_stmt);
3469 unsigned char * hdrptr;
3471 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3472 & end_of_sequence)) == NULL)
3475 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3476 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3477 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3478 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3479 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3480 if (linfo.li_version >= 4)
3481 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3482 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3483 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3484 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3485 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3487 /* PR 17512: file: 1665-6428-0.004. */
3488 if (linfo.li_line_range == 0)
3490 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3491 linfo.li_line_range = 1;
3494 reset_state_machine (linfo.li_default_is_stmt);
3496 /* Display the contents of the Opcodes table. */
3497 standard_opcodes = hdrptr;
3499 /* PR 17512: file: 002-417945-0.004. */
3500 if (standard_opcodes + linfo.li_opcode_base >= end)
3502 warn (_("Line Base extends beyond end of section\n"));
3506 printf (_("\n Opcodes:\n"));
3508 for (i = 1; i < linfo.li_opcode_base; i++)
3509 printf (ngettext (" Opcode %d has %d arg\n",
3510 " Opcode %d has %d args\n",
3511 standard_opcodes[i - 1]),
3512 i, standard_opcodes[i - 1]);
3514 /* Display the contents of the Directory table. */
3515 data = standard_opcodes + linfo.li_opcode_base - 1;
3517 if (linfo.li_version >= 5)
3519 load_debug_section_with_follow (line_str, file);
3521 data = display_formatted_table (data, start, end, &linfo, section,
3523 data = display_formatted_table (data, start, end, &linfo, section,
3529 printf (_("\n The Directory Table is empty.\n"));
3532 unsigned int last_dir_entry = 0;
3534 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3535 (long)(data - start));
3537 while (data < end && *data != 0)
3539 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3541 data += strnlen ((char *) data, end - data) + 1;
3544 /* PR 17512: file: 002-132094-0.004. */
3545 if (data >= end - 1)
3549 /* Skip the NUL at the end of the table. */
3552 /* Display the contents of the File Name table. */
3554 printf (_("\n The File Name Table is empty.\n"));
3557 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3558 (long)(data - start));
3559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3561 while (data < end && *data != 0)
3563 unsigned char *name;
3564 unsigned int bytes_read;
3566 printf (" %d\t", ++state_machine_regs.last_file_entry);
3568 data += strnlen ((char *) data, end - data) + 1;
3571 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3574 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3577 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3579 printf ("%.*s\n", (int)(end - name), name);
3583 warn (_("Corrupt file name table entry\n"));
3589 /* Skip the NUL at the end of the table. */
3594 saved_linfo = linfo;
3597 /* Now display the statements. */
3598 if (data >= end_of_sequence)
3599 printf (_(" No Line Number Statements.\n"));
3602 printf (_(" Line Number Statements:\n"));
3604 while (data < end_of_sequence)
3606 unsigned char op_code;
3607 dwarf_signed_vma adv;
3609 unsigned int bytes_read;
3611 printf (" [0x%08lx]", (long)(data - start));
3615 if (op_code >= linfo.li_opcode_base)
3617 op_code -= linfo.li_opcode_base;
3618 uladv = (op_code / linfo.li_line_range);
3619 if (linfo.li_max_ops_per_insn == 1)
3621 uladv *= linfo.li_min_insn_length;
3622 state_machine_regs.address += uladv;
3624 state_machine_regs.view = 0;
3625 printf (_(" Special opcode %d: "
3626 "advance Address by %s to 0x%s%s"),
3627 op_code, dwarf_vmatoa ("u", uladv),
3628 dwarf_vmatoa ("x", state_machine_regs.address),
3629 verbose_view && uladv
3630 ? _(" (reset view)") : "");
3635 = ((state_machine_regs.op_index + uladv)
3636 / linfo.li_max_ops_per_insn)
3637 * linfo.li_min_insn_length;
3639 state_machine_regs.address += addrdelta;
3640 state_machine_regs.op_index
3641 = (state_machine_regs.op_index + uladv)
3642 % linfo.li_max_ops_per_insn;
3644 state_machine_regs.view = 0;
3645 printf (_(" Special opcode %d: "
3646 "advance Address by %s to 0x%s[%d]%s"),
3647 op_code, dwarf_vmatoa ("u", uladv),
3648 dwarf_vmatoa ("x", state_machine_regs.address),
3649 state_machine_regs.op_index,
3650 verbose_view && addrdelta
3651 ? _(" (reset view)") : "");
3653 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3654 state_machine_regs.line += adv;
3655 printf (_(" and Line by %s to %d"),
3656 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3657 if (verbose_view || state_machine_regs.view)
3658 printf (_(" (view %u)\n"), state_machine_regs.view);
3661 state_machine_regs.view++;
3663 else switch (op_code)
3665 case DW_LNS_extended_op:
3666 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3670 printf (_(" Copy"));
3671 if (verbose_view || state_machine_regs.view)
3672 printf (_(" (view %u)\n"), state_machine_regs.view);
3675 state_machine_regs.view++;
3678 case DW_LNS_advance_pc:
3679 uladv = read_uleb128 (data, & bytes_read, end);
3681 if (linfo.li_max_ops_per_insn == 1)
3683 uladv *= linfo.li_min_insn_length;
3684 state_machine_regs.address += uladv;
3686 state_machine_regs.view = 0;
3687 printf (_(" Advance PC by %s to 0x%s%s\n"),
3688 dwarf_vmatoa ("u", uladv),
3689 dwarf_vmatoa ("x", state_machine_regs.address),
3690 verbose_view && uladv
3691 ? _(" (reset view)") : "");
3696 = ((state_machine_regs.op_index + uladv)
3697 / linfo.li_max_ops_per_insn)
3698 * linfo.li_min_insn_length;
3699 state_machine_regs.address
3701 state_machine_regs.op_index
3702 = (state_machine_regs.op_index + uladv)
3703 % linfo.li_max_ops_per_insn;
3705 state_machine_regs.view = 0;
3706 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3707 dwarf_vmatoa ("u", uladv),
3708 dwarf_vmatoa ("x", state_machine_regs.address),
3709 state_machine_regs.op_index,
3710 verbose_view && addrdelta
3711 ? _(" (reset view)") : "");
3715 case DW_LNS_advance_line:
3716 adv = read_sleb128 (data, & bytes_read, end);
3718 state_machine_regs.line += adv;
3719 printf (_(" Advance Line by %s to %d\n"),
3720 dwarf_vmatoa ("d", adv),
3721 state_machine_regs.line);
3724 case DW_LNS_set_file:
3725 adv = read_uleb128 (data, & bytes_read, end);
3727 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3728 dwarf_vmatoa ("d", adv));
3729 state_machine_regs.file = adv;
3732 case DW_LNS_set_column:
3733 uladv = read_uleb128 (data, & bytes_read, end);
3735 printf (_(" Set column to %s\n"),
3736 dwarf_vmatoa ("u", uladv));
3737 state_machine_regs.column = uladv;
3740 case DW_LNS_negate_stmt:
3741 adv = state_machine_regs.is_stmt;
3743 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3744 state_machine_regs.is_stmt = adv;
3747 case DW_LNS_set_basic_block:
3748 printf (_(" Set basic block\n"));
3749 state_machine_regs.basic_block = 1;
3752 case DW_LNS_const_add_pc:
3753 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3754 if (linfo.li_max_ops_per_insn)
3756 uladv *= linfo.li_min_insn_length;
3757 state_machine_regs.address += uladv;
3759 state_machine_regs.view = 0;
3760 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3761 dwarf_vmatoa ("u", uladv),
3762 dwarf_vmatoa ("x", state_machine_regs.address),
3763 verbose_view && uladv
3764 ? _(" (reset view)") : "");
3769 = ((state_machine_regs.op_index + uladv)
3770 / linfo.li_max_ops_per_insn)
3771 * linfo.li_min_insn_length;
3772 state_machine_regs.address
3774 state_machine_regs.op_index
3775 = (state_machine_regs.op_index + uladv)
3776 % linfo.li_max_ops_per_insn;
3778 state_machine_regs.view = 0;
3779 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3780 dwarf_vmatoa ("u", uladv),
3781 dwarf_vmatoa ("x", state_machine_regs.address),
3782 state_machine_regs.op_index,
3783 verbose_view && addrdelta
3784 ? _(" (reset view)") : "");
3788 case DW_LNS_fixed_advance_pc:
3789 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3790 state_machine_regs.address += uladv;
3791 state_machine_regs.op_index = 0;
3792 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3793 dwarf_vmatoa ("u", uladv),
3794 dwarf_vmatoa ("x", state_machine_regs.address));
3795 /* Do NOT reset view. */
3798 case DW_LNS_set_prologue_end:
3799 printf (_(" Set prologue_end to true\n"));
3802 case DW_LNS_set_epilogue_begin:
3803 printf (_(" Set epilogue_begin to true\n"));
3806 case DW_LNS_set_isa:
3807 uladv = read_uleb128 (data, & bytes_read, end);
3809 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3813 printf (_(" Unknown opcode %d with operands: "), op_code);
3815 if (standard_opcodes != NULL)
3816 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3818 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3820 i == 1 ? "" : ", ");
3836 unsigned char *name;
3837 unsigned int directory_index;
3838 unsigned int modification_date;
3839 unsigned int length;
3842 /* Output a decoded representation of the .debug_line section. */
3845 display_debug_lines_decoded (struct dwarf_section * section,
3846 unsigned char * data,
3847 unsigned char * end,
3850 static DWARF2_Internal_LineInfo saved_linfo;
3852 introduce (section, FALSE);
3856 /* This loop amounts to one iteration per compilation unit. */
3857 DWARF2_Internal_LineInfo linfo;
3858 unsigned char *standard_opcodes;
3859 unsigned char *end_of_sequence;
3861 File_Entry *file_table = NULL;
3862 unsigned int n_files = 0;
3863 unsigned char **directory_table = NULL;
3864 dwarf_vma n_directories = 0;
3866 if (const_strneq (section->name, ".debug_line.")
3867 /* Note: the following does not apply to .debug_line.dwo sections.
3868 These are full debug_line sections. */
3869 && strcmp (section->name, ".debug_line.dwo") != 0)
3871 /* See comment in display_debug_lines_raw(). */
3872 end_of_sequence = end;
3873 standard_opcodes = NULL;
3874 linfo = saved_linfo;
3875 /* PR 17531: file: 0522b371. */
3876 if (linfo.li_line_range == 0)
3878 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3881 reset_state_machine (linfo.li_default_is_stmt);
3885 unsigned char *hdrptr;
3887 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3888 & end_of_sequence)) == NULL)
3891 /* PR 17531: file: 0522b371. */
3892 if (linfo.li_line_range == 0)
3894 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3895 linfo.li_line_range = 1;
3897 reset_state_machine (linfo.li_default_is_stmt);
3899 /* Save a pointer to the contents of the Opcodes table. */
3900 standard_opcodes = hdrptr;
3902 /* Traverse the Directory table just to count entries. */
3903 data = standard_opcodes + linfo.li_opcode_base - 1;
3907 warn (_("opcode base of %d extends beyond end of section\n"),
3908 linfo.li_opcode_base);
3912 if (linfo.li_version >= 5)
3914 unsigned char *format_start, format_count, *format;
3915 dwarf_vma formati, entryi;
3916 unsigned int bytes_read;
3918 load_debug_section_with_follow (line_str, fileptr);
3920 /* Skip directories format. */
3921 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3922 format_start = data;
3923 for (formati = 0; formati < format_count; formati++)
3925 read_uleb128 (data, & bytes_read, end);
3927 read_uleb128 (data, & bytes_read, end);
3931 n_directories = read_uleb128 (data, & bytes_read, end);
3935 warn (_("Corrupt directories list\n"));
3939 directory_table = (unsigned char **)
3940 xmalloc (n_directories * sizeof (unsigned char *));
3942 for (entryi = 0; entryi < n_directories; entryi++)
3944 unsigned char **pathp = &directory_table[entryi];
3946 format = format_start;
3947 for (formati = 0; formati < format_count; formati++)
3949 dwarf_vma content_type, form;
3952 content_type = read_uleb128 (format, & bytes_read, end);
3953 format += bytes_read;
3954 form = read_uleb128 (format, & bytes_read, end);
3955 format += bytes_read;
3958 warn (_("Corrupt directories list\n"));
3961 switch (content_type)
3966 case DW_FORM_string:
3969 case DW_FORM_line_strp:
3970 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3972 /* Remove const by the cast. */
3973 *pathp = (unsigned char *)
3974 fetch_indirect_line_string (uvalue);
3979 data = read_and_display_attr_value (0, form, 0, data, end,
3981 linfo.li_offset_size,
3988 warn (_("Corrupt directories list\n"));
3993 /* Skip files format. */
3994 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3995 format_start = data;
3996 for (formati = 0; formati < format_count; formati++)
3998 read_uleb128 (data, & bytes_read, end);
4000 read_uleb128 (data, & bytes_read, end);
4004 n_files = read_uleb128 (data, & bytes_read, end);
4008 warn (_("Corrupt file name list\n"));
4012 file_table = (File_Entry *) xcalloc (1, n_files
4013 * sizeof (File_Entry));
4015 for (entryi = 0; entryi < n_files; entryi++)
4017 File_Entry *file = &file_table[entryi];
4019 format = format_start;
4020 for (formati = 0; formati < format_count; formati++)
4022 dwarf_vma content_type, form;
4025 content_type = read_uleb128 (format, & bytes_read, end);
4026 format += bytes_read;
4027 form = read_uleb128 (format, & bytes_read, end);
4028 format += bytes_read;
4031 warn (_("Corrupt file name list\n"));
4034 switch (content_type)
4039 case DW_FORM_string:
4042 case DW_FORM_line_strp:
4043 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4045 /* Remove const by the cast. */
4046 file->name = (unsigned char *)
4047 fetch_indirect_line_string (uvalue);
4051 case DW_LNCT_directory_index:
4055 SAFE_BYTE_GET (file->directory_index, data, 1,
4059 SAFE_BYTE_GET (file->directory_index, data, 2,
4063 file->directory_index = read_uleb128 (data, NULL,
4069 data = read_and_display_attr_value (0, form, 0, data, end,
4071 linfo.li_offset_size,
4078 warn (_("Corrupt file name list\n"));
4087 unsigned char *ptr_directory_table = data;
4089 while (data < end && *data != 0)
4091 data += strnlen ((char *) data, end - data) + 1;
4098 warn (_("directory table ends unexpectedly\n"));
4103 /* Go through the directory table again to save the directories. */
4104 directory_table = (unsigned char **)
4105 xmalloc (n_directories * sizeof (unsigned char *));
4108 while (*ptr_directory_table != 0)
4110 directory_table[i] = ptr_directory_table;
4111 ptr_directory_table += strnlen ((char *) ptr_directory_table,
4112 ptr_directory_table - end) + 1;
4116 /* Skip the NUL at the end of the table. */
4119 /* Traverse the File Name table just to count the entries. */
4120 if (data < end && *data != 0)
4122 unsigned char *ptr_file_name_table = data;
4124 while (data < end && *data != 0)
4126 unsigned int bytes_read;
4128 /* Skip Name, directory index, last modification time and length
4130 data += strnlen ((char *) data, end - data) + 1;
4131 read_uleb128 (data, & bytes_read, end);
4133 read_uleb128 (data, & bytes_read, end);
4135 read_uleb128 (data, & bytes_read, end);
4143 warn (_("file table ends unexpectedly\n"));
4148 /* Go through the file table again to save the strings. */
4149 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
4152 while (*ptr_file_name_table != 0)
4154 unsigned int bytes_read;
4156 file_table[i].name = ptr_file_name_table;
4157 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
4158 end - ptr_file_name_table) + 1;
4160 /* We are not interested in directory, time or size. */
4161 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
4163 ptr_file_name_table += bytes_read;
4164 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
4166 ptr_file_name_table += bytes_read;
4167 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
4168 ptr_file_name_table += bytes_read;
4174 /* Skip the NUL at the end of the table. */
4178 /* Print the Compilation Unit's name and a header. */
4179 if (file_table == NULL)
4181 else if (directory_table == NULL)
4182 printf (_("CU: %s:\n"), file_table[0].name);
4185 unsigned int ix = file_table[0].directory_index;
4186 const char *directory;
4191 else if (n_directories == 0)
4192 directory = _("<unknown>");
4193 else if (ix > n_directories)
4195 warn (_("directory index %u > number of directories %s\n"),
4196 ix, dwarf_vmatoa ("u", n_directories));
4197 directory = _("<corrupt>");
4200 directory = (char *) directory_table[ix - 1];
4202 if (do_wide || strlen (directory) < 76)
4203 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4205 printf ("%s:\n", file_table[0].name);
4208 printf (_("File name Line number Starting address View\n"));
4209 saved_linfo = linfo;
4212 /* This loop iterates through the Dwarf Line Number Program. */
4213 while (data < end_of_sequence)
4215 unsigned char op_code;
4218 unsigned long int uladv;
4219 unsigned int bytes_read;
4220 int is_special_opcode = 0;
4225 if (op_code >= linfo.li_opcode_base)
4227 op_code -= linfo.li_opcode_base;
4228 uladv = (op_code / linfo.li_line_range);
4229 if (linfo.li_max_ops_per_insn == 1)
4231 uladv *= linfo.li_min_insn_length;
4232 state_machine_regs.address += uladv;
4234 state_machine_regs.view = 0;
4239 = ((state_machine_regs.op_index + uladv)
4240 / linfo.li_max_ops_per_insn)
4241 * linfo.li_min_insn_length;
4242 state_machine_regs.address
4244 state_machine_regs.op_index
4245 = (state_machine_regs.op_index + uladv)
4246 % linfo.li_max_ops_per_insn;
4248 state_machine_regs.view = 0;
4251 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4252 state_machine_regs.line += adv;
4253 is_special_opcode = 1;
4254 /* Increment view after printing this row. */
4256 else switch (op_code)
4258 case DW_LNS_extended_op:
4260 unsigned int ext_op_code_len;
4261 unsigned char ext_op_code;
4262 unsigned char *op_code_data = data;
4264 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4266 op_code_data += bytes_read;
4268 if (ext_op_code_len == 0)
4270 warn (_("Badly formed extended line op encountered!\n"));
4273 ext_op_code_len += bytes_read;
4274 ext_op_code = *op_code_data++;
4278 switch (ext_op_code)
4280 case DW_LNE_end_sequence:
4281 /* Reset stuff after printing this row. */
4283 case DW_LNE_set_address:
4284 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
4286 ext_op_code_len - bytes_read - 1,
4288 state_machine_regs.op_index = 0;
4289 state_machine_regs.view = 0;
4291 case DW_LNE_define_file:
4293 file_table = (File_Entry *) xrealloc
4294 (file_table, (n_files + 1) * sizeof (File_Entry));
4296 ++state_machine_regs.last_file_entry;
4297 /* Source file name. */
4298 file_table[n_files].name = op_code_data;
4299 op_code_data += strlen ((char *) op_code_data) + 1;
4300 /* Directory index. */
4301 file_table[n_files].directory_index =
4302 read_uleb128 (op_code_data, & bytes_read,
4304 op_code_data += bytes_read;
4305 /* Last modification time. */
4306 file_table[n_files].modification_date =
4307 read_uleb128 (op_code_data, & bytes_read,
4309 op_code_data += bytes_read;
4311 file_table[n_files].length =
4312 read_uleb128 (op_code_data, & bytes_read,
4318 case DW_LNE_set_discriminator:
4319 case DW_LNE_HP_set_sequence:
4320 /* Simply ignored. */
4324 printf (_("UNKNOWN (%u): length %d\n"),
4325 ext_op_code, ext_op_code_len - bytes_read);
4328 data += ext_op_code_len;
4332 /* Increment view after printing this row. */
4335 case DW_LNS_advance_pc:
4336 uladv = read_uleb128 (data, & bytes_read, end);
4338 if (linfo.li_max_ops_per_insn == 1)
4340 uladv *= linfo.li_min_insn_length;
4341 state_machine_regs.address += uladv;
4343 state_machine_regs.view = 0;
4348 = ((state_machine_regs.op_index + uladv)
4349 / linfo.li_max_ops_per_insn)
4350 * linfo.li_min_insn_length;
4351 state_machine_regs.address
4353 state_machine_regs.op_index
4354 = (state_machine_regs.op_index + uladv)
4355 % linfo.li_max_ops_per_insn;
4357 state_machine_regs.view = 0;
4361 case DW_LNS_advance_line:
4362 adv = read_sleb128 (data, & bytes_read, end);
4364 state_machine_regs.line += adv;
4367 case DW_LNS_set_file:
4368 adv = read_uleb128 (data, & bytes_read, end);
4370 state_machine_regs.file = adv;
4373 unsigned file = state_machine_regs.file - 1;
4376 if (file_table == NULL || n_files == 0)
4377 printf (_("\n [Use file table entry %d]\n"), file);
4379 else if (file >= n_files)
4381 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4382 printf (_("\n <over large file table index %u>"), file);
4384 else if ((dir = file_table[file].directory_index) == 0)
4385 /* If directory index is 0, that means current directory. */
4386 printf ("\n./%s:[++]\n", file_table[file].name);
4387 else if (directory_table == NULL || n_directories == 0)
4388 printf (_("\n [Use file %s in directory table entry %d]\n"),
4389 file_table[file].name, dir);
4391 else if (dir > n_directories)
4393 warn (_("directory index %u > number of directories %s\n"),
4394 dir, dwarf_vmatoa ("u", n_directories));
4395 printf (_("\n <over large directory table entry %u>\n"), dir);
4398 printf ("\n%s/%s:\n",
4399 /* The directory index starts counting at 1. */
4400 directory_table[dir - 1], file_table[file].name);
4404 case DW_LNS_set_column:
4405 uladv = read_uleb128 (data, & bytes_read, end);
4407 state_machine_regs.column = uladv;
4410 case DW_LNS_negate_stmt:
4411 adv = state_machine_regs.is_stmt;
4413 state_machine_regs.is_stmt = adv;
4416 case DW_LNS_set_basic_block:
4417 state_machine_regs.basic_block = 1;
4420 case DW_LNS_const_add_pc:
4421 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4422 if (linfo.li_max_ops_per_insn == 1)
4424 uladv *= linfo.li_min_insn_length;
4425 state_machine_regs.address += uladv;
4427 state_machine_regs.view = 0;
4432 = ((state_machine_regs.op_index + uladv)
4433 / linfo.li_max_ops_per_insn)
4434 * linfo.li_min_insn_length;
4435 state_machine_regs.address
4437 state_machine_regs.op_index
4438 = (state_machine_regs.op_index + uladv)
4439 % linfo.li_max_ops_per_insn;
4441 state_machine_regs.view = 0;
4445 case DW_LNS_fixed_advance_pc:
4446 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4447 state_machine_regs.address += uladv;
4448 state_machine_regs.op_index = 0;
4449 /* Do NOT reset view. */
4452 case DW_LNS_set_prologue_end:
4455 case DW_LNS_set_epilogue_begin:
4458 case DW_LNS_set_isa:
4459 uladv = read_uleb128 (data, & bytes_read, end);
4461 printf (_(" Set ISA to %lu\n"), uladv);
4465 printf (_(" Unknown opcode %d with operands: "), op_code);
4467 if (standard_opcodes != NULL)
4468 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4470 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4472 i == 1 ? "" : ", ");
4479 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4480 to the DWARF address/line matrix. */
4481 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4482 || (xop == DW_LNS_copy))
4484 const unsigned int MAX_FILENAME_LENGTH = 35;
4486 char *newFileName = NULL;
4487 size_t fileNameLength;
4491 unsigned indx = state_machine_regs.file - 1;
4493 if (indx >= n_files)
4495 warn (_("corrupt file index %u encountered\n"), indx);
4496 fileName = _("<corrupt>");
4499 fileName = (char *) file_table[indx].name;
4502 fileName = _("<unknown>");
4504 fileNameLength = strlen (fileName);
4506 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4508 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4509 /* Truncate file name */
4510 strncpy (newFileName,
4511 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4512 MAX_FILENAME_LENGTH + 1);
4516 newFileName = (char *) xmalloc (fileNameLength + 1);
4517 strncpy (newFileName, fileName, fileNameLength + 1);
4520 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4522 if (linfo.li_max_ops_per_insn == 1)
4523 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
4524 newFileName, state_machine_regs.line,
4525 state_machine_regs.address);
4527 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
4528 newFileName, state_machine_regs.line,
4529 state_machine_regs.address,
4530 state_machine_regs.op_index);
4534 if (linfo.li_max_ops_per_insn == 1)
4535 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
4536 newFileName, state_machine_regs.line,
4537 state_machine_regs.address);
4539 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
4540 newFileName, state_machine_regs.line,
4541 state_machine_regs.address,
4542 state_machine_regs.op_index);
4545 if (state_machine_regs.view)
4546 printf (" %6u\n", state_machine_regs.view);
4549 state_machine_regs.view++;
4551 if (xop == -DW_LNE_end_sequence)
4553 reset_state_machine (linfo.li_default_is_stmt);
4568 if (directory_table)
4570 free (directory_table);
4571 directory_table = NULL;
4582 display_debug_lines (struct dwarf_section *section, void *file)
4584 unsigned char *data = section->start;
4585 unsigned char *end = data + section->size;
4587 int retValDecoded = 1;
4589 if (do_debug_lines == 0)
4590 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4592 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4593 retValRaw = display_debug_lines_raw (section, data, end, file);
4595 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4596 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4598 if (!retValRaw || !retValDecoded)
4605 find_debug_info_for_offset (unsigned long offset)
4609 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4612 for (i = 0; i < num_debug_info_entries; i++)
4613 if (debug_information[i].cu_offset == offset)
4614 return debug_information + i;
4620 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4622 /* See gdb/gdb-index.h. */
4623 static const char * const kinds[] =
4635 return _ (kinds[kind]);
4639 display_debug_pubnames_worker (struct dwarf_section *section,
4640 void *file ATTRIBUTE_UNUSED,
4643 DWARF2_Internal_PubNames names;
4644 unsigned char *start = section->start;
4645 unsigned char *end = start + section->size;
4647 /* It does not matter if this load fails,
4648 we test for that later on. */
4649 load_debug_info (file);
4651 introduce (section, FALSE);
4655 unsigned char *data;
4656 unsigned long sec_off;
4657 unsigned int offset_size, initial_length_size;
4659 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
4660 if (names.pn_length == 0xffffffff)
4662 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
4664 initial_length_size = 12;
4669 initial_length_size = 4;
4672 sec_off = start - section->start;
4673 if (sec_off + names.pn_length < sec_off
4674 || sec_off + names.pn_length > section->size)
4676 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4678 sec_off - initial_length_size,
4679 dwarf_vmatoa ("x", names.pn_length));
4684 start += names.pn_length;
4686 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4687 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4689 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4690 && num_debug_info_entries > 0
4691 && find_debug_info_for_offset (names.pn_offset) == NULL)
4692 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4693 (unsigned long) names.pn_offset, section->name);
4695 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4697 printf (_(" Length: %ld\n"),
4698 (long) names.pn_length);
4699 printf (_(" Version: %d\n"),
4701 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4702 (unsigned long) names.pn_offset);
4703 printf (_(" Size of area in .debug_info section: %ld\n"),
4704 (long) names.pn_size);
4706 if (names.pn_version != 2 && names.pn_version != 3)
4708 static int warned = 0;
4712 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4720 printf (_("\n Offset Kind Name\n"));
4722 printf (_("\n Offset\tName\n"));
4726 bfd_size_type maxprint;
4729 SAFE_BYTE_GET (offset, data, offset_size, end);
4734 data += offset_size;
4737 maxprint = (end - data) - 1;
4741 unsigned int kind_data;
4742 gdb_index_symbol_kind kind;
4743 const char *kind_name;
4746 SAFE_BYTE_GET (kind_data, data, 1, end);
4749 /* GCC computes the kind as the upper byte in the CU index
4750 word, and then right shifts it by the CU index size.
4751 Left shift KIND to where the gdb-index.h accessor macros
4753 kind_data <<= GDB_INDEX_CU_BITSIZE;
4754 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4755 kind_name = get_gdb_index_symbol_kind_name (kind);
4756 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4757 printf (" %-6lx %s,%-10s %.*s\n",
4758 (unsigned long) offset, is_static ? _("s") : _("g"),
4759 kind_name, (int) maxprint, data);
4762 printf (" %-6lx\t%.*s\n",
4763 (unsigned long) offset, (int) maxprint, data);
4765 data += strnlen ((char *) data, maxprint) + 1;
4776 display_debug_pubnames (struct dwarf_section *section, void *file)
4778 return display_debug_pubnames_worker (section, file, 0);
4782 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4784 return display_debug_pubnames_worker (section, file, 1);
4788 display_debug_macinfo (struct dwarf_section *section,
4789 void *file ATTRIBUTE_UNUSED)
4791 unsigned char *start = section->start;
4792 unsigned char *end = start + section->size;
4793 unsigned char *curr = start;
4794 unsigned int bytes_read;
4795 enum dwarf_macinfo_record_type op;
4797 introduce (section, FALSE);
4801 unsigned int lineno;
4802 const unsigned char *string;
4804 op = (enum dwarf_macinfo_record_type) *curr;
4809 case DW_MACINFO_start_file:
4811 unsigned int filenum;
4813 lineno = read_uleb128 (curr, & bytes_read, end);
4815 filenum = read_uleb128 (curr, & bytes_read, end);
4818 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4823 case DW_MACINFO_end_file:
4824 printf (_(" DW_MACINFO_end_file\n"));
4827 case DW_MACINFO_define:
4828 lineno = read_uleb128 (curr, & bytes_read, end);
4831 curr += strnlen ((char *) string, end - string) + 1;
4832 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4836 case DW_MACINFO_undef:
4837 lineno = read_uleb128 (curr, & bytes_read, end);
4840 curr += strnlen ((char *) string, end - string) + 1;
4841 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4845 case DW_MACINFO_vendor_ext:
4847 unsigned int constant;
4849 constant = read_uleb128 (curr, & bytes_read, end);
4852 curr += strnlen ((char *) string, end - string) + 1;
4853 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4863 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4864 filename and dirname corresponding to file name table entry with index
4865 FILEIDX. Return NULL on failure. */
4867 static unsigned char *
4868 get_line_filename_and_dirname (dwarf_vma line_offset,
4870 unsigned char **dir_name)
4872 struct dwarf_section *section = &debug_displays [line].section;
4873 unsigned char *hdrptr, *dirtable, *file_name;
4874 unsigned int offset_size, initial_length_size;
4875 unsigned int version, opcode_base, bytes_read;
4876 dwarf_vma length, diridx;
4877 const unsigned char * end;
4880 if (section->start == NULL
4881 || line_offset >= section->size
4885 hdrptr = section->start + line_offset;
4886 end = section->start + section->size;
4888 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4889 if (length == 0xffffffff)
4891 /* This section is 64-bit DWARF 3. */
4892 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4894 initial_length_size = 12;
4899 initial_length_size = 4;
4901 if (length + initial_length_size < length
4902 || length + initial_length_size > section->size)
4905 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4906 if (version != 2 && version != 3 && version != 4)
4908 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4910 hdrptr++; /* Skip max_ops_per_insn. */
4911 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4913 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4914 if (opcode_base == 0)
4917 hdrptr += opcode_base - 1;
4922 /* Skip over dirname table. */
4923 while (*hdrptr != '\0')
4925 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4929 hdrptr++; /* Skip the NUL at the end of the table. */
4931 /* Now skip over preceding filename table entries. */
4932 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
4934 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4935 read_uleb128 (hdrptr, &bytes_read, end);
4936 hdrptr += bytes_read;
4937 read_uleb128 (hdrptr, &bytes_read, end);
4938 hdrptr += bytes_read;
4939 read_uleb128 (hdrptr, &bytes_read, end);
4940 hdrptr += bytes_read;
4942 if (hdrptr >= end || *hdrptr == '\0')
4946 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4949 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4952 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
4953 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4954 if (dirtable >= end || *dirtable == '\0')
4956 *dir_name = dirtable;
4961 display_debug_macro (struct dwarf_section *section,
4964 unsigned char *start = section->start;
4965 unsigned char *end = start + section->size;
4966 unsigned char *curr = start;
4967 unsigned char *extended_op_buf[256];
4968 unsigned int bytes_read;
4970 load_debug_section_with_follow (str, file);
4971 load_debug_section_with_follow (line, file);
4973 introduce (section, FALSE);
4977 unsigned int lineno, version, flags;
4978 unsigned int offset_size = 4;
4979 const unsigned char *string;
4980 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4981 unsigned char **extended_ops = NULL;
4983 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4984 if (version != 4 && version != 5)
4986 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4991 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4994 printf (_(" Offset: 0x%lx\n"),
4995 (unsigned long) sec_offset);
4996 printf (_(" Version: %d\n"), version);
4997 printf (_(" Offset size: %d\n"), offset_size);
5000 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
5001 printf (_(" Offset into .debug_line: 0x%lx\n"),
5002 (unsigned long) line_offset);
5006 unsigned int i, count, op;
5009 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
5011 memset (extended_op_buf, 0, sizeof (extended_op_buf));
5012 extended_ops = extended_op_buf;
5015 printf (_(" Extension opcode arguments:\n"));
5016 for (i = 0; i < count; i++)
5018 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5019 extended_ops[op] = curr;
5020 nargs = read_uleb128 (curr, &bytes_read, end);
5023 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
5026 printf (_(" DW_MACRO_%02x arguments: "), op);
5027 for (n = 0; n < nargs; n++)
5031 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
5032 printf ("%s%s", get_FORM_name (form),
5033 n == nargs - 1 ? "\n" : ", ");
5043 case DW_FORM_block1:
5044 case DW_FORM_block2:
5045 case DW_FORM_block4:
5047 case DW_FORM_string:
5049 case DW_FORM_sec_offset:
5052 error (_("Invalid extension opcode form %s\n"),
5053 get_FORM_name (form));
5069 error (_(".debug_macro section not zero terminated\n"));
5073 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
5079 case DW_MACRO_start_file:
5081 unsigned int filenum;
5082 unsigned char *file_name = NULL, *dir_name = NULL;
5084 lineno = read_uleb128 (curr, &bytes_read, end);
5086 filenum = read_uleb128 (curr, &bytes_read, end);
5089 if ((flags & 2) == 0)
5090 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5093 = get_line_filename_and_dirname (line_offset, filenum,
5095 if (file_name == NULL)
5096 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5099 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5101 dir_name != NULL ? (const char *) dir_name : "",
5102 dir_name != NULL ? "/" : "", file_name);
5106 case DW_MACRO_end_file:
5107 printf (_(" DW_MACRO_end_file\n"));
5110 case DW_MACRO_define:
5111 lineno = read_uleb128 (curr, &bytes_read, end);
5114 curr += strnlen ((char *) string, end - string) + 1;
5115 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5119 case DW_MACRO_undef:
5120 lineno = read_uleb128 (curr, &bytes_read, end);
5123 curr += strnlen ((char *) string, end - string) + 1;
5124 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5128 case DW_MACRO_define_strp:
5129 lineno = read_uleb128 (curr, &bytes_read, end);
5131 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5132 string = fetch_indirect_string (offset);
5133 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5137 case DW_MACRO_undef_strp:
5138 lineno = read_uleb128 (curr, &bytes_read, end);
5140 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5141 string = fetch_indirect_string (offset);
5142 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5146 case DW_MACRO_import:
5147 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5148 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5149 (unsigned long) offset);
5152 case DW_MACRO_define_sup:
5153 lineno = read_uleb128 (curr, &bytes_read, end);
5155 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5156 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5157 lineno, (unsigned long) offset);
5160 case DW_MACRO_undef_sup:
5161 lineno = read_uleb128 (curr, &bytes_read, end);
5163 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5164 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5165 lineno, (unsigned long) offset);
5168 case DW_MACRO_import_sup:
5169 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
5170 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5171 (unsigned long) offset);
5175 if (extended_ops == NULL || extended_ops[op] == NULL)
5177 error (_(" Unknown macro opcode %02x seen\n"), op);
5182 /* Skip over unhandled opcodes. */
5184 unsigned char *desc = extended_ops[op];
5185 nargs = read_uleb128 (desc, &bytes_read, end);
5189 printf (_(" DW_MACRO_%02x\n"), op);
5192 printf (_(" DW_MACRO_%02x -"), op);
5193 for (n = 0; n < nargs; n++)
5197 /* DW_FORM_implicit_const is not expected here. */
5198 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
5200 = read_and_display_attr_value (0, val, 0,
5201 curr, end, 0, 0, offset_size,
5202 version, NULL, 0, NULL,
5220 display_debug_abbrev (struct dwarf_section *section,
5221 void *file ATTRIBUTE_UNUSED)
5223 abbrev_entry *entry;
5224 unsigned char *start = section->start;
5225 unsigned char *end = start + section->size;
5227 introduce (section, FALSE);
5231 unsigned char *last;
5236 start = process_abbrev_section (start, end);
5238 if (first_abbrev == NULL)
5241 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
5243 for (entry = first_abbrev; entry; entry = entry->next)
5247 printf (" %ld %s [%s]\n",
5249 get_TAG_name (entry->tag),
5250 entry->children ? _("has children") : _("no children"));
5252 for (attr = entry->first_attr; attr; attr = attr->next)
5254 printf (" %-18s %s",
5255 get_AT_name (attr->attribute),
5256 get_FORM_name (attr->form));
5257 if (attr->form == DW_FORM_implicit_const)
5258 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5270 /* Return true when ADDR is the maximum address, when addresses are
5271 POINTER_SIZE bytes long. */
5274 is_max_address (dwarf_vma addr, unsigned int pointer_size)
5276 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5277 return ((addr & mask) == mask);
5280 /* Display a view pair list starting at *VSTART_PTR and ending at
5281 VLISTEND within SECTION. */
5284 display_view_pair_list (struct dwarf_section *section,
5285 unsigned char **vstart_ptr,
5286 unsigned int debug_info_entry,
5287 unsigned char *vlistend)
5289 unsigned char *vstart = *vstart_ptr;
5290 unsigned char *section_end = section->start + section->size;
5291 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5293 if (vlistend < section_end)
5294 section_end = vlistend;
5298 while (vstart < section_end)
5300 dwarf_vma off = vstart - section->start;
5301 dwarf_vma vbegin, vend;
5303 unsigned int bytes_read;
5304 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5305 vstart += bytes_read;
5306 if (vstart == section_end)
5308 vstart -= bytes_read;
5312 vend = read_uleb128 (vstart, &bytes_read, section_end);
5313 vstart += bytes_read;
5315 printf (" %8.8lx ", (unsigned long) off);
5317 print_dwarf_view (vbegin, pointer_size, 1);
5318 print_dwarf_view (vend, pointer_size, 1);
5319 printf (_("location view pair\n"));
5323 *vstart_ptr = vstart;
5326 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5329 display_loc_list (struct dwarf_section *section,
5330 unsigned char **start_ptr,
5331 unsigned int debug_info_entry,
5333 dwarf_vma base_address,
5334 unsigned char **vstart_ptr,
5337 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5338 unsigned char *section_end = section->start + section->size;
5339 unsigned long cu_offset;
5340 unsigned int pointer_size;
5341 unsigned int offset_size;
5346 unsigned short length;
5347 int need_frame_base;
5349 if (debug_info_entry >= num_debug_info_entries)
5351 warn (_("No debug information available for loc lists of entry: %u\n"),
5356 cu_offset = debug_information [debug_info_entry].cu_offset;
5357 pointer_size = debug_information [debug_info_entry].pointer_size;
5358 offset_size = debug_information [debug_info_entry].offset_size;
5359 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5361 if (pointer_size < 2 || pointer_size > 8)
5363 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5364 pointer_size, debug_info_entry);
5370 dwarf_vma off = offset + (start - *start_ptr);
5371 dwarf_vma vbegin = vm1, vend = vm1;
5373 if (start + 2 * pointer_size > section_end)
5375 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5376 (unsigned long) offset);
5380 printf (" %8.8lx ", (unsigned long) off);
5382 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5383 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5385 if (begin == 0 && end == 0)
5387 /* PR 18374: In a object file we can have a location list that
5388 starts with a begin and end of 0 because there are relocations
5389 that need to be applied to the addresses. Actually applying
5390 the relocations now does not help as they will probably resolve
5391 to 0, since the object file has not been fully linked. Real
5392 end of list markers will not have any relocations against them. */
5393 if (! reloc_at (section, off)
5394 && ! reloc_at (section, off + pointer_size))
5396 printf (_("<End of list>\n"));
5401 /* Check base address specifiers. */
5402 if (is_max_address (begin, pointer_size)
5403 && !is_max_address (end, pointer_size))
5406 print_dwarf_vma (begin, pointer_size);
5407 print_dwarf_vma (end, pointer_size);
5408 printf (_("(base address)\n"));
5414 unsigned int bytes_read;
5416 off = offset + (vstart - *start_ptr);
5418 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5419 vstart += bytes_read;
5420 print_dwarf_view (vbegin, pointer_size, 1);
5422 vend = read_uleb128 (vstart, &bytes_read, section_end);
5423 vstart += bytes_read;
5424 print_dwarf_view (vend, pointer_size, 1);
5426 printf (_("views at %8.8lx for:\n %*s "),
5427 (unsigned long) off, 8, "");
5430 if (start + 2 > section_end)
5432 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5433 (unsigned long) offset);
5437 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5439 if (start + length > section_end)
5441 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5442 (unsigned long) offset);
5446 print_dwarf_vma (begin + base_address, pointer_size);
5447 print_dwarf_vma (end + base_address, pointer_size);
5450 need_frame_base = decode_location_expression (start,
5455 cu_offset, section);
5458 if (need_frame_base && !has_frame_base)
5459 printf (_(" [without DW_AT_frame_base]"));
5461 if (begin == end && vbegin == vend)
5462 fputs (_(" (start == end)"), stdout);
5463 else if (begin > end || (begin == end && vbegin > vend))
5464 fputs (_(" (start > end)"), stdout);
5472 *vstart_ptr = vstart;
5475 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5478 display_loclists_list (struct dwarf_section *section,
5479 unsigned char **start_ptr,
5480 unsigned int debug_info_entry,
5482 dwarf_vma base_address,
5483 unsigned char **vstart_ptr,
5486 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5487 unsigned char *section_end = section->start + section->size;
5488 unsigned long cu_offset;
5489 unsigned int pointer_size;
5490 unsigned int offset_size;
5492 unsigned int bytes_read;
5494 /* Initialize it due to a false compiler warning. */
5495 dwarf_vma begin = -1, vbegin = -1;
5496 dwarf_vma end = -1, vend = -1;
5498 int need_frame_base;
5500 if (debug_info_entry >= num_debug_info_entries)
5502 warn (_("No debug information available for "
5503 "loclists lists of entry: %u\n"),
5508 cu_offset = debug_information [debug_info_entry].cu_offset;
5509 pointer_size = debug_information [debug_info_entry].pointer_size;
5510 offset_size = debug_information [debug_info_entry].offset_size;
5511 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5513 if (pointer_size < 2 || pointer_size > 8)
5515 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5516 pointer_size, debug_info_entry);
5522 dwarf_vma off = offset + (start - *start_ptr);
5523 enum dwarf_location_list_entry_type llet;
5525 if (start + 1 > section_end)
5527 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5528 (unsigned long) offset);
5532 printf (" %8.8lx ", (unsigned long) off);
5534 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5536 if (vstart && llet == DW_LLE_offset_pair)
5538 off = offset + (vstart - *start_ptr);
5540 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5541 vstart += bytes_read;
5542 print_dwarf_view (vbegin, pointer_size, 1);
5544 vend = read_uleb128 (vstart, &bytes_read, section_end);
5545 vstart += bytes_read;
5546 print_dwarf_view (vend, pointer_size, 1);
5548 printf (_("views at %8.8lx for:\n %*s "),
5549 (unsigned long) off, 8, "");
5554 case DW_LLE_end_of_list:
5555 printf (_("<End of list>\n"));
5557 case DW_LLE_offset_pair:
5558 begin = read_uleb128 (start, &bytes_read, section_end);
5559 start += bytes_read;
5560 end = read_uleb128 (start, &bytes_read, section_end);
5561 start += bytes_read;
5563 case DW_LLE_base_address:
5564 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5566 print_dwarf_vma (base_address, pointer_size);
5567 printf (_("(base address)\n"));
5569 #ifdef DW_LLE_view_pair
5570 case DW_LLE_view_pair:
5572 printf (_("View pair entry in loclist with locviews attribute\n"));
5573 vbegin = read_uleb128 (start, &bytes_read, section_end);
5574 start += bytes_read;
5575 print_dwarf_view (vbegin, pointer_size, 1);
5577 vend = read_uleb128 (start, &bytes_read, section_end);
5578 start += bytes_read;
5579 print_dwarf_view (vend, pointer_size, 1);
5581 printf (_("views for:\n"));
5585 error (_("Invalid location list entry type %d\n"), llet);
5588 if (llet == DW_LLE_end_of_list)
5590 if (llet != DW_LLE_offset_pair)
5593 if (start + 2 > section_end)
5595 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5596 (unsigned long) offset);
5600 length = read_uleb128 (start, &bytes_read, section_end);
5601 start += bytes_read;
5603 print_dwarf_vma (begin + base_address, pointer_size);
5604 print_dwarf_vma (end + base_address, pointer_size);
5607 need_frame_base = decode_location_expression (start,
5612 cu_offset, section);
5615 if (need_frame_base && !has_frame_base)
5616 printf (_(" [without DW_AT_frame_base]"));
5618 if (begin == end && vbegin == vend)
5619 fputs (_(" (start == end)"), stdout);
5620 else if (begin > end || (begin == end && vbegin > vend))
5621 fputs (_(" (start > end)"), stdout);
5629 if (vbegin != vm1 || vend != vm1)
5630 printf (_("Trailing view pair not used in a range"));
5633 *vstart_ptr = vstart;
5636 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5637 right-adjusted in a field of length LEN, and followed by a space. */
5640 print_addr_index (unsigned int idx, unsigned int len)
5642 static char buf[15];
5643 snprintf (buf, sizeof (buf), "[%d]", idx);
5644 printf ("%*s ", len, buf);
5647 /* Display a location list from a .dwo section. It uses address indexes rather
5648 than embedded addresses. This code closely follows display_loc_list, but the
5649 two are sufficiently different that combining things is very ugly. */
5652 display_loc_list_dwo (struct dwarf_section *section,
5653 unsigned char **start_ptr,
5654 unsigned int debug_info_entry,
5656 unsigned char **vstart_ptr,
5659 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5660 unsigned char *section_end = section->start + section->size;
5661 unsigned long cu_offset;
5662 unsigned int pointer_size;
5663 unsigned int offset_size;
5666 unsigned short length;
5667 int need_frame_base;
5669 unsigned int bytes_read;
5671 if (debug_info_entry >= num_debug_info_entries)
5673 warn (_("No debug information for loc lists of entry: %u\n"),
5678 cu_offset = debug_information [debug_info_entry].cu_offset;
5679 pointer_size = debug_information [debug_info_entry].pointer_size;
5680 offset_size = debug_information [debug_info_entry].offset_size;
5681 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5683 if (pointer_size < 2 || pointer_size > 8)
5685 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5686 pointer_size, debug_info_entry);
5692 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5694 if (start >= section_end)
5696 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5697 (unsigned long) offset);
5701 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5714 dwarf_vma off = offset + (vstart - *start_ptr);
5716 view = read_uleb128 (vstart, &bytes_read, section_end);
5717 vstart += bytes_read;
5718 print_dwarf_view (view, 8, 1);
5720 view = read_uleb128 (vstart, &bytes_read, section_end);
5721 vstart += bytes_read;
5722 print_dwarf_view (view, 8, 1);
5724 printf (_("views at %8.8lx for:\n %*s "),
5725 (unsigned long) off, 8, "");
5733 case 0: /* A terminating entry. */
5735 *vstart_ptr = vstart;
5736 printf (_("<End of list>\n"));
5738 case 1: /* A base-address entry. */
5739 idx = read_uleb128 (start, &bytes_read, section_end);
5740 start += bytes_read;
5741 print_addr_index (idx, 8);
5742 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
5743 printf (_("(base address selection entry)\n"));
5745 case 2: /* A start/end entry. */
5746 idx = read_uleb128 (start, &bytes_read, section_end);
5747 start += bytes_read;
5748 print_addr_index (idx, 8);
5749 idx = read_uleb128 (start, &bytes_read, section_end);
5750 start += bytes_read;
5751 print_addr_index (idx, 8);
5753 case 3: /* A start/length entry. */
5754 idx = read_uleb128 (start, &bytes_read, section_end);
5755 start += bytes_read;
5756 print_addr_index (idx, 8);
5757 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5758 printf ("%08x ", idx);
5760 case 4: /* An offset pair entry. */
5761 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5762 printf ("%08x ", idx);
5763 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5764 printf ("%08x ", idx);
5767 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5769 *vstart_ptr = vstart;
5773 if (start + 2 > section_end)
5775 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5776 (unsigned long) offset);
5780 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5781 if (start + length > section_end)
5783 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5784 (unsigned long) offset);
5789 need_frame_base = decode_location_expression (start,
5794 cu_offset, section);
5797 if (need_frame_base && !has_frame_base)
5798 printf (_(" [without DW_AT_frame_base]"));
5806 *vstart_ptr = vstart;
5809 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5812 static dwarf_vma *loc_offsets, *loc_views;
5815 loc_offsets_compar (const void *ap, const void *bp)
5817 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5818 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5820 int ret = (a > b) - (b > a);
5824 a = loc_views[*(const unsigned int *) ap];
5825 b = loc_views[*(const unsigned int *) bp];
5827 ret = (a > b) - (b > a);
5833 display_debug_loc (struct dwarf_section *section, void *file)
5835 unsigned char *start = section->start, *vstart = NULL;
5836 unsigned long bytes;
5837 unsigned char *section_begin = start;
5838 unsigned int num_loc_list = 0;
5839 unsigned long last_offset = 0;
5840 unsigned long last_view = 0;
5841 unsigned int first = 0;
5844 int seen_first_offset = 0;
5845 int locs_sorted = 1;
5846 unsigned char *next = start, *vnext = vstart;
5847 unsigned int *array = NULL;
5848 const char *suffix = strrchr (section->name, '.');
5850 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5851 dwarf_vma expected_start = 0;
5853 if (suffix && strcmp (suffix, ".dwo") == 0)
5856 bytes = section->size;
5860 printf (_("\nThe %s section is empty.\n"), section->name);
5866 unsigned char *hdrptr = section_begin;
5867 dwarf_vma ll_length;
5868 unsigned short ll_version;
5869 unsigned char *end = section_begin + section->size;
5870 unsigned char address_size, segment_selector_size;
5871 uint32_t offset_entry_count;
5873 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5874 if (ll_length == 0xffffffff)
5875 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5877 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5878 if (ll_version != 5)
5880 warn (_("The %s section contains corrupt or "
5881 "unsupported version number: %d.\n"),
5882 section->name, ll_version);
5886 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5888 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5889 if (segment_selector_size != 0)
5891 warn (_("The %s section contains "
5892 "unsupported segment selector size: %d.\n"),
5893 section->name, segment_selector_size);
5897 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5898 if (offset_entry_count != 0)
5900 warn (_("The %s section contains "
5901 "unsupported offset entry count: %d.\n"),
5902 section->name, offset_entry_count);
5906 expected_start = hdrptr - section_begin;
5909 if (load_debug_info (file) == 0)
5911 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5916 /* Check the order of location list in .debug_info section. If
5917 offsets of location lists are in the ascending order, we can
5918 use `debug_information' directly. */
5919 for (i = 0; i < num_debug_info_entries; i++)
5923 num = debug_information [i].num_loc_offsets;
5924 if (num > num_loc_list)
5927 /* Check if we can use `debug_information' directly. */
5928 if (locs_sorted && num != 0)
5930 if (!seen_first_offset)
5932 /* This is the first location list. */
5933 last_offset = debug_information [i].loc_offsets [0];
5934 last_view = debug_information [i].loc_views [0];
5936 seen_first_offset = 1;
5942 for (; j < num; j++)
5945 debug_information [i].loc_offsets [j]
5946 || (last_offset == debug_information [i].loc_offsets [j]
5947 && last_view > debug_information [i].loc_views [j]))
5952 last_offset = debug_information [i].loc_offsets [j];
5953 last_view = debug_information [i].loc_views [j];
5958 if (!seen_first_offset)
5959 error (_("No location lists in .debug_info section!\n"));
5961 if (debug_information [first].num_loc_offsets > 0
5962 && debug_information [first].loc_offsets [0] != expected_start
5963 && debug_information [first].loc_views [0] != expected_start)
5964 warn (_("Location lists in %s section start at 0x%s\n"),
5966 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5969 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5971 introduce (section, FALSE);
5973 if (reloc_at (section, 0))
5974 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5976 printf (_(" Offset Begin End Expression\n"));
5978 seen_first_offset = 0;
5979 for (i = first; i < num_debug_info_entries; i++)
5981 dwarf_vma offset, voffset;
5982 dwarf_vma base_address;
5988 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5990 loc_offsets = debug_information [i].loc_offsets;
5991 loc_views = debug_information [i].loc_views;
5992 qsort (array, debug_information [i].num_loc_offsets,
5993 sizeof (*array), loc_offsets_compar);
5996 int adjacent_view_loclists = 1;
5997 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5999 j = locs_sorted ? k : array[k];
6001 && (debug_information [i].loc_offsets [locs_sorted
6002 ? k - 1 : array [k - 1]]
6003 == debug_information [i].loc_offsets [j])
6004 && (debug_information [i].loc_views [locs_sorted
6005 ? k - 1 : array [k - 1]]
6006 == debug_information [i].loc_views [j]))
6008 has_frame_base = debug_information [i].have_frame_base [j];
6009 offset = debug_information [i].loc_offsets [j];
6010 next = section_begin + offset;
6011 voffset = debug_information [i].loc_views [j];
6013 vnext = section_begin + voffset;
6016 base_address = debug_information [i].base_address;
6018 if (vnext && vnext < next)
6021 display_view_pair_list (section, &vstart, i, next);
6026 if (!seen_first_offset || !adjacent_view_loclists)
6027 seen_first_offset = 1;
6031 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6032 (unsigned long) (start - section_begin),
6033 (unsigned long) offset);
6034 else if (start > next)
6035 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6036 (unsigned long) (start - section_begin),
6037 (unsigned long) offset);
6042 if (offset >= bytes)
6044 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6045 (unsigned long) offset);
6049 if (vnext && voffset >= bytes)
6051 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6052 (unsigned long) voffset);
6059 display_loc_list_dwo (section, &start, i, offset,
6060 &vstart, has_frame_base);
6062 display_loc_list (section, &start, i, offset, base_address,
6063 &vstart, has_frame_base);
6068 warn (_("DWO is not yet supported.\n"));
6070 display_loclists_list (section, &start, i, offset, base_address,
6071 &vstart, has_frame_base);
6074 /* FIXME: this arrangement is quite simplistic. Nothing
6075 requires locview lists to be adjacent to corresponding
6076 loclists, and a single loclist could be augmented by
6077 different locview lists, and vice-versa, unlikely as it
6078 is that it would make sense to do so. Hopefully we'll
6079 have view pair support built into loclists before we ever
6080 need to address all these possibilities. */
6081 if (adjacent_view_loclists && vnext
6082 && vnext != start && vstart != next)
6084 adjacent_view_loclists = 0;
6085 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6088 if (vnext && vnext == start)
6089 display_view_pair_list (section, &start, i, vstart);
6093 if (start < section->start + section->size)
6094 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6095 "There are %ld unused bytes at the end of section %s\n",
6096 (long) (section->start + section->size - start)),
6097 (long) (section->start + section->size - start), section->name);
6104 display_debug_str (struct dwarf_section *section,
6105 void *file ATTRIBUTE_UNUSED)
6107 unsigned char *start = section->start;
6108 unsigned long bytes = section->size;
6109 dwarf_vma addr = section->address;
6113 printf (_("\nThe %s section is empty.\n"), section->name);
6117 introduce (section, FALSE);
6125 lbytes = (bytes > 16 ? 16 : bytes);
6127 printf (" 0x%8.8lx ", (unsigned long) addr);
6129 for (j = 0; j < 16; j++)
6132 printf ("%2.2x", start[j]);
6140 for (j = 0; j < lbytes; j++)
6143 if (k >= ' ' && k < 0x80)
6162 display_debug_info (struct dwarf_section *section, void *file)
6164 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
6168 display_debug_types (struct dwarf_section *section, void *file)
6170 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
6174 display_trace_info (struct dwarf_section *section, void *file)
6176 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
6180 display_debug_aranges (struct dwarf_section *section,
6181 void *file ATTRIBUTE_UNUSED)
6183 unsigned char *start = section->start;
6184 unsigned char *end = start + section->size;
6186 introduce (section, FALSE);
6188 /* It does not matter if this load fails,
6189 we test for that later on. */
6190 load_debug_info (file);
6194 unsigned char *hdrptr;
6195 DWARF2_Internal_ARange arange;
6196 unsigned char *addr_ranges;
6199 unsigned long sec_off;
6200 unsigned char address_size;
6202 unsigned int offset_size;
6203 unsigned int initial_length_size;
6207 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
6208 if (arange.ar_length == 0xffffffff)
6210 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
6212 initial_length_size = 12;
6217 initial_length_size = 4;
6220 sec_off = hdrptr - section->start;
6221 if (sec_off + arange.ar_length < sec_off
6222 || sec_off + arange.ar_length > section->size)
6224 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6226 sec_off - initial_length_size,
6227 dwarf_vmatoa ("x", arange.ar_length));
6231 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6232 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
6234 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6235 && num_debug_info_entries > 0
6236 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6237 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6238 (unsigned long) arange.ar_info_offset, section->name);
6240 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6241 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
6243 if (arange.ar_version != 2 && arange.ar_version != 3)
6245 /* PR 19872: A version number of 0 probably means that there is
6246 padding at the end of the .debug_aranges section. Gold puts
6247 it there when performing an incremental link, for example.
6248 So do not generate a warning in this case. */
6249 if (arange.ar_version)
6250 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6254 printf (_(" Length: %ld\n"),
6255 (long) arange.ar_length);
6256 printf (_(" Version: %d\n"), arange.ar_version);
6257 printf (_(" Offset into .debug_info: 0x%lx\n"),
6258 (unsigned long) arange.ar_info_offset);
6259 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6260 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6262 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6264 /* PR 17512: file: 001-108546-0.001:0.1. */
6265 if (address_size == 0 || address_size > 8)
6267 error (_("Invalid address size in %s section!\n"),
6272 /* The DWARF spec does not require that the address size be a power
6273 of two, but we do. This will have to change if we ever encounter
6274 an uneven architecture. */
6275 if ((address_size & (address_size - 1)) != 0)
6277 warn (_("Pointer size + Segment size is not a power of two.\n"));
6281 if (address_size > 4)
6282 printf (_("\n Address Length\n"));
6284 printf (_("\n Address Length\n"));
6286 addr_ranges = hdrptr;
6288 /* Must pad to an alignment boundary that is twice the address size. */
6289 excess = (hdrptr - start) % (2 * address_size);
6291 addr_ranges += (2 * address_size) - excess;
6293 start += arange.ar_length + initial_length_size;
6295 while (addr_ranges + 2 * address_size <= start)
6297 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6298 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
6301 print_dwarf_vma (address, address_size);
6302 print_dwarf_vma (length, address_size);
6312 /* Comparison function for qsort. */
6314 comp_addr_base (const void * v0, const void * v1)
6316 debug_info * info0 = (debug_info *) v0;
6317 debug_info * info1 = (debug_info *) v1;
6318 return info0->addr_base - info1->addr_base;
6321 /* Display the debug_addr section. */
6323 display_debug_addr (struct dwarf_section *section,
6326 debug_info **debug_addr_info;
6327 unsigned char *entry;
6332 if (section->size == 0)
6334 printf (_("\nThe %s section is empty.\n"), section->name);
6338 if (load_debug_info (file) == 0)
6340 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6345 introduce (section, FALSE);
6347 /* PR 17531: file: cf38d01b.
6348 We use xcalloc because a corrupt file may not have initialised all of the
6349 fields in the debug_info structure, which means that the sort below might
6350 try to move uninitialised data. */
6351 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
6352 sizeof (debug_info *));
6355 for (i = 0; i < num_debug_info_entries; i++)
6356 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
6358 /* PR 17531: file: cf38d01b. */
6359 if (debug_information[i].addr_base >= section->size)
6360 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6361 (unsigned long) debug_information[i].addr_base, i);
6363 debug_addr_info [count++] = debug_information + i;
6366 /* Add a sentinel to make iteration convenient. */
6367 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6368 debug_addr_info [count]->addr_base = section->size;
6369 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
6371 for (i = 0; i < count; i++)
6374 unsigned int address_size = debug_addr_info [i]->pointer_size;
6376 printf (_(" For compilation unit at offset 0x%s:\n"),
6377 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
6379 printf (_("\tIndex\tAddress\n"));
6380 entry = section->start + debug_addr_info [i]->addr_base;
6381 end = section->start + debug_addr_info [i + 1]->addr_base;
6385 dwarf_vma base = byte_get (entry, address_size);
6386 printf (_("\t%d:\t"), idx);
6387 print_dwarf_vma (base, address_size);
6389 entry += address_size;
6395 free (debug_addr_info);
6399 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6401 display_debug_str_offsets (struct dwarf_section *section,
6402 void *file ATTRIBUTE_UNUSED)
6404 if (section->size == 0)
6406 printf (_("\nThe %s section is empty.\n"), section->name);
6409 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6410 what the offset size is for this section. */
6414 /* Each debug_information[x].range_lists[y] gets this representation for
6415 sorting purposes. */
6419 /* The debug_information[x].range_lists[y] value. */
6420 dwarf_vma ranges_offset;
6422 /* Original debug_information to find parameters of the data. */
6423 debug_info *debug_info_p;
6426 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6429 range_entry_compar (const void *ap, const void *bp)
6431 const struct range_entry *a_re = (const struct range_entry *) ap;
6432 const struct range_entry *b_re = (const struct range_entry *) bp;
6433 const dwarf_vma a = a_re->ranges_offset;
6434 const dwarf_vma b = b_re->ranges_offset;
6436 return (a > b) - (b > a);
6440 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6441 unsigned int pointer_size, unsigned long offset,
6442 unsigned long base_address)
6444 while (start < finish)
6449 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6450 if (start >= finish)
6452 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6454 printf (" %8.8lx ", offset);
6456 if (begin == 0 && end == 0)
6458 printf (_("<End of list>\n"));
6462 /* Check base address specifiers. */
6463 if (is_max_address (begin, pointer_size)
6464 && !is_max_address (end, pointer_size))
6467 print_dwarf_vma (begin, pointer_size);
6468 print_dwarf_vma (end, pointer_size);
6469 printf ("(base address)\n");
6473 print_dwarf_vma (begin + base_address, pointer_size);
6474 print_dwarf_vma (end + base_address, pointer_size);
6477 fputs (_("(start == end)"), stdout);
6478 else if (begin > end)
6479 fputs (_("(start > end)"), stdout);
6486 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6487 unsigned int pointer_size, unsigned long offset,
6488 unsigned long base_address)
6490 unsigned char *next = start;
6494 unsigned long off = offset + (start - next);
6495 enum dwarf_range_list_entry rlet;
6496 /* Initialize it due to a false compiler warning. */
6497 dwarf_vma begin = -1, length, end = -1;
6498 unsigned int bytes_read;
6500 if (start + 1 > finish)
6502 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6507 printf (" %8.8lx ", off);
6509 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6513 case DW_RLE_end_of_list:
6514 printf (_("<End of list>\n"));
6516 case DW_RLE_base_address:
6517 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6518 print_dwarf_vma (base_address, pointer_size);
6519 printf (_("(base address)\n"));
6521 case DW_RLE_start_length:
6522 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6523 length = read_uleb128 (start, &bytes_read, finish);
6524 start += bytes_read;
6525 end = begin + length;
6527 case DW_RLE_offset_pair:
6528 begin = read_uleb128 (start, &bytes_read, finish);
6529 start += bytes_read;
6530 end = read_uleb128 (start, &bytes_read, finish);
6531 start += bytes_read;
6533 case DW_RLE_start_end:
6534 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6535 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6538 error (_("Invalid range list entry type %d\n"), rlet);
6539 rlet = DW_RLE_end_of_list;
6542 if (rlet == DW_RLE_end_of_list)
6544 if (rlet == DW_RLE_base_address)
6547 print_dwarf_vma (begin + base_address, pointer_size);
6548 print_dwarf_vma (end + base_address, pointer_size);
6551 fputs (_("(start == end)"), stdout);
6552 else if (begin > end)
6553 fputs (_("(start > end)"), stdout);
6560 display_debug_ranges (struct dwarf_section *section,
6561 void *file ATTRIBUTE_UNUSED)
6563 unsigned char *start = section->start;
6564 unsigned char *last_start = start;
6565 unsigned long bytes = section->size;
6566 unsigned char *section_begin = start;
6567 unsigned char *finish = start + bytes;
6568 unsigned int num_range_list, i;
6569 struct range_entry *range_entries, *range_entry_fill;
6570 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6571 /* Initialize it due to a false compiler warning. */
6572 unsigned char address_size = 0;
6576 printf (_("\nThe %s section is empty.\n"), section->name);
6582 dwarf_vma initial_length;
6583 unsigned int initial_length_size;
6584 unsigned char segment_selector_size;
6585 unsigned int offset_size, offset_entry_count;
6586 unsigned short version;
6588 /* Get and check the length of the block. */
6589 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6591 if (initial_length == 0xffffffff)
6593 /* This section is 64-bit DWARF 3. */
6594 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6596 initial_length_size = 12;
6601 initial_length_size = 4;
6604 if (initial_length + initial_length_size > section->size)
6606 /* If the length field has a relocation against it, then we should
6607 not complain if it is inaccurate (and probably negative).
6608 It is copied from .debug_line handling code. */
6609 if (reloc_at (section, (start - section->start) - offset_size))
6611 initial_length = (finish - start) - initial_length_size;
6615 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6616 (long) initial_length);
6621 /* Get and check the version number. */
6622 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6626 warn (_("Only DWARF version 5 debug_rnglists info "
6627 "is currently supported.\n"));
6631 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6633 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6634 if (segment_selector_size != 0)
6636 warn (_("The %s section contains "
6637 "unsupported segment selector size: %d.\n"),
6638 section->name, segment_selector_size);
6642 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6643 if (offset_entry_count != 0)
6645 warn (_("The %s section contains "
6646 "unsupported offset entry count: %u.\n"),
6647 section->name, offset_entry_count);
6652 if (load_debug_info (file) == 0)
6654 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6660 for (i = 0; i < num_debug_info_entries; i++)
6661 num_range_list += debug_information [i].num_range_lists;
6663 if (num_range_list == 0)
6665 /* This can happen when the file was compiled with -gsplit-debug
6666 which removes references to range lists from the primary .o file. */
6667 printf (_("No range lists in .debug_info section.\n"));
6671 range_entries = (struct range_entry *)
6672 xmalloc (sizeof (*range_entries) * num_range_list);
6673 range_entry_fill = range_entries;
6675 for (i = 0; i < num_debug_info_entries; i++)
6677 debug_info *debug_info_p = &debug_information[i];
6680 for (j = 0; j < debug_info_p->num_range_lists; j++)
6682 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6683 range_entry_fill->debug_info_p = debug_info_p;
6688 qsort (range_entries, num_range_list, sizeof (*range_entries),
6689 range_entry_compar);
6691 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6692 warn (_("Range lists in %s section start at 0x%lx\n"),
6693 section->name, (unsigned long) range_entries[0].ranges_offset);
6695 introduce (section, FALSE);
6697 printf (_(" Offset Begin End\n"));
6699 for (i = 0; i < num_range_list; i++)
6701 struct range_entry *range_entry = &range_entries[i];
6702 debug_info *debug_info_p = range_entry->debug_info_p;
6703 unsigned int pointer_size;
6705 unsigned char *next;
6706 dwarf_vma base_address;
6708 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6709 offset = range_entry->ranges_offset;
6710 next = section_begin + offset;
6711 base_address = debug_info_p->base_address;
6713 /* PR 17512: file: 001-101485-0.001:0.1. */
6714 if (pointer_size < 2 || pointer_size > 8)
6716 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6717 pointer_size, (unsigned long) offset);
6721 if (dwarf_check != 0 && i > 0)
6724 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6725 (unsigned long) (start - section_begin),
6726 (unsigned long) (next - section_begin), section->name);
6727 else if (start > next)
6729 if (next == last_start)
6731 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6732 (unsigned long) (start - section_begin),
6733 (unsigned long) (next - section_begin), section->name);
6739 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6740 (start, finish, pointer_size, offset, base_address);
6744 free (range_entries);
6749 typedef struct Frame_Chunk
6751 struct Frame_Chunk *next;
6752 unsigned char *chunk_start;
6754 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6755 short int *col_type;
6758 unsigned int code_factor;
6762 unsigned int cfa_reg;
6763 dwarf_vma cfa_offset;
6765 unsigned char fde_encoding;
6766 unsigned char cfa_exp;
6767 unsigned char ptr_size;
6768 unsigned char segment_size;
6772 static const char *const *dwarf_regnames;
6773 static unsigned int dwarf_regnames_count;
6775 /* A marker for a col_type that means this column was never referenced
6776 in the frame info. */
6777 #define DW_CFA_unreferenced (-1)
6779 /* Return 0 if no more space is needed, 1 if more space is needed,
6780 -1 for invalid reg. */
6783 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6785 unsigned int prev = fc->ncols;
6787 if (reg < (unsigned int) fc->ncols)
6790 if (dwarf_regnames_count
6791 && reg > dwarf_regnames_count)
6794 fc->ncols = reg + 1;
6795 /* PR 17512: file: 10450-2643-0.004.
6796 If reg == -1 then this can happen... */
6800 /* PR 17512: file: 2844a11d. */
6801 if (fc->ncols > 1024)
6803 error (_("Unfeasibly large register number: %u\n"), reg);
6805 /* FIXME: 1024 is an arbitrary limit. Increase it if
6806 we ever encounter a valid binary that exceeds it. */
6810 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6811 sizeof (short int));
6812 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6813 /* PR 17512: file:002-10025-0.005. */
6814 if (fc->col_type == NULL || fc->col_offset == NULL)
6816 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6822 while (prev < fc->ncols)
6824 fc->col_type[prev] = DW_CFA_unreferenced;
6825 fc->col_offset[prev] = 0;
6831 static const char *const dwarf_regnames_i386[] =
6833 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6834 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6835 "eip", "eflags", NULL, /* 8 - 10 */
6836 "st0", "st1", "st2", "st3", /* 11 - 14 */
6837 "st4", "st5", "st6", "st7", /* 15 - 18 */
6838 NULL, NULL, /* 19 - 20 */
6839 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6840 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6841 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6842 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6843 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6844 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6845 "tr", "ldtr", /* 48 - 49 */
6846 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6847 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6848 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6849 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6850 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6851 NULL, NULL, NULL, /* 90 - 92 */
6852 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6855 static const char *const dwarf_regnames_iamcu[] =
6857 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6858 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6859 "eip", "eflags", NULL, /* 8 - 10 */
6860 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6861 NULL, NULL, /* 19 - 20 */
6862 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6863 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6864 NULL, NULL, NULL, /* 37 - 39 */
6865 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6866 "tr", "ldtr", /* 48 - 49 */
6867 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6868 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6869 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6870 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6871 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6872 NULL, NULL, NULL, /* 90 - 92 */
6873 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6877 init_dwarf_regnames_i386 (void)
6879 dwarf_regnames = dwarf_regnames_i386;
6880 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6884 init_dwarf_regnames_iamcu (void)
6886 dwarf_regnames = dwarf_regnames_iamcu;
6887 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6890 static const char *const dwarf_regnames_x86_64[] =
6892 "rax", "rdx", "rcx", "rbx",
6893 "rsi", "rdi", "rbp", "rsp",
6894 "r8", "r9", "r10", "r11",
6895 "r12", "r13", "r14", "r15",
6897 "xmm0", "xmm1", "xmm2", "xmm3",
6898 "xmm4", "xmm5", "xmm6", "xmm7",
6899 "xmm8", "xmm9", "xmm10", "xmm11",
6900 "xmm12", "xmm13", "xmm14", "xmm15",
6901 "st0", "st1", "st2", "st3",
6902 "st4", "st5", "st6", "st7",
6903 "mm0", "mm1", "mm2", "mm3",
6904 "mm4", "mm5", "mm6", "mm7",
6906 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6907 "fs.base", "gs.base", NULL, NULL,
6909 "mxcsr", "fcw", "fsw",
6910 "xmm16", "xmm17", "xmm18", "xmm19",
6911 "xmm20", "xmm21", "xmm22", "xmm23",
6912 "xmm24", "xmm25", "xmm26", "xmm27",
6913 "xmm28", "xmm29", "xmm30", "xmm31",
6914 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6915 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6916 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6917 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6918 NULL, NULL, NULL, /* 115 - 117 */
6919 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6923 init_dwarf_regnames_x86_64 (void)
6925 dwarf_regnames = dwarf_regnames_x86_64;
6926 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6929 static const char *const dwarf_regnames_aarch64[] =
6931 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6932 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6933 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6934 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6935 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6936 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6937 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6938 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6939 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6940 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6941 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6942 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6946 init_dwarf_regnames_aarch64 (void)
6948 dwarf_regnames = dwarf_regnames_aarch64;
6949 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6952 static const char *const dwarf_regnames_s390[] =
6954 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6955 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6956 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6957 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6958 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6959 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6960 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6961 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6962 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6965 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6966 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6970 init_dwarf_regnames_s390 (void)
6972 dwarf_regnames = dwarf_regnames_s390;
6973 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6977 init_dwarf_regnames (unsigned int e_machine)
6982 init_dwarf_regnames_i386 ();
6986 init_dwarf_regnames_iamcu ();
6992 init_dwarf_regnames_x86_64 ();
6996 init_dwarf_regnames_aarch64 ();
7000 init_dwarf_regnames_s390 ();
7009 regname (unsigned int regno, int row)
7011 static char reg[64];
7014 && regno < dwarf_regnames_count
7015 && dwarf_regnames [regno] != NULL)
7018 return dwarf_regnames [regno];
7019 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
7020 dwarf_regnames [regno]);
7023 snprintf (reg, sizeof (reg), "r%d", regno);
7028 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
7033 if (*max_regs != fc->ncols)
7034 *max_regs = fc->ncols;
7036 if (*need_col_headers)
7038 static const char *sloc = " LOC";
7040 *need_col_headers = 0;
7042 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
7044 for (r = 0; r < *max_regs; r++)
7045 if (fc->col_type[r] != DW_CFA_unreferenced)
7050 printf ("%-5s ", regname (r, 1));
7056 print_dwarf_vma (fc->pc_begin, eh_addr_size);
7058 strcpy (tmp, "exp");
7060 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
7061 printf ("%-8s ", tmp);
7063 for (r = 0; r < fc->ncols; r++)
7065 if (fc->col_type[r] != DW_CFA_unreferenced)
7067 switch (fc->col_type[r])
7069 case DW_CFA_undefined:
7072 case DW_CFA_same_value:
7076 sprintf (tmp, "c%+d", fc->col_offset[r]);
7078 case DW_CFA_val_offset:
7079 sprintf (tmp, "v%+d", fc->col_offset[r]);
7081 case DW_CFA_register:
7082 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
7084 case DW_CFA_expression:
7085 strcpy (tmp, "exp");
7087 case DW_CFA_val_expression:
7088 strcpy (tmp, "vexp");
7091 strcpy (tmp, "n/a");
7094 printf ("%-5s ", tmp);
7100 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7102 static unsigned char *
7103 read_cie (unsigned char *start, unsigned char *end,
7104 Frame_Chunk **p_cie, int *p_version,
7105 bfd_size_type *p_aug_len, unsigned char **p_aug)
7109 unsigned int length_return;
7110 unsigned char *augmentation_data = NULL;
7111 bfd_size_type augmentation_data_len = 0;
7114 /* PR 17512: file: 001-228113-0.004. */
7118 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7119 memset (fc, 0, sizeof (Frame_Chunk));
7121 fc->col_type = (short int *) xmalloc (sizeof (short int));
7122 fc->col_offset = (int *) xmalloc (sizeof (int));
7126 fc->augmentation = (char *) start;
7127 /* PR 17512: file: 001-228113-0.004.
7128 Skip past augmentation name, but avoid running off the end of the data. */
7130 if (* start ++ == '\0')
7134 warn (_("No terminator for augmentation name\n"));
7138 if (strcmp (fc->augmentation, "eh") == 0)
7139 start += eh_addr_size;
7143 GET (fc->ptr_size, 1);
7144 if (fc->ptr_size < 1 || fc->ptr_size > 8)
7146 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
7150 GET (fc->segment_size, 1);
7151 /* PR 17512: file: e99d2804. */
7152 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
7154 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
7158 eh_addr_size = fc->ptr_size;
7162 fc->ptr_size = eh_addr_size;
7163 fc->segment_size = 0;
7165 READ_ULEB (fc->code_factor);
7166 READ_SLEB (fc->data_factor);
7176 if (fc->augmentation[0] == 'z')
7178 READ_ULEB (augmentation_data_len);
7179 augmentation_data = start;
7180 /* PR 17512: file: 11042-2589-0.004. */
7181 if (augmentation_data_len > (bfd_size_type) (end - start))
7183 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7184 dwarf_vmatoa ("x", augmentation_data_len),
7185 (unsigned long) (end - start));
7188 start += augmentation_data_len;
7191 if (augmentation_data_len)
7195 unsigned char *qend;
7197 p = (unsigned char *) fc->augmentation + 1;
7198 q = augmentation_data;
7199 qend = q + augmentation_data_len;
7201 while (p < end && q < qend)
7206 q += 1 + size_of_encoded_value (*q);
7208 fc->fde_encoding = *q++;
7215 /* Note - it is OK if this loop terminates with q < qend.
7216 Padding may have been inserted to align the end of the CIE. */
7221 *p_version = version;
7224 *p_aug_len = augmentation_data_len;
7225 *p_aug = augmentation_data;
7230 /* Prints out the contents on the augmentation data array.
7231 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7234 display_augmentation_data (const unsigned char * data, const bfd_size_type len)
7238 i = printf (_(" Augmentation data: "));
7240 if (do_wide || len < ((80 - i) / 3))
7241 for (i = 0; i < len; ++i)
7242 printf (" %02x", data[i]);
7245 for (i = 0; i < len; ++i)
7247 if (i % (80 / 3) == 0)
7249 printf (" %02x", data[i]);
7256 display_debug_frames (struct dwarf_section *section,
7257 void *file ATTRIBUTE_UNUSED)
7259 unsigned char *start = section->start;
7260 unsigned char *end = start + section->size;
7261 unsigned char *section_start = start;
7262 Frame_Chunk *chunks = 0, *forward_refs = 0;
7263 Frame_Chunk *remembered_state = 0;
7265 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7266 unsigned int length_return;
7267 unsigned int max_regs = 0;
7268 const char *bad_reg = _("bad register: ");
7269 unsigned int saved_eh_addr_size = eh_addr_size;
7271 introduce (section, FALSE);
7275 unsigned char *saved_start;
7276 unsigned char *block_end;
7281 int need_col_headers = 1;
7282 unsigned char *augmentation_data = NULL;
7283 bfd_size_type augmentation_data_len = 0;
7284 unsigned int encoded_ptr_size = saved_eh_addr_size;
7285 unsigned int offset_size;
7286 unsigned int initial_length_size;
7287 bfd_boolean all_nops;
7289 saved_start = start;
7291 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
7295 printf ("\n%08lx ZERO terminator\n\n",
7296 (unsigned long)(saved_start - section_start));
7297 /* Skip any zero terminators that directly follow.
7298 A corrupt section size could have loaded a whole
7299 slew of zero filled memory bytes. eg
7300 PR 17512: file: 070-19381-0.004. */
7301 while (start < end && * start == 0)
7306 if (length == 0xffffffff)
7308 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
7310 initial_length_size = 12;
7315 initial_length_size = 4;
7318 block_end = saved_start + length + initial_length_size;
7319 if (block_end > end || block_end < start)
7321 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7322 dwarf_vmatoa_1 (NULL, length, offset_size),
7323 (unsigned long) (saved_start - section_start));
7327 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
7329 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7330 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
7335 start = read_cie (start, end, &cie, &version,
7336 &augmentation_data_len, &augmentation_data);
7337 /* PR 17512: file: 027-135133-0.005. */
7344 fc->chunk_start = saved_start;
7345 mreg = max_regs > 0 ? max_regs - 1 : 0;
7348 if (frame_need_space (fc, mreg) < 0)
7350 if (fc->fde_encoding)
7351 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7353 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7354 print_dwarf_vma (length, fc->ptr_size);
7355 print_dwarf_vma (cie_id, offset_size);
7357 if (do_debug_frames_interp)
7359 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7360 fc->code_factor, fc->data_factor, fc->ra);
7365 printf (" Version: %d\n", version);
7366 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7369 printf (" Pointer Size: %u\n", fc->ptr_size);
7370 printf (" Segment Size: %u\n", fc->segment_size);
7372 printf (" Code alignment factor: %u\n", fc->code_factor);
7373 printf (" Data alignment factor: %d\n", fc->data_factor);
7374 printf (" Return address column: %d\n", fc->ra);
7376 if (augmentation_data_len)
7377 display_augmentation_data (augmentation_data, augmentation_data_len);
7384 unsigned char *look_for;
7385 static Frame_Chunk fde_fc;
7386 unsigned long segment_selector;
7390 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7391 look_for = start - 4 - ((cie_id ^ sign) - sign);
7394 look_for = section_start + cie_id;
7396 if (look_for <= saved_start)
7398 for (cie = chunks; cie ; cie = cie->next)
7399 if (cie->chunk_start == look_for)
7404 for (cie = forward_refs; cie ; cie = cie->next)
7405 if (cie->chunk_start == look_for)
7409 unsigned int off_size;
7410 unsigned char *cie_scan;
7412 cie_scan = look_for;
7414 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7415 if (length == 0xffffffff)
7417 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7424 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7427 : ((off_size == 4 && c_id == DW_CIE_ID)
7428 || (off_size == 8 && c_id == DW64_CIE_ID)))
7433 read_cie (cie_scan, end, &cie, &version,
7434 &augmentation_data_len, &augmentation_data);
7435 /* PR 17512: file: 3450-2098-0.004. */
7438 warn (_("Failed to read CIE information\n"));
7441 cie->next = forward_refs;
7443 cie->chunk_start = look_for;
7444 mreg = max_regs > 0 ? max_regs - 1 : 0;
7447 if (frame_need_space (cie, mreg) < 0)
7449 warn (_("Invalid max register\n"));
7452 if (cie->fde_encoding)
7454 = size_of_encoded_value (cie->fde_encoding);
7461 memset (fc, 0, sizeof (Frame_Chunk));
7465 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7466 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7467 (unsigned long) (saved_start - section_start));
7469 fc->col_type = (short int *) xmalloc (sizeof (short int));
7470 fc->col_offset = (int *) xmalloc (sizeof (int));
7471 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7473 warn (_("Invalid max register\n"));
7477 fc->augmentation = "";
7478 fc->fde_encoding = 0;
7479 fc->ptr_size = eh_addr_size;
7480 fc->segment_size = 0;
7484 fc->ncols = cie->ncols;
7485 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7486 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
7487 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7488 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7489 fc->augmentation = cie->augmentation;
7490 fc->ptr_size = cie->ptr_size;
7491 eh_addr_size = cie->ptr_size;
7492 fc->segment_size = cie->segment_size;
7493 fc->code_factor = cie->code_factor;
7494 fc->data_factor = cie->data_factor;
7495 fc->cfa_reg = cie->cfa_reg;
7496 fc->cfa_offset = cie->cfa_offset;
7498 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7500 warn (_("Invalid max register\n"));
7503 fc->fde_encoding = cie->fde_encoding;
7506 if (fc->fde_encoding)
7507 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7509 segment_selector = 0;
7510 if (fc->segment_size)
7512 if (fc->segment_size > sizeof (segment_selector))
7514 /* PR 17512: file: 9e196b3e. */
7515 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7516 fc->segment_size = 4;
7518 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7521 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
7523 /* FIXME: It appears that sometimes the final pc_range value is
7524 encoded in less than encoded_ptr_size bytes. See the x86_64
7525 run of the "objcopy on compressed debug sections" test for an
7527 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
7529 if (cie->augmentation[0] == 'z')
7531 READ_ULEB (augmentation_data_len);
7532 augmentation_data = start;
7533 start += augmentation_data_len;
7534 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7536 || ((bfd_signed_vma) augmentation_data_len) < 0
7537 || augmentation_data > start)
7539 warn (_("Corrupt augmentation data length: 0x%s\n"),
7540 dwarf_vmatoa ("x", augmentation_data_len));
7542 augmentation_data = NULL;
7543 augmentation_data_len = 0;
7547 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7548 (unsigned long)(saved_start - section_start),
7549 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7550 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7551 (unsigned long)(cie->chunk_start - section_start));
7553 if (fc->segment_size)
7554 printf ("%04lx:", segment_selector);
7557 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7558 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7560 if (! do_debug_frames_interp && augmentation_data_len)
7562 display_augmentation_data (augmentation_data, augmentation_data_len);
7567 /* At this point, fc is the current chunk, cie (if any) is set, and
7568 we're about to interpret instructions for the chunk. */
7569 /* ??? At present we need to do this always, since this sizes the
7570 fc->col_type and fc->col_offset arrays, which we write into always.
7571 We should probably split the interpreted and non-interpreted bits
7572 into two different routines, since there's so much that doesn't
7573 really overlap between them. */
7574 if (1 || do_debug_frames_interp)
7576 /* Start by making a pass over the chunk, allocating storage
7577 and taking note of what registers are used. */
7578 unsigned char *tmp = start;
7580 while (start < block_end)
7582 unsigned int reg, op, opa;
7584 unsigned char * new_start;
7591 /* Warning: if you add any more cases to this switch, be
7592 sure to add them to the corresponding switch below. */
7595 case DW_CFA_advance_loc:
7599 if (frame_need_space (fc, opa) >= 0)
7600 fc->col_type[opa] = DW_CFA_undefined;
7602 case DW_CFA_restore:
7603 if (frame_need_space (fc, opa) >= 0)
7604 fc->col_type[opa] = DW_CFA_undefined;
7606 case DW_CFA_set_loc:
7607 start += encoded_ptr_size;
7609 case DW_CFA_advance_loc1:
7612 case DW_CFA_advance_loc2:
7615 case DW_CFA_advance_loc4:
7618 case DW_CFA_offset_extended:
7619 case DW_CFA_val_offset:
7622 if (frame_need_space (fc, reg) >= 0)
7623 fc->col_type[reg] = DW_CFA_undefined;
7625 case DW_CFA_restore_extended:
7627 if (frame_need_space (fc, reg) >= 0)
7628 fc->col_type[reg] = DW_CFA_undefined;
7630 case DW_CFA_undefined:
7632 if (frame_need_space (fc, reg) >= 0)
7633 fc->col_type[reg] = DW_CFA_undefined;
7635 case DW_CFA_same_value:
7637 if (frame_need_space (fc, reg) >= 0)
7638 fc->col_type[reg] = DW_CFA_undefined;
7640 case DW_CFA_register:
7643 if (frame_need_space (fc, reg) >= 0)
7644 fc->col_type[reg] = DW_CFA_undefined;
7646 case DW_CFA_def_cfa:
7650 case DW_CFA_def_cfa_register:
7653 case DW_CFA_def_cfa_offset:
7656 case DW_CFA_def_cfa_expression:
7658 new_start = start + temp;
7659 if (new_start < start)
7661 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7667 case DW_CFA_expression:
7668 case DW_CFA_val_expression:
7671 new_start = start + temp;
7672 if (new_start < start)
7674 /* PR 17512: file:306-192417-0.005. */
7675 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7680 if (frame_need_space (fc, reg) >= 0)
7681 fc->col_type[reg] = DW_CFA_undefined;
7683 case DW_CFA_offset_extended_sf:
7684 case DW_CFA_val_offset_sf:
7687 if (frame_need_space (fc, reg) >= 0)
7688 fc->col_type[reg] = DW_CFA_undefined;
7690 case DW_CFA_def_cfa_sf:
7694 case DW_CFA_def_cfa_offset_sf:
7697 case DW_CFA_MIPS_advance_loc8:
7700 case DW_CFA_GNU_args_size:
7703 case DW_CFA_GNU_negative_offset_extended:
7706 if (frame_need_space (fc, reg) >= 0)
7707 fc->col_type[reg] = DW_CFA_undefined;
7718 /* Now we know what registers are used, make a second pass over
7719 the chunk, this time actually printing out the info. */
7721 while (start < block_end)
7723 unsigned char * tmp;
7725 unsigned long ul, roffs;
7726 /* Note: It is tempting to use an unsigned long for 'reg' but there
7727 are various functions, notably frame_space_needed() that assume that
7728 reg is an unsigned int. */
7733 const char *reg_prefix = "";
7740 /* Make a note if something other than DW_CFA_nop happens. */
7741 if (op != DW_CFA_nop)
7744 /* Warning: if you add any more cases to this switch, be
7745 sure to add them to the corresponding switch above. */
7748 case DW_CFA_advance_loc:
7749 if (do_debug_frames_interp)
7750 frame_display_row (fc, &need_col_headers, &max_regs);
7752 printf (" DW_CFA_advance_loc: %d to %s\n",
7753 opa * fc->code_factor,
7754 dwarf_vmatoa_1 (NULL,
7755 fc->pc_begin + opa * fc->code_factor,
7757 fc->pc_begin += opa * fc->code_factor;
7762 if (opa >= (unsigned int) fc->ncols)
7763 reg_prefix = bad_reg;
7764 if (! do_debug_frames_interp || *reg_prefix != '\0')
7765 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7766 reg_prefix, regname (opa, 0),
7767 roffs * fc->data_factor);
7768 if (*reg_prefix == '\0')
7770 fc->col_type[opa] = DW_CFA_offset;
7771 fc->col_offset[opa] = roffs * fc->data_factor;
7775 case DW_CFA_restore:
7776 if (opa >= (unsigned int) fc->ncols)
7777 reg_prefix = bad_reg;
7778 if (! do_debug_frames_interp || *reg_prefix != '\0')
7779 printf (" DW_CFA_restore: %s%s\n",
7780 reg_prefix, regname (opa, 0));
7781 if (*reg_prefix != '\0')
7784 if (opa >= (unsigned int) cie->ncols
7785 || (do_debug_frames_interp
7786 && cie->col_type[opa] == DW_CFA_unreferenced))
7788 fc->col_type[opa] = DW_CFA_undefined;
7789 fc->col_offset[opa] = 0;
7793 fc->col_type[opa] = cie->col_type[opa];
7794 fc->col_offset[opa] = cie->col_offset[opa];
7798 case DW_CFA_set_loc:
7799 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7800 if (do_debug_frames_interp)
7801 frame_display_row (fc, &need_col_headers, &max_regs);
7803 printf (" DW_CFA_set_loc: %s\n",
7804 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7808 case DW_CFA_advance_loc1:
7809 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7810 if (do_debug_frames_interp)
7811 frame_display_row (fc, &need_col_headers, &max_regs);
7813 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7814 (unsigned long) (ofs * fc->code_factor),
7815 dwarf_vmatoa_1 (NULL,
7816 fc->pc_begin + ofs * fc->code_factor,
7818 fc->pc_begin += ofs * fc->code_factor;
7821 case DW_CFA_advance_loc2:
7822 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7823 if (do_debug_frames_interp)
7824 frame_display_row (fc, &need_col_headers, &max_regs);
7826 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7827 (unsigned long) (ofs * fc->code_factor),
7828 dwarf_vmatoa_1 (NULL,
7829 fc->pc_begin + ofs * fc->code_factor,
7831 fc->pc_begin += ofs * fc->code_factor;
7834 case DW_CFA_advance_loc4:
7835 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7836 if (do_debug_frames_interp)
7837 frame_display_row (fc, &need_col_headers, &max_regs);
7839 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7840 (unsigned long) (ofs * fc->code_factor),
7841 dwarf_vmatoa_1 (NULL,
7842 fc->pc_begin + ofs * fc->code_factor,
7844 fc->pc_begin += ofs * fc->code_factor;
7847 case DW_CFA_offset_extended:
7850 if (reg >= (unsigned int) fc->ncols)
7851 reg_prefix = bad_reg;
7852 if (! do_debug_frames_interp || *reg_prefix != '\0')
7853 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7854 reg_prefix, regname (reg, 0),
7855 roffs * fc->data_factor);
7856 if (*reg_prefix == '\0')
7858 fc->col_type[reg] = DW_CFA_offset;
7859 fc->col_offset[reg] = roffs * fc->data_factor;
7863 case DW_CFA_val_offset:
7866 if (reg >= (unsigned int) fc->ncols)
7867 reg_prefix = bad_reg;
7868 if (! do_debug_frames_interp || *reg_prefix != '\0')
7869 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7870 reg_prefix, regname (reg, 0),
7871 roffs * fc->data_factor);
7872 if (*reg_prefix == '\0')
7874 fc->col_type[reg] = DW_CFA_val_offset;
7875 fc->col_offset[reg] = roffs * fc->data_factor;
7879 case DW_CFA_restore_extended:
7881 if (reg >= (unsigned int) fc->ncols)
7882 reg_prefix = bad_reg;
7883 if (! do_debug_frames_interp || *reg_prefix != '\0')
7884 printf (" DW_CFA_restore_extended: %s%s\n",
7885 reg_prefix, regname (reg, 0));
7886 if (*reg_prefix != '\0')
7889 if (reg >= (unsigned int) cie->ncols)
7891 fc->col_type[reg] = DW_CFA_undefined;
7892 fc->col_offset[reg] = 0;
7896 fc->col_type[reg] = cie->col_type[reg];
7897 fc->col_offset[reg] = cie->col_offset[reg];
7901 case DW_CFA_undefined:
7903 if (reg >= (unsigned int) fc->ncols)
7904 reg_prefix = bad_reg;
7905 if (! do_debug_frames_interp || *reg_prefix != '\0')
7906 printf (" DW_CFA_undefined: %s%s\n",
7907 reg_prefix, regname (reg, 0));
7908 if (*reg_prefix == '\0')
7910 fc->col_type[reg] = DW_CFA_undefined;
7911 fc->col_offset[reg] = 0;
7915 case DW_CFA_same_value:
7917 if (reg >= (unsigned int) fc->ncols)
7918 reg_prefix = bad_reg;
7919 if (! do_debug_frames_interp || *reg_prefix != '\0')
7920 printf (" DW_CFA_same_value: %s%s\n",
7921 reg_prefix, regname (reg, 0));
7922 if (*reg_prefix == '\0')
7924 fc->col_type[reg] = DW_CFA_same_value;
7925 fc->col_offset[reg] = 0;
7929 case DW_CFA_register:
7932 if (reg >= (unsigned int) fc->ncols)
7933 reg_prefix = bad_reg;
7934 if (! do_debug_frames_interp || *reg_prefix != '\0')
7936 printf (" DW_CFA_register: %s%s in ",
7937 reg_prefix, regname (reg, 0));
7938 puts (regname (roffs, 0));
7940 if (*reg_prefix == '\0')
7942 fc->col_type[reg] = DW_CFA_register;
7943 fc->col_offset[reg] = roffs;
7947 case DW_CFA_remember_state:
7948 if (! do_debug_frames_interp)
7949 printf (" DW_CFA_remember_state\n");
7950 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7951 rs->cfa_offset = fc->cfa_offset;
7952 rs->cfa_reg = fc->cfa_reg;
7954 rs->cfa_exp = fc->cfa_exp;
7955 rs->ncols = fc->ncols;
7956 rs->col_type = (short int *) xcmalloc (rs->ncols,
7957 sizeof (* rs->col_type));
7958 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7959 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7960 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7961 rs->next = remembered_state;
7962 remembered_state = rs;
7965 case DW_CFA_restore_state:
7966 if (! do_debug_frames_interp)
7967 printf (" DW_CFA_restore_state\n");
7968 rs = remembered_state;
7971 remembered_state = rs->next;
7972 fc->cfa_offset = rs->cfa_offset;
7973 fc->cfa_reg = rs->cfa_reg;
7975 fc->cfa_exp = rs->cfa_exp;
7976 if (frame_need_space (fc, rs->ncols - 1) < 0)
7978 warn (_("Invalid column number in saved frame state\n"));
7982 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7983 memcpy (fc->col_offset, rs->col_offset,
7984 rs->ncols * sizeof (* rs->col_offset));
7985 free (rs->col_type);
7986 free (rs->col_offset);
7989 else if (do_debug_frames_interp)
7990 printf ("Mismatched DW_CFA_restore_state\n");
7993 case DW_CFA_def_cfa:
7994 READ_ULEB (fc->cfa_reg);
7995 READ_ULEB (fc->cfa_offset);
7997 if (! do_debug_frames_interp)
7998 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7999 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8002 case DW_CFA_def_cfa_register:
8003 READ_ULEB (fc->cfa_reg);
8005 if (! do_debug_frames_interp)
8006 printf (" DW_CFA_def_cfa_register: %s\n",
8007 regname (fc->cfa_reg, 0));
8010 case DW_CFA_def_cfa_offset:
8011 READ_ULEB (fc->cfa_offset);
8012 if (! do_debug_frames_interp)
8013 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
8017 if (! do_debug_frames_interp)
8018 printf (" DW_CFA_nop\n");
8021 case DW_CFA_def_cfa_expression:
8023 if (start >= block_end || ul > (unsigned long) (block_end - start))
8025 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
8028 if (! do_debug_frames_interp)
8030 printf (" DW_CFA_def_cfa_expression (");
8031 decode_location_expression (start, eh_addr_size, 0, -1,
8039 case DW_CFA_expression:
8042 if (reg >= (unsigned int) fc->ncols)
8043 reg_prefix = bad_reg;
8044 /* PR 17512: file: 069-133014-0.006. */
8045 /* PR 17512: file: 98c02eb4. */
8047 if (start >= block_end || tmp > block_end || tmp < start)
8049 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
8052 if (! do_debug_frames_interp || *reg_prefix != '\0')
8054 printf (" DW_CFA_expression: %s%s (",
8055 reg_prefix, regname (reg, 0));
8056 decode_location_expression (start, eh_addr_size, 0, -1,
8060 if (*reg_prefix == '\0')
8061 fc->col_type[reg] = DW_CFA_expression;
8065 case DW_CFA_val_expression:
8068 if (reg >= (unsigned int) fc->ncols)
8069 reg_prefix = bad_reg;
8071 if (start >= block_end || tmp > block_end || tmp < start)
8073 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
8076 if (! do_debug_frames_interp || *reg_prefix != '\0')
8078 printf (" DW_CFA_val_expression: %s%s (",
8079 reg_prefix, regname (reg, 0));
8080 decode_location_expression (start, eh_addr_size, 0, -1,
8084 if (*reg_prefix == '\0')
8085 fc->col_type[reg] = DW_CFA_val_expression;
8089 case DW_CFA_offset_extended_sf:
8092 if (frame_need_space (fc, reg) < 0)
8093 reg_prefix = bad_reg;
8094 if (! do_debug_frames_interp || *reg_prefix != '\0')
8095 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8096 reg_prefix, regname (reg, 0),
8097 (long)(l * fc->data_factor));
8098 if (*reg_prefix == '\0')
8100 fc->col_type[reg] = DW_CFA_offset;
8101 fc->col_offset[reg] = l * fc->data_factor;
8105 case DW_CFA_val_offset_sf:
8108 if (frame_need_space (fc, reg) < 0)
8109 reg_prefix = bad_reg;
8110 if (! do_debug_frames_interp || *reg_prefix != '\0')
8111 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8112 reg_prefix, regname (reg, 0),
8113 (long)(l * fc->data_factor));
8114 if (*reg_prefix == '\0')
8116 fc->col_type[reg] = DW_CFA_val_offset;
8117 fc->col_offset[reg] = l * fc->data_factor;
8121 case DW_CFA_def_cfa_sf:
8122 READ_ULEB (fc->cfa_reg);
8123 READ_ULEB (fc->cfa_offset);
8124 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
8126 if (! do_debug_frames_interp)
8127 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8128 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
8131 case DW_CFA_def_cfa_offset_sf:
8132 READ_ULEB (fc->cfa_offset);
8133 fc->cfa_offset *= fc->data_factor;
8134 if (! do_debug_frames_interp)
8135 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
8138 case DW_CFA_MIPS_advance_loc8:
8139 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
8140 if (do_debug_frames_interp)
8141 frame_display_row (fc, &need_col_headers, &max_regs);
8143 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8144 (unsigned long) (ofs * fc->code_factor),
8145 dwarf_vmatoa_1 (NULL,
8146 fc->pc_begin + ofs * fc->code_factor,
8148 fc->pc_begin += ofs * fc->code_factor;
8151 case DW_CFA_GNU_window_save:
8152 if (! do_debug_frames_interp)
8153 printf (" DW_CFA_GNU_window_save\n");
8156 case DW_CFA_GNU_args_size:
8158 if (! do_debug_frames_interp)
8159 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8162 case DW_CFA_GNU_negative_offset_extended:
8166 if (frame_need_space (fc, reg) < 0)
8167 reg_prefix = bad_reg;
8168 if (! do_debug_frames_interp || *reg_prefix != '\0')
8169 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8170 reg_prefix, regname (reg, 0),
8171 (long)(l * fc->data_factor));
8172 if (*reg_prefix == '\0')
8174 fc->col_type[reg] = DW_CFA_offset;
8175 fc->col_offset[reg] = l * fc->data_factor;
8180 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
8181 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
8183 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
8188 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8189 if (do_debug_frames_interp && ! all_nops)
8190 frame_display_row (fc, &need_col_headers, &max_regs);
8193 eh_addr_size = saved_eh_addr_size;
8204 display_debug_names (struct dwarf_section *section, void *file)
8206 unsigned char *hdrptr = section->start;
8207 dwarf_vma unit_length;
8208 unsigned char *unit_start;
8209 const unsigned char *const section_end = section->start + section->size;
8210 unsigned char *unit_end;
8212 introduce (section, FALSE);
8214 load_debug_section_with_follow (str, file);
8216 for (; hdrptr < section_end; hdrptr = unit_end)
8218 unsigned int offset_size;
8219 uint16_t dwarf_version, padding;
8220 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8221 uint32_t bucket_count, name_count, abbrev_table_size;
8222 uint32_t augmentation_string_size;
8224 unsigned long sec_off;
8226 unit_start = hdrptr;
8228 /* Get and check the length of the block. */
8229 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8231 if (unit_length == 0xffffffff)
8233 /* This section is 64-bit DWARF. */
8234 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8239 unit_end = hdrptr + unit_length;
8241 sec_off = hdrptr - section->start;
8242 if (sec_off + unit_length < sec_off
8243 || sec_off + unit_length > section->size)
8245 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8247 (unsigned long) (unit_start - section->start),
8248 dwarf_vmatoa ("x", unit_length));
8252 /* Get and check the version number. */
8253 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8254 printf (_("Version %ld\n"), (long) dwarf_version);
8256 /* Prior versions did not exist, and future versions may not be
8257 backwards compatible. */
8258 if (dwarf_version != 5)
8260 warn (_("Only DWARF version 5 .debug_names "
8261 "is currently supported.\n"));
8265 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8267 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8270 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8271 if (comp_unit_count == 0)
8272 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8274 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8275 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8276 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8277 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8278 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8280 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8281 if (augmentation_string_size % 4 != 0)
8283 warn (_("Augmentation string length %u must be rounded up "
8284 "to a multiple of 4 in .debug_names.\n"),
8285 augmentation_string_size);
8286 augmentation_string_size += (-augmentation_string_size) & 3;
8288 printf (_("Augmentation string:"));
8289 for (i = 0; i < augmentation_string_size; i++)
8293 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8294 printf (" %02x", uc);
8299 printf (_("CU table:\n"));
8300 for (i = 0; i < comp_unit_count; i++)
8304 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8305 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8309 printf (_("TU table:\n"));
8310 for (i = 0; i < local_type_unit_count; i++)
8314 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8315 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8319 printf (_("Foreign TU table:\n"));
8320 for (i = 0; i < foreign_type_unit_count; i++)
8324 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8325 printf (_("[%3u] "), i);
8326 print_dwarf_vma (signature, 8);
8331 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8332 hdrptr += bucket_count * sizeof (uint32_t);
8333 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8334 hdrptr += name_count * sizeof (uint32_t);
8335 unsigned char *const name_table_string_offsets = hdrptr;
8336 hdrptr += name_count * offset_size;
8337 unsigned char *const name_table_entry_offsets = hdrptr;
8338 hdrptr += name_count * offset_size;
8339 unsigned char *const abbrev_table = hdrptr;
8340 hdrptr += abbrev_table_size;
8341 const unsigned char *const abbrev_table_end = hdrptr;
8342 unsigned char *const entry_pool = hdrptr;
8343 if (hdrptr > unit_end)
8345 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8346 "for unit 0x%lx in the debug_names\n"),
8347 (long) (hdrptr - section->start),
8348 (long) (unit_end - section->start),
8349 (long) (unit_start - section->start));
8353 size_t buckets_filled = 0;
8355 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8357 const uint32_t bucket = hash_table_buckets[bucketi];
8362 printf (ngettext ("Used %zu of %lu bucket.\n",
8363 "Used %zu of %lu buckets.\n",
8365 buckets_filled, (unsigned long) bucket_count);
8367 uint32_t hash_prev = 0;
8368 size_t hash_clash_count = 0;
8369 size_t longest_clash = 0;
8370 size_t this_length = 0;
8372 for (hashi = 0; hashi < name_count; hashi++)
8374 const uint32_t hash_this = hash_table_hashes[hashi];
8378 if (hash_prev % bucket_count == hash_this % bucket_count)
8382 longest_clash = MAX (longest_clash, this_length);
8387 hash_prev = hash_this;
8389 printf (_("Out of %lu items there are %zu bucket clashes"
8390 " (longest of %zu entries).\n"),
8391 (unsigned long) name_count, hash_clash_count, longest_clash);
8392 assert (name_count == buckets_filled + hash_clash_count);
8394 struct abbrev_lookup_entry
8396 dwarf_vma abbrev_tag;
8397 unsigned char *abbrev_lookup_ptr;
8399 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8400 size_t abbrev_lookup_used = 0;
8401 size_t abbrev_lookup_allocated = 0;
8403 unsigned char *abbrevptr = abbrev_table;
8406 unsigned int bytes_read;
8407 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8409 abbrevptr += bytes_read;
8410 if (abbrev_tag == 0)
8412 if (abbrev_lookup_used == abbrev_lookup_allocated)
8414 abbrev_lookup_allocated = MAX (0x100,
8415 abbrev_lookup_allocated * 2);
8416 abbrev_lookup = xrealloc (abbrev_lookup,
8417 (abbrev_lookup_allocated
8418 * sizeof (*abbrev_lookup)));
8420 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8421 struct abbrev_lookup_entry *entry;
8422 for (entry = abbrev_lookup;
8423 entry < abbrev_lookup + abbrev_lookup_used;
8425 if (entry->abbrev_tag == abbrev_tag)
8427 warn (_("Duplicate abbreviation tag %lu "
8428 "in unit 0x%lx in the debug_names\n"),
8429 (long) abbrev_tag, (long) (unit_start - section->start));
8432 entry = &abbrev_lookup[abbrev_lookup_used++];
8433 entry->abbrev_tag = abbrev_tag;
8434 entry->abbrev_lookup_ptr = abbrevptr;
8436 /* Skip DWARF tag. */
8437 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8438 abbrevptr += bytes_read;
8441 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8444 abbrevptr += bytes_read;
8445 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8447 abbrevptr += bytes_read;
8448 if (xindex == 0 && form == 0)
8453 printf (_("\nSymbol table:\n"));
8455 for (namei = 0; namei < name_count; ++namei)
8457 uint64_t string_offset, entry_offset;
8459 SAFE_BYTE_GET (string_offset,
8460 name_table_string_offsets + namei * offset_size,
8461 offset_size, unit_end);
8462 SAFE_BYTE_GET (entry_offset,
8463 name_table_entry_offsets + namei * offset_size,
8464 offset_size, unit_end);
8466 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8467 fetch_indirect_string (string_offset));
8469 unsigned char *entryptr = entry_pool + entry_offset;
8471 // We need to scan first whether there is a single or multiple
8472 // entries. TAGNO is -2 for the first entry, it is -1 for the
8473 // initial tag read of the second entry, then it becomes 0 for the
8474 // first entry for real printing etc.
8476 /* Initialize it due to a false compiler warning. */
8477 dwarf_vma second_abbrev_tag = -1;
8480 unsigned int bytes_read;
8481 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8483 entryptr += bytes_read;
8486 second_abbrev_tag = abbrev_tag;
8488 entryptr = entry_pool + entry_offset;
8491 if (abbrev_tag == 0)
8495 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8496 (unsigned long) abbrev_tag);
8498 const struct abbrev_lookup_entry *entry;
8499 for (entry = abbrev_lookup;
8500 entry < abbrev_lookup + abbrev_lookup_used;
8502 if (entry->abbrev_tag == abbrev_tag)
8504 if (entry >= abbrev_lookup + abbrev_lookup_used)
8506 warn (_("Undefined abbreviation tag %lu "
8507 "in unit 0x%lx in the debug_names\n"),
8509 (long) (unit_start - section->start));
8512 abbrevptr = entry->abbrev_lookup_ptr;
8513 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8515 abbrevptr += bytes_read;
8517 printf (" %s", get_TAG_name (dwarf_tag));
8520 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8523 abbrevptr += bytes_read;
8524 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8526 abbrevptr += bytes_read;
8527 if (xindex == 0 && form == 0)
8531 printf (" %s", get_IDX_name (xindex));
8532 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8535 dwarf_version, NULL,
8542 printf (_(" <no entries>"));
8546 free (abbrev_lookup);
8553 display_debug_links (struct dwarf_section * section,
8554 void * file ATTRIBUTE_UNUSED)
8556 const unsigned char * filename;
8557 unsigned int filelen;
8559 introduce (section, FALSE);
8561 /* The .gnu_debuglink section is formatted as:
8562 (c-string) Filename.
8563 (padding) If needed to reach a 4 byte boundary.
8564 (uint32_t) CRC32 value.
8566 The .gun_debugaltlink section is formatted as:
8567 (c-string) Filename.
8568 (binary) Build-ID. */
8570 filename = section->start;
8571 filelen = strnlen ((const char *) filename, section->size);
8572 if (filelen == section->size)
8574 warn (_("The debuglink filename is corrupt/missing\n"));
8578 printf (_(" Separate debug info file: %s\n"), filename);
8580 if (const_strneq (section->name, ".gnu_debuglink"))
8583 unsigned int crc_offset;
8585 crc_offset = filelen + 1;
8586 crc_offset = (crc_offset + 3) & ~3;
8587 if (crc_offset + 4 > section->size)
8589 warn (_("CRC offset missing/truncated\n"));
8593 crc32 = byte_get (filename + crc_offset, 4);
8595 printf (_(" CRC value: %#x\n"), crc32);
8597 if (crc_offset + 4 < section->size)
8599 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
8600 (long)(section->size - (crc_offset + 4)));
8604 else /* const_strneq (section->name, ".gnu_debugaltlink") */
8606 const unsigned char * build_id = section->start + filelen + 1;
8607 bfd_size_type build_id_len = section->size - (filelen + 1);
8608 bfd_size_type printed;
8610 /* FIXME: Should we support smaller build-id notes ? */
8611 if (build_id_len < 0x14)
8613 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
8617 printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
8619 if (do_wide || build_id_len < ((80 - printed) / 3))
8620 for (printed = 0; printed < build_id_len; ++printed)
8621 printf (" %02x", build_id[printed]);
8624 for (printed = 0; printed < build_id_len; ++printed)
8626 if (printed % (80 / 3) == 0)
8628 printf (" %02x", build_id[printed]);
8639 display_gdb_index (struct dwarf_section *section,
8640 void *file ATTRIBUTE_UNUSED)
8642 unsigned char *start = section->start;
8644 uint32_t cu_list_offset, tu_list_offset;
8645 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8646 unsigned int cu_list_elements, tu_list_elements;
8647 unsigned int address_table_size, symbol_table_slots;
8648 unsigned char *cu_list, *tu_list;
8649 unsigned char *address_table, *symbol_table, *constant_pool;
8652 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8654 introduce (section, FALSE);
8656 if (section->size < 6 * sizeof (uint32_t))
8658 warn (_("Truncated header in the %s section.\n"), section->name);
8662 version = byte_get_little_endian (start, 4);
8663 printf (_("Version %ld\n"), (long) version);
8665 /* Prior versions are obsolete, and future versions may not be
8666 backwards compatible. */
8667 if (version < 3 || version > 8)
8669 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8673 warn (_("The address table data in version 3 may be wrong.\n"));
8675 warn (_("Version 4 does not support case insensitive lookups.\n"));
8677 warn (_("Version 5 does not include inlined functions.\n"));
8679 warn (_("Version 6 does not include symbol attributes.\n"));
8680 /* Version 7 indices generated by Gold have bad type unit references,
8681 PR binutils/15021. But we don't know if the index was generated by
8682 Gold or not, so to avoid worrying users with gdb-generated indices
8683 we say nothing for version 7 here. */
8685 cu_list_offset = byte_get_little_endian (start + 4, 4);
8686 tu_list_offset = byte_get_little_endian (start + 8, 4);
8687 address_table_offset = byte_get_little_endian (start + 12, 4);
8688 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8689 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8691 if (cu_list_offset > section->size
8692 || tu_list_offset > section->size
8693 || address_table_offset > section->size
8694 || symbol_table_offset > section->size
8695 || constant_pool_offset > section->size)
8697 warn (_("Corrupt header in the %s section.\n"), section->name);
8701 /* PR 17531: file: 418d0a8a. */
8702 if (tu_list_offset < cu_list_offset)
8704 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8705 tu_list_offset, cu_list_offset);
8709 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8711 if (address_table_offset < tu_list_offset)
8713 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8714 address_table_offset, tu_list_offset);
8718 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8720 /* PR 17531: file: 18a47d3d. */
8721 if (symbol_table_offset < address_table_offset)
8723 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8724 symbol_table_offset, address_table_offset);
8728 address_table_size = symbol_table_offset - address_table_offset;
8730 if (constant_pool_offset < symbol_table_offset)
8732 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8733 constant_pool_offset, symbol_table_offset);
8737 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8739 cu_list = start + cu_list_offset;
8740 tu_list = start + tu_list_offset;
8741 address_table = start + address_table_offset;
8742 symbol_table = start + symbol_table_offset;
8743 constant_pool = start + constant_pool_offset;
8745 if (address_table + address_table_size > section->start + section->size)
8747 warn (_("Address table extends beyond end of section.\n"));
8751 printf (_("\nCU table:\n"));
8752 for (i = 0; i < cu_list_elements; i += 2)
8754 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8755 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8757 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8758 (unsigned long) cu_offset,
8759 (unsigned long) (cu_offset + cu_length - 1));
8762 printf (_("\nTU table:\n"));
8763 for (i = 0; i < tu_list_elements; i += 3)
8765 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8766 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8767 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8769 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8770 (unsigned long) tu_offset,
8771 (unsigned long) type_offset);
8772 print_dwarf_vma (signature, 8);
8776 printf (_("\nAddress table:\n"));
8777 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8780 uint64_t low = byte_get_little_endian (address_table + i, 8);
8781 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8782 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8784 print_dwarf_vma (low, 8);
8785 print_dwarf_vma (high, 8);
8786 printf (_("%lu\n"), (unsigned long) cu_index);
8789 printf (_("\nSymbol table:\n"));
8790 for (i = 0; i < symbol_table_slots; ++i)
8792 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8793 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8794 uint32_t num_cus, cu;
8796 if (name_offset != 0
8797 || cu_vector_offset != 0)
8800 unsigned char * adr;
8802 adr = constant_pool + name_offset;
8803 /* PR 17531: file: 5b7b07ad. */
8804 if (adr < constant_pool || adr >= section->start + section->size)
8806 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8807 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8811 printf ("[%3u] %.*s:", i,
8812 (int) (section->size - (constant_pool_offset + name_offset)),
8813 constant_pool + name_offset);
8815 adr = constant_pool + cu_vector_offset;
8816 if (adr < constant_pool || adr >= section->start + section->size - 3)
8818 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8819 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8820 cu_vector_offset, i);
8824 num_cus = byte_get_little_endian (adr, 4);
8826 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8827 if (num_cus * 4 < num_cus
8828 || adr >= section->start + section->size
8829 || adr < constant_pool)
8831 printf ("<invalid number of CUs: %d>\n", num_cus);
8832 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8840 for (j = 0; j < num_cus; ++j)
8843 gdb_index_symbol_kind kind;
8845 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8846 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8847 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8848 cu = GDB_INDEX_CU_VALUE (cu);
8849 /* Convert to TU number if it's for a type unit. */
8850 if (cu >= cu_list_elements / 2)
8851 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8852 (unsigned long) (cu - cu_list_elements / 2));
8854 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8856 printf (" [%s, %s]",
8857 is_static ? _("static") : _("global"),
8858 get_gdb_index_symbol_kind_name (kind));
8870 /* Pre-allocate enough space for the CU/TU sets needed. */
8873 prealloc_cu_tu_list (unsigned int nshndx)
8875 if (shndx_pool == NULL)
8877 shndx_pool_size = nshndx;
8878 shndx_pool_used = 0;
8879 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8880 sizeof (unsigned int));
8884 shndx_pool_size = shndx_pool_used + nshndx;
8885 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8886 sizeof (unsigned int));
8891 add_shndx_to_cu_tu_entry (unsigned int shndx)
8893 if (shndx_pool_used >= shndx_pool_size)
8895 error (_("Internal error: out of space in the shndx pool.\n"));
8898 shndx_pool [shndx_pool_used++] = shndx;
8902 end_cu_tu_entry (void)
8904 if (shndx_pool_used >= shndx_pool_size)
8906 error (_("Internal error: out of space in the shndx pool.\n"));
8909 shndx_pool [shndx_pool_used++] = 0;
8912 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8915 get_DW_SECT_short_name (unsigned int dw_sect)
8917 static char buf[16];
8925 case DW_SECT_ABBREV:
8931 case DW_SECT_STR_OFFSETS:
8933 case DW_SECT_MACINFO:
8941 snprintf (buf, sizeof (buf), "%d", dw_sect);
8945 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8946 These sections are extensions for Fission.
8947 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8950 process_cu_tu_index (struct dwarf_section *section, int do_display)
8952 unsigned char *phdr = section->start;
8953 unsigned char *limit = phdr + section->size;
8954 unsigned char *phash;
8955 unsigned char *pindex;
8956 unsigned char *ppool;
8957 unsigned int version;
8958 unsigned int ncols = 0;
8960 unsigned int nslots;
8963 dwarf_vma signature_high;
8964 dwarf_vma signature_low;
8967 /* PR 17512: file: 002-168123-0.004. */
8970 warn (_("Section %s is empty\n"), section->name);
8973 /* PR 17512: file: 002-376-0.004. */
8974 if (section->size < 24)
8976 warn (_("Section %s is too small to contain a CU/TU header\n"),
8981 SAFE_BYTE_GET (version, phdr, 4, limit);
8983 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8984 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8985 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8988 pindex = phash + nslots * 8;
8989 ppool = pindex + nslots * 4;
8991 /* PR 17531: file: 45d69832. */
8992 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
8994 warn (ngettext ("Section %s is too small for %d slot\n",
8995 "Section %s is too small for %d slots\n",
8997 section->name, nslots);
9003 introduce (section, FALSE);
9005 printf (_(" Version: %d\n"), version);
9007 printf (_(" Number of columns: %d\n"), ncols);
9008 printf (_(" Number of used entries: %d\n"), nused);
9009 printf (_(" Number of slots: %d\n\n"), nslots);
9012 if (ppool > limit || ppool < phdr)
9014 warn (_("Section %s too small for %d hash table entries\n"),
9015 section->name, nslots);
9022 prealloc_cu_tu_list ((limit - ppool) / 4);
9023 for (i = 0; i < nslots; i++)
9025 unsigned char *shndx_list;
9028 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
9029 if (signature_high != 0 || signature_low != 0)
9031 SAFE_BYTE_GET (j, pindex, 4, limit);
9032 shndx_list = ppool + j * 4;
9033 /* PR 17531: file: 705e010d. */
9034 if (shndx_list < ppool)
9036 warn (_("Section index pool located before start of section\n"));
9041 printf (_(" [%3d] Signature: 0x%s Sections: "),
9042 i, dwarf_vmatoa64 (signature_high, signature_low,
9043 buf, sizeof (buf)));
9046 if (shndx_list >= limit)
9048 warn (_("Section %s too small for shndx pool\n"),
9052 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
9056 printf (" %d", shndx);
9058 add_shndx_to_cu_tu_entry (shndx);
9070 else if (version == 2)
9073 unsigned int dw_sect;
9074 unsigned char *ph = phash;
9075 unsigned char *pi = pindex;
9076 unsigned char *poffsets = ppool + ncols * 4;
9077 unsigned char *psizes = poffsets + nused * ncols * 4;
9078 unsigned char *pend = psizes + nused * ncols * 4;
9079 bfd_boolean is_tu_index;
9080 struct cu_tu_set *this_set = NULL;
9082 unsigned char *prow;
9084 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
9086 /* PR 17531: file: 0dd159bf.
9087 Check for wraparound with an overlarge ncols value. */
9088 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
9090 warn (_("Overlarge number of columns: %x\n"), ncols);
9096 warn (_("Section %s too small for offset and size tables\n"),
9103 printf (_(" Offset table\n"));
9104 printf (" slot %-16s ",
9105 is_tu_index ? _("signature") : _("dwo_id"));
9112 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9118 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
9125 for (j = 0; j < ncols; j++)
9127 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9128 printf (" %8s", get_DW_SECT_short_name (dw_sect));
9133 for (i = 0; i < nslots; i++)
9135 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9137 SAFE_BYTE_GET (row, pi, 4, limit);
9140 /* PR 17531: file: a05f6ab3. */
9143 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9149 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
9151 prow = poffsets + (row - 1) * ncols * 4;
9152 /* PR 17531: file: b8ce60a8. */
9153 if (prow < poffsets || prow > limit)
9155 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9161 printf (_(" [%3d] 0x%s"),
9162 i, dwarf_vmatoa64 (signature_high, signature_low,
9163 buf, sizeof (buf)));
9164 for (j = 0; j < ncols; j++)
9166 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9168 printf (" %8d", val);
9171 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9173 /* PR 17531: file: 10796eb3. */
9174 if (dw_sect >= DW_SECT_MAX)
9175 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9177 this_set [row - 1].section_offsets [dw_sect] = val;
9193 printf (_(" Size table\n"));
9194 printf (" slot %-16s ",
9195 is_tu_index ? _("signature") : _("dwo_id"));
9198 for (j = 0; j < ncols; j++)
9200 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
9202 printf (" %8s", get_DW_SECT_short_name (val));
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 prow = psizes + (row - 1) * ncols * 4;
9218 printf (_(" [%3d] 0x%s"),
9219 i, dwarf_vmatoa64 (signature_high, signature_low,
9220 buf, sizeof (buf)));
9222 for (j = 0; j < ncols; j++)
9224 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
9226 printf (" %8d", val);
9229 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
9230 if (dw_sect >= DW_SECT_MAX)
9231 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9233 this_set [row - 1].section_sizes [dw_sect] = val;
9245 else if (do_display)
9246 printf (_(" Unsupported version (%d)\n"), version);
9254 /* Load the CU and TU indexes if present. This will build a list of
9255 section sets that we can use to associate a .debug_info.dwo section
9256 with its associated .debug_abbrev.dwo section in a .dwp file. */
9259 load_cu_tu_indexes (void *file)
9261 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
9263 /* If we have already loaded (or tried to load) the CU and TU indexes
9264 then do not bother to repeat the task. */
9265 if (cu_tu_indexes_read == -1)
9267 cu_tu_indexes_read = TRUE;
9269 if (load_debug_section_with_follow (dwp_cu_index, file))
9270 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
9271 cu_tu_indexes_read = FALSE;
9273 if (load_debug_section_with_follow (dwp_tu_index, file))
9274 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
9275 cu_tu_indexes_read = FALSE;
9278 return (bfd_boolean) cu_tu_indexes_read;
9281 /* Find the set of sections that includes section SHNDX. */
9284 find_cu_tu_set (void *file, unsigned int shndx)
9288 if (! load_cu_tu_indexes (file))
9291 /* Find SHNDX in the shndx pool. */
9292 for (i = 0; i < shndx_pool_used; i++)
9293 if (shndx_pool [i] == shndx)
9296 if (i >= shndx_pool_used)
9299 /* Now backup to find the first entry in the set. */
9300 while (i > 0 && shndx_pool [i - 1] != 0)
9303 return shndx_pool + i;
9306 /* Display a .debug_cu_index or .debug_tu_index section. */
9309 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9311 return process_cu_tu_index (section, 1);
9315 display_debug_not_supported (struct dwarf_section *section,
9316 void *file ATTRIBUTE_UNUSED)
9318 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9324 /* Like malloc, but takes two parameters like calloc.
9325 Verifies that the first parameter is not too large.
9326 Note: does *not* initialise the allocated memory to zero. */
9329 cmalloc (size_t nmemb, size_t size)
9331 /* Check for overflow. */
9332 if (nmemb >= ~(size_t) 0 / size)
9335 return xmalloc (nmemb * size);
9338 /* Like xmalloc, but takes two parameters like calloc.
9339 Verifies that the first parameter is not too large.
9340 Note: does *not* initialise the allocated memory to zero. */
9343 xcmalloc (size_t nmemb, size_t size)
9345 /* Check for overflow. */
9346 if (nmemb >= ~(size_t) 0 / size)
9349 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9354 return xmalloc (nmemb * size);
9357 /* Like xrealloc, but takes three parameters.
9358 Verifies that the second parameter is not too large.
9359 Note: does *not* initialise any new memory to zero. */
9362 xcrealloc (void *ptr, size_t nmemb, size_t size)
9364 /* Check for overflow. */
9365 if (nmemb >= ~(size_t) 0 / size)
9367 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9372 return xrealloc (ptr, nmemb * size);
9375 /* Like xcalloc, but verifies that the first parameter is not too large. */
9378 xcalloc2 (size_t nmemb, size_t size)
9380 /* Check for overflow. */
9381 if (nmemb >= ~(size_t) 0 / size)
9383 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9388 return xcalloc (nmemb, size);
9391 static unsigned long
9392 calc_gnu_debuglink_crc32 (unsigned long crc,
9393 const unsigned char * buf,
9396 static const unsigned long crc32_table[256] =
9398 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9399 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9400 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9401 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9402 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9403 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9404 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9405 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9406 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9407 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9408 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9409 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9410 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9411 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9412 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9413 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9414 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9415 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9416 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9417 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9418 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9419 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9420 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9421 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9422 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9423 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9424 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9425 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9426 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9427 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9428 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9429 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9430 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9431 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9432 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9433 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
9434 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
9435 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
9436 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
9437 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
9438 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
9439 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
9440 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
9441 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
9442 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
9443 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
9444 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
9445 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
9446 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
9447 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
9448 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
9451 const unsigned char *end;
9453 crc = ~crc & 0xffffffff;
9454 for (end = buf + len; buf < end; ++ buf)
9455 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
9456 return ~crc & 0xffffffff;
9459 typedef bfd_boolean (* check_func_type) (const char *, void *);
9460 typedef const char * (* parse_func_type) (struct dwarf_section *, void *);
9463 check_gnu_debuglink (const char * pathname, void * crc_pointer)
9465 static unsigned char buffer [8 * 1024];
9467 bfd_size_type count;
9468 unsigned long crc = 0;
9471 sep_data = open_debug_file (pathname);
9472 if (sep_data == NULL)
9475 /* Yes - we are opening the file twice... */
9476 f = fopen (pathname, "rb");
9479 /* Paranoia: This should never happen. */
9480 close_debug_file (sep_data);
9481 warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
9485 while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
9486 crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
9490 if (crc != * (unsigned long *) crc_pointer)
9492 close_debug_file (sep_data);
9493 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
9502 parse_gnu_debuglink (struct dwarf_section * section, void * data)
9505 unsigned int crc_offset;
9506 unsigned long * crc32 = (unsigned long *) data;
9508 /* The name is first.
9509 The CRC value is stored after the filename, aligned up to 4 bytes. */
9510 name = (const char *) section->start;
9512 crc_offset = strnlen (name, section->size) + 1;
9513 crc_offset = (crc_offset + 3) & ~3;
9514 if (crc_offset + 4 > section->size)
9517 * crc32 = byte_get (section->start + crc_offset, 4);
9522 check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
9524 void * sep_data = open_debug_file (filename);
9526 if (sep_data == NULL)
9529 /* FIXME: We should now extract the build-id in the separate file
9535 typedef struct build_id_data
9538 const unsigned char * data;
9542 parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
9545 bfd_size_type namelen;
9546 bfd_size_type id_len;
9547 Build_id_data * build_id_data;
9549 /* The name is first.
9550 The build-id follows immediately, with no padding, up to the section's end. */
9552 name = (const char *) section->start;
9553 namelen = strnlen (name, section->size) + 1;
9554 if (namelen >= section->size)
9557 id_len = section->size - namelen;
9561 build_id_data = calloc (1, sizeof * build_id_data);
9562 if (build_id_data == NULL)
9565 build_id_data->len = id_len;
9566 build_id_data->data = section->start + namelen;
9568 * (Build_id_data **) data = build_id_data;
9574 load_separate_debug_info (const char * main_filename,
9575 struct dwarf_section * link,
9576 parse_func_type parse_func,
9577 check_func_type check_func,
9580 const char * separate_filename;
9583 size_t canon_dirlen;
9586 if ((separate_filename = parse_func (link, func_data)) == NULL)
9588 warn (_("Corrupt debuglink section: %s\n"),
9589 link->name ? link->name : link->uncompressed_name);
9593 /* Attempt to locate the separate file.
9594 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
9596 canon_dir = lrealpath (main_filename);
9598 for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
9599 if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
9601 canon_dir[canon_dirlen] = '\0';
9604 #define DEBUGDIR "/lib/debug"
9606 #ifndef EXTRA_DEBUG_ROOT1
9607 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
9609 #ifndef EXTRA_DEBUG_ROOT2
9610 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
9613 debugfile = (char *) malloc (strlen (DEBUGDIR) + 1
9615 + strlen (".debug/")
9616 #ifdef EXTRA_DEBUG_ROOT1
9617 + strlen (EXTRA_DEBUG_ROOT1)
9619 #ifdef EXTRA_DEBUG_ROOT2
9620 + strlen (EXTRA_DEBUG_ROOT2)
9622 + strlen (separate_filename)
9624 if (debugfile == NULL)
9626 warn (_("Out of memory"));
9630 /* First try in the current directory. */
9631 sprintf (debugfile, "%s", separate_filename);
9632 if (check_func (debugfile, func_data))
9635 /* Then try in a subdirectory called .debug. */
9636 sprintf (debugfile, ".debug/%s", separate_filename);
9637 if (check_func (debugfile, func_data))
9640 /* Then try in the same directory as the original file. */
9641 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9642 if (check_func (debugfile, func_data))
9645 /* And the .debug subdirectory of that directory. */
9646 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9647 if (check_func (debugfile, func_data))
9650 #ifdef EXTRA_DEBUG_ROOT1
9651 /* Try the first extra debug file root. */
9652 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9653 if (check_func (debugfile, func_data))
9657 #ifdef EXTRA_DEBUG_ROOT2
9658 /* Try the second extra debug file root. */
9659 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9660 if (check_func (debugfile, func_data))
9664 /* Then try in the global debugfile directory. */
9665 strcpy (debugfile, DEBUGDIR);
9666 dirlen = strlen (DEBUGDIR) - 1;
9667 if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
9668 strcat (debugfile, "/");
9669 strcat (debugfile, (const char *) separate_filename);
9671 if (check_func (debugfile, func_data))
9674 /* Failed to find the file. */
9675 warn (_("could not find separate debug file '%s'\n"), separate_filename);
9676 warn (_("tried: %s\n"), debugfile);
9678 #ifdef EXTRA_DEBUG_ROOT2
9679 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9680 warn (_("tried: %s\n"), debugfile);
9683 #ifdef EXTRA_DEBUG_ROOT1
9684 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9685 warn (_("tried: %s\n"), debugfile);
9688 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9689 warn (_("tried: %s\n"), debugfile);
9691 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9692 warn (_("tried: %s\n"), debugfile);
9694 sprintf (debugfile, ".debug/%s", separate_filename);
9695 warn (_("tried: %s\n"), debugfile);
9697 sprintf (debugfile, "%s", separate_filename);
9698 warn (_("tried: %s\n"), debugfile);
9707 /* Now open the file.... */
9708 if ((separate_debug_file = open_debug_file (debugfile)) == NULL)
9710 warn (_("failed to open separate debug file: %s\n"), debugfile);
9715 /* FIXME: We do not check to see if there are any other separate debug info
9716 files that would also match. */
9718 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debugfile);
9719 separate_debug_filename = debugfile;
9721 /* Do not free debugfile - it might be referenced inside
9722 the structure returned by open_debug_file(). */
9723 return separate_debug_file;
9726 /* Load a separate debug info file, if it exists.
9727 Returns the data pointer that is the result of calling open_debug_file
9728 on the separate debug info file. */
9731 load_separate_debug_file (void * file, const char * filename)
9733 if (! do_follow_links)
9736 /* FIXME: We do not check for the presence of both link sections in the same file. */
9737 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
9738 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
9740 /* We try the alt version first as that is blessed by the DWARF5 standard. */
9741 if (load_debug_section (gnu_debugaltlink, file))
9743 Build_id_data * build_id_data;
9745 return load_separate_debug_info (filename,
9746 & debug_displays[gnu_debugaltlink].section,
9747 parse_gnu_debugaltlink,
9748 check_gnu_debugaltlink,
9752 if (load_debug_section (gnu_debuglink, file))
9754 unsigned long crc32;
9756 return load_separate_debug_info (filename,
9757 & debug_displays[gnu_debuglink].section,
9758 parse_gnu_debuglink,
9759 check_gnu_debuglink,
9763 do_follow_links = 0;
9768 free_debug_memory (void)
9774 for (i = 0; i < max; i++)
9775 free_debug_section ((enum dwarf_section_display_enum) i);
9777 if (debug_information != NULL)
9779 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
9781 for (i = 0; i < num_debug_info_entries; i++)
9783 if (!debug_information [i].max_loc_offsets)
9785 free (debug_information [i].loc_offsets);
9786 free (debug_information [i].have_frame_base);
9788 if (!debug_information [i].max_range_lists)
9789 free (debug_information [i].range_lists);
9792 free (debug_information);
9793 debug_information = NULL;
9794 alloc_num_debug_info_entries = num_debug_info_entries = 0;
9797 if (separate_debug_file != NULL)
9799 close_debug_file (separate_debug_file);
9800 separate_debug_file = NULL;
9802 free ((void *) separate_debug_filename);
9803 separate_debug_filename = NULL;
9808 dwarf_select_sections_by_names (const char *names)
9812 const char * option;
9816 debug_dump_long_opts;
9818 static const debug_dump_long_opts opts_table [] =
9820 /* Please keep this table alpha- sorted. */
9821 { "Ranges", & do_debug_ranges, 1 },
9822 { "abbrev", & do_debug_abbrevs, 1 },
9823 { "addr", & do_debug_addr, 1 },
9824 { "aranges", & do_debug_aranges, 1 },
9825 { "cu_index", & do_debug_cu_index, 1 },
9826 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
9827 { "follow-links", & do_follow_links, 1 },
9828 { "frames", & do_debug_frames, 1 },
9829 { "frames-interp", & do_debug_frames_interp, 1 },
9830 /* The special .gdb_index section. */
9831 { "gdb_index", & do_gdb_index, 1 },
9832 { "info", & do_debug_info, 1 },
9833 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
9834 { "links", & do_debug_links, 1 },
9835 { "loc", & do_debug_loc, 1 },
9836 { "macro", & do_debug_macinfo, 1 },
9837 { "pubnames", & do_debug_pubnames, 1 },
9838 { "pubtypes", & do_debug_pubtypes, 1 },
9839 /* This entry is for compatibility
9840 with earlier versions of readelf. */
9841 { "ranges", & do_debug_aranges, 1 },
9842 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
9843 { "str", & do_debug_str, 1 },
9844 /* These trace_* sections are used by Itanium VMS. */
9845 { "trace_abbrev", & do_trace_abbrevs, 1 },
9846 { "trace_aranges", & do_trace_aranges, 1 },
9847 { "trace_info", & do_trace_info, 1 },
9856 const debug_dump_long_opts * entry;
9858 for (entry = opts_table; entry->option; entry++)
9860 size_t len = strlen (entry->option);
9862 if (strncmp (p, entry->option, len) == 0
9863 && (p[len] == ',' || p[len] == '\0'))
9865 * entry->variable |= entry->val;
9867 /* The --debug-dump=frames-interp option also
9868 enables the --debug-dump=frames option. */
9869 if (do_debug_frames_interp)
9870 do_debug_frames = 1;
9877 if (entry->option == NULL)
9879 warn (_("Unrecognized debug option '%s'\n"), p);
9880 p = strchr (p, ',');
9891 dwarf_select_sections_by_letters (const char *letters)
9893 unsigned int lindex = 0;
9895 while (letters[lindex])
9896 switch (letters[lindex++])
9898 case 'A': do_debug_addr = 1; break;
9899 case 'a': do_debug_abbrevs = 1; break;
9900 case 'c': do_debug_cu_index = 1; break;
9901 case 'F': do_debug_frames_interp = 1; /* Fall through. */
9902 case 'f': do_debug_frames = 1; break;
9903 case 'g': do_gdb_index = 1; break;
9904 case 'i': do_debug_info = 1; break;
9905 case 'K': do_follow_links = 1; break;
9906 case 'k': do_debug_links = 1; break;
9907 case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
9908 case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
9909 case 'm': do_debug_macinfo = 1; break;
9910 case 'o': do_debug_loc = 1; break;
9911 case 'p': do_debug_pubnames = 1; break;
9912 case 'R': do_debug_ranges = 1; break;
9913 case 'r': do_debug_aranges = 1; break;
9914 case 's': do_debug_str = 1; break;
9915 case 'T': do_trace_aranges = 1; break;
9916 case 't': do_debug_pubtypes = 1; break;
9917 case 'U': do_trace_info = 1; break;
9918 case 'u': do_trace_abbrevs = 1; break;
9921 warn (_("Unrecognized debug option '%s'\n"), letters);
9927 dwarf_select_sections_all (void)
9930 do_debug_abbrevs = 1;
9931 do_debug_lines = FLAG_DEBUG_LINES_RAW;
9932 do_debug_pubnames = 1;
9933 do_debug_pubtypes = 1;
9934 do_debug_aranges = 1;
9935 do_debug_ranges = 1;
9936 do_debug_frames = 1;
9937 do_debug_macinfo = 1;
9942 do_trace_abbrevs = 1;
9943 do_trace_aranges = 1;
9945 do_debug_cu_index = 1;
9946 do_follow_links = 1;
9950 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
9951 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
9953 /* N.B. The order here must match the order in section_display_enum. */
9955 struct dwarf_section_display debug_displays[] =
9957 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
9958 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE },
9959 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
9960 { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE },
9961 { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
9962 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE },
9963 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
9964 { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
9965 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
9966 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
9967 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
9968 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
9969 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9970 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9971 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE },
9972 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
9973 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
9974 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
9975 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9976 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9977 { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE },
9978 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9979 { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE },
9980 { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE },
9981 { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE },
9982 { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE },
9983 { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE },
9984 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE },
9985 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
9986 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE },
9987 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
9988 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9989 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
9990 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
9991 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE },
9992 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
9993 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
9994 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE },
9995 { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
9996 { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
9997 { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
9998 { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
9999 /* Separate debug info files can containt their own .debug_str section,
10000 and this might be in *addition* to a .debug_str section already present
10001 in the main file. Hence we need to have two entries for .debug_str. */
10002 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
10005 /* A static assertion. */
10006 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];