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"
35 #define MAX(a, b) ((a) > (b) ? (a) : (b))
36 #define MIN(a, b) ((a) < (b) ? (a) : (b))
38 static const char *regname (unsigned int regno, int row);
40 static int have_frame_base;
41 static int need_base_address;
43 static unsigned int last_pointer_size = 0;
44 static int warned_about_missing_comp_units = FALSE;
46 static unsigned int num_debug_info_entries = 0;
47 static unsigned int alloc_num_debug_info_entries = 0;
48 static debug_info *debug_information = NULL;
49 /* Special value for num_debug_info_entries to indicate
50 that the .debug_info section could not be loaded/parsed. */
51 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
53 unsigned int eh_addr_size;
58 int do_debug_pubnames;
59 int do_debug_pubtypes;
63 int do_debug_frames_interp;
72 int do_debug_cu_index;
75 int dwarf_cutoff_level = -1;
76 unsigned long dwarf_start_die;
80 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
81 sections. For version 1 package files, each set is stored in SHNDX_POOL
82 as a zero-terminated list of section indexes comprising one set of debug
83 sections from a .dwo file. */
85 static unsigned int *shndx_pool = NULL;
86 static unsigned int shndx_pool_size = 0;
87 static unsigned int shndx_pool_used = 0;
89 /* For version 2 package files, each set contains an array of section offsets
90 and an array of section sizes, giving the offset and size of the
91 contribution from a CU or TU within one of the debug sections.
92 When displaying debug info from a package file, we need to use these
93 tables to locate the corresponding contributions to each section. */
98 dwarf_vma section_offsets[DW_SECT_MAX];
99 size_t section_sizes[DW_SECT_MAX];
102 static int cu_count = 0;
103 static int tu_count = 0;
104 static struct cu_tu_set *cu_sets = NULL;
105 static struct cu_tu_set *tu_sets = NULL;
107 static bfd_boolean load_cu_tu_indexes (void *);
109 /* Values for do_debug_lines. */
110 #define FLAG_DEBUG_LINES_RAW 1
111 #define FLAG_DEBUG_LINES_DECODED 2
114 size_of_encoded_value (int encoding)
116 switch (encoding & 0x7)
119 case 0: return eh_addr_size;
127 get_encoded_value (unsigned char **pdata,
129 struct dwarf_section *section,
132 unsigned char * data = * pdata;
133 unsigned int size = size_of_encoded_value (encoding);
136 if (data + size >= end)
138 warn (_("Encoded value extends past end of section\n"));
143 /* PR 17512: file: 002-829853-0.004. */
146 warn (_("Encoded size of %d is too large to read\n"), size);
151 /* PR 17512: file: 1085-5603-0.004. */
154 warn (_("Encoded size of 0 is too small to read\n"));
159 if (encoding & DW_EH_PE_signed)
160 val = byte_get_signed (data, size);
162 val = byte_get (data, size);
164 if ((encoding & 0x70) == DW_EH_PE_pcrel)
165 val += section->address + (data - section->start);
167 * pdata = data + size;
171 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
173 # define DWARF_VMA_FMT "ll"
174 # define DWARF_VMA_FMT_LONG "%16.16llx"
176 # define DWARF_VMA_FMT "I64"
177 # define DWARF_VMA_FMT_LONG "%016I64x"
180 # define DWARF_VMA_FMT "l"
181 # define DWARF_VMA_FMT_LONG "%16.16lx"
184 /* Convert a dwarf vma value into a string. Returns a pointer to a static
185 buffer containing the converted VALUE. The value is converted according
186 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
187 it specifies the maximum number of bytes to be displayed in the converted
188 value and FMTCH is ignored - hex is always used. */
191 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
193 /* As dwarf_vmatoa is used more then once in a printf call
194 for output, we are cycling through an fixed array of pointers
195 for return address. */
196 static int buf_pos = 0;
197 static struct dwarf_vmatoa_buf
203 ret = buf[buf_pos++].place;
204 buf_pos %= ARRAY_SIZE (buf);
208 /* Printf does not have a way of specifying a maximum field width for an
209 integer value, so we print the full value into a buffer and then select
210 the precision we need. */
211 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
214 return ret + (16 - 2 * num_bytes);
220 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
221 snprintf (ret, sizeof (buf[0].place), fmt, value);
226 static inline const char *
227 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
229 return dwarf_vmatoa_1 (fmtch, value, 0);
232 /* Print a dwarf_vma value (typically an address, offset or length) in
233 hexadecimal format, followed by a space. The length of the VALUE (and
234 hence the precision displayed) is determined by the NUM_BYTES parameter. */
237 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
239 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
242 /* Format a 64-bit value, given as two 32-bit values, in hex.
243 For reentrancy, this uses a buffer provided by the caller. */
246 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
247 unsigned int buf_len)
252 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
255 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
256 snprintf (buf + len, buf_len - len,
257 "%08" DWARF_VMA_FMT "x", lvalue);
263 /* Read in a LEB128 encoded value starting at address DATA.
264 If SIGN is true, return a signed LEB128 value.
265 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
266 No bytes will be read at address END or beyond. */
269 read_leb128 (unsigned char *data,
270 unsigned int *length_return,
272 const unsigned char * const end)
274 dwarf_vma result = 0;
275 unsigned int num_read = 0;
276 unsigned int shift = 0;
277 unsigned char byte = 0;
284 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
287 if ((byte & 0x80) == 0)
290 /* PR 17512: file: 0ca183b8.
291 FIXME: Should we signal this error somehow ? */
292 if (shift >= sizeof (result) * 8)
296 if (length_return != NULL)
297 *length_return = num_read;
299 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
300 result |= -((dwarf_vma) 1 << shift);
305 /* Create a signed version to avoid painful typecasts. */
306 static inline dwarf_signed_vma
307 read_sleb128 (unsigned char * data,
308 unsigned int * length_return,
309 const unsigned char * const end)
311 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
314 static inline dwarf_vma
315 read_uleb128 (unsigned char * data,
316 unsigned int * length_return,
317 const unsigned char * const end)
319 return read_leb128 (data, length_return, FALSE, end);
322 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
323 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
325 #define READ_ULEB(var) \
330 (var) = _val = read_uleb128 (start, &length_return, end); \
332 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
333 __FILE__, __LINE__, _val); \
334 start += length_return; \
338 #define READ_SLEB(var) \
341 dwarf_signed_vma _val; \
343 (var) = _val = read_sleb128 (start, &length_return, end); \
345 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
346 __FILE__, __LINE__, _val); \
347 start += length_return; \
351 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
354 unsigned int amount = (AMOUNT); \
355 if (sizeof (VAL) < amount) \
357 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
358 amount, (int) sizeof (VAL)); \
359 amount = sizeof (VAL); \
361 if (((PTR) + amount) >= (END)) \
364 amount = (END) - (PTR); \
368 if (amount == 0 || amount > 8) \
371 VAL = byte_get ((PTR), amount); \
375 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
378 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
383 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
386 unsigned int amount = (AMOUNT); \
387 if (((PTR) + amount) >= (END)) \
390 amount = (END) - (PTR); \
395 VAL = byte_get_signed ((PTR), amount); \
401 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
404 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
409 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
412 if (((PTR) + 8) <= (END)) \
414 byte_get_64 ((PTR), (HIGH), (LOW)); \
418 * (LOW) = * (HIGH) = 0; \
423 typedef struct State_Machine_Registers
431 unsigned char op_index;
432 unsigned char end_sequence;
433 /* This variable hold the number of the last entry seen
434 in the File Table. */
435 unsigned int last_file_entry;
438 static SMR state_machine_regs;
441 reset_state_machine (int is_stmt)
443 state_machine_regs.address = 0;
444 state_machine_regs.op_index = 0;
445 state_machine_regs.file = 1;
446 state_machine_regs.line = 1;
447 state_machine_regs.column = 0;
448 state_machine_regs.is_stmt = is_stmt;
449 state_machine_regs.basic_block = 0;
450 state_machine_regs.end_sequence = 0;
451 state_machine_regs.last_file_entry = 0;
454 /* Handled an extend line op.
455 Returns the number of bytes read. */
458 process_extended_line_op (unsigned char * data,
462 unsigned char op_code;
463 unsigned int bytes_read;
466 unsigned char *orig_data = data;
469 len = read_uleb128 (data, & bytes_read, end);
472 if (len == 0 || data == end || len > (uintptr_t) (end - data))
474 warn (_("Badly formed extended line op encountered!\n"));
481 printf (_(" Extended opcode %d: "), op_code);
485 case DW_LNE_end_sequence:
486 printf (_("End of Sequence\n\n"));
487 reset_state_machine (is_stmt);
490 case DW_LNE_set_address:
491 /* PR 17512: file: 002-100480-0.004. */
492 if (len - bytes_read - 1 > 8)
494 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
495 len - bytes_read - 1);
499 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
500 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
501 state_machine_regs.address = adr;
502 state_machine_regs.op_index = 0;
505 case DW_LNE_define_file:
506 printf (_("define new File Table entry\n"));
507 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
508 printf (" %d\t", ++state_machine_regs.last_file_entry);
514 l = strnlen ((char *) data, end - data);
516 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
518 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
520 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
522 printf ("%.*s\n\n", (int) l, name);
525 if (((unsigned int) (data - orig_data) != len) || data == end)
526 warn (_("DW_LNE_define_file: Bad opcode length\n"));
529 case DW_LNE_set_discriminator:
530 printf (_("set Discriminator to %s\n"),
531 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
535 case DW_LNE_HP_negate_is_UV_update:
536 printf ("DW_LNE_HP_negate_is_UV_update\n");
538 case DW_LNE_HP_push_context:
539 printf ("DW_LNE_HP_push_context\n");
541 case DW_LNE_HP_pop_context:
542 printf ("DW_LNE_HP_pop_context\n");
544 case DW_LNE_HP_set_file_line_column:
545 printf ("DW_LNE_HP_set_file_line_column\n");
547 case DW_LNE_HP_set_routine_name:
548 printf ("DW_LNE_HP_set_routine_name\n");
550 case DW_LNE_HP_set_sequence:
551 printf ("DW_LNE_HP_set_sequence\n");
553 case DW_LNE_HP_negate_post_semantics:
554 printf ("DW_LNE_HP_negate_post_semantics\n");
556 case DW_LNE_HP_negate_function_exit:
557 printf ("DW_LNE_HP_negate_function_exit\n");
559 case DW_LNE_HP_negate_front_end_logical:
560 printf ("DW_LNE_HP_negate_front_end_logical\n");
562 case DW_LNE_HP_define_proc:
563 printf ("DW_LNE_HP_define_proc\n");
565 case DW_LNE_HP_source_file_correlation:
567 unsigned char *edata = data + len - bytes_read - 1;
569 printf ("DW_LNE_HP_source_file_correlation\n");
575 opc = read_uleb128 (data, & bytes_read, edata);
580 case DW_LNE_HP_SFC_formfeed:
581 printf (" DW_LNE_HP_SFC_formfeed\n");
583 case DW_LNE_HP_SFC_set_listing_line:
584 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
586 read_uleb128 (data, & bytes_read, edata)));
589 case DW_LNE_HP_SFC_associate:
590 printf (" DW_LNE_HP_SFC_associate ");
593 read_uleb128 (data, & bytes_read, edata)));
597 read_uleb128 (data, & bytes_read, edata)));
601 read_uleb128 (data, & bytes_read, edata)));
605 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
615 unsigned int rlen = len - bytes_read - 1;
617 if (op_code >= DW_LNE_lo_user
618 /* The test against DW_LNW_hi_user is redundant due to
619 the limited range of the unsigned char data type used
621 /*&& op_code <= DW_LNE_hi_user*/)
622 printf (_("user defined: "));
624 printf (_("UNKNOWN: "));
625 printf (_("length %d ["), rlen);
627 printf (" %02x", *data++);
636 static const unsigned char *
637 fetch_indirect_string (dwarf_vma offset)
639 struct dwarf_section *section = &debug_displays [str].section;
640 const unsigned char * ret;
642 if (section->start == NULL)
643 return (const unsigned char *) _("<no .debug_str section>");
645 if (offset >= section->size)
647 warn (_("DW_FORM_strp offset too big: %s\n"),
648 dwarf_vmatoa ("x", offset));
649 return (const unsigned char *) _("<offset is too big>");
652 ret = section->start + offset;
653 /* Unfortunately we cannot rely upon the .debug_str section ending with a
654 NUL byte. Since our caller is expecting to receive a well formed C
655 string we test for the lack of a terminating byte here. */
656 if (strnlen ((const char *) ret, section->size - offset)
657 == section->size - offset)
658 ret = (const unsigned char *)
659 _("<no NUL byte at end of .debug_str section>");
664 static const unsigned char *
665 fetch_indirect_line_string (dwarf_vma offset)
667 struct dwarf_section *section = &debug_displays [line_str].section;
668 const unsigned char * ret;
670 if (section->start == NULL)
671 return (const unsigned char *) _("<no .debug_line_str section>");
673 if (offset >= section->size)
675 warn (_("DW_FORM_line_strp offset too big: %s\n"),
676 dwarf_vmatoa ("x", offset));
677 return (const unsigned char *) _("<offset is too big>");
680 ret = section->start + offset;
681 /* Unfortunately we cannot rely upon the .debug_line_str section ending
682 with a NUL byte. Since our caller is expecting to receive a well formed
683 C string we test for the lack of a terminating byte here. */
684 if (strnlen ((const char *) ret, section->size - offset)
685 == section->size - offset)
686 ret = (const unsigned char *)
687 _("<no NUL byte at end of .debug_line_str section>");
693 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
694 dwarf_vma offset_size, int dwo)
696 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
697 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
698 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
699 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
700 dwarf_vma index_offset = idx * offset_size;
701 dwarf_vma str_offset;
704 if (index_section->start == NULL)
705 return (dwo ? _("<no .debug_str_offsets.dwo section>")
706 : _("<no .debug_str_offsets section>"));
708 if (this_set != NULL)
709 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
710 if (index_offset >= index_section->size)
712 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
713 dwarf_vmatoa ("x", index_offset));
714 return _("<index offset is too big>");
717 if (str_section->start == NULL)
718 return (dwo ? _("<no .debug_str.dwo section>")
719 : _("<no .debug_str section>"));
721 str_offset = byte_get (index_section->start + index_offset, offset_size);
722 str_offset -= str_section->address;
723 if (str_offset >= str_section->size)
725 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
726 dwarf_vmatoa ("x", str_offset));
727 return _("<indirect index offset is too big>");
730 ret = (const char *) str_section->start + str_offset;
731 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
732 Since our caller is expecting to receive a well formed C string we test
733 for the lack of a terminating byte here. */
734 if (strnlen (ret, str_section->size - str_offset)
735 == str_section->size - str_offset)
736 ret = (const char *) _("<no NUL byte at end of section>");
742 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
744 struct dwarf_section *section = &debug_displays [debug_addr].section;
746 if (section->start == NULL)
747 return (_("<no .debug_addr section>"));
749 if (offset + bytes > section->size)
751 warn (_("Offset into section %s too big: %s\n"),
752 section->name, dwarf_vmatoa ("x", offset));
753 return "<offset too big>";
756 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
760 /* FIXME: There are better and more efficient ways to handle
761 these structures. For now though, I just want something that
762 is simple to implement. */
763 typedef struct abbrev_attr
765 unsigned long attribute;
767 bfd_signed_vma implicit_const;
768 struct abbrev_attr *next;
772 typedef struct abbrev_entry
777 struct abbrev_attr *first_attr;
778 struct abbrev_attr *last_attr;
779 struct abbrev_entry *next;
783 static abbrev_entry *first_abbrev = NULL;
784 static abbrev_entry *last_abbrev = NULL;
791 for (abbrv = first_abbrev; abbrv;)
793 abbrev_entry *next_abbrev = abbrv->next;
796 for (attr = abbrv->first_attr; attr;)
798 abbrev_attr *next_attr = attr->next;
808 last_abbrev = first_abbrev = NULL;
812 add_abbrev (unsigned long number, unsigned long tag, int children)
816 entry = (abbrev_entry *) malloc (sizeof (*entry));
821 entry->entry = number;
823 entry->children = children;
824 entry->first_attr = NULL;
825 entry->last_attr = NULL;
828 if (first_abbrev == NULL)
829 first_abbrev = entry;
831 last_abbrev->next = entry;
837 add_abbrev_attr (unsigned long attribute, unsigned long form,
838 bfd_signed_vma implicit_const)
842 attr = (abbrev_attr *) malloc (sizeof (*attr));
847 attr->attribute = attribute;
849 attr->implicit_const = implicit_const;
852 if (last_abbrev->first_attr == NULL)
853 last_abbrev->first_attr = attr;
855 last_abbrev->last_attr->next = attr;
857 last_abbrev->last_attr = attr;
860 /* Processes the (partial) contents of a .debug_abbrev section.
861 Returns NULL if the end of the section was encountered.
862 Returns the address after the last byte read if the end of
863 an abbreviation set was found. */
865 static unsigned char *
866 process_abbrev_section (unsigned char *start, unsigned char *end)
868 if (first_abbrev != NULL)
873 unsigned int bytes_read;
876 unsigned long attribute;
879 entry = read_uleb128 (start, & bytes_read, end);
882 /* A single zero is supposed to end the section according
883 to the standard. If there's more, then signal that to
890 tag = read_uleb128 (start, & bytes_read, end);
897 add_abbrev (entry, tag, children);
902 /* Initialize it due to a false compiler warning. */
903 bfd_signed_vma implicit_const = -1;
905 attribute = read_uleb128 (start, & bytes_read, end);
910 form = read_uleb128 (start, & bytes_read, end);
915 if (form == DW_FORM_implicit_const)
917 implicit_const = read_sleb128 (start, & bytes_read, end);
923 add_abbrev_attr (attribute, form, implicit_const);
925 while (attribute != 0);
928 /* Report the missing single zero which ends the section. */
929 error (_(".debug_abbrev section not zero terminated\n"));
935 get_TAG_name (unsigned long tag)
937 const char *name = get_DW_TAG_name ((unsigned int)tag);
941 static char buffer[100];
943 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
951 get_FORM_name (unsigned long form)
956 return "DW_FORM value: 0";
958 name = get_DW_FORM_name (form);
961 static char buffer[100];
963 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
971 get_IDX_name (unsigned long idx)
973 const char *name = get_DW_IDX_name ((unsigned int) idx);
977 static char buffer[100];
979 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
986 static unsigned char *
987 display_block (unsigned char *data,
989 const unsigned char * const end, char delimiter)
993 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
995 return (unsigned char *) end;
997 maxlen = (dwarf_vma) (end - data);
998 length = length > maxlen ? maxlen : length;
1001 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1007 decode_location_expression (unsigned char * data,
1008 unsigned int pointer_size,
1009 unsigned int offset_size,
1012 dwarf_vma cu_offset,
1013 struct dwarf_section * section)
1016 unsigned int bytes_read;
1018 dwarf_signed_vma svalue;
1019 unsigned char *end = data + length;
1020 int need_frame_base = 0;
1029 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1030 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1033 printf ("DW_OP_deref");
1036 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1037 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1040 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1041 printf ("DW_OP_const1s: %ld", (long) svalue);
1044 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1045 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1048 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1049 printf ("DW_OP_const2s: %ld", (long) svalue);
1052 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1053 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1056 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1057 printf ("DW_OP_const4s: %ld", (long) svalue);
1060 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1061 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1062 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1063 printf ("%lu", (unsigned long) uvalue);
1066 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1067 printf ("DW_OP_const8s: %ld ", (long) svalue);
1068 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1069 printf ("%ld", (long) svalue);
1072 printf ("DW_OP_constu: %s",
1073 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1077 printf ("DW_OP_consts: %s",
1078 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1082 printf ("DW_OP_dup");
1085 printf ("DW_OP_drop");
1088 printf ("DW_OP_over");
1091 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1092 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1095 printf ("DW_OP_swap");
1098 printf ("DW_OP_rot");
1101 printf ("DW_OP_xderef");
1104 printf ("DW_OP_abs");
1107 printf ("DW_OP_and");
1110 printf ("DW_OP_div");
1113 printf ("DW_OP_minus");
1116 printf ("DW_OP_mod");
1119 printf ("DW_OP_mul");
1122 printf ("DW_OP_neg");
1125 printf ("DW_OP_not");
1128 printf ("DW_OP_or");
1131 printf ("DW_OP_plus");
1133 case DW_OP_plus_uconst:
1134 printf ("DW_OP_plus_uconst: %s",
1135 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1139 printf ("DW_OP_shl");
1142 printf ("DW_OP_shr");
1145 printf ("DW_OP_shra");
1148 printf ("DW_OP_xor");
1151 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1152 printf ("DW_OP_bra: %ld", (long) svalue);
1155 printf ("DW_OP_eq");
1158 printf ("DW_OP_ge");
1161 printf ("DW_OP_gt");
1164 printf ("DW_OP_le");
1167 printf ("DW_OP_lt");
1170 printf ("DW_OP_ne");
1173 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1174 printf ("DW_OP_skip: %ld", (long) svalue);
1209 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1244 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1245 regname (op - DW_OP_reg0, 1));
1280 printf ("DW_OP_breg%d (%s): %s",
1282 regname (op - DW_OP_breg0, 1),
1283 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1288 uvalue = read_uleb128 (data, &bytes_read, end);
1290 printf ("DW_OP_regx: %s (%s)",
1291 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1294 need_frame_base = 1;
1295 printf ("DW_OP_fbreg: %s",
1296 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1300 uvalue = read_uleb128 (data, &bytes_read, end);
1302 printf ("DW_OP_bregx: %s (%s) %s",
1303 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1304 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1308 printf ("DW_OP_piece: %s",
1309 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1312 case DW_OP_deref_size:
1313 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1314 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1316 case DW_OP_xderef_size:
1317 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1318 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1321 printf ("DW_OP_nop");
1324 /* DWARF 3 extensions. */
1325 case DW_OP_push_object_address:
1326 printf ("DW_OP_push_object_address");
1329 /* XXX: Strictly speaking for 64-bit DWARF3 files
1330 this ought to be an 8-byte wide computation. */
1331 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1332 printf ("DW_OP_call2: <0x%s>",
1333 dwarf_vmatoa ("x", svalue + cu_offset));
1336 /* XXX: Strictly speaking for 64-bit DWARF3 files
1337 this ought to be an 8-byte wide computation. */
1338 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1339 printf ("DW_OP_call4: <0x%s>",
1340 dwarf_vmatoa ("x", svalue + cu_offset));
1342 case DW_OP_call_ref:
1343 /* XXX: Strictly speaking for 64-bit DWARF3 files
1344 this ought to be an 8-byte wide computation. */
1345 if (dwarf_version == -1)
1347 printf (_("(DW_OP_call_ref in frame info)"));
1348 /* No way to tell where the next op is, so just bail. */
1349 return need_frame_base;
1351 if (dwarf_version == 2)
1353 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1357 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1359 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1361 case DW_OP_form_tls_address:
1362 printf ("DW_OP_form_tls_address");
1364 case DW_OP_call_frame_cfa:
1365 printf ("DW_OP_call_frame_cfa");
1367 case DW_OP_bit_piece:
1368 printf ("DW_OP_bit_piece: ");
1369 printf (_("size: %s "),
1370 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1372 printf (_("offset: %s "),
1373 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1377 /* DWARF 4 extensions. */
1378 case DW_OP_stack_value:
1379 printf ("DW_OP_stack_value");
1382 case DW_OP_implicit_value:
1383 printf ("DW_OP_implicit_value");
1384 uvalue = read_uleb128 (data, &bytes_read, end);
1386 data = display_block (data, uvalue, end, ' ');
1389 /* GNU extensions. */
1390 case DW_OP_GNU_push_tls_address:
1391 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1393 case DW_OP_GNU_uninit:
1394 printf ("DW_OP_GNU_uninit");
1395 /* FIXME: Is there data associated with this OP ? */
1397 case DW_OP_GNU_encoded_addr:
1404 addr = get_encoded_value (&data, encoding, section, end);
1406 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1407 print_dwarf_vma (addr, pointer_size);
1410 case DW_OP_implicit_pointer:
1411 case DW_OP_GNU_implicit_pointer:
1412 /* XXX: Strictly speaking for 64-bit DWARF3 files
1413 this ought to be an 8-byte wide computation. */
1414 if (dwarf_version == -1)
1416 printf (_("(%s in frame info)"),
1417 (op == DW_OP_implicit_pointer
1418 ? "DW_OP_implicit_pointer"
1419 : "DW_OP_GNU_implicit_pointer"));
1420 /* No way to tell where the next op is, so just bail. */
1421 return need_frame_base;
1423 if (dwarf_version == 2)
1425 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1429 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1431 printf ("%s: <0x%s> %s",
1432 (op == DW_OP_implicit_pointer
1433 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1434 dwarf_vmatoa ("x", uvalue),
1435 dwarf_vmatoa ("d", read_sleb128 (data,
1436 &bytes_read, end)));
1439 case DW_OP_entry_value:
1440 case DW_OP_GNU_entry_value:
1441 uvalue = read_uleb128 (data, &bytes_read, end);
1443 /* PR 17531: file: 0cc9cd00. */
1444 if (uvalue > (dwarf_vma) (end - data))
1445 uvalue = end - data;
1446 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1447 : "DW_OP_GNU_entry_value"));
1448 if (decode_location_expression (data, pointer_size, offset_size,
1449 dwarf_version, uvalue,
1450 cu_offset, section))
1451 need_frame_base = 1;
1457 case DW_OP_const_type:
1458 case DW_OP_GNU_const_type:
1459 uvalue = read_uleb128 (data, &bytes_read, end);
1461 printf ("%s: <0x%s> ",
1462 (op == DW_OP_const_type ? "DW_OP_const_type"
1463 : "DW_OP_GNU_const_type"),
1464 dwarf_vmatoa ("x", cu_offset + uvalue));
1465 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1466 data = display_block (data, uvalue, end, ' ');
1468 case DW_OP_regval_type:
1469 case DW_OP_GNU_regval_type:
1470 uvalue = read_uleb128 (data, &bytes_read, end);
1472 printf ("%s: %s (%s)",
1473 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1474 : "DW_OP_GNU_regval_type"),
1475 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1476 uvalue = read_uleb128 (data, &bytes_read, end);
1478 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1480 case DW_OP_deref_type:
1481 case DW_OP_GNU_deref_type:
1482 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1484 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1485 : "DW_OP_GNU_deref_type"),
1487 uvalue = read_uleb128 (data, &bytes_read, end);
1489 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1492 case DW_OP_GNU_convert:
1493 uvalue = read_uleb128 (data, &bytes_read, end);
1495 printf ("%s <0x%s>",
1496 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1497 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1499 case DW_OP_reinterpret:
1500 case DW_OP_GNU_reinterpret:
1501 uvalue = read_uleb128 (data, &bytes_read, end);
1503 printf ("%s <0x%s>",
1504 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1505 : "DW_OP_GNU_reinterpret"),
1506 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1508 case DW_OP_GNU_parameter_ref:
1509 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1510 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1511 dwarf_vmatoa ("x", cu_offset + uvalue));
1513 case DW_OP_GNU_addr_index:
1514 uvalue = read_uleb128 (data, &bytes_read, end);
1516 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1518 case DW_OP_GNU_const_index:
1519 uvalue = read_uleb128 (data, &bytes_read, end);
1521 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1524 /* HP extensions. */
1525 case DW_OP_HP_is_value:
1526 printf ("DW_OP_HP_is_value");
1527 /* FIXME: Is there data associated with this OP ? */
1529 case DW_OP_HP_fltconst4:
1530 printf ("DW_OP_HP_fltconst4");
1531 /* FIXME: Is there data associated with this OP ? */
1533 case DW_OP_HP_fltconst8:
1534 printf ("DW_OP_HP_fltconst8");
1535 /* FIXME: Is there data associated with this OP ? */
1537 case DW_OP_HP_mod_range:
1538 printf ("DW_OP_HP_mod_range");
1539 /* FIXME: Is there data associated with this OP ? */
1541 case DW_OP_HP_unmod_range:
1542 printf ("DW_OP_HP_unmod_range");
1543 /* FIXME: Is there data associated with this OP ? */
1546 printf ("DW_OP_HP_tls");
1547 /* FIXME: Is there data associated with this OP ? */
1550 /* PGI (STMicroelectronics) extensions. */
1551 case DW_OP_PGI_omp_thread_num:
1552 /* Pushes the thread number for the current thread as it would be
1553 returned by the standard OpenMP library function:
1554 omp_get_thread_num(). The "current thread" is the thread for
1555 which the expression is being evaluated. */
1556 printf ("DW_OP_PGI_omp_thread_num");
1560 if (op >= DW_OP_lo_user
1561 && op <= DW_OP_hi_user)
1562 printf (_("(User defined location op 0x%x)"), op);
1564 printf (_("(Unknown location op 0x%x)"), op);
1565 /* No way to tell where the next op is, so just bail. */
1566 return need_frame_base;
1569 /* Separate the ops. */
1574 return need_frame_base;
1577 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1578 This is used for DWARF package files. */
1580 static struct cu_tu_set *
1581 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1583 struct cu_tu_set *p;
1585 unsigned int dw_sect;
1591 dw_sect = DW_SECT_TYPES;
1597 dw_sect = DW_SECT_INFO;
1601 if (p->section_offsets [dw_sect] == cu_offset)
1609 /* Add INC to HIGH_BITS:LOW_BITS. */
1611 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1613 dwarf_vma tmp = * low_bits;
1617 /* FIXME: There is probably a better way of handling this:
1619 We need to cope with dwarf_vma being a 32-bit or 64-bit
1620 type. Plus regardless of its size LOW_BITS is meant to
1621 only hold 32-bits, so if there is overflow or wrap around
1622 we must propagate into HIGH_BITS. */
1623 if (tmp < * low_bits)
1627 else if (sizeof (tmp) > 8
1637 static unsigned char *
1638 read_and_display_attr_value (unsigned long attribute,
1640 dwarf_signed_vma implicit_const,
1641 unsigned char * data,
1642 unsigned char * end,
1643 dwarf_vma cu_offset,
1644 dwarf_vma pointer_size,
1645 dwarf_vma offset_size,
1647 debug_info * debug_info_p,
1649 struct dwarf_section * section,
1650 struct cu_tu_set * this_set, char delimiter)
1652 dwarf_vma uvalue = 0;
1653 unsigned char *block_start = NULL;
1654 unsigned char * orig_data = data;
1655 unsigned int bytes_read;
1657 if (data > end || (data == end && form != DW_FORM_flag_present))
1659 warn (_("Corrupt attribute\n"));
1668 case DW_FORM_ref_addr:
1669 if (dwarf_version == 2)
1670 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1671 else if (dwarf_version == 3 || dwarf_version == 4)
1672 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1674 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1679 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1683 case DW_FORM_line_strp:
1684 case DW_FORM_sec_offset:
1685 case DW_FORM_GNU_ref_alt:
1686 case DW_FORM_GNU_strp_alt:
1687 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1690 case DW_FORM_flag_present:
1697 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1702 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1707 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1711 uvalue = read_sleb128 (data, & bytes_read, end);
1715 case DW_FORM_GNU_str_index:
1716 uvalue = read_uleb128 (data, & bytes_read, end);
1720 case DW_FORM_ref_udata:
1722 uvalue = read_uleb128 (data, & bytes_read, end);
1726 case DW_FORM_indirect:
1727 form = read_uleb128 (data, & bytes_read, end);
1730 printf ("%c%s", delimiter, get_FORM_name (form));
1731 if (form == DW_FORM_implicit_const)
1733 implicit_const = read_sleb128 (data, & bytes_read, end);
1736 return read_and_display_attr_value (attribute, form, implicit_const, data,
1737 end, cu_offset, pointer_size,
1738 offset_size, dwarf_version,
1739 debug_info_p, do_loc,
1740 section, this_set, delimiter);
1741 case DW_FORM_GNU_addr_index:
1742 uvalue = read_uleb128 (data, & bytes_read, end);
1749 case DW_FORM_ref_addr:
1751 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1754 case DW_FORM_GNU_ref_alt:
1756 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1762 case DW_FORM_ref_udata:
1764 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1769 case DW_FORM_sec_offset:
1771 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1774 case DW_FORM_flag_present:
1781 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1784 case DW_FORM_implicit_const:
1786 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1793 dwarf_vma high_bits;
1797 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1799 if (form == DW_FORM_ref8)
1800 add64 (& high_bits, & utmp, cu_offset);
1801 printf ("%c0x%s", delimiter,
1802 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1805 if ((do_loc || do_debug_loc || do_debug_ranges)
1806 && num_debug_info_entries == 0)
1808 if (sizeof (uvalue) == 8)
1809 SAFE_BYTE_GET (uvalue, data, 8, end);
1811 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1817 case DW_FORM_data16:
1820 dwarf_vma left_high_bits, left_low_bits;
1821 dwarf_vma right_high_bits, right_low_bits;
1823 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1824 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1825 if (byte_get == byte_get_little_endian)
1828 left_high_bits ^= right_high_bits;
1829 right_high_bits ^= left_high_bits;
1830 left_high_bits ^= right_high_bits;
1831 left_low_bits ^= right_low_bits;
1832 right_low_bits ^= left_low_bits;
1833 left_low_bits ^= right_low_bits;
1835 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1836 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1837 left_high_bits, left_low_bits, right_high_bits,
1843 case DW_FORM_string:
1845 printf ("%c%.*s", delimiter, (int) (end - data), data);
1846 data += strnlen ((char *) data, end - data) + 1;
1850 case DW_FORM_exprloc:
1851 uvalue = read_uleb128 (data, & bytes_read, end);
1852 block_start = data + bytes_read;
1853 if (block_start >= end)
1855 warn (_("Block ends prematurely\n"));
1859 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1860 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1861 block_start + uvalue here. */
1862 data = block_start + uvalue;
1863 /* PR 17512: file: 008-103549-0.001:0.1. */
1864 if (block_start + uvalue > end || data < block_start)
1866 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1867 uvalue = end - block_start;
1870 data = block_start + uvalue;
1872 data = display_block (block_start, uvalue, end, delimiter);
1875 case DW_FORM_block1:
1876 SAFE_BYTE_GET (uvalue, data, 1, end);
1877 block_start = data + 1;
1878 if (block_start >= end)
1880 warn (_("Block ends prematurely\n"));
1884 data = block_start + uvalue;
1885 if (block_start + uvalue > end || data < block_start)
1887 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1888 uvalue = end - block_start;
1891 data = block_start + uvalue;
1893 data = display_block (block_start, uvalue, end, delimiter);
1896 case DW_FORM_block2:
1897 SAFE_BYTE_GET (uvalue, data, 2, end);
1898 block_start = data + 2;
1899 if (block_start >= end)
1901 warn (_("Block ends prematurely\n"));
1905 data = block_start + uvalue;
1906 if (block_start + uvalue > end || data < block_start)
1908 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1909 uvalue = end - block_start;
1912 data = block_start + uvalue;
1914 data = display_block (block_start, uvalue, end, delimiter);
1917 case DW_FORM_block4:
1918 SAFE_BYTE_GET (uvalue, data, 4, end);
1919 block_start = data + 4;
1920 /* PR 17512: file: 3371-3907-0.004. */
1921 if (block_start >= end)
1923 warn (_("Block ends prematurely\n"));
1927 data = block_start + uvalue;
1928 if (block_start + uvalue > end
1929 /* PR 17531: file: 5b5f0592. */
1930 || data < block_start)
1932 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1933 uvalue = end - block_start;
1936 data = block_start + uvalue;
1938 data = display_block (block_start, uvalue, end, delimiter);
1943 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1944 dwarf_vmatoa ("x", uvalue),
1945 fetch_indirect_string (uvalue));
1948 case DW_FORM_line_strp:
1950 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1951 dwarf_vmatoa ("x", uvalue),
1952 fetch_indirect_line_string (uvalue));
1955 case DW_FORM_GNU_str_index:
1958 const char *suffix = strrchr (section->name, '.');
1959 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1961 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1962 dwarf_vmatoa ("x", uvalue),
1963 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1967 case DW_FORM_GNU_strp_alt:
1969 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1970 dwarf_vmatoa ("x", uvalue));
1973 case DW_FORM_indirect:
1974 /* Handled above. */
1977 case DW_FORM_ref_sig8:
1980 dwarf_vma high_bits;
1983 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1984 printf ("%csignature: 0x%s", delimiter,
1985 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1990 case DW_FORM_GNU_addr_index:
1992 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
1993 dwarf_vmatoa ("x", uvalue),
1994 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1998 warn (_("Unrecognized form: %lu\n"), form);
2002 if ((do_loc || do_debug_loc || do_debug_ranges)
2003 && num_debug_info_entries == 0
2004 && debug_info_p != NULL)
2008 case DW_AT_frame_base:
2009 have_frame_base = 1;
2011 case DW_AT_location:
2012 case DW_AT_string_length:
2013 case DW_AT_return_addr:
2014 case DW_AT_data_member_location:
2015 case DW_AT_vtable_elem_location:
2017 case DW_AT_static_link:
2018 case DW_AT_use_location:
2019 case DW_AT_call_value:
2020 case DW_AT_GNU_call_site_value:
2021 case DW_AT_call_data_value:
2022 case DW_AT_GNU_call_site_data_value:
2023 case DW_AT_call_target:
2024 case DW_AT_GNU_call_site_target:
2025 case DW_AT_call_target_clobbered:
2026 case DW_AT_GNU_call_site_target_clobbered:
2027 if ((dwarf_version < 4
2028 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2029 || form == DW_FORM_sec_offset)
2031 /* Process location list. */
2032 unsigned int lmax = debug_info_p->max_loc_offsets;
2033 unsigned int num = debug_info_p->num_loc_offsets;
2035 if (lmax == 0 || num >= lmax)
2038 debug_info_p->loc_offsets = (dwarf_vma *)
2039 xcrealloc (debug_info_p->loc_offsets,
2040 lmax, sizeof (*debug_info_p->loc_offsets));
2041 debug_info_p->have_frame_base = (int *)
2042 xcrealloc (debug_info_p->have_frame_base,
2043 lmax, sizeof (*debug_info_p->have_frame_base));
2044 debug_info_p->max_loc_offsets = lmax;
2046 if (this_set != NULL)
2047 uvalue += this_set->section_offsets [DW_SECT_LOC];
2048 debug_info_p->loc_offsets [num] = uvalue;
2049 debug_info_p->have_frame_base [num] = have_frame_base;
2050 debug_info_p->num_loc_offsets++;
2055 if (need_base_address)
2056 debug_info_p->base_address = uvalue;
2059 case DW_AT_GNU_addr_base:
2060 debug_info_p->addr_base = uvalue;
2063 case DW_AT_GNU_ranges_base:
2064 debug_info_p->ranges_base = uvalue;
2068 if ((dwarf_version < 4
2069 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2070 || form == DW_FORM_sec_offset)
2072 /* Process range list. */
2073 unsigned int lmax = debug_info_p->max_range_lists;
2074 unsigned int num = debug_info_p->num_range_lists;
2076 if (lmax == 0 || num >= lmax)
2079 debug_info_p->range_lists = (dwarf_vma *)
2080 xcrealloc (debug_info_p->range_lists,
2081 lmax, sizeof (*debug_info_p->range_lists));
2082 debug_info_p->max_range_lists = lmax;
2084 debug_info_p->range_lists [num] = uvalue;
2085 debug_info_p->num_range_lists++;
2094 if (do_loc || attribute == 0)
2097 /* For some attributes we can display further information. */
2104 case DW_INL_not_inlined:
2105 printf (_("(not inlined)"));
2107 case DW_INL_inlined:
2108 printf (_("(inlined)"));
2110 case DW_INL_declared_not_inlined:
2111 printf (_("(declared as inline but ignored)"));
2113 case DW_INL_declared_inlined:
2114 printf (_("(declared as inline and inlined)"));
2117 printf (_(" (Unknown inline attribute value: %s)"),
2118 dwarf_vmatoa ("x", uvalue));
2123 case DW_AT_language:
2127 /* Ordered by the numeric value of these constants. */
2128 case DW_LANG_C89: printf ("(ANSI C)"); break;
2129 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2130 case DW_LANG_Ada83: printf ("(Ada)"); break;
2131 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2132 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2133 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2134 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2135 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2136 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2137 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2138 /* DWARF 2.1 values. */
2139 case DW_LANG_Java: printf ("(Java)"); break;
2140 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2141 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2142 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2143 /* DWARF 3 values. */
2144 case DW_LANG_PLI: printf ("(PLI)"); break;
2145 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2146 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2147 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2148 case DW_LANG_D: printf ("(D)"); break;
2149 /* DWARF 4 values. */
2150 case DW_LANG_Python: printf ("(Python)"); break;
2151 /* DWARF 5 values. */
2152 case DW_LANG_Go: printf ("(Go)"); break;
2153 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2154 case DW_LANG_C11: printf ("(C11)"); break;
2155 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2156 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2157 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2158 /* MIPS extension. */
2159 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2160 /* UPC extension. */
2161 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2163 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2164 printf (_("(implementation defined: %s)"),
2165 dwarf_vmatoa ("x", uvalue));
2167 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2172 case DW_AT_encoding:
2176 case DW_ATE_void: printf ("(void)"); break;
2177 case DW_ATE_address: printf ("(machine address)"); break;
2178 case DW_ATE_boolean: printf ("(boolean)"); break;
2179 case DW_ATE_complex_float: printf ("(complex float)"); break;
2180 case DW_ATE_float: printf ("(float)"); break;
2181 case DW_ATE_signed: printf ("(signed)"); break;
2182 case DW_ATE_signed_char: printf ("(signed char)"); break;
2183 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2184 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2185 /* DWARF 2.1 values: */
2186 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2187 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2188 /* DWARF 3 values: */
2189 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2190 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2191 case DW_ATE_edited: printf ("(edited)"); break;
2192 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2193 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2194 /* HP extensions: */
2195 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2196 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2197 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2198 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2199 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2200 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2201 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2202 /* DWARF 4 values: */
2203 case DW_ATE_UTF: printf ("(unicode string)"); break;
2206 if (uvalue >= DW_ATE_lo_user
2207 && uvalue <= DW_ATE_hi_user)
2208 printf (_("(user defined type)"));
2210 printf (_("(unknown type)"));
2215 case DW_AT_accessibility:
2219 case DW_ACCESS_public: printf ("(public)"); break;
2220 case DW_ACCESS_protected: printf ("(protected)"); break;
2221 case DW_ACCESS_private: printf ("(private)"); break;
2223 printf (_("(unknown accessibility)"));
2228 case DW_AT_visibility:
2232 case DW_VIS_local: printf ("(local)"); break;
2233 case DW_VIS_exported: printf ("(exported)"); break;
2234 case DW_VIS_qualified: printf ("(qualified)"); break;
2235 default: printf (_("(unknown visibility)")); break;
2239 case DW_AT_virtuality:
2243 case DW_VIRTUALITY_none: printf ("(none)"); break;
2244 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2245 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2246 default: printf (_("(unknown virtuality)")); break;
2250 case DW_AT_identifier_case:
2254 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2255 case DW_ID_up_case: printf ("(up_case)"); break;
2256 case DW_ID_down_case: printf ("(down_case)"); break;
2257 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2258 default: printf (_("(unknown case)")); break;
2262 case DW_AT_calling_convention:
2266 case DW_CC_normal: printf ("(normal)"); break;
2267 case DW_CC_program: printf ("(program)"); break;
2268 case DW_CC_nocall: printf ("(nocall)"); break;
2270 if (uvalue >= DW_CC_lo_user
2271 && uvalue <= DW_CC_hi_user)
2272 printf (_("(user defined)"));
2274 printf (_("(unknown convention)"));
2278 case DW_AT_ordering:
2282 case -1: printf (_("(undefined)")); break;
2283 case 0: printf ("(row major)"); break;
2284 case 1: printf ("(column major)"); break;
2288 case DW_AT_frame_base:
2289 have_frame_base = 1;
2291 case DW_AT_location:
2292 case DW_AT_string_length:
2293 case DW_AT_return_addr:
2294 case DW_AT_data_member_location:
2295 case DW_AT_vtable_elem_location:
2297 case DW_AT_static_link:
2298 case DW_AT_use_location:
2299 case DW_AT_call_value:
2300 case DW_AT_GNU_call_site_value:
2301 case DW_AT_call_data_value:
2302 case DW_AT_GNU_call_site_data_value:
2303 case DW_AT_call_target:
2304 case DW_AT_GNU_call_site_target:
2305 case DW_AT_call_target_clobbered:
2306 case DW_AT_GNU_call_site_target_clobbered:
2307 if ((dwarf_version < 4
2308 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2309 || form == DW_FORM_sec_offset)
2310 printf (_(" (location list)"));
2312 case DW_AT_allocated:
2313 case DW_AT_associated:
2314 case DW_AT_data_location:
2316 case DW_AT_upper_bound:
2317 case DW_AT_lower_bound:
2320 int need_frame_base;
2323 need_frame_base = decode_location_expression (block_start,
2328 cu_offset, section);
2330 if (need_frame_base && !have_frame_base)
2331 printf (_(" [without DW_AT_frame_base]"));
2337 if (form == DW_FORM_ref_sig8
2338 || form == DW_FORM_GNU_ref_alt)
2341 if (form == DW_FORM_ref1
2342 || form == DW_FORM_ref2
2343 || form == DW_FORM_ref4
2344 || form == DW_FORM_ref_udata)
2345 uvalue += cu_offset;
2347 if (uvalue >= section->size)
2348 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2349 dwarf_vmatoa ("x", uvalue),
2350 (unsigned long) (orig_data - section->start));
2353 unsigned long abbrev_number;
2354 abbrev_entry * entry;
2356 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2358 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2359 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2360 use different abbrev table, and we don't track .debug_info chunks
2362 if (form != DW_FORM_ref_addr)
2364 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2365 if (entry->entry == abbrev_number)
2368 printf (" (%s)", get_TAG_name (entry->tag));
2383 get_AT_name (unsigned long attribute)
2388 return "DW_AT value: 0";
2390 /* One value is shared by the MIPS and HP extensions: */
2391 if (attribute == DW_AT_MIPS_fde)
2392 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2394 name = get_DW_AT_name (attribute);
2398 static char buffer[100];
2400 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2408 static unsigned char *
2409 read_and_display_attr (unsigned long attribute,
2411 dwarf_signed_vma implicit_const,
2412 unsigned char * data,
2413 unsigned char * end,
2414 dwarf_vma cu_offset,
2415 dwarf_vma pointer_size,
2416 dwarf_vma offset_size,
2418 debug_info * debug_info_p,
2420 struct dwarf_section * section,
2421 struct cu_tu_set * this_set)
2424 printf (" %-18s:", get_AT_name (attribute));
2425 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2426 cu_offset, pointer_size, offset_size,
2427 dwarf_version, debug_info_p,
2428 do_loc, section, this_set, ' ');
2434 /* Process the contents of a .debug_info section. If do_loc is non-zero
2435 then we are scanning for location lists and we do not want to display
2436 anything to the user. If do_types is non-zero, we are processing
2437 a .debug_types section instead of a .debug_info section. */
2440 process_debug_info (struct dwarf_section *section,
2442 enum dwarf_section_display_enum abbrev_sec,
2446 unsigned char *start = section->start;
2447 unsigned char *end = start + section->size;
2448 unsigned char *section_begin;
2450 unsigned int num_units = 0;
2452 if ((do_loc || do_debug_loc || do_debug_ranges)
2453 && num_debug_info_entries == 0
2458 /* First scan the section to get the number of comp units. */
2459 for (section_begin = start, num_units = 0; section_begin < end;
2462 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2463 will be the length. For a 64-bit DWARF section, it'll be
2464 the escape code 0xffffffff followed by an 8 byte length. */
2465 SAFE_BYTE_GET (length, section_begin, 4, end);
2467 if (length == 0xffffffff)
2469 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2470 section_begin += length + 12;
2472 else if (length >= 0xfffffff0 && length < 0xffffffff)
2474 warn (_("Reserved length value (0x%s) found in section %s\n"),
2475 dwarf_vmatoa ("x", length), section->name);
2479 section_begin += length + 4;
2481 /* Negative values are illegal, they may even cause infinite
2482 looping. This can happen if we can't accurately apply
2483 relocations to an object file, or if the file is corrupt. */
2484 if ((signed long) length <= 0 || section_begin < start)
2486 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2487 dwarf_vmatoa ("x", length), section->name);
2494 error (_("No comp units in %s section ?\n"), section->name);
2498 /* Then allocate an array to hold the information. */
2499 debug_information = (debug_info *) cmalloc (num_units,
2500 sizeof (* debug_information));
2501 if (debug_information == NULL)
2503 error (_("Not enough memory for a debug info array of %u entries\n"),
2505 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2508 /* PR 17531: file: 92ca3797.
2509 We cannot rely upon the debug_information array being initialised
2510 before it is used. A corrupt file could easily contain references
2511 to a unit for which information has not been made available. So
2512 we ensure that the array is zeroed here. */
2513 memset (debug_information, 0, num_units * sizeof (*debug_information));
2515 alloc_num_debug_info_entries = num_units;
2520 if (dwarf_start_die == 0)
2521 printf (_("Contents of the %s section:\n\n"), section->name);
2523 load_debug_section (str, file);
2524 load_debug_section (line_str, file);
2525 load_debug_section (str_dwo, file);
2526 load_debug_section (str_index, file);
2527 load_debug_section (str_index_dwo, file);
2528 load_debug_section (debug_addr, file);
2531 load_debug_section (abbrev_sec, file);
2532 if (debug_displays [abbrev_sec].section.start == NULL)
2534 warn (_("Unable to locate %s section!\n"),
2535 debug_displays [abbrev_sec].section.name);
2539 for (section_begin = start, unit = 0; start < end; unit++)
2541 DWARF2_Internal_CompUnit compunit;
2542 unsigned char *hdrptr;
2543 unsigned char *tags;
2544 int level, last_level, saved_level;
2545 dwarf_vma cu_offset;
2546 unsigned int offset_size;
2547 int initial_length_size;
2548 dwarf_vma signature_high = 0;
2549 dwarf_vma signature_low = 0;
2550 dwarf_vma type_offset = 0;
2551 struct cu_tu_set *this_set;
2552 dwarf_vma abbrev_base;
2557 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2559 if (compunit.cu_length == 0xffffffff)
2561 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2563 initial_length_size = 12;
2568 initial_length_size = 4;
2571 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2573 cu_offset = start - section_begin;
2575 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2577 if (compunit.cu_version < 5)
2579 compunit.cu_unit_type = DW_UT_compile;
2580 /* Initialize it due to a false compiler warning. */
2581 compunit.cu_pointer_size = -1;
2585 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2586 do_types = (compunit.cu_unit_type == DW_UT_type);
2588 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2591 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2593 if (this_set == NULL)
2596 abbrev_size = debug_displays [abbrev_sec].section.size;
2600 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2601 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2604 if (compunit.cu_version < 5)
2605 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2607 /* PR 17512: file: 001-108546-0.001:0.1. */
2608 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2610 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2611 compunit.cu_pointer_size, offset_size);
2612 compunit.cu_pointer_size = offset_size;
2617 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2619 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2622 if ((do_loc || do_debug_loc || do_debug_ranges)
2623 && num_debug_info_entries == 0
2626 debug_information [unit].cu_offset = cu_offset;
2627 debug_information [unit].pointer_size
2628 = compunit.cu_pointer_size;
2629 debug_information [unit].offset_size = offset_size;
2630 debug_information [unit].dwarf_version = compunit.cu_version;
2631 debug_information [unit].base_address = 0;
2632 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2633 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2634 debug_information [unit].loc_offsets = NULL;
2635 debug_information [unit].have_frame_base = NULL;
2636 debug_information [unit].max_loc_offsets = 0;
2637 debug_information [unit].num_loc_offsets = 0;
2638 debug_information [unit].range_lists = NULL;
2639 debug_information [unit].max_range_lists= 0;
2640 debug_information [unit].num_range_lists = 0;
2643 if (!do_loc && dwarf_start_die == 0)
2645 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2646 dwarf_vmatoa ("x", cu_offset));
2647 printf (_(" Length: 0x%s (%s)\n"),
2648 dwarf_vmatoa ("x", compunit.cu_length),
2649 offset_size == 8 ? "64-bit" : "32-bit");
2650 printf (_(" Version: %d\n"), compunit.cu_version);
2651 printf (_(" Abbrev Offset: 0x%s\n"),
2652 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2653 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2658 printf (_(" Signature: 0x%s\n"),
2659 dwarf_vmatoa64 (signature_high, signature_low,
2660 buf, sizeof (buf)));
2661 printf (_(" Type Offset: 0x%s\n"),
2662 dwarf_vmatoa ("x", type_offset));
2664 if (this_set != NULL)
2666 dwarf_vma *offsets = this_set->section_offsets;
2667 size_t *sizes = this_set->section_sizes;
2669 printf (_(" Section contributions:\n"));
2670 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2671 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2672 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2673 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2674 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2675 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2676 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2677 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2678 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2679 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2680 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2681 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2685 if (cu_offset + compunit.cu_length + initial_length_size
2688 warn (_("Debug info is corrupted, length of CU at %s"
2689 " extends beyond end of section (length = %s)\n"),
2690 dwarf_vmatoa ("x", cu_offset),
2691 dwarf_vmatoa ("x", compunit.cu_length));
2696 start += compunit.cu_length + initial_length_size;
2700 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2701 dwarf_vmatoa ("x", cu_offset));
2705 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2707 warn (_("CU at offset %s contains corrupt or "
2708 "unsupported version number: %d.\n"),
2709 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2713 if (compunit.cu_unit_type != DW_UT_compile
2714 && compunit.cu_unit_type != DW_UT_type)
2716 warn (_("CU at offset %s contains corrupt or "
2717 "unsupported unit type: %d.\n"),
2718 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2724 /* Process the abbrevs used by this compilation unit. */
2725 if (compunit.cu_abbrev_offset >= abbrev_size)
2726 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2727 (unsigned long) compunit.cu_abbrev_offset,
2728 (unsigned long) abbrev_size);
2729 /* PR 17531: file:4bcd9ce9. */
2730 else if ((abbrev_base + abbrev_size)
2731 > debug_displays [abbrev_sec].section.size)
2732 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2733 (unsigned long) abbrev_base + abbrev_size,
2734 (unsigned long) debug_displays [abbrev_sec].section.size);
2736 process_abbrev_section
2737 (((unsigned char *) debug_displays [abbrev_sec].section.start
2738 + abbrev_base + compunit.cu_abbrev_offset),
2739 ((unsigned char *) debug_displays [abbrev_sec].section.start
2740 + abbrev_base + abbrev_size));
2745 while (tags < start)
2747 unsigned int bytes_read;
2748 unsigned long abbrev_number;
2749 unsigned long die_offset;
2750 abbrev_entry *entry;
2752 int do_printing = 1;
2754 die_offset = tags - section_begin;
2756 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2759 /* A null DIE marks the end of a list of siblings or it may also be
2760 a section padding. */
2761 if (abbrev_number == 0)
2763 /* Check if it can be a section padding for the last CU. */
2764 if (level == 0 && start == end)
2768 for (chk = tags; chk < start; chk++)
2775 if (!do_loc && die_offset >= dwarf_start_die
2776 && (dwarf_cutoff_level == -1
2777 || level < dwarf_cutoff_level))
2778 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2784 static unsigned num_bogus_warns = 0;
2786 if (num_bogus_warns < 3)
2788 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2789 die_offset, section->name);
2791 if (num_bogus_warns == 3)
2792 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2795 if (dwarf_start_die != 0 && level < saved_level)
2802 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2806 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2807 saved_level = level;
2808 do_printing = (dwarf_cutoff_level == -1
2809 || level < dwarf_cutoff_level);
2811 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2812 level, die_offset, abbrev_number);
2813 else if (dwarf_cutoff_level == -1
2814 || last_level < dwarf_cutoff_level)
2815 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2820 /* Scan through the abbreviation list until we reach the
2822 for (entry = first_abbrev;
2823 entry && entry->entry != abbrev_number;
2824 entry = entry->next)
2829 if (!do_loc && do_printing)
2834 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2835 die_offset, abbrev_number);
2839 if (!do_loc && do_printing)
2840 printf (" (%s)\n", get_TAG_name (entry->tag));
2845 need_base_address = 0;
2847 case DW_TAG_compile_unit:
2848 need_base_address = 1;
2850 case DW_TAG_entry_point:
2851 case DW_TAG_subprogram:
2852 need_base_address = 0;
2853 /* Assuming that there is no DW_AT_frame_base. */
2854 have_frame_base = 0;
2858 for (attr = entry->first_attr;
2859 attr && attr->attribute;
2864 if (! do_loc && do_printing)
2865 /* Show the offset from where the tag was extracted. */
2866 printf (" <%lx>", (unsigned long)(tags - section_begin));
2868 if (debug_information && unit < alloc_num_debug_info_entries)
2869 arg = debug_information + unit;
2873 tags = read_and_display_attr (attr->attribute,
2875 attr->implicit_const,
2879 compunit.cu_pointer_size,
2881 compunit.cu_version,
2883 do_loc || ! do_printing,
2888 if (entry->children)
2893 /* Set num_debug_info_entries here so that it can be used to check if
2894 we need to process .debug_loc and .debug_ranges sections. */
2895 if ((do_loc || do_debug_loc || do_debug_ranges)
2896 && num_debug_info_entries == 0
2899 if (num_units > alloc_num_debug_info_entries)
2900 num_debug_info_entries = alloc_num_debug_info_entries;
2902 num_debug_info_entries = num_units;
2911 /* Locate and scan the .debug_info section in the file and record the pointer
2912 sizes and offsets for the compilation units in it. Usually an executable
2913 will have just one pointer size, but this is not guaranteed, and so we try
2914 not to make any assumptions. Returns zero upon failure, or the number of
2915 compilation units upon success. */
2918 load_debug_info (void * file)
2920 /* Reset the last pointer size so that we can issue correct error
2921 messages if we are displaying the contents of more than one section. */
2922 last_pointer_size = 0;
2923 warned_about_missing_comp_units = FALSE;
2925 /* If we have already tried and failed to load the .debug_info
2926 section then do not bother to repeat the task. */
2927 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2930 /* If we already have the information there is nothing else to do. */
2931 if (num_debug_info_entries > 0)
2932 return num_debug_info_entries;
2934 /* If this is a DWARF package file, load the CU and TU indexes. */
2935 (void) load_cu_tu_indexes (file);
2937 if (load_debug_section (info, file)
2938 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2939 return num_debug_info_entries;
2941 if (load_debug_section (info_dwo, file)
2942 && process_debug_info (&debug_displays [info_dwo].section, file,
2944 return num_debug_info_entries;
2946 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2950 /* Read a DWARF .debug_line section header starting at DATA.
2951 Upon success returns an updated DATA pointer and the LINFO
2952 structure and the END_OF_SEQUENCE pointer will be filled in.
2953 Otherwise returns NULL. */
2955 static unsigned char *
2956 read_debug_line_header (struct dwarf_section * section,
2957 unsigned char * data,
2958 unsigned char * end,
2959 DWARF2_Internal_LineInfo * linfo,
2960 unsigned char ** end_of_sequence)
2962 unsigned char *hdrptr;
2963 unsigned int initial_length_size;
2964 unsigned char address_size, segment_selector_size;
2966 /* Extract information from the Line Number Program Header.
2967 (section 6.2.4 in the Dwarf3 doc). */
2970 /* Get and check the length of the block. */
2971 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2973 if (linfo->li_length == 0xffffffff)
2975 /* This section is 64-bit DWARF 3. */
2976 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2977 linfo->li_offset_size = 8;
2978 initial_length_size = 12;
2982 linfo->li_offset_size = 4;
2983 initial_length_size = 4;
2986 if (linfo->li_length + initial_length_size > section->size)
2988 /* If the length field has a relocation against it, then we should
2989 not complain if it is inaccurate (and probably negative). This
2990 happens in object files when the .debug_line section is actually
2991 comprised of several different .debug_line.* sections, (some of
2992 which may be removed by linker garbage collection), and a relocation
2993 is used to compute the correct length once that is done. */
2994 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
2996 linfo->li_length = (end - data) - initial_length_size;
3000 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3001 (long) linfo->li_length);
3006 /* Get and check the version number. */
3007 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3009 if (linfo->li_version != 2
3010 && linfo->li_version != 3
3011 && linfo->li_version != 4
3012 && linfo->li_version != 5)
3014 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3015 "is currently supported.\n"));
3019 if (linfo->li_version >= 5)
3021 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3023 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3024 if (segment_selector_size != 0)
3026 warn (_("The %s section contains "
3027 "unsupported segment selector size: %d.\n"),
3028 section->name, segment_selector_size);
3033 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3034 linfo->li_offset_size, end);
3035 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3037 if (linfo->li_version >= 4)
3039 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3041 if (linfo->li_max_ops_per_insn == 0)
3043 warn (_("Invalid maximum operations per insn.\n"));
3048 linfo->li_max_ops_per_insn = 1;
3050 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3051 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3052 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3053 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3055 * end_of_sequence = data + linfo->li_length + initial_length_size;
3056 /* PR 17512: file:002-117414-0.004. */
3057 if (* end_of_sequence > end)
3059 warn (_("Line length %s extends beyond end of section\n"),
3060 dwarf_vmatoa ("u", linfo->li_length));
3061 * end_of_sequence = end;
3068 static unsigned char *
3069 display_formatted_table (unsigned char *data,
3070 unsigned char *start, unsigned char *end,
3071 const DWARF2_Internal_LineInfo *linfo,
3072 struct dwarf_section *section, const char *what)
3074 unsigned char *format_start, format_count, *format, formati;
3075 dwarf_vma data_count, datai;
3076 unsigned int bytes_read, namepass, last_entry = 0;
3078 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3079 format_start = data;
3080 for (formati = 0; formati < format_count; formati++)
3082 read_uleb128 (data, & bytes_read, end);
3084 read_uleb128 (data, & bytes_read, end);
3088 warn (_("Corrupt %s format table entry\n"), what);
3093 data_count = read_uleb128 (data, & bytes_read, end);
3097 warn (_("Corrupt %s list\n"), what);
3101 if (data_count == 0)
3103 printf (_("\n The %s Table is empty.\n"), what);
3107 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3108 (long)(data - start));
3110 printf (_(" Entry"));
3111 /* Delay displaying name as the last entry for better screen layout. */
3112 for (namepass = 0; namepass < 2; namepass++)
3114 format = format_start;
3115 for (formati = 0; formati < format_count; formati++)
3117 dwarf_vma content_type;
3119 content_type = read_uleb128 (format, & bytes_read, end);
3120 format += bytes_read;
3121 if ((content_type == DW_LNCT_path) == (namepass == 1))
3122 switch (content_type)
3125 printf (_("\tName"));
3127 case DW_LNCT_directory_index:
3128 printf (_("\tDir"));
3130 case DW_LNCT_timestamp:
3131 printf (_("\tTime"));
3134 printf (_("\tSize"));
3137 printf (_("\tMD5"));
3140 printf (_("\t(Unknown format content type %s)"),
3141 dwarf_vmatoa ("u", content_type));
3143 read_uleb128 (format, & bytes_read, end);
3144 format += bytes_read;
3149 for (datai = 0; datai < data_count; datai++)
3151 unsigned char *datapass = data;
3153 printf (" %d", last_entry++);
3154 /* Delay displaying name as the last entry for better screen layout. */
3155 for (namepass = 0; namepass < 2; namepass++)
3157 format = format_start;
3159 for (formati = 0; formati < format_count; formati++)
3161 dwarf_vma content_type, form;
3163 content_type = read_uleb128 (format, & bytes_read, end);
3164 format += bytes_read;
3165 form = read_uleb128 (format, & bytes_read, end);
3166 format += bytes_read;
3167 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3168 linfo->li_offset_size,
3169 linfo->li_version, NULL,
3170 ((content_type == DW_LNCT_path) != (namepass == 1)),
3171 section, NULL, '\t');
3176 warn (_("Corrupt %s entries list\n"), what);
3185 display_debug_lines_raw (struct dwarf_section *section,
3186 unsigned char *data,
3187 unsigned char *end, void *file)
3189 unsigned char *start = section->start;
3191 printf (_("Raw dump of debug contents of section %s:\n\n"),
3196 static DWARF2_Internal_LineInfo saved_linfo;
3197 DWARF2_Internal_LineInfo linfo;
3198 unsigned char *standard_opcodes;
3199 unsigned char *end_of_sequence;
3202 if (const_strneq (section->name, ".debug_line.")
3203 /* Note: the following does not apply to .debug_line.dwo sections.
3204 These are full debug_line sections. */
3205 && strcmp (section->name, ".debug_line.dwo") != 0)
3207 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3208 section containing just the Line Number Statements. They are
3209 created by the assembler and intended to be used alongside gcc's
3210 -ffunction-sections command line option. When the linker's
3211 garbage collection decides to discard a .text.<foo> section it
3212 can then also discard the line number information in .debug_line.<foo>.
3214 Since the section is a fragment it does not have the details
3215 needed to fill out a LineInfo structure, so instead we use the
3216 details from the last full debug_line section that we processed. */
3217 end_of_sequence = end;
3218 standard_opcodes = NULL;
3219 linfo = saved_linfo;
3220 /* PR 17531: file: 0522b371. */
3221 if (linfo.li_line_range == 0)
3223 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3226 reset_state_machine (linfo.li_default_is_stmt);
3230 unsigned char * hdrptr;
3232 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3233 & end_of_sequence)) == NULL)
3236 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3237 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3238 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3239 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3240 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3241 if (linfo.li_version >= 4)
3242 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3243 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3244 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3245 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3246 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3248 /* PR 17512: file: 1665-6428-0.004. */
3249 if (linfo.li_line_range == 0)
3251 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3252 linfo.li_line_range = 1;
3255 reset_state_machine (linfo.li_default_is_stmt);
3257 /* Display the contents of the Opcodes table. */
3258 standard_opcodes = hdrptr;
3260 /* PR 17512: file: 002-417945-0.004. */
3261 if (standard_opcodes + linfo.li_opcode_base >= end)
3263 warn (_("Line Base extends beyond end of section\n"));
3267 printf (_("\n Opcodes:\n"));
3269 for (i = 1; i < linfo.li_opcode_base; i++)
3270 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3272 /* Display the contents of the Directory table. */
3273 data = standard_opcodes + linfo.li_opcode_base - 1;
3275 if (linfo.li_version >= 5)
3277 load_debug_section (line_str, file);
3279 data = display_formatted_table (data, start, end, &linfo, section,
3281 data = display_formatted_table (data, start, end, &linfo, section,
3287 printf (_("\n The Directory Table is empty.\n"));
3290 unsigned int last_dir_entry = 0;
3292 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3293 (long)(data - start));
3295 while (data < end && *data != 0)
3297 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3299 data += strnlen ((char *) data, end - data) + 1;
3302 /* PR 17512: file: 002-132094-0.004. */
3303 if (data >= end - 1)
3307 /* Skip the NUL at the end of the table. */
3310 /* Display the contents of the File Name table. */
3312 printf (_("\n The File Name Table is empty.\n"));
3315 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3316 (long)(data - start));
3317 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3319 while (data < end && *data != 0)
3321 unsigned char *name;
3322 unsigned int bytes_read;
3324 printf (" %d\t", ++state_machine_regs.last_file_entry);
3326 data += strnlen ((char *) data, end - data) + 1;
3329 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3332 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3335 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3337 printf ("%.*s\n", (int)(end - name), name);
3341 warn (_("Corrupt file name table entry\n"));
3347 /* Skip the NUL at the end of the table. */
3352 saved_linfo = linfo;
3355 /* Now display the statements. */
3356 if (data >= end_of_sequence)
3357 printf (_(" No Line Number Statements.\n"));
3360 printf (_(" Line Number Statements:\n"));
3362 while (data < end_of_sequence)
3364 unsigned char op_code;
3365 dwarf_signed_vma adv;
3367 unsigned int bytes_read;
3369 printf (" [0x%08lx]", (long)(data - start));
3373 if (op_code >= linfo.li_opcode_base)
3375 op_code -= linfo.li_opcode_base;
3376 uladv = (op_code / linfo.li_line_range);
3377 if (linfo.li_max_ops_per_insn == 1)
3379 uladv *= linfo.li_min_insn_length;
3380 state_machine_regs.address += uladv;
3381 printf (_(" Special opcode %d: "
3382 "advance Address by %s to 0x%s"),
3383 op_code, dwarf_vmatoa ("u", uladv),
3384 dwarf_vmatoa ("x", state_machine_regs.address));
3388 state_machine_regs.address
3389 += ((state_machine_regs.op_index + uladv)
3390 / linfo.li_max_ops_per_insn)
3391 * linfo.li_min_insn_length;
3392 state_machine_regs.op_index
3393 = (state_machine_regs.op_index + uladv)
3394 % linfo.li_max_ops_per_insn;
3395 printf (_(" Special opcode %d: "
3396 "advance Address by %s to 0x%s[%d]"),
3397 op_code, dwarf_vmatoa ("u", uladv),
3398 dwarf_vmatoa ("x", state_machine_regs.address),
3399 state_machine_regs.op_index);
3401 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3402 state_machine_regs.line += adv;
3403 printf (_(" and Line by %s to %d\n"),
3404 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3406 else switch (op_code)
3408 case DW_LNS_extended_op:
3409 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3413 printf (_(" Copy\n"));
3416 case DW_LNS_advance_pc:
3417 uladv = read_uleb128 (data, & bytes_read, end);
3419 if (linfo.li_max_ops_per_insn == 1)
3421 uladv *= linfo.li_min_insn_length;
3422 state_machine_regs.address += uladv;
3423 printf (_(" Advance PC by %s to 0x%s\n"),
3424 dwarf_vmatoa ("u", uladv),
3425 dwarf_vmatoa ("x", state_machine_regs.address));
3429 state_machine_regs.address
3430 += ((state_machine_regs.op_index + uladv)
3431 / linfo.li_max_ops_per_insn)
3432 * linfo.li_min_insn_length;
3433 state_machine_regs.op_index
3434 = (state_machine_regs.op_index + uladv)
3435 % linfo.li_max_ops_per_insn;
3436 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3437 dwarf_vmatoa ("u", uladv),
3438 dwarf_vmatoa ("x", state_machine_regs.address),
3439 state_machine_regs.op_index);
3443 case DW_LNS_advance_line:
3444 adv = read_sleb128 (data, & bytes_read, end);
3446 state_machine_regs.line += adv;
3447 printf (_(" Advance Line by %s to %d\n"),
3448 dwarf_vmatoa ("d", adv),
3449 state_machine_regs.line);
3452 case DW_LNS_set_file:
3453 adv = read_uleb128 (data, & bytes_read, end);
3455 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3456 dwarf_vmatoa ("d", adv));
3457 state_machine_regs.file = adv;
3460 case DW_LNS_set_column:
3461 uladv = read_uleb128 (data, & bytes_read, end);
3463 printf (_(" Set column to %s\n"),
3464 dwarf_vmatoa ("u", uladv));
3465 state_machine_regs.column = uladv;
3468 case DW_LNS_negate_stmt:
3469 adv = state_machine_regs.is_stmt;
3471 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3472 state_machine_regs.is_stmt = adv;
3475 case DW_LNS_set_basic_block:
3476 printf (_(" Set basic block\n"));
3477 state_machine_regs.basic_block = 1;
3480 case DW_LNS_const_add_pc:
3481 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3482 if (linfo.li_max_ops_per_insn)
3484 uladv *= linfo.li_min_insn_length;
3485 state_machine_regs.address += uladv;
3486 printf (_(" Advance PC by constant %s to 0x%s\n"),
3487 dwarf_vmatoa ("u", uladv),
3488 dwarf_vmatoa ("x", state_machine_regs.address));
3492 state_machine_regs.address
3493 += ((state_machine_regs.op_index + uladv)
3494 / linfo.li_max_ops_per_insn)
3495 * linfo.li_min_insn_length;
3496 state_machine_regs.op_index
3497 = (state_machine_regs.op_index + uladv)
3498 % linfo.li_max_ops_per_insn;
3499 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3500 dwarf_vmatoa ("u", uladv),
3501 dwarf_vmatoa ("x", state_machine_regs.address),
3502 state_machine_regs.op_index);
3506 case DW_LNS_fixed_advance_pc:
3507 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3508 state_machine_regs.address += uladv;
3509 state_machine_regs.op_index = 0;
3510 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3511 dwarf_vmatoa ("u", uladv),
3512 dwarf_vmatoa ("x", state_machine_regs.address));
3515 case DW_LNS_set_prologue_end:
3516 printf (_(" Set prologue_end to true\n"));
3519 case DW_LNS_set_epilogue_begin:
3520 printf (_(" Set epilogue_begin to true\n"));
3523 case DW_LNS_set_isa:
3524 uladv = read_uleb128 (data, & bytes_read, end);
3526 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3530 printf (_(" Unknown opcode %d with operands: "), op_code);
3532 if (standard_opcodes != NULL)
3533 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3535 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3537 i == 1 ? "" : ", ");
3553 unsigned char *name;
3554 unsigned int directory_index;
3555 unsigned int modification_date;
3556 unsigned int length;
3559 /* Output a decoded representation of the .debug_line section. */
3562 display_debug_lines_decoded (struct dwarf_section *section,
3563 unsigned char *data,
3564 unsigned char *end, void *fileptr)
3566 static DWARF2_Internal_LineInfo saved_linfo;
3568 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3573 /* This loop amounts to one iteration per compilation unit. */
3574 DWARF2_Internal_LineInfo linfo;
3575 unsigned char *standard_opcodes;
3576 unsigned char *end_of_sequence;
3578 File_Entry *file_table = NULL;
3579 unsigned int n_files = 0;
3580 unsigned char **directory_table = NULL;
3581 dwarf_vma n_directories = 0;
3583 if (const_strneq (section->name, ".debug_line.")
3584 /* Note: the following does not apply to .debug_line.dwo sections.
3585 These are full debug_line sections. */
3586 && strcmp (section->name, ".debug_line.dwo") != 0)
3588 /* See comment in display_debug_lines_raw(). */
3589 end_of_sequence = end;
3590 standard_opcodes = NULL;
3591 linfo = saved_linfo;
3592 /* PR 17531: file: 0522b371. */
3593 if (linfo.li_line_range == 0)
3595 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3598 reset_state_machine (linfo.li_default_is_stmt);
3602 unsigned char *hdrptr;
3604 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3605 & end_of_sequence)) == NULL)
3608 /* PR 17531: file: 0522b371. */
3609 if (linfo.li_line_range == 0)
3611 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3612 linfo.li_line_range = 1;
3614 reset_state_machine (linfo.li_default_is_stmt);
3616 /* Save a pointer to the contents of the Opcodes table. */
3617 standard_opcodes = hdrptr;
3619 /* Traverse the Directory table just to count entries. */
3620 data = standard_opcodes + linfo.li_opcode_base - 1;
3624 warn (_("opcode base of %d extends beyond end of section\n"),
3625 linfo.li_opcode_base);
3629 if (linfo.li_version >= 5)
3631 unsigned char *format_start, format_count, *format;
3632 dwarf_vma formati, entryi;
3633 unsigned int bytes_read;
3635 load_debug_section (line_str, fileptr);
3637 /* Skip directories format. */
3638 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3639 format_start = data;
3640 for (formati = 0; formati < format_count; formati++)
3642 read_uleb128 (data, & bytes_read, end);
3644 read_uleb128 (data, & bytes_read, end);
3648 n_directories = read_uleb128 (data, & bytes_read, end);
3652 warn (_("Corrupt directories list\n"));
3656 directory_table = (unsigned char **)
3657 xmalloc (n_directories * sizeof (unsigned char *));
3659 for (entryi = 0; entryi < n_directories; entryi++)
3661 unsigned char **pathp = &directory_table[entryi];
3663 format = format_start;
3664 for (formati = 0; formati < format_count; formati++)
3666 dwarf_vma content_type, form;
3669 content_type = read_uleb128 (format, & bytes_read, end);
3670 format += bytes_read;
3671 form = read_uleb128 (format, & bytes_read, end);
3672 format += bytes_read;
3675 warn (_("Corrupt directories list\n"));
3678 switch (content_type)
3683 case DW_FORM_string:
3686 case DW_FORM_line_strp:
3687 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3689 /* Remove const by the cast. */
3690 *pathp = (unsigned char *)
3691 fetch_indirect_line_string (uvalue);
3696 data = read_and_display_attr_value (0, form, 0, data, end,
3698 linfo.li_offset_size,
3705 warn (_("Corrupt directories list\n"));
3710 /* Skip files format. */
3711 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3712 format_start = data;
3713 for (formati = 0; formati < format_count; formati++)
3715 read_uleb128 (data, & bytes_read, end);
3717 read_uleb128 (data, & bytes_read, end);
3721 n_files = read_uleb128 (data, & bytes_read, end);
3725 warn (_("Corrupt file name list\n"));
3729 file_table = (File_Entry *) xcalloc (1, n_files
3730 * sizeof (File_Entry));
3732 for (entryi = 0; entryi < n_files; entryi++)
3734 File_Entry *file = &file_table[entryi];
3736 format = format_start;
3737 for (formati = 0; formati < format_count; formati++)
3739 dwarf_vma content_type, form;
3742 content_type = read_uleb128 (format, & bytes_read, end);
3743 format += bytes_read;
3744 form = read_uleb128 (format, & bytes_read, end);
3745 format += bytes_read;
3748 warn (_("Corrupt file name list\n"));
3751 switch (content_type)
3756 case DW_FORM_string:
3759 case DW_FORM_line_strp:
3760 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3762 /* Remove const by the cast. */
3763 file->name = (unsigned char *)
3764 fetch_indirect_line_string (uvalue);
3768 case DW_LNCT_directory_index:
3772 SAFE_BYTE_GET (file->directory_index, data, 1,
3776 SAFE_BYTE_GET (file->directory_index, data, 2,
3780 file->directory_index = read_uleb128 (data, NULL,
3786 data = read_and_display_attr_value (0, form, 0, data, end,
3788 linfo.li_offset_size,
3795 warn (_("Corrupt file name list\n"));
3804 unsigned char *ptr_directory_table = data;
3806 while (data < end && *data != 0)
3808 data += strnlen ((char *) data, end - data) + 1;
3815 warn (_("directory table ends unexpectedly\n"));
3820 /* Go through the directory table again to save the directories. */
3821 directory_table = (unsigned char **)
3822 xmalloc (n_directories * sizeof (unsigned char *));
3825 while (*ptr_directory_table != 0)
3827 directory_table[i] = ptr_directory_table;
3828 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3829 ptr_directory_table - end) + 1;
3833 /* Skip the NUL at the end of the table. */
3836 /* Traverse the File Name table just to count the entries. */
3837 if (data < end && *data != 0)
3839 unsigned char *ptr_file_name_table = data;
3841 while (data < end && *data != 0)
3843 unsigned int bytes_read;
3845 /* Skip Name, directory index, last modification time and length
3847 data += strnlen ((char *) data, end - data) + 1;
3848 read_uleb128 (data, & bytes_read, end);
3850 read_uleb128 (data, & bytes_read, end);
3852 read_uleb128 (data, & bytes_read, end);
3860 warn (_("file table ends unexpectedly\n"));
3865 /* Go through the file table again to save the strings. */
3866 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3869 while (*ptr_file_name_table != 0)
3871 unsigned int bytes_read;
3873 file_table[i].name = ptr_file_name_table;
3874 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3875 end - ptr_file_name_table) + 1;
3877 /* We are not interested in directory, time or size. */
3878 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3880 ptr_file_name_table += bytes_read;
3881 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3883 ptr_file_name_table += bytes_read;
3884 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3885 ptr_file_name_table += bytes_read;
3891 /* Skip the NUL at the end of the table. */
3895 /* Print the Compilation Unit's name and a header. */
3896 if (file_table == NULL)
3898 else if (directory_table == NULL)
3899 printf (_("CU: %s:\n"), file_table[0].name);
3902 unsigned int ix = file_table[0].directory_index;
3903 const char *directory;
3908 else if (n_directories == 0)
3909 directory = _("<unknown>");
3910 else if (ix > n_directories)
3912 warn (_("directory index %u > number of directories %s\n"),
3913 ix, dwarf_vmatoa ("u", n_directories));
3914 directory = _("<corrupt>");
3917 directory = (char *) directory_table[ix - 1];
3919 if (do_wide || strlen (directory) < 76)
3920 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3922 printf ("%s:\n", file_table[0].name);
3925 printf (_("File name Line number Starting address\n"));
3926 saved_linfo = linfo;
3929 /* This loop iterates through the Dwarf Line Number Program. */
3930 while (data < end_of_sequence)
3932 unsigned char op_code;
3934 unsigned long int uladv;
3935 unsigned int bytes_read;
3936 int is_special_opcode = 0;
3940 if (op_code >= linfo.li_opcode_base)
3942 op_code -= linfo.li_opcode_base;
3943 uladv = (op_code / linfo.li_line_range);
3944 if (linfo.li_max_ops_per_insn == 1)
3946 uladv *= linfo.li_min_insn_length;
3947 state_machine_regs.address += uladv;
3951 state_machine_regs.address
3952 += ((state_machine_regs.op_index + uladv)
3953 / linfo.li_max_ops_per_insn)
3954 * linfo.li_min_insn_length;
3955 state_machine_regs.op_index
3956 = (state_machine_regs.op_index + uladv)
3957 % linfo.li_max_ops_per_insn;
3960 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3961 state_machine_regs.line += adv;
3962 is_special_opcode = 1;
3964 else switch (op_code)
3966 case DW_LNS_extended_op:
3968 unsigned int ext_op_code_len;
3969 unsigned char ext_op_code;
3970 unsigned char *op_code_data = data;
3972 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3974 op_code_data += bytes_read;
3976 if (ext_op_code_len == 0)
3978 warn (_("Badly formed extended line op encountered!\n"));
3981 ext_op_code_len += bytes_read;
3982 ext_op_code = *op_code_data++;
3984 switch (ext_op_code)
3986 case DW_LNE_end_sequence:
3987 reset_state_machine (linfo.li_default_is_stmt);
3989 case DW_LNE_set_address:
3990 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3992 ext_op_code_len - bytes_read - 1,
3994 state_machine_regs.op_index = 0;
3996 case DW_LNE_define_file:
3998 file_table = (File_Entry *) xrealloc
3999 (file_table, (n_files + 1) * sizeof (File_Entry));
4001 ++state_machine_regs.last_file_entry;
4002 /* Source file name. */
4003 file_table[n_files].name = op_code_data;
4004 op_code_data += strlen ((char *) op_code_data) + 1;
4005 /* Directory index. */
4006 file_table[n_files].directory_index =
4007 read_uleb128 (op_code_data, & bytes_read,
4009 op_code_data += bytes_read;
4010 /* Last modification time. */
4011 file_table[n_files].modification_date =
4012 read_uleb128 (op_code_data, & bytes_read,
4014 op_code_data += bytes_read;
4016 file_table[n_files].length =
4017 read_uleb128 (op_code_data, & bytes_read,
4023 case DW_LNE_set_discriminator:
4024 case DW_LNE_HP_set_sequence:
4025 /* Simply ignored. */
4029 printf (_("UNKNOWN (%u): length %d\n"),
4030 ext_op_code, ext_op_code_len - bytes_read);
4033 data += ext_op_code_len;
4039 case DW_LNS_advance_pc:
4040 uladv = read_uleb128 (data, & bytes_read, end);
4042 if (linfo.li_max_ops_per_insn == 1)
4044 uladv *= linfo.li_min_insn_length;
4045 state_machine_regs.address += uladv;
4049 state_machine_regs.address
4050 += ((state_machine_regs.op_index + uladv)
4051 / linfo.li_max_ops_per_insn)
4052 * linfo.li_min_insn_length;
4053 state_machine_regs.op_index
4054 = (state_machine_regs.op_index + uladv)
4055 % linfo.li_max_ops_per_insn;
4059 case DW_LNS_advance_line:
4060 adv = read_sleb128 (data, & bytes_read, end);
4062 state_machine_regs.line += adv;
4065 case DW_LNS_set_file:
4066 adv = read_uleb128 (data, & bytes_read, end);
4068 state_machine_regs.file = adv;
4071 unsigned file = state_machine_regs.file - 1;
4074 if (file_table == NULL || n_files == 0)
4075 printf (_("\n [Use file table entry %d]\n"), file);
4077 else if (file >= n_files)
4079 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4080 printf (_("\n <over large file table index %u>"), file);
4082 else if ((dir = file_table[file].directory_index) == 0)
4083 /* If directory index is 0, that means current directory. */
4084 printf ("\n./%s:[++]\n", file_table[file].name);
4085 else if (directory_table == NULL || n_directories == 0)
4086 printf (_("\n [Use file %s in directory table entry %d]\n"),
4087 file_table[file].name, dir);
4089 else if (dir > n_directories)
4091 warn (_("directory index %u > number of directories %s\n"),
4092 dir, dwarf_vmatoa ("u", n_directories));
4093 printf (_("\n <over large directory table entry %u>\n"), dir);
4096 printf ("\n%s/%s:\n",
4097 /* The directory index starts counting at 1. */
4098 directory_table[dir - 1], file_table[file].name);
4102 case DW_LNS_set_column:
4103 uladv = read_uleb128 (data, & bytes_read, end);
4105 state_machine_regs.column = uladv;
4108 case DW_LNS_negate_stmt:
4109 adv = state_machine_regs.is_stmt;
4111 state_machine_regs.is_stmt = adv;
4114 case DW_LNS_set_basic_block:
4115 state_machine_regs.basic_block = 1;
4118 case DW_LNS_const_add_pc:
4119 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4120 if (linfo.li_max_ops_per_insn == 1)
4122 uladv *= linfo.li_min_insn_length;
4123 state_machine_regs.address += uladv;
4127 state_machine_regs.address
4128 += ((state_machine_regs.op_index + uladv)
4129 / linfo.li_max_ops_per_insn)
4130 * linfo.li_min_insn_length;
4131 state_machine_regs.op_index
4132 = (state_machine_regs.op_index + uladv)
4133 % linfo.li_max_ops_per_insn;
4137 case DW_LNS_fixed_advance_pc:
4138 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4139 state_machine_regs.address += uladv;
4140 state_machine_regs.op_index = 0;
4143 case DW_LNS_set_prologue_end:
4146 case DW_LNS_set_epilogue_begin:
4149 case DW_LNS_set_isa:
4150 uladv = read_uleb128 (data, & bytes_read, end);
4152 printf (_(" Set ISA to %lu\n"), uladv);
4156 printf (_(" Unknown opcode %d with operands: "), op_code);
4158 if (standard_opcodes != NULL)
4159 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4161 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4163 i == 1 ? "" : ", ");
4170 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4171 to the DWARF address/line matrix. */
4172 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
4173 || (op_code == DW_LNS_copy))
4175 const unsigned int MAX_FILENAME_LENGTH = 35;
4177 char *newFileName = NULL;
4178 size_t fileNameLength;
4182 unsigned indx = state_machine_regs.file - 1;
4184 if (indx >= n_files)
4186 warn (_("corrupt file index %u encountered\n"), indx);
4187 fileName = _("<corrupt>");
4190 fileName = (char *) file_table[indx].name;
4193 fileName = _("<unknown>");
4195 fileNameLength = strlen (fileName);
4197 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4199 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4200 /* Truncate file name */
4201 strncpy (newFileName,
4202 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4203 MAX_FILENAME_LENGTH + 1);
4207 newFileName = (char *) xmalloc (fileNameLength + 1);
4208 strncpy (newFileName, fileName, fileNameLength + 1);
4211 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4213 if (linfo.li_max_ops_per_insn == 1)
4214 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
4215 newFileName, state_machine_regs.line,
4216 state_machine_regs.address);
4218 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4219 newFileName, state_machine_regs.line,
4220 state_machine_regs.address,
4221 state_machine_regs.op_index);
4225 if (linfo.li_max_ops_per_insn == 1)
4226 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
4227 newFileName, state_machine_regs.line,
4228 state_machine_regs.address);
4230 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4231 newFileName, state_machine_regs.line,
4232 state_machine_regs.address,
4233 state_machine_regs.op_index);
4236 if (op_code == DW_LNE_end_sequence)
4250 if (directory_table)
4252 free (directory_table);
4253 directory_table = NULL;
4264 display_debug_lines (struct dwarf_section *section, void *file)
4266 unsigned char *data = section->start;
4267 unsigned char *end = data + section->size;
4269 int retValDecoded = 1;
4271 if (do_debug_lines == 0)
4272 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4274 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4275 retValRaw = display_debug_lines_raw (section, data, end, file);
4277 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4278 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4280 if (!retValRaw || !retValDecoded)
4287 find_debug_info_for_offset (unsigned long offset)
4291 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4294 for (i = 0; i < num_debug_info_entries; i++)
4295 if (debug_information[i].cu_offset == offset)
4296 return debug_information + i;
4302 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4304 /* See gdb/gdb-index.h. */
4305 static const char * const kinds[] =
4317 return _ (kinds[kind]);
4321 display_debug_pubnames_worker (struct dwarf_section *section,
4322 void *file ATTRIBUTE_UNUSED,
4325 DWARF2_Internal_PubNames names;
4326 unsigned char *start = section->start;
4327 unsigned char *end = start + section->size;
4329 /* It does not matter if this load fails,
4330 we test for that later on. */
4331 load_debug_info (file);
4333 printf (_("Contents of the %s section:\n\n"), section->name);
4337 unsigned char *data;
4340 unsigned int offset_size, initial_length_size;
4344 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4345 if (names.pn_length == 0xffffffff)
4347 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4349 initial_length_size = 12;
4354 initial_length_size = 4;
4357 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4358 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4360 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4361 && num_debug_info_entries > 0
4362 && find_debug_info_for_offset (names.pn_offset) == NULL)
4363 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4364 (unsigned long) names.pn_offset, section->name);
4366 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4368 adr = start + names.pn_length + initial_length_size;
4369 /* PR 17531: file: 7615b6b2. */
4370 if ((dwarf_signed_vma) names.pn_length < 0
4371 /* PR 17531: file: a5dbeaa7. */
4374 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4380 printf (_(" Length: %ld\n"),
4381 (long) names.pn_length);
4382 printf (_(" Version: %d\n"),
4384 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4385 (unsigned long) names.pn_offset);
4386 printf (_(" Size of area in .debug_info section: %ld\n"),
4387 (long) names.pn_size);
4389 if (names.pn_version != 2 && names.pn_version != 3)
4391 static int warned = 0;
4395 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4403 printf (_("\n Offset Kind Name\n"));
4405 printf (_("\n Offset\tName\n"));
4409 bfd_size_type maxprint;
4411 SAFE_BYTE_GET (offset, data, offset_size, end);
4415 data += offset_size;
4418 maxprint = (end - data) - 1;
4422 unsigned int kind_data;
4423 gdb_index_symbol_kind kind;
4424 const char *kind_name;
4427 SAFE_BYTE_GET (kind_data, data, 1, end);
4430 /* GCC computes the kind as the upper byte in the CU index
4431 word, and then right shifts it by the CU index size.
4432 Left shift KIND to where the gdb-index.h accessor macros
4434 kind_data <<= GDB_INDEX_CU_BITSIZE;
4435 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4436 kind_name = get_gdb_index_symbol_kind_name (kind);
4437 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4438 printf (" %-6lx %s,%-10s %.*s\n",
4439 (unsigned long) offset, is_static ? _("s") : _("g"),
4440 kind_name, (int) maxprint, data);
4443 printf (" %-6lx\t%.*s\n",
4444 (unsigned long) offset, (int) maxprint, data);
4446 data += strnlen ((char *) data, maxprint) + 1;
4451 while (offset != 0);
4459 display_debug_pubnames (struct dwarf_section *section, void *file)
4461 return display_debug_pubnames_worker (section, file, 0);
4465 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4467 return display_debug_pubnames_worker (section, file, 1);
4471 display_debug_macinfo (struct dwarf_section *section,
4472 void *file ATTRIBUTE_UNUSED)
4474 unsigned char *start = section->start;
4475 unsigned char *end = start + section->size;
4476 unsigned char *curr = start;
4477 unsigned int bytes_read;
4478 enum dwarf_macinfo_record_type op;
4480 printf (_("Contents of the %s section:\n\n"), section->name);
4484 unsigned int lineno;
4485 const unsigned char *string;
4487 op = (enum dwarf_macinfo_record_type) *curr;
4492 case DW_MACINFO_start_file:
4494 unsigned int filenum;
4496 lineno = read_uleb128 (curr, & bytes_read, end);
4498 filenum = read_uleb128 (curr, & bytes_read, end);
4501 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4506 case DW_MACINFO_end_file:
4507 printf (_(" DW_MACINFO_end_file\n"));
4510 case DW_MACINFO_define:
4511 lineno = read_uleb128 (curr, & bytes_read, end);
4514 curr += strnlen ((char *) string, end - string) + 1;
4515 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4519 case DW_MACINFO_undef:
4520 lineno = read_uleb128 (curr, & bytes_read, end);
4523 curr += strnlen ((char *) string, end - string) + 1;
4524 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4528 case DW_MACINFO_vendor_ext:
4530 unsigned int constant;
4532 constant = read_uleb128 (curr, & bytes_read, end);
4535 curr += strnlen ((char *) string, end - string) + 1;
4536 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4546 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4547 filename and dirname corresponding to file name table entry with index
4548 FILEIDX. Return NULL on failure. */
4550 static unsigned char *
4551 get_line_filename_and_dirname (dwarf_vma line_offset,
4553 unsigned char **dir_name)
4555 struct dwarf_section *section = &debug_displays [line].section;
4556 unsigned char *hdrptr, *dirtable, *file_name;
4557 unsigned int offset_size, initial_length_size;
4558 unsigned int version, opcode_base, bytes_read;
4559 dwarf_vma length, diridx;
4560 const unsigned char * end;
4563 if (section->start == NULL
4564 || line_offset >= section->size
4568 hdrptr = section->start + line_offset;
4569 end = section->start + section->size;
4571 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4572 if (length == 0xffffffff)
4574 /* This section is 64-bit DWARF 3. */
4575 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4577 initial_length_size = 12;
4582 initial_length_size = 4;
4584 if (length + initial_length_size > section->size)
4587 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4588 if (version != 2 && version != 3 && version != 4)
4590 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4592 hdrptr++; /* Skip max_ops_per_insn. */
4593 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4595 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4596 if (opcode_base == 0)
4599 hdrptr += opcode_base - 1;
4601 /* Skip over dirname table. */
4602 while (*hdrptr != '\0')
4603 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4604 hdrptr++; /* Skip the NUL at the end of the table. */
4605 /* Now skip over preceding filename table entries. */
4606 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4608 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4609 read_uleb128 (hdrptr, &bytes_read, end);
4610 hdrptr += bytes_read;
4611 read_uleb128 (hdrptr, &bytes_read, end);
4612 hdrptr += bytes_read;
4613 read_uleb128 (hdrptr, &bytes_read, end);
4614 hdrptr += bytes_read;
4616 if (hdrptr == end || *hdrptr == '\0')
4619 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4620 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4623 for (; *dirtable != '\0' && diridx > 1; diridx--)
4624 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4625 if (*dirtable == '\0')
4627 *dir_name = dirtable;
4632 display_debug_macro (struct dwarf_section *section,
4635 unsigned char *start = section->start;
4636 unsigned char *end = start + section->size;
4637 unsigned char *curr = start;
4638 unsigned char *extended_op_buf[256];
4639 unsigned int bytes_read;
4641 load_debug_section (str, file);
4642 load_debug_section (line, file);
4644 printf (_("Contents of the %s section:\n\n"), section->name);
4648 unsigned int lineno, version, flags;
4649 unsigned int offset_size = 4;
4650 const unsigned char *string;
4651 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4652 unsigned char **extended_ops = NULL;
4654 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4655 if (version != 4 && version != 5)
4657 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4662 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4665 printf (_(" Offset: 0x%lx\n"),
4666 (unsigned long) sec_offset);
4667 printf (_(" Version: %d\n"), version);
4668 printf (_(" Offset size: %d\n"), offset_size);
4671 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4672 printf (_(" Offset into .debug_line: 0x%lx\n"),
4673 (unsigned long) line_offset);
4677 unsigned int i, count, op;
4680 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4682 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4683 extended_ops = extended_op_buf;
4686 printf (_(" Extension opcode arguments:\n"));
4687 for (i = 0; i < count; i++)
4689 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4690 extended_ops[op] = curr;
4691 nargs = read_uleb128 (curr, &bytes_read, end);
4694 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4697 printf (_(" DW_MACRO_%02x arguments: "), op);
4698 for (n = 0; n < nargs; n++)
4702 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4703 printf ("%s%s", get_FORM_name (form),
4704 n == nargs - 1 ? "\n" : ", ");
4714 case DW_FORM_block1:
4715 case DW_FORM_block2:
4716 case DW_FORM_block4:
4718 case DW_FORM_string:
4720 case DW_FORM_sec_offset:
4723 error (_("Invalid extension opcode form %s\n"),
4724 get_FORM_name (form));
4740 error (_(".debug_macro section not zero terminated\n"));
4744 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4750 case DW_MACRO_start_file:
4752 unsigned int filenum;
4753 unsigned char *file_name = NULL, *dir_name = NULL;
4755 lineno = read_uleb128 (curr, &bytes_read, end);
4757 filenum = read_uleb128 (curr, &bytes_read, end);
4760 if ((flags & 2) == 0)
4761 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4764 = get_line_filename_and_dirname (line_offset, filenum,
4766 if (file_name == NULL)
4767 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4770 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4772 dir_name != NULL ? (const char *) dir_name : "",
4773 dir_name != NULL ? "/" : "", file_name);
4777 case DW_MACRO_end_file:
4778 printf (_(" DW_MACRO_end_file\n"));
4781 case DW_MACRO_define:
4782 lineno = read_uleb128 (curr, &bytes_read, end);
4785 curr += strnlen ((char *) string, end - string) + 1;
4786 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4790 case DW_MACRO_undef:
4791 lineno = read_uleb128 (curr, &bytes_read, end);
4794 curr += strnlen ((char *) string, end - string) + 1;
4795 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4799 case DW_MACRO_define_strp:
4800 lineno = read_uleb128 (curr, &bytes_read, end);
4802 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4803 string = fetch_indirect_string (offset);
4804 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4808 case DW_MACRO_undef_strp:
4809 lineno = read_uleb128 (curr, &bytes_read, end);
4811 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4812 string = fetch_indirect_string (offset);
4813 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4817 case DW_MACRO_import:
4818 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4819 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4820 (unsigned long) offset);
4823 case DW_MACRO_define_sup:
4824 lineno = read_uleb128 (curr, &bytes_read, end);
4826 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4827 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4828 lineno, (unsigned long) offset);
4831 case DW_MACRO_undef_sup:
4832 lineno = read_uleb128 (curr, &bytes_read, end);
4834 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4835 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4836 lineno, (unsigned long) offset);
4839 case DW_MACRO_import_sup:
4840 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4841 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4842 (unsigned long) offset);
4846 if (extended_ops == NULL || extended_ops[op] == NULL)
4848 error (_(" Unknown macro opcode %02x seen\n"), op);
4853 /* Skip over unhandled opcodes. */
4855 unsigned char *desc = extended_ops[op];
4856 nargs = read_uleb128 (desc, &bytes_read, end);
4860 printf (_(" DW_MACRO_%02x\n"), op);
4863 printf (_(" DW_MACRO_%02x -"), op);
4864 for (n = 0; n < nargs; n++)
4868 /* DW_FORM_implicit_const is not expected here. */
4869 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4871 = read_and_display_attr_value (0, val, 0,
4872 curr, end, 0, 0, offset_size,
4873 version, NULL, 0, NULL,
4891 display_debug_abbrev (struct dwarf_section *section,
4892 void *file ATTRIBUTE_UNUSED)
4894 abbrev_entry *entry;
4895 unsigned char *start = section->start;
4896 unsigned char *end = start + section->size;
4898 printf (_("Contents of the %s section:\n\n"), section->name);
4902 unsigned char *last;
4907 start = process_abbrev_section (start, end);
4909 if (first_abbrev == NULL)
4912 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4914 for (entry = first_abbrev; entry; entry = entry->next)
4918 printf (" %ld %s [%s]\n",
4920 get_TAG_name (entry->tag),
4921 entry->children ? _("has children") : _("no children"));
4923 for (attr = entry->first_attr; attr; attr = attr->next)
4925 printf (" %-18s %s",
4926 get_AT_name (attr->attribute),
4927 get_FORM_name (attr->form));
4928 if (attr->form == DW_FORM_implicit_const)
4929 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
4941 /* Return true when ADDR is the maximum address, when addresses are
4942 POINTER_SIZE bytes long. */
4945 is_max_address (dwarf_vma addr, unsigned int pointer_size)
4947 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
4948 return ((addr & mask) == mask);
4951 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4954 display_loc_list (struct dwarf_section *section,
4955 unsigned char **start_ptr,
4956 unsigned int debug_info_entry,
4958 dwarf_vma base_address,
4961 unsigned char *start = *start_ptr;
4962 unsigned char *section_end = section->start + section->size;
4963 unsigned long cu_offset;
4964 unsigned int pointer_size;
4965 unsigned int offset_size;
4970 unsigned short length;
4971 int need_frame_base;
4973 if (debug_info_entry >= num_debug_info_entries)
4975 warn (_("No debug information available for loc lists of entry: %u\n"),
4980 cu_offset = debug_information [debug_info_entry].cu_offset;
4981 pointer_size = debug_information [debug_info_entry].pointer_size;
4982 offset_size = debug_information [debug_info_entry].offset_size;
4983 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4985 if (pointer_size < 2 || pointer_size > 8)
4987 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4988 pointer_size, debug_info_entry);
4994 dwarf_vma off = offset + (start - *start_ptr);
4996 if (start + 2 * pointer_size > section_end)
4998 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4999 (unsigned long) offset);
5003 printf (" %8.8lx ", (unsigned long) off);
5005 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5006 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5008 if (begin == 0 && end == 0)
5010 /* PR 18374: In a object file we can have a location list that
5011 starts with a begin and end of 0 because there are relocations
5012 that need to be applied to the addresses. Actually applying
5013 the relocations now does not help as they will probably resolve
5014 to 0, since the object file has not been fully linked. Real
5015 end of list markers will not have any relocations against them. */
5016 if (! reloc_at (section, off)
5017 && ! reloc_at (section, off + pointer_size))
5019 printf (_("<End of list>\n"));
5024 /* Check base address specifiers. */
5025 if (is_max_address (begin, pointer_size)
5026 && !is_max_address (end, pointer_size))
5029 print_dwarf_vma (begin, pointer_size);
5030 print_dwarf_vma (end, pointer_size);
5031 printf (_("(base address)\n"));
5035 if (start + 2 > section_end)
5037 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5038 (unsigned long) offset);
5042 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5044 if (start + length > section_end)
5046 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5047 (unsigned long) offset);
5051 print_dwarf_vma (begin + base_address, pointer_size);
5052 print_dwarf_vma (end + base_address, pointer_size);
5055 need_frame_base = decode_location_expression (start,
5060 cu_offset, section);
5063 if (need_frame_base && !has_frame_base)
5064 printf (_(" [without DW_AT_frame_base]"));
5067 fputs (_(" (start == end)"), stdout);
5068 else if (begin > end)
5069 fputs (_(" (start > end)"), stdout);
5079 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5082 display_loclists_list (struct dwarf_section *section,
5083 unsigned char **start_ptr,
5084 unsigned int debug_info_entry,
5086 dwarf_vma base_address,
5089 unsigned char *start = *start_ptr;
5090 unsigned char *section_end = section->start + section->size;
5091 unsigned long cu_offset;
5092 unsigned int pointer_size;
5093 unsigned int offset_size;
5095 unsigned int bytes_read;
5097 /* Initialize it due to a false compiler warning. */
5098 dwarf_vma begin = -1;
5101 int need_frame_base;
5103 if (debug_info_entry >= num_debug_info_entries)
5105 warn (_("No debug information available for "
5106 "loclists lists of entry: %u\n"),
5111 cu_offset = debug_information [debug_info_entry].cu_offset;
5112 pointer_size = debug_information [debug_info_entry].pointer_size;
5113 offset_size = debug_information [debug_info_entry].offset_size;
5114 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5116 if (pointer_size < 2 || pointer_size > 8)
5118 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5119 pointer_size, debug_info_entry);
5125 dwarf_vma off = offset + (start - *start_ptr);
5126 enum dwarf_location_list_entry_type llet;
5128 if (start + 1 > section_end)
5130 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5131 (unsigned long) offset);
5135 printf (" %8.8lx ", (unsigned long) off);
5137 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5141 case DW_LLE_end_of_list:
5142 printf (_("<End of list>\n"));
5144 case DW_LLE_offset_pair:
5145 begin = read_uleb128 (start, &bytes_read, section_end);
5146 start += bytes_read;
5147 end = read_uleb128 (start, &bytes_read, section_end);
5148 start += bytes_read;
5150 case DW_LLE_base_address:
5151 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5153 print_dwarf_vma (base_address, pointer_size);
5154 printf (_("(base address)\n"));
5157 error (_("Invalid location list entry type %d\n"), llet);
5160 if (llet == DW_LLE_end_of_list)
5162 if (llet != DW_LLE_offset_pair)
5165 if (start + 2 > section_end)
5167 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5168 (unsigned long) offset);
5172 length = read_uleb128 (start, &bytes_read, section_end);
5173 start += bytes_read;
5175 print_dwarf_vma (begin + base_address, pointer_size);
5176 print_dwarf_vma (end + base_address, pointer_size);
5179 need_frame_base = decode_location_expression (start,
5184 cu_offset, section);
5187 if (need_frame_base && !has_frame_base)
5188 printf (_(" [without DW_AT_frame_base]"));
5191 fputs (_(" (start == end)"), stdout);
5192 else if (begin > end)
5193 fputs (_(" (start > end)"), stdout);
5203 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5204 right-adjusted in a field of length LEN, and followed by a space. */
5207 print_addr_index (unsigned int idx, unsigned int len)
5209 static char buf[15];
5210 snprintf (buf, sizeof (buf), "[%d]", idx);
5211 printf ("%*s ", len, buf);
5214 /* Display a location list from a .dwo section. It uses address indexes rather
5215 than embedded addresses. This code closely follows display_loc_list, but the
5216 two are sufficiently different that combining things is very ugly. */
5219 display_loc_list_dwo (struct dwarf_section *section,
5220 unsigned char **start_ptr,
5221 unsigned int debug_info_entry,
5225 unsigned char *start = *start_ptr;
5226 unsigned char *section_end = section->start + section->size;
5227 unsigned long cu_offset;
5228 unsigned int pointer_size;
5229 unsigned int offset_size;
5232 unsigned short length;
5233 int need_frame_base;
5235 unsigned int bytes_read;
5237 if (debug_info_entry >= num_debug_info_entries)
5239 warn (_("No debug information for loc lists of entry: %u\n"),
5244 cu_offset = debug_information [debug_info_entry].cu_offset;
5245 pointer_size = debug_information [debug_info_entry].pointer_size;
5246 offset_size = debug_information [debug_info_entry].offset_size;
5247 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5249 if (pointer_size < 2 || pointer_size > 8)
5251 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5252 pointer_size, debug_info_entry);
5258 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5260 if (start >= section_end)
5262 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5263 (unsigned long) offset);
5267 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5270 case 0: /* A terminating entry. */
5272 printf (_("<End of list>\n"));
5274 case 1: /* A base-address entry. */
5275 idx = read_uleb128 (start, &bytes_read, section_end);
5276 start += bytes_read;
5277 print_addr_index (idx, 8);
5279 printf (_("(base address selection entry)\n"));
5281 case 2: /* A start/end entry. */
5282 idx = read_uleb128 (start, &bytes_read, section_end);
5283 start += bytes_read;
5284 print_addr_index (idx, 8);
5285 idx = read_uleb128 (start, &bytes_read, section_end);
5286 start += bytes_read;
5287 print_addr_index (idx, 8);
5289 case 3: /* A start/length entry. */
5290 idx = read_uleb128 (start, &bytes_read, section_end);
5291 start += bytes_read;
5292 print_addr_index (idx, 8);
5293 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5294 printf ("%08x ", idx);
5296 case 4: /* An offset pair entry. */
5297 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5298 printf ("%08x ", idx);
5299 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5300 printf ("%08x ", idx);
5303 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5308 if (start + 2 > section_end)
5310 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5311 (unsigned long) offset);
5315 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5316 if (start + length > section_end)
5318 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5319 (unsigned long) offset);
5324 need_frame_base = decode_location_expression (start,
5329 cu_offset, section);
5332 if (need_frame_base && !has_frame_base)
5333 printf (_(" [without DW_AT_frame_base]"));
5343 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5345 static dwarf_vma *loc_offsets;
5348 loc_offsets_compar (const void *ap, const void *bp)
5350 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5351 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5353 return (a > b) - (b > a);
5357 display_debug_loc (struct dwarf_section *section, void *file)
5359 unsigned char *start = section->start;
5360 unsigned long bytes;
5361 unsigned char *section_begin = start;
5362 unsigned int num_loc_list = 0;
5363 unsigned long last_offset = 0;
5364 unsigned int first = 0;
5367 int seen_first_offset = 0;
5368 int locs_sorted = 1;
5369 unsigned char *next;
5370 unsigned int *array = NULL;
5371 const char *suffix = strrchr (section->name, '.');
5373 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5374 dwarf_vma expected_start = 0;
5376 if (suffix && strcmp (suffix, ".dwo") == 0)
5379 bytes = section->size;
5383 printf (_("\nThe %s section is empty.\n"), section->name);
5389 unsigned char *hdrptr = section_begin;
5390 dwarf_vma ll_length;
5391 unsigned short ll_version;
5392 unsigned char *end = section_begin + section->size;
5393 unsigned char address_size, segment_selector_size;
5394 uint32_t offset_entry_count;
5396 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5397 if (ll_length == 0xffffffff)
5398 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5400 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5401 if (ll_version != 5)
5403 warn (_("The %s section contains corrupt or "
5404 "unsupported version number: %d.\n"),
5405 section->name, ll_version);
5409 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5411 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5412 if (segment_selector_size != 0)
5414 warn (_("The %s section contains "
5415 "unsupported segment selector size: %d.\n"),
5416 section->name, segment_selector_size);
5420 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5421 if (offset_entry_count != 0)
5423 warn (_("The %s section contains "
5424 "unsupported offset entry count: %d.\n"),
5425 section->name, offset_entry_count);
5429 expected_start = hdrptr - section_begin;
5432 if (load_debug_info (file) == 0)
5434 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5439 /* Check the order of location list in .debug_info section. If
5440 offsets of location lists are in the ascending order, we can
5441 use `debug_information' directly. */
5442 for (i = 0; i < num_debug_info_entries; i++)
5446 num = debug_information [i].num_loc_offsets;
5447 if (num > num_loc_list)
5450 /* Check if we can use `debug_information' directly. */
5451 if (locs_sorted && num != 0)
5453 if (!seen_first_offset)
5455 /* This is the first location list. */
5456 last_offset = debug_information [i].loc_offsets [0];
5458 seen_first_offset = 1;
5464 for (; j < num; j++)
5467 debug_information [i].loc_offsets [j])
5472 last_offset = debug_information [i].loc_offsets [j];
5477 if (!seen_first_offset)
5478 error (_("No location lists in .debug_info section!\n"));
5480 if (debug_information [first].num_loc_offsets > 0
5481 && debug_information [first].loc_offsets [0] != expected_start)
5482 warn (_("Location lists in %s section start at 0x%s\n"),
5484 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5487 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5488 printf (_("Contents of the %s section:\n\n"), section->name);
5489 if (reloc_at (section, 0))
5490 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5491 printf (_(" Offset Begin End Expression\n"));
5493 seen_first_offset = 0;
5494 for (i = first; i < num_debug_info_entries; i++)
5497 dwarf_vma base_address;
5503 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5505 loc_offsets = debug_information [i].loc_offsets;
5506 qsort (array, debug_information [i].num_loc_offsets,
5507 sizeof (*array), loc_offsets_compar);
5510 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5512 j = locs_sorted ? k : array[k];
5514 && debug_information [i].loc_offsets [locs_sorted
5515 ? k - 1 : array [k - 1]]
5516 == debug_information [i].loc_offsets [j])
5518 has_frame_base = debug_information [i].have_frame_base [j];
5519 offset = debug_information [i].loc_offsets [j];
5520 next = section_begin + offset;
5521 base_address = debug_information [i].base_address;
5523 if (!seen_first_offset)
5524 seen_first_offset = 1;
5528 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5529 (unsigned long) (start - section_begin),
5530 (unsigned long) offset);
5531 else if (start > next)
5532 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5533 (unsigned long) (start - section_begin),
5534 (unsigned long) offset);
5538 if (offset >= bytes)
5540 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5541 (unsigned long) offset);
5548 display_loc_list_dwo (section, &start, i, offset,
5551 display_loc_list (section, &start, i, offset, base_address,
5557 warn (_("DWO is not yet supported.\n"));
5559 display_loclists_list (section, &start, i, offset, base_address,
5565 if (start < section->start + section->size)
5566 warn (_("There are %ld unused bytes at the end of section %s\n"),
5567 (long) (section->start + section->size - start), section->name);
5574 display_debug_str (struct dwarf_section *section,
5575 void *file ATTRIBUTE_UNUSED)
5577 unsigned char *start = section->start;
5578 unsigned long bytes = section->size;
5579 dwarf_vma addr = section->address;
5583 printf (_("\nThe %s section is empty.\n"), section->name);
5587 printf (_("Contents of the %s section:\n\n"), section->name);
5595 lbytes = (bytes > 16 ? 16 : bytes);
5597 printf (" 0x%8.8lx ", (unsigned long) addr);
5599 for (j = 0; j < 16; j++)
5602 printf ("%2.2x", start[j]);
5610 for (j = 0; j < lbytes; j++)
5613 if (k >= ' ' && k < 0x80)
5632 display_debug_info (struct dwarf_section *section, void *file)
5634 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5638 display_debug_types (struct dwarf_section *section, void *file)
5640 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5644 display_trace_info (struct dwarf_section *section, void *file)
5646 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5650 display_debug_aranges (struct dwarf_section *section,
5651 void *file ATTRIBUTE_UNUSED)
5653 unsigned char *start = section->start;
5654 unsigned char *end = start + section->size;
5656 printf (_("Contents of the %s section:\n\n"), section->name);
5658 /* It does not matter if this load fails,
5659 we test for that later on. */
5660 load_debug_info (file);
5664 unsigned char *hdrptr;
5665 DWARF2_Internal_ARange arange;
5666 unsigned char *addr_ranges;
5669 unsigned char address_size;
5671 unsigned int offset_size;
5672 unsigned int initial_length_size;
5676 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
5677 if (arange.ar_length == 0xffffffff)
5679 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
5681 initial_length_size = 12;
5686 initial_length_size = 4;
5689 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
5690 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
5692 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5693 && num_debug_info_entries > 0
5694 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
5695 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5696 (unsigned long) arange.ar_info_offset, section->name);
5698 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
5699 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
5701 if (arange.ar_version != 2 && arange.ar_version != 3)
5703 /* PR 19872: A version number of 0 probably means that there is
5704 padding at the end of the .debug_aranges section. Gold puts
5705 it there when performing an incremental link, for example.
5706 So do not generate a warning in this case. */
5707 if (arange.ar_version)
5708 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5712 printf (_(" Length: %ld\n"),
5713 (long) arange.ar_length);
5714 printf (_(" Version: %d\n"), arange.ar_version);
5715 printf (_(" Offset into .debug_info: 0x%lx\n"),
5716 (unsigned long) arange.ar_info_offset);
5717 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5718 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5720 address_size = arange.ar_pointer_size + arange.ar_segment_size;
5722 /* PR 17512: file: 001-108546-0.001:0.1. */
5723 if (address_size == 0 || address_size > 8)
5725 error (_("Invalid address size in %s section!\n"),
5730 /* The DWARF spec does not require that the address size be a power
5731 of two, but we do. This will have to change if we ever encounter
5732 an uneven architecture. */
5733 if ((address_size & (address_size - 1)) != 0)
5735 warn (_("Pointer size + Segment size is not a power of two.\n"));
5739 if (address_size > 4)
5740 printf (_("\n Address Length\n"));
5742 printf (_("\n Address Length\n"));
5744 addr_ranges = hdrptr;
5746 /* Must pad to an alignment boundary that is twice the address size. */
5747 excess = (hdrptr - start) % (2 * address_size);
5749 addr_ranges += (2 * address_size) - excess;
5751 hdrptr = start + arange.ar_length + initial_length_size;
5752 if (hdrptr < start || hdrptr > end)
5754 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5759 while (addr_ranges + 2 * address_size <= start)
5761 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5762 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5765 print_dwarf_vma (address, address_size);
5766 print_dwarf_vma (length, address_size);
5776 /* Comparison function for qsort. */
5778 comp_addr_base (const void * v0, const void * v1)
5780 debug_info * info0 = (debug_info *) v0;
5781 debug_info * info1 = (debug_info *) v1;
5782 return info0->addr_base - info1->addr_base;
5785 /* Display the debug_addr section. */
5787 display_debug_addr (struct dwarf_section *section,
5790 debug_info **debug_addr_info;
5791 unsigned char *entry;
5796 if (section->size == 0)
5798 printf (_("\nThe %s section is empty.\n"), section->name);
5802 if (load_debug_info (file) == 0)
5804 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5809 printf (_("Contents of the %s section:\n\n"), section->name);
5811 /* PR 17531: file: cf38d01b.
5812 We use xcalloc because a corrupt file may not have initialised all of the
5813 fields in the debug_info structure, which means that the sort below might
5814 try to move uninitialised data. */
5815 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5816 sizeof (debug_info *));
5819 for (i = 0; i < num_debug_info_entries; i++)
5820 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5822 /* PR 17531: file: cf38d01b. */
5823 if (debug_information[i].addr_base >= section->size)
5824 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5825 (unsigned long) debug_information[i].addr_base, i);
5827 debug_addr_info [count++] = debug_information + i;
5830 /* Add a sentinel to make iteration convenient. */
5831 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5832 debug_addr_info [count]->addr_base = section->size;
5833 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5835 for (i = 0; i < count; i++)
5838 unsigned int address_size = debug_addr_info [i]->pointer_size;
5840 printf (_(" For compilation unit at offset 0x%s:\n"),
5841 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5843 printf (_("\tIndex\tAddress\n"));
5844 entry = section->start + debug_addr_info [i]->addr_base;
5845 end = section->start + debug_addr_info [i + 1]->addr_base;
5849 dwarf_vma base = byte_get (entry, address_size);
5850 printf (_("\t%d:\t"), idx);
5851 print_dwarf_vma (base, address_size);
5853 entry += address_size;
5859 free (debug_addr_info);
5863 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5865 display_debug_str_offsets (struct dwarf_section *section,
5866 void *file ATTRIBUTE_UNUSED)
5868 if (section->size == 0)
5870 printf (_("\nThe %s section is empty.\n"), section->name);
5873 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5874 what the offset size is for this section. */
5878 /* Each debug_information[x].range_lists[y] gets this representation for
5879 sorting purposes. */
5883 /* The debug_information[x].range_lists[y] value. */
5884 dwarf_vma ranges_offset;
5886 /* Original debug_information to find parameters of the data. */
5887 debug_info *debug_info_p;
5890 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5893 range_entry_compar (const void *ap, const void *bp)
5895 const struct range_entry *a_re = (const struct range_entry *) ap;
5896 const struct range_entry *b_re = (const struct range_entry *) bp;
5897 const dwarf_vma a = a_re->ranges_offset;
5898 const dwarf_vma b = b_re->ranges_offset;
5900 return (a > b) - (b > a);
5904 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
5905 unsigned int pointer_size, unsigned long offset,
5906 unsigned long base_address)
5908 while (start < finish)
5913 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5914 if (start >= finish)
5916 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5918 printf (" %8.8lx ", offset);
5920 if (begin == 0 && end == 0)
5922 printf (_("<End of list>\n"));
5926 /* Check base address specifiers. */
5927 if (is_max_address (begin, pointer_size)
5928 && !is_max_address (end, pointer_size))
5931 print_dwarf_vma (begin, pointer_size);
5932 print_dwarf_vma (end, pointer_size);
5933 printf ("(base address)\n");
5937 print_dwarf_vma (begin + base_address, pointer_size);
5938 print_dwarf_vma (end + base_address, pointer_size);
5941 fputs (_("(start == end)"), stdout);
5942 else if (begin > end)
5943 fputs (_("(start > end)"), stdout);
5950 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
5951 unsigned int pointer_size, unsigned long offset,
5952 unsigned long base_address)
5954 unsigned char *next = start;
5958 unsigned long off = offset + (start - next);
5959 enum dwarf_range_list_entry rlet;
5960 /* Initialize it due to a false compiler warning. */
5961 dwarf_vma begin = -1, length, end = -1;
5962 unsigned int bytes_read;
5964 if (start + 1 > finish)
5966 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
5971 printf (" %8.8lx ", off);
5973 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
5977 case DW_RLE_end_of_list:
5978 printf (_("<End of list>\n"));
5980 case DW_RLE_base_address:
5981 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
5982 print_dwarf_vma (base_address, pointer_size);
5983 printf (_("(base address)\n"));
5985 case DW_RLE_start_length:
5986 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5987 length = read_uleb128 (start, &bytes_read, finish);
5988 start += bytes_read;
5989 end = begin + length;
5991 case DW_RLE_offset_pair:
5992 begin = read_uleb128 (start, &bytes_read, finish);
5993 start += bytes_read;
5994 end = read_uleb128 (start, &bytes_read, finish);
5995 start += bytes_read;
5997 case DW_RLE_start_end:
5998 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5999 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6002 error (_("Invalid range list entry type %d\n"), rlet);
6003 rlet = DW_RLE_end_of_list;
6006 if (rlet == DW_RLE_end_of_list)
6008 if (rlet == DW_RLE_base_address)
6011 print_dwarf_vma (begin + base_address, pointer_size);
6012 print_dwarf_vma (end + base_address, pointer_size);
6015 fputs (_("(start == end)"), stdout);
6016 else if (begin > end)
6017 fputs (_("(start > end)"), stdout);
6024 display_debug_ranges (struct dwarf_section *section,
6025 void *file ATTRIBUTE_UNUSED)
6027 unsigned char *start = section->start;
6028 unsigned char *last_start = start;
6029 unsigned long bytes = section->size;
6030 unsigned char *section_begin = start;
6031 unsigned char *finish = start + bytes;
6032 unsigned int num_range_list, i;
6033 struct range_entry *range_entries, *range_entry_fill;
6034 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6035 /* Initialize it due to a false compiler warning. */
6036 unsigned char address_size = 0;
6040 printf (_("\nThe %s section is empty.\n"), section->name);
6046 dwarf_vma initial_length;
6047 unsigned int initial_length_size;
6048 unsigned char segment_selector_size;
6049 unsigned int offset_size, offset_entry_count;
6050 unsigned short version;
6052 /* Get and check the length of the block. */
6053 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6055 if (initial_length == 0xffffffff)
6057 /* This section is 64-bit DWARF 3. */
6058 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6060 initial_length_size = 12;
6065 initial_length_size = 4;
6068 if (initial_length + initial_length_size > section->size)
6070 /* If the length field has a relocation against it, then we should
6071 not complain if it is inaccurate (and probably negative).
6072 It is copied from .debug_line handling code. */
6073 if (reloc_at (section, (start - section->start) - offset_size))
6075 initial_length = (finish - start) - initial_length_size;
6079 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6080 (long) initial_length);
6085 /* Get and check the version number. */
6086 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6090 warn (_("Only DWARF version 5 debug_rnglists info "
6091 "is currently supported.\n"));
6095 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6097 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6098 if (segment_selector_size != 0)
6100 warn (_("The %s section contains "
6101 "unsupported segment selector size: %d.\n"),
6102 section->name, segment_selector_size);
6106 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6107 if (offset_entry_count != 0)
6109 warn (_("The %s section contains "
6110 "unsupported offset entry count: %u.\n"),
6111 section->name, offset_entry_count);
6116 if (load_debug_info (file) == 0)
6118 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6124 for (i = 0; i < num_debug_info_entries; i++)
6125 num_range_list += debug_information [i].num_range_lists;
6127 if (num_range_list == 0)
6129 /* This can happen when the file was compiled with -gsplit-debug
6130 which removes references to range lists from the primary .o file. */
6131 printf (_("No range lists in .debug_info section.\n"));
6135 range_entries = (struct range_entry *)
6136 xmalloc (sizeof (*range_entries) * num_range_list);
6137 range_entry_fill = range_entries;
6139 for (i = 0; i < num_debug_info_entries; i++)
6141 debug_info *debug_info_p = &debug_information[i];
6144 for (j = 0; j < debug_info_p->num_range_lists; j++)
6146 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6147 range_entry_fill->debug_info_p = debug_info_p;
6152 qsort (range_entries, num_range_list, sizeof (*range_entries),
6153 range_entry_compar);
6155 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6156 warn (_("Range lists in %s section start at 0x%lx\n"),
6157 section->name, (unsigned long) range_entries[0].ranges_offset);
6159 printf (_("Contents of the %s section:\n\n"), section->name);
6160 printf (_(" Offset Begin End\n"));
6162 for (i = 0; i < num_range_list; i++)
6164 struct range_entry *range_entry = &range_entries[i];
6165 debug_info *debug_info_p = range_entry->debug_info_p;
6166 unsigned int pointer_size;
6168 unsigned char *next;
6169 dwarf_vma base_address;
6171 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6172 offset = range_entry->ranges_offset;
6173 next = section_begin + offset;
6174 base_address = debug_info_p->base_address;
6176 /* PR 17512: file: 001-101485-0.001:0.1. */
6177 if (pointer_size < 2 || pointer_size > 8)
6179 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6180 pointer_size, (unsigned long) offset);
6184 if (dwarf_check != 0 && i > 0)
6187 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6188 (unsigned long) (start - section_begin),
6189 (unsigned long) (next - section_begin), section->name);
6190 else if (start > next)
6192 if (next == last_start)
6194 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6195 (unsigned long) (start - section_begin),
6196 (unsigned long) (next - section_begin), section->name);
6202 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6203 (start, finish, pointer_size, offset, base_address);
6207 free (range_entries);
6212 typedef struct Frame_Chunk
6214 struct Frame_Chunk *next;
6215 unsigned char *chunk_start;
6217 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6218 short int *col_type;
6221 unsigned int code_factor;
6226 dwarf_vma cfa_offset;
6228 unsigned char fde_encoding;
6229 unsigned char cfa_exp;
6230 unsigned char ptr_size;
6231 unsigned char segment_size;
6235 static const char *const *dwarf_regnames;
6236 static unsigned int dwarf_regnames_count;
6238 /* A marker for a col_type that means this column was never referenced
6239 in the frame info. */
6240 #define DW_CFA_unreferenced (-1)
6242 /* Return 0 if no more space is needed, 1 if more space is needed,
6243 -1 for invalid reg. */
6246 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6248 unsigned int prev = fc->ncols;
6250 if (reg < (unsigned int) fc->ncols)
6253 if (dwarf_regnames_count
6254 && reg > dwarf_regnames_count)
6257 fc->ncols = reg + 1;
6258 /* PR 17512: file: 10450-2643-0.004.
6259 If reg == -1 then this can happen... */
6263 /* PR 17512: file: 2844a11d. */
6264 if (fc->ncols > 1024)
6266 error (_("Unfeasibly large register number: %u\n"), reg);
6268 /* FIXME: 1024 is an arbitrary limit. Increase it if
6269 we ever encounter a valid binary that exceeds it. */
6273 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6274 sizeof (short int));
6275 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6276 /* PR 17512: file:002-10025-0.005. */
6277 if (fc->col_type == NULL || fc->col_offset == NULL)
6279 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6285 while (prev < fc->ncols)
6287 fc->col_type[prev] = DW_CFA_unreferenced;
6288 fc->col_offset[prev] = 0;
6294 static const char *const dwarf_regnames_i386[] =
6296 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6297 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6298 "eip", "eflags", NULL, /* 8 - 10 */
6299 "st0", "st1", "st2", "st3", /* 11 - 14 */
6300 "st4", "st5", "st6", "st7", /* 15 - 18 */
6301 NULL, NULL, /* 19 - 20 */
6302 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6303 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6304 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6305 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6306 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6307 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6308 "tr", "ldtr", /* 48 - 49 */
6309 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6310 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6311 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6312 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6313 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6314 NULL, NULL, NULL, /* 90 - 92 */
6315 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6318 static const char *const dwarf_regnames_iamcu[] =
6320 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6321 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6322 "eip", "eflags", NULL, /* 8 - 10 */
6323 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6324 NULL, NULL, /* 19 - 20 */
6325 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6326 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6327 NULL, NULL, NULL, /* 37 - 39 */
6328 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6329 "tr", "ldtr", /* 48 - 49 */
6330 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6331 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6332 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6333 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6334 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6335 NULL, NULL, NULL, /* 90 - 92 */
6336 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6340 init_dwarf_regnames_i386 (void)
6342 dwarf_regnames = dwarf_regnames_i386;
6343 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6347 init_dwarf_regnames_iamcu (void)
6349 dwarf_regnames = dwarf_regnames_iamcu;
6350 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6353 static const char *const dwarf_regnames_x86_64[] =
6355 "rax", "rdx", "rcx", "rbx",
6356 "rsi", "rdi", "rbp", "rsp",
6357 "r8", "r9", "r10", "r11",
6358 "r12", "r13", "r14", "r15",
6360 "xmm0", "xmm1", "xmm2", "xmm3",
6361 "xmm4", "xmm5", "xmm6", "xmm7",
6362 "xmm8", "xmm9", "xmm10", "xmm11",
6363 "xmm12", "xmm13", "xmm14", "xmm15",
6364 "st0", "st1", "st2", "st3",
6365 "st4", "st5", "st6", "st7",
6366 "mm0", "mm1", "mm2", "mm3",
6367 "mm4", "mm5", "mm6", "mm7",
6369 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6370 "fs.base", "gs.base", NULL, NULL,
6372 "mxcsr", "fcw", "fsw",
6373 "xmm16", "xmm17", "xmm18", "xmm19",
6374 "xmm20", "xmm21", "xmm22", "xmm23",
6375 "xmm24", "xmm25", "xmm26", "xmm27",
6376 "xmm28", "xmm29", "xmm30", "xmm31",
6377 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6378 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6379 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6380 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6381 NULL, NULL, NULL, /* 115 - 117 */
6382 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6386 init_dwarf_regnames_x86_64 (void)
6388 dwarf_regnames = dwarf_regnames_x86_64;
6389 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6392 static const char *const dwarf_regnames_aarch64[] =
6394 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6395 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6396 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6397 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6398 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6399 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6400 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6401 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6402 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6403 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6404 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6405 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6409 init_dwarf_regnames_aarch64 (void)
6411 dwarf_regnames = dwarf_regnames_aarch64;
6412 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6415 static const char *const dwarf_regnames_s390[] =
6417 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6418 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6419 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6420 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6421 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6422 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6423 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6424 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6425 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6428 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6429 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6433 init_dwarf_regnames_s390 (void)
6435 dwarf_regnames = dwarf_regnames_s390;
6436 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6440 init_dwarf_regnames (unsigned int e_machine)
6445 init_dwarf_regnames_i386 ();
6449 init_dwarf_regnames_iamcu ();
6455 init_dwarf_regnames_x86_64 ();
6459 init_dwarf_regnames_aarch64 ();
6463 init_dwarf_regnames_s390 ();
6472 regname (unsigned int regno, int row)
6474 static char reg[64];
6477 && regno < dwarf_regnames_count
6478 && dwarf_regnames [regno] != NULL)
6481 return dwarf_regnames [regno];
6482 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6483 dwarf_regnames [regno]);
6486 snprintf (reg, sizeof (reg), "r%d", regno);
6491 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6496 if (*max_regs != fc->ncols)
6497 *max_regs = fc->ncols;
6499 if (*need_col_headers)
6501 static const char *sloc = " LOC";
6503 *need_col_headers = 0;
6505 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6507 for (r = 0; r < *max_regs; r++)
6508 if (fc->col_type[r] != DW_CFA_unreferenced)
6513 printf ("%-5s ", regname (r, 1));
6519 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6521 strcpy (tmp, "exp");
6523 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6524 printf ("%-8s ", tmp);
6526 for (r = 0; r < fc->ncols; r++)
6528 if (fc->col_type[r] != DW_CFA_unreferenced)
6530 switch (fc->col_type[r])
6532 case DW_CFA_undefined:
6535 case DW_CFA_same_value:
6539 sprintf (tmp, "c%+d", fc->col_offset[r]);
6541 case DW_CFA_val_offset:
6542 sprintf (tmp, "v%+d", fc->col_offset[r]);
6544 case DW_CFA_register:
6545 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6547 case DW_CFA_expression:
6548 strcpy (tmp, "exp");
6550 case DW_CFA_val_expression:
6551 strcpy (tmp, "vexp");
6554 strcpy (tmp, "n/a");
6557 printf ("%-5s ", tmp);
6563 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6565 static unsigned char *
6566 read_cie (unsigned char *start, unsigned char *end,
6567 Frame_Chunk **p_cie, int *p_version,
6568 unsigned long *p_aug_len, unsigned char **p_aug)
6572 unsigned int length_return;
6573 unsigned char *augmentation_data = NULL;
6574 unsigned long augmentation_data_len = 0;
6577 /* PR 17512: file: 001-228113-0.004. */
6581 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6582 memset (fc, 0, sizeof (Frame_Chunk));
6584 fc->col_type = (short int *) xmalloc (sizeof (short int));
6585 fc->col_offset = (int *) xmalloc (sizeof (int));
6589 fc->augmentation = (char *) start;
6590 /* PR 17512: file: 001-228113-0.004.
6591 Skip past augmentation name, but avoid running off the end of the data. */
6593 if (* start ++ == '\0')
6597 warn (_("No terminator for augmentation name\n"));
6601 if (strcmp (fc->augmentation, "eh") == 0)
6602 start += eh_addr_size;
6606 GET (fc->ptr_size, 1);
6607 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6609 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6613 GET (fc->segment_size, 1);
6614 /* PR 17512: file: e99d2804. */
6615 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6617 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6621 eh_addr_size = fc->ptr_size;
6625 fc->ptr_size = eh_addr_size;
6626 fc->segment_size = 0;
6628 READ_ULEB (fc->code_factor);
6629 READ_SLEB (fc->data_factor);
6639 if (fc->augmentation[0] == 'z')
6641 READ_ULEB (augmentation_data_len);
6642 augmentation_data = start;
6643 start += augmentation_data_len;
6644 /* PR 17512: file: 11042-2589-0.004. */
6647 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
6648 augmentation_data_len, (long)((end - start) + augmentation_data_len));
6653 if (augmentation_data_len)
6657 unsigned char *qend;
6659 p = (unsigned char *) fc->augmentation + 1;
6660 q = augmentation_data;
6661 qend = q + augmentation_data_len;
6663 /* PR 17531: file: 015adfaa. */
6666 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
6667 augmentation_data_len = 0;
6670 while (p < end && q < augmentation_data + augmentation_data_len)
6675 q += 1 + size_of_encoded_value (*q);
6677 fc->fde_encoding = *q++;
6684 /* Note - it is OK if this loop terminates with q < qend.
6685 Padding may have been inserted to align the end of the CIE. */
6690 *p_version = version;
6693 *p_aug_len = augmentation_data_len;
6694 *p_aug = augmentation_data;
6700 display_debug_frames (struct dwarf_section *section,
6701 void *file ATTRIBUTE_UNUSED)
6703 unsigned char *start = section->start;
6704 unsigned char *end = start + section->size;
6705 unsigned char *section_start = start;
6706 Frame_Chunk *chunks = 0, *forward_refs = 0;
6707 Frame_Chunk *remembered_state = 0;
6709 int is_eh = strcmp (section->name, ".eh_frame") == 0;
6710 unsigned int length_return;
6711 unsigned int max_regs = 0;
6712 const char *bad_reg = _("bad register: ");
6713 unsigned int saved_eh_addr_size = eh_addr_size;
6715 printf (_("Contents of the %s section:\n"), section->name);
6719 unsigned char *saved_start;
6720 unsigned char *block_end;
6725 int need_col_headers = 1;
6726 unsigned char *augmentation_data = NULL;
6727 unsigned long augmentation_data_len = 0;
6728 unsigned int encoded_ptr_size = saved_eh_addr_size;
6729 unsigned int offset_size;
6730 unsigned int initial_length_size;
6731 bfd_boolean all_nops;
6733 saved_start = start;
6735 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
6739 printf ("\n%08lx ZERO terminator\n\n",
6740 (unsigned long)(saved_start - section_start));
6741 /* Skip any zero terminators that directly follow.
6742 A corrupt section size could have loaded a whole
6743 slew of zero filled memory bytes. eg
6744 PR 17512: file: 070-19381-0.004. */
6745 while (start < end && * start == 0)
6750 if (length == 0xffffffff)
6752 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
6754 initial_length_size = 12;
6759 initial_length_size = 4;
6762 block_end = saved_start + length + initial_length_size;
6763 if (block_end > end || block_end < start)
6765 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6766 dwarf_vmatoa_1 (NULL, length, offset_size),
6767 (unsigned long) (saved_start - section_start));
6771 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
6773 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
6774 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
6779 start = read_cie (start, end, &cie, &version,
6780 &augmentation_data_len, &augmentation_data);
6781 /* PR 17512: file: 027-135133-0.005. */
6788 fc->chunk_start = saved_start;
6789 mreg = max_regs > 0 ? max_regs - 1 : 0;
6792 if (frame_need_space (fc, mreg) < 0)
6794 if (fc->fde_encoding)
6795 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6797 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
6798 print_dwarf_vma (length, fc->ptr_size);
6799 print_dwarf_vma (cie_id, offset_size);
6801 if (do_debug_frames_interp)
6803 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
6804 fc->code_factor, fc->data_factor, fc->ra);
6809 printf (" Version: %d\n", version);
6810 printf (" Augmentation: \"%s\"\n", fc->augmentation);
6813 printf (" Pointer Size: %u\n", fc->ptr_size);
6814 printf (" Segment Size: %u\n", fc->segment_size);
6816 printf (" Code alignment factor: %u\n", fc->code_factor);
6817 printf (" Data alignment factor: %d\n", fc->data_factor);
6818 printf (" Return address column: %d\n", fc->ra);
6820 if (augmentation_data_len)
6824 printf (" Augmentation data: ");
6825 for (i = 0; i < augmentation_data_len; ++i)
6826 /* FIXME: If do_wide is FALSE, then we should
6827 add carriage returns at 80 columns... */
6828 printf (" %02x", augmentation_data[i]);
6836 unsigned char *look_for;
6837 static Frame_Chunk fde_fc;
6838 unsigned long segment_selector;
6842 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
6843 look_for = start - 4 - ((cie_id ^ sign) - sign);
6846 look_for = section_start + cie_id;
6848 if (look_for <= saved_start)
6850 for (cie = chunks; cie ; cie = cie->next)
6851 if (cie->chunk_start == look_for)
6856 for (cie = forward_refs; cie ; cie = cie->next)
6857 if (cie->chunk_start == look_for)
6861 unsigned int off_size;
6862 unsigned char *cie_scan;
6864 cie_scan = look_for;
6866 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
6867 if (length == 0xffffffff)
6869 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
6876 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
6879 : ((off_size == 4 && c_id == DW_CIE_ID)
6880 || (off_size == 8 && c_id == DW64_CIE_ID)))
6885 read_cie (cie_scan, end, &cie, &version,
6886 &augmentation_data_len, &augmentation_data);
6887 /* PR 17512: file: 3450-2098-0.004. */
6890 warn (_("Failed to read CIE information\n"));
6893 cie->next = forward_refs;
6895 cie->chunk_start = look_for;
6896 mreg = max_regs > 0 ? max_regs - 1 : 0;
6899 if (frame_need_space (cie, mreg) < 0)
6901 warn (_("Invalid max register\n"));
6904 if (cie->fde_encoding)
6906 = size_of_encoded_value (cie->fde_encoding);
6913 memset (fc, 0, sizeof (Frame_Chunk));
6917 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6918 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6919 (unsigned long) (saved_start - section_start));
6921 fc->col_type = (short int *) xmalloc (sizeof (short int));
6922 fc->col_offset = (int *) xmalloc (sizeof (int));
6923 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
6925 warn (_("Invalid max register\n"));
6929 fc->augmentation = "";
6930 fc->fde_encoding = 0;
6931 fc->ptr_size = eh_addr_size;
6932 fc->segment_size = 0;
6936 fc->ncols = cie->ncols;
6937 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
6938 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
6939 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6940 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6941 fc->augmentation = cie->augmentation;
6942 fc->ptr_size = cie->ptr_size;
6943 eh_addr_size = cie->ptr_size;
6944 fc->segment_size = cie->segment_size;
6945 fc->code_factor = cie->code_factor;
6946 fc->data_factor = cie->data_factor;
6947 fc->cfa_reg = cie->cfa_reg;
6948 fc->cfa_offset = cie->cfa_offset;
6950 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
6952 warn (_("Invalid max register\n"));
6955 fc->fde_encoding = cie->fde_encoding;
6958 if (fc->fde_encoding)
6959 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6961 segment_selector = 0;
6962 if (fc->segment_size)
6964 if (fc->segment_size > sizeof (segment_selector))
6966 /* PR 17512: file: 9e196b3e. */
6967 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
6968 fc->segment_size = 4;
6970 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
6973 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
6975 /* FIXME: It appears that sometimes the final pc_range value is
6976 encoded in less than encoded_ptr_size bytes. See the x86_64
6977 run of the "objcopy on compressed debug sections" test for an
6979 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
6981 if (cie->augmentation[0] == 'z')
6983 READ_ULEB (augmentation_data_len);
6984 augmentation_data = start;
6985 start += augmentation_data_len;
6986 /* PR 17512: file: 722-8446-0.004. */
6987 if (start >= end || ((signed long) augmentation_data_len) < 0)
6989 warn (_("Corrupt augmentation data length: %lx\n"),
6990 augmentation_data_len);
6992 augmentation_data = NULL;
6993 augmentation_data_len = 0;
6997 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6998 (unsigned long)(saved_start - section_start),
6999 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7000 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7001 (unsigned long)(cie->chunk_start - section_start));
7003 if (fc->segment_size)
7004 printf ("%04lx:", segment_selector);
7007 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7008 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7010 if (! do_debug_frames_interp && augmentation_data_len)
7014 printf (" Augmentation data: ");
7015 for (i = 0; i < augmentation_data_len; ++i)
7016 printf (" %02x", augmentation_data[i]);
7022 /* At this point, fc is the current chunk, cie (if any) is set, and
7023 we're about to interpret instructions for the chunk. */
7024 /* ??? At present we need to do this always, since this sizes the
7025 fc->col_type and fc->col_offset arrays, which we write into always.
7026 We should probably split the interpreted and non-interpreted bits
7027 into two different routines, since there's so much that doesn't
7028 really overlap between them. */
7029 if (1 || do_debug_frames_interp)
7031 /* Start by making a pass over the chunk, allocating storage
7032 and taking note of what registers are used. */
7033 unsigned char *tmp = start;
7035 while (start < block_end)
7037 unsigned int reg, op, opa;
7039 unsigned char * new_start;
7046 /* Warning: if you add any more cases to this switch, be
7047 sure to add them to the corresponding switch below. */
7050 case DW_CFA_advance_loc:
7054 if (frame_need_space (fc, opa) >= 0)
7055 fc->col_type[opa] = DW_CFA_undefined;
7057 case DW_CFA_restore:
7058 if (frame_need_space (fc, opa) >= 0)
7059 fc->col_type[opa] = DW_CFA_undefined;
7061 case DW_CFA_set_loc:
7062 start += encoded_ptr_size;
7064 case DW_CFA_advance_loc1:
7067 case DW_CFA_advance_loc2:
7070 case DW_CFA_advance_loc4:
7073 case DW_CFA_offset_extended:
7074 case DW_CFA_val_offset:
7077 if (frame_need_space (fc, reg) >= 0)
7078 fc->col_type[reg] = DW_CFA_undefined;
7080 case DW_CFA_restore_extended:
7082 if (frame_need_space (fc, reg) >= 0)
7083 fc->col_type[reg] = DW_CFA_undefined;
7085 case DW_CFA_undefined:
7087 if (frame_need_space (fc, reg) >= 0)
7088 fc->col_type[reg] = DW_CFA_undefined;
7090 case DW_CFA_same_value:
7092 if (frame_need_space (fc, reg) >= 0)
7093 fc->col_type[reg] = DW_CFA_undefined;
7095 case DW_CFA_register:
7098 if (frame_need_space (fc, reg) >= 0)
7099 fc->col_type[reg] = DW_CFA_undefined;
7101 case DW_CFA_def_cfa:
7105 case DW_CFA_def_cfa_register:
7108 case DW_CFA_def_cfa_offset:
7111 case DW_CFA_def_cfa_expression:
7113 new_start = start + temp;
7114 if (new_start < start)
7116 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7122 case DW_CFA_expression:
7123 case DW_CFA_val_expression:
7126 new_start = start + temp;
7127 if (new_start < start)
7129 /* PR 17512: file:306-192417-0.005. */
7130 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7135 if (frame_need_space (fc, reg) >= 0)
7136 fc->col_type[reg] = DW_CFA_undefined;
7138 case DW_CFA_offset_extended_sf:
7139 case DW_CFA_val_offset_sf:
7142 if (frame_need_space (fc, reg) >= 0)
7143 fc->col_type[reg] = DW_CFA_undefined;
7145 case DW_CFA_def_cfa_sf:
7149 case DW_CFA_def_cfa_offset_sf:
7152 case DW_CFA_MIPS_advance_loc8:
7155 case DW_CFA_GNU_args_size:
7158 case DW_CFA_GNU_negative_offset_extended:
7161 if (frame_need_space (fc, reg) >= 0)
7162 fc->col_type[reg] = DW_CFA_undefined;
7173 /* Now we know what registers are used, make a second pass over
7174 the chunk, this time actually printing out the info. */
7176 while (start < block_end)
7178 unsigned char * tmp;
7180 unsigned long ul, roffs;
7181 /* Note: It is tempting to use an unsigned long for 'reg' but there
7182 are various functions, notably frame_space_needed() that assume that
7183 reg is an unsigned int. */
7188 const char *reg_prefix = "";
7195 /* Make a note if something other than DW_CFA_nop happens. */
7196 if (op != DW_CFA_nop)
7199 /* Warning: if you add any more cases to this switch, be
7200 sure to add them to the corresponding switch above. */
7203 case DW_CFA_advance_loc:
7204 if (do_debug_frames_interp)
7205 frame_display_row (fc, &need_col_headers, &max_regs);
7207 printf (" DW_CFA_advance_loc: %d to %s\n",
7208 opa * fc->code_factor,
7209 dwarf_vmatoa_1 (NULL,
7210 fc->pc_begin + opa * fc->code_factor,
7212 fc->pc_begin += opa * fc->code_factor;
7217 if (opa >= (unsigned int) fc->ncols)
7218 reg_prefix = bad_reg;
7219 if (! do_debug_frames_interp || *reg_prefix != '\0')
7220 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7221 reg_prefix, regname (opa, 0),
7222 roffs * fc->data_factor);
7223 if (*reg_prefix == '\0')
7225 fc->col_type[opa] = DW_CFA_offset;
7226 fc->col_offset[opa] = roffs * fc->data_factor;
7230 case DW_CFA_restore:
7231 if (opa >= (unsigned int) fc->ncols)
7232 reg_prefix = bad_reg;
7233 if (! do_debug_frames_interp || *reg_prefix != '\0')
7234 printf (" DW_CFA_restore: %s%s\n",
7235 reg_prefix, regname (opa, 0));
7236 if (*reg_prefix != '\0')
7239 if (opa >= (unsigned int) cie->ncols
7240 || (do_debug_frames_interp
7241 && cie->col_type[opa] == DW_CFA_unreferenced))
7243 fc->col_type[opa] = DW_CFA_undefined;
7244 fc->col_offset[opa] = 0;
7248 fc->col_type[opa] = cie->col_type[opa];
7249 fc->col_offset[opa] = cie->col_offset[opa];
7253 case DW_CFA_set_loc:
7254 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7255 if (do_debug_frames_interp)
7256 frame_display_row (fc, &need_col_headers, &max_regs);
7258 printf (" DW_CFA_set_loc: %s\n",
7259 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7263 case DW_CFA_advance_loc1:
7264 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7265 if (do_debug_frames_interp)
7266 frame_display_row (fc, &need_col_headers, &max_regs);
7268 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7269 (unsigned long) (ofs * fc->code_factor),
7270 dwarf_vmatoa_1 (NULL,
7271 fc->pc_begin + ofs * fc->code_factor,
7273 fc->pc_begin += ofs * fc->code_factor;
7276 case DW_CFA_advance_loc2:
7277 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7278 if (do_debug_frames_interp)
7279 frame_display_row (fc, &need_col_headers, &max_regs);
7281 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7282 (unsigned long) (ofs * fc->code_factor),
7283 dwarf_vmatoa_1 (NULL,
7284 fc->pc_begin + ofs * fc->code_factor,
7286 fc->pc_begin += ofs * fc->code_factor;
7289 case DW_CFA_advance_loc4:
7290 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7291 if (do_debug_frames_interp)
7292 frame_display_row (fc, &need_col_headers, &max_regs);
7294 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7295 (unsigned long) (ofs * fc->code_factor),
7296 dwarf_vmatoa_1 (NULL,
7297 fc->pc_begin + ofs * fc->code_factor,
7299 fc->pc_begin += ofs * fc->code_factor;
7302 case DW_CFA_offset_extended:
7305 if (reg >= (unsigned int) fc->ncols)
7306 reg_prefix = bad_reg;
7307 if (! do_debug_frames_interp || *reg_prefix != '\0')
7308 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7309 reg_prefix, regname (reg, 0),
7310 roffs * fc->data_factor);
7311 if (*reg_prefix == '\0')
7313 fc->col_type[reg] = DW_CFA_offset;
7314 fc->col_offset[reg] = roffs * fc->data_factor;
7318 case DW_CFA_val_offset:
7321 if (reg >= (unsigned int) fc->ncols)
7322 reg_prefix = bad_reg;
7323 if (! do_debug_frames_interp || *reg_prefix != '\0')
7324 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7325 reg_prefix, regname (reg, 0),
7326 roffs * fc->data_factor);
7327 if (*reg_prefix == '\0')
7329 fc->col_type[reg] = DW_CFA_val_offset;
7330 fc->col_offset[reg] = roffs * fc->data_factor;
7334 case DW_CFA_restore_extended:
7336 if (reg >= (unsigned int) fc->ncols)
7337 reg_prefix = bad_reg;
7338 if (! do_debug_frames_interp || *reg_prefix != '\0')
7339 printf (" DW_CFA_restore_extended: %s%s\n",
7340 reg_prefix, regname (reg, 0));
7341 if (*reg_prefix != '\0')
7344 if (reg >= (unsigned int) cie->ncols)
7346 fc->col_type[reg] = DW_CFA_undefined;
7347 fc->col_offset[reg] = 0;
7351 fc->col_type[reg] = cie->col_type[reg];
7352 fc->col_offset[reg] = cie->col_offset[reg];
7356 case DW_CFA_undefined:
7358 if (reg >= (unsigned int) fc->ncols)
7359 reg_prefix = bad_reg;
7360 if (! do_debug_frames_interp || *reg_prefix != '\0')
7361 printf (" DW_CFA_undefined: %s%s\n",
7362 reg_prefix, regname (reg, 0));
7363 if (*reg_prefix == '\0')
7365 fc->col_type[reg] = DW_CFA_undefined;
7366 fc->col_offset[reg] = 0;
7370 case DW_CFA_same_value:
7372 if (reg >= (unsigned int) fc->ncols)
7373 reg_prefix = bad_reg;
7374 if (! do_debug_frames_interp || *reg_prefix != '\0')
7375 printf (" DW_CFA_same_value: %s%s\n",
7376 reg_prefix, regname (reg, 0));
7377 if (*reg_prefix == '\0')
7379 fc->col_type[reg] = DW_CFA_same_value;
7380 fc->col_offset[reg] = 0;
7384 case DW_CFA_register:
7387 if (reg >= (unsigned int) fc->ncols)
7388 reg_prefix = bad_reg;
7389 if (! do_debug_frames_interp || *reg_prefix != '\0')
7391 printf (" DW_CFA_register: %s%s in ",
7392 reg_prefix, regname (reg, 0));
7393 puts (regname (roffs, 0));
7395 if (*reg_prefix == '\0')
7397 fc->col_type[reg] = DW_CFA_register;
7398 fc->col_offset[reg] = roffs;
7402 case DW_CFA_remember_state:
7403 if (! do_debug_frames_interp)
7404 printf (" DW_CFA_remember_state\n");
7405 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7406 rs->cfa_offset = fc->cfa_offset;
7407 rs->cfa_reg = fc->cfa_reg;
7409 rs->cfa_exp = fc->cfa_exp;
7410 rs->ncols = fc->ncols;
7411 rs->col_type = (short int *) xcmalloc (rs->ncols,
7412 sizeof (* rs->col_type));
7413 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7414 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7415 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7416 rs->next = remembered_state;
7417 remembered_state = rs;
7420 case DW_CFA_restore_state:
7421 if (! do_debug_frames_interp)
7422 printf (" DW_CFA_restore_state\n");
7423 rs = remembered_state;
7426 remembered_state = rs->next;
7427 fc->cfa_offset = rs->cfa_offset;
7428 fc->cfa_reg = rs->cfa_reg;
7430 fc->cfa_exp = rs->cfa_exp;
7431 if (frame_need_space (fc, rs->ncols - 1) < 0)
7433 warn (_("Invalid column number in saved frame state\n"));
7437 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7438 memcpy (fc->col_offset, rs->col_offset,
7439 rs->ncols * sizeof (* rs->col_offset));
7440 free (rs->col_type);
7441 free (rs->col_offset);
7444 else if (do_debug_frames_interp)
7445 printf ("Mismatched DW_CFA_restore_state\n");
7448 case DW_CFA_def_cfa:
7449 READ_SLEB (fc->cfa_reg);
7450 READ_ULEB (fc->cfa_offset);
7452 if (! do_debug_frames_interp)
7453 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7454 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7457 case DW_CFA_def_cfa_register:
7458 READ_SLEB (fc->cfa_reg);
7460 if (! do_debug_frames_interp)
7461 printf (" DW_CFA_def_cfa_register: %s\n",
7462 regname (fc->cfa_reg, 0));
7465 case DW_CFA_def_cfa_offset:
7466 READ_ULEB (fc->cfa_offset);
7467 if (! do_debug_frames_interp)
7468 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7472 if (! do_debug_frames_interp)
7473 printf (" DW_CFA_nop\n");
7476 case DW_CFA_def_cfa_expression:
7478 if (start >= block_end || ul > (unsigned long) (block_end - start))
7480 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7483 if (! do_debug_frames_interp)
7485 printf (" DW_CFA_def_cfa_expression (");
7486 decode_location_expression (start, eh_addr_size, 0, -1,
7494 case DW_CFA_expression:
7497 if (reg >= (unsigned int) fc->ncols)
7498 reg_prefix = bad_reg;
7499 /* PR 17512: file: 069-133014-0.006. */
7500 /* PR 17512: file: 98c02eb4. */
7502 if (start >= block_end || tmp > block_end || tmp < start)
7504 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7507 if (! do_debug_frames_interp || *reg_prefix != '\0')
7509 printf (" DW_CFA_expression: %s%s (",
7510 reg_prefix, regname (reg, 0));
7511 decode_location_expression (start, eh_addr_size, 0, -1,
7515 if (*reg_prefix == '\0')
7516 fc->col_type[reg] = DW_CFA_expression;
7520 case DW_CFA_val_expression:
7523 if (reg >= (unsigned int) fc->ncols)
7524 reg_prefix = bad_reg;
7526 if (start >= block_end || tmp > block_end || tmp < start)
7528 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7531 if (! do_debug_frames_interp || *reg_prefix != '\0')
7533 printf (" DW_CFA_val_expression: %s%s (",
7534 reg_prefix, regname (reg, 0));
7535 decode_location_expression (start, eh_addr_size, 0, -1,
7539 if (*reg_prefix == '\0')
7540 fc->col_type[reg] = DW_CFA_val_expression;
7544 case DW_CFA_offset_extended_sf:
7547 if (frame_need_space (fc, reg) < 0)
7548 reg_prefix = bad_reg;
7549 if (! do_debug_frames_interp || *reg_prefix != '\0')
7550 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7551 reg_prefix, regname (reg, 0),
7552 (long)(l * fc->data_factor));
7553 if (*reg_prefix == '\0')
7555 fc->col_type[reg] = DW_CFA_offset;
7556 fc->col_offset[reg] = l * fc->data_factor;
7560 case DW_CFA_val_offset_sf:
7563 if (frame_need_space (fc, reg) < 0)
7564 reg_prefix = bad_reg;
7565 if (! do_debug_frames_interp || *reg_prefix != '\0')
7566 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7567 reg_prefix, regname (reg, 0),
7568 (long)(l * fc->data_factor));
7569 if (*reg_prefix == '\0')
7571 fc->col_type[reg] = DW_CFA_val_offset;
7572 fc->col_offset[reg] = l * fc->data_factor;
7576 case DW_CFA_def_cfa_sf:
7577 READ_SLEB (fc->cfa_reg);
7578 READ_ULEB (fc->cfa_offset);
7579 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7581 if (! do_debug_frames_interp)
7582 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7583 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7586 case DW_CFA_def_cfa_offset_sf:
7587 READ_ULEB (fc->cfa_offset);
7588 fc->cfa_offset *= fc->data_factor;
7589 if (! do_debug_frames_interp)
7590 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7593 case DW_CFA_MIPS_advance_loc8:
7594 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7595 if (do_debug_frames_interp)
7596 frame_display_row (fc, &need_col_headers, &max_regs);
7598 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7599 (unsigned long) (ofs * fc->code_factor),
7600 dwarf_vmatoa_1 (NULL,
7601 fc->pc_begin + ofs * fc->code_factor,
7603 fc->pc_begin += ofs * fc->code_factor;
7606 case DW_CFA_GNU_window_save:
7607 if (! do_debug_frames_interp)
7608 printf (" DW_CFA_GNU_window_save\n");
7611 case DW_CFA_GNU_args_size:
7613 if (! do_debug_frames_interp)
7614 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7617 case DW_CFA_GNU_negative_offset_extended:
7621 if (frame_need_space (fc, reg) < 0)
7622 reg_prefix = bad_reg;
7623 if (! do_debug_frames_interp || *reg_prefix != '\0')
7624 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7625 reg_prefix, regname (reg, 0),
7626 (long)(l * fc->data_factor));
7627 if (*reg_prefix == '\0')
7629 fc->col_type[reg] = DW_CFA_offset;
7630 fc->col_offset[reg] = l * fc->data_factor;
7635 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7636 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7638 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7643 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7644 if (do_debug_frames_interp && ! all_nops)
7645 frame_display_row (fc, &need_col_headers, &max_regs);
7648 eh_addr_size = saved_eh_addr_size;
7659 display_debug_names (struct dwarf_section *section, void *file)
7661 unsigned char *hdrptr = section->start;
7662 dwarf_vma unit_length;
7663 unsigned char *unit_start;
7664 const unsigned char *const section_end = section->start + section->size;
7665 unsigned char *unit_end;
7667 printf (_("Contents of the %s section:\n"), section->name);
7669 load_debug_section (str, file);
7671 for (; hdrptr < section_end; hdrptr = unit_end)
7673 unsigned int offset_size;
7674 uint16_t dwarf_version, padding;
7675 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
7676 uint32_t bucket_count, name_count, abbrev_table_size;
7677 uint32_t augmentation_string_size;
7680 unit_start = hdrptr;
7682 /* Get and check the length of the block. */
7683 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
7685 if (unit_length == 0xffffffff)
7687 /* This section is 64-bit DWARF. */
7688 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
7693 unit_end = hdrptr + unit_length;
7695 if ((hdrptr - section->start) + unit_length > section->size)
7697 warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names "
7698 "header is wrong - the section is too small\n"),
7699 (long) unit_length, (long) (unit_start - section->start));
7703 /* Get and check the version number. */
7704 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
7705 printf (_("Version %ld\n"), (long) dwarf_version);
7707 /* Prior versions did not exist, and future versions may not be
7708 backwards compatible. */
7709 if (dwarf_version != 5)
7711 warn (_("Only DWARF version 5 .debug_names "
7712 "is currently supported.\n"));
7716 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
7718 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
7721 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
7722 if (comp_unit_count == 0)
7723 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
7725 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
7726 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
7727 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
7728 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
7729 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
7731 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
7732 if (augmentation_string_size % 4 != 0)
7734 warn (_("Augmentation string length %u must be rounded up "
7735 "to a multiple of 4 in .debug_names.\n"),
7736 augmentation_string_size);
7737 augmentation_string_size += (-augmentation_string_size) & 3;
7739 printf (_("Augmentation string:"));
7740 for (i = 0; i < augmentation_string_size; i++)
7744 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
7745 printf (" %02x", uc);
7750 printf (_("CU table:\n"));
7751 for (i = 0; i < comp_unit_count; i++)
7755 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
7756 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
7760 printf (_("TU table:\n"));
7761 for (i = 0; i < local_type_unit_count; i++)
7765 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
7766 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
7770 printf (_("Foreign TU table:\n"));
7771 for (i = 0; i < foreign_type_unit_count; i++)
7775 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
7776 printf (_("[%3u] "), i);
7777 print_dwarf_vma (signature, 8);
7782 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
7783 hdrptr += bucket_count * sizeof (uint32_t);
7784 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
7785 hdrptr += name_count * sizeof (uint32_t);
7786 unsigned char *const name_table_string_offsets = hdrptr;
7787 hdrptr += name_count * offset_size;
7788 unsigned char *const name_table_entry_offsets = hdrptr;
7789 hdrptr += name_count * offset_size;
7790 unsigned char *const abbrev_table = hdrptr;
7791 hdrptr += abbrev_table_size;
7792 const unsigned char *const abbrev_table_end = hdrptr;
7793 unsigned char *const entry_pool = hdrptr;
7794 if (hdrptr > unit_end)
7796 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
7797 "for unit 0x%lx in the debug_names\n"),
7798 (long) (hdrptr - section->start),
7799 (long) (unit_end - section->start),
7800 (long) (unit_start - section->start));
7804 size_t buckets_filled = 0;
7806 for (bucketi = 0; bucketi < bucket_count; bucketi++)
7808 const uint32_t bucket = hash_table_buckets[bucketi];
7813 printf (_("Used %zu of %lu buckets.\n"), buckets_filled,
7814 (unsigned long) bucket_count);
7817 size_t hash_clash_count = 0;
7818 size_t longest_clash = 0;
7819 size_t this_length = 0;
7821 for (hashi = 0; hashi < name_count; hashi++)
7823 const uint32_t hash_this = hash_table_hashes[hashi];
7827 if (hash_prev % bucket_count == hash_this % bucket_count)
7831 longest_clash = MAX (longest_clash, this_length);
7836 hash_prev = hash_this;
7838 printf (_("Out of %lu items there are %zu bucket clashes"
7839 " (longest of %zu entries).\n"),
7840 (unsigned long) name_count, hash_clash_count, longest_clash);
7841 assert (name_count == buckets_filled + hash_clash_count);
7843 struct abbrev_lookup_entry
7845 dwarf_vma abbrev_tag;
7846 unsigned char *abbrev_lookup_ptr;
7848 struct abbrev_lookup_entry *abbrev_lookup = NULL;
7849 size_t abbrev_lookup_used = 0;
7850 size_t abbrev_lookup_allocated = 0;
7852 unsigned char *abbrevptr = abbrev_table;
7855 unsigned int bytes_read;
7856 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
7858 abbrevptr += bytes_read;
7859 if (abbrev_tag == 0)
7861 if (abbrev_lookup_used == abbrev_lookup_allocated)
7863 abbrev_lookup_allocated = MAX (0x100,
7864 abbrev_lookup_allocated * 2);
7865 abbrev_lookup = xrealloc (abbrev_lookup,
7866 (abbrev_lookup_allocated
7867 * sizeof (*abbrev_lookup)));
7869 assert (abbrev_lookup_used < abbrev_lookup_allocated);
7870 struct abbrev_lookup_entry *entry;
7871 for (entry = abbrev_lookup;
7872 entry < abbrev_lookup + abbrev_lookup_used;
7874 if (entry->abbrev_tag == abbrev_tag)
7876 warn (_("Duplicate abbreviation tag %lu "
7877 "in unit 0x%lx in the debug_names\n"),
7878 (long) abbrev_tag, (long) (unit_start - section->start));
7881 entry = &abbrev_lookup[abbrev_lookup_used++];
7882 entry->abbrev_tag = abbrev_tag;
7883 entry->abbrev_lookup_ptr = abbrevptr;
7885 /* Skip DWARF tag. */
7886 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
7887 abbrevptr += bytes_read;
7890 const dwarf_vma xindex = read_uleb128 (abbrevptr,
7893 abbrevptr += bytes_read;
7894 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
7896 abbrevptr += bytes_read;
7897 if (xindex == 0 && form == 0)
7902 printf (_("\nSymbol table:\n"));
7904 for (namei = 0; namei < name_count; ++namei)
7906 uint64_t string_offset, entry_offset;
7908 SAFE_BYTE_GET (string_offset,
7909 name_table_string_offsets + namei * offset_size,
7910 offset_size, unit_end);
7911 SAFE_BYTE_GET (entry_offset,
7912 name_table_entry_offsets + namei * offset_size,
7913 offset_size, unit_end);
7915 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
7916 fetch_indirect_string (string_offset));
7918 unsigned char *entryptr = entry_pool + entry_offset;
7920 // We need to scan first whether there is a single or multiple
7921 // entries. TAGNO is -2 for the first entry, it is -1 for the
7922 // initial tag read of the second entry, then it becomes 0 for the
7923 // first entry for real printing etc.
7925 /* Initialize it due to a false compiler warning. */
7926 dwarf_vma second_abbrev_tag = -1;
7929 unsigned int bytes_read;
7930 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
7932 entryptr += bytes_read;
7935 second_abbrev_tag = abbrev_tag;
7937 entryptr = entry_pool + entry_offset;
7940 if (abbrev_tag == 0)
7944 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
7945 (unsigned long) abbrev_tag);
7947 const struct abbrev_lookup_entry *entry;
7948 for (entry = abbrev_lookup;
7949 entry < abbrev_lookup + abbrev_lookup_used;
7951 if (entry->abbrev_tag == abbrev_tag)
7953 if (entry >= abbrev_lookup + abbrev_lookup_used)
7955 warn (_("Undefined abbreviation tag %lu "
7956 "in unit 0x%lx in the debug_names\n"),
7958 (long) (unit_start - section->start));
7961 abbrevptr = entry->abbrev_lookup_ptr;
7962 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
7964 abbrevptr += bytes_read;
7966 printf (" %s", get_TAG_name (dwarf_tag));
7969 const dwarf_vma xindex = read_uleb128 (abbrevptr,
7972 abbrevptr += bytes_read;
7973 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
7975 abbrevptr += bytes_read;
7976 if (xindex == 0 && form == 0)
7980 printf (" %s", get_IDX_name (xindex));
7981 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
7984 dwarf_version, NULL,
7991 printf (_(" <no entries>"));
7995 free (abbrev_lookup);
8002 display_gdb_index (struct dwarf_section *section,
8003 void *file ATTRIBUTE_UNUSED)
8005 unsigned char *start = section->start;
8007 uint32_t cu_list_offset, tu_list_offset;
8008 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8009 unsigned int cu_list_elements, tu_list_elements;
8010 unsigned int address_table_size, symbol_table_slots;
8011 unsigned char *cu_list, *tu_list;
8012 unsigned char *address_table, *symbol_table, *constant_pool;
8015 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8017 printf (_("Contents of the %s section:\n"), section->name);
8019 if (section->size < 6 * sizeof (uint32_t))
8021 warn (_("Truncated header in the %s section.\n"), section->name);
8025 version = byte_get_little_endian (start, 4);
8026 printf (_("Version %ld\n"), (long) version);
8028 /* Prior versions are obsolete, and future versions may not be
8029 backwards compatible. */
8030 if (version < 3 || version > 8)
8032 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8036 warn (_("The address table data in version 3 may be wrong.\n"));
8038 warn (_("Version 4 does not support case insensitive lookups.\n"));
8040 warn (_("Version 5 does not include inlined functions.\n"));
8042 warn (_("Version 6 does not include symbol attributes.\n"));
8043 /* Version 7 indices generated by Gold have bad type unit references,
8044 PR binutils/15021. But we don't know if the index was generated by
8045 Gold or not, so to avoid worrying users with gdb-generated indices
8046 we say nothing for version 7 here. */
8048 cu_list_offset = byte_get_little_endian (start + 4, 4);
8049 tu_list_offset = byte_get_little_endian (start + 8, 4);
8050 address_table_offset = byte_get_little_endian (start + 12, 4);
8051 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8052 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8054 if (cu_list_offset > section->size
8055 || tu_list_offset > section->size
8056 || address_table_offset > section->size
8057 || symbol_table_offset > section->size
8058 || constant_pool_offset > section->size)
8060 warn (_("Corrupt header in the %s section.\n"), section->name);
8064 /* PR 17531: file: 418d0a8a. */
8065 if (tu_list_offset < cu_list_offset)
8067 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8068 tu_list_offset, cu_list_offset);
8072 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8074 if (address_table_offset < tu_list_offset)
8076 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8077 address_table_offset, tu_list_offset);
8081 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8083 /* PR 17531: file: 18a47d3d. */
8084 if (symbol_table_offset < address_table_offset)
8086 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
8087 symbol_table_offset, address_table_offset);
8091 address_table_size = symbol_table_offset - address_table_offset;
8093 if (constant_pool_offset < symbol_table_offset)
8095 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8096 constant_pool_offset, symbol_table_offset);
8100 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8102 cu_list = start + cu_list_offset;
8103 tu_list = start + tu_list_offset;
8104 address_table = start + address_table_offset;
8105 symbol_table = start + symbol_table_offset;
8106 constant_pool = start + constant_pool_offset;
8108 if (address_table + address_table_size > section->start + section->size)
8110 warn (_("Address table extends beyond end of section.\n"));
8114 printf (_("\nCU table:\n"));
8115 for (i = 0; i < cu_list_elements; i += 2)
8117 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8118 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8120 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8121 (unsigned long) cu_offset,
8122 (unsigned long) (cu_offset + cu_length - 1));
8125 printf (_("\nTU table:\n"));
8126 for (i = 0; i < tu_list_elements; i += 3)
8128 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8129 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8130 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8132 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8133 (unsigned long) tu_offset,
8134 (unsigned long) type_offset);
8135 print_dwarf_vma (signature, 8);
8139 printf (_("\nAddress table:\n"));
8140 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8143 uint64_t low = byte_get_little_endian (address_table + i, 8);
8144 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8145 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8147 print_dwarf_vma (low, 8);
8148 print_dwarf_vma (high, 8);
8149 printf (_("%lu\n"), (unsigned long) cu_index);
8152 printf (_("\nSymbol table:\n"));
8153 for (i = 0; i < symbol_table_slots; ++i)
8155 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8156 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8157 uint32_t num_cus, cu;
8159 if (name_offset != 0
8160 || cu_vector_offset != 0)
8163 unsigned char * adr;
8165 adr = constant_pool + name_offset;
8166 /* PR 17531: file: 5b7b07ad. */
8167 if (adr < constant_pool || adr >= section->start + section->size)
8169 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8170 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8174 printf ("[%3u] %.*s:", i,
8175 (int) (section->size - (constant_pool_offset + name_offset)),
8176 constant_pool + name_offset);
8178 adr = constant_pool + cu_vector_offset;
8179 if (adr < constant_pool || adr >= section->start + section->size - 3)
8181 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8182 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8183 cu_vector_offset, i);
8187 num_cus = byte_get_little_endian (adr, 4);
8189 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8190 if (num_cus * 4 < num_cus
8191 || adr >= section->start + section->size
8192 || adr < constant_pool)
8194 printf ("<invalid number of CUs: %d>\n", num_cus);
8195 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8203 for (j = 0; j < num_cus; ++j)
8206 gdb_index_symbol_kind kind;
8208 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8209 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8210 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8211 cu = GDB_INDEX_CU_VALUE (cu);
8212 /* Convert to TU number if it's for a type unit. */
8213 if (cu >= cu_list_elements / 2)
8214 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8215 (unsigned long) (cu - cu_list_elements / 2));
8217 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8219 printf (" [%s, %s]",
8220 is_static ? _("static") : _("global"),
8221 get_gdb_index_symbol_kind_name (kind));
8233 /* Pre-allocate enough space for the CU/TU sets needed. */
8236 prealloc_cu_tu_list (unsigned int nshndx)
8238 if (shndx_pool == NULL)
8240 shndx_pool_size = nshndx;
8241 shndx_pool_used = 0;
8242 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8243 sizeof (unsigned int));
8247 shndx_pool_size = shndx_pool_used + nshndx;
8248 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8249 sizeof (unsigned int));
8254 add_shndx_to_cu_tu_entry (unsigned int shndx)
8256 if (shndx_pool_used >= shndx_pool_size)
8258 error (_("Internal error: out of space in the shndx pool.\n"));
8261 shndx_pool [shndx_pool_used++] = shndx;
8265 end_cu_tu_entry (void)
8267 if (shndx_pool_used >= shndx_pool_size)
8269 error (_("Internal error: out of space in the shndx pool.\n"));
8272 shndx_pool [shndx_pool_used++] = 0;
8275 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8278 get_DW_SECT_short_name (unsigned int dw_sect)
8280 static char buf[16];
8288 case DW_SECT_ABBREV:
8294 case DW_SECT_STR_OFFSETS:
8296 case DW_SECT_MACINFO:
8304 snprintf (buf, sizeof (buf), "%d", dw_sect);
8308 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8309 These sections are extensions for Fission.
8310 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8313 process_cu_tu_index (struct dwarf_section *section, int do_display)
8315 unsigned char *phdr = section->start;
8316 unsigned char *limit = phdr + section->size;
8317 unsigned char *phash;
8318 unsigned char *pindex;
8319 unsigned char *ppool;
8320 unsigned int version;
8321 unsigned int ncols = 0;
8323 unsigned int nslots;
8326 dwarf_vma signature_high;
8327 dwarf_vma signature_low;
8330 /* PR 17512: file: 002-168123-0.004. */
8333 warn (_("Section %s is empty\n"), section->name);
8336 /* PR 17512: file: 002-376-0.004. */
8337 if (section->size < 24)
8339 warn (_("Section %s is too small to contain a CU/TU header\n"),
8344 SAFE_BYTE_GET (version, phdr, 4, limit);
8346 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8347 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8348 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8351 pindex = phash + nslots * 8;
8352 ppool = pindex + nslots * 4;
8354 /* PR 17531: file: 45d69832. */
8355 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
8357 warn (_("Section %s is too small for %d slots\n"),
8358 section->name, nslots);
8364 printf (_("Contents of the %s section:\n\n"), section->name);
8365 printf (_(" Version: %d\n"), version);
8367 printf (_(" Number of columns: %d\n"), ncols);
8368 printf (_(" Number of used entries: %d\n"), nused);
8369 printf (_(" Number of slots: %d\n\n"), nslots);
8372 if (ppool > limit || ppool < phdr)
8374 warn (_("Section %s too small for %d hash table entries\n"),
8375 section->name, nslots);
8382 prealloc_cu_tu_list ((limit - ppool) / 4);
8383 for (i = 0; i < nslots; i++)
8385 unsigned char *shndx_list;
8388 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
8389 if (signature_high != 0 || signature_low != 0)
8391 SAFE_BYTE_GET (j, pindex, 4, limit);
8392 shndx_list = ppool + j * 4;
8393 /* PR 17531: file: 705e010d. */
8394 if (shndx_list < ppool)
8396 warn (_("Section index pool located before start of section\n"));
8401 printf (_(" [%3d] Signature: 0x%s Sections: "),
8402 i, dwarf_vmatoa64 (signature_high, signature_low,
8403 buf, sizeof (buf)));
8406 if (shndx_list >= limit)
8408 warn (_("Section %s too small for shndx pool\n"),
8412 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
8416 printf (" %d", shndx);
8418 add_shndx_to_cu_tu_entry (shndx);
8430 else if (version == 2)
8433 unsigned int dw_sect;
8434 unsigned char *ph = phash;
8435 unsigned char *pi = pindex;
8436 unsigned char *poffsets = ppool + ncols * 4;
8437 unsigned char *psizes = poffsets + nused * ncols * 4;
8438 unsigned char *pend = psizes + nused * ncols * 4;
8439 bfd_boolean is_tu_index;
8440 struct cu_tu_set *this_set = NULL;
8442 unsigned char *prow;
8444 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8446 /* PR 17531: file: 0dd159bf.
8447 Check for wraparound with an overlarge ncols value. */
8448 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
8450 warn (_("Overlarge number of columns: %x\n"), ncols);
8456 warn (_("Section %s too small for offset and size tables\n"),
8463 printf (_(" Offset table\n"));
8464 printf (" slot %-16s ",
8465 is_tu_index ? _("signature") : _("dwo_id"));
8472 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8478 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8485 for (j = 0; j < ncols; j++)
8487 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8488 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8493 for (i = 0; i < nslots; i++)
8495 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8497 SAFE_BYTE_GET (row, pi, 4, limit);
8500 /* PR 17531: file: a05f6ab3. */
8503 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8509 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8511 prow = poffsets + (row - 1) * ncols * 4;
8512 /* PR 17531: file: b8ce60a8. */
8513 if (prow < poffsets || prow > limit)
8515 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8521 printf (_(" [%3d] 0x%s"),
8522 i, dwarf_vmatoa64 (signature_high, signature_low,
8523 buf, sizeof (buf)));
8524 for (j = 0; j < ncols; j++)
8526 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8528 printf (" %8d", val);
8531 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8533 /* PR 17531: file: 10796eb3. */
8534 if (dw_sect >= DW_SECT_MAX)
8535 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8537 this_set [row - 1].section_offsets [dw_sect] = val;
8553 printf (_(" Size table\n"));
8554 printf (" slot %-16s ",
8555 is_tu_index ? _("signature") : _("dwo_id"));
8558 for (j = 0; j < ncols; j++)
8560 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8562 printf (" %8s", get_DW_SECT_short_name (val));
8568 for (i = 0; i < nslots; i++)
8570 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8572 SAFE_BYTE_GET (row, pi, 4, limit);
8575 prow = psizes + (row - 1) * ncols * 4;
8578 printf (_(" [%3d] 0x%s"),
8579 i, dwarf_vmatoa64 (signature_high, signature_low,
8580 buf, sizeof (buf)));
8582 for (j = 0; j < ncols; j++)
8584 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8586 printf (" %8d", val);
8589 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8590 if (dw_sect >= DW_SECT_MAX)
8591 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8593 this_set [row - 1].section_sizes [dw_sect] = val;
8605 else if (do_display)
8606 printf (_(" Unsupported version (%d)\n"), version);
8614 /* Load the CU and TU indexes if present. This will build a list of
8615 section sets that we can use to associate a .debug_info.dwo section
8616 with its associated .debug_abbrev.dwo section in a .dwp file. */
8619 load_cu_tu_indexes (void *file)
8621 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8623 /* If we have already loaded (or tried to load) the CU and TU indexes
8624 then do not bother to repeat the task. */
8625 if (cu_tu_indexes_read == -1)
8627 cu_tu_indexes_read = TRUE;
8629 if (load_debug_section (dwp_cu_index, file))
8630 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8631 cu_tu_indexes_read = FALSE;
8633 if (load_debug_section (dwp_tu_index, file))
8634 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8635 cu_tu_indexes_read = FALSE;
8638 return (bfd_boolean) cu_tu_indexes_read;
8641 /* Find the set of sections that includes section SHNDX. */
8644 find_cu_tu_set (void *file, unsigned int shndx)
8648 if (! load_cu_tu_indexes (file))
8651 /* Find SHNDX in the shndx pool. */
8652 for (i = 0; i < shndx_pool_used; i++)
8653 if (shndx_pool [i] == shndx)
8656 if (i >= shndx_pool_used)
8659 /* Now backup to find the first entry in the set. */
8660 while (i > 0 && shndx_pool [i - 1] != 0)
8663 return shndx_pool + i;
8666 /* Display a .debug_cu_index or .debug_tu_index section. */
8669 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
8671 return process_cu_tu_index (section, 1);
8675 display_debug_not_supported (struct dwarf_section *section,
8676 void *file ATTRIBUTE_UNUSED)
8678 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8684 /* Like malloc, but takes two parameters like calloc.
8685 Verifies that the first parameter is not too large.
8686 Note: does *not* initialise the allocated memory to zero. */
8688 cmalloc (size_t nmemb, size_t size)
8690 /* Check for overflow. */
8691 if (nmemb >= ~(size_t) 0 / size)
8694 return xmalloc (nmemb * size);
8697 /* Like xmalloc, but takes two parameters like calloc.
8698 Verifies that the first parameter is not too large.
8699 Note: does *not* initialise the allocated memory to zero. */
8701 xcmalloc (size_t nmemb, size_t size)
8703 /* Check for overflow. */
8704 if (nmemb >= ~(size_t) 0 / size)
8707 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8712 return xmalloc (nmemb * size);
8715 /* Like xrealloc, but takes three parameters.
8716 Verifies that the second parameter is not too large.
8717 Note: does *not* initialise any new memory to zero. */
8719 xcrealloc (void *ptr, size_t nmemb, size_t size)
8721 /* Check for overflow. */
8722 if (nmemb >= ~(size_t) 0 / size)
8725 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8730 return xrealloc (ptr, nmemb * size);
8733 /* Like xcalloc, but verifies that the first parameter is not too large. */
8735 xcalloc2 (size_t nmemb, size_t size)
8737 /* Check for overflow. */
8738 if (nmemb >= ~(size_t) 0 / size)
8741 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8746 return xcalloc (nmemb, size);
8750 free_debug_memory (void)
8756 for (i = 0; i < max; i++)
8757 free_debug_section ((enum dwarf_section_display_enum) i);
8759 if (debug_information != NULL)
8761 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
8763 for (i = 0; i < num_debug_info_entries; i++)
8765 if (!debug_information [i].max_loc_offsets)
8767 free (debug_information [i].loc_offsets);
8768 free (debug_information [i].have_frame_base);
8770 if (!debug_information [i].max_range_lists)
8771 free (debug_information [i].range_lists);
8774 free (debug_information);
8775 debug_information = NULL;
8776 alloc_num_debug_info_entries = num_debug_info_entries = 0;
8781 dwarf_select_sections_by_names (const char *names)
8785 const char * option;
8789 debug_dump_long_opts;
8791 static const debug_dump_long_opts opts_table [] =
8793 /* Please keep this table alpha- sorted. */
8794 { "Ranges", & do_debug_ranges, 1 },
8795 { "abbrev", & do_debug_abbrevs, 1 },
8796 { "addr", & do_debug_addr, 1 },
8797 { "aranges", & do_debug_aranges, 1 },
8798 { "cu_index", & do_debug_cu_index, 1 },
8799 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
8800 { "frames", & do_debug_frames, 1 },
8801 { "frames-interp", & do_debug_frames_interp, 1 },
8802 /* The special .gdb_index section. */
8803 { "gdb_index", & do_gdb_index, 1 },
8804 { "info", & do_debug_info, 1 },
8805 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
8806 { "loc", & do_debug_loc, 1 },
8807 { "macro", & do_debug_macinfo, 1 },
8808 { "pubnames", & do_debug_pubnames, 1 },
8809 { "pubtypes", & do_debug_pubtypes, 1 },
8810 /* This entry is for compatibility
8811 with earlier versions of readelf. */
8812 { "ranges", & do_debug_aranges, 1 },
8813 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
8814 { "str", & do_debug_str, 1 },
8815 /* These trace_* sections are used by Itanium VMS. */
8816 { "trace_abbrev", & do_trace_abbrevs, 1 },
8817 { "trace_aranges", & do_trace_aranges, 1 },
8818 { "trace_info", & do_trace_info, 1 },
8827 const debug_dump_long_opts * entry;
8829 for (entry = opts_table; entry->option; entry++)
8831 size_t len = strlen (entry->option);
8833 if (strncmp (p, entry->option, len) == 0
8834 && (p[len] == ',' || p[len] == '\0'))
8836 * entry->variable |= entry->val;
8838 /* The --debug-dump=frames-interp option also
8839 enables the --debug-dump=frames option. */
8840 if (do_debug_frames_interp)
8841 do_debug_frames = 1;
8848 if (entry->option == NULL)
8850 warn (_("Unrecognized debug option '%s'\n"), p);
8851 p = strchr (p, ',');
8862 dwarf_select_sections_by_letters (const char *letters)
8864 unsigned int lindex = 0;
8866 while (letters[lindex])
8867 switch (letters[lindex++])
8874 do_debug_abbrevs = 1;
8878 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
8882 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
8886 do_debug_pubnames = 1;
8890 do_debug_pubtypes = 1;
8894 do_debug_aranges = 1;
8898 do_debug_ranges = 1;
8902 do_debug_frames_interp = 1;
8905 do_debug_frames = 1;
8909 do_debug_macinfo = 1;
8921 warn (_("Unrecognized debug option '%s'\n"), letters);
8927 dwarf_select_sections_all (void)
8930 do_debug_abbrevs = 1;
8931 do_debug_lines = FLAG_DEBUG_LINES_RAW;
8932 do_debug_pubnames = 1;
8933 do_debug_pubtypes = 1;
8934 do_debug_aranges = 1;
8935 do_debug_ranges = 1;
8936 do_debug_frames = 1;
8937 do_debug_macinfo = 1;
8942 do_trace_abbrevs = 1;
8943 do_trace_aranges = 1;
8945 do_debug_cu_index = 1;
8948 struct dwarf_section_display debug_displays[] =
8950 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8951 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8952 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8953 display_debug_aranges, &do_debug_aranges, TRUE },
8954 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8955 display_debug_frames, &do_debug_frames, TRUE },
8956 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8957 display_debug_info, &do_debug_info, TRUE },
8958 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8959 display_debug_lines, &do_debug_lines, TRUE },
8960 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8961 display_debug_pubnames, &do_debug_pubnames, FALSE },
8962 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8963 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
8964 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8965 display_debug_frames, &do_debug_frames, TRUE },
8966 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8967 display_debug_macinfo, &do_debug_macinfo, FALSE },
8968 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8969 display_debug_macro, &do_debug_macinfo, TRUE },
8970 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8971 display_debug_str, &do_debug_str, FALSE },
8972 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8973 display_debug_str, &do_debug_str, FALSE },
8974 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8975 display_debug_loc, &do_debug_loc, TRUE },
8976 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8977 display_debug_loc, &do_debug_loc, TRUE },
8978 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8979 display_debug_pubnames, &do_debug_pubtypes, FALSE },
8980 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8981 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
8982 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8983 display_debug_ranges, &do_debug_ranges, TRUE },
8984 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8985 display_debug_ranges, &do_debug_ranges, TRUE },
8986 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8987 display_debug_not_supported, NULL, FALSE },
8988 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8989 display_debug_not_supported, NULL, FALSE },
8990 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8991 display_debug_types, &do_debug_info, TRUE },
8992 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8993 display_debug_not_supported, NULL, FALSE },
8994 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8995 display_gdb_index, &do_gdb_index, FALSE },
8996 { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8997 display_debug_names, &do_gdb_index, FALSE },
8998 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
8999 display_trace_info, &do_trace_info, TRUE },
9000 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9001 display_debug_abbrev, &do_trace_abbrevs, FALSE },
9002 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9003 display_debug_aranges, &do_trace_aranges, FALSE },
9004 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9005 display_debug_info, &do_debug_info, TRUE },
9006 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9007 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9008 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9009 display_debug_types, &do_debug_info, TRUE },
9010 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9011 display_debug_lines, &do_debug_lines, TRUE },
9012 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9013 display_debug_loc, &do_debug_loc, TRUE },
9014 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9015 display_debug_macro, &do_debug_macinfo, TRUE },
9016 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9017 display_debug_macinfo, &do_debug_macinfo, FALSE },
9018 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9019 display_debug_str, &do_debug_str, TRUE },
9020 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9021 display_debug_str_offsets, NULL, FALSE },
9022 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9023 display_debug_str_offsets, NULL, FALSE },
9024 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9025 display_debug_addr, &do_debug_addr, TRUE },
9026 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9027 display_cu_index, &do_debug_cu_index, FALSE },
9028 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9029 display_cu_index, &do_debug_cu_index, FALSE },
9032 /* A static assertion. */
9033 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];