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);
221 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
223 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
224 snprintf (ret, sizeof (buf[0].place), fmt, value);
229 static inline const char *
230 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
232 return dwarf_vmatoa_1 (fmtch, value, 0);
235 /* Print a dwarf_vma value (typically an address, offset or length) in
236 hexadecimal format, followed by a space. The length of the VALUE (and
237 hence the precision displayed) is determined by the NUM_BYTES parameter. */
240 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
242 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
245 /* Format a 64-bit value, given as two 32-bit values, in hex.
246 For reentrancy, this uses a buffer provided by the caller. */
249 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
250 unsigned int buf_len)
255 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
258 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
259 snprintf (buf + len, buf_len - len,
260 "%08" DWARF_VMA_FMT "x", lvalue);
266 /* Read in a LEB128 encoded value starting at address DATA.
267 If SIGN is true, return a signed LEB128 value.
268 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
269 No bytes will be read at address END or beyond. */
272 read_leb128 (unsigned char *data,
273 unsigned int *length_return,
275 const unsigned char * const end)
277 dwarf_vma result = 0;
278 unsigned int num_read = 0;
279 unsigned int shift = 0;
280 unsigned char byte = 0;
287 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
290 if ((byte & 0x80) == 0)
293 /* PR 17512: file: 0ca183b8.
294 FIXME: Should we signal this error somehow ? */
295 if (shift >= sizeof (result) * 8)
299 if (length_return != NULL)
300 *length_return = num_read;
302 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
303 result |= -((dwarf_vma) 1 << shift);
308 /* Create a signed version to avoid painful typecasts. */
309 static inline dwarf_signed_vma
310 read_sleb128 (unsigned char * data,
311 unsigned int * length_return,
312 const unsigned char * const end)
314 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
317 static inline dwarf_vma
318 read_uleb128 (unsigned char * data,
319 unsigned int * length_return,
320 const unsigned char * const end)
322 return read_leb128 (data, length_return, FALSE, end);
325 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
326 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
328 #define READ_ULEB(var) \
333 (var) = _val = read_uleb128 (start, &length_return, end); \
335 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
336 __FILE__, __LINE__, _val); \
337 start += length_return; \
341 #define READ_SLEB(var) \
344 dwarf_signed_vma _val; \
346 (var) = _val = read_sleb128 (start, &length_return, end); \
348 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
349 __FILE__, __LINE__, _val); \
350 start += length_return; \
354 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
357 unsigned int amount = (AMOUNT); \
358 if (sizeof (VAL) < amount) \
360 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
361 amount, (int) sizeof (VAL)); \
362 amount = sizeof (VAL); \
364 if (((PTR) + amount) >= (END)) \
367 amount = (END) - (PTR); \
371 if (amount == 0 || amount > 8) \
374 VAL = byte_get ((PTR), amount); \
378 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
381 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
386 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
389 unsigned int amount = (AMOUNT); \
390 if (((PTR) + amount) >= (END)) \
393 amount = (END) - (PTR); \
398 VAL = byte_get_signed ((PTR), amount); \
404 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
407 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
412 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
415 if (((PTR) + 8) <= (END)) \
417 byte_get_64 ((PTR), (HIGH), (LOW)); \
421 * (LOW) = * (HIGH) = 0; \
426 typedef struct State_Machine_Registers
435 unsigned char op_index;
436 unsigned char end_sequence;
437 /* This variable hold the number of the last entry seen
438 in the File Table. */
439 unsigned int last_file_entry;
442 static SMR state_machine_regs;
445 reset_state_machine (int is_stmt)
447 state_machine_regs.address = 0;
448 state_machine_regs.view = 0;
449 state_machine_regs.op_index = 0;
450 state_machine_regs.file = 1;
451 state_machine_regs.line = 1;
452 state_machine_regs.column = 0;
453 state_machine_regs.is_stmt = is_stmt;
454 state_machine_regs.basic_block = 0;
455 state_machine_regs.end_sequence = 0;
456 state_machine_regs.last_file_entry = 0;
459 /* Handled an extend line op.
460 Returns the number of bytes read. */
463 process_extended_line_op (unsigned char * data,
467 unsigned char op_code;
468 unsigned int bytes_read;
471 unsigned char *orig_data = data;
474 len = read_uleb128 (data, & bytes_read, end);
477 if (len == 0 || data == end || len > (uintptr_t) (end - data))
479 warn (_("Badly formed extended line op encountered!\n"));
486 printf (_(" Extended opcode %d: "), op_code);
490 case DW_LNE_end_sequence:
491 printf (_("End of Sequence\n\n"));
492 reset_state_machine (is_stmt);
495 case DW_LNE_set_address:
496 /* PR 17512: file: 002-100480-0.004. */
497 if (len - bytes_read - 1 > 8)
499 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
500 len - bytes_read - 1);
504 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
505 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
506 state_machine_regs.address = adr;
507 state_machine_regs.view = 0;
508 state_machine_regs.op_index = 0;
511 case DW_LNE_define_file:
512 printf (_("define new File Table entry\n"));
513 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
514 printf (" %d\t", ++state_machine_regs.last_file_entry);
520 l = strnlen ((char *) data, end - data);
522 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
524 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
526 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
528 printf ("%.*s\n\n", (int) l, name);
531 if (((unsigned int) (data - orig_data) != len) || data == end)
532 warn (_("DW_LNE_define_file: Bad opcode length\n"));
535 case DW_LNE_set_discriminator:
536 printf (_("set Discriminator to %s\n"),
537 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
541 case DW_LNE_HP_negate_is_UV_update:
542 printf ("DW_LNE_HP_negate_is_UV_update\n");
544 case DW_LNE_HP_push_context:
545 printf ("DW_LNE_HP_push_context\n");
547 case DW_LNE_HP_pop_context:
548 printf ("DW_LNE_HP_pop_context\n");
550 case DW_LNE_HP_set_file_line_column:
551 printf ("DW_LNE_HP_set_file_line_column\n");
553 case DW_LNE_HP_set_routine_name:
554 printf ("DW_LNE_HP_set_routine_name\n");
556 case DW_LNE_HP_set_sequence:
557 printf ("DW_LNE_HP_set_sequence\n");
559 case DW_LNE_HP_negate_post_semantics:
560 printf ("DW_LNE_HP_negate_post_semantics\n");
562 case DW_LNE_HP_negate_function_exit:
563 printf ("DW_LNE_HP_negate_function_exit\n");
565 case DW_LNE_HP_negate_front_end_logical:
566 printf ("DW_LNE_HP_negate_front_end_logical\n");
568 case DW_LNE_HP_define_proc:
569 printf ("DW_LNE_HP_define_proc\n");
571 case DW_LNE_HP_source_file_correlation:
573 unsigned char *edata = data + len - bytes_read - 1;
575 printf ("DW_LNE_HP_source_file_correlation\n");
581 opc = read_uleb128 (data, & bytes_read, edata);
586 case DW_LNE_HP_SFC_formfeed:
587 printf (" DW_LNE_HP_SFC_formfeed\n");
589 case DW_LNE_HP_SFC_set_listing_line:
590 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
592 read_uleb128 (data, & bytes_read, edata)));
595 case DW_LNE_HP_SFC_associate:
596 printf (" DW_LNE_HP_SFC_associate ");
599 read_uleb128 (data, & bytes_read, edata)));
603 read_uleb128 (data, & bytes_read, edata)));
607 read_uleb128 (data, & bytes_read, edata)));
611 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
621 unsigned int rlen = len - bytes_read - 1;
623 if (op_code >= DW_LNE_lo_user
624 /* The test against DW_LNW_hi_user is redundant due to
625 the limited range of the unsigned char data type used
627 /*&& op_code <= DW_LNE_hi_user*/)
628 printf (_("user defined: "));
630 printf (_("UNKNOWN: "));
631 printf (_("length %d ["), rlen);
633 printf (" %02x", *data++);
642 static const unsigned char *
643 fetch_indirect_string (dwarf_vma offset)
645 struct dwarf_section *section = &debug_displays [str].section;
646 const unsigned char * ret;
648 if (section->start == NULL)
649 return (const unsigned char *) _("<no .debug_str section>");
651 if (offset >= section->size)
653 warn (_("DW_FORM_strp offset too big: %s\n"),
654 dwarf_vmatoa ("x", offset));
655 return (const unsigned char *) _("<offset is too big>");
658 ret = section->start + offset;
659 /* Unfortunately we cannot rely upon the .debug_str section ending with a
660 NUL byte. Since our caller is expecting to receive a well formed C
661 string we test for the lack of a terminating byte here. */
662 if (strnlen ((const char *) ret, section->size - offset)
663 == section->size - offset)
664 ret = (const unsigned char *)
665 _("<no NUL byte at end of .debug_str section>");
670 static const unsigned char *
671 fetch_indirect_line_string (dwarf_vma offset)
673 struct dwarf_section *section = &debug_displays [line_str].section;
674 const unsigned char * ret;
676 if (section->start == NULL)
677 return (const unsigned char *) _("<no .debug_line_str section>");
679 if (offset >= section->size)
681 warn (_("DW_FORM_line_strp offset too big: %s\n"),
682 dwarf_vmatoa ("x", offset));
683 return (const unsigned char *) _("<offset is too big>");
686 ret = section->start + offset;
687 /* Unfortunately we cannot rely upon the .debug_line_str section ending
688 with a NUL byte. Since our caller is expecting to receive a well formed
689 C string we test for the lack of a terminating byte here. */
690 if (strnlen ((const char *) ret, section->size - offset)
691 == section->size - offset)
692 ret = (const unsigned char *)
693 _("<no NUL byte at end of .debug_line_str section>");
699 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
700 dwarf_vma offset_size, int dwo)
702 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
703 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
704 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
705 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
706 dwarf_vma index_offset = idx * offset_size;
707 dwarf_vma str_offset;
710 if (index_section->start == NULL)
711 return (dwo ? _("<no .debug_str_offsets.dwo section>")
712 : _("<no .debug_str_offsets section>"));
714 if (this_set != NULL)
715 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
716 if (index_offset >= index_section->size)
718 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
719 dwarf_vmatoa ("x", index_offset));
720 return _("<index offset is too big>");
723 if (str_section->start == NULL)
724 return (dwo ? _("<no .debug_str.dwo section>")
725 : _("<no .debug_str section>"));
727 str_offset = byte_get (index_section->start + index_offset, offset_size);
728 str_offset -= str_section->address;
729 if (str_offset >= str_section->size)
731 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
732 dwarf_vmatoa ("x", str_offset));
733 return _("<indirect index offset is too big>");
736 ret = (const char *) str_section->start + str_offset;
737 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
738 Since our caller is expecting to receive a well formed C string we test
739 for the lack of a terminating byte here. */
740 if (strnlen (ret, str_section->size - str_offset)
741 == str_section->size - str_offset)
742 ret = (const char *) _("<no NUL byte at end of section>");
748 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
750 struct dwarf_section *section = &debug_displays [debug_addr].section;
752 if (section->start == NULL)
753 return (_("<no .debug_addr section>"));
755 if (offset + bytes > section->size)
757 warn (_("Offset into section %s too big: %s\n"),
758 section->name, dwarf_vmatoa ("x", offset));
759 return "<offset too big>";
762 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
766 /* FIXME: There are better and more efficient ways to handle
767 these structures. For now though, I just want something that
768 is simple to implement. */
769 typedef struct abbrev_attr
771 unsigned long attribute;
773 bfd_signed_vma implicit_const;
774 struct abbrev_attr *next;
778 typedef struct abbrev_entry
783 struct abbrev_attr *first_attr;
784 struct abbrev_attr *last_attr;
785 struct abbrev_entry *next;
789 static abbrev_entry *first_abbrev = NULL;
790 static abbrev_entry *last_abbrev = NULL;
797 for (abbrv = first_abbrev; abbrv;)
799 abbrev_entry *next_abbrev = abbrv->next;
802 for (attr = abbrv->first_attr; attr;)
804 abbrev_attr *next_attr = attr->next;
814 last_abbrev = first_abbrev = NULL;
818 add_abbrev (unsigned long number, unsigned long tag, int children)
822 entry = (abbrev_entry *) malloc (sizeof (*entry));
827 entry->entry = number;
829 entry->children = children;
830 entry->first_attr = NULL;
831 entry->last_attr = NULL;
834 if (first_abbrev == NULL)
835 first_abbrev = entry;
837 last_abbrev->next = entry;
843 add_abbrev_attr (unsigned long attribute, unsigned long form,
844 bfd_signed_vma implicit_const)
848 attr = (abbrev_attr *) malloc (sizeof (*attr));
853 attr->attribute = attribute;
855 attr->implicit_const = implicit_const;
858 if (last_abbrev->first_attr == NULL)
859 last_abbrev->first_attr = attr;
861 last_abbrev->last_attr->next = attr;
863 last_abbrev->last_attr = attr;
866 /* Processes the (partial) contents of a .debug_abbrev section.
867 Returns NULL if the end of the section was encountered.
868 Returns the address after the last byte read if the end of
869 an abbreviation set was found. */
871 static unsigned char *
872 process_abbrev_section (unsigned char *start, unsigned char *end)
874 if (first_abbrev != NULL)
879 unsigned int bytes_read;
882 unsigned long attribute;
885 entry = read_uleb128 (start, & bytes_read, end);
888 /* A single zero is supposed to end the section according
889 to the standard. If there's more, then signal that to
896 tag = read_uleb128 (start, & bytes_read, end);
903 add_abbrev (entry, tag, children);
908 /* Initialize it due to a false compiler warning. */
909 bfd_signed_vma implicit_const = -1;
911 attribute = read_uleb128 (start, & bytes_read, end);
916 form = read_uleb128 (start, & bytes_read, end);
921 if (form == DW_FORM_implicit_const)
923 implicit_const = read_sleb128 (start, & bytes_read, end);
929 add_abbrev_attr (attribute, form, implicit_const);
931 while (attribute != 0);
934 /* Report the missing single zero which ends the section. */
935 error (_(".debug_abbrev section not zero terminated\n"));
941 get_TAG_name (unsigned long tag)
943 const char *name = get_DW_TAG_name ((unsigned int)tag);
947 static char buffer[100];
949 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
957 get_FORM_name (unsigned long form)
962 return "DW_FORM value: 0";
964 name = get_DW_FORM_name (form);
967 static char buffer[100];
969 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
977 get_IDX_name (unsigned long idx)
979 const char *name = get_DW_IDX_name ((unsigned int) idx);
983 static char buffer[100];
985 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
992 static unsigned char *
993 display_block (unsigned char *data,
995 const unsigned char * const end, char delimiter)
999 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
1001 return (unsigned char *) end;
1003 maxlen = (dwarf_vma) (end - data);
1004 length = length > maxlen ? maxlen : length;
1007 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1013 decode_location_expression (unsigned char * data,
1014 unsigned int pointer_size,
1015 unsigned int offset_size,
1018 dwarf_vma cu_offset,
1019 struct dwarf_section * section)
1022 unsigned int bytes_read;
1024 dwarf_signed_vma svalue;
1025 unsigned char *end = data + length;
1026 int need_frame_base = 0;
1035 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1036 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1039 printf ("DW_OP_deref");
1042 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1043 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1046 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1047 printf ("DW_OP_const1s: %ld", (long) svalue);
1050 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1051 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1054 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1055 printf ("DW_OP_const2s: %ld", (long) svalue);
1058 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1059 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1062 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1063 printf ("DW_OP_const4s: %ld", (long) svalue);
1066 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1067 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1068 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1069 printf ("%lu", (unsigned long) uvalue);
1072 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1073 printf ("DW_OP_const8s: %ld ", (long) svalue);
1074 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1075 printf ("%ld", (long) svalue);
1078 printf ("DW_OP_constu: %s",
1079 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1083 printf ("DW_OP_consts: %s",
1084 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1088 printf ("DW_OP_dup");
1091 printf ("DW_OP_drop");
1094 printf ("DW_OP_over");
1097 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1098 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1101 printf ("DW_OP_swap");
1104 printf ("DW_OP_rot");
1107 printf ("DW_OP_xderef");
1110 printf ("DW_OP_abs");
1113 printf ("DW_OP_and");
1116 printf ("DW_OP_div");
1119 printf ("DW_OP_minus");
1122 printf ("DW_OP_mod");
1125 printf ("DW_OP_mul");
1128 printf ("DW_OP_neg");
1131 printf ("DW_OP_not");
1134 printf ("DW_OP_or");
1137 printf ("DW_OP_plus");
1139 case DW_OP_plus_uconst:
1140 printf ("DW_OP_plus_uconst: %s",
1141 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1145 printf ("DW_OP_shl");
1148 printf ("DW_OP_shr");
1151 printf ("DW_OP_shra");
1154 printf ("DW_OP_xor");
1157 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1158 printf ("DW_OP_bra: %ld", (long) svalue);
1161 printf ("DW_OP_eq");
1164 printf ("DW_OP_ge");
1167 printf ("DW_OP_gt");
1170 printf ("DW_OP_le");
1173 printf ("DW_OP_lt");
1176 printf ("DW_OP_ne");
1179 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1180 printf ("DW_OP_skip: %ld", (long) svalue);
1215 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1250 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1251 regname (op - DW_OP_reg0, 1));
1286 printf ("DW_OP_breg%d (%s): %s",
1288 regname (op - DW_OP_breg0, 1),
1289 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1294 uvalue = read_uleb128 (data, &bytes_read, end);
1296 printf ("DW_OP_regx: %s (%s)",
1297 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1300 need_frame_base = 1;
1301 printf ("DW_OP_fbreg: %s",
1302 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1306 uvalue = read_uleb128 (data, &bytes_read, end);
1308 printf ("DW_OP_bregx: %s (%s) %s",
1309 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1310 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1314 printf ("DW_OP_piece: %s",
1315 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1318 case DW_OP_deref_size:
1319 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1320 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1322 case DW_OP_xderef_size:
1323 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1324 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1327 printf ("DW_OP_nop");
1330 /* DWARF 3 extensions. */
1331 case DW_OP_push_object_address:
1332 printf ("DW_OP_push_object_address");
1335 /* XXX: Strictly speaking for 64-bit DWARF3 files
1336 this ought to be an 8-byte wide computation. */
1337 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1338 printf ("DW_OP_call2: <0x%s>",
1339 dwarf_vmatoa ("x", svalue + cu_offset));
1342 /* XXX: Strictly speaking for 64-bit DWARF3 files
1343 this ought to be an 8-byte wide computation. */
1344 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1345 printf ("DW_OP_call4: <0x%s>",
1346 dwarf_vmatoa ("x", svalue + cu_offset));
1348 case DW_OP_call_ref:
1349 /* XXX: Strictly speaking for 64-bit DWARF3 files
1350 this ought to be an 8-byte wide computation. */
1351 if (dwarf_version == -1)
1353 printf (_("(DW_OP_call_ref in frame info)"));
1354 /* No way to tell where the next op is, so just bail. */
1355 return need_frame_base;
1357 if (dwarf_version == 2)
1359 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1363 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1365 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1367 case DW_OP_form_tls_address:
1368 printf ("DW_OP_form_tls_address");
1370 case DW_OP_call_frame_cfa:
1371 printf ("DW_OP_call_frame_cfa");
1373 case DW_OP_bit_piece:
1374 printf ("DW_OP_bit_piece: ");
1375 printf (_("size: %s "),
1376 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1378 printf (_("offset: %s "),
1379 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1383 /* DWARF 4 extensions. */
1384 case DW_OP_stack_value:
1385 printf ("DW_OP_stack_value");
1388 case DW_OP_implicit_value:
1389 printf ("DW_OP_implicit_value");
1390 uvalue = read_uleb128 (data, &bytes_read, end);
1392 data = display_block (data, uvalue, end, ' ');
1395 /* GNU extensions. */
1396 case DW_OP_GNU_push_tls_address:
1397 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1399 case DW_OP_GNU_uninit:
1400 printf ("DW_OP_GNU_uninit");
1401 /* FIXME: Is there data associated with this OP ? */
1403 case DW_OP_GNU_encoded_addr:
1410 addr = get_encoded_value (&data, encoding, section, end);
1412 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1413 print_dwarf_vma (addr, pointer_size);
1416 case DW_OP_implicit_pointer:
1417 case DW_OP_GNU_implicit_pointer:
1418 /* XXX: Strictly speaking for 64-bit DWARF3 files
1419 this ought to be an 8-byte wide computation. */
1420 if (dwarf_version == -1)
1422 printf (_("(%s in frame info)"),
1423 (op == DW_OP_implicit_pointer
1424 ? "DW_OP_implicit_pointer"
1425 : "DW_OP_GNU_implicit_pointer"));
1426 /* No way to tell where the next op is, so just bail. */
1427 return need_frame_base;
1429 if (dwarf_version == 2)
1431 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1435 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1437 printf ("%s: <0x%s> %s",
1438 (op == DW_OP_implicit_pointer
1439 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1440 dwarf_vmatoa ("x", uvalue),
1441 dwarf_vmatoa ("d", read_sleb128 (data,
1442 &bytes_read, end)));
1445 case DW_OP_entry_value:
1446 case DW_OP_GNU_entry_value:
1447 uvalue = read_uleb128 (data, &bytes_read, end);
1449 /* PR 17531: file: 0cc9cd00. */
1450 if (uvalue > (dwarf_vma) (end - data))
1451 uvalue = end - data;
1452 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1453 : "DW_OP_GNU_entry_value"));
1454 if (decode_location_expression (data, pointer_size, offset_size,
1455 dwarf_version, uvalue,
1456 cu_offset, section))
1457 need_frame_base = 1;
1463 case DW_OP_const_type:
1464 case DW_OP_GNU_const_type:
1465 uvalue = read_uleb128 (data, &bytes_read, end);
1467 printf ("%s: <0x%s> ",
1468 (op == DW_OP_const_type ? "DW_OP_const_type"
1469 : "DW_OP_GNU_const_type"),
1470 dwarf_vmatoa ("x", cu_offset + uvalue));
1471 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1472 data = display_block (data, uvalue, end, ' ');
1474 case DW_OP_regval_type:
1475 case DW_OP_GNU_regval_type:
1476 uvalue = read_uleb128 (data, &bytes_read, end);
1478 printf ("%s: %s (%s)",
1479 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1480 : "DW_OP_GNU_regval_type"),
1481 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1482 uvalue = read_uleb128 (data, &bytes_read, end);
1484 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1486 case DW_OP_deref_type:
1487 case DW_OP_GNU_deref_type:
1488 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1490 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1491 : "DW_OP_GNU_deref_type"),
1493 uvalue = read_uleb128 (data, &bytes_read, end);
1495 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1498 case DW_OP_GNU_convert:
1499 uvalue = read_uleb128 (data, &bytes_read, end);
1501 printf ("%s <0x%s>",
1502 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1503 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1505 case DW_OP_reinterpret:
1506 case DW_OP_GNU_reinterpret:
1507 uvalue = read_uleb128 (data, &bytes_read, end);
1509 printf ("%s <0x%s>",
1510 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1511 : "DW_OP_GNU_reinterpret"),
1512 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1514 case DW_OP_GNU_parameter_ref:
1515 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1516 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1517 dwarf_vmatoa ("x", cu_offset + uvalue));
1519 case DW_OP_GNU_addr_index:
1520 uvalue = read_uleb128 (data, &bytes_read, end);
1522 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1524 case DW_OP_GNU_const_index:
1525 uvalue = read_uleb128 (data, &bytes_read, end);
1527 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1530 /* HP extensions. */
1531 case DW_OP_HP_is_value:
1532 printf ("DW_OP_HP_is_value");
1533 /* FIXME: Is there data associated with this OP ? */
1535 case DW_OP_HP_fltconst4:
1536 printf ("DW_OP_HP_fltconst4");
1537 /* FIXME: Is there data associated with this OP ? */
1539 case DW_OP_HP_fltconst8:
1540 printf ("DW_OP_HP_fltconst8");
1541 /* FIXME: Is there data associated with this OP ? */
1543 case DW_OP_HP_mod_range:
1544 printf ("DW_OP_HP_mod_range");
1545 /* FIXME: Is there data associated with this OP ? */
1547 case DW_OP_HP_unmod_range:
1548 printf ("DW_OP_HP_unmod_range");
1549 /* FIXME: Is there data associated with this OP ? */
1552 printf ("DW_OP_HP_tls");
1553 /* FIXME: Is there data associated with this OP ? */
1556 /* PGI (STMicroelectronics) extensions. */
1557 case DW_OP_PGI_omp_thread_num:
1558 /* Pushes the thread number for the current thread as it would be
1559 returned by the standard OpenMP library function:
1560 omp_get_thread_num(). The "current thread" is the thread for
1561 which the expression is being evaluated. */
1562 printf ("DW_OP_PGI_omp_thread_num");
1566 if (op >= DW_OP_lo_user
1567 && op <= DW_OP_hi_user)
1568 printf (_("(User defined location op 0x%x)"), op);
1570 printf (_("(Unknown location op 0x%x)"), op);
1571 /* No way to tell where the next op is, so just bail. */
1572 return need_frame_base;
1575 /* Separate the ops. */
1580 return need_frame_base;
1583 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1584 This is used for DWARF package files. */
1586 static struct cu_tu_set *
1587 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1589 struct cu_tu_set *p;
1591 unsigned int dw_sect;
1597 dw_sect = DW_SECT_TYPES;
1603 dw_sect = DW_SECT_INFO;
1607 if (p->section_offsets [dw_sect] == cu_offset)
1615 /* Add INC to HIGH_BITS:LOW_BITS. */
1617 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1619 dwarf_vma tmp = * low_bits;
1623 /* FIXME: There is probably a better way of handling this:
1625 We need to cope with dwarf_vma being a 32-bit or 64-bit
1626 type. Plus regardless of its size LOW_BITS is meant to
1627 only hold 32-bits, so if there is overflow or wrap around
1628 we must propagate into HIGH_BITS. */
1629 if (tmp < * low_bits)
1633 else if (sizeof (tmp) > 8
1643 static unsigned char *
1644 read_and_display_attr_value (unsigned long attribute,
1646 dwarf_signed_vma implicit_const,
1647 unsigned char * data,
1648 unsigned char * end,
1649 dwarf_vma cu_offset,
1650 dwarf_vma pointer_size,
1651 dwarf_vma offset_size,
1653 debug_info * debug_info_p,
1655 struct dwarf_section * section,
1656 struct cu_tu_set * this_set, char delimiter)
1658 dwarf_vma uvalue = 0;
1659 unsigned char *block_start = NULL;
1660 unsigned char * orig_data = data;
1661 unsigned int bytes_read;
1663 if (data > end || (data == end && form != DW_FORM_flag_present))
1665 warn (_("Corrupt attribute\n"));
1674 case DW_FORM_ref_addr:
1675 if (dwarf_version == 2)
1676 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1677 else if (dwarf_version == 3 || dwarf_version == 4)
1678 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1680 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1685 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1689 case DW_FORM_line_strp:
1690 case DW_FORM_sec_offset:
1691 case DW_FORM_GNU_ref_alt:
1692 case DW_FORM_GNU_strp_alt:
1693 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1696 case DW_FORM_flag_present:
1703 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1708 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1713 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1717 uvalue = read_sleb128 (data, & bytes_read, end);
1721 case DW_FORM_GNU_str_index:
1722 uvalue = read_uleb128 (data, & bytes_read, end);
1726 case DW_FORM_ref_udata:
1728 uvalue = read_uleb128 (data, & bytes_read, end);
1732 case DW_FORM_indirect:
1733 form = read_uleb128 (data, & bytes_read, end);
1736 printf ("%c%s", delimiter, get_FORM_name (form));
1737 if (form == DW_FORM_implicit_const)
1739 implicit_const = read_sleb128 (data, & bytes_read, end);
1742 return read_and_display_attr_value (attribute, form, implicit_const, data,
1743 end, cu_offset, pointer_size,
1744 offset_size, dwarf_version,
1745 debug_info_p, do_loc,
1746 section, this_set, delimiter);
1747 case DW_FORM_GNU_addr_index:
1748 uvalue = read_uleb128 (data, & bytes_read, end);
1755 case DW_FORM_ref_addr:
1757 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1760 case DW_FORM_GNU_ref_alt:
1762 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1768 case DW_FORM_ref_udata:
1770 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1775 case DW_FORM_sec_offset:
1777 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1780 case DW_FORM_flag_present:
1787 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1790 case DW_FORM_implicit_const:
1792 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1799 dwarf_vma high_bits;
1803 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1805 if (form == DW_FORM_ref8)
1806 add64 (& high_bits, & utmp, cu_offset);
1807 printf ("%c0x%s", delimiter,
1808 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1811 if ((do_loc || do_debug_loc || do_debug_ranges)
1812 && num_debug_info_entries == 0)
1814 if (sizeof (uvalue) == 8)
1815 SAFE_BYTE_GET (uvalue, data, 8, end);
1817 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1823 case DW_FORM_data16:
1826 dwarf_vma left_high_bits, left_low_bits;
1827 dwarf_vma right_high_bits, right_low_bits;
1829 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1830 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1831 if (byte_get == byte_get_little_endian)
1834 left_high_bits ^= right_high_bits;
1835 right_high_bits ^= left_high_bits;
1836 left_high_bits ^= right_high_bits;
1837 left_low_bits ^= right_low_bits;
1838 right_low_bits ^= left_low_bits;
1839 left_low_bits ^= right_low_bits;
1841 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1842 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1843 left_high_bits, left_low_bits, right_high_bits,
1849 case DW_FORM_string:
1851 printf ("%c%.*s", delimiter, (int) (end - data), data);
1852 data += strnlen ((char *) data, end - data) + 1;
1856 case DW_FORM_exprloc:
1857 uvalue = read_uleb128 (data, & bytes_read, end);
1858 block_start = data + bytes_read;
1859 if (block_start >= end)
1861 warn (_("Block ends prematurely\n"));
1865 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1866 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1867 block_start + uvalue here. */
1868 data = block_start + uvalue;
1869 /* PR 17512: file: 008-103549-0.001:0.1. */
1870 if (block_start + uvalue > end || data < block_start)
1872 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1873 uvalue = end - block_start;
1876 data = block_start + uvalue;
1878 data = display_block (block_start, uvalue, end, delimiter);
1881 case DW_FORM_block1:
1882 SAFE_BYTE_GET (uvalue, data, 1, end);
1883 block_start = data + 1;
1884 if (block_start >= end)
1886 warn (_("Block ends prematurely\n"));
1890 data = block_start + uvalue;
1891 if (block_start + uvalue > end || data < block_start)
1893 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1894 uvalue = end - block_start;
1897 data = block_start + uvalue;
1899 data = display_block (block_start, uvalue, end, delimiter);
1902 case DW_FORM_block2:
1903 SAFE_BYTE_GET (uvalue, data, 2, end);
1904 block_start = data + 2;
1905 if (block_start >= end)
1907 warn (_("Block ends prematurely\n"));
1911 data = block_start + uvalue;
1912 if (block_start + uvalue > end || data < block_start)
1914 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1915 uvalue = end - block_start;
1918 data = block_start + uvalue;
1920 data = display_block (block_start, uvalue, end, delimiter);
1923 case DW_FORM_block4:
1924 SAFE_BYTE_GET (uvalue, data, 4, end);
1925 block_start = data + 4;
1926 /* PR 17512: file: 3371-3907-0.004. */
1927 if (block_start >= end)
1929 warn (_("Block ends prematurely\n"));
1933 data = block_start + uvalue;
1934 if (block_start + uvalue > end
1935 /* PR 17531: file: 5b5f0592. */
1936 || data < block_start)
1938 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1939 uvalue = end - block_start;
1942 data = block_start + uvalue;
1944 data = display_block (block_start, uvalue, end, delimiter);
1949 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1950 dwarf_vmatoa ("x", uvalue),
1951 fetch_indirect_string (uvalue));
1954 case DW_FORM_line_strp:
1956 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1957 dwarf_vmatoa ("x", uvalue),
1958 fetch_indirect_line_string (uvalue));
1961 case DW_FORM_GNU_str_index:
1964 const char *suffix = strrchr (section->name, '.');
1965 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1967 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1968 dwarf_vmatoa ("x", uvalue),
1969 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1973 case DW_FORM_GNU_strp_alt:
1975 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1976 dwarf_vmatoa ("x", uvalue));
1979 case DW_FORM_indirect:
1980 /* Handled above. */
1983 case DW_FORM_ref_sig8:
1986 dwarf_vma high_bits;
1989 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1990 printf ("%csignature: 0x%s", delimiter,
1991 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1996 case DW_FORM_GNU_addr_index:
1998 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
1999 dwarf_vmatoa ("x", uvalue),
2000 fetch_indexed_value (uvalue * pointer_size, pointer_size));
2004 warn (_("Unrecognized form: %lu\n"), form);
2008 if ((do_loc || do_debug_loc || do_debug_ranges)
2009 && num_debug_info_entries == 0
2010 && debug_info_p != NULL)
2014 case DW_AT_frame_base:
2015 have_frame_base = 1;
2017 case DW_AT_location:
2018 case DW_AT_string_length:
2019 case DW_AT_return_addr:
2020 case DW_AT_data_member_location:
2021 case DW_AT_vtable_elem_location:
2023 case DW_AT_static_link:
2024 case DW_AT_use_location:
2025 case DW_AT_call_value:
2026 case DW_AT_GNU_call_site_value:
2027 case DW_AT_call_data_value:
2028 case DW_AT_GNU_call_site_data_value:
2029 case DW_AT_call_target:
2030 case DW_AT_GNU_call_site_target:
2031 case DW_AT_call_target_clobbered:
2032 case DW_AT_GNU_call_site_target_clobbered:
2033 if ((dwarf_version < 4
2034 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2035 || form == DW_FORM_sec_offset)
2037 /* Process location list. */
2038 unsigned int lmax = debug_info_p->max_loc_offsets;
2039 unsigned int num = debug_info_p->num_loc_offsets;
2041 if (lmax == 0 || num >= lmax)
2044 debug_info_p->loc_offsets = (dwarf_vma *)
2045 xcrealloc (debug_info_p->loc_offsets,
2046 lmax, sizeof (*debug_info_p->loc_offsets));
2047 debug_info_p->have_frame_base = (int *)
2048 xcrealloc (debug_info_p->have_frame_base,
2049 lmax, sizeof (*debug_info_p->have_frame_base));
2050 debug_info_p->max_loc_offsets = lmax;
2052 if (this_set != NULL)
2053 uvalue += this_set->section_offsets [DW_SECT_LOC];
2054 debug_info_p->loc_offsets [num] = uvalue;
2055 debug_info_p->have_frame_base [num] = have_frame_base;
2056 debug_info_p->num_loc_offsets++;
2061 if (need_base_address)
2062 debug_info_p->base_address = uvalue;
2065 case DW_AT_GNU_addr_base:
2066 debug_info_p->addr_base = uvalue;
2069 case DW_AT_GNU_ranges_base:
2070 debug_info_p->ranges_base = uvalue;
2074 if ((dwarf_version < 4
2075 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2076 || form == DW_FORM_sec_offset)
2078 /* Process range list. */
2079 unsigned int lmax = debug_info_p->max_range_lists;
2080 unsigned int num = debug_info_p->num_range_lists;
2082 if (lmax == 0 || num >= lmax)
2085 debug_info_p->range_lists = (dwarf_vma *)
2086 xcrealloc (debug_info_p->range_lists,
2087 lmax, sizeof (*debug_info_p->range_lists));
2088 debug_info_p->max_range_lists = lmax;
2090 debug_info_p->range_lists [num] = uvalue;
2091 debug_info_p->num_range_lists++;
2100 if (do_loc || attribute == 0)
2103 /* For some attributes we can display further information. */
2110 case DW_INL_not_inlined:
2111 printf (_("(not inlined)"));
2113 case DW_INL_inlined:
2114 printf (_("(inlined)"));
2116 case DW_INL_declared_not_inlined:
2117 printf (_("(declared as inline but ignored)"));
2119 case DW_INL_declared_inlined:
2120 printf (_("(declared as inline and inlined)"));
2123 printf (_(" (Unknown inline attribute value: %s)"),
2124 dwarf_vmatoa ("x", uvalue));
2129 case DW_AT_language:
2133 /* Ordered by the numeric value of these constants. */
2134 case DW_LANG_C89: printf ("(ANSI C)"); break;
2135 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2136 case DW_LANG_Ada83: printf ("(Ada)"); break;
2137 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2138 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2139 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2140 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2141 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2142 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2143 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2144 /* DWARF 2.1 values. */
2145 case DW_LANG_Java: printf ("(Java)"); break;
2146 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2147 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2148 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2149 /* DWARF 3 values. */
2150 case DW_LANG_PLI: printf ("(PLI)"); break;
2151 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2152 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2153 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2154 case DW_LANG_D: printf ("(D)"); break;
2155 /* DWARF 4 values. */
2156 case DW_LANG_Python: printf ("(Python)"); break;
2157 /* DWARF 5 values. */
2158 case DW_LANG_Go: printf ("(Go)"); break;
2159 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2160 case DW_LANG_C11: printf ("(C11)"); break;
2161 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2162 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2163 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2164 /* MIPS extension. */
2165 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2166 /* UPC extension. */
2167 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2169 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2170 printf (_("(implementation defined: %s)"),
2171 dwarf_vmatoa ("x", uvalue));
2173 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2178 case DW_AT_encoding:
2182 case DW_ATE_void: printf ("(void)"); break;
2183 case DW_ATE_address: printf ("(machine address)"); break;
2184 case DW_ATE_boolean: printf ("(boolean)"); break;
2185 case DW_ATE_complex_float: printf ("(complex float)"); break;
2186 case DW_ATE_float: printf ("(float)"); break;
2187 case DW_ATE_signed: printf ("(signed)"); break;
2188 case DW_ATE_signed_char: printf ("(signed char)"); break;
2189 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2190 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2191 /* DWARF 2.1 values: */
2192 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2193 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2194 /* DWARF 3 values: */
2195 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2196 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2197 case DW_ATE_edited: printf ("(edited)"); break;
2198 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2199 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2200 /* HP extensions: */
2201 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2202 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2203 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2204 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2205 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2206 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2207 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2208 /* DWARF 4 values: */
2209 case DW_ATE_UTF: printf ("(unicode string)"); break;
2212 if (uvalue >= DW_ATE_lo_user
2213 && uvalue <= DW_ATE_hi_user)
2214 printf (_("(user defined type)"));
2216 printf (_("(unknown type)"));
2221 case DW_AT_accessibility:
2225 case DW_ACCESS_public: printf ("(public)"); break;
2226 case DW_ACCESS_protected: printf ("(protected)"); break;
2227 case DW_ACCESS_private: printf ("(private)"); break;
2229 printf (_("(unknown accessibility)"));
2234 case DW_AT_visibility:
2238 case DW_VIS_local: printf ("(local)"); break;
2239 case DW_VIS_exported: printf ("(exported)"); break;
2240 case DW_VIS_qualified: printf ("(qualified)"); break;
2241 default: printf (_("(unknown visibility)")); break;
2245 case DW_AT_virtuality:
2249 case DW_VIRTUALITY_none: printf ("(none)"); break;
2250 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2251 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2252 default: printf (_("(unknown virtuality)")); break;
2256 case DW_AT_identifier_case:
2260 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2261 case DW_ID_up_case: printf ("(up_case)"); break;
2262 case DW_ID_down_case: printf ("(down_case)"); break;
2263 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2264 default: printf (_("(unknown case)")); break;
2268 case DW_AT_calling_convention:
2272 case DW_CC_normal: printf ("(normal)"); break;
2273 case DW_CC_program: printf ("(program)"); break;
2274 case DW_CC_nocall: printf ("(nocall)"); break;
2276 if (uvalue >= DW_CC_lo_user
2277 && uvalue <= DW_CC_hi_user)
2278 printf (_("(user defined)"));
2280 printf (_("(unknown convention)"));
2284 case DW_AT_ordering:
2288 case -1: printf (_("(undefined)")); break;
2289 case 0: printf ("(row major)"); break;
2290 case 1: printf ("(column major)"); break;
2294 case DW_AT_frame_base:
2295 have_frame_base = 1;
2297 case DW_AT_location:
2298 case DW_AT_string_length:
2299 case DW_AT_return_addr:
2300 case DW_AT_data_member_location:
2301 case DW_AT_vtable_elem_location:
2303 case DW_AT_static_link:
2304 case DW_AT_use_location:
2305 case DW_AT_call_value:
2306 case DW_AT_GNU_call_site_value:
2307 case DW_AT_call_data_value:
2308 case DW_AT_GNU_call_site_data_value:
2309 case DW_AT_call_target:
2310 case DW_AT_GNU_call_site_target:
2311 case DW_AT_call_target_clobbered:
2312 case DW_AT_GNU_call_site_target_clobbered:
2313 if ((dwarf_version < 4
2314 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2315 || form == DW_FORM_sec_offset)
2316 printf (_(" (location list)"));
2318 case DW_AT_allocated:
2319 case DW_AT_associated:
2320 case DW_AT_data_location:
2322 case DW_AT_upper_bound:
2323 case DW_AT_lower_bound:
2326 int need_frame_base;
2329 need_frame_base = decode_location_expression (block_start,
2334 cu_offset, section);
2336 if (need_frame_base && !have_frame_base)
2337 printf (_(" [without DW_AT_frame_base]"));
2343 if (form == DW_FORM_ref_sig8
2344 || form == DW_FORM_GNU_ref_alt)
2347 if (form == DW_FORM_ref1
2348 || form == DW_FORM_ref2
2349 || form == DW_FORM_ref4
2350 || form == DW_FORM_ref_udata)
2351 uvalue += cu_offset;
2353 if (uvalue >= section->size)
2354 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2355 dwarf_vmatoa ("x", uvalue),
2356 (unsigned long) (orig_data - section->start));
2359 unsigned long abbrev_number;
2360 abbrev_entry * entry;
2362 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2364 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2365 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2366 use different abbrev table, and we don't track .debug_info chunks
2368 if (form != DW_FORM_ref_addr)
2370 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2371 if (entry->entry == abbrev_number)
2374 printf (" (%s)", get_TAG_name (entry->tag));
2389 get_AT_name (unsigned long attribute)
2394 return "DW_AT value: 0";
2396 /* One value is shared by the MIPS and HP extensions: */
2397 if (attribute == DW_AT_MIPS_fde)
2398 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2400 name = get_DW_AT_name (attribute);
2404 static char buffer[100];
2406 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2414 static unsigned char *
2415 read_and_display_attr (unsigned long attribute,
2417 dwarf_signed_vma implicit_const,
2418 unsigned char * data,
2419 unsigned char * end,
2420 dwarf_vma cu_offset,
2421 dwarf_vma pointer_size,
2422 dwarf_vma offset_size,
2424 debug_info * debug_info_p,
2426 struct dwarf_section * section,
2427 struct cu_tu_set * this_set)
2430 printf (" %-18s:", get_AT_name (attribute));
2431 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2432 cu_offset, pointer_size, offset_size,
2433 dwarf_version, debug_info_p,
2434 do_loc, section, this_set, ' ');
2440 /* Process the contents of a .debug_info section. If do_loc is non-zero
2441 then we are scanning for location lists and we do not want to display
2442 anything to the user. If do_types is non-zero, we are processing
2443 a .debug_types section instead of a .debug_info section. */
2446 process_debug_info (struct dwarf_section *section,
2448 enum dwarf_section_display_enum abbrev_sec,
2452 unsigned char *start = section->start;
2453 unsigned char *end = start + section->size;
2454 unsigned char *section_begin;
2456 unsigned int num_units = 0;
2458 if ((do_loc || do_debug_loc || do_debug_ranges)
2459 && num_debug_info_entries == 0
2464 /* First scan the section to get the number of comp units. */
2465 for (section_begin = start, num_units = 0; section_begin < end;
2468 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2469 will be the length. For a 64-bit DWARF section, it'll be
2470 the escape code 0xffffffff followed by an 8 byte length. */
2471 SAFE_BYTE_GET (length, section_begin, 4, end);
2473 if (length == 0xffffffff)
2475 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2476 section_begin += length + 12;
2478 else if (length >= 0xfffffff0 && length < 0xffffffff)
2480 warn (_("Reserved length value (0x%s) found in section %s\n"),
2481 dwarf_vmatoa ("x", length), section->name);
2485 section_begin += length + 4;
2487 /* Negative values are illegal, they may even cause infinite
2488 looping. This can happen if we can't accurately apply
2489 relocations to an object file, or if the file is corrupt. */
2490 if ((signed long) length <= 0 || section_begin < start)
2492 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2493 dwarf_vmatoa ("x", length), section->name);
2500 error (_("No comp units in %s section ?\n"), section->name);
2504 /* Then allocate an array to hold the information. */
2505 debug_information = (debug_info *) cmalloc (num_units,
2506 sizeof (* debug_information));
2507 if (debug_information == NULL)
2509 error (_("Not enough memory for a debug info array of %u entries\n"),
2511 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2514 /* PR 17531: file: 92ca3797.
2515 We cannot rely upon the debug_information array being initialised
2516 before it is used. A corrupt file could easily contain references
2517 to a unit for which information has not been made available. So
2518 we ensure that the array is zeroed here. */
2519 memset (debug_information, 0, num_units * sizeof (*debug_information));
2521 alloc_num_debug_info_entries = num_units;
2526 if (dwarf_start_die == 0)
2527 printf (_("Contents of the %s section:\n\n"), section->name);
2529 load_debug_section (str, file);
2530 load_debug_section (line_str, file);
2531 load_debug_section (str_dwo, file);
2532 load_debug_section (str_index, file);
2533 load_debug_section (str_index_dwo, file);
2534 load_debug_section (debug_addr, file);
2537 load_debug_section (abbrev_sec, file);
2538 if (debug_displays [abbrev_sec].section.start == NULL)
2540 warn (_("Unable to locate %s section!\n"),
2541 debug_displays [abbrev_sec].section.name);
2545 for (section_begin = start, unit = 0; start < end; unit++)
2547 DWARF2_Internal_CompUnit compunit;
2548 unsigned char *hdrptr;
2549 unsigned char *tags;
2550 int level, last_level, saved_level;
2551 dwarf_vma cu_offset;
2552 unsigned int offset_size;
2553 int initial_length_size;
2554 dwarf_vma signature_high = 0;
2555 dwarf_vma signature_low = 0;
2556 dwarf_vma type_offset = 0;
2557 struct cu_tu_set *this_set;
2558 dwarf_vma abbrev_base;
2563 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2565 if (compunit.cu_length == 0xffffffff)
2567 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2569 initial_length_size = 12;
2574 initial_length_size = 4;
2577 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2579 cu_offset = start - section_begin;
2581 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2583 if (compunit.cu_version < 5)
2585 compunit.cu_unit_type = DW_UT_compile;
2586 /* Initialize it due to a false compiler warning. */
2587 compunit.cu_pointer_size = -1;
2591 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2592 do_types = (compunit.cu_unit_type == DW_UT_type);
2594 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2597 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2599 if (this_set == NULL)
2602 abbrev_size = debug_displays [abbrev_sec].section.size;
2606 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2607 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2610 if (compunit.cu_version < 5)
2611 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2613 /* PR 17512: file: 001-108546-0.001:0.1. */
2614 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2616 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2617 compunit.cu_pointer_size, offset_size);
2618 compunit.cu_pointer_size = offset_size;
2623 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2625 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2628 if ((do_loc || do_debug_loc || do_debug_ranges)
2629 && num_debug_info_entries == 0
2632 debug_information [unit].cu_offset = cu_offset;
2633 debug_information [unit].pointer_size
2634 = compunit.cu_pointer_size;
2635 debug_information [unit].offset_size = offset_size;
2636 debug_information [unit].dwarf_version = compunit.cu_version;
2637 debug_information [unit].base_address = 0;
2638 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2639 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2640 debug_information [unit].loc_offsets = NULL;
2641 debug_information [unit].have_frame_base = NULL;
2642 debug_information [unit].max_loc_offsets = 0;
2643 debug_information [unit].num_loc_offsets = 0;
2644 debug_information [unit].range_lists = NULL;
2645 debug_information [unit].max_range_lists= 0;
2646 debug_information [unit].num_range_lists = 0;
2649 if (!do_loc && dwarf_start_die == 0)
2651 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2652 dwarf_vmatoa ("x", cu_offset));
2653 printf (_(" Length: 0x%s (%s)\n"),
2654 dwarf_vmatoa ("x", compunit.cu_length),
2655 offset_size == 8 ? "64-bit" : "32-bit");
2656 printf (_(" Version: %d\n"), compunit.cu_version);
2657 printf (_(" Abbrev Offset: 0x%s\n"),
2658 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2659 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2664 printf (_(" Signature: 0x%s\n"),
2665 dwarf_vmatoa64 (signature_high, signature_low,
2666 buf, sizeof (buf)));
2667 printf (_(" Type Offset: 0x%s\n"),
2668 dwarf_vmatoa ("x", type_offset));
2670 if (this_set != NULL)
2672 dwarf_vma *offsets = this_set->section_offsets;
2673 size_t *sizes = this_set->section_sizes;
2675 printf (_(" Section contributions:\n"));
2676 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2677 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2678 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2679 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2680 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2681 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2682 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2683 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2684 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2685 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2686 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2687 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2691 if (cu_offset + compunit.cu_length + initial_length_size
2694 warn (_("Debug info is corrupted, length of CU at %s"
2695 " extends beyond end of section (length = %s)\n"),
2696 dwarf_vmatoa ("x", cu_offset),
2697 dwarf_vmatoa ("x", compunit.cu_length));
2702 start += compunit.cu_length + initial_length_size;
2706 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2707 dwarf_vmatoa ("x", cu_offset));
2711 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2713 warn (_("CU at offset %s contains corrupt or "
2714 "unsupported version number: %d.\n"),
2715 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2719 if (compunit.cu_unit_type != DW_UT_compile
2720 && compunit.cu_unit_type != DW_UT_type)
2722 warn (_("CU at offset %s contains corrupt or "
2723 "unsupported unit type: %d.\n"),
2724 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2730 /* Process the abbrevs used by this compilation unit. */
2731 if (compunit.cu_abbrev_offset >= abbrev_size)
2732 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2733 (unsigned long) compunit.cu_abbrev_offset,
2734 (unsigned long) abbrev_size);
2735 /* PR 17531: file:4bcd9ce9. */
2736 else if ((abbrev_base + abbrev_size)
2737 > debug_displays [abbrev_sec].section.size)
2738 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2739 (unsigned long) abbrev_base + abbrev_size,
2740 (unsigned long) debug_displays [abbrev_sec].section.size);
2742 process_abbrev_section
2743 (((unsigned char *) debug_displays [abbrev_sec].section.start
2744 + abbrev_base + compunit.cu_abbrev_offset),
2745 ((unsigned char *) debug_displays [abbrev_sec].section.start
2746 + abbrev_base + abbrev_size));
2751 while (tags < start)
2753 unsigned int bytes_read;
2754 unsigned long abbrev_number;
2755 unsigned long die_offset;
2756 abbrev_entry *entry;
2758 int do_printing = 1;
2760 die_offset = tags - section_begin;
2762 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2765 /* A null DIE marks the end of a list of siblings or it may also be
2766 a section padding. */
2767 if (abbrev_number == 0)
2769 /* Check if it can be a section padding for the last CU. */
2770 if (level == 0 && start == end)
2774 for (chk = tags; chk < start; chk++)
2781 if (!do_loc && die_offset >= dwarf_start_die
2782 && (dwarf_cutoff_level == -1
2783 || level < dwarf_cutoff_level))
2784 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2790 static unsigned num_bogus_warns = 0;
2792 if (num_bogus_warns < 3)
2794 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2795 die_offset, section->name);
2797 if (num_bogus_warns == 3)
2798 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2801 if (dwarf_start_die != 0 && level < saved_level)
2808 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2812 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2813 saved_level = level;
2814 do_printing = (dwarf_cutoff_level == -1
2815 || level < dwarf_cutoff_level);
2817 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2818 level, die_offset, abbrev_number);
2819 else if (dwarf_cutoff_level == -1
2820 || last_level < dwarf_cutoff_level)
2821 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2826 /* Scan through the abbreviation list until we reach the
2828 for (entry = first_abbrev;
2829 entry && entry->entry != abbrev_number;
2830 entry = entry->next)
2835 if (!do_loc && do_printing)
2840 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2841 die_offset, abbrev_number);
2845 if (!do_loc && do_printing)
2846 printf (" (%s)\n", get_TAG_name (entry->tag));
2851 need_base_address = 0;
2853 case DW_TAG_compile_unit:
2854 need_base_address = 1;
2856 case DW_TAG_entry_point:
2857 case DW_TAG_subprogram:
2858 need_base_address = 0;
2859 /* Assuming that there is no DW_AT_frame_base. */
2860 have_frame_base = 0;
2864 for (attr = entry->first_attr;
2865 attr && attr->attribute;
2870 if (! do_loc && do_printing)
2871 /* Show the offset from where the tag was extracted. */
2872 printf (" <%lx>", (unsigned long)(tags - section_begin));
2874 if (debug_information && unit < alloc_num_debug_info_entries)
2875 arg = debug_information + unit;
2879 tags = read_and_display_attr (attr->attribute,
2881 attr->implicit_const,
2885 compunit.cu_pointer_size,
2887 compunit.cu_version,
2889 do_loc || ! do_printing,
2894 if (entry->children)
2899 /* Set num_debug_info_entries here so that it can be used to check if
2900 we need to process .debug_loc and .debug_ranges sections. */
2901 if ((do_loc || do_debug_loc || do_debug_ranges)
2902 && num_debug_info_entries == 0
2905 if (num_units > alloc_num_debug_info_entries)
2906 num_debug_info_entries = alloc_num_debug_info_entries;
2908 num_debug_info_entries = num_units;
2917 /* Locate and scan the .debug_info section in the file and record the pointer
2918 sizes and offsets for the compilation units in it. Usually an executable
2919 will have just one pointer size, but this is not guaranteed, and so we try
2920 not to make any assumptions. Returns zero upon failure, or the number of
2921 compilation units upon success. */
2924 load_debug_info (void * file)
2926 /* Reset the last pointer size so that we can issue correct error
2927 messages if we are displaying the contents of more than one section. */
2928 last_pointer_size = 0;
2929 warned_about_missing_comp_units = FALSE;
2931 /* If we have already tried and failed to load the .debug_info
2932 section then do not bother to repeat the task. */
2933 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2936 /* If we already have the information there is nothing else to do. */
2937 if (num_debug_info_entries > 0)
2938 return num_debug_info_entries;
2940 /* If this is a DWARF package file, load the CU and TU indexes. */
2941 (void) load_cu_tu_indexes (file);
2943 if (load_debug_section (info, file)
2944 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2945 return num_debug_info_entries;
2947 if (load_debug_section (info_dwo, file)
2948 && process_debug_info (&debug_displays [info_dwo].section, file,
2950 return num_debug_info_entries;
2952 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2956 /* Read a DWARF .debug_line section header starting at DATA.
2957 Upon success returns an updated DATA pointer and the LINFO
2958 structure and the END_OF_SEQUENCE pointer will be filled in.
2959 Otherwise returns NULL. */
2961 static unsigned char *
2962 read_debug_line_header (struct dwarf_section * section,
2963 unsigned char * data,
2964 unsigned char * end,
2965 DWARF2_Internal_LineInfo * linfo,
2966 unsigned char ** end_of_sequence)
2968 unsigned char *hdrptr;
2969 unsigned int initial_length_size;
2970 unsigned char address_size, segment_selector_size;
2972 /* Extract information from the Line Number Program Header.
2973 (section 6.2.4 in the Dwarf3 doc). */
2976 /* Get and check the length of the block. */
2977 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2979 if (linfo->li_length == 0xffffffff)
2981 /* This section is 64-bit DWARF 3. */
2982 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2983 linfo->li_offset_size = 8;
2984 initial_length_size = 12;
2988 linfo->li_offset_size = 4;
2989 initial_length_size = 4;
2992 if (linfo->li_length + initial_length_size > section->size)
2994 /* If the length field has a relocation against it, then we should
2995 not complain if it is inaccurate (and probably negative). This
2996 happens in object files when the .debug_line section is actually
2997 comprised of several different .debug_line.* sections, (some of
2998 which may be removed by linker garbage collection), and a relocation
2999 is used to compute the correct length once that is done. */
3000 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
3002 linfo->li_length = (end - data) - initial_length_size;
3006 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3007 (long) linfo->li_length);
3012 /* Get and check the version number. */
3013 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3015 if (linfo->li_version != 2
3016 && linfo->li_version != 3
3017 && linfo->li_version != 4
3018 && linfo->li_version != 5)
3020 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3021 "is currently supported.\n"));
3025 if (linfo->li_version >= 5)
3027 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3029 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3030 if (segment_selector_size != 0)
3032 warn (_("The %s section contains "
3033 "unsupported segment selector size: %d.\n"),
3034 section->name, segment_selector_size);
3039 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3040 linfo->li_offset_size, end);
3041 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3043 if (linfo->li_version >= 4)
3045 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3047 if (linfo->li_max_ops_per_insn == 0)
3049 warn (_("Invalid maximum operations per insn.\n"));
3054 linfo->li_max_ops_per_insn = 1;
3056 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3057 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3058 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3059 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3061 * end_of_sequence = data + linfo->li_length + initial_length_size;
3062 /* PR 17512: file:002-117414-0.004. */
3063 if (* end_of_sequence > end)
3065 warn (_("Line length %s extends beyond end of section\n"),
3066 dwarf_vmatoa ("u", linfo->li_length));
3067 * end_of_sequence = end;
3074 static unsigned char *
3075 display_formatted_table (unsigned char *data,
3076 unsigned char *start, unsigned char *end,
3077 const DWARF2_Internal_LineInfo *linfo,
3078 struct dwarf_section *section, const char *what)
3080 unsigned char *format_start, format_count, *format, formati;
3081 dwarf_vma data_count, datai;
3082 unsigned int bytes_read, namepass, last_entry = 0;
3084 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3085 format_start = data;
3086 for (formati = 0; formati < format_count; formati++)
3088 read_uleb128 (data, & bytes_read, end);
3090 read_uleb128 (data, & bytes_read, end);
3094 warn (_("Corrupt %s format table entry\n"), what);
3099 data_count = read_uleb128 (data, & bytes_read, end);
3103 warn (_("Corrupt %s list\n"), what);
3107 if (data_count == 0)
3109 printf (_("\n The %s Table is empty.\n"), what);
3113 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3114 (long)(data - start));
3116 printf (_(" Entry"));
3117 /* Delay displaying name as the last entry for better screen layout. */
3118 for (namepass = 0; namepass < 2; namepass++)
3120 format = format_start;
3121 for (formati = 0; formati < format_count; formati++)
3123 dwarf_vma content_type;
3125 content_type = read_uleb128 (format, & bytes_read, end);
3126 format += bytes_read;
3127 if ((content_type == DW_LNCT_path) == (namepass == 1))
3128 switch (content_type)
3131 printf (_("\tName"));
3133 case DW_LNCT_directory_index:
3134 printf (_("\tDir"));
3136 case DW_LNCT_timestamp:
3137 printf (_("\tTime"));
3140 printf (_("\tSize"));
3143 printf (_("\tMD5"));
3146 printf (_("\t(Unknown format content type %s)"),
3147 dwarf_vmatoa ("u", content_type));
3149 read_uleb128 (format, & bytes_read, end);
3150 format += bytes_read;
3155 for (datai = 0; datai < data_count; datai++)
3157 unsigned char *datapass = data;
3159 printf (" %d", last_entry++);
3160 /* Delay displaying name as the last entry for better screen layout. */
3161 for (namepass = 0; namepass < 2; namepass++)
3163 format = format_start;
3165 for (formati = 0; formati < format_count; formati++)
3167 dwarf_vma content_type, form;
3169 content_type = read_uleb128 (format, & bytes_read, end);
3170 format += bytes_read;
3171 form = read_uleb128 (format, & bytes_read, end);
3172 format += bytes_read;
3173 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3174 linfo->li_offset_size,
3175 linfo->li_version, NULL,
3176 ((content_type == DW_LNCT_path) != (namepass == 1)),
3177 section, NULL, '\t');
3182 warn (_("Corrupt %s entries list\n"), what);
3191 display_debug_lines_raw (struct dwarf_section *section,
3192 unsigned char *data,
3193 unsigned char *end, void *file)
3195 unsigned char *start = section->start;
3196 int verbose_view = 0;
3198 printf (_("Raw dump of debug contents of section %s:\n\n"),
3203 static DWARF2_Internal_LineInfo saved_linfo;
3204 DWARF2_Internal_LineInfo linfo;
3205 unsigned char *standard_opcodes;
3206 unsigned char *end_of_sequence;
3209 if (const_strneq (section->name, ".debug_line.")
3210 /* Note: the following does not apply to .debug_line.dwo sections.
3211 These are full debug_line sections. */
3212 && strcmp (section->name, ".debug_line.dwo") != 0)
3214 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3215 section containing just the Line Number Statements. They are
3216 created by the assembler and intended to be used alongside gcc's
3217 -ffunction-sections command line option. When the linker's
3218 garbage collection decides to discard a .text.<foo> section it
3219 can then also discard the line number information in .debug_line.<foo>.
3221 Since the section is a fragment it does not have the details
3222 needed to fill out a LineInfo structure, so instead we use the
3223 details from the last full debug_line section that we processed. */
3224 end_of_sequence = end;
3225 standard_opcodes = NULL;
3226 linfo = saved_linfo;
3227 /* PR 17531: file: 0522b371. */
3228 if (linfo.li_line_range == 0)
3230 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3233 reset_state_machine (linfo.li_default_is_stmt);
3237 unsigned char * hdrptr;
3239 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3240 & end_of_sequence)) == NULL)
3243 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3244 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3245 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3246 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3247 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3248 if (linfo.li_version >= 4)
3249 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3250 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3251 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3252 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3253 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3255 /* PR 17512: file: 1665-6428-0.004. */
3256 if (linfo.li_line_range == 0)
3258 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3259 linfo.li_line_range = 1;
3262 reset_state_machine (linfo.li_default_is_stmt);
3264 /* Display the contents of the Opcodes table. */
3265 standard_opcodes = hdrptr;
3267 /* PR 17512: file: 002-417945-0.004. */
3268 if (standard_opcodes + linfo.li_opcode_base >= end)
3270 warn (_("Line Base extends beyond end of section\n"));
3274 printf (_("\n Opcodes:\n"));
3276 for (i = 1; i < linfo.li_opcode_base; i++)
3277 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3279 /* Display the contents of the Directory table. */
3280 data = standard_opcodes + linfo.li_opcode_base - 1;
3282 if (linfo.li_version >= 5)
3284 load_debug_section (line_str, file);
3286 data = display_formatted_table (data, start, end, &linfo, section,
3288 data = display_formatted_table (data, start, end, &linfo, section,
3294 printf (_("\n The Directory Table is empty.\n"));
3297 unsigned int last_dir_entry = 0;
3299 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3300 (long)(data - start));
3302 while (data < end && *data != 0)
3304 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3306 data += strnlen ((char *) data, end - data) + 1;
3309 /* PR 17512: file: 002-132094-0.004. */
3310 if (data >= end - 1)
3314 /* Skip the NUL at the end of the table. */
3317 /* Display the contents of the File Name table. */
3319 printf (_("\n The File Name Table is empty.\n"));
3322 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3323 (long)(data - start));
3324 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3326 while (data < end && *data != 0)
3328 unsigned char *name;
3329 unsigned int bytes_read;
3331 printf (" %d\t", ++state_machine_regs.last_file_entry);
3333 data += strnlen ((char *) data, end - data) + 1;
3336 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3339 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3342 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3344 printf ("%.*s\n", (int)(end - name), name);
3348 warn (_("Corrupt file name table entry\n"));
3354 /* Skip the NUL at the end of the table. */
3359 saved_linfo = linfo;
3362 /* Now display the statements. */
3363 if (data >= end_of_sequence)
3364 printf (_(" No Line Number Statements.\n"));
3367 printf (_(" Line Number Statements:\n"));
3369 while (data < end_of_sequence)
3371 unsigned char op_code;
3372 dwarf_signed_vma adv;
3374 unsigned int bytes_read;
3376 printf (" [0x%08lx]", (long)(data - start));
3380 if (op_code >= linfo.li_opcode_base)
3382 op_code -= linfo.li_opcode_base;
3383 uladv = (op_code / linfo.li_line_range);
3384 if (linfo.li_max_ops_per_insn == 1)
3386 uladv *= linfo.li_min_insn_length;
3387 state_machine_regs.address += uladv;
3389 state_machine_regs.view = 0;
3390 printf (_(" Special opcode %d: "
3391 "advance Address by %s to 0x%s%s"),
3392 op_code, dwarf_vmatoa ("u", uladv),
3393 dwarf_vmatoa ("x", state_machine_regs.address),
3394 verbose_view && uladv
3395 ? _(" (reset view)") : "");
3400 = ((state_machine_regs.op_index + uladv)
3401 / linfo.li_max_ops_per_insn)
3402 * linfo.li_min_insn_length;
3404 state_machine_regs.address += addrdelta;
3405 state_machine_regs.op_index
3406 = (state_machine_regs.op_index + uladv)
3407 % linfo.li_max_ops_per_insn;
3409 state_machine_regs.view = 0;
3410 printf (_(" Special opcode %d: "
3411 "advance Address by %s to 0x%s[%d]%s"),
3412 op_code, dwarf_vmatoa ("u", uladv),
3413 dwarf_vmatoa ("x", state_machine_regs.address),
3414 state_machine_regs.op_index,
3415 verbose_view && addrdelta
3416 ? _(" (reset view)") : "");
3418 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3419 state_machine_regs.line += adv;
3420 printf (_(" and Line by %s to %d"),
3421 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3422 if (verbose_view || state_machine_regs.view)
3423 printf (_(" (view %u)\n"), state_machine_regs.view);
3426 state_machine_regs.view++;
3428 else switch (op_code)
3430 case DW_LNS_extended_op:
3431 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3435 printf (_(" Copy"));
3436 if (verbose_view || state_machine_regs.view)
3437 printf (_(" (view %u)\n"), state_machine_regs.view);
3440 state_machine_regs.view++;
3443 case DW_LNS_advance_pc:
3444 uladv = read_uleb128 (data, & bytes_read, end);
3446 if (linfo.li_max_ops_per_insn == 1)
3448 uladv *= linfo.li_min_insn_length;
3449 state_machine_regs.address += uladv;
3451 state_machine_regs.view = 0;
3452 printf (_(" Advance PC by %s to 0x%s%s\n"),
3453 dwarf_vmatoa ("u", uladv),
3454 dwarf_vmatoa ("x", state_machine_regs.address),
3455 verbose_view && uladv
3456 ? _(" (reset view)") : "");
3461 = ((state_machine_regs.op_index + uladv)
3462 / linfo.li_max_ops_per_insn)
3463 * linfo.li_min_insn_length;
3464 state_machine_regs.address
3466 state_machine_regs.op_index
3467 = (state_machine_regs.op_index + uladv)
3468 % linfo.li_max_ops_per_insn;
3470 state_machine_regs.view = 0;
3471 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3472 dwarf_vmatoa ("u", uladv),
3473 dwarf_vmatoa ("x", state_machine_regs.address),
3474 state_machine_regs.op_index,
3475 verbose_view && addrdelta
3476 ? _(" (reset view)") : "");
3480 case DW_LNS_advance_line:
3481 adv = read_sleb128 (data, & bytes_read, end);
3483 state_machine_regs.line += adv;
3484 printf (_(" Advance Line by %s to %d\n"),
3485 dwarf_vmatoa ("d", adv),
3486 state_machine_regs.line);
3489 case DW_LNS_set_file:
3490 adv = read_uleb128 (data, & bytes_read, end);
3492 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3493 dwarf_vmatoa ("d", adv));
3494 state_machine_regs.file = adv;
3497 case DW_LNS_set_column:
3498 uladv = read_uleb128 (data, & bytes_read, end);
3500 printf (_(" Set column to %s\n"),
3501 dwarf_vmatoa ("u", uladv));
3502 state_machine_regs.column = uladv;
3505 case DW_LNS_negate_stmt:
3506 adv = state_machine_regs.is_stmt;
3508 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3509 state_machine_regs.is_stmt = adv;
3512 case DW_LNS_set_basic_block:
3513 printf (_(" Set basic block\n"));
3514 state_machine_regs.basic_block = 1;
3517 case DW_LNS_const_add_pc:
3518 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3519 if (linfo.li_max_ops_per_insn)
3521 uladv *= linfo.li_min_insn_length;
3522 state_machine_regs.address += uladv;
3524 state_machine_regs.view = 0;
3525 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3526 dwarf_vmatoa ("u", uladv),
3527 dwarf_vmatoa ("x", state_machine_regs.address),
3528 verbose_view && uladv
3529 ? _(" (reset view)") : "");
3534 = ((state_machine_regs.op_index + uladv)
3535 / linfo.li_max_ops_per_insn)
3536 * linfo.li_min_insn_length;
3537 state_machine_regs.address
3539 state_machine_regs.op_index
3540 = (state_machine_regs.op_index + uladv)
3541 % linfo.li_max_ops_per_insn;
3543 state_machine_regs.view = 0;
3544 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3545 dwarf_vmatoa ("u", uladv),
3546 dwarf_vmatoa ("x", state_machine_regs.address),
3547 state_machine_regs.op_index,
3548 verbose_view && addrdelta
3549 ? _(" (reset view)") : "");
3553 case DW_LNS_fixed_advance_pc:
3554 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3555 state_machine_regs.address += uladv;
3556 state_machine_regs.op_index = 0;
3557 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3558 dwarf_vmatoa ("u", uladv),
3559 dwarf_vmatoa ("x", state_machine_regs.address));
3560 /* Do NOT reset view. */
3563 case DW_LNS_set_prologue_end:
3564 printf (_(" Set prologue_end to true\n"));
3567 case DW_LNS_set_epilogue_begin:
3568 printf (_(" Set epilogue_begin to true\n"));
3571 case DW_LNS_set_isa:
3572 uladv = read_uleb128 (data, & bytes_read, end);
3574 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3578 printf (_(" Unknown opcode %d with operands: "), op_code);
3580 if (standard_opcodes != NULL)
3581 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3583 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3585 i == 1 ? "" : ", ");
3601 unsigned char *name;
3602 unsigned int directory_index;
3603 unsigned int modification_date;
3604 unsigned int length;
3607 /* Output a decoded representation of the .debug_line section. */
3610 display_debug_lines_decoded (struct dwarf_section *section,
3611 unsigned char *data,
3612 unsigned char *end, void *fileptr)
3614 static DWARF2_Internal_LineInfo saved_linfo;
3616 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3621 /* This loop amounts to one iteration per compilation unit. */
3622 DWARF2_Internal_LineInfo linfo;
3623 unsigned char *standard_opcodes;
3624 unsigned char *end_of_sequence;
3626 File_Entry *file_table = NULL;
3627 unsigned int n_files = 0;
3628 unsigned char **directory_table = NULL;
3629 dwarf_vma n_directories = 0;
3631 if (const_strneq (section->name, ".debug_line.")
3632 /* Note: the following does not apply to .debug_line.dwo sections.
3633 These are full debug_line sections. */
3634 && strcmp (section->name, ".debug_line.dwo") != 0)
3636 /* See comment in display_debug_lines_raw(). */
3637 end_of_sequence = end;
3638 standard_opcodes = NULL;
3639 linfo = saved_linfo;
3640 /* PR 17531: file: 0522b371. */
3641 if (linfo.li_line_range == 0)
3643 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3646 reset_state_machine (linfo.li_default_is_stmt);
3650 unsigned char *hdrptr;
3652 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3653 & end_of_sequence)) == NULL)
3656 /* PR 17531: file: 0522b371. */
3657 if (linfo.li_line_range == 0)
3659 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3660 linfo.li_line_range = 1;
3662 reset_state_machine (linfo.li_default_is_stmt);
3664 /* Save a pointer to the contents of the Opcodes table. */
3665 standard_opcodes = hdrptr;
3667 /* Traverse the Directory table just to count entries. */
3668 data = standard_opcodes + linfo.li_opcode_base - 1;
3672 warn (_("opcode base of %d extends beyond end of section\n"),
3673 linfo.li_opcode_base);
3677 if (linfo.li_version >= 5)
3679 unsigned char *format_start, format_count, *format;
3680 dwarf_vma formati, entryi;
3681 unsigned int bytes_read;
3683 load_debug_section (line_str, fileptr);
3685 /* Skip directories format. */
3686 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3687 format_start = data;
3688 for (formati = 0; formati < format_count; formati++)
3690 read_uleb128 (data, & bytes_read, end);
3692 read_uleb128 (data, & bytes_read, end);
3696 n_directories = read_uleb128 (data, & bytes_read, end);
3700 warn (_("Corrupt directories list\n"));
3704 directory_table = (unsigned char **)
3705 xmalloc (n_directories * sizeof (unsigned char *));
3707 for (entryi = 0; entryi < n_directories; entryi++)
3709 unsigned char **pathp = &directory_table[entryi];
3711 format = format_start;
3712 for (formati = 0; formati < format_count; formati++)
3714 dwarf_vma content_type, form;
3717 content_type = read_uleb128 (format, & bytes_read, end);
3718 format += bytes_read;
3719 form = read_uleb128 (format, & bytes_read, end);
3720 format += bytes_read;
3723 warn (_("Corrupt directories list\n"));
3726 switch (content_type)
3731 case DW_FORM_string:
3734 case DW_FORM_line_strp:
3735 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3737 /* Remove const by the cast. */
3738 *pathp = (unsigned char *)
3739 fetch_indirect_line_string (uvalue);
3744 data = read_and_display_attr_value (0, form, 0, data, end,
3746 linfo.li_offset_size,
3753 warn (_("Corrupt directories list\n"));
3758 /* Skip files format. */
3759 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3760 format_start = data;
3761 for (formati = 0; formati < format_count; formati++)
3763 read_uleb128 (data, & bytes_read, end);
3765 read_uleb128 (data, & bytes_read, end);
3769 n_files = read_uleb128 (data, & bytes_read, end);
3773 warn (_("Corrupt file name list\n"));
3777 file_table = (File_Entry *) xcalloc (1, n_files
3778 * sizeof (File_Entry));
3780 for (entryi = 0; entryi < n_files; entryi++)
3782 File_Entry *file = &file_table[entryi];
3784 format = format_start;
3785 for (formati = 0; formati < format_count; formati++)
3787 dwarf_vma content_type, form;
3790 content_type = read_uleb128 (format, & bytes_read, end);
3791 format += bytes_read;
3792 form = read_uleb128 (format, & bytes_read, end);
3793 format += bytes_read;
3796 warn (_("Corrupt file name list\n"));
3799 switch (content_type)
3804 case DW_FORM_string:
3807 case DW_FORM_line_strp:
3808 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3810 /* Remove const by the cast. */
3811 file->name = (unsigned char *)
3812 fetch_indirect_line_string (uvalue);
3816 case DW_LNCT_directory_index:
3820 SAFE_BYTE_GET (file->directory_index, data, 1,
3824 SAFE_BYTE_GET (file->directory_index, data, 2,
3828 file->directory_index = read_uleb128 (data, NULL,
3834 data = read_and_display_attr_value (0, form, 0, data, end,
3836 linfo.li_offset_size,
3843 warn (_("Corrupt file name list\n"));
3852 unsigned char *ptr_directory_table = data;
3854 while (data < end && *data != 0)
3856 data += strnlen ((char *) data, end - data) + 1;
3863 warn (_("directory table ends unexpectedly\n"));
3868 /* Go through the directory table again to save the directories. */
3869 directory_table = (unsigned char **)
3870 xmalloc (n_directories * sizeof (unsigned char *));
3873 while (*ptr_directory_table != 0)
3875 directory_table[i] = ptr_directory_table;
3876 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3877 ptr_directory_table - end) + 1;
3881 /* Skip the NUL at the end of the table. */
3884 /* Traverse the File Name table just to count the entries. */
3885 if (data < end && *data != 0)
3887 unsigned char *ptr_file_name_table = data;
3889 while (data < end && *data != 0)
3891 unsigned int bytes_read;
3893 /* Skip Name, directory index, last modification time and length
3895 data += strnlen ((char *) data, end - data) + 1;
3896 read_uleb128 (data, & bytes_read, end);
3898 read_uleb128 (data, & bytes_read, end);
3900 read_uleb128 (data, & bytes_read, end);
3908 warn (_("file table ends unexpectedly\n"));
3913 /* Go through the file table again to save the strings. */
3914 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3917 while (*ptr_file_name_table != 0)
3919 unsigned int bytes_read;
3921 file_table[i].name = ptr_file_name_table;
3922 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3923 end - ptr_file_name_table) + 1;
3925 /* We are not interested in directory, time or size. */
3926 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3928 ptr_file_name_table += bytes_read;
3929 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3931 ptr_file_name_table += bytes_read;
3932 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3933 ptr_file_name_table += bytes_read;
3939 /* Skip the NUL at the end of the table. */
3943 /* Print the Compilation Unit's name and a header. */
3944 if (file_table == NULL)
3946 else if (directory_table == NULL)
3947 printf (_("CU: %s:\n"), file_table[0].name);
3950 unsigned int ix = file_table[0].directory_index;
3951 const char *directory;
3956 else if (n_directories == 0)
3957 directory = _("<unknown>");
3958 else if (ix > n_directories)
3960 warn (_("directory index %u > number of directories %s\n"),
3961 ix, dwarf_vmatoa ("u", n_directories));
3962 directory = _("<corrupt>");
3965 directory = (char *) directory_table[ix - 1];
3967 if (do_wide || strlen (directory) < 76)
3968 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3970 printf ("%s:\n", file_table[0].name);
3973 printf (_("File name Line number Starting address View\n"));
3974 saved_linfo = linfo;
3977 /* This loop iterates through the Dwarf Line Number Program. */
3978 while (data < end_of_sequence)
3980 unsigned char op_code;
3983 unsigned long int uladv;
3984 unsigned int bytes_read;
3985 int is_special_opcode = 0;
3990 if (op_code >= linfo.li_opcode_base)
3992 op_code -= linfo.li_opcode_base;
3993 uladv = (op_code / linfo.li_line_range);
3994 if (linfo.li_max_ops_per_insn == 1)
3996 uladv *= linfo.li_min_insn_length;
3997 state_machine_regs.address += uladv;
3999 state_machine_regs.view = 0;
4004 = ((state_machine_regs.op_index + uladv)
4005 / linfo.li_max_ops_per_insn)
4006 * linfo.li_min_insn_length;
4007 state_machine_regs.address
4009 state_machine_regs.op_index
4010 = (state_machine_regs.op_index + uladv)
4011 % linfo.li_max_ops_per_insn;
4013 state_machine_regs.view = 0;
4016 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4017 state_machine_regs.line += adv;
4018 is_special_opcode = 1;
4019 /* Increment view after printing this row. */
4021 else switch (op_code)
4023 case DW_LNS_extended_op:
4025 unsigned int ext_op_code_len;
4026 unsigned char ext_op_code;
4027 unsigned char *op_code_data = data;
4029 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4031 op_code_data += bytes_read;
4033 if (ext_op_code_len == 0)
4035 warn (_("Badly formed extended line op encountered!\n"));
4038 ext_op_code_len += bytes_read;
4039 ext_op_code = *op_code_data++;
4043 switch (ext_op_code)
4045 case DW_LNE_end_sequence:
4046 /* Reset stuff after printing this row. */
4048 case DW_LNE_set_address:
4049 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
4051 ext_op_code_len - bytes_read - 1,
4053 state_machine_regs.op_index = 0;
4054 state_machine_regs.view = 0;
4056 case DW_LNE_define_file:
4058 file_table = (File_Entry *) xrealloc
4059 (file_table, (n_files + 1) * sizeof (File_Entry));
4061 ++state_machine_regs.last_file_entry;
4062 /* Source file name. */
4063 file_table[n_files].name = op_code_data;
4064 op_code_data += strlen ((char *) op_code_data) + 1;
4065 /* Directory index. */
4066 file_table[n_files].directory_index =
4067 read_uleb128 (op_code_data, & bytes_read,
4069 op_code_data += bytes_read;
4070 /* Last modification time. */
4071 file_table[n_files].modification_date =
4072 read_uleb128 (op_code_data, & bytes_read,
4074 op_code_data += bytes_read;
4076 file_table[n_files].length =
4077 read_uleb128 (op_code_data, & bytes_read,
4083 case DW_LNE_set_discriminator:
4084 case DW_LNE_HP_set_sequence:
4085 /* Simply ignored. */
4089 printf (_("UNKNOWN (%u): length %d\n"),
4090 ext_op_code, ext_op_code_len - bytes_read);
4093 data += ext_op_code_len;
4097 /* Increment view after printing this row. */
4100 case DW_LNS_advance_pc:
4101 uladv = read_uleb128 (data, & bytes_read, end);
4103 if (linfo.li_max_ops_per_insn == 1)
4105 uladv *= linfo.li_min_insn_length;
4106 state_machine_regs.address += uladv;
4108 state_machine_regs.view = 0;
4113 = ((state_machine_regs.op_index + uladv)
4114 / linfo.li_max_ops_per_insn)
4115 * linfo.li_min_insn_length;
4116 state_machine_regs.address
4118 state_machine_regs.op_index
4119 = (state_machine_regs.op_index + uladv)
4120 % linfo.li_max_ops_per_insn;
4122 state_machine_regs.view = 0;
4126 case DW_LNS_advance_line:
4127 adv = read_sleb128 (data, & bytes_read, end);
4129 state_machine_regs.line += adv;
4132 case DW_LNS_set_file:
4133 adv = read_uleb128 (data, & bytes_read, end);
4135 state_machine_regs.file = adv;
4138 unsigned file = state_machine_regs.file - 1;
4141 if (file_table == NULL || n_files == 0)
4142 printf (_("\n [Use file table entry %d]\n"), file);
4144 else if (file >= n_files)
4146 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4147 printf (_("\n <over large file table index %u>"), file);
4149 else if ((dir = file_table[file].directory_index) == 0)
4150 /* If directory index is 0, that means current directory. */
4151 printf ("\n./%s:[++]\n", file_table[file].name);
4152 else if (directory_table == NULL || n_directories == 0)
4153 printf (_("\n [Use file %s in directory table entry %d]\n"),
4154 file_table[file].name, dir);
4156 else if (dir > n_directories)
4158 warn (_("directory index %u > number of directories %s\n"),
4159 dir, dwarf_vmatoa ("u", n_directories));
4160 printf (_("\n <over large directory table entry %u>\n"), dir);
4163 printf ("\n%s/%s:\n",
4164 /* The directory index starts counting at 1. */
4165 directory_table[dir - 1], file_table[file].name);
4169 case DW_LNS_set_column:
4170 uladv = read_uleb128 (data, & bytes_read, end);
4172 state_machine_regs.column = uladv;
4175 case DW_LNS_negate_stmt:
4176 adv = state_machine_regs.is_stmt;
4178 state_machine_regs.is_stmt = adv;
4181 case DW_LNS_set_basic_block:
4182 state_machine_regs.basic_block = 1;
4185 case DW_LNS_const_add_pc:
4186 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4187 if (linfo.li_max_ops_per_insn == 1)
4189 uladv *= linfo.li_min_insn_length;
4190 state_machine_regs.address += uladv;
4192 state_machine_regs.view = 0;
4197 = ((state_machine_regs.op_index + uladv)
4198 / linfo.li_max_ops_per_insn)
4199 * linfo.li_min_insn_length;
4200 state_machine_regs.address
4202 state_machine_regs.op_index
4203 = (state_machine_regs.op_index + uladv)
4204 % linfo.li_max_ops_per_insn;
4206 state_machine_regs.view = 0;
4210 case DW_LNS_fixed_advance_pc:
4211 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4212 state_machine_regs.address += uladv;
4213 state_machine_regs.op_index = 0;
4214 /* Do NOT reset view. */
4217 case DW_LNS_set_prologue_end:
4220 case DW_LNS_set_epilogue_begin:
4223 case DW_LNS_set_isa:
4224 uladv = read_uleb128 (data, & bytes_read, end);
4226 printf (_(" Set ISA to %lu\n"), uladv);
4230 printf (_(" Unknown opcode %d with operands: "), op_code);
4232 if (standard_opcodes != NULL)
4233 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4235 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4237 i == 1 ? "" : ", ");
4244 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4245 to the DWARF address/line matrix. */
4246 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4247 || (xop == DW_LNS_copy))
4249 const unsigned int MAX_FILENAME_LENGTH = 35;
4251 char *newFileName = NULL;
4252 size_t fileNameLength;
4256 unsigned indx = state_machine_regs.file - 1;
4258 if (indx >= n_files)
4260 warn (_("corrupt file index %u encountered\n"), indx);
4261 fileName = _("<corrupt>");
4264 fileName = (char *) file_table[indx].name;
4267 fileName = _("<unknown>");
4269 fileNameLength = strlen (fileName);
4271 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4273 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4274 /* Truncate file name */
4275 strncpy (newFileName,
4276 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4277 MAX_FILENAME_LENGTH + 1);
4281 newFileName = (char *) xmalloc (fileNameLength + 1);
4282 strncpy (newFileName, fileName, fileNameLength + 1);
4285 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4287 if (linfo.li_max_ops_per_insn == 1)
4288 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
4289 newFileName, state_machine_regs.line,
4290 state_machine_regs.address);
4292 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
4293 newFileName, state_machine_regs.line,
4294 state_machine_regs.address,
4295 state_machine_regs.op_index);
4299 if (linfo.li_max_ops_per_insn == 1)
4300 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
4301 newFileName, state_machine_regs.line,
4302 state_machine_regs.address);
4304 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
4305 newFileName, state_machine_regs.line,
4306 state_machine_regs.address,
4307 state_machine_regs.op_index);
4310 if (state_machine_regs.view)
4311 printf (" %6u\n", state_machine_regs.view);
4314 state_machine_regs.view++;
4316 if (xop == -DW_LNE_end_sequence)
4318 reset_state_machine (linfo.li_default_is_stmt);
4333 if (directory_table)
4335 free (directory_table);
4336 directory_table = NULL;
4347 display_debug_lines (struct dwarf_section *section, void *file)
4349 unsigned char *data = section->start;
4350 unsigned char *end = data + section->size;
4352 int retValDecoded = 1;
4354 if (do_debug_lines == 0)
4355 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4357 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4358 retValRaw = display_debug_lines_raw (section, data, end, file);
4360 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4361 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4363 if (!retValRaw || !retValDecoded)
4370 find_debug_info_for_offset (unsigned long offset)
4374 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4377 for (i = 0; i < num_debug_info_entries; i++)
4378 if (debug_information[i].cu_offset == offset)
4379 return debug_information + i;
4385 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4387 /* See gdb/gdb-index.h. */
4388 static const char * const kinds[] =
4400 return _ (kinds[kind]);
4404 display_debug_pubnames_worker (struct dwarf_section *section,
4405 void *file ATTRIBUTE_UNUSED,
4408 DWARF2_Internal_PubNames names;
4409 unsigned char *start = section->start;
4410 unsigned char *end = start + section->size;
4412 /* It does not matter if this load fails,
4413 we test for that later on. */
4414 load_debug_info (file);
4416 printf (_("Contents of the %s section:\n\n"), section->name);
4420 unsigned char *data;
4423 unsigned int offset_size, initial_length_size;
4427 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4428 if (names.pn_length == 0xffffffff)
4430 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4432 initial_length_size = 12;
4437 initial_length_size = 4;
4440 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4441 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4443 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4444 && num_debug_info_entries > 0
4445 && find_debug_info_for_offset (names.pn_offset) == NULL)
4446 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4447 (unsigned long) names.pn_offset, section->name);
4449 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4451 adr = start + names.pn_length + initial_length_size;
4452 /* PR 17531: file: 7615b6b2. */
4453 if ((dwarf_signed_vma) names.pn_length < 0
4454 /* PR 17531: file: a5dbeaa7. */
4457 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4463 printf (_(" Length: %ld\n"),
4464 (long) names.pn_length);
4465 printf (_(" Version: %d\n"),
4467 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4468 (unsigned long) names.pn_offset);
4469 printf (_(" Size of area in .debug_info section: %ld\n"),
4470 (long) names.pn_size);
4472 if (names.pn_version != 2 && names.pn_version != 3)
4474 static int warned = 0;
4478 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4486 printf (_("\n Offset Kind Name\n"));
4488 printf (_("\n Offset\tName\n"));
4492 bfd_size_type maxprint;
4494 SAFE_BYTE_GET (offset, data, offset_size, end);
4498 data += offset_size;
4501 maxprint = (end - data) - 1;
4505 unsigned int kind_data;
4506 gdb_index_symbol_kind kind;
4507 const char *kind_name;
4510 SAFE_BYTE_GET (kind_data, data, 1, end);
4513 /* GCC computes the kind as the upper byte in the CU index
4514 word, and then right shifts it by the CU index size.
4515 Left shift KIND to where the gdb-index.h accessor macros
4517 kind_data <<= GDB_INDEX_CU_BITSIZE;
4518 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4519 kind_name = get_gdb_index_symbol_kind_name (kind);
4520 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4521 printf (" %-6lx %s,%-10s %.*s\n",
4522 (unsigned long) offset, is_static ? _("s") : _("g"),
4523 kind_name, (int) maxprint, data);
4526 printf (" %-6lx\t%.*s\n",
4527 (unsigned long) offset, (int) maxprint, data);
4529 data += strnlen ((char *) data, maxprint) + 1;
4534 while (offset != 0);
4542 display_debug_pubnames (struct dwarf_section *section, void *file)
4544 return display_debug_pubnames_worker (section, file, 0);
4548 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4550 return display_debug_pubnames_worker (section, file, 1);
4554 display_debug_macinfo (struct dwarf_section *section,
4555 void *file ATTRIBUTE_UNUSED)
4557 unsigned char *start = section->start;
4558 unsigned char *end = start + section->size;
4559 unsigned char *curr = start;
4560 unsigned int bytes_read;
4561 enum dwarf_macinfo_record_type op;
4563 printf (_("Contents of the %s section:\n\n"), section->name);
4567 unsigned int lineno;
4568 const unsigned char *string;
4570 op = (enum dwarf_macinfo_record_type) *curr;
4575 case DW_MACINFO_start_file:
4577 unsigned int filenum;
4579 lineno = read_uleb128 (curr, & bytes_read, end);
4581 filenum = read_uleb128 (curr, & bytes_read, end);
4584 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4589 case DW_MACINFO_end_file:
4590 printf (_(" DW_MACINFO_end_file\n"));
4593 case DW_MACINFO_define:
4594 lineno = read_uleb128 (curr, & bytes_read, end);
4597 curr += strnlen ((char *) string, end - string) + 1;
4598 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4602 case DW_MACINFO_undef:
4603 lineno = read_uleb128 (curr, & bytes_read, end);
4606 curr += strnlen ((char *) string, end - string) + 1;
4607 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4611 case DW_MACINFO_vendor_ext:
4613 unsigned int constant;
4615 constant = read_uleb128 (curr, & bytes_read, end);
4618 curr += strnlen ((char *) string, end - string) + 1;
4619 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4629 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4630 filename and dirname corresponding to file name table entry with index
4631 FILEIDX. Return NULL on failure. */
4633 static unsigned char *
4634 get_line_filename_and_dirname (dwarf_vma line_offset,
4636 unsigned char **dir_name)
4638 struct dwarf_section *section = &debug_displays [line].section;
4639 unsigned char *hdrptr, *dirtable, *file_name;
4640 unsigned int offset_size, initial_length_size;
4641 unsigned int version, opcode_base, bytes_read;
4642 dwarf_vma length, diridx;
4643 const unsigned char * end;
4646 if (section->start == NULL
4647 || line_offset >= section->size
4651 hdrptr = section->start + line_offset;
4652 end = section->start + section->size;
4654 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4655 if (length == 0xffffffff)
4657 /* This section is 64-bit DWARF 3. */
4658 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4660 initial_length_size = 12;
4665 initial_length_size = 4;
4667 if (length + initial_length_size > section->size)
4670 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4671 if (version != 2 && version != 3 && version != 4)
4673 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4675 hdrptr++; /* Skip max_ops_per_insn. */
4676 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4678 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4679 if (opcode_base == 0)
4682 hdrptr += opcode_base - 1;
4684 /* Skip over dirname table. */
4685 while (*hdrptr != '\0')
4686 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4687 hdrptr++; /* Skip the NUL at the end of the table. */
4688 /* Now skip over preceding filename table entries. */
4689 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4691 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4692 read_uleb128 (hdrptr, &bytes_read, end);
4693 hdrptr += bytes_read;
4694 read_uleb128 (hdrptr, &bytes_read, end);
4695 hdrptr += bytes_read;
4696 read_uleb128 (hdrptr, &bytes_read, end);
4697 hdrptr += bytes_read;
4699 if (hdrptr == end || *hdrptr == '\0')
4702 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4703 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4706 for (; *dirtable != '\0' && diridx > 1; diridx--)
4707 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4708 if (*dirtable == '\0')
4710 *dir_name = dirtable;
4715 display_debug_macro (struct dwarf_section *section,
4718 unsigned char *start = section->start;
4719 unsigned char *end = start + section->size;
4720 unsigned char *curr = start;
4721 unsigned char *extended_op_buf[256];
4722 unsigned int bytes_read;
4724 load_debug_section (str, file);
4725 load_debug_section (line, file);
4727 printf (_("Contents of the %s section:\n\n"), section->name);
4731 unsigned int lineno, version, flags;
4732 unsigned int offset_size = 4;
4733 const unsigned char *string;
4734 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4735 unsigned char **extended_ops = NULL;
4737 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4738 if (version != 4 && version != 5)
4740 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4745 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4748 printf (_(" Offset: 0x%lx\n"),
4749 (unsigned long) sec_offset);
4750 printf (_(" Version: %d\n"), version);
4751 printf (_(" Offset size: %d\n"), offset_size);
4754 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4755 printf (_(" Offset into .debug_line: 0x%lx\n"),
4756 (unsigned long) line_offset);
4760 unsigned int i, count, op;
4763 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4765 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4766 extended_ops = extended_op_buf;
4769 printf (_(" Extension opcode arguments:\n"));
4770 for (i = 0; i < count; i++)
4772 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4773 extended_ops[op] = curr;
4774 nargs = read_uleb128 (curr, &bytes_read, end);
4777 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4780 printf (_(" DW_MACRO_%02x arguments: "), op);
4781 for (n = 0; n < nargs; n++)
4785 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4786 printf ("%s%s", get_FORM_name (form),
4787 n == nargs - 1 ? "\n" : ", ");
4797 case DW_FORM_block1:
4798 case DW_FORM_block2:
4799 case DW_FORM_block4:
4801 case DW_FORM_string:
4803 case DW_FORM_sec_offset:
4806 error (_("Invalid extension opcode form %s\n"),
4807 get_FORM_name (form));
4823 error (_(".debug_macro section not zero terminated\n"));
4827 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4833 case DW_MACRO_start_file:
4835 unsigned int filenum;
4836 unsigned char *file_name = NULL, *dir_name = NULL;
4838 lineno = read_uleb128 (curr, &bytes_read, end);
4840 filenum = read_uleb128 (curr, &bytes_read, end);
4843 if ((flags & 2) == 0)
4844 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4847 = get_line_filename_and_dirname (line_offset, filenum,
4849 if (file_name == NULL)
4850 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4853 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4855 dir_name != NULL ? (const char *) dir_name : "",
4856 dir_name != NULL ? "/" : "", file_name);
4860 case DW_MACRO_end_file:
4861 printf (_(" DW_MACRO_end_file\n"));
4864 case DW_MACRO_define:
4865 lineno = read_uleb128 (curr, &bytes_read, end);
4868 curr += strnlen ((char *) string, end - string) + 1;
4869 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4873 case DW_MACRO_undef:
4874 lineno = read_uleb128 (curr, &bytes_read, end);
4877 curr += strnlen ((char *) string, end - string) + 1;
4878 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4882 case DW_MACRO_define_strp:
4883 lineno = read_uleb128 (curr, &bytes_read, end);
4885 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4886 string = fetch_indirect_string (offset);
4887 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4891 case DW_MACRO_undef_strp:
4892 lineno = read_uleb128 (curr, &bytes_read, end);
4894 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4895 string = fetch_indirect_string (offset);
4896 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4900 case DW_MACRO_import:
4901 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4902 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4903 (unsigned long) offset);
4906 case DW_MACRO_define_sup:
4907 lineno = read_uleb128 (curr, &bytes_read, end);
4909 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4910 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4911 lineno, (unsigned long) offset);
4914 case DW_MACRO_undef_sup:
4915 lineno = read_uleb128 (curr, &bytes_read, end);
4917 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4918 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4919 lineno, (unsigned long) offset);
4922 case DW_MACRO_import_sup:
4923 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4924 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4925 (unsigned long) offset);
4929 if (extended_ops == NULL || extended_ops[op] == NULL)
4931 error (_(" Unknown macro opcode %02x seen\n"), op);
4936 /* Skip over unhandled opcodes. */
4938 unsigned char *desc = extended_ops[op];
4939 nargs = read_uleb128 (desc, &bytes_read, end);
4943 printf (_(" DW_MACRO_%02x\n"), op);
4946 printf (_(" DW_MACRO_%02x -"), op);
4947 for (n = 0; n < nargs; n++)
4951 /* DW_FORM_implicit_const is not expected here. */
4952 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4954 = read_and_display_attr_value (0, val, 0,
4955 curr, end, 0, 0, offset_size,
4956 version, NULL, 0, NULL,
4974 display_debug_abbrev (struct dwarf_section *section,
4975 void *file ATTRIBUTE_UNUSED)
4977 abbrev_entry *entry;
4978 unsigned char *start = section->start;
4979 unsigned char *end = start + section->size;
4981 printf (_("Contents of the %s section:\n\n"), section->name);
4985 unsigned char *last;
4990 start = process_abbrev_section (start, end);
4992 if (first_abbrev == NULL)
4995 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4997 for (entry = first_abbrev; entry; entry = entry->next)
5001 printf (" %ld %s [%s]\n",
5003 get_TAG_name (entry->tag),
5004 entry->children ? _("has children") : _("no children"));
5006 for (attr = entry->first_attr; attr; attr = attr->next)
5008 printf (" %-18s %s",
5009 get_AT_name (attr->attribute),
5010 get_FORM_name (attr->form));
5011 if (attr->form == DW_FORM_implicit_const)
5012 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5024 /* Return true when ADDR is the maximum address, when addresses are
5025 POINTER_SIZE bytes long. */
5028 is_max_address (dwarf_vma addr, unsigned int pointer_size)
5030 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5031 return ((addr & mask) == mask);
5034 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5037 display_loc_list (struct dwarf_section *section,
5038 unsigned char **start_ptr,
5039 unsigned int debug_info_entry,
5041 dwarf_vma base_address,
5044 unsigned char *start = *start_ptr;
5045 unsigned char *section_end = section->start + section->size;
5046 unsigned long cu_offset;
5047 unsigned int pointer_size;
5048 unsigned int offset_size;
5053 unsigned short length;
5054 int need_frame_base;
5056 if (debug_info_entry >= num_debug_info_entries)
5058 warn (_("No debug information available for loc lists of entry: %u\n"),
5063 cu_offset = debug_information [debug_info_entry].cu_offset;
5064 pointer_size = debug_information [debug_info_entry].pointer_size;
5065 offset_size = debug_information [debug_info_entry].offset_size;
5066 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5068 if (pointer_size < 2 || pointer_size > 8)
5070 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5071 pointer_size, debug_info_entry);
5077 dwarf_vma off = offset + (start - *start_ptr);
5079 if (start + 2 * pointer_size > section_end)
5081 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5082 (unsigned long) offset);
5086 printf (" %8.8lx ", (unsigned long) off);
5088 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5089 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5091 if (begin == 0 && end == 0)
5093 /* PR 18374: In a object file we can have a location list that
5094 starts with a begin and end of 0 because there are relocations
5095 that need to be applied to the addresses. Actually applying
5096 the relocations now does not help as they will probably resolve
5097 to 0, since the object file has not been fully linked. Real
5098 end of list markers will not have any relocations against them. */
5099 if (! reloc_at (section, off)
5100 && ! reloc_at (section, off + pointer_size))
5102 printf (_("<End of list>\n"));
5107 /* Check base address specifiers. */
5108 if (is_max_address (begin, pointer_size)
5109 && !is_max_address (end, pointer_size))
5112 print_dwarf_vma (begin, pointer_size);
5113 print_dwarf_vma (end, pointer_size);
5114 printf (_("(base address)\n"));
5118 if (start + 2 > section_end)
5120 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5121 (unsigned long) offset);
5125 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5127 if (start + length > section_end)
5129 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5130 (unsigned long) offset);
5134 print_dwarf_vma (begin + base_address, pointer_size);
5135 print_dwarf_vma (end + base_address, pointer_size);
5138 need_frame_base = decode_location_expression (start,
5143 cu_offset, section);
5146 if (need_frame_base && !has_frame_base)
5147 printf (_(" [without DW_AT_frame_base]"));
5150 fputs (_(" (start == end)"), stdout);
5151 else if (begin > end)
5152 fputs (_(" (start > end)"), stdout);
5162 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5165 display_loclists_list (struct dwarf_section *section,
5166 unsigned char **start_ptr,
5167 unsigned int debug_info_entry,
5169 dwarf_vma base_address,
5172 unsigned char *start = *start_ptr;
5173 unsigned char *section_end = section->start + section->size;
5174 unsigned long cu_offset;
5175 unsigned int pointer_size;
5176 unsigned int offset_size;
5178 unsigned int bytes_read;
5180 /* Initialize it due to a false compiler warning. */
5181 dwarf_vma begin = -1;
5184 int need_frame_base;
5186 if (debug_info_entry >= num_debug_info_entries)
5188 warn (_("No debug information available for "
5189 "loclists lists of entry: %u\n"),
5194 cu_offset = debug_information [debug_info_entry].cu_offset;
5195 pointer_size = debug_information [debug_info_entry].pointer_size;
5196 offset_size = debug_information [debug_info_entry].offset_size;
5197 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5199 if (pointer_size < 2 || pointer_size > 8)
5201 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5202 pointer_size, debug_info_entry);
5208 dwarf_vma off = offset + (start - *start_ptr);
5209 enum dwarf_location_list_entry_type llet;
5211 if (start + 1 > section_end)
5213 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5214 (unsigned long) offset);
5218 printf (" %8.8lx ", (unsigned long) off);
5220 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5224 case DW_LLE_end_of_list:
5225 printf (_("<End of list>\n"));
5227 case DW_LLE_offset_pair:
5228 begin = read_uleb128 (start, &bytes_read, section_end);
5229 start += bytes_read;
5230 end = read_uleb128 (start, &bytes_read, section_end);
5231 start += bytes_read;
5233 case DW_LLE_base_address:
5234 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5236 print_dwarf_vma (base_address, pointer_size);
5237 printf (_("(base address)\n"));
5240 error (_("Invalid location list entry type %d\n"), llet);
5243 if (llet == DW_LLE_end_of_list)
5245 if (llet != DW_LLE_offset_pair)
5248 if (start + 2 > section_end)
5250 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5251 (unsigned long) offset);
5255 length = read_uleb128 (start, &bytes_read, section_end);
5256 start += bytes_read;
5258 print_dwarf_vma (begin + base_address, pointer_size);
5259 print_dwarf_vma (end + base_address, pointer_size);
5262 need_frame_base = decode_location_expression (start,
5267 cu_offset, section);
5270 if (need_frame_base && !has_frame_base)
5271 printf (_(" [without DW_AT_frame_base]"));
5274 fputs (_(" (start == end)"), stdout);
5275 else if (begin > end)
5276 fputs (_(" (start > end)"), stdout);
5286 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5287 right-adjusted in a field of length LEN, and followed by a space. */
5290 print_addr_index (unsigned int idx, unsigned int len)
5292 static char buf[15];
5293 snprintf (buf, sizeof (buf), "[%d]", idx);
5294 printf ("%*s ", len, buf);
5297 /* Display a location list from a .dwo section. It uses address indexes rather
5298 than embedded addresses. This code closely follows display_loc_list, but the
5299 two are sufficiently different that combining things is very ugly. */
5302 display_loc_list_dwo (struct dwarf_section *section,
5303 unsigned char **start_ptr,
5304 unsigned int debug_info_entry,
5308 unsigned char *start = *start_ptr;
5309 unsigned char *section_end = section->start + section->size;
5310 unsigned long cu_offset;
5311 unsigned int pointer_size;
5312 unsigned int offset_size;
5315 unsigned short length;
5316 int need_frame_base;
5318 unsigned int bytes_read;
5320 if (debug_info_entry >= num_debug_info_entries)
5322 warn (_("No debug information for loc lists of entry: %u\n"),
5327 cu_offset = debug_information [debug_info_entry].cu_offset;
5328 pointer_size = debug_information [debug_info_entry].pointer_size;
5329 offset_size = debug_information [debug_info_entry].offset_size;
5330 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5332 if (pointer_size < 2 || pointer_size > 8)
5334 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5335 pointer_size, debug_info_entry);
5341 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5343 if (start >= section_end)
5345 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5346 (unsigned long) offset);
5350 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5353 case 0: /* A terminating entry. */
5355 printf (_("<End of list>\n"));
5357 case 1: /* A base-address entry. */
5358 idx = read_uleb128 (start, &bytes_read, section_end);
5359 start += bytes_read;
5360 print_addr_index (idx, 8);
5362 printf (_("(base address selection entry)\n"));
5364 case 2: /* A start/end entry. */
5365 idx = read_uleb128 (start, &bytes_read, section_end);
5366 start += bytes_read;
5367 print_addr_index (idx, 8);
5368 idx = read_uleb128 (start, &bytes_read, section_end);
5369 start += bytes_read;
5370 print_addr_index (idx, 8);
5372 case 3: /* A start/length entry. */
5373 idx = read_uleb128 (start, &bytes_read, section_end);
5374 start += bytes_read;
5375 print_addr_index (idx, 8);
5376 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5377 printf ("%08x ", idx);
5379 case 4: /* An offset pair entry. */
5380 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5381 printf ("%08x ", idx);
5382 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5383 printf ("%08x ", idx);
5386 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5391 if (start + 2 > section_end)
5393 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5394 (unsigned long) offset);
5398 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5399 if (start + length > section_end)
5401 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5402 (unsigned long) offset);
5407 need_frame_base = decode_location_expression (start,
5412 cu_offset, section);
5415 if (need_frame_base && !has_frame_base)
5416 printf (_(" [without DW_AT_frame_base]"));
5426 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5428 static dwarf_vma *loc_offsets;
5431 loc_offsets_compar (const void *ap, const void *bp)
5433 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5434 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5436 return (a > b) - (b > a);
5440 display_debug_loc (struct dwarf_section *section, void *file)
5442 unsigned char *start = section->start;
5443 unsigned long bytes;
5444 unsigned char *section_begin = start;
5445 unsigned int num_loc_list = 0;
5446 unsigned long last_offset = 0;
5447 unsigned int first = 0;
5450 int seen_first_offset = 0;
5451 int locs_sorted = 1;
5452 unsigned char *next;
5453 unsigned int *array = NULL;
5454 const char *suffix = strrchr (section->name, '.');
5456 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5457 dwarf_vma expected_start = 0;
5459 if (suffix && strcmp (suffix, ".dwo") == 0)
5462 bytes = section->size;
5466 printf (_("\nThe %s section is empty.\n"), section->name);
5472 unsigned char *hdrptr = section_begin;
5473 dwarf_vma ll_length;
5474 unsigned short ll_version;
5475 unsigned char *end = section_begin + section->size;
5476 unsigned char address_size, segment_selector_size;
5477 uint32_t offset_entry_count;
5479 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5480 if (ll_length == 0xffffffff)
5481 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5483 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5484 if (ll_version != 5)
5486 warn (_("The %s section contains corrupt or "
5487 "unsupported version number: %d.\n"),
5488 section->name, ll_version);
5492 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5494 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5495 if (segment_selector_size != 0)
5497 warn (_("The %s section contains "
5498 "unsupported segment selector size: %d.\n"),
5499 section->name, segment_selector_size);
5503 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5504 if (offset_entry_count != 0)
5506 warn (_("The %s section contains "
5507 "unsupported offset entry count: %d.\n"),
5508 section->name, offset_entry_count);
5512 expected_start = hdrptr - section_begin;
5515 if (load_debug_info (file) == 0)
5517 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5522 /* Check the order of location list in .debug_info section. If
5523 offsets of location lists are in the ascending order, we can
5524 use `debug_information' directly. */
5525 for (i = 0; i < num_debug_info_entries; i++)
5529 num = debug_information [i].num_loc_offsets;
5530 if (num > num_loc_list)
5533 /* Check if we can use `debug_information' directly. */
5534 if (locs_sorted && num != 0)
5536 if (!seen_first_offset)
5538 /* This is the first location list. */
5539 last_offset = debug_information [i].loc_offsets [0];
5541 seen_first_offset = 1;
5547 for (; j < num; j++)
5550 debug_information [i].loc_offsets [j])
5555 last_offset = debug_information [i].loc_offsets [j];
5560 if (!seen_first_offset)
5561 error (_("No location lists in .debug_info section!\n"));
5563 if (debug_information [first].num_loc_offsets > 0
5564 && debug_information [first].loc_offsets [0] != expected_start)
5565 warn (_("Location lists in %s section start at 0x%s\n"),
5567 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5570 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5571 printf (_("Contents of the %s section:\n\n"), section->name);
5572 if (reloc_at (section, 0))
5573 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5574 printf (_(" Offset Begin End Expression\n"));
5576 seen_first_offset = 0;
5577 for (i = first; i < num_debug_info_entries; i++)
5580 dwarf_vma base_address;
5586 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5588 loc_offsets = debug_information [i].loc_offsets;
5589 qsort (array, debug_information [i].num_loc_offsets,
5590 sizeof (*array), loc_offsets_compar);
5593 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5595 j = locs_sorted ? k : array[k];
5597 && debug_information [i].loc_offsets [locs_sorted
5598 ? k - 1 : array [k - 1]]
5599 == debug_information [i].loc_offsets [j])
5601 has_frame_base = debug_information [i].have_frame_base [j];
5602 offset = debug_information [i].loc_offsets [j];
5603 next = section_begin + offset;
5604 base_address = debug_information [i].base_address;
5606 if (!seen_first_offset)
5607 seen_first_offset = 1;
5611 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5612 (unsigned long) (start - section_begin),
5613 (unsigned long) offset);
5614 else if (start > next)
5615 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5616 (unsigned long) (start - section_begin),
5617 (unsigned long) offset);
5621 if (offset >= bytes)
5623 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5624 (unsigned long) offset);
5631 display_loc_list_dwo (section, &start, i, offset,
5634 display_loc_list (section, &start, i, offset, base_address,
5640 warn (_("DWO is not yet supported.\n"));
5642 display_loclists_list (section, &start, i, offset, base_address,
5648 if (start < section->start + section->size)
5649 warn (_("There are %ld unused bytes at the end of section %s\n"),
5650 (long) (section->start + section->size - start), section->name);
5657 display_debug_str (struct dwarf_section *section,
5658 void *file ATTRIBUTE_UNUSED)
5660 unsigned char *start = section->start;
5661 unsigned long bytes = section->size;
5662 dwarf_vma addr = section->address;
5666 printf (_("\nThe %s section is empty.\n"), section->name);
5670 printf (_("Contents of the %s section:\n\n"), section->name);
5678 lbytes = (bytes > 16 ? 16 : bytes);
5680 printf (" 0x%8.8lx ", (unsigned long) addr);
5682 for (j = 0; j < 16; j++)
5685 printf ("%2.2x", start[j]);
5693 for (j = 0; j < lbytes; j++)
5696 if (k >= ' ' && k < 0x80)
5715 display_debug_info (struct dwarf_section *section, void *file)
5717 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5721 display_debug_types (struct dwarf_section *section, void *file)
5723 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5727 display_trace_info (struct dwarf_section *section, void *file)
5729 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5733 display_debug_aranges (struct dwarf_section *section,
5734 void *file ATTRIBUTE_UNUSED)
5736 unsigned char *start = section->start;
5737 unsigned char *end = start + section->size;
5739 printf (_("Contents of the %s section:\n\n"), section->name);
5741 /* It does not matter if this load fails,
5742 we test for that later on. */
5743 load_debug_info (file);
5747 unsigned char *hdrptr;
5748 DWARF2_Internal_ARange arange;
5749 unsigned char *addr_ranges;
5752 unsigned char address_size;
5754 unsigned int offset_size;
5755 unsigned int initial_length_size;
5759 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
5760 if (arange.ar_length == 0xffffffff)
5762 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
5764 initial_length_size = 12;
5769 initial_length_size = 4;
5772 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
5773 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
5775 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5776 && num_debug_info_entries > 0
5777 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
5778 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5779 (unsigned long) arange.ar_info_offset, section->name);
5781 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
5782 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
5784 if (arange.ar_version != 2 && arange.ar_version != 3)
5786 /* PR 19872: A version number of 0 probably means that there is
5787 padding at the end of the .debug_aranges section. Gold puts
5788 it there when performing an incremental link, for example.
5789 So do not generate a warning in this case. */
5790 if (arange.ar_version)
5791 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5795 printf (_(" Length: %ld\n"),
5796 (long) arange.ar_length);
5797 printf (_(" Version: %d\n"), arange.ar_version);
5798 printf (_(" Offset into .debug_info: 0x%lx\n"),
5799 (unsigned long) arange.ar_info_offset);
5800 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5801 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5803 address_size = arange.ar_pointer_size + arange.ar_segment_size;
5805 /* PR 17512: file: 001-108546-0.001:0.1. */
5806 if (address_size == 0 || address_size > 8)
5808 error (_("Invalid address size in %s section!\n"),
5813 /* The DWARF spec does not require that the address size be a power
5814 of two, but we do. This will have to change if we ever encounter
5815 an uneven architecture. */
5816 if ((address_size & (address_size - 1)) != 0)
5818 warn (_("Pointer size + Segment size is not a power of two.\n"));
5822 if (address_size > 4)
5823 printf (_("\n Address Length\n"));
5825 printf (_("\n Address Length\n"));
5827 addr_ranges = hdrptr;
5829 /* Must pad to an alignment boundary that is twice the address size. */
5830 excess = (hdrptr - start) % (2 * address_size);
5832 addr_ranges += (2 * address_size) - excess;
5834 hdrptr = start + arange.ar_length + initial_length_size;
5835 if (hdrptr < start || hdrptr > end)
5837 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5842 while (addr_ranges + 2 * address_size <= start)
5844 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5845 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5848 print_dwarf_vma (address, address_size);
5849 print_dwarf_vma (length, address_size);
5859 /* Comparison function for qsort. */
5861 comp_addr_base (const void * v0, const void * v1)
5863 debug_info * info0 = (debug_info *) v0;
5864 debug_info * info1 = (debug_info *) v1;
5865 return info0->addr_base - info1->addr_base;
5868 /* Display the debug_addr section. */
5870 display_debug_addr (struct dwarf_section *section,
5873 debug_info **debug_addr_info;
5874 unsigned char *entry;
5879 if (section->size == 0)
5881 printf (_("\nThe %s section is empty.\n"), section->name);
5885 if (load_debug_info (file) == 0)
5887 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5892 printf (_("Contents of the %s section:\n\n"), section->name);
5894 /* PR 17531: file: cf38d01b.
5895 We use xcalloc because a corrupt file may not have initialised all of the
5896 fields in the debug_info structure, which means that the sort below might
5897 try to move uninitialised data. */
5898 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5899 sizeof (debug_info *));
5902 for (i = 0; i < num_debug_info_entries; i++)
5903 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5905 /* PR 17531: file: cf38d01b. */
5906 if (debug_information[i].addr_base >= section->size)
5907 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5908 (unsigned long) debug_information[i].addr_base, i);
5910 debug_addr_info [count++] = debug_information + i;
5913 /* Add a sentinel to make iteration convenient. */
5914 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5915 debug_addr_info [count]->addr_base = section->size;
5916 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5918 for (i = 0; i < count; i++)
5921 unsigned int address_size = debug_addr_info [i]->pointer_size;
5923 printf (_(" For compilation unit at offset 0x%s:\n"),
5924 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5926 printf (_("\tIndex\tAddress\n"));
5927 entry = section->start + debug_addr_info [i]->addr_base;
5928 end = section->start + debug_addr_info [i + 1]->addr_base;
5932 dwarf_vma base = byte_get (entry, address_size);
5933 printf (_("\t%d:\t"), idx);
5934 print_dwarf_vma (base, address_size);
5936 entry += address_size;
5942 free (debug_addr_info);
5946 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5948 display_debug_str_offsets (struct dwarf_section *section,
5949 void *file ATTRIBUTE_UNUSED)
5951 if (section->size == 0)
5953 printf (_("\nThe %s section is empty.\n"), section->name);
5956 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5957 what the offset size is for this section. */
5961 /* Each debug_information[x].range_lists[y] gets this representation for
5962 sorting purposes. */
5966 /* The debug_information[x].range_lists[y] value. */
5967 dwarf_vma ranges_offset;
5969 /* Original debug_information to find parameters of the data. */
5970 debug_info *debug_info_p;
5973 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5976 range_entry_compar (const void *ap, const void *bp)
5978 const struct range_entry *a_re = (const struct range_entry *) ap;
5979 const struct range_entry *b_re = (const struct range_entry *) bp;
5980 const dwarf_vma a = a_re->ranges_offset;
5981 const dwarf_vma b = b_re->ranges_offset;
5983 return (a > b) - (b > a);
5987 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
5988 unsigned int pointer_size, unsigned long offset,
5989 unsigned long base_address)
5991 while (start < finish)
5996 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5997 if (start >= finish)
5999 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6001 printf (" %8.8lx ", offset);
6003 if (begin == 0 && end == 0)
6005 printf (_("<End of list>\n"));
6009 /* Check base address specifiers. */
6010 if (is_max_address (begin, pointer_size)
6011 && !is_max_address (end, pointer_size))
6014 print_dwarf_vma (begin, pointer_size);
6015 print_dwarf_vma (end, pointer_size);
6016 printf ("(base address)\n");
6020 print_dwarf_vma (begin + base_address, pointer_size);
6021 print_dwarf_vma (end + base_address, pointer_size);
6024 fputs (_("(start == end)"), stdout);
6025 else if (begin > end)
6026 fputs (_("(start > end)"), stdout);
6033 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6034 unsigned int pointer_size, unsigned long offset,
6035 unsigned long base_address)
6037 unsigned char *next = start;
6041 unsigned long off = offset + (start - next);
6042 enum dwarf_range_list_entry rlet;
6043 /* Initialize it due to a false compiler warning. */
6044 dwarf_vma begin = -1, length, end = -1;
6045 unsigned int bytes_read;
6047 if (start + 1 > finish)
6049 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6054 printf (" %8.8lx ", off);
6056 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6060 case DW_RLE_end_of_list:
6061 printf (_("<End of list>\n"));
6063 case DW_RLE_base_address:
6064 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6065 print_dwarf_vma (base_address, pointer_size);
6066 printf (_("(base address)\n"));
6068 case DW_RLE_start_length:
6069 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6070 length = read_uleb128 (start, &bytes_read, finish);
6071 start += bytes_read;
6072 end = begin + length;
6074 case DW_RLE_offset_pair:
6075 begin = read_uleb128 (start, &bytes_read, finish);
6076 start += bytes_read;
6077 end = read_uleb128 (start, &bytes_read, finish);
6078 start += bytes_read;
6080 case DW_RLE_start_end:
6081 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6082 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6085 error (_("Invalid range list entry type %d\n"), rlet);
6086 rlet = DW_RLE_end_of_list;
6089 if (rlet == DW_RLE_end_of_list)
6091 if (rlet == DW_RLE_base_address)
6094 print_dwarf_vma (begin + base_address, pointer_size);
6095 print_dwarf_vma (end + base_address, pointer_size);
6098 fputs (_("(start == end)"), stdout);
6099 else if (begin > end)
6100 fputs (_("(start > end)"), stdout);
6107 display_debug_ranges (struct dwarf_section *section,
6108 void *file ATTRIBUTE_UNUSED)
6110 unsigned char *start = section->start;
6111 unsigned char *last_start = start;
6112 unsigned long bytes = section->size;
6113 unsigned char *section_begin = start;
6114 unsigned char *finish = start + bytes;
6115 unsigned int num_range_list, i;
6116 struct range_entry *range_entries, *range_entry_fill;
6117 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6118 /* Initialize it due to a false compiler warning. */
6119 unsigned char address_size = 0;
6123 printf (_("\nThe %s section is empty.\n"), section->name);
6129 dwarf_vma initial_length;
6130 unsigned int initial_length_size;
6131 unsigned char segment_selector_size;
6132 unsigned int offset_size, offset_entry_count;
6133 unsigned short version;
6135 /* Get and check the length of the block. */
6136 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6138 if (initial_length == 0xffffffff)
6140 /* This section is 64-bit DWARF 3. */
6141 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6143 initial_length_size = 12;
6148 initial_length_size = 4;
6151 if (initial_length + initial_length_size > section->size)
6153 /* If the length field has a relocation against it, then we should
6154 not complain if it is inaccurate (and probably negative).
6155 It is copied from .debug_line handling code. */
6156 if (reloc_at (section, (start - section->start) - offset_size))
6158 initial_length = (finish - start) - initial_length_size;
6162 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6163 (long) initial_length);
6168 /* Get and check the version number. */
6169 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6173 warn (_("Only DWARF version 5 debug_rnglists info "
6174 "is currently supported.\n"));
6178 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6180 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6181 if (segment_selector_size != 0)
6183 warn (_("The %s section contains "
6184 "unsupported segment selector size: %d.\n"),
6185 section->name, segment_selector_size);
6189 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6190 if (offset_entry_count != 0)
6192 warn (_("The %s section contains "
6193 "unsupported offset entry count: %u.\n"),
6194 section->name, offset_entry_count);
6199 if (load_debug_info (file) == 0)
6201 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6207 for (i = 0; i < num_debug_info_entries; i++)
6208 num_range_list += debug_information [i].num_range_lists;
6210 if (num_range_list == 0)
6212 /* This can happen when the file was compiled with -gsplit-debug
6213 which removes references to range lists from the primary .o file. */
6214 printf (_("No range lists in .debug_info section.\n"));
6218 range_entries = (struct range_entry *)
6219 xmalloc (sizeof (*range_entries) * num_range_list);
6220 range_entry_fill = range_entries;
6222 for (i = 0; i < num_debug_info_entries; i++)
6224 debug_info *debug_info_p = &debug_information[i];
6227 for (j = 0; j < debug_info_p->num_range_lists; j++)
6229 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6230 range_entry_fill->debug_info_p = debug_info_p;
6235 qsort (range_entries, num_range_list, sizeof (*range_entries),
6236 range_entry_compar);
6238 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6239 warn (_("Range lists in %s section start at 0x%lx\n"),
6240 section->name, (unsigned long) range_entries[0].ranges_offset);
6242 printf (_("Contents of the %s section:\n\n"), section->name);
6243 printf (_(" Offset Begin End\n"));
6245 for (i = 0; i < num_range_list; i++)
6247 struct range_entry *range_entry = &range_entries[i];
6248 debug_info *debug_info_p = range_entry->debug_info_p;
6249 unsigned int pointer_size;
6251 unsigned char *next;
6252 dwarf_vma base_address;
6254 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6255 offset = range_entry->ranges_offset;
6256 next = section_begin + offset;
6257 base_address = debug_info_p->base_address;
6259 /* PR 17512: file: 001-101485-0.001:0.1. */
6260 if (pointer_size < 2 || pointer_size > 8)
6262 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6263 pointer_size, (unsigned long) offset);
6267 if (dwarf_check != 0 && i > 0)
6270 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6271 (unsigned long) (start - section_begin),
6272 (unsigned long) (next - section_begin), section->name);
6273 else if (start > next)
6275 if (next == last_start)
6277 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6278 (unsigned long) (start - section_begin),
6279 (unsigned long) (next - section_begin), section->name);
6285 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6286 (start, finish, pointer_size, offset, base_address);
6290 free (range_entries);
6295 typedef struct Frame_Chunk
6297 struct Frame_Chunk *next;
6298 unsigned char *chunk_start;
6300 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6301 short int *col_type;
6304 unsigned int code_factor;
6309 dwarf_vma cfa_offset;
6311 unsigned char fde_encoding;
6312 unsigned char cfa_exp;
6313 unsigned char ptr_size;
6314 unsigned char segment_size;
6318 static const char *const *dwarf_regnames;
6319 static unsigned int dwarf_regnames_count;
6321 /* A marker for a col_type that means this column was never referenced
6322 in the frame info. */
6323 #define DW_CFA_unreferenced (-1)
6325 /* Return 0 if no more space is needed, 1 if more space is needed,
6326 -1 for invalid reg. */
6329 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6331 unsigned int prev = fc->ncols;
6333 if (reg < (unsigned int) fc->ncols)
6336 if (dwarf_regnames_count
6337 && reg > dwarf_regnames_count)
6340 fc->ncols = reg + 1;
6341 /* PR 17512: file: 10450-2643-0.004.
6342 If reg == -1 then this can happen... */
6346 /* PR 17512: file: 2844a11d. */
6347 if (fc->ncols > 1024)
6349 error (_("Unfeasibly large register number: %u\n"), reg);
6351 /* FIXME: 1024 is an arbitrary limit. Increase it if
6352 we ever encounter a valid binary that exceeds it. */
6356 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6357 sizeof (short int));
6358 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6359 /* PR 17512: file:002-10025-0.005. */
6360 if (fc->col_type == NULL || fc->col_offset == NULL)
6362 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6368 while (prev < fc->ncols)
6370 fc->col_type[prev] = DW_CFA_unreferenced;
6371 fc->col_offset[prev] = 0;
6377 static const char *const dwarf_regnames_i386[] =
6379 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6380 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6381 "eip", "eflags", NULL, /* 8 - 10 */
6382 "st0", "st1", "st2", "st3", /* 11 - 14 */
6383 "st4", "st5", "st6", "st7", /* 15 - 18 */
6384 NULL, NULL, /* 19 - 20 */
6385 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6386 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6387 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6388 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6389 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6390 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6391 "tr", "ldtr", /* 48 - 49 */
6392 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6393 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6394 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6395 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6396 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6397 NULL, NULL, NULL, /* 90 - 92 */
6398 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6401 static const char *const dwarf_regnames_iamcu[] =
6403 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6404 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6405 "eip", "eflags", NULL, /* 8 - 10 */
6406 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6407 NULL, NULL, /* 19 - 20 */
6408 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6409 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6410 NULL, NULL, NULL, /* 37 - 39 */
6411 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6412 "tr", "ldtr", /* 48 - 49 */
6413 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6414 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6415 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6416 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6417 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6418 NULL, NULL, NULL, /* 90 - 92 */
6419 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6423 init_dwarf_regnames_i386 (void)
6425 dwarf_regnames = dwarf_regnames_i386;
6426 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6430 init_dwarf_regnames_iamcu (void)
6432 dwarf_regnames = dwarf_regnames_iamcu;
6433 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6436 static const char *const dwarf_regnames_x86_64[] =
6438 "rax", "rdx", "rcx", "rbx",
6439 "rsi", "rdi", "rbp", "rsp",
6440 "r8", "r9", "r10", "r11",
6441 "r12", "r13", "r14", "r15",
6443 "xmm0", "xmm1", "xmm2", "xmm3",
6444 "xmm4", "xmm5", "xmm6", "xmm7",
6445 "xmm8", "xmm9", "xmm10", "xmm11",
6446 "xmm12", "xmm13", "xmm14", "xmm15",
6447 "st0", "st1", "st2", "st3",
6448 "st4", "st5", "st6", "st7",
6449 "mm0", "mm1", "mm2", "mm3",
6450 "mm4", "mm5", "mm6", "mm7",
6452 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6453 "fs.base", "gs.base", NULL, NULL,
6455 "mxcsr", "fcw", "fsw",
6456 "xmm16", "xmm17", "xmm18", "xmm19",
6457 "xmm20", "xmm21", "xmm22", "xmm23",
6458 "xmm24", "xmm25", "xmm26", "xmm27",
6459 "xmm28", "xmm29", "xmm30", "xmm31",
6460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6464 NULL, NULL, NULL, /* 115 - 117 */
6465 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6469 init_dwarf_regnames_x86_64 (void)
6471 dwarf_regnames = dwarf_regnames_x86_64;
6472 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6475 static const char *const dwarf_regnames_aarch64[] =
6477 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6478 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6479 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6480 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6481 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6482 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6483 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6484 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6485 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6486 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6487 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6488 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6492 init_dwarf_regnames_aarch64 (void)
6494 dwarf_regnames = dwarf_regnames_aarch64;
6495 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6498 static const char *const dwarf_regnames_s390[] =
6500 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6501 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6502 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6503 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6504 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6505 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6506 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6507 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6508 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6511 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6512 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6516 init_dwarf_regnames_s390 (void)
6518 dwarf_regnames = dwarf_regnames_s390;
6519 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6523 init_dwarf_regnames (unsigned int e_machine)
6528 init_dwarf_regnames_i386 ();
6532 init_dwarf_regnames_iamcu ();
6538 init_dwarf_regnames_x86_64 ();
6542 init_dwarf_regnames_aarch64 ();
6546 init_dwarf_regnames_s390 ();
6555 regname (unsigned int regno, int row)
6557 static char reg[64];
6560 && regno < dwarf_regnames_count
6561 && dwarf_regnames [regno] != NULL)
6564 return dwarf_regnames [regno];
6565 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6566 dwarf_regnames [regno]);
6569 snprintf (reg, sizeof (reg), "r%d", regno);
6574 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6579 if (*max_regs != fc->ncols)
6580 *max_regs = fc->ncols;
6582 if (*need_col_headers)
6584 static const char *sloc = " LOC";
6586 *need_col_headers = 0;
6588 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6590 for (r = 0; r < *max_regs; r++)
6591 if (fc->col_type[r] != DW_CFA_unreferenced)
6596 printf ("%-5s ", regname (r, 1));
6602 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6604 strcpy (tmp, "exp");
6606 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6607 printf ("%-8s ", tmp);
6609 for (r = 0; r < fc->ncols; r++)
6611 if (fc->col_type[r] != DW_CFA_unreferenced)
6613 switch (fc->col_type[r])
6615 case DW_CFA_undefined:
6618 case DW_CFA_same_value:
6622 sprintf (tmp, "c%+d", fc->col_offset[r]);
6624 case DW_CFA_val_offset:
6625 sprintf (tmp, "v%+d", fc->col_offset[r]);
6627 case DW_CFA_register:
6628 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6630 case DW_CFA_expression:
6631 strcpy (tmp, "exp");
6633 case DW_CFA_val_expression:
6634 strcpy (tmp, "vexp");
6637 strcpy (tmp, "n/a");
6640 printf ("%-5s ", tmp);
6646 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6648 static unsigned char *
6649 read_cie (unsigned char *start, unsigned char *end,
6650 Frame_Chunk **p_cie, int *p_version,
6651 unsigned long *p_aug_len, unsigned char **p_aug)
6655 unsigned int length_return;
6656 unsigned char *augmentation_data = NULL;
6657 unsigned long augmentation_data_len = 0;
6660 /* PR 17512: file: 001-228113-0.004. */
6664 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6665 memset (fc, 0, sizeof (Frame_Chunk));
6667 fc->col_type = (short int *) xmalloc (sizeof (short int));
6668 fc->col_offset = (int *) xmalloc (sizeof (int));
6672 fc->augmentation = (char *) start;
6673 /* PR 17512: file: 001-228113-0.004.
6674 Skip past augmentation name, but avoid running off the end of the data. */
6676 if (* start ++ == '\0')
6680 warn (_("No terminator for augmentation name\n"));
6684 if (strcmp (fc->augmentation, "eh") == 0)
6685 start += eh_addr_size;
6689 GET (fc->ptr_size, 1);
6690 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6692 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6696 GET (fc->segment_size, 1);
6697 /* PR 17512: file: e99d2804. */
6698 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6700 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6704 eh_addr_size = fc->ptr_size;
6708 fc->ptr_size = eh_addr_size;
6709 fc->segment_size = 0;
6711 READ_ULEB (fc->code_factor);
6712 READ_SLEB (fc->data_factor);
6722 if (fc->augmentation[0] == 'z')
6724 READ_ULEB (augmentation_data_len);
6725 augmentation_data = start;
6726 start += augmentation_data_len;
6727 /* PR 17512: file: 11042-2589-0.004. */
6730 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
6731 augmentation_data_len, (long)((end - start) + augmentation_data_len));
6736 if (augmentation_data_len)
6740 unsigned char *qend;
6742 p = (unsigned char *) fc->augmentation + 1;
6743 q = augmentation_data;
6744 qend = q + augmentation_data_len;
6746 /* PR 17531: file: 015adfaa. */
6749 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
6750 augmentation_data_len = 0;
6753 while (p < end && q < augmentation_data + augmentation_data_len)
6758 q += 1 + size_of_encoded_value (*q);
6760 fc->fde_encoding = *q++;
6767 /* Note - it is OK if this loop terminates with q < qend.
6768 Padding may have been inserted to align the end of the CIE. */
6773 *p_version = version;
6776 *p_aug_len = augmentation_data_len;
6777 *p_aug = augmentation_data;
6783 display_debug_frames (struct dwarf_section *section,
6784 void *file ATTRIBUTE_UNUSED)
6786 unsigned char *start = section->start;
6787 unsigned char *end = start + section->size;
6788 unsigned char *section_start = start;
6789 Frame_Chunk *chunks = 0, *forward_refs = 0;
6790 Frame_Chunk *remembered_state = 0;
6792 int is_eh = strcmp (section->name, ".eh_frame") == 0;
6793 unsigned int length_return;
6794 unsigned int max_regs = 0;
6795 const char *bad_reg = _("bad register: ");
6796 unsigned int saved_eh_addr_size = eh_addr_size;
6798 printf (_("Contents of the %s section:\n"), section->name);
6802 unsigned char *saved_start;
6803 unsigned char *block_end;
6808 int need_col_headers = 1;
6809 unsigned char *augmentation_data = NULL;
6810 unsigned long augmentation_data_len = 0;
6811 unsigned int encoded_ptr_size = saved_eh_addr_size;
6812 unsigned int offset_size;
6813 unsigned int initial_length_size;
6814 bfd_boolean all_nops;
6816 saved_start = start;
6818 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
6822 printf ("\n%08lx ZERO terminator\n\n",
6823 (unsigned long)(saved_start - section_start));
6824 /* Skip any zero terminators that directly follow.
6825 A corrupt section size could have loaded a whole
6826 slew of zero filled memory bytes. eg
6827 PR 17512: file: 070-19381-0.004. */
6828 while (start < end && * start == 0)
6833 if (length == 0xffffffff)
6835 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
6837 initial_length_size = 12;
6842 initial_length_size = 4;
6845 block_end = saved_start + length + initial_length_size;
6846 if (block_end > end || block_end < start)
6848 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6849 dwarf_vmatoa_1 (NULL, length, offset_size),
6850 (unsigned long) (saved_start - section_start));
6854 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
6856 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
6857 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
6862 start = read_cie (start, end, &cie, &version,
6863 &augmentation_data_len, &augmentation_data);
6864 /* PR 17512: file: 027-135133-0.005. */
6871 fc->chunk_start = saved_start;
6872 mreg = max_regs > 0 ? max_regs - 1 : 0;
6875 if (frame_need_space (fc, mreg) < 0)
6877 if (fc->fde_encoding)
6878 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6880 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
6881 print_dwarf_vma (length, fc->ptr_size);
6882 print_dwarf_vma (cie_id, offset_size);
6884 if (do_debug_frames_interp)
6886 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
6887 fc->code_factor, fc->data_factor, fc->ra);
6892 printf (" Version: %d\n", version);
6893 printf (" Augmentation: \"%s\"\n", fc->augmentation);
6896 printf (" Pointer Size: %u\n", fc->ptr_size);
6897 printf (" Segment Size: %u\n", fc->segment_size);
6899 printf (" Code alignment factor: %u\n", fc->code_factor);
6900 printf (" Data alignment factor: %d\n", fc->data_factor);
6901 printf (" Return address column: %d\n", fc->ra);
6903 if (augmentation_data_len)
6907 printf (" Augmentation data: ");
6908 for (i = 0; i < augmentation_data_len; ++i)
6909 /* FIXME: If do_wide is FALSE, then we should
6910 add carriage returns at 80 columns... */
6911 printf (" %02x", augmentation_data[i]);
6919 unsigned char *look_for;
6920 static Frame_Chunk fde_fc;
6921 unsigned long segment_selector;
6925 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
6926 look_for = start - 4 - ((cie_id ^ sign) - sign);
6929 look_for = section_start + cie_id;
6931 if (look_for <= saved_start)
6933 for (cie = chunks; cie ; cie = cie->next)
6934 if (cie->chunk_start == look_for)
6939 for (cie = forward_refs; cie ; cie = cie->next)
6940 if (cie->chunk_start == look_for)
6944 unsigned int off_size;
6945 unsigned char *cie_scan;
6947 cie_scan = look_for;
6949 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
6950 if (length == 0xffffffff)
6952 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
6959 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
6962 : ((off_size == 4 && c_id == DW_CIE_ID)
6963 || (off_size == 8 && c_id == DW64_CIE_ID)))
6968 read_cie (cie_scan, end, &cie, &version,
6969 &augmentation_data_len, &augmentation_data);
6970 /* PR 17512: file: 3450-2098-0.004. */
6973 warn (_("Failed to read CIE information\n"));
6976 cie->next = forward_refs;
6978 cie->chunk_start = look_for;
6979 mreg = max_regs > 0 ? max_regs - 1 : 0;
6982 if (frame_need_space (cie, mreg) < 0)
6984 warn (_("Invalid max register\n"));
6987 if (cie->fde_encoding)
6989 = size_of_encoded_value (cie->fde_encoding);
6996 memset (fc, 0, sizeof (Frame_Chunk));
7000 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7001 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7002 (unsigned long) (saved_start - section_start));
7004 fc->col_type = (short int *) xmalloc (sizeof (short int));
7005 fc->col_offset = (int *) xmalloc (sizeof (int));
7006 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7008 warn (_("Invalid max register\n"));
7012 fc->augmentation = "";
7013 fc->fde_encoding = 0;
7014 fc->ptr_size = eh_addr_size;
7015 fc->segment_size = 0;
7019 fc->ncols = cie->ncols;
7020 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7021 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
7022 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7023 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7024 fc->augmentation = cie->augmentation;
7025 fc->ptr_size = cie->ptr_size;
7026 eh_addr_size = cie->ptr_size;
7027 fc->segment_size = cie->segment_size;
7028 fc->code_factor = cie->code_factor;
7029 fc->data_factor = cie->data_factor;
7030 fc->cfa_reg = cie->cfa_reg;
7031 fc->cfa_offset = cie->cfa_offset;
7033 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7035 warn (_("Invalid max register\n"));
7038 fc->fde_encoding = cie->fde_encoding;
7041 if (fc->fde_encoding)
7042 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7044 segment_selector = 0;
7045 if (fc->segment_size)
7047 if (fc->segment_size > sizeof (segment_selector))
7049 /* PR 17512: file: 9e196b3e. */
7050 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7051 fc->segment_size = 4;
7053 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7056 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
7058 /* FIXME: It appears that sometimes the final pc_range value is
7059 encoded in less than encoded_ptr_size bytes. See the x86_64
7060 run of the "objcopy on compressed debug sections" test for an
7062 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
7064 if (cie->augmentation[0] == 'z')
7066 READ_ULEB (augmentation_data_len);
7067 augmentation_data = start;
7068 start += augmentation_data_len;
7069 /* PR 17512: file: 722-8446-0.004. */
7070 if (start >= end || ((signed long) augmentation_data_len) < 0)
7072 warn (_("Corrupt augmentation data length: %lx\n"),
7073 augmentation_data_len);
7075 augmentation_data = NULL;
7076 augmentation_data_len = 0;
7080 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7081 (unsigned long)(saved_start - section_start),
7082 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7083 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7084 (unsigned long)(cie->chunk_start - section_start));
7086 if (fc->segment_size)
7087 printf ("%04lx:", segment_selector);
7090 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7091 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7093 if (! do_debug_frames_interp && augmentation_data_len)
7097 printf (" Augmentation data: ");
7098 for (i = 0; i < augmentation_data_len; ++i)
7099 printf (" %02x", augmentation_data[i]);
7105 /* At this point, fc is the current chunk, cie (if any) is set, and
7106 we're about to interpret instructions for the chunk. */
7107 /* ??? At present we need to do this always, since this sizes the
7108 fc->col_type and fc->col_offset arrays, which we write into always.
7109 We should probably split the interpreted and non-interpreted bits
7110 into two different routines, since there's so much that doesn't
7111 really overlap between them. */
7112 if (1 || do_debug_frames_interp)
7114 /* Start by making a pass over the chunk, allocating storage
7115 and taking note of what registers are used. */
7116 unsigned char *tmp = start;
7118 while (start < block_end)
7120 unsigned int reg, op, opa;
7122 unsigned char * new_start;
7129 /* Warning: if you add any more cases to this switch, be
7130 sure to add them to the corresponding switch below. */
7133 case DW_CFA_advance_loc:
7137 if (frame_need_space (fc, opa) >= 0)
7138 fc->col_type[opa] = DW_CFA_undefined;
7140 case DW_CFA_restore:
7141 if (frame_need_space (fc, opa) >= 0)
7142 fc->col_type[opa] = DW_CFA_undefined;
7144 case DW_CFA_set_loc:
7145 start += encoded_ptr_size;
7147 case DW_CFA_advance_loc1:
7150 case DW_CFA_advance_loc2:
7153 case DW_CFA_advance_loc4:
7156 case DW_CFA_offset_extended:
7157 case DW_CFA_val_offset:
7160 if (frame_need_space (fc, reg) >= 0)
7161 fc->col_type[reg] = DW_CFA_undefined;
7163 case DW_CFA_restore_extended:
7165 if (frame_need_space (fc, reg) >= 0)
7166 fc->col_type[reg] = DW_CFA_undefined;
7168 case DW_CFA_undefined:
7170 if (frame_need_space (fc, reg) >= 0)
7171 fc->col_type[reg] = DW_CFA_undefined;
7173 case DW_CFA_same_value:
7175 if (frame_need_space (fc, reg) >= 0)
7176 fc->col_type[reg] = DW_CFA_undefined;
7178 case DW_CFA_register:
7181 if (frame_need_space (fc, reg) >= 0)
7182 fc->col_type[reg] = DW_CFA_undefined;
7184 case DW_CFA_def_cfa:
7188 case DW_CFA_def_cfa_register:
7191 case DW_CFA_def_cfa_offset:
7194 case DW_CFA_def_cfa_expression:
7196 new_start = start + temp;
7197 if (new_start < start)
7199 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7205 case DW_CFA_expression:
7206 case DW_CFA_val_expression:
7209 new_start = start + temp;
7210 if (new_start < start)
7212 /* PR 17512: file:306-192417-0.005. */
7213 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7218 if (frame_need_space (fc, reg) >= 0)
7219 fc->col_type[reg] = DW_CFA_undefined;
7221 case DW_CFA_offset_extended_sf:
7222 case DW_CFA_val_offset_sf:
7225 if (frame_need_space (fc, reg) >= 0)
7226 fc->col_type[reg] = DW_CFA_undefined;
7228 case DW_CFA_def_cfa_sf:
7232 case DW_CFA_def_cfa_offset_sf:
7235 case DW_CFA_MIPS_advance_loc8:
7238 case DW_CFA_GNU_args_size:
7241 case DW_CFA_GNU_negative_offset_extended:
7244 if (frame_need_space (fc, reg) >= 0)
7245 fc->col_type[reg] = DW_CFA_undefined;
7256 /* Now we know what registers are used, make a second pass over
7257 the chunk, this time actually printing out the info. */
7259 while (start < block_end)
7261 unsigned char * tmp;
7263 unsigned long ul, roffs;
7264 /* Note: It is tempting to use an unsigned long for 'reg' but there
7265 are various functions, notably frame_space_needed() that assume that
7266 reg is an unsigned int. */
7271 const char *reg_prefix = "";
7278 /* Make a note if something other than DW_CFA_nop happens. */
7279 if (op != DW_CFA_nop)
7282 /* Warning: if you add any more cases to this switch, be
7283 sure to add them to the corresponding switch above. */
7286 case DW_CFA_advance_loc:
7287 if (do_debug_frames_interp)
7288 frame_display_row (fc, &need_col_headers, &max_regs);
7290 printf (" DW_CFA_advance_loc: %d to %s\n",
7291 opa * fc->code_factor,
7292 dwarf_vmatoa_1 (NULL,
7293 fc->pc_begin + opa * fc->code_factor,
7295 fc->pc_begin += opa * fc->code_factor;
7300 if (opa >= (unsigned int) fc->ncols)
7301 reg_prefix = bad_reg;
7302 if (! do_debug_frames_interp || *reg_prefix != '\0')
7303 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7304 reg_prefix, regname (opa, 0),
7305 roffs * fc->data_factor);
7306 if (*reg_prefix == '\0')
7308 fc->col_type[opa] = DW_CFA_offset;
7309 fc->col_offset[opa] = roffs * fc->data_factor;
7313 case DW_CFA_restore:
7314 if (opa >= (unsigned int) fc->ncols)
7315 reg_prefix = bad_reg;
7316 if (! do_debug_frames_interp || *reg_prefix != '\0')
7317 printf (" DW_CFA_restore: %s%s\n",
7318 reg_prefix, regname (opa, 0));
7319 if (*reg_prefix != '\0')
7322 if (opa >= (unsigned int) cie->ncols
7323 || (do_debug_frames_interp
7324 && cie->col_type[opa] == DW_CFA_unreferenced))
7326 fc->col_type[opa] = DW_CFA_undefined;
7327 fc->col_offset[opa] = 0;
7331 fc->col_type[opa] = cie->col_type[opa];
7332 fc->col_offset[opa] = cie->col_offset[opa];
7336 case DW_CFA_set_loc:
7337 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7338 if (do_debug_frames_interp)
7339 frame_display_row (fc, &need_col_headers, &max_regs);
7341 printf (" DW_CFA_set_loc: %s\n",
7342 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7346 case DW_CFA_advance_loc1:
7347 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7348 if (do_debug_frames_interp)
7349 frame_display_row (fc, &need_col_headers, &max_regs);
7351 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7352 (unsigned long) (ofs * fc->code_factor),
7353 dwarf_vmatoa_1 (NULL,
7354 fc->pc_begin + ofs * fc->code_factor,
7356 fc->pc_begin += ofs * fc->code_factor;
7359 case DW_CFA_advance_loc2:
7360 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7361 if (do_debug_frames_interp)
7362 frame_display_row (fc, &need_col_headers, &max_regs);
7364 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7365 (unsigned long) (ofs * fc->code_factor),
7366 dwarf_vmatoa_1 (NULL,
7367 fc->pc_begin + ofs * fc->code_factor,
7369 fc->pc_begin += ofs * fc->code_factor;
7372 case DW_CFA_advance_loc4:
7373 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7374 if (do_debug_frames_interp)
7375 frame_display_row (fc, &need_col_headers, &max_regs);
7377 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7378 (unsigned long) (ofs * fc->code_factor),
7379 dwarf_vmatoa_1 (NULL,
7380 fc->pc_begin + ofs * fc->code_factor,
7382 fc->pc_begin += ofs * fc->code_factor;
7385 case DW_CFA_offset_extended:
7388 if (reg >= (unsigned int) fc->ncols)
7389 reg_prefix = bad_reg;
7390 if (! do_debug_frames_interp || *reg_prefix != '\0')
7391 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7392 reg_prefix, regname (reg, 0),
7393 roffs * fc->data_factor);
7394 if (*reg_prefix == '\0')
7396 fc->col_type[reg] = DW_CFA_offset;
7397 fc->col_offset[reg] = roffs * fc->data_factor;
7401 case DW_CFA_val_offset:
7404 if (reg >= (unsigned int) fc->ncols)
7405 reg_prefix = bad_reg;
7406 if (! do_debug_frames_interp || *reg_prefix != '\0')
7407 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7408 reg_prefix, regname (reg, 0),
7409 roffs * fc->data_factor);
7410 if (*reg_prefix == '\0')
7412 fc->col_type[reg] = DW_CFA_val_offset;
7413 fc->col_offset[reg] = roffs * fc->data_factor;
7417 case DW_CFA_restore_extended:
7419 if (reg >= (unsigned int) fc->ncols)
7420 reg_prefix = bad_reg;
7421 if (! do_debug_frames_interp || *reg_prefix != '\0')
7422 printf (" DW_CFA_restore_extended: %s%s\n",
7423 reg_prefix, regname (reg, 0));
7424 if (*reg_prefix != '\0')
7427 if (reg >= (unsigned int) cie->ncols)
7429 fc->col_type[reg] = DW_CFA_undefined;
7430 fc->col_offset[reg] = 0;
7434 fc->col_type[reg] = cie->col_type[reg];
7435 fc->col_offset[reg] = cie->col_offset[reg];
7439 case DW_CFA_undefined:
7441 if (reg >= (unsigned int) fc->ncols)
7442 reg_prefix = bad_reg;
7443 if (! do_debug_frames_interp || *reg_prefix != '\0')
7444 printf (" DW_CFA_undefined: %s%s\n",
7445 reg_prefix, regname (reg, 0));
7446 if (*reg_prefix == '\0')
7448 fc->col_type[reg] = DW_CFA_undefined;
7449 fc->col_offset[reg] = 0;
7453 case DW_CFA_same_value:
7455 if (reg >= (unsigned int) fc->ncols)
7456 reg_prefix = bad_reg;
7457 if (! do_debug_frames_interp || *reg_prefix != '\0')
7458 printf (" DW_CFA_same_value: %s%s\n",
7459 reg_prefix, regname (reg, 0));
7460 if (*reg_prefix == '\0')
7462 fc->col_type[reg] = DW_CFA_same_value;
7463 fc->col_offset[reg] = 0;
7467 case DW_CFA_register:
7470 if (reg >= (unsigned int) fc->ncols)
7471 reg_prefix = bad_reg;
7472 if (! do_debug_frames_interp || *reg_prefix != '\0')
7474 printf (" DW_CFA_register: %s%s in ",
7475 reg_prefix, regname (reg, 0));
7476 puts (regname (roffs, 0));
7478 if (*reg_prefix == '\0')
7480 fc->col_type[reg] = DW_CFA_register;
7481 fc->col_offset[reg] = roffs;
7485 case DW_CFA_remember_state:
7486 if (! do_debug_frames_interp)
7487 printf (" DW_CFA_remember_state\n");
7488 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7489 rs->cfa_offset = fc->cfa_offset;
7490 rs->cfa_reg = fc->cfa_reg;
7492 rs->cfa_exp = fc->cfa_exp;
7493 rs->ncols = fc->ncols;
7494 rs->col_type = (short int *) xcmalloc (rs->ncols,
7495 sizeof (* rs->col_type));
7496 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7497 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7498 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7499 rs->next = remembered_state;
7500 remembered_state = rs;
7503 case DW_CFA_restore_state:
7504 if (! do_debug_frames_interp)
7505 printf (" DW_CFA_restore_state\n");
7506 rs = remembered_state;
7509 remembered_state = rs->next;
7510 fc->cfa_offset = rs->cfa_offset;
7511 fc->cfa_reg = rs->cfa_reg;
7513 fc->cfa_exp = rs->cfa_exp;
7514 if (frame_need_space (fc, rs->ncols - 1) < 0)
7516 warn (_("Invalid column number in saved frame state\n"));
7520 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7521 memcpy (fc->col_offset, rs->col_offset,
7522 rs->ncols * sizeof (* rs->col_offset));
7523 free (rs->col_type);
7524 free (rs->col_offset);
7527 else if (do_debug_frames_interp)
7528 printf ("Mismatched DW_CFA_restore_state\n");
7531 case DW_CFA_def_cfa:
7532 READ_SLEB (fc->cfa_reg);
7533 READ_ULEB (fc->cfa_offset);
7535 if (! do_debug_frames_interp)
7536 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7537 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7540 case DW_CFA_def_cfa_register:
7541 READ_SLEB (fc->cfa_reg);
7543 if (! do_debug_frames_interp)
7544 printf (" DW_CFA_def_cfa_register: %s\n",
7545 regname (fc->cfa_reg, 0));
7548 case DW_CFA_def_cfa_offset:
7549 READ_ULEB (fc->cfa_offset);
7550 if (! do_debug_frames_interp)
7551 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7555 if (! do_debug_frames_interp)
7556 printf (" DW_CFA_nop\n");
7559 case DW_CFA_def_cfa_expression:
7561 if (start >= block_end || ul > (unsigned long) (block_end - start))
7563 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7566 if (! do_debug_frames_interp)
7568 printf (" DW_CFA_def_cfa_expression (");
7569 decode_location_expression (start, eh_addr_size, 0, -1,
7577 case DW_CFA_expression:
7580 if (reg >= (unsigned int) fc->ncols)
7581 reg_prefix = bad_reg;
7582 /* PR 17512: file: 069-133014-0.006. */
7583 /* PR 17512: file: 98c02eb4. */
7585 if (start >= block_end || tmp > block_end || tmp < start)
7587 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7590 if (! do_debug_frames_interp || *reg_prefix != '\0')
7592 printf (" DW_CFA_expression: %s%s (",
7593 reg_prefix, regname (reg, 0));
7594 decode_location_expression (start, eh_addr_size, 0, -1,
7598 if (*reg_prefix == '\0')
7599 fc->col_type[reg] = DW_CFA_expression;
7603 case DW_CFA_val_expression:
7606 if (reg >= (unsigned int) fc->ncols)
7607 reg_prefix = bad_reg;
7609 if (start >= block_end || tmp > block_end || tmp < start)
7611 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7614 if (! do_debug_frames_interp || *reg_prefix != '\0')
7616 printf (" DW_CFA_val_expression: %s%s (",
7617 reg_prefix, regname (reg, 0));
7618 decode_location_expression (start, eh_addr_size, 0, -1,
7622 if (*reg_prefix == '\0')
7623 fc->col_type[reg] = DW_CFA_val_expression;
7627 case DW_CFA_offset_extended_sf:
7630 if (frame_need_space (fc, reg) < 0)
7631 reg_prefix = bad_reg;
7632 if (! do_debug_frames_interp || *reg_prefix != '\0')
7633 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7634 reg_prefix, regname (reg, 0),
7635 (long)(l * fc->data_factor));
7636 if (*reg_prefix == '\0')
7638 fc->col_type[reg] = DW_CFA_offset;
7639 fc->col_offset[reg] = l * fc->data_factor;
7643 case DW_CFA_val_offset_sf:
7646 if (frame_need_space (fc, reg) < 0)
7647 reg_prefix = bad_reg;
7648 if (! do_debug_frames_interp || *reg_prefix != '\0')
7649 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7650 reg_prefix, regname (reg, 0),
7651 (long)(l * fc->data_factor));
7652 if (*reg_prefix == '\0')
7654 fc->col_type[reg] = DW_CFA_val_offset;
7655 fc->col_offset[reg] = l * fc->data_factor;
7659 case DW_CFA_def_cfa_sf:
7660 READ_SLEB (fc->cfa_reg);
7661 READ_ULEB (fc->cfa_offset);
7662 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7664 if (! do_debug_frames_interp)
7665 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7666 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7669 case DW_CFA_def_cfa_offset_sf:
7670 READ_ULEB (fc->cfa_offset);
7671 fc->cfa_offset *= fc->data_factor;
7672 if (! do_debug_frames_interp)
7673 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7676 case DW_CFA_MIPS_advance_loc8:
7677 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7678 if (do_debug_frames_interp)
7679 frame_display_row (fc, &need_col_headers, &max_regs);
7681 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7682 (unsigned long) (ofs * fc->code_factor),
7683 dwarf_vmatoa_1 (NULL,
7684 fc->pc_begin + ofs * fc->code_factor,
7686 fc->pc_begin += ofs * fc->code_factor;
7689 case DW_CFA_GNU_window_save:
7690 if (! do_debug_frames_interp)
7691 printf (" DW_CFA_GNU_window_save\n");
7694 case DW_CFA_GNU_args_size:
7696 if (! do_debug_frames_interp)
7697 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7700 case DW_CFA_GNU_negative_offset_extended:
7704 if (frame_need_space (fc, reg) < 0)
7705 reg_prefix = bad_reg;
7706 if (! do_debug_frames_interp || *reg_prefix != '\0')
7707 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7708 reg_prefix, regname (reg, 0),
7709 (long)(l * fc->data_factor));
7710 if (*reg_prefix == '\0')
7712 fc->col_type[reg] = DW_CFA_offset;
7713 fc->col_offset[reg] = l * fc->data_factor;
7718 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7719 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7721 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7726 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7727 if (do_debug_frames_interp && ! all_nops)
7728 frame_display_row (fc, &need_col_headers, &max_regs);
7731 eh_addr_size = saved_eh_addr_size;
7742 display_debug_names (struct dwarf_section *section, void *file)
7744 unsigned char *hdrptr = section->start;
7745 dwarf_vma unit_length;
7746 unsigned char *unit_start;
7747 const unsigned char *const section_end = section->start + section->size;
7748 unsigned char *unit_end;
7750 printf (_("Contents of the %s section:\n"), section->name);
7752 load_debug_section (str, file);
7754 for (; hdrptr < section_end; hdrptr = unit_end)
7756 unsigned int offset_size;
7757 uint16_t dwarf_version, padding;
7758 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
7759 uint32_t bucket_count, name_count, abbrev_table_size;
7760 uint32_t augmentation_string_size;
7763 unit_start = hdrptr;
7765 /* Get and check the length of the block. */
7766 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
7768 if (unit_length == 0xffffffff)
7770 /* This section is 64-bit DWARF. */
7771 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
7776 unit_end = hdrptr + unit_length;
7778 if ((hdrptr - section->start) + unit_length > section->size)
7780 warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names "
7781 "header is wrong - the section is too small\n"),
7782 (long) unit_length, (long) (unit_start - section->start));
7786 /* Get and check the version number. */
7787 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
7788 printf (_("Version %ld\n"), (long) dwarf_version);
7790 /* Prior versions did not exist, and future versions may not be
7791 backwards compatible. */
7792 if (dwarf_version != 5)
7794 warn (_("Only DWARF version 5 .debug_names "
7795 "is currently supported.\n"));
7799 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
7801 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
7804 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
7805 if (comp_unit_count == 0)
7806 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
7808 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
7809 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
7810 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
7811 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
7812 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
7814 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
7815 if (augmentation_string_size % 4 != 0)
7817 warn (_("Augmentation string length %u must be rounded up "
7818 "to a multiple of 4 in .debug_names.\n"),
7819 augmentation_string_size);
7820 augmentation_string_size += (-augmentation_string_size) & 3;
7822 printf (_("Augmentation string:"));
7823 for (i = 0; i < augmentation_string_size; i++)
7827 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
7828 printf (" %02x", uc);
7833 printf (_("CU table:\n"));
7834 for (i = 0; i < comp_unit_count; i++)
7838 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
7839 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
7843 printf (_("TU table:\n"));
7844 for (i = 0; i < local_type_unit_count; i++)
7848 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
7849 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
7853 printf (_("Foreign TU table:\n"));
7854 for (i = 0; i < foreign_type_unit_count; i++)
7858 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
7859 printf (_("[%3u] "), i);
7860 print_dwarf_vma (signature, 8);
7865 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
7866 hdrptr += bucket_count * sizeof (uint32_t);
7867 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
7868 hdrptr += name_count * sizeof (uint32_t);
7869 unsigned char *const name_table_string_offsets = hdrptr;
7870 hdrptr += name_count * offset_size;
7871 unsigned char *const name_table_entry_offsets = hdrptr;
7872 hdrptr += name_count * offset_size;
7873 unsigned char *const abbrev_table = hdrptr;
7874 hdrptr += abbrev_table_size;
7875 const unsigned char *const abbrev_table_end = hdrptr;
7876 unsigned char *const entry_pool = hdrptr;
7877 if (hdrptr > unit_end)
7879 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
7880 "for unit 0x%lx in the debug_names\n"),
7881 (long) (hdrptr - section->start),
7882 (long) (unit_end - section->start),
7883 (long) (unit_start - section->start));
7887 size_t buckets_filled = 0;
7889 for (bucketi = 0; bucketi < bucket_count; bucketi++)
7891 const uint32_t bucket = hash_table_buckets[bucketi];
7896 printf (_("Used %zu of %lu buckets.\n"), buckets_filled,
7897 (unsigned long) bucket_count);
7899 uint32_t hash_prev = 0;
7900 size_t hash_clash_count = 0;
7901 size_t longest_clash = 0;
7902 size_t this_length = 0;
7904 for (hashi = 0; hashi < name_count; hashi++)
7906 const uint32_t hash_this = hash_table_hashes[hashi];
7910 if (hash_prev % bucket_count == hash_this % bucket_count)
7914 longest_clash = MAX (longest_clash, this_length);
7919 hash_prev = hash_this;
7921 printf (_("Out of %lu items there are %zu bucket clashes"
7922 " (longest of %zu entries).\n"),
7923 (unsigned long) name_count, hash_clash_count, longest_clash);
7924 assert (name_count == buckets_filled + hash_clash_count);
7926 struct abbrev_lookup_entry
7928 dwarf_vma abbrev_tag;
7929 unsigned char *abbrev_lookup_ptr;
7931 struct abbrev_lookup_entry *abbrev_lookup = NULL;
7932 size_t abbrev_lookup_used = 0;
7933 size_t abbrev_lookup_allocated = 0;
7935 unsigned char *abbrevptr = abbrev_table;
7938 unsigned int bytes_read;
7939 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
7941 abbrevptr += bytes_read;
7942 if (abbrev_tag == 0)
7944 if (abbrev_lookup_used == abbrev_lookup_allocated)
7946 abbrev_lookup_allocated = MAX (0x100,
7947 abbrev_lookup_allocated * 2);
7948 abbrev_lookup = xrealloc (abbrev_lookup,
7949 (abbrev_lookup_allocated
7950 * sizeof (*abbrev_lookup)));
7952 assert (abbrev_lookup_used < abbrev_lookup_allocated);
7953 struct abbrev_lookup_entry *entry;
7954 for (entry = abbrev_lookup;
7955 entry < abbrev_lookup + abbrev_lookup_used;
7957 if (entry->abbrev_tag == abbrev_tag)
7959 warn (_("Duplicate abbreviation tag %lu "
7960 "in unit 0x%lx in the debug_names\n"),
7961 (long) abbrev_tag, (long) (unit_start - section->start));
7964 entry = &abbrev_lookup[abbrev_lookup_used++];
7965 entry->abbrev_tag = abbrev_tag;
7966 entry->abbrev_lookup_ptr = abbrevptr;
7968 /* Skip DWARF tag. */
7969 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
7970 abbrevptr += bytes_read;
7973 const dwarf_vma xindex = read_uleb128 (abbrevptr,
7976 abbrevptr += bytes_read;
7977 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
7979 abbrevptr += bytes_read;
7980 if (xindex == 0 && form == 0)
7985 printf (_("\nSymbol table:\n"));
7987 for (namei = 0; namei < name_count; ++namei)
7989 uint64_t string_offset, entry_offset;
7991 SAFE_BYTE_GET (string_offset,
7992 name_table_string_offsets + namei * offset_size,
7993 offset_size, unit_end);
7994 SAFE_BYTE_GET (entry_offset,
7995 name_table_entry_offsets + namei * offset_size,
7996 offset_size, unit_end);
7998 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
7999 fetch_indirect_string (string_offset));
8001 unsigned char *entryptr = entry_pool + entry_offset;
8003 // We need to scan first whether there is a single or multiple
8004 // entries. TAGNO is -2 for the first entry, it is -1 for the
8005 // initial tag read of the second entry, then it becomes 0 for the
8006 // first entry for real printing etc.
8008 /* Initialize it due to a false compiler warning. */
8009 dwarf_vma second_abbrev_tag = -1;
8012 unsigned int bytes_read;
8013 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8015 entryptr += bytes_read;
8018 second_abbrev_tag = abbrev_tag;
8020 entryptr = entry_pool + entry_offset;
8023 if (abbrev_tag == 0)
8027 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8028 (unsigned long) abbrev_tag);
8030 const struct abbrev_lookup_entry *entry;
8031 for (entry = abbrev_lookup;
8032 entry < abbrev_lookup + abbrev_lookup_used;
8034 if (entry->abbrev_tag == abbrev_tag)
8036 if (entry >= abbrev_lookup + abbrev_lookup_used)
8038 warn (_("Undefined abbreviation tag %lu "
8039 "in unit 0x%lx in the debug_names\n"),
8041 (long) (unit_start - section->start));
8044 abbrevptr = entry->abbrev_lookup_ptr;
8045 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8047 abbrevptr += bytes_read;
8049 printf (" %s", get_TAG_name (dwarf_tag));
8052 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8055 abbrevptr += bytes_read;
8056 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8058 abbrevptr += bytes_read;
8059 if (xindex == 0 && form == 0)
8063 printf (" %s", get_IDX_name (xindex));
8064 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8067 dwarf_version, NULL,
8074 printf (_(" <no entries>"));
8078 free (abbrev_lookup);
8085 display_gdb_index (struct dwarf_section *section,
8086 void *file ATTRIBUTE_UNUSED)
8088 unsigned char *start = section->start;
8090 uint32_t cu_list_offset, tu_list_offset;
8091 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8092 unsigned int cu_list_elements, tu_list_elements;
8093 unsigned int address_table_size, symbol_table_slots;
8094 unsigned char *cu_list, *tu_list;
8095 unsigned char *address_table, *symbol_table, *constant_pool;
8098 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8100 printf (_("Contents of the %s section:\n"), section->name);
8102 if (section->size < 6 * sizeof (uint32_t))
8104 warn (_("Truncated header in the %s section.\n"), section->name);
8108 version = byte_get_little_endian (start, 4);
8109 printf (_("Version %ld\n"), (long) version);
8111 /* Prior versions are obsolete, and future versions may not be
8112 backwards compatible. */
8113 if (version < 3 || version > 8)
8115 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8119 warn (_("The address table data in version 3 may be wrong.\n"));
8121 warn (_("Version 4 does not support case insensitive lookups.\n"));
8123 warn (_("Version 5 does not include inlined functions.\n"));
8125 warn (_("Version 6 does not include symbol attributes.\n"));
8126 /* Version 7 indices generated by Gold have bad type unit references,
8127 PR binutils/15021. But we don't know if the index was generated by
8128 Gold or not, so to avoid worrying users with gdb-generated indices
8129 we say nothing for version 7 here. */
8131 cu_list_offset = byte_get_little_endian (start + 4, 4);
8132 tu_list_offset = byte_get_little_endian (start + 8, 4);
8133 address_table_offset = byte_get_little_endian (start + 12, 4);
8134 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8135 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8137 if (cu_list_offset > section->size
8138 || tu_list_offset > section->size
8139 || address_table_offset > section->size
8140 || symbol_table_offset > section->size
8141 || constant_pool_offset > section->size)
8143 warn (_("Corrupt header in the %s section.\n"), section->name);
8147 /* PR 17531: file: 418d0a8a. */
8148 if (tu_list_offset < cu_list_offset)
8150 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8151 tu_list_offset, cu_list_offset);
8155 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8157 if (address_table_offset < tu_list_offset)
8159 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8160 address_table_offset, tu_list_offset);
8164 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8166 /* PR 17531: file: 18a47d3d. */
8167 if (symbol_table_offset < address_table_offset)
8169 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
8170 symbol_table_offset, address_table_offset);
8174 address_table_size = symbol_table_offset - address_table_offset;
8176 if (constant_pool_offset < symbol_table_offset)
8178 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8179 constant_pool_offset, symbol_table_offset);
8183 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8185 cu_list = start + cu_list_offset;
8186 tu_list = start + tu_list_offset;
8187 address_table = start + address_table_offset;
8188 symbol_table = start + symbol_table_offset;
8189 constant_pool = start + constant_pool_offset;
8191 if (address_table + address_table_size > section->start + section->size)
8193 warn (_("Address table extends beyond end of section.\n"));
8197 printf (_("\nCU table:\n"));
8198 for (i = 0; i < cu_list_elements; i += 2)
8200 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8201 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8203 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8204 (unsigned long) cu_offset,
8205 (unsigned long) (cu_offset + cu_length - 1));
8208 printf (_("\nTU table:\n"));
8209 for (i = 0; i < tu_list_elements; i += 3)
8211 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8212 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8213 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8215 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8216 (unsigned long) tu_offset,
8217 (unsigned long) type_offset);
8218 print_dwarf_vma (signature, 8);
8222 printf (_("\nAddress table:\n"));
8223 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8226 uint64_t low = byte_get_little_endian (address_table + i, 8);
8227 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8228 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8230 print_dwarf_vma (low, 8);
8231 print_dwarf_vma (high, 8);
8232 printf (_("%lu\n"), (unsigned long) cu_index);
8235 printf (_("\nSymbol table:\n"));
8236 for (i = 0; i < symbol_table_slots; ++i)
8238 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8239 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8240 uint32_t num_cus, cu;
8242 if (name_offset != 0
8243 || cu_vector_offset != 0)
8246 unsigned char * adr;
8248 adr = constant_pool + name_offset;
8249 /* PR 17531: file: 5b7b07ad. */
8250 if (adr < constant_pool || adr >= section->start + section->size)
8252 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8253 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8257 printf ("[%3u] %.*s:", i,
8258 (int) (section->size - (constant_pool_offset + name_offset)),
8259 constant_pool + name_offset);
8261 adr = constant_pool + cu_vector_offset;
8262 if (adr < constant_pool || adr >= section->start + section->size - 3)
8264 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8265 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8266 cu_vector_offset, i);
8270 num_cus = byte_get_little_endian (adr, 4);
8272 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8273 if (num_cus * 4 < num_cus
8274 || adr >= section->start + section->size
8275 || adr < constant_pool)
8277 printf ("<invalid number of CUs: %d>\n", num_cus);
8278 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8286 for (j = 0; j < num_cus; ++j)
8289 gdb_index_symbol_kind kind;
8291 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8292 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8293 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8294 cu = GDB_INDEX_CU_VALUE (cu);
8295 /* Convert to TU number if it's for a type unit. */
8296 if (cu >= cu_list_elements / 2)
8297 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8298 (unsigned long) (cu - cu_list_elements / 2));
8300 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8302 printf (" [%s, %s]",
8303 is_static ? _("static") : _("global"),
8304 get_gdb_index_symbol_kind_name (kind));
8316 /* Pre-allocate enough space for the CU/TU sets needed. */
8319 prealloc_cu_tu_list (unsigned int nshndx)
8321 if (shndx_pool == NULL)
8323 shndx_pool_size = nshndx;
8324 shndx_pool_used = 0;
8325 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8326 sizeof (unsigned int));
8330 shndx_pool_size = shndx_pool_used + nshndx;
8331 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8332 sizeof (unsigned int));
8337 add_shndx_to_cu_tu_entry (unsigned int shndx)
8339 if (shndx_pool_used >= shndx_pool_size)
8341 error (_("Internal error: out of space in the shndx pool.\n"));
8344 shndx_pool [shndx_pool_used++] = shndx;
8348 end_cu_tu_entry (void)
8350 if (shndx_pool_used >= shndx_pool_size)
8352 error (_("Internal error: out of space in the shndx pool.\n"));
8355 shndx_pool [shndx_pool_used++] = 0;
8358 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8361 get_DW_SECT_short_name (unsigned int dw_sect)
8363 static char buf[16];
8371 case DW_SECT_ABBREV:
8377 case DW_SECT_STR_OFFSETS:
8379 case DW_SECT_MACINFO:
8387 snprintf (buf, sizeof (buf), "%d", dw_sect);
8391 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8392 These sections are extensions for Fission.
8393 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8396 process_cu_tu_index (struct dwarf_section *section, int do_display)
8398 unsigned char *phdr = section->start;
8399 unsigned char *limit = phdr + section->size;
8400 unsigned char *phash;
8401 unsigned char *pindex;
8402 unsigned char *ppool;
8403 unsigned int version;
8404 unsigned int ncols = 0;
8406 unsigned int nslots;
8409 dwarf_vma signature_high;
8410 dwarf_vma signature_low;
8413 /* PR 17512: file: 002-168123-0.004. */
8416 warn (_("Section %s is empty\n"), section->name);
8419 /* PR 17512: file: 002-376-0.004. */
8420 if (section->size < 24)
8422 warn (_("Section %s is too small to contain a CU/TU header\n"),
8427 SAFE_BYTE_GET (version, phdr, 4, limit);
8429 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8430 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8431 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8434 pindex = phash + nslots * 8;
8435 ppool = pindex + nslots * 4;
8437 /* PR 17531: file: 45d69832. */
8438 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
8440 warn (_("Section %s is too small for %d slots\n"),
8441 section->name, nslots);
8447 printf (_("Contents of the %s section:\n\n"), section->name);
8448 printf (_(" Version: %d\n"), version);
8450 printf (_(" Number of columns: %d\n"), ncols);
8451 printf (_(" Number of used entries: %d\n"), nused);
8452 printf (_(" Number of slots: %d\n\n"), nslots);
8455 if (ppool > limit || ppool < phdr)
8457 warn (_("Section %s too small for %d hash table entries\n"),
8458 section->name, nslots);
8465 prealloc_cu_tu_list ((limit - ppool) / 4);
8466 for (i = 0; i < nslots; i++)
8468 unsigned char *shndx_list;
8471 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
8472 if (signature_high != 0 || signature_low != 0)
8474 SAFE_BYTE_GET (j, pindex, 4, limit);
8475 shndx_list = ppool + j * 4;
8476 /* PR 17531: file: 705e010d. */
8477 if (shndx_list < ppool)
8479 warn (_("Section index pool located before start of section\n"));
8484 printf (_(" [%3d] Signature: 0x%s Sections: "),
8485 i, dwarf_vmatoa64 (signature_high, signature_low,
8486 buf, sizeof (buf)));
8489 if (shndx_list >= limit)
8491 warn (_("Section %s too small for shndx pool\n"),
8495 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
8499 printf (" %d", shndx);
8501 add_shndx_to_cu_tu_entry (shndx);
8513 else if (version == 2)
8516 unsigned int dw_sect;
8517 unsigned char *ph = phash;
8518 unsigned char *pi = pindex;
8519 unsigned char *poffsets = ppool + ncols * 4;
8520 unsigned char *psizes = poffsets + nused * ncols * 4;
8521 unsigned char *pend = psizes + nused * ncols * 4;
8522 bfd_boolean is_tu_index;
8523 struct cu_tu_set *this_set = NULL;
8525 unsigned char *prow;
8527 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8529 /* PR 17531: file: 0dd159bf.
8530 Check for wraparound with an overlarge ncols value. */
8531 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
8533 warn (_("Overlarge number of columns: %x\n"), ncols);
8539 warn (_("Section %s too small for offset and size tables\n"),
8546 printf (_(" Offset table\n"));
8547 printf (" slot %-16s ",
8548 is_tu_index ? _("signature") : _("dwo_id"));
8555 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8561 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8568 for (j = 0; j < ncols; j++)
8570 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8571 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8576 for (i = 0; i < nslots; i++)
8578 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8580 SAFE_BYTE_GET (row, pi, 4, limit);
8583 /* PR 17531: file: a05f6ab3. */
8586 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8592 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8594 prow = poffsets + (row - 1) * ncols * 4;
8595 /* PR 17531: file: b8ce60a8. */
8596 if (prow < poffsets || prow > limit)
8598 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8604 printf (_(" [%3d] 0x%s"),
8605 i, dwarf_vmatoa64 (signature_high, signature_low,
8606 buf, sizeof (buf)));
8607 for (j = 0; j < ncols; j++)
8609 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8611 printf (" %8d", val);
8614 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8616 /* PR 17531: file: 10796eb3. */
8617 if (dw_sect >= DW_SECT_MAX)
8618 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8620 this_set [row - 1].section_offsets [dw_sect] = val;
8636 printf (_(" Size table\n"));
8637 printf (" slot %-16s ",
8638 is_tu_index ? _("signature") : _("dwo_id"));
8641 for (j = 0; j < ncols; j++)
8643 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8645 printf (" %8s", get_DW_SECT_short_name (val));
8651 for (i = 0; i < nslots; i++)
8653 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8655 SAFE_BYTE_GET (row, pi, 4, limit);
8658 prow = psizes + (row - 1) * ncols * 4;
8661 printf (_(" [%3d] 0x%s"),
8662 i, dwarf_vmatoa64 (signature_high, signature_low,
8663 buf, sizeof (buf)));
8665 for (j = 0; j < ncols; j++)
8667 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8669 printf (" %8d", val);
8672 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8673 if (dw_sect >= DW_SECT_MAX)
8674 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8676 this_set [row - 1].section_sizes [dw_sect] = val;
8688 else if (do_display)
8689 printf (_(" Unsupported version (%d)\n"), version);
8697 /* Load the CU and TU indexes if present. This will build a list of
8698 section sets that we can use to associate a .debug_info.dwo section
8699 with its associated .debug_abbrev.dwo section in a .dwp file. */
8702 load_cu_tu_indexes (void *file)
8704 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8706 /* If we have already loaded (or tried to load) the CU and TU indexes
8707 then do not bother to repeat the task. */
8708 if (cu_tu_indexes_read == -1)
8710 cu_tu_indexes_read = TRUE;
8712 if (load_debug_section (dwp_cu_index, file))
8713 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8714 cu_tu_indexes_read = FALSE;
8716 if (load_debug_section (dwp_tu_index, file))
8717 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8718 cu_tu_indexes_read = FALSE;
8721 return (bfd_boolean) cu_tu_indexes_read;
8724 /* Find the set of sections that includes section SHNDX. */
8727 find_cu_tu_set (void *file, unsigned int shndx)
8731 if (! load_cu_tu_indexes (file))
8734 /* Find SHNDX in the shndx pool. */
8735 for (i = 0; i < shndx_pool_used; i++)
8736 if (shndx_pool [i] == shndx)
8739 if (i >= shndx_pool_used)
8742 /* Now backup to find the first entry in the set. */
8743 while (i > 0 && shndx_pool [i - 1] != 0)
8746 return shndx_pool + i;
8749 /* Display a .debug_cu_index or .debug_tu_index section. */
8752 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
8754 return process_cu_tu_index (section, 1);
8758 display_debug_not_supported (struct dwarf_section *section,
8759 void *file ATTRIBUTE_UNUSED)
8761 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8767 /* Like malloc, but takes two parameters like calloc.
8768 Verifies that the first parameter is not too large.
8769 Note: does *not* initialise the allocated memory to zero. */
8771 cmalloc (size_t nmemb, size_t size)
8773 /* Check for overflow. */
8774 if (nmemb >= ~(size_t) 0 / size)
8777 return xmalloc (nmemb * size);
8780 /* Like xmalloc, but takes two parameters like calloc.
8781 Verifies that the first parameter is not too large.
8782 Note: does *not* initialise the allocated memory to zero. */
8784 xcmalloc (size_t nmemb, size_t size)
8786 /* Check for overflow. */
8787 if (nmemb >= ~(size_t) 0 / size)
8790 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8795 return xmalloc (nmemb * size);
8798 /* Like xrealloc, but takes three parameters.
8799 Verifies that the second parameter is not too large.
8800 Note: does *not* initialise any new memory to zero. */
8802 xcrealloc (void *ptr, size_t nmemb, size_t size)
8804 /* Check for overflow. */
8805 if (nmemb >= ~(size_t) 0 / size)
8808 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8813 return xrealloc (ptr, nmemb * size);
8816 /* Like xcalloc, but verifies that the first parameter is not too large. */
8818 xcalloc2 (size_t nmemb, size_t size)
8820 /* Check for overflow. */
8821 if (nmemb >= ~(size_t) 0 / size)
8824 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8829 return xcalloc (nmemb, size);
8833 free_debug_memory (void)
8839 for (i = 0; i < max; i++)
8840 free_debug_section ((enum dwarf_section_display_enum) i);
8842 if (debug_information != NULL)
8844 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
8846 for (i = 0; i < num_debug_info_entries; i++)
8848 if (!debug_information [i].max_loc_offsets)
8850 free (debug_information [i].loc_offsets);
8851 free (debug_information [i].have_frame_base);
8853 if (!debug_information [i].max_range_lists)
8854 free (debug_information [i].range_lists);
8857 free (debug_information);
8858 debug_information = NULL;
8859 alloc_num_debug_info_entries = num_debug_info_entries = 0;
8864 dwarf_select_sections_by_names (const char *names)
8868 const char * option;
8872 debug_dump_long_opts;
8874 static const debug_dump_long_opts opts_table [] =
8876 /* Please keep this table alpha- sorted. */
8877 { "Ranges", & do_debug_ranges, 1 },
8878 { "abbrev", & do_debug_abbrevs, 1 },
8879 { "addr", & do_debug_addr, 1 },
8880 { "aranges", & do_debug_aranges, 1 },
8881 { "cu_index", & do_debug_cu_index, 1 },
8882 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
8883 { "frames", & do_debug_frames, 1 },
8884 { "frames-interp", & do_debug_frames_interp, 1 },
8885 /* The special .gdb_index section. */
8886 { "gdb_index", & do_gdb_index, 1 },
8887 { "info", & do_debug_info, 1 },
8888 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
8889 { "loc", & do_debug_loc, 1 },
8890 { "macro", & do_debug_macinfo, 1 },
8891 { "pubnames", & do_debug_pubnames, 1 },
8892 { "pubtypes", & do_debug_pubtypes, 1 },
8893 /* This entry is for compatibility
8894 with earlier versions of readelf. */
8895 { "ranges", & do_debug_aranges, 1 },
8896 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
8897 { "str", & do_debug_str, 1 },
8898 /* These trace_* sections are used by Itanium VMS. */
8899 { "trace_abbrev", & do_trace_abbrevs, 1 },
8900 { "trace_aranges", & do_trace_aranges, 1 },
8901 { "trace_info", & do_trace_info, 1 },
8910 const debug_dump_long_opts * entry;
8912 for (entry = opts_table; entry->option; entry++)
8914 size_t len = strlen (entry->option);
8916 if (strncmp (p, entry->option, len) == 0
8917 && (p[len] == ',' || p[len] == '\0'))
8919 * entry->variable |= entry->val;
8921 /* The --debug-dump=frames-interp option also
8922 enables the --debug-dump=frames option. */
8923 if (do_debug_frames_interp)
8924 do_debug_frames = 1;
8931 if (entry->option == NULL)
8933 warn (_("Unrecognized debug option '%s'\n"), p);
8934 p = strchr (p, ',');
8945 dwarf_select_sections_by_letters (const char *letters)
8947 unsigned int lindex = 0;
8949 while (letters[lindex])
8950 switch (letters[lindex++])
8957 do_debug_abbrevs = 1;
8961 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
8965 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
8969 do_debug_pubnames = 1;
8973 do_debug_pubtypes = 1;
8977 do_debug_aranges = 1;
8981 do_debug_ranges = 1;
8985 do_debug_frames_interp = 1;
8988 do_debug_frames = 1;
8992 do_debug_macinfo = 1;
9004 warn (_("Unrecognized debug option '%s'\n"), letters);
9010 dwarf_select_sections_all (void)
9013 do_debug_abbrevs = 1;
9014 do_debug_lines = FLAG_DEBUG_LINES_RAW;
9015 do_debug_pubnames = 1;
9016 do_debug_pubtypes = 1;
9017 do_debug_aranges = 1;
9018 do_debug_ranges = 1;
9019 do_debug_frames = 1;
9020 do_debug_macinfo = 1;
9025 do_trace_abbrevs = 1;
9026 do_trace_aranges = 1;
9028 do_debug_cu_index = 1;
9031 struct dwarf_section_display debug_displays[] =
9033 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9034 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9035 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9036 display_debug_aranges, &do_debug_aranges, TRUE },
9037 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9038 display_debug_frames, &do_debug_frames, TRUE },
9039 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9040 display_debug_info, &do_debug_info, TRUE },
9041 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9042 display_debug_lines, &do_debug_lines, TRUE },
9043 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9044 display_debug_pubnames, &do_debug_pubnames, FALSE },
9045 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9046 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
9047 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9048 display_debug_frames, &do_debug_frames, TRUE },
9049 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9050 display_debug_macinfo, &do_debug_macinfo, FALSE },
9051 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9052 display_debug_macro, &do_debug_macinfo, TRUE },
9053 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9054 display_debug_str, &do_debug_str, FALSE },
9055 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9056 display_debug_str, &do_debug_str, FALSE },
9057 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9058 display_debug_loc, &do_debug_loc, TRUE },
9059 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9060 display_debug_loc, &do_debug_loc, TRUE },
9061 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9062 display_debug_pubnames, &do_debug_pubtypes, FALSE },
9063 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9064 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
9065 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9066 display_debug_ranges, &do_debug_ranges, TRUE },
9067 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9068 display_debug_ranges, &do_debug_ranges, TRUE },
9069 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9070 display_debug_not_supported, NULL, FALSE },
9071 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9072 display_debug_not_supported, NULL, FALSE },
9073 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9074 display_debug_types, &do_debug_info, TRUE },
9075 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9076 display_debug_not_supported, NULL, FALSE },
9077 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9078 display_gdb_index, &do_gdb_index, FALSE },
9079 { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9080 display_debug_names, &do_gdb_index, FALSE },
9081 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
9082 display_trace_info, &do_trace_info, TRUE },
9083 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9084 display_debug_abbrev, &do_trace_abbrevs, FALSE },
9085 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9086 display_debug_aranges, &do_trace_aranges, FALSE },
9087 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9088 display_debug_info, &do_debug_info, TRUE },
9089 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9090 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9091 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9092 display_debug_types, &do_debug_info, TRUE },
9093 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9094 display_debug_lines, &do_debug_lines, TRUE },
9095 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9096 display_debug_loc, &do_debug_loc, TRUE },
9097 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9098 display_debug_macro, &do_debug_macinfo, TRUE },
9099 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9100 display_debug_macinfo, &do_debug_macinfo, FALSE },
9101 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9102 display_debug_str, &do_debug_str, TRUE },
9103 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9104 display_debug_str_offsets, NULL, FALSE },
9105 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9106 display_debug_str_offsets, NULL, FALSE },
9107 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9108 display_debug_addr, &do_debug_addr, TRUE },
9109 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9110 display_cu_index, &do_debug_cu_index, FALSE },
9111 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9112 display_cu_index, &do_debug_cu_index, FALSE },
9115 /* A static assertion. */
9116 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];