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"
32 static const char *regname (unsigned int regno, int row);
34 static int have_frame_base;
35 static int need_base_address;
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
40 static unsigned int num_debug_info_entries = 0;
41 static unsigned int alloc_num_debug_info_entries = 0;
42 static debug_info *debug_information = NULL;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 unsigned int eh_addr_size;
52 int do_debug_pubnames;
53 int do_debug_pubtypes;
57 int do_debug_frames_interp;
66 int do_debug_cu_index;
69 int dwarf_cutoff_level = -1;
70 unsigned long dwarf_start_die;
74 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
75 sections. For version 1 package files, each set is stored in SHNDX_POOL
76 as a zero-terminated list of section indexes comprising one set of debug
77 sections from a .dwo file. */
79 static unsigned int *shndx_pool = NULL;
80 static unsigned int shndx_pool_size = 0;
81 static unsigned int shndx_pool_used = 0;
83 /* For version 2 package files, each set contains an array of section offsets
84 and an array of section sizes, giving the offset and size of the
85 contribution from a CU or TU within one of the debug sections.
86 When displaying debug info from a package file, we need to use these
87 tables to locate the corresponding contributions to each section. */
92 dwarf_vma section_offsets[DW_SECT_MAX];
93 size_t section_sizes[DW_SECT_MAX];
96 static int cu_count = 0;
97 static int tu_count = 0;
98 static struct cu_tu_set *cu_sets = NULL;
99 static struct cu_tu_set *tu_sets = NULL;
101 static bfd_boolean load_cu_tu_indexes (void *);
103 /* Values for do_debug_lines. */
104 #define FLAG_DEBUG_LINES_RAW 1
105 #define FLAG_DEBUG_LINES_DECODED 2
108 size_of_encoded_value (int encoding)
110 switch (encoding & 0x7)
113 case 0: return eh_addr_size;
121 get_encoded_value (unsigned char **pdata,
123 struct dwarf_section *section,
126 unsigned char * data = * pdata;
127 unsigned int size = size_of_encoded_value (encoding);
130 if (data + size >= end)
132 warn (_("Encoded value extends past end of section\n"));
137 /* PR 17512: file: 002-829853-0.004. */
140 warn (_("Encoded size of %d is too large to read\n"), size);
145 /* PR 17512: file: 1085-5603-0.004. */
148 warn (_("Encoded size of 0 is too small to read\n"));
153 if (encoding & DW_EH_PE_signed)
154 val = byte_get_signed (data, size);
156 val = byte_get (data, size);
158 if ((encoding & 0x70) == DW_EH_PE_pcrel)
159 val += section->address + (data - section->start);
161 * pdata = data + size;
165 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
167 # define DWARF_VMA_FMT "ll"
168 # define DWARF_VMA_FMT_LONG "%16.16llx"
170 # define DWARF_VMA_FMT "I64"
171 # define DWARF_VMA_FMT_LONG "%016I64x"
174 # define DWARF_VMA_FMT "l"
175 # define DWARF_VMA_FMT_LONG "%16.16lx"
178 /* Convert a dwarf vma value into a string. Returns a pointer to a static
179 buffer containing the converted VALUE. The value is converted according
180 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
181 it specifies the maximum number of bytes to be displayed in the converted
182 value and FMTCH is ignored - hex is always used. */
185 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
187 /* As dwarf_vmatoa is used more then once in a printf call
188 for output, we are cycling through an fixed array of pointers
189 for return address. */
190 static int buf_pos = 0;
191 static struct dwarf_vmatoa_buf
197 ret = buf[buf_pos++].place;
198 buf_pos %= ARRAY_SIZE (buf);
202 /* Printf does not have a way of specifying a maximum field width for an
203 integer value, so we print the full value into a buffer and then select
204 the precision we need. */
205 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
208 return ret + (16 - 2 * num_bytes);
214 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
215 snprintf (ret, sizeof (buf[0].place), fmt, value);
220 static inline const char *
221 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
223 return dwarf_vmatoa_1 (fmtch, value, 0);
226 /* Print a dwarf_vma value (typically an address, offset or length) in
227 hexadecimal format, followed by a space. The length of the VALUE (and
228 hence the precision displayed) is determined by the NUM_BYTES parameter. */
231 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
233 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
236 /* Format a 64-bit value, given as two 32-bit values, in hex.
237 For reentrancy, this uses a buffer provided by the caller. */
240 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
241 unsigned int buf_len)
246 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
249 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
250 snprintf (buf + len, buf_len - len,
251 "%08" DWARF_VMA_FMT "x", lvalue);
257 /* Read in a LEB128 encoded value starting at address DATA.
258 If SIGN is true, return a signed LEB128 value.
259 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
260 No bytes will be read at address END or beyond. */
263 read_leb128 (unsigned char *data,
264 unsigned int *length_return,
266 const unsigned char * const end)
268 dwarf_vma result = 0;
269 unsigned int num_read = 0;
270 unsigned int shift = 0;
271 unsigned char byte = 0;
278 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
281 if ((byte & 0x80) == 0)
284 /* PR 17512: file: 0ca183b8.
285 FIXME: Should we signal this error somehow ? */
286 if (shift >= sizeof (result) * 8)
290 if (length_return != NULL)
291 *length_return = num_read;
293 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
294 result |= -((dwarf_vma) 1 << shift);
299 /* Create a signed version to avoid painful typecasts. */
300 static inline dwarf_signed_vma
301 read_sleb128 (unsigned char * data,
302 unsigned int * length_return,
303 const unsigned char * const end)
305 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
308 static inline dwarf_vma
309 read_uleb128 (unsigned char * data,
310 unsigned int * length_return,
311 const unsigned char * const end)
313 return read_leb128 (data, length_return, FALSE, end);
316 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
319 unsigned int amount = (AMOUNT); \
320 if (sizeof (VAL) < amount) \
322 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
323 amount, (int) sizeof (VAL)); \
324 amount = sizeof (VAL); \
326 if (((PTR) + amount) >= (END)) \
329 amount = (END) - (PTR); \
333 if (amount == 0 || amount > 8) \
336 VAL = byte_get ((PTR), amount); \
340 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
343 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
348 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
351 unsigned int amount = (AMOUNT); \
352 if (((PTR) + amount) >= (END)) \
355 amount = (END) - (PTR); \
360 VAL = byte_get_signed ((PTR), amount); \
366 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
369 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
374 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
377 if (((PTR) + 8) <= (END)) \
379 byte_get_64 ((PTR), (HIGH), (LOW)); \
383 * (LOW) = * (HIGH) = 0; \
388 typedef struct State_Machine_Registers
396 unsigned char op_index;
397 unsigned char end_sequence;
398 /* This variable hold the number of the last entry seen
399 in the File Table. */
400 unsigned int last_file_entry;
403 static SMR state_machine_regs;
406 reset_state_machine (int is_stmt)
408 state_machine_regs.address = 0;
409 state_machine_regs.op_index = 0;
410 state_machine_regs.file = 1;
411 state_machine_regs.line = 1;
412 state_machine_regs.column = 0;
413 state_machine_regs.is_stmt = is_stmt;
414 state_machine_regs.basic_block = 0;
415 state_machine_regs.end_sequence = 0;
416 state_machine_regs.last_file_entry = 0;
419 /* Handled an extend line op.
420 Returns the number of bytes read. */
423 process_extended_line_op (unsigned char * data,
427 unsigned char op_code;
428 unsigned int bytes_read;
431 unsigned char *orig_data = data;
434 len = read_uleb128 (data, & bytes_read, end);
437 if (len == 0 || data == end || len > (uintptr_t) (end - data))
439 warn (_("Badly formed extended line op encountered!\n"));
446 printf (_(" Extended opcode %d: "), op_code);
450 case DW_LNE_end_sequence:
451 printf (_("End of Sequence\n\n"));
452 reset_state_machine (is_stmt);
455 case DW_LNE_set_address:
456 /* PR 17512: file: 002-100480-0.004. */
457 if (len - bytes_read - 1 > 8)
459 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
460 len - bytes_read - 1);
464 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
465 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
466 state_machine_regs.address = adr;
467 state_machine_regs.op_index = 0;
470 case DW_LNE_define_file:
471 printf (_("define new File Table entry\n"));
472 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
473 printf (" %d\t", ++state_machine_regs.last_file_entry);
479 l = strnlen ((char *) data, end - data);
481 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
483 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
485 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
487 printf ("%.*s\n\n", (int) l, name);
490 if (((unsigned int) (data - orig_data) != len) || data == end)
491 warn (_("DW_LNE_define_file: Bad opcode length\n"));
494 case DW_LNE_set_discriminator:
495 printf (_("set Discriminator to %s\n"),
496 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
500 case DW_LNE_HP_negate_is_UV_update:
501 printf ("DW_LNE_HP_negate_is_UV_update\n");
503 case DW_LNE_HP_push_context:
504 printf ("DW_LNE_HP_push_context\n");
506 case DW_LNE_HP_pop_context:
507 printf ("DW_LNE_HP_pop_context\n");
509 case DW_LNE_HP_set_file_line_column:
510 printf ("DW_LNE_HP_set_file_line_column\n");
512 case DW_LNE_HP_set_routine_name:
513 printf ("DW_LNE_HP_set_routine_name\n");
515 case DW_LNE_HP_set_sequence:
516 printf ("DW_LNE_HP_set_sequence\n");
518 case DW_LNE_HP_negate_post_semantics:
519 printf ("DW_LNE_HP_negate_post_semantics\n");
521 case DW_LNE_HP_negate_function_exit:
522 printf ("DW_LNE_HP_negate_function_exit\n");
524 case DW_LNE_HP_negate_front_end_logical:
525 printf ("DW_LNE_HP_negate_front_end_logical\n");
527 case DW_LNE_HP_define_proc:
528 printf ("DW_LNE_HP_define_proc\n");
530 case DW_LNE_HP_source_file_correlation:
532 unsigned char *edata = data + len - bytes_read - 1;
534 printf ("DW_LNE_HP_source_file_correlation\n");
540 opc = read_uleb128 (data, & bytes_read, edata);
545 case DW_LNE_HP_SFC_formfeed:
546 printf (" DW_LNE_HP_SFC_formfeed\n");
548 case DW_LNE_HP_SFC_set_listing_line:
549 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
551 read_uleb128 (data, & bytes_read, edata)));
554 case DW_LNE_HP_SFC_associate:
555 printf (" DW_LNE_HP_SFC_associate ");
558 read_uleb128 (data, & bytes_read, edata)));
562 read_uleb128 (data, & bytes_read, edata)));
566 read_uleb128 (data, & bytes_read, edata)));
570 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
580 unsigned int rlen = len - bytes_read - 1;
582 if (op_code >= DW_LNE_lo_user
583 /* The test against DW_LNW_hi_user is redundant due to
584 the limited range of the unsigned char data type used
586 /*&& op_code <= DW_LNE_hi_user*/)
587 printf (_("user defined: "));
589 printf (_("UNKNOWN: "));
590 printf (_("length %d ["), rlen);
592 printf (" %02x", *data++);
601 static const unsigned char *
602 fetch_indirect_string (dwarf_vma offset)
604 struct dwarf_section *section = &debug_displays [str].section;
605 const unsigned char * ret;
607 if (section->start == NULL)
608 return (const unsigned char *) _("<no .debug_str section>");
610 if (offset >= section->size)
612 warn (_("DW_FORM_strp offset too big: %s\n"),
613 dwarf_vmatoa ("x", offset));
614 return (const unsigned char *) _("<offset is too big>");
617 ret = section->start + offset;
618 /* Unfortunately we cannot rely upon the .debug_str section ending with a
619 NUL byte. Since our caller is expecting to receive a well formed C
620 string we test for the lack of a terminating byte here. */
621 if (strnlen ((const char *) ret, section->size - offset)
622 == section->size - offset)
623 ret = (const unsigned char *)
624 _("<no NUL byte at end of .debug_str section>");
629 static const unsigned char *
630 fetch_indirect_line_string (dwarf_vma offset)
632 struct dwarf_section *section = &debug_displays [line_str].section;
633 const unsigned char * ret;
635 if (section->start == NULL)
636 return (const unsigned char *) _("<no .debug_line_str section>");
638 if (offset >= section->size)
640 warn (_("DW_FORM_line_strp offset too big: %s\n"),
641 dwarf_vmatoa ("x", offset));
642 return (const unsigned char *) _("<offset is too big>");
645 ret = section->start + offset;
646 /* Unfortunately we cannot rely upon the .debug_line_str section ending
647 with a NUL byte. Since our caller is expecting to receive a well formed
648 C string we test for the lack of a terminating byte here. */
649 if (strnlen ((const char *) ret, section->size - offset)
650 == section->size - offset)
651 ret = (const unsigned char *)
652 _("<no NUL byte at end of .debug_line_str section>");
658 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
659 dwarf_vma offset_size, int dwo)
661 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
662 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
663 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
664 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
665 dwarf_vma index_offset = idx * offset_size;
666 dwarf_vma str_offset;
669 if (index_section->start == NULL)
670 return (dwo ? _("<no .debug_str_offsets.dwo section>")
671 : _("<no .debug_str_offsets section>"));
673 if (this_set != NULL)
674 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
675 if (index_offset >= index_section->size)
677 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
678 dwarf_vmatoa ("x", index_offset));
679 return _("<index offset is too big>");
682 if (str_section->start == NULL)
683 return (dwo ? _("<no .debug_str.dwo section>")
684 : _("<no .debug_str section>"));
686 str_offset = byte_get (index_section->start + index_offset, offset_size);
687 str_offset -= str_section->address;
688 if (str_offset >= str_section->size)
690 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
691 dwarf_vmatoa ("x", str_offset));
692 return _("<indirect index offset is too big>");
695 ret = (const char *) str_section->start + str_offset;
696 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
697 Since our caller is expecting to receive a well formed C string we test
698 for the lack of a terminating byte here. */
699 if (strnlen (ret, str_section->size - str_offset)
700 == str_section->size - str_offset)
701 ret = (const char *) _("<no NUL byte at end of section>");
707 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
709 struct dwarf_section *section = &debug_displays [debug_addr].section;
711 if (section->start == NULL)
712 return (_("<no .debug_addr section>"));
714 if (offset + bytes > section->size)
716 warn (_("Offset into section %s too big: %s\n"),
717 section->name, dwarf_vmatoa ("x", offset));
718 return "<offset too big>";
721 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
725 /* FIXME: There are better and more efficient ways to handle
726 these structures. For now though, I just want something that
727 is simple to implement. */
728 typedef struct abbrev_attr
730 unsigned long attribute;
732 bfd_signed_vma implicit_const;
733 struct abbrev_attr *next;
737 typedef struct abbrev_entry
742 struct abbrev_attr *first_attr;
743 struct abbrev_attr *last_attr;
744 struct abbrev_entry *next;
748 static abbrev_entry *first_abbrev = NULL;
749 static abbrev_entry *last_abbrev = NULL;
756 for (abbrv = first_abbrev; abbrv;)
758 abbrev_entry *next_abbrev = abbrv->next;
761 for (attr = abbrv->first_attr; attr;)
763 abbrev_attr *next_attr = attr->next;
773 last_abbrev = first_abbrev = NULL;
777 add_abbrev (unsigned long number, unsigned long tag, int children)
781 entry = (abbrev_entry *) malloc (sizeof (*entry));
786 entry->entry = number;
788 entry->children = children;
789 entry->first_attr = NULL;
790 entry->last_attr = NULL;
793 if (first_abbrev == NULL)
794 first_abbrev = entry;
796 last_abbrev->next = entry;
802 add_abbrev_attr (unsigned long attribute, unsigned long form,
803 bfd_signed_vma implicit_const)
807 attr = (abbrev_attr *) malloc (sizeof (*attr));
812 attr->attribute = attribute;
814 attr->implicit_const = implicit_const;
817 if (last_abbrev->first_attr == NULL)
818 last_abbrev->first_attr = attr;
820 last_abbrev->last_attr->next = attr;
822 last_abbrev->last_attr = attr;
825 /* Processes the (partial) contents of a .debug_abbrev section.
826 Returns NULL if the end of the section was encountered.
827 Returns the address after the last byte read if the end of
828 an abbreviation set was found. */
830 static unsigned char *
831 process_abbrev_section (unsigned char *start, unsigned char *end)
833 if (first_abbrev != NULL)
838 unsigned int bytes_read;
841 unsigned long attribute;
844 entry = read_uleb128 (start, & bytes_read, end);
847 /* A single zero is supposed to end the section according
848 to the standard. If there's more, then signal that to
855 tag = read_uleb128 (start, & bytes_read, end);
862 add_abbrev (entry, tag, children);
867 /* Initialize it due to a false compiler warning. */
868 bfd_signed_vma implicit_const = -1;
870 attribute = read_uleb128 (start, & bytes_read, end);
875 form = read_uleb128 (start, & bytes_read, end);
880 if (form == DW_FORM_implicit_const)
882 implicit_const = read_sleb128 (start, & bytes_read, end);
888 add_abbrev_attr (attribute, form, implicit_const);
890 while (attribute != 0);
893 /* Report the missing single zero which ends the section. */
894 error (_(".debug_abbrev section not zero terminated\n"));
900 get_TAG_name (unsigned long tag)
902 const char *name = get_DW_TAG_name ((unsigned int)tag);
906 static char buffer[100];
908 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
916 get_FORM_name (unsigned long form)
921 return "DW_FORM value: 0";
923 name = get_DW_FORM_name (form);
926 static char buffer[100];
928 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
935 static unsigned char *
936 display_block (unsigned char *data,
938 const unsigned char * const end, char delimiter)
942 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
944 return (unsigned char *) end;
946 maxlen = (dwarf_vma) (end - data);
947 length = length > maxlen ? maxlen : length;
950 printf ("%lx ", (unsigned long) byte_get (data++, 1));
956 decode_location_expression (unsigned char * data,
957 unsigned int pointer_size,
958 unsigned int offset_size,
962 struct dwarf_section * section)
965 unsigned int bytes_read;
967 dwarf_signed_vma svalue;
968 unsigned char *end = data + length;
969 int need_frame_base = 0;
978 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
979 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
982 printf ("DW_OP_deref");
985 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
986 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
989 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
990 printf ("DW_OP_const1s: %ld", (long) svalue);
993 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
994 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
997 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
998 printf ("DW_OP_const2s: %ld", (long) svalue);
1001 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1002 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1005 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1006 printf ("DW_OP_const4s: %ld", (long) svalue);
1009 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1010 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1011 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1012 printf ("%lu", (unsigned long) uvalue);
1015 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1016 printf ("DW_OP_const8s: %ld ", (long) svalue);
1017 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1018 printf ("%ld", (long) svalue);
1021 printf ("DW_OP_constu: %s",
1022 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1026 printf ("DW_OP_consts: %s",
1027 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1031 printf ("DW_OP_dup");
1034 printf ("DW_OP_drop");
1037 printf ("DW_OP_over");
1040 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1041 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1044 printf ("DW_OP_swap");
1047 printf ("DW_OP_rot");
1050 printf ("DW_OP_xderef");
1053 printf ("DW_OP_abs");
1056 printf ("DW_OP_and");
1059 printf ("DW_OP_div");
1062 printf ("DW_OP_minus");
1065 printf ("DW_OP_mod");
1068 printf ("DW_OP_mul");
1071 printf ("DW_OP_neg");
1074 printf ("DW_OP_not");
1077 printf ("DW_OP_or");
1080 printf ("DW_OP_plus");
1082 case DW_OP_plus_uconst:
1083 printf ("DW_OP_plus_uconst: %s",
1084 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1088 printf ("DW_OP_shl");
1091 printf ("DW_OP_shr");
1094 printf ("DW_OP_shra");
1097 printf ("DW_OP_xor");
1100 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1101 printf ("DW_OP_bra: %ld", (long) svalue);
1104 printf ("DW_OP_eq");
1107 printf ("DW_OP_ge");
1110 printf ("DW_OP_gt");
1113 printf ("DW_OP_le");
1116 printf ("DW_OP_lt");
1119 printf ("DW_OP_ne");
1122 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1123 printf ("DW_OP_skip: %ld", (long) svalue);
1158 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1193 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1194 regname (op - DW_OP_reg0, 1));
1229 printf ("DW_OP_breg%d (%s): %s",
1231 regname (op - DW_OP_breg0, 1),
1232 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1237 uvalue = read_uleb128 (data, &bytes_read, end);
1239 printf ("DW_OP_regx: %s (%s)",
1240 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1243 need_frame_base = 1;
1244 printf ("DW_OP_fbreg: %s",
1245 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1249 uvalue = read_uleb128 (data, &bytes_read, end);
1251 printf ("DW_OP_bregx: %s (%s) %s",
1252 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1253 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1257 printf ("DW_OP_piece: %s",
1258 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1261 case DW_OP_deref_size:
1262 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1263 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1265 case DW_OP_xderef_size:
1266 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1267 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1270 printf ("DW_OP_nop");
1273 /* DWARF 3 extensions. */
1274 case DW_OP_push_object_address:
1275 printf ("DW_OP_push_object_address");
1278 /* XXX: Strictly speaking for 64-bit DWARF3 files
1279 this ought to be an 8-byte wide computation. */
1280 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1281 printf ("DW_OP_call2: <0x%s>",
1282 dwarf_vmatoa ("x", svalue + cu_offset));
1285 /* XXX: Strictly speaking for 64-bit DWARF3 files
1286 this ought to be an 8-byte wide computation. */
1287 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1288 printf ("DW_OP_call4: <0x%s>",
1289 dwarf_vmatoa ("x", svalue + cu_offset));
1291 case DW_OP_call_ref:
1292 /* XXX: Strictly speaking for 64-bit DWARF3 files
1293 this ought to be an 8-byte wide computation. */
1294 if (dwarf_version == -1)
1296 printf (_("(DW_OP_call_ref in frame info)"));
1297 /* No way to tell where the next op is, so just bail. */
1298 return need_frame_base;
1300 if (dwarf_version == 2)
1302 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1306 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1308 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1310 case DW_OP_form_tls_address:
1311 printf ("DW_OP_form_tls_address");
1313 case DW_OP_call_frame_cfa:
1314 printf ("DW_OP_call_frame_cfa");
1316 case DW_OP_bit_piece:
1317 printf ("DW_OP_bit_piece: ");
1318 printf (_("size: %s "),
1319 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1321 printf (_("offset: %s "),
1322 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1326 /* DWARF 4 extensions. */
1327 case DW_OP_stack_value:
1328 printf ("DW_OP_stack_value");
1331 case DW_OP_implicit_value:
1332 printf ("DW_OP_implicit_value");
1333 uvalue = read_uleb128 (data, &bytes_read, end);
1335 data = display_block (data, uvalue, end, ' ');
1338 /* GNU extensions. */
1339 case DW_OP_GNU_push_tls_address:
1340 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1342 case DW_OP_GNU_uninit:
1343 printf ("DW_OP_GNU_uninit");
1344 /* FIXME: Is there data associated with this OP ? */
1346 case DW_OP_GNU_encoded_addr:
1353 addr = get_encoded_value (&data, encoding, section, end);
1355 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1356 print_dwarf_vma (addr, pointer_size);
1359 case DW_OP_implicit_pointer:
1360 case DW_OP_GNU_implicit_pointer:
1361 /* XXX: Strictly speaking for 64-bit DWARF3 files
1362 this ought to be an 8-byte wide computation. */
1363 if (dwarf_version == -1)
1365 printf (_("(%s in frame info)"),
1366 (op == DW_OP_implicit_pointer
1367 ? "DW_OP_implicit_pointer"
1368 : "DW_OP_GNU_implicit_pointer"));
1369 /* No way to tell where the next op is, so just bail. */
1370 return need_frame_base;
1372 if (dwarf_version == 2)
1374 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1378 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1380 printf ("%s: <0x%s> %s",
1381 (op == DW_OP_implicit_pointer
1382 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1383 dwarf_vmatoa ("x", uvalue),
1384 dwarf_vmatoa ("d", read_sleb128 (data,
1385 &bytes_read, end)));
1388 case DW_OP_entry_value:
1389 case DW_OP_GNU_entry_value:
1390 uvalue = read_uleb128 (data, &bytes_read, end);
1392 /* PR 17531: file: 0cc9cd00. */
1393 if (uvalue > (dwarf_vma) (end - data))
1394 uvalue = end - data;
1395 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1396 : "DW_OP_GNU_entry_value"));
1397 if (decode_location_expression (data, pointer_size, offset_size,
1398 dwarf_version, uvalue,
1399 cu_offset, section))
1400 need_frame_base = 1;
1406 case DW_OP_const_type:
1407 case DW_OP_GNU_const_type:
1408 uvalue = read_uleb128 (data, &bytes_read, end);
1410 printf ("%s: <0x%s> ",
1411 (op == DW_OP_const_type ? "DW_OP_const_type"
1412 : "DW_OP_GNU_const_type"),
1413 dwarf_vmatoa ("x", cu_offset + uvalue));
1414 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1415 data = display_block (data, uvalue, end, ' ');
1417 case DW_OP_regval_type:
1418 case DW_OP_GNU_regval_type:
1419 uvalue = read_uleb128 (data, &bytes_read, end);
1421 printf ("%s: %s (%s)",
1422 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1423 : "DW_OP_GNU_regval_type"),
1424 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1425 uvalue = read_uleb128 (data, &bytes_read, end);
1427 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1429 case DW_OP_deref_type:
1430 case DW_OP_GNU_deref_type:
1431 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1433 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1434 : "DW_OP_GNU_deref_type"),
1436 uvalue = read_uleb128 (data, &bytes_read, end);
1438 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1441 case DW_OP_GNU_convert:
1442 uvalue = read_uleb128 (data, &bytes_read, end);
1444 printf ("%s <0x%s>",
1445 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1446 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1448 case DW_OP_reinterpret:
1449 case DW_OP_GNU_reinterpret:
1450 uvalue = read_uleb128 (data, &bytes_read, end);
1452 printf ("%s <0x%s>",
1453 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1454 : "DW_OP_GNU_reinterpret"),
1455 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1457 case DW_OP_GNU_parameter_ref:
1458 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1459 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1460 dwarf_vmatoa ("x", cu_offset + uvalue));
1462 case DW_OP_GNU_addr_index:
1463 uvalue = read_uleb128 (data, &bytes_read, end);
1465 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1467 case DW_OP_GNU_const_index:
1468 uvalue = read_uleb128 (data, &bytes_read, end);
1470 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1473 /* HP extensions. */
1474 case DW_OP_HP_is_value:
1475 printf ("DW_OP_HP_is_value");
1476 /* FIXME: Is there data associated with this OP ? */
1478 case DW_OP_HP_fltconst4:
1479 printf ("DW_OP_HP_fltconst4");
1480 /* FIXME: Is there data associated with this OP ? */
1482 case DW_OP_HP_fltconst8:
1483 printf ("DW_OP_HP_fltconst8");
1484 /* FIXME: Is there data associated with this OP ? */
1486 case DW_OP_HP_mod_range:
1487 printf ("DW_OP_HP_mod_range");
1488 /* FIXME: Is there data associated with this OP ? */
1490 case DW_OP_HP_unmod_range:
1491 printf ("DW_OP_HP_unmod_range");
1492 /* FIXME: Is there data associated with this OP ? */
1495 printf ("DW_OP_HP_tls");
1496 /* FIXME: Is there data associated with this OP ? */
1499 /* PGI (STMicroelectronics) extensions. */
1500 case DW_OP_PGI_omp_thread_num:
1501 /* Pushes the thread number for the current thread as it would be
1502 returned by the standard OpenMP library function:
1503 omp_get_thread_num(). The "current thread" is the thread for
1504 which the expression is being evaluated. */
1505 printf ("DW_OP_PGI_omp_thread_num");
1509 if (op >= DW_OP_lo_user
1510 && op <= DW_OP_hi_user)
1511 printf (_("(User defined location op 0x%x)"), op);
1513 printf (_("(Unknown location op 0x%x)"), op);
1514 /* No way to tell where the next op is, so just bail. */
1515 return need_frame_base;
1518 /* Separate the ops. */
1523 return need_frame_base;
1526 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1527 This is used for DWARF package files. */
1529 static struct cu_tu_set *
1530 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1532 struct cu_tu_set *p;
1534 unsigned int dw_sect;
1540 dw_sect = DW_SECT_TYPES;
1546 dw_sect = DW_SECT_INFO;
1550 if (p->section_offsets [dw_sect] == cu_offset)
1558 /* Add INC to HIGH_BITS:LOW_BITS. */
1560 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1562 dwarf_vma tmp = * low_bits;
1566 /* FIXME: There is probably a better way of handling this:
1568 We need to cope with dwarf_vma being a 32-bit or 64-bit
1569 type. Plus regardless of its size LOW_BITS is meant to
1570 only hold 32-bits, so if there is overflow or wrap around
1571 we must propagate into HIGH_BITS. */
1572 if (tmp < * low_bits)
1576 else if (sizeof (tmp) > 8
1586 static unsigned char *
1587 read_and_display_attr_value (unsigned long attribute,
1589 dwarf_signed_vma implicit_const,
1590 unsigned char * data,
1591 unsigned char * end,
1592 dwarf_vma cu_offset,
1593 dwarf_vma pointer_size,
1594 dwarf_vma offset_size,
1596 debug_info * debug_info_p,
1598 struct dwarf_section * section,
1599 struct cu_tu_set * this_set, char delimiter)
1601 dwarf_vma uvalue = 0;
1602 unsigned char *block_start = NULL;
1603 unsigned char * orig_data = data;
1604 unsigned int bytes_read;
1606 if (data > end || (data == end && form != DW_FORM_flag_present))
1608 warn (_("Corrupt attribute\n"));
1617 case DW_FORM_ref_addr:
1618 if (dwarf_version == 2)
1619 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1620 else if (dwarf_version == 3 || dwarf_version == 4)
1621 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1623 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1628 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1632 case DW_FORM_line_strp:
1633 case DW_FORM_sec_offset:
1634 case DW_FORM_GNU_ref_alt:
1635 case DW_FORM_GNU_strp_alt:
1636 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1639 case DW_FORM_flag_present:
1646 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1651 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1656 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1660 uvalue = read_sleb128 (data, & bytes_read, end);
1664 case DW_FORM_GNU_str_index:
1665 uvalue = read_uleb128 (data, & bytes_read, end);
1669 case DW_FORM_ref_udata:
1671 uvalue = read_uleb128 (data, & bytes_read, end);
1675 case DW_FORM_indirect:
1676 form = read_uleb128 (data, & bytes_read, end);
1679 printf ("%c%s", delimiter, get_FORM_name (form));
1680 if (form == DW_FORM_implicit_const)
1682 implicit_const = read_sleb128 (data, & bytes_read, end);
1685 return read_and_display_attr_value (attribute, form, implicit_const, data,
1686 end, cu_offset, pointer_size,
1687 offset_size, dwarf_version,
1688 debug_info_p, do_loc,
1689 section, this_set, delimiter);
1690 case DW_FORM_GNU_addr_index:
1691 uvalue = read_uleb128 (data, & bytes_read, end);
1698 case DW_FORM_ref_addr:
1700 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1703 case DW_FORM_GNU_ref_alt:
1705 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1711 case DW_FORM_ref_udata:
1713 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1718 case DW_FORM_sec_offset:
1720 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1723 case DW_FORM_flag_present:
1730 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1733 case DW_FORM_implicit_const:
1735 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1742 dwarf_vma high_bits;
1746 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1748 if (form == DW_FORM_ref8)
1749 add64 (& high_bits, & utmp, cu_offset);
1750 printf ("%c0x%s", delimiter,
1751 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1754 if ((do_loc || do_debug_loc || do_debug_ranges)
1755 && num_debug_info_entries == 0)
1757 if (sizeof (uvalue) == 8)
1758 SAFE_BYTE_GET (uvalue, data, 8, end);
1760 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1766 case DW_FORM_data16:
1769 dwarf_vma left_high_bits, left_low_bits;
1770 dwarf_vma right_high_bits, right_low_bits;
1772 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1773 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1774 if (byte_get == byte_get_little_endian)
1777 left_high_bits ^= right_high_bits;
1778 right_high_bits ^= left_high_bits;
1779 left_high_bits ^= right_high_bits;
1780 left_low_bits ^= right_low_bits;
1781 right_low_bits ^= left_low_bits;
1782 left_low_bits ^= right_low_bits;
1784 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1785 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1786 left_high_bits, left_low_bits, right_high_bits,
1792 case DW_FORM_string:
1794 printf ("%c%.*s", delimiter, (int) (end - data), data);
1795 data += strnlen ((char *) data, end - data) + 1;
1799 case DW_FORM_exprloc:
1800 uvalue = read_uleb128 (data, & bytes_read, end);
1801 block_start = data + bytes_read;
1802 if (block_start >= end)
1804 warn (_("Block ends prematurely\n"));
1808 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1809 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1810 block_start + uvalue here. */
1811 data = block_start + uvalue;
1812 /* PR 17512: file: 008-103549-0.001:0.1. */
1813 if (block_start + uvalue > end || data < block_start)
1815 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1816 uvalue = end - block_start;
1819 data = block_start + uvalue;
1821 data = display_block (block_start, uvalue, end, delimiter);
1824 case DW_FORM_block1:
1825 SAFE_BYTE_GET (uvalue, data, 1, end);
1826 block_start = data + 1;
1827 if (block_start >= end)
1829 warn (_("Block ends prematurely\n"));
1833 data = block_start + uvalue;
1834 if (block_start + uvalue > end || data < block_start)
1836 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1837 uvalue = end - block_start;
1840 data = block_start + uvalue;
1842 data = display_block (block_start, uvalue, end, delimiter);
1845 case DW_FORM_block2:
1846 SAFE_BYTE_GET (uvalue, data, 2, end);
1847 block_start = data + 2;
1848 if (block_start >= end)
1850 warn (_("Block ends prematurely\n"));
1854 data = block_start + uvalue;
1855 if (block_start + uvalue > end || data < block_start)
1857 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1858 uvalue = end - block_start;
1861 data = block_start + uvalue;
1863 data = display_block (block_start, uvalue, end, delimiter);
1866 case DW_FORM_block4:
1867 SAFE_BYTE_GET (uvalue, data, 4, end);
1868 block_start = data + 4;
1869 /* PR 17512: file: 3371-3907-0.004. */
1870 if (block_start >= end)
1872 warn (_("Block ends prematurely\n"));
1876 data = block_start + uvalue;
1877 if (block_start + uvalue > end
1878 /* PR 17531: file: 5b5f0592. */
1879 || data < block_start)
1881 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1882 uvalue = end - block_start;
1885 data = block_start + uvalue;
1887 data = display_block (block_start, uvalue, end, delimiter);
1892 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1893 dwarf_vmatoa ("x", uvalue),
1894 fetch_indirect_string (uvalue));
1897 case DW_FORM_line_strp:
1899 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1900 dwarf_vmatoa ("x", uvalue),
1901 fetch_indirect_line_string (uvalue));
1904 case DW_FORM_GNU_str_index:
1907 const char *suffix = strrchr (section->name, '.');
1908 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1910 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1911 dwarf_vmatoa ("x", uvalue),
1912 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1916 case DW_FORM_GNU_strp_alt:
1918 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1919 dwarf_vmatoa ("x", uvalue));
1922 case DW_FORM_indirect:
1923 /* Handled above. */
1926 case DW_FORM_ref_sig8:
1929 dwarf_vma high_bits;
1932 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1933 printf ("%csignature: 0x%s", delimiter,
1934 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1939 case DW_FORM_GNU_addr_index:
1941 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
1942 dwarf_vmatoa ("x", uvalue),
1943 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1947 warn (_("Unrecognized form: %lu\n"), form);
1951 if ((do_loc || do_debug_loc || do_debug_ranges)
1952 && num_debug_info_entries == 0
1953 && debug_info_p != NULL)
1957 case DW_AT_frame_base:
1958 have_frame_base = 1;
1960 case DW_AT_location:
1961 case DW_AT_string_length:
1962 case DW_AT_return_addr:
1963 case DW_AT_data_member_location:
1964 case DW_AT_vtable_elem_location:
1966 case DW_AT_static_link:
1967 case DW_AT_use_location:
1968 case DW_AT_call_value:
1969 case DW_AT_GNU_call_site_value:
1970 case DW_AT_call_data_value:
1971 case DW_AT_GNU_call_site_data_value:
1972 case DW_AT_call_target:
1973 case DW_AT_GNU_call_site_target:
1974 case DW_AT_call_target_clobbered:
1975 case DW_AT_GNU_call_site_target_clobbered:
1976 if ((dwarf_version < 4
1977 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1978 || form == DW_FORM_sec_offset)
1980 /* Process location list. */
1981 unsigned int lmax = debug_info_p->max_loc_offsets;
1982 unsigned int num = debug_info_p->num_loc_offsets;
1984 if (lmax == 0 || num >= lmax)
1987 debug_info_p->loc_offsets = (dwarf_vma *)
1988 xcrealloc (debug_info_p->loc_offsets,
1989 lmax, sizeof (*debug_info_p->loc_offsets));
1990 debug_info_p->have_frame_base = (int *)
1991 xcrealloc (debug_info_p->have_frame_base,
1992 lmax, sizeof (*debug_info_p->have_frame_base));
1993 debug_info_p->max_loc_offsets = lmax;
1995 if (this_set != NULL)
1996 uvalue += this_set->section_offsets [DW_SECT_LOC];
1997 debug_info_p->loc_offsets [num] = uvalue;
1998 debug_info_p->have_frame_base [num] = have_frame_base;
1999 debug_info_p->num_loc_offsets++;
2004 if (need_base_address)
2005 debug_info_p->base_address = uvalue;
2008 case DW_AT_GNU_addr_base:
2009 debug_info_p->addr_base = uvalue;
2012 case DW_AT_GNU_ranges_base:
2013 debug_info_p->ranges_base = uvalue;
2017 if ((dwarf_version < 4
2018 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2019 || form == DW_FORM_sec_offset)
2021 /* Process range list. */
2022 unsigned int lmax = debug_info_p->max_range_lists;
2023 unsigned int num = debug_info_p->num_range_lists;
2025 if (lmax == 0 || num >= lmax)
2028 debug_info_p->range_lists = (dwarf_vma *)
2029 xcrealloc (debug_info_p->range_lists,
2030 lmax, sizeof (*debug_info_p->range_lists));
2031 debug_info_p->max_range_lists = lmax;
2033 debug_info_p->range_lists [num] = uvalue;
2034 debug_info_p->num_range_lists++;
2043 if (do_loc || attribute == 0)
2046 /* For some attributes we can display further information. */
2053 case DW_INL_not_inlined:
2054 printf (_("(not inlined)"));
2056 case DW_INL_inlined:
2057 printf (_("(inlined)"));
2059 case DW_INL_declared_not_inlined:
2060 printf (_("(declared as inline but ignored)"));
2062 case DW_INL_declared_inlined:
2063 printf (_("(declared as inline and inlined)"));
2066 printf (_(" (Unknown inline attribute value: %s)"),
2067 dwarf_vmatoa ("x", uvalue));
2072 case DW_AT_language:
2076 /* Ordered by the numeric value of these constants. */
2077 case DW_LANG_C89: printf ("(ANSI C)"); break;
2078 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2079 case DW_LANG_Ada83: printf ("(Ada)"); break;
2080 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2081 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2082 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2083 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2084 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2085 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2086 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2087 /* DWARF 2.1 values. */
2088 case DW_LANG_Java: printf ("(Java)"); break;
2089 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2090 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2091 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2092 /* DWARF 3 values. */
2093 case DW_LANG_PLI: printf ("(PLI)"); break;
2094 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2095 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2096 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2097 case DW_LANG_D: printf ("(D)"); break;
2098 /* DWARF 4 values. */
2099 case DW_LANG_Python: printf ("(Python)"); break;
2100 /* DWARF 5 values. */
2101 case DW_LANG_Go: printf ("(Go)"); break;
2102 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2103 case DW_LANG_C11: printf ("(C11)"); break;
2104 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2105 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2106 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2107 /* MIPS extension. */
2108 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2109 /* UPC extension. */
2110 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2112 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2113 printf (_("(implementation defined: %s)"),
2114 dwarf_vmatoa ("x", uvalue));
2116 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2121 case DW_AT_encoding:
2125 case DW_ATE_void: printf ("(void)"); break;
2126 case DW_ATE_address: printf ("(machine address)"); break;
2127 case DW_ATE_boolean: printf ("(boolean)"); break;
2128 case DW_ATE_complex_float: printf ("(complex float)"); break;
2129 case DW_ATE_float: printf ("(float)"); break;
2130 case DW_ATE_signed: printf ("(signed)"); break;
2131 case DW_ATE_signed_char: printf ("(signed char)"); break;
2132 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2133 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2134 /* DWARF 2.1 values: */
2135 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2136 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2137 /* DWARF 3 values: */
2138 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2139 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2140 case DW_ATE_edited: printf ("(edited)"); break;
2141 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2142 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2143 /* HP extensions: */
2144 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2145 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2146 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2147 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2148 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2149 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2150 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2151 /* DWARF 4 values: */
2152 case DW_ATE_UTF: printf ("(unicode string)"); break;
2155 if (uvalue >= DW_ATE_lo_user
2156 && uvalue <= DW_ATE_hi_user)
2157 printf (_("(user defined type)"));
2159 printf (_("(unknown type)"));
2164 case DW_AT_accessibility:
2168 case DW_ACCESS_public: printf ("(public)"); break;
2169 case DW_ACCESS_protected: printf ("(protected)"); break;
2170 case DW_ACCESS_private: printf ("(private)"); break;
2172 printf (_("(unknown accessibility)"));
2177 case DW_AT_visibility:
2181 case DW_VIS_local: printf ("(local)"); break;
2182 case DW_VIS_exported: printf ("(exported)"); break;
2183 case DW_VIS_qualified: printf ("(qualified)"); break;
2184 default: printf (_("(unknown visibility)")); break;
2188 case DW_AT_virtuality:
2192 case DW_VIRTUALITY_none: printf ("(none)"); break;
2193 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2194 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2195 default: printf (_("(unknown virtuality)")); break;
2199 case DW_AT_identifier_case:
2203 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2204 case DW_ID_up_case: printf ("(up_case)"); break;
2205 case DW_ID_down_case: printf ("(down_case)"); break;
2206 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2207 default: printf (_("(unknown case)")); break;
2211 case DW_AT_calling_convention:
2215 case DW_CC_normal: printf ("(normal)"); break;
2216 case DW_CC_program: printf ("(program)"); break;
2217 case DW_CC_nocall: printf ("(nocall)"); break;
2219 if (uvalue >= DW_CC_lo_user
2220 && uvalue <= DW_CC_hi_user)
2221 printf (_("(user defined)"));
2223 printf (_("(unknown convention)"));
2227 case DW_AT_ordering:
2231 case -1: printf (_("(undefined)")); break;
2232 case 0: printf ("(row major)"); break;
2233 case 1: printf ("(column major)"); break;
2237 case DW_AT_frame_base:
2238 have_frame_base = 1;
2240 case DW_AT_location:
2241 case DW_AT_string_length:
2242 case DW_AT_return_addr:
2243 case DW_AT_data_member_location:
2244 case DW_AT_vtable_elem_location:
2246 case DW_AT_static_link:
2247 case DW_AT_use_location:
2248 case DW_AT_call_value:
2249 case DW_AT_GNU_call_site_value:
2250 case DW_AT_call_data_value:
2251 case DW_AT_GNU_call_site_data_value:
2252 case DW_AT_call_target:
2253 case DW_AT_GNU_call_site_target:
2254 case DW_AT_call_target_clobbered:
2255 case DW_AT_GNU_call_site_target_clobbered:
2256 if ((dwarf_version < 4
2257 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2258 || form == DW_FORM_sec_offset)
2259 printf (_(" (location list)"));
2261 case DW_AT_allocated:
2262 case DW_AT_associated:
2263 case DW_AT_data_location:
2265 case DW_AT_upper_bound:
2266 case DW_AT_lower_bound:
2269 int need_frame_base;
2272 need_frame_base = decode_location_expression (block_start,
2277 cu_offset, section);
2279 if (need_frame_base && !have_frame_base)
2280 printf (_(" [without DW_AT_frame_base]"));
2286 if (form == DW_FORM_ref_sig8
2287 || form == DW_FORM_GNU_ref_alt)
2290 if (form == DW_FORM_ref1
2291 || form == DW_FORM_ref2
2292 || form == DW_FORM_ref4
2293 || form == DW_FORM_ref_udata)
2294 uvalue += cu_offset;
2296 if (uvalue >= section->size)
2297 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2298 dwarf_vmatoa ("x", uvalue),
2299 (unsigned long) (orig_data - section->start));
2302 unsigned long abbrev_number;
2303 abbrev_entry * entry;
2305 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2307 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2308 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2309 use different abbrev table, and we don't track .debug_info chunks
2311 if (form != DW_FORM_ref_addr)
2313 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2314 if (entry->entry == abbrev_number)
2317 printf (" (%s)", get_TAG_name (entry->tag));
2332 get_AT_name (unsigned long attribute)
2337 return "DW_AT value: 0";
2339 /* One value is shared by the MIPS and HP extensions: */
2340 if (attribute == DW_AT_MIPS_fde)
2341 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2343 name = get_DW_AT_name (attribute);
2347 static char buffer[100];
2349 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2357 static unsigned char *
2358 read_and_display_attr (unsigned long attribute,
2360 dwarf_signed_vma implicit_const,
2361 unsigned char * data,
2362 unsigned char * end,
2363 dwarf_vma cu_offset,
2364 dwarf_vma pointer_size,
2365 dwarf_vma offset_size,
2367 debug_info * debug_info_p,
2369 struct dwarf_section * section,
2370 struct cu_tu_set * this_set)
2373 printf (" %-18s:", get_AT_name (attribute));
2374 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2375 cu_offset, pointer_size, offset_size,
2376 dwarf_version, debug_info_p,
2377 do_loc, section, this_set, ' ');
2383 /* Process the contents of a .debug_info section. If do_loc is non-zero
2384 then we are scanning for location lists and we do not want to display
2385 anything to the user. If do_types is non-zero, we are processing
2386 a .debug_types section instead of a .debug_info section. */
2389 process_debug_info (struct dwarf_section *section,
2391 enum dwarf_section_display_enum abbrev_sec,
2395 unsigned char *start = section->start;
2396 unsigned char *end = start + section->size;
2397 unsigned char *section_begin;
2399 unsigned int num_units = 0;
2401 if ((do_loc || do_debug_loc || do_debug_ranges)
2402 && num_debug_info_entries == 0
2407 /* First scan the section to get the number of comp units. */
2408 for (section_begin = start, num_units = 0; section_begin < end;
2411 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2412 will be the length. For a 64-bit DWARF section, it'll be
2413 the escape code 0xffffffff followed by an 8 byte length. */
2414 SAFE_BYTE_GET (length, section_begin, 4, end);
2416 if (length == 0xffffffff)
2418 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2419 section_begin += length + 12;
2421 else if (length >= 0xfffffff0 && length < 0xffffffff)
2423 warn (_("Reserved length value (0x%s) found in section %s\n"),
2424 dwarf_vmatoa ("x", length), section->name);
2428 section_begin += length + 4;
2430 /* Negative values are illegal, they may even cause infinite
2431 looping. This can happen if we can't accurately apply
2432 relocations to an object file, or if the file is corrupt. */
2433 if ((signed long) length <= 0 || section_begin < start)
2435 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2436 dwarf_vmatoa ("x", length), section->name);
2443 error (_("No comp units in %s section ?\n"), section->name);
2447 /* Then allocate an array to hold the information. */
2448 debug_information = (debug_info *) cmalloc (num_units,
2449 sizeof (* debug_information));
2450 if (debug_information == NULL)
2452 error (_("Not enough memory for a debug info array of %u entries\n"),
2454 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2457 /* PR 17531: file: 92ca3797.
2458 We cannot rely upon the debug_information array being initialised
2459 before it is used. A corrupt file could easily contain references
2460 to a unit for which information has not been made available. So
2461 we ensure that the array is zeroed here. */
2462 memset (debug_information, 0, num_units * sizeof (*debug_information));
2464 alloc_num_debug_info_entries = num_units;
2469 if (dwarf_start_die == 0)
2470 printf (_("Contents of the %s section:\n\n"), section->name);
2472 load_debug_section (str, file);
2473 load_debug_section (line_str, file);
2474 load_debug_section (str_dwo, file);
2475 load_debug_section (str_index, file);
2476 load_debug_section (str_index_dwo, file);
2477 load_debug_section (debug_addr, file);
2480 load_debug_section (abbrev_sec, file);
2481 if (debug_displays [abbrev_sec].section.start == NULL)
2483 warn (_("Unable to locate %s section!\n"),
2484 debug_displays [abbrev_sec].section.name);
2488 for (section_begin = start, unit = 0; start < end; unit++)
2490 DWARF2_Internal_CompUnit compunit;
2491 unsigned char *hdrptr;
2492 unsigned char *tags;
2493 int level, last_level, saved_level;
2494 dwarf_vma cu_offset;
2495 unsigned int offset_size;
2496 int initial_length_size;
2497 dwarf_vma signature_high = 0;
2498 dwarf_vma signature_low = 0;
2499 dwarf_vma type_offset = 0;
2500 struct cu_tu_set *this_set;
2501 dwarf_vma abbrev_base;
2506 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2508 if (compunit.cu_length == 0xffffffff)
2510 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2512 initial_length_size = 12;
2517 initial_length_size = 4;
2520 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2522 cu_offset = start - section_begin;
2524 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2526 if (compunit.cu_version < 5)
2528 compunit.cu_unit_type = DW_UT_compile;
2529 /* Initialize it due to a false compiler warning. */
2530 compunit.cu_pointer_size = -1;
2534 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2535 do_types = (compunit.cu_unit_type == DW_UT_type);
2537 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2540 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2542 if (this_set == NULL)
2545 abbrev_size = debug_displays [abbrev_sec].section.size;
2549 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2550 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2553 if (compunit.cu_version < 5)
2554 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2556 /* PR 17512: file: 001-108546-0.001:0.1. */
2557 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2559 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2560 compunit.cu_pointer_size, offset_size);
2561 compunit.cu_pointer_size = offset_size;
2566 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2568 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2571 if ((do_loc || do_debug_loc || do_debug_ranges)
2572 && num_debug_info_entries == 0
2575 debug_information [unit].cu_offset = cu_offset;
2576 debug_information [unit].pointer_size
2577 = compunit.cu_pointer_size;
2578 debug_information [unit].offset_size = offset_size;
2579 debug_information [unit].dwarf_version = compunit.cu_version;
2580 debug_information [unit].base_address = 0;
2581 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2582 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2583 debug_information [unit].loc_offsets = NULL;
2584 debug_information [unit].have_frame_base = NULL;
2585 debug_information [unit].max_loc_offsets = 0;
2586 debug_information [unit].num_loc_offsets = 0;
2587 debug_information [unit].range_lists = NULL;
2588 debug_information [unit].max_range_lists= 0;
2589 debug_information [unit].num_range_lists = 0;
2592 if (!do_loc && dwarf_start_die == 0)
2594 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2595 dwarf_vmatoa ("x", cu_offset));
2596 printf (_(" Length: 0x%s (%s)\n"),
2597 dwarf_vmatoa ("x", compunit.cu_length),
2598 offset_size == 8 ? "64-bit" : "32-bit");
2599 printf (_(" Version: %d\n"), compunit.cu_version);
2600 printf (_(" Abbrev Offset: 0x%s\n"),
2601 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2602 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2607 printf (_(" Signature: 0x%s\n"),
2608 dwarf_vmatoa64 (signature_high, signature_low,
2609 buf, sizeof (buf)));
2610 printf (_(" Type Offset: 0x%s\n"),
2611 dwarf_vmatoa ("x", type_offset));
2613 if (this_set != NULL)
2615 dwarf_vma *offsets = this_set->section_offsets;
2616 size_t *sizes = this_set->section_sizes;
2618 printf (_(" Section contributions:\n"));
2619 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2620 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2621 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2622 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2623 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2624 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2625 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2626 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2627 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2628 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2629 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2630 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2634 if (cu_offset + compunit.cu_length + initial_length_size
2637 warn (_("Debug info is corrupted, length of CU at %s"
2638 " extends beyond end of section (length = %s)\n"),
2639 dwarf_vmatoa ("x", cu_offset),
2640 dwarf_vmatoa ("x", compunit.cu_length));
2645 start += compunit.cu_length + initial_length_size;
2649 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2650 dwarf_vmatoa ("x", cu_offset));
2654 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2656 warn (_("CU at offset %s contains corrupt or "
2657 "unsupported version number: %d.\n"),
2658 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2662 if (compunit.cu_unit_type != DW_UT_compile
2663 && compunit.cu_unit_type != DW_UT_type)
2665 warn (_("CU at offset %s contains corrupt or "
2666 "unsupported unit type: %d.\n"),
2667 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2673 /* Process the abbrevs used by this compilation unit. */
2674 if (compunit.cu_abbrev_offset >= abbrev_size)
2675 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2676 (unsigned long) compunit.cu_abbrev_offset,
2677 (unsigned long) abbrev_size);
2678 /* PR 17531: file:4bcd9ce9. */
2679 else if ((abbrev_base + abbrev_size)
2680 > debug_displays [abbrev_sec].section.size)
2681 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2682 (unsigned long) abbrev_base + abbrev_size,
2683 (unsigned long) debug_displays [abbrev_sec].section.size);
2685 process_abbrev_section
2686 (((unsigned char *) debug_displays [abbrev_sec].section.start
2687 + abbrev_base + compunit.cu_abbrev_offset),
2688 ((unsigned char *) debug_displays [abbrev_sec].section.start
2689 + abbrev_base + abbrev_size));
2694 while (tags < start)
2696 unsigned int bytes_read;
2697 unsigned long abbrev_number;
2698 unsigned long die_offset;
2699 abbrev_entry *entry;
2701 int do_printing = 1;
2703 die_offset = tags - section_begin;
2705 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2708 /* A null DIE marks the end of a list of siblings or it may also be
2709 a section padding. */
2710 if (abbrev_number == 0)
2712 /* Check if it can be a section padding for the last CU. */
2713 if (level == 0 && start == end)
2717 for (chk = tags; chk < start; chk++)
2724 if (!do_loc && die_offset >= dwarf_start_die
2725 && (dwarf_cutoff_level == -1
2726 || level < dwarf_cutoff_level))
2727 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2733 static unsigned num_bogus_warns = 0;
2735 if (num_bogus_warns < 3)
2737 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2738 die_offset, section->name);
2740 if (num_bogus_warns == 3)
2741 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2744 if (dwarf_start_die != 0 && level < saved_level)
2751 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2755 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2756 saved_level = level;
2757 do_printing = (dwarf_cutoff_level == -1
2758 || level < dwarf_cutoff_level);
2760 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2761 level, die_offset, abbrev_number);
2762 else if (dwarf_cutoff_level == -1
2763 || last_level < dwarf_cutoff_level)
2764 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2769 /* Scan through the abbreviation list until we reach the
2771 for (entry = first_abbrev;
2772 entry && entry->entry != abbrev_number;
2773 entry = entry->next)
2778 if (!do_loc && do_printing)
2783 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2784 die_offset, abbrev_number);
2788 if (!do_loc && do_printing)
2789 printf (" (%s)\n", get_TAG_name (entry->tag));
2794 need_base_address = 0;
2796 case DW_TAG_compile_unit:
2797 need_base_address = 1;
2799 case DW_TAG_entry_point:
2800 case DW_TAG_subprogram:
2801 need_base_address = 0;
2802 /* Assuming that there is no DW_AT_frame_base. */
2803 have_frame_base = 0;
2807 for (attr = entry->first_attr;
2808 attr && attr->attribute;
2813 if (! do_loc && do_printing)
2814 /* Show the offset from where the tag was extracted. */
2815 printf (" <%lx>", (unsigned long)(tags - section_begin));
2817 if (debug_information && unit < alloc_num_debug_info_entries)
2818 arg = debug_information + unit;
2822 tags = read_and_display_attr (attr->attribute,
2824 attr->implicit_const,
2828 compunit.cu_pointer_size,
2830 compunit.cu_version,
2832 do_loc || ! do_printing,
2837 if (entry->children)
2842 /* Set num_debug_info_entries here so that it can be used to check if
2843 we need to process .debug_loc and .debug_ranges sections. */
2844 if ((do_loc || do_debug_loc || do_debug_ranges)
2845 && num_debug_info_entries == 0
2848 if (num_units > alloc_num_debug_info_entries)
2849 num_debug_info_entries = alloc_num_debug_info_entries;
2851 num_debug_info_entries = num_units;
2860 /* Locate and scan the .debug_info section in the file and record the pointer
2861 sizes and offsets for the compilation units in it. Usually an executable
2862 will have just one pointer size, but this is not guaranteed, and so we try
2863 not to make any assumptions. Returns zero upon failure, or the number of
2864 compilation units upon success. */
2867 load_debug_info (void * file)
2869 /* Reset the last pointer size so that we can issue correct error
2870 messages if we are displaying the contents of more than one section. */
2871 last_pointer_size = 0;
2872 warned_about_missing_comp_units = FALSE;
2874 /* If we have already tried and failed to load the .debug_info
2875 section then do not bother to repeat the task. */
2876 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2879 /* If we already have the information there is nothing else to do. */
2880 if (num_debug_info_entries > 0)
2881 return num_debug_info_entries;
2883 /* If this is a DWARF package file, load the CU and TU indexes. */
2884 (void) load_cu_tu_indexes (file);
2886 if (load_debug_section (info, file)
2887 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2888 return num_debug_info_entries;
2890 if (load_debug_section (info_dwo, file)
2891 && process_debug_info (&debug_displays [info_dwo].section, file,
2893 return num_debug_info_entries;
2895 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2899 /* Read a DWARF .debug_line section header starting at DATA.
2900 Upon success returns an updated DATA pointer and the LINFO
2901 structure and the END_OF_SEQUENCE pointer will be filled in.
2902 Otherwise returns NULL. */
2904 static unsigned char *
2905 read_debug_line_header (struct dwarf_section * section,
2906 unsigned char * data,
2907 unsigned char * end,
2908 DWARF2_Internal_LineInfo * linfo,
2909 unsigned char ** end_of_sequence)
2911 unsigned char *hdrptr;
2912 unsigned int initial_length_size;
2913 unsigned char address_size, segment_selector_size;
2915 /* Extract information from the Line Number Program Header.
2916 (section 6.2.4 in the Dwarf3 doc). */
2919 /* Get and check the length of the block. */
2920 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2922 if (linfo->li_length == 0xffffffff)
2924 /* This section is 64-bit DWARF 3. */
2925 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2926 linfo->li_offset_size = 8;
2927 initial_length_size = 12;
2931 linfo->li_offset_size = 4;
2932 initial_length_size = 4;
2935 if (linfo->li_length + initial_length_size > section->size)
2937 /* If the length field has a relocation against it, then we should
2938 not complain if it is inaccurate (and probably negative). This
2939 happens in object files when the .debug_line section is actually
2940 comprised of several different .debug_line.* sections, (some of
2941 which may be removed by linker garbage collection), and a relocation
2942 is used to compute the correct length once that is done. */
2943 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
2945 linfo->li_length = (end - data) - initial_length_size;
2949 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2950 (long) linfo->li_length);
2955 /* Get and check the version number. */
2956 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2958 if (linfo->li_version != 2
2959 && linfo->li_version != 3
2960 && linfo->li_version != 4
2961 && linfo->li_version != 5)
2963 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
2964 "is currently supported.\n"));
2968 if (linfo->li_version >= 5)
2970 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
2972 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
2973 if (segment_selector_size != 0)
2975 warn (_("The %s section contains "
2976 "unsupported segment selector size: %d.\n"),
2977 section->name, segment_selector_size);
2982 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
2983 linfo->li_offset_size, end);
2984 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2986 if (linfo->li_version >= 4)
2988 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2990 if (linfo->li_max_ops_per_insn == 0)
2992 warn (_("Invalid maximum operations per insn.\n"));
2997 linfo->li_max_ops_per_insn = 1;
2999 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3000 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3001 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3002 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3004 * end_of_sequence = data + linfo->li_length + initial_length_size;
3005 /* PR 17512: file:002-117414-0.004. */
3006 if (* end_of_sequence > end)
3008 warn (_("Line length %s extends beyond end of section\n"),
3009 dwarf_vmatoa ("u", linfo->li_length));
3010 * end_of_sequence = end;
3017 static unsigned char *
3018 display_formatted_table (unsigned char *data,
3019 unsigned char *start, unsigned char *end,
3020 const DWARF2_Internal_LineInfo *linfo,
3021 struct dwarf_section *section, const char *what)
3023 unsigned char *format_start, format_count, *format, formati;
3024 dwarf_vma data_count, datai;
3025 unsigned int bytes_read, namepass, last_entry = 0;
3027 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3028 format_start = data;
3029 for (formati = 0; formati < format_count; formati++)
3031 read_uleb128 (data, & bytes_read, end);
3033 read_uleb128 (data, & bytes_read, end);
3037 warn (_("Corrupt %s entry format table entry\n"), what);
3042 data_count = read_uleb128 (data, & bytes_read, end);
3046 warn (_("Corrupt %s list\n"), what);
3050 if (data_count == 0)
3052 printf (_("\n The %s Table is empty.\n"), what);
3056 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3057 (long)(data - start));
3059 printf (_(" Entry"));
3060 /* Delay displaying name as the last entry for better screen layout. */
3061 for (namepass = 0; namepass < 2; namepass++)
3063 format = format_start;
3064 for (formati = 0; formati < format_count; formati++)
3066 dwarf_vma content_type;
3068 content_type = read_uleb128 (format, & bytes_read, end);
3069 format += bytes_read;
3070 if ((content_type == DW_LNCT_path) == (namepass == 1))
3071 switch (content_type)
3074 printf (_("\tName"));
3076 case DW_LNCT_directory_index:
3077 printf (_("\tDir"));
3079 case DW_LNCT_timestamp:
3080 printf (_("\tTime"));
3083 printf (_("\tSize"));
3086 printf (_("\tMD5"));
3089 printf (_("\t(Unknown format content type %s)"),
3090 dwarf_vmatoa ("u", content_type));
3092 read_uleb128 (format, & bytes_read, end);
3093 format += bytes_read;
3098 for (datai = 0; datai < data_count; datai++)
3100 unsigned char *datapass = data;
3102 printf (" %d", last_entry++);
3103 /* Delay displaying name as the last entry for better screen layout. */
3104 for (namepass = 0; namepass < 2; namepass++)
3106 format = format_start;
3108 for (formati = 0; formati < format_count; formati++)
3110 dwarf_vma content_type, form;
3112 content_type = read_uleb128 (format, & bytes_read, end);
3113 format += bytes_read;
3114 form = read_uleb128 (format, & bytes_read, end);
3115 format += bytes_read;
3116 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3117 linfo->li_offset_size,
3118 linfo->li_version, NULL,
3119 ((content_type == DW_LNCT_path) != (namepass == 1)),
3120 section, NULL, '\t');
3125 warn (_("Corrupt %s entries list\n"), what);
3134 display_debug_lines_raw (struct dwarf_section *section,
3135 unsigned char *data,
3136 unsigned char *end, void *file)
3138 unsigned char *start = section->start;
3140 printf (_("Raw dump of debug contents of section %s:\n\n"),
3145 static DWARF2_Internal_LineInfo saved_linfo;
3146 DWARF2_Internal_LineInfo linfo;
3147 unsigned char *standard_opcodes;
3148 unsigned char *end_of_sequence;
3151 if (const_strneq (section->name, ".debug_line.")
3152 /* Note: the following does not apply to .debug_line.dwo sections.
3153 These are full debug_line sections. */
3154 && strcmp (section->name, ".debug_line.dwo") != 0)
3156 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3157 section containing just the Line Number Statements. They are
3158 created by the assembler and intended to be used alongside gcc's
3159 -ffunction-sections command line option. When the linker's
3160 garbage collection decides to discard a .text.<foo> section it
3161 can then also discard the line number information in .debug_line.<foo>.
3163 Since the section is a fragment it does not have the details
3164 needed to fill out a LineInfo structure, so instead we use the
3165 details from the last full debug_line section that we processed. */
3166 end_of_sequence = end;
3167 standard_opcodes = NULL;
3168 linfo = saved_linfo;
3169 /* PR 17531: file: 0522b371. */
3170 if (linfo.li_line_range == 0)
3172 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3175 reset_state_machine (linfo.li_default_is_stmt);
3179 unsigned char * hdrptr;
3181 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3182 & end_of_sequence)) == NULL)
3185 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3186 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3187 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3188 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3189 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3190 if (linfo.li_version >= 4)
3191 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3192 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3193 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3194 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3195 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3197 /* PR 17512: file: 1665-6428-0.004. */
3198 if (linfo.li_line_range == 0)
3200 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3201 linfo.li_line_range = 1;
3204 reset_state_machine (linfo.li_default_is_stmt);
3206 /* Display the contents of the Opcodes table. */
3207 standard_opcodes = hdrptr;
3209 /* PR 17512: file: 002-417945-0.004. */
3210 if (standard_opcodes + linfo.li_opcode_base >= end)
3212 warn (_("Line Base extends beyond end of section\n"));
3216 printf (_("\n Opcodes:\n"));
3218 for (i = 1; i < linfo.li_opcode_base; i++)
3219 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3221 /* Display the contents of the Directory table. */
3222 data = standard_opcodes + linfo.li_opcode_base - 1;
3224 if (linfo.li_version >= 5)
3226 load_debug_section (line_str, file);
3228 data = display_formatted_table (data, start, end, &linfo, section,
3230 data = display_formatted_table (data, start, end, &linfo, section,
3236 printf (_("\n The Directory Table is empty.\n"));
3239 unsigned int last_dir_entry = 0;
3241 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3242 (long)(data - start));
3244 while (data < end && *data != 0)
3246 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3248 data += strnlen ((char *) data, end - data) + 1;
3251 /* PR 17512: file: 002-132094-0.004. */
3252 if (data >= end - 1)
3256 /* Skip the NUL at the end of the table. */
3259 /* Display the contents of the File Name table. */
3261 printf (_("\n The File Name Table is empty.\n"));
3264 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3265 (long)(data - start));
3266 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3268 while (data < end && *data != 0)
3270 unsigned char *name;
3271 unsigned int bytes_read;
3273 printf (" %d\t", ++state_machine_regs.last_file_entry);
3275 data += strnlen ((char *) data, end - data) + 1;
3278 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3281 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3284 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3286 printf ("%.*s\n", (int)(end - name), name);
3290 warn (_("Corrupt file name table entry\n"));
3296 /* Skip the NUL at the end of the table. */
3301 saved_linfo = linfo;
3304 /* Now display the statements. */
3305 if (data >= end_of_sequence)
3306 printf (_(" No Line Number Statements.\n"));
3309 printf (_(" Line Number Statements:\n"));
3311 while (data < end_of_sequence)
3313 unsigned char op_code;
3314 dwarf_signed_vma adv;
3316 unsigned int bytes_read;
3318 printf (" [0x%08lx]", (long)(data - start));
3322 if (op_code >= linfo.li_opcode_base)
3324 op_code -= linfo.li_opcode_base;
3325 uladv = (op_code / linfo.li_line_range);
3326 if (linfo.li_max_ops_per_insn == 1)
3328 uladv *= linfo.li_min_insn_length;
3329 state_machine_regs.address += uladv;
3330 printf (_(" Special opcode %d: "
3331 "advance Address by %s to 0x%s"),
3332 op_code, dwarf_vmatoa ("u", uladv),
3333 dwarf_vmatoa ("x", state_machine_regs.address));
3337 state_machine_regs.address
3338 += ((state_machine_regs.op_index + uladv)
3339 / linfo.li_max_ops_per_insn)
3340 * linfo.li_min_insn_length;
3341 state_machine_regs.op_index
3342 = (state_machine_regs.op_index + uladv)
3343 % linfo.li_max_ops_per_insn;
3344 printf (_(" Special opcode %d: "
3345 "advance Address by %s to 0x%s[%d]"),
3346 op_code, dwarf_vmatoa ("u", uladv),
3347 dwarf_vmatoa ("x", state_machine_regs.address),
3348 state_machine_regs.op_index);
3350 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3351 state_machine_regs.line += adv;
3352 printf (_(" and Line by %s to %d\n"),
3353 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3355 else switch (op_code)
3357 case DW_LNS_extended_op:
3358 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3362 printf (_(" Copy\n"));
3365 case DW_LNS_advance_pc:
3366 uladv = read_uleb128 (data, & bytes_read, end);
3368 if (linfo.li_max_ops_per_insn == 1)
3370 uladv *= linfo.li_min_insn_length;
3371 state_machine_regs.address += uladv;
3372 printf (_(" Advance PC by %s to 0x%s\n"),
3373 dwarf_vmatoa ("u", uladv),
3374 dwarf_vmatoa ("x", state_machine_regs.address));
3378 state_machine_regs.address
3379 += ((state_machine_regs.op_index + uladv)
3380 / linfo.li_max_ops_per_insn)
3381 * linfo.li_min_insn_length;
3382 state_machine_regs.op_index
3383 = (state_machine_regs.op_index + uladv)
3384 % linfo.li_max_ops_per_insn;
3385 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3386 dwarf_vmatoa ("u", uladv),
3387 dwarf_vmatoa ("x", state_machine_regs.address),
3388 state_machine_regs.op_index);
3392 case DW_LNS_advance_line:
3393 adv = read_sleb128 (data, & bytes_read, end);
3395 state_machine_regs.line += adv;
3396 printf (_(" Advance Line by %s to %d\n"),
3397 dwarf_vmatoa ("d", adv),
3398 state_machine_regs.line);
3401 case DW_LNS_set_file:
3402 adv = read_uleb128 (data, & bytes_read, end);
3404 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3405 dwarf_vmatoa ("d", adv));
3406 state_machine_regs.file = adv;
3409 case DW_LNS_set_column:
3410 uladv = read_uleb128 (data, & bytes_read, end);
3412 printf (_(" Set column to %s\n"),
3413 dwarf_vmatoa ("u", uladv));
3414 state_machine_regs.column = uladv;
3417 case DW_LNS_negate_stmt:
3418 adv = state_machine_regs.is_stmt;
3420 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3421 state_machine_regs.is_stmt = adv;
3424 case DW_LNS_set_basic_block:
3425 printf (_(" Set basic block\n"));
3426 state_machine_regs.basic_block = 1;
3429 case DW_LNS_const_add_pc:
3430 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3431 if (linfo.li_max_ops_per_insn)
3433 uladv *= linfo.li_min_insn_length;
3434 state_machine_regs.address += uladv;
3435 printf (_(" Advance PC by constant %s to 0x%s\n"),
3436 dwarf_vmatoa ("u", uladv),
3437 dwarf_vmatoa ("x", state_machine_regs.address));
3441 state_machine_regs.address
3442 += ((state_machine_regs.op_index + uladv)
3443 / linfo.li_max_ops_per_insn)
3444 * linfo.li_min_insn_length;
3445 state_machine_regs.op_index
3446 = (state_machine_regs.op_index + uladv)
3447 % linfo.li_max_ops_per_insn;
3448 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3449 dwarf_vmatoa ("u", uladv),
3450 dwarf_vmatoa ("x", state_machine_regs.address),
3451 state_machine_regs.op_index);
3455 case DW_LNS_fixed_advance_pc:
3456 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3457 state_machine_regs.address += uladv;
3458 state_machine_regs.op_index = 0;
3459 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3460 dwarf_vmatoa ("u", uladv),
3461 dwarf_vmatoa ("x", state_machine_regs.address));
3464 case DW_LNS_set_prologue_end:
3465 printf (_(" Set prologue_end to true\n"));
3468 case DW_LNS_set_epilogue_begin:
3469 printf (_(" Set epilogue_begin to true\n"));
3472 case DW_LNS_set_isa:
3473 uladv = read_uleb128 (data, & bytes_read, end);
3475 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3479 printf (_(" Unknown opcode %d with operands: "), op_code);
3481 if (standard_opcodes != NULL)
3482 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3484 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3486 i == 1 ? "" : ", ");
3502 unsigned char *name;
3503 unsigned int directory_index;
3504 unsigned int modification_date;
3505 unsigned int length;
3508 /* Output a decoded representation of the .debug_line section. */
3511 display_debug_lines_decoded (struct dwarf_section *section,
3512 unsigned char *data,
3513 unsigned char *end, void *fileptr)
3515 static DWARF2_Internal_LineInfo saved_linfo;
3517 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3522 /* This loop amounts to one iteration per compilation unit. */
3523 DWARF2_Internal_LineInfo linfo;
3524 unsigned char *standard_opcodes;
3525 unsigned char *end_of_sequence;
3527 File_Entry *file_table = NULL;
3528 unsigned int n_files = 0;
3529 unsigned char **directory_table = NULL;
3530 dwarf_vma n_directories = 0;
3532 if (const_strneq (section->name, ".debug_line.")
3533 /* Note: the following does not apply to .debug_line.dwo sections.
3534 These are full debug_line sections. */
3535 && strcmp (section->name, ".debug_line.dwo") != 0)
3537 /* See comment in display_debug_lines_raw(). */
3538 end_of_sequence = end;
3539 standard_opcodes = NULL;
3540 linfo = saved_linfo;
3541 /* PR 17531: file: 0522b371. */
3542 if (linfo.li_line_range == 0)
3544 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3547 reset_state_machine (linfo.li_default_is_stmt);
3551 unsigned char *hdrptr;
3553 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3554 & end_of_sequence)) == NULL)
3557 /* PR 17531: file: 0522b371. */
3558 if (linfo.li_line_range == 0)
3560 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3561 linfo.li_line_range = 1;
3563 reset_state_machine (linfo.li_default_is_stmt);
3565 /* Save a pointer to the contents of the Opcodes table. */
3566 standard_opcodes = hdrptr;
3568 /* Traverse the Directory table just to count entries. */
3569 data = standard_opcodes + linfo.li_opcode_base - 1;
3573 warn (_("opcode base of %d extends beyond end of section\n"),
3574 linfo.li_opcode_base);
3578 if (linfo.li_version >= 5)
3580 unsigned char *format_start, format_count, *format;
3581 dwarf_vma formati, entryi;
3582 unsigned int bytes_read;
3584 load_debug_section (line_str, fileptr);
3586 /* Skip directories format. */
3587 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3588 format_start = data;
3589 for (formati = 0; formati < format_count; formati++)
3591 read_uleb128 (data, & bytes_read, end);
3593 read_uleb128 (data, & bytes_read, end);
3597 n_directories = read_uleb128 (data, & bytes_read, end);
3601 warn (_("Corrupt directories list\n"));
3605 directory_table = (unsigned char **)
3606 xmalloc (n_directories * sizeof (unsigned char *));
3608 for (entryi = 0; entryi < n_directories; entryi++)
3610 unsigned char **pathp = &directory_table[entryi];
3612 format = format_start;
3613 for (formati = 0; formati < format_count; formati++)
3615 dwarf_vma content_type, form;
3618 content_type = read_uleb128 (format, & bytes_read, end);
3619 format += bytes_read;
3620 form = read_uleb128 (format, & bytes_read, end);
3621 format += bytes_read;
3624 warn (_("Corrupt directories list\n"));
3627 switch (content_type)
3632 case DW_FORM_string:
3635 case DW_FORM_line_strp:
3636 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3638 /* Remove const by the cast. */
3639 *pathp = (unsigned char *)
3640 fetch_indirect_line_string (uvalue);
3645 data = read_and_display_attr_value (0, form, 0, data, end,
3647 linfo.li_offset_size,
3654 warn (_("Corrupt directories list\n"));
3659 /* Skip files format. */
3660 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3661 format_start = data;
3662 for (formati = 0; formati < format_count; formati++)
3664 read_uleb128 (data, & bytes_read, end);
3666 read_uleb128 (data, & bytes_read, end);
3670 n_files = read_uleb128 (data, & bytes_read, end);
3674 warn (_("Corrupt file name list\n"));
3678 file_table = (File_Entry *) xcalloc (1, n_files
3679 * sizeof (File_Entry));
3681 for (entryi = 0; entryi < n_files; entryi++)
3683 File_Entry *file = &file_table[entryi];
3685 format = format_start;
3686 for (formati = 0; formati < format_count; formati++)
3688 dwarf_vma content_type, form;
3691 content_type = read_uleb128 (format, & bytes_read, end);
3692 format += bytes_read;
3693 form = read_uleb128 (format, & bytes_read, end);
3694 format += bytes_read;
3697 warn (_("Corrupt file name list\n"));
3700 switch (content_type)
3705 case DW_FORM_string:
3708 case DW_FORM_line_strp:
3709 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3711 /* Remove const by the cast. */
3712 file->name = (unsigned char *)
3713 fetch_indirect_line_string (uvalue);
3717 case DW_LNCT_directory_index:
3721 SAFE_BYTE_GET (file->directory_index, data, 1,
3725 SAFE_BYTE_GET (file->directory_index, data, 2,
3729 file->directory_index = read_uleb128 (data, NULL,
3735 data = read_and_display_attr_value (0, form, 0, data, end,
3737 linfo.li_offset_size,
3744 warn (_("Corrupt file name list\n"));
3753 unsigned char *ptr_directory_table = data;
3755 while (data < end && *data != 0)
3757 data += strnlen ((char *) data, end - data) + 1;
3764 warn (_("directory table ends unexpectedly\n"));
3769 /* Go through the directory table again to save the directories. */
3770 directory_table = (unsigned char **)
3771 xmalloc (n_directories * sizeof (unsigned char *));
3774 while (*ptr_directory_table != 0)
3776 directory_table[i] = ptr_directory_table;
3777 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3778 ptr_directory_table - end) + 1;
3782 /* Skip the NUL at the end of the table. */
3785 /* Traverse the File Name table just to count the entries. */
3786 if (data < end && *data != 0)
3788 unsigned char *ptr_file_name_table = data;
3790 while (data < end && *data != 0)
3792 unsigned int bytes_read;
3794 /* Skip Name, directory index, last modification time and length
3796 data += strnlen ((char *) data, end - data) + 1;
3797 read_uleb128 (data, & bytes_read, end);
3799 read_uleb128 (data, & bytes_read, end);
3801 read_uleb128 (data, & bytes_read, end);
3809 warn (_("file table ends unexpectedly\n"));
3814 /* Go through the file table again to save the strings. */
3815 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3818 while (*ptr_file_name_table != 0)
3820 unsigned int bytes_read;
3822 file_table[i].name = ptr_file_name_table;
3823 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3824 end - ptr_file_name_table) + 1;
3826 /* We are not interested in directory, time or size. */
3827 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3829 ptr_file_name_table += bytes_read;
3830 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3832 ptr_file_name_table += bytes_read;
3833 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3834 ptr_file_name_table += bytes_read;
3840 /* Skip the NUL at the end of the table. */
3844 /* Print the Compilation Unit's name and a header. */
3845 if (file_table == NULL)
3847 else if (directory_table == NULL)
3848 printf (_("CU: %s:\n"), file_table[0].name);
3851 unsigned int ix = file_table[0].directory_index;
3852 const char *directory;
3857 else if (n_directories == 0)
3858 directory = _("<unknown>");
3859 else if (ix > n_directories)
3861 warn (_("directory index %u > number of directories %s\n"),
3862 ix, dwarf_vmatoa ("u", n_directories));
3863 directory = _("<corrupt>");
3866 directory = (char *) directory_table[ix - 1];
3868 if (do_wide || strlen (directory) < 76)
3869 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3871 printf ("%s:\n", file_table[0].name);
3874 printf (_("File name Line number Starting address\n"));
3875 saved_linfo = linfo;
3878 /* This loop iterates through the Dwarf Line Number Program. */
3879 while (data < end_of_sequence)
3881 unsigned char op_code;
3883 unsigned long int uladv;
3884 unsigned int bytes_read;
3885 int is_special_opcode = 0;
3889 if (op_code >= linfo.li_opcode_base)
3891 op_code -= linfo.li_opcode_base;
3892 uladv = (op_code / linfo.li_line_range);
3893 if (linfo.li_max_ops_per_insn == 1)
3895 uladv *= linfo.li_min_insn_length;
3896 state_machine_regs.address += uladv;
3900 state_machine_regs.address
3901 += ((state_machine_regs.op_index + uladv)
3902 / linfo.li_max_ops_per_insn)
3903 * linfo.li_min_insn_length;
3904 state_machine_regs.op_index
3905 = (state_machine_regs.op_index + uladv)
3906 % linfo.li_max_ops_per_insn;
3909 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3910 state_machine_regs.line += adv;
3911 is_special_opcode = 1;
3913 else switch (op_code)
3915 case DW_LNS_extended_op:
3917 unsigned int ext_op_code_len;
3918 unsigned char ext_op_code;
3919 unsigned char *op_code_data = data;
3921 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3923 op_code_data += bytes_read;
3925 if (ext_op_code_len == 0)
3927 warn (_("Badly formed extended line op encountered!\n"));
3930 ext_op_code_len += bytes_read;
3931 ext_op_code = *op_code_data++;
3933 switch (ext_op_code)
3935 case DW_LNE_end_sequence:
3936 reset_state_machine (linfo.li_default_is_stmt);
3938 case DW_LNE_set_address:
3939 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3941 ext_op_code_len - bytes_read - 1,
3943 state_machine_regs.op_index = 0;
3945 case DW_LNE_define_file:
3947 file_table = (File_Entry *) xrealloc
3948 (file_table, (n_files + 1) * sizeof (File_Entry));
3950 ++state_machine_regs.last_file_entry;
3951 /* Source file name. */
3952 file_table[n_files].name = op_code_data;
3953 op_code_data += strlen ((char *) op_code_data) + 1;
3954 /* Directory index. */
3955 file_table[n_files].directory_index =
3956 read_uleb128 (op_code_data, & bytes_read,
3958 op_code_data += bytes_read;
3959 /* Last modification time. */
3960 file_table[n_files].modification_date =
3961 read_uleb128 (op_code_data, & bytes_read,
3963 op_code_data += bytes_read;
3965 file_table[n_files].length =
3966 read_uleb128 (op_code_data, & bytes_read,
3972 case DW_LNE_set_discriminator:
3973 case DW_LNE_HP_set_sequence:
3974 /* Simply ignored. */
3978 printf (_("UNKNOWN (%u): length %d\n"),
3979 ext_op_code, ext_op_code_len - bytes_read);
3982 data += ext_op_code_len;
3988 case DW_LNS_advance_pc:
3989 uladv = read_uleb128 (data, & bytes_read, end);
3991 if (linfo.li_max_ops_per_insn == 1)
3993 uladv *= linfo.li_min_insn_length;
3994 state_machine_regs.address += uladv;
3998 state_machine_regs.address
3999 += ((state_machine_regs.op_index + uladv)
4000 / linfo.li_max_ops_per_insn)
4001 * linfo.li_min_insn_length;
4002 state_machine_regs.op_index
4003 = (state_machine_regs.op_index + uladv)
4004 % linfo.li_max_ops_per_insn;
4008 case DW_LNS_advance_line:
4009 adv = read_sleb128 (data, & bytes_read, end);
4011 state_machine_regs.line += adv;
4014 case DW_LNS_set_file:
4015 adv = read_uleb128 (data, & bytes_read, end);
4017 state_machine_regs.file = adv;
4020 unsigned file = state_machine_regs.file - 1;
4023 if (file_table == NULL || n_files == 0)
4024 printf (_("\n [Use file table entry %d]\n"), file);
4026 else if (file >= n_files)
4028 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4029 printf (_("\n <over large file table index %u>"), file);
4031 else if ((dir = file_table[file].directory_index) == 0)
4032 /* If directory index is 0, that means current directory. */
4033 printf ("\n./%s:[++]\n", file_table[file].name);
4034 else if (directory_table == NULL || n_directories == 0)
4035 printf (_("\n [Use file %s in directory table entry %d]\n"),
4036 file_table[file].name, dir);
4038 else if (dir > n_directories)
4040 warn (_("directory index %u > number of directories %s\n"),
4041 dir, dwarf_vmatoa ("u", n_directories));
4042 printf (_("\n <over large directory table entry %u>\n"), dir);
4045 printf ("\n%s/%s:\n",
4046 /* The directory index starts counting at 1. */
4047 directory_table[dir - 1], file_table[file].name);
4051 case DW_LNS_set_column:
4052 uladv = read_uleb128 (data, & bytes_read, end);
4054 state_machine_regs.column = uladv;
4057 case DW_LNS_negate_stmt:
4058 adv = state_machine_regs.is_stmt;
4060 state_machine_regs.is_stmt = adv;
4063 case DW_LNS_set_basic_block:
4064 state_machine_regs.basic_block = 1;
4067 case DW_LNS_const_add_pc:
4068 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4069 if (linfo.li_max_ops_per_insn == 1)
4071 uladv *= linfo.li_min_insn_length;
4072 state_machine_regs.address += uladv;
4076 state_machine_regs.address
4077 += ((state_machine_regs.op_index + uladv)
4078 / linfo.li_max_ops_per_insn)
4079 * linfo.li_min_insn_length;
4080 state_machine_regs.op_index
4081 = (state_machine_regs.op_index + uladv)
4082 % linfo.li_max_ops_per_insn;
4086 case DW_LNS_fixed_advance_pc:
4087 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4088 state_machine_regs.address += uladv;
4089 state_machine_regs.op_index = 0;
4092 case DW_LNS_set_prologue_end:
4095 case DW_LNS_set_epilogue_begin:
4098 case DW_LNS_set_isa:
4099 uladv = read_uleb128 (data, & bytes_read, end);
4101 printf (_(" Set ISA to %lu\n"), uladv);
4105 printf (_(" Unknown opcode %d with operands: "), op_code);
4107 if (standard_opcodes != NULL)
4108 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4110 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4112 i == 1 ? "" : ", ");
4119 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4120 to the DWARF address/line matrix. */
4121 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
4122 || (op_code == DW_LNS_copy))
4124 const unsigned int MAX_FILENAME_LENGTH = 35;
4126 char *newFileName = NULL;
4127 size_t fileNameLength;
4131 unsigned indx = state_machine_regs.file - 1;
4133 if (indx >= n_files)
4135 warn (_("corrupt file index %u encountered\n"), indx);
4136 fileName = _("<corrupt>");
4139 fileName = (char *) file_table[indx].name;
4142 fileName = _("<unknown>");
4144 fileNameLength = strlen (fileName);
4146 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4148 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4149 /* Truncate file name */
4150 strncpy (newFileName,
4151 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4152 MAX_FILENAME_LENGTH + 1);
4156 newFileName = (char *) xmalloc (fileNameLength + 1);
4157 strncpy (newFileName, fileName, fileNameLength + 1);
4160 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4162 if (linfo.li_max_ops_per_insn == 1)
4163 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
4164 newFileName, state_machine_regs.line,
4165 state_machine_regs.address);
4167 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4168 newFileName, state_machine_regs.line,
4169 state_machine_regs.address,
4170 state_machine_regs.op_index);
4174 if (linfo.li_max_ops_per_insn == 1)
4175 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
4176 newFileName, state_machine_regs.line,
4177 state_machine_regs.address);
4179 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
4180 newFileName, state_machine_regs.line,
4181 state_machine_regs.address,
4182 state_machine_regs.op_index);
4185 if (op_code == DW_LNE_end_sequence)
4199 if (directory_table)
4201 free (directory_table);
4202 directory_table = NULL;
4213 display_debug_lines (struct dwarf_section *section, void *file)
4215 unsigned char *data = section->start;
4216 unsigned char *end = data + section->size;
4218 int retValDecoded = 1;
4220 if (do_debug_lines == 0)
4221 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4223 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4224 retValRaw = display_debug_lines_raw (section, data, end, file);
4226 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4227 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4229 if (!retValRaw || !retValDecoded)
4236 find_debug_info_for_offset (unsigned long offset)
4240 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4243 for (i = 0; i < num_debug_info_entries; i++)
4244 if (debug_information[i].cu_offset == offset)
4245 return debug_information + i;
4251 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4253 /* See gdb/gdb-index.h. */
4254 static const char * const kinds[] =
4266 return _ (kinds[kind]);
4270 display_debug_pubnames_worker (struct dwarf_section *section,
4271 void *file ATTRIBUTE_UNUSED,
4274 DWARF2_Internal_PubNames names;
4275 unsigned char *start = section->start;
4276 unsigned char *end = start + section->size;
4278 /* It does not matter if this load fails,
4279 we test for that later on. */
4280 load_debug_info (file);
4282 printf (_("Contents of the %s section:\n\n"), section->name);
4286 unsigned char *data;
4289 unsigned int offset_size, initial_length_size;
4293 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4294 if (names.pn_length == 0xffffffff)
4296 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4298 initial_length_size = 12;
4303 initial_length_size = 4;
4306 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4307 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4309 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4310 && num_debug_info_entries > 0
4311 && find_debug_info_for_offset (names.pn_offset) == NULL)
4312 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4313 (unsigned long) names.pn_offset, section->name);
4315 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4317 adr = start + names.pn_length + initial_length_size;
4318 /* PR 17531: file: 7615b6b2. */
4319 if ((dwarf_signed_vma) names.pn_length < 0
4320 /* PR 17531: file: a5dbeaa7. */
4323 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4329 printf (_(" Length: %ld\n"),
4330 (long) names.pn_length);
4331 printf (_(" Version: %d\n"),
4333 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4334 (unsigned long) names.pn_offset);
4335 printf (_(" Size of area in .debug_info section: %ld\n"),
4336 (long) names.pn_size);
4338 if (names.pn_version != 2 && names.pn_version != 3)
4340 static int warned = 0;
4344 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4352 printf (_("\n Offset Kind Name\n"));
4354 printf (_("\n Offset\tName\n"));
4358 bfd_size_type maxprint;
4360 SAFE_BYTE_GET (offset, data, offset_size, end);
4364 data += offset_size;
4367 maxprint = (end - data) - 1;
4371 unsigned int kind_data;
4372 gdb_index_symbol_kind kind;
4373 const char *kind_name;
4376 SAFE_BYTE_GET (kind_data, data, 1, end);
4379 /* GCC computes the kind as the upper byte in the CU index
4380 word, and then right shifts it by the CU index size.
4381 Left shift KIND to where the gdb-index.h accessor macros
4383 kind_data <<= GDB_INDEX_CU_BITSIZE;
4384 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4385 kind_name = get_gdb_index_symbol_kind_name (kind);
4386 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4387 printf (" %-6lx %s,%-10s %.*s\n",
4388 (unsigned long) offset, is_static ? _("s") : _("g"),
4389 kind_name, (int) maxprint, data);
4392 printf (" %-6lx\t%.*s\n",
4393 (unsigned long) offset, (int) maxprint, data);
4395 data += strnlen ((char *) data, maxprint) + 1;
4400 while (offset != 0);
4408 display_debug_pubnames (struct dwarf_section *section, void *file)
4410 return display_debug_pubnames_worker (section, file, 0);
4414 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4416 return display_debug_pubnames_worker (section, file, 1);
4420 display_debug_macinfo (struct dwarf_section *section,
4421 void *file ATTRIBUTE_UNUSED)
4423 unsigned char *start = section->start;
4424 unsigned char *end = start + section->size;
4425 unsigned char *curr = start;
4426 unsigned int bytes_read;
4427 enum dwarf_macinfo_record_type op;
4429 printf (_("Contents of the %s section:\n\n"), section->name);
4433 unsigned int lineno;
4434 const unsigned char *string;
4436 op = (enum dwarf_macinfo_record_type) *curr;
4441 case DW_MACINFO_start_file:
4443 unsigned int filenum;
4445 lineno = read_uleb128 (curr, & bytes_read, end);
4447 filenum = read_uleb128 (curr, & bytes_read, end);
4450 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4455 case DW_MACINFO_end_file:
4456 printf (_(" DW_MACINFO_end_file\n"));
4459 case DW_MACINFO_define:
4460 lineno = read_uleb128 (curr, & bytes_read, end);
4463 curr += strnlen ((char *) string, end - string) + 1;
4464 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4468 case DW_MACINFO_undef:
4469 lineno = read_uleb128 (curr, & bytes_read, end);
4472 curr += strnlen ((char *) string, end - string) + 1;
4473 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4477 case DW_MACINFO_vendor_ext:
4479 unsigned int constant;
4481 constant = read_uleb128 (curr, & bytes_read, end);
4484 curr += strnlen ((char *) string, end - string) + 1;
4485 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4495 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4496 filename and dirname corresponding to file name table entry with index
4497 FILEIDX. Return NULL on failure. */
4499 static unsigned char *
4500 get_line_filename_and_dirname (dwarf_vma line_offset,
4502 unsigned char **dir_name)
4504 struct dwarf_section *section = &debug_displays [line].section;
4505 unsigned char *hdrptr, *dirtable, *file_name;
4506 unsigned int offset_size, initial_length_size;
4507 unsigned int version, opcode_base, bytes_read;
4508 dwarf_vma length, diridx;
4509 const unsigned char * end;
4512 if (section->start == NULL
4513 || line_offset >= section->size
4517 hdrptr = section->start + line_offset;
4518 end = section->start + section->size;
4520 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4521 if (length == 0xffffffff)
4523 /* This section is 64-bit DWARF 3. */
4524 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4526 initial_length_size = 12;
4531 initial_length_size = 4;
4533 if (length + initial_length_size > section->size)
4536 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4537 if (version != 2 && version != 3 && version != 4)
4539 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4541 hdrptr++; /* Skip max_ops_per_insn. */
4542 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4544 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4545 if (opcode_base == 0)
4548 hdrptr += opcode_base - 1;
4550 /* Skip over dirname table. */
4551 while (*hdrptr != '\0')
4552 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4553 hdrptr++; /* Skip the NUL at the end of the table. */
4554 /* Now skip over preceding filename table entries. */
4555 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4557 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4558 read_uleb128 (hdrptr, &bytes_read, end);
4559 hdrptr += bytes_read;
4560 read_uleb128 (hdrptr, &bytes_read, end);
4561 hdrptr += bytes_read;
4562 read_uleb128 (hdrptr, &bytes_read, end);
4563 hdrptr += bytes_read;
4565 if (hdrptr == end || *hdrptr == '\0')
4568 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4569 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4572 for (; *dirtable != '\0' && diridx > 1; diridx--)
4573 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4574 if (*dirtable == '\0')
4576 *dir_name = dirtable;
4581 display_debug_macro (struct dwarf_section *section,
4584 unsigned char *start = section->start;
4585 unsigned char *end = start + section->size;
4586 unsigned char *curr = start;
4587 unsigned char *extended_op_buf[256];
4588 unsigned int bytes_read;
4590 load_debug_section (str, file);
4591 load_debug_section (line, file);
4593 printf (_("Contents of the %s section:\n\n"), section->name);
4597 unsigned int lineno, version, flags;
4598 unsigned int offset_size = 4;
4599 const unsigned char *string;
4600 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4601 unsigned char **extended_ops = NULL;
4603 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4604 if (version != 4 && version != 5)
4606 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4611 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4614 printf (_(" Offset: 0x%lx\n"),
4615 (unsigned long) sec_offset);
4616 printf (_(" Version: %d\n"), version);
4617 printf (_(" Offset size: %d\n"), offset_size);
4620 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4621 printf (_(" Offset into .debug_line: 0x%lx\n"),
4622 (unsigned long) line_offset);
4626 unsigned int i, count, op;
4629 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4631 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4632 extended_ops = extended_op_buf;
4635 printf (_(" Extension opcode arguments:\n"));
4636 for (i = 0; i < count; i++)
4638 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4639 extended_ops[op] = curr;
4640 nargs = read_uleb128 (curr, &bytes_read, end);
4643 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4646 printf (_(" DW_MACRO_%02x arguments: "), op);
4647 for (n = 0; n < nargs; n++)
4651 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4652 printf ("%s%s", get_FORM_name (form),
4653 n == nargs - 1 ? "\n" : ", ");
4663 case DW_FORM_block1:
4664 case DW_FORM_block2:
4665 case DW_FORM_block4:
4667 case DW_FORM_string:
4669 case DW_FORM_sec_offset:
4672 error (_("Invalid extension opcode form %s\n"),
4673 get_FORM_name (form));
4689 error (_(".debug_macro section not zero terminated\n"));
4693 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4699 case DW_MACRO_start_file:
4701 unsigned int filenum;
4702 unsigned char *file_name = NULL, *dir_name = NULL;
4704 lineno = read_uleb128 (curr, &bytes_read, end);
4706 filenum = read_uleb128 (curr, &bytes_read, end);
4709 if ((flags & 2) == 0)
4710 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4713 = get_line_filename_and_dirname (line_offset, filenum,
4715 if (file_name == NULL)
4716 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4719 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4721 dir_name != NULL ? (const char *) dir_name : "",
4722 dir_name != NULL ? "/" : "", file_name);
4726 case DW_MACRO_end_file:
4727 printf (_(" DW_MACRO_end_file\n"));
4730 case DW_MACRO_define:
4731 lineno = read_uleb128 (curr, &bytes_read, end);
4734 curr += strnlen ((char *) string, end - string) + 1;
4735 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4739 case DW_MACRO_undef:
4740 lineno = read_uleb128 (curr, &bytes_read, end);
4743 curr += strnlen ((char *) string, end - string) + 1;
4744 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4748 case DW_MACRO_define_strp:
4749 lineno = read_uleb128 (curr, &bytes_read, end);
4751 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4752 string = fetch_indirect_string (offset);
4753 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4757 case DW_MACRO_undef_strp:
4758 lineno = read_uleb128 (curr, &bytes_read, end);
4760 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4761 string = fetch_indirect_string (offset);
4762 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4766 case DW_MACRO_import:
4767 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4768 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4769 (unsigned long) offset);
4772 case DW_MACRO_define_sup:
4773 lineno = read_uleb128 (curr, &bytes_read, end);
4775 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4776 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4777 lineno, (unsigned long) offset);
4780 case DW_MACRO_undef_sup:
4781 lineno = read_uleb128 (curr, &bytes_read, end);
4783 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4784 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4785 lineno, (unsigned long) offset);
4788 case DW_MACRO_import_sup:
4789 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4790 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4791 (unsigned long) offset);
4795 if (extended_ops == NULL || extended_ops[op] == NULL)
4797 error (_(" Unknown macro opcode %02x seen\n"), op);
4802 /* Skip over unhandled opcodes. */
4804 unsigned char *desc = extended_ops[op];
4805 nargs = read_uleb128 (desc, &bytes_read, end);
4809 printf (_(" DW_MACRO_%02x\n"), op);
4812 printf (_(" DW_MACRO_%02x -"), op);
4813 for (n = 0; n < nargs; n++)
4817 /* DW_FORM_implicit_const is not expected here. */
4818 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4820 = read_and_display_attr_value (0, val, 0,
4821 curr, end, 0, 0, offset_size,
4822 version, NULL, 0, NULL,
4840 display_debug_abbrev (struct dwarf_section *section,
4841 void *file ATTRIBUTE_UNUSED)
4843 abbrev_entry *entry;
4844 unsigned char *start = section->start;
4845 unsigned char *end = start + section->size;
4847 printf (_("Contents of the %s section:\n\n"), section->name);
4851 unsigned char *last;
4856 start = process_abbrev_section (start, end);
4858 if (first_abbrev == NULL)
4861 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4863 for (entry = first_abbrev; entry; entry = entry->next)
4867 printf (" %ld %s [%s]\n",
4869 get_TAG_name (entry->tag),
4870 entry->children ? _("has children") : _("no children"));
4872 for (attr = entry->first_attr; attr; attr = attr->next)
4874 printf (" %-18s %s",
4875 get_AT_name (attr->attribute),
4876 get_FORM_name (attr->form));
4877 if (attr->form == DW_FORM_implicit_const)
4878 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
4890 /* Return true when ADDR is the maximum address, when addresses are
4891 POINTER_SIZE bytes long. */
4894 is_max_address (dwarf_vma addr, unsigned int pointer_size)
4896 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
4897 return ((addr & mask) == mask);
4900 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4903 display_loc_list (struct dwarf_section *section,
4904 unsigned char **start_ptr,
4905 unsigned int debug_info_entry,
4907 dwarf_vma base_address,
4910 unsigned char *start = *start_ptr;
4911 unsigned char *section_end = section->start + section->size;
4912 unsigned long cu_offset;
4913 unsigned int pointer_size;
4914 unsigned int offset_size;
4919 unsigned short length;
4920 int need_frame_base;
4922 if (debug_info_entry >= num_debug_info_entries)
4924 warn (_("No debug information available for loc lists of entry: %u\n"),
4929 cu_offset = debug_information [debug_info_entry].cu_offset;
4930 pointer_size = debug_information [debug_info_entry].pointer_size;
4931 offset_size = debug_information [debug_info_entry].offset_size;
4932 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4934 if (pointer_size < 2 || pointer_size > 8)
4936 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4937 pointer_size, debug_info_entry);
4943 dwarf_vma off = offset + (start - *start_ptr);
4945 if (start + 2 * pointer_size > section_end)
4947 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4948 (unsigned long) offset);
4952 printf (" %8.8lx ", (unsigned long) off);
4954 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4955 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4957 if (begin == 0 && end == 0)
4959 /* PR 18374: In a object file we can have a location list that
4960 starts with a begin and end of 0 because there are relocations
4961 that need to be applied to the addresses. Actually applying
4962 the relocations now does not help as they will probably resolve
4963 to 0, since the object file has not been fully linked. Real
4964 end of list markers will not have any relocations against them. */
4965 if (! reloc_at (section, off)
4966 && ! reloc_at (section, off + pointer_size))
4968 printf (_("<End of list>\n"));
4973 /* Check base address specifiers. */
4974 if (is_max_address (begin, pointer_size)
4975 && !is_max_address (end, pointer_size))
4978 print_dwarf_vma (begin, pointer_size);
4979 print_dwarf_vma (end, pointer_size);
4980 printf (_("(base address)\n"));
4984 if (start + 2 > section_end)
4986 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4987 (unsigned long) offset);
4991 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4993 if (start + length > section_end)
4995 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4996 (unsigned long) offset);
5000 print_dwarf_vma (begin + base_address, pointer_size);
5001 print_dwarf_vma (end + base_address, pointer_size);
5004 need_frame_base = decode_location_expression (start,
5009 cu_offset, section);
5012 if (need_frame_base && !has_frame_base)
5013 printf (_(" [without DW_AT_frame_base]"));
5016 fputs (_(" (start == end)"), stdout);
5017 else if (begin > end)
5018 fputs (_(" (start > end)"), stdout);
5028 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5031 display_loclists_list (struct dwarf_section *section,
5032 unsigned char **start_ptr,
5033 unsigned int debug_info_entry,
5035 dwarf_vma base_address,
5038 unsigned char *start = *start_ptr;
5039 unsigned char *section_end = section->start + section->size;
5040 unsigned long cu_offset;
5041 unsigned int pointer_size;
5042 unsigned int offset_size;
5044 unsigned int bytes_read;
5046 /* Initialize it due to a false compiler warning. */
5047 dwarf_vma begin = -1;
5050 int need_frame_base;
5052 if (debug_info_entry >= num_debug_info_entries)
5054 warn (_("No debug information available for "
5055 "loclists lists of entry: %u\n"),
5060 cu_offset = debug_information [debug_info_entry].cu_offset;
5061 pointer_size = debug_information [debug_info_entry].pointer_size;
5062 offset_size = debug_information [debug_info_entry].offset_size;
5063 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5065 if (pointer_size < 2 || pointer_size > 8)
5067 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5068 pointer_size, debug_info_entry);
5074 dwarf_vma off = offset + (start - *start_ptr);
5075 enum dwarf_location_list_entry_type llet;
5077 if (start + 1 > section_end)
5079 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5080 (unsigned long) offset);
5084 printf (" %8.8lx ", (unsigned long) off);
5086 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5090 case DW_LLE_end_of_list:
5091 printf (_("<End of list>\n"));
5093 case DW_LLE_offset_pair:
5094 begin = read_uleb128 (start, &bytes_read, section_end);
5095 start += bytes_read;
5096 end = read_uleb128 (start, &bytes_read, section_end);
5097 start += bytes_read;
5099 case DW_LLE_base_address:
5100 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5102 print_dwarf_vma (base_address, pointer_size);
5103 printf (_("(base address)\n"));
5106 error (_("Invalid location list entry type %d\n"), llet);
5109 if (llet == DW_LLE_end_of_list)
5111 if (llet != DW_LLE_offset_pair)
5114 if (start + 2 > section_end)
5116 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5117 (unsigned long) offset);
5121 length = read_uleb128 (start, &bytes_read, section_end);
5122 start += bytes_read;
5124 print_dwarf_vma (begin + base_address, pointer_size);
5125 print_dwarf_vma (end + base_address, pointer_size);
5128 need_frame_base = decode_location_expression (start,
5133 cu_offset, section);
5136 if (need_frame_base && !has_frame_base)
5137 printf (_(" [without DW_AT_frame_base]"));
5140 fputs (_(" (start == end)"), stdout);
5141 else if (begin > end)
5142 fputs (_(" (start > end)"), stdout);
5152 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5153 right-adjusted in a field of length LEN, and followed by a space. */
5156 print_addr_index (unsigned int idx, unsigned int len)
5158 static char buf[15];
5159 snprintf (buf, sizeof (buf), "[%d]", idx);
5160 printf ("%*s ", len, buf);
5163 /* Display a location list from a .dwo section. It uses address indexes rather
5164 than embedded addresses. This code closely follows display_loc_list, but the
5165 two are sufficiently different that combining things is very ugly. */
5168 display_loc_list_dwo (struct dwarf_section *section,
5169 unsigned char **start_ptr,
5170 unsigned int debug_info_entry,
5174 unsigned char *start = *start_ptr;
5175 unsigned char *section_end = section->start + section->size;
5176 unsigned long cu_offset;
5177 unsigned int pointer_size;
5178 unsigned int offset_size;
5181 unsigned short length;
5182 int need_frame_base;
5184 unsigned int bytes_read;
5186 if (debug_info_entry >= num_debug_info_entries)
5188 warn (_("No debug information for loc lists of entry: %u\n"),
5193 cu_offset = debug_information [debug_info_entry].cu_offset;
5194 pointer_size = debug_information [debug_info_entry].pointer_size;
5195 offset_size = debug_information [debug_info_entry].offset_size;
5196 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5198 if (pointer_size < 2 || pointer_size > 8)
5200 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5201 pointer_size, debug_info_entry);
5207 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5209 if (start >= section_end)
5211 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5212 (unsigned long) offset);
5216 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5219 case 0: /* A terminating entry. */
5221 printf (_("<End of list>\n"));
5223 case 1: /* A base-address entry. */
5224 idx = read_uleb128 (start, &bytes_read, section_end);
5225 start += bytes_read;
5226 print_addr_index (idx, 8);
5228 printf (_("(base address selection entry)\n"));
5230 case 2: /* A start/end entry. */
5231 idx = read_uleb128 (start, &bytes_read, section_end);
5232 start += bytes_read;
5233 print_addr_index (idx, 8);
5234 idx = read_uleb128 (start, &bytes_read, section_end);
5235 start += bytes_read;
5236 print_addr_index (idx, 8);
5238 case 3: /* A start/length entry. */
5239 idx = read_uleb128 (start, &bytes_read, section_end);
5240 start += bytes_read;
5241 print_addr_index (idx, 8);
5242 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5243 printf ("%08x ", idx);
5245 case 4: /* An offset pair entry. */
5246 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5247 printf ("%08x ", idx);
5248 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5249 printf ("%08x ", idx);
5252 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5257 if (start + 2 > section_end)
5259 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5260 (unsigned long) offset);
5264 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5265 if (start + length > section_end)
5267 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5268 (unsigned long) offset);
5273 need_frame_base = decode_location_expression (start,
5278 cu_offset, section);
5281 if (need_frame_base && !has_frame_base)
5282 printf (_(" [without DW_AT_frame_base]"));
5292 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
5294 static dwarf_vma *loc_offsets;
5297 loc_offsets_compar (const void *ap, const void *bp)
5299 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5300 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5302 return (a > b) - (b > a);
5306 display_debug_loc (struct dwarf_section *section, void *file)
5308 unsigned char *start = section->start;
5309 unsigned long bytes;
5310 unsigned char *section_begin = start;
5311 unsigned int num_loc_list = 0;
5312 unsigned long last_offset = 0;
5313 unsigned int first = 0;
5316 int seen_first_offset = 0;
5317 int locs_sorted = 1;
5318 unsigned char *next;
5319 unsigned int *array = NULL;
5320 const char *suffix = strrchr (section->name, '.');
5322 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5323 dwarf_vma expected_start = 0;
5325 if (suffix && strcmp (suffix, ".dwo") == 0)
5328 bytes = section->size;
5332 printf (_("\nThe %s section is empty.\n"), section->name);
5338 unsigned char *hdrptr = section_begin;
5339 dwarf_vma ll_length;
5340 unsigned short ll_version;
5341 unsigned char *end = section_begin + section->size;
5342 unsigned char address_size, segment_selector_size;
5343 uint32_t offset_entry_count;
5345 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5346 if (ll_length == 0xffffffff)
5347 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5349 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5350 if (ll_version != 5)
5352 warn (_("The %s section contains corrupt or "
5353 "unsupported version number: %d.\n"),
5354 section->name, ll_version);
5358 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5360 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5361 if (segment_selector_size != 0)
5363 warn (_("The %s section contains "
5364 "unsupported segment selector size: %d.\n"),
5365 section->name, segment_selector_size);
5369 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5370 if (offset_entry_count != 0)
5372 warn (_("The %s section contains "
5373 "unsupported offset entry count: %d.\n"),
5374 section->name, offset_entry_count);
5378 expected_start = hdrptr - section_begin;
5381 if (load_debug_info (file) == 0)
5383 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5388 /* Check the order of location list in .debug_info section. If
5389 offsets of location lists are in the ascending order, we can
5390 use `debug_information' directly. */
5391 for (i = 0; i < num_debug_info_entries; i++)
5395 num = debug_information [i].num_loc_offsets;
5396 if (num > num_loc_list)
5399 /* Check if we can use `debug_information' directly. */
5400 if (locs_sorted && num != 0)
5402 if (!seen_first_offset)
5404 /* This is the first location list. */
5405 last_offset = debug_information [i].loc_offsets [0];
5407 seen_first_offset = 1;
5413 for (; j < num; j++)
5416 debug_information [i].loc_offsets [j])
5421 last_offset = debug_information [i].loc_offsets [j];
5426 if (!seen_first_offset)
5427 error (_("No location lists in .debug_info section!\n"));
5429 if (debug_information [first].num_loc_offsets > 0
5430 && debug_information [first].loc_offsets [0] != expected_start)
5431 warn (_("Location lists in %s section start at 0x%s\n"),
5433 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5436 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5437 printf (_("Contents of the %s section:\n\n"), section->name);
5438 if (reloc_at (section, 0))
5439 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5440 printf (_(" Offset Begin End Expression\n"));
5442 seen_first_offset = 0;
5443 for (i = first; i < num_debug_info_entries; i++)
5446 dwarf_vma base_address;
5452 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5454 loc_offsets = debug_information [i].loc_offsets;
5455 qsort (array, debug_information [i].num_loc_offsets,
5456 sizeof (*array), loc_offsets_compar);
5459 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5461 j = locs_sorted ? k : array[k];
5463 && debug_information [i].loc_offsets [locs_sorted
5464 ? k - 1 : array [k - 1]]
5465 == debug_information [i].loc_offsets [j])
5467 has_frame_base = debug_information [i].have_frame_base [j];
5468 offset = debug_information [i].loc_offsets [j];
5469 next = section_begin + offset;
5470 base_address = debug_information [i].base_address;
5472 if (!seen_first_offset)
5473 seen_first_offset = 1;
5477 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5478 (unsigned long) (start - section_begin),
5479 (unsigned long) offset);
5480 else if (start > next)
5481 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5482 (unsigned long) (start - section_begin),
5483 (unsigned long) offset);
5487 if (offset >= bytes)
5489 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5490 (unsigned long) offset);
5497 display_loc_list_dwo (section, &start, i, offset,
5500 display_loc_list (section, &start, i, offset, base_address,
5506 warn (_("DWO is not yet supported.\n"));
5508 display_loclists_list (section, &start, i, offset, base_address,
5514 if (start < section->start + section->size)
5515 warn (_("There are %ld unused bytes at the end of section %s\n"),
5516 (long) (section->start + section->size - start), section->name);
5523 display_debug_str (struct dwarf_section *section,
5524 void *file ATTRIBUTE_UNUSED)
5526 unsigned char *start = section->start;
5527 unsigned long bytes = section->size;
5528 dwarf_vma addr = section->address;
5532 printf (_("\nThe %s section is empty.\n"), section->name);
5536 printf (_("Contents of the %s section:\n\n"), section->name);
5544 lbytes = (bytes > 16 ? 16 : bytes);
5546 printf (" 0x%8.8lx ", (unsigned long) addr);
5548 for (j = 0; j < 16; j++)
5551 printf ("%2.2x", start[j]);
5559 for (j = 0; j < lbytes; j++)
5562 if (k >= ' ' && k < 0x80)
5581 display_debug_info (struct dwarf_section *section, void *file)
5583 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5587 display_debug_types (struct dwarf_section *section, void *file)
5589 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5593 display_trace_info (struct dwarf_section *section, void *file)
5595 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5599 display_debug_aranges (struct dwarf_section *section,
5600 void *file ATTRIBUTE_UNUSED)
5602 unsigned char *start = section->start;
5603 unsigned char *end = start + section->size;
5605 printf (_("Contents of the %s section:\n\n"), section->name);
5607 /* It does not matter if this load fails,
5608 we test for that later on. */
5609 load_debug_info (file);
5613 unsigned char *hdrptr;
5614 DWARF2_Internal_ARange arange;
5615 unsigned char *addr_ranges;
5618 unsigned char address_size;
5620 unsigned int offset_size;
5621 unsigned int initial_length_size;
5625 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
5626 if (arange.ar_length == 0xffffffff)
5628 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
5630 initial_length_size = 12;
5635 initial_length_size = 4;
5638 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
5639 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
5641 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5642 && num_debug_info_entries > 0
5643 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
5644 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5645 (unsigned long) arange.ar_info_offset, section->name);
5647 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
5648 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
5650 if (arange.ar_version != 2 && arange.ar_version != 3)
5652 /* PR 19872: A version number of 0 probably means that there is
5653 padding at the end of the .debug_aranges section. Gold puts
5654 it there when performing an incremental link, for example.
5655 So do not generate a warning in this case. */
5656 if (arange.ar_version)
5657 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
5661 printf (_(" Length: %ld\n"),
5662 (long) arange.ar_length);
5663 printf (_(" Version: %d\n"), arange.ar_version);
5664 printf (_(" Offset into .debug_info: 0x%lx\n"),
5665 (unsigned long) arange.ar_info_offset);
5666 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
5667 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
5669 address_size = arange.ar_pointer_size + arange.ar_segment_size;
5671 /* PR 17512: file: 001-108546-0.001:0.1. */
5672 if (address_size == 0 || address_size > 8)
5674 error (_("Invalid address size in %s section!\n"),
5679 /* The DWARF spec does not require that the address size be a power
5680 of two, but we do. This will have to change if we ever encounter
5681 an uneven architecture. */
5682 if ((address_size & (address_size - 1)) != 0)
5684 warn (_("Pointer size + Segment size is not a power of two.\n"));
5688 if (address_size > 4)
5689 printf (_("\n Address Length\n"));
5691 printf (_("\n Address Length\n"));
5693 addr_ranges = hdrptr;
5695 /* Must pad to an alignment boundary that is twice the address size. */
5696 excess = (hdrptr - start) % (2 * address_size);
5698 addr_ranges += (2 * address_size) - excess;
5700 hdrptr = start + arange.ar_length + initial_length_size;
5701 if (hdrptr < start || hdrptr > end)
5703 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5708 while (addr_ranges + 2 * address_size <= start)
5710 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5711 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5714 print_dwarf_vma (address, address_size);
5715 print_dwarf_vma (length, address_size);
5725 /* Comparison function for qsort. */
5727 comp_addr_base (const void * v0, const void * v1)
5729 debug_info * info0 = (debug_info *) v0;
5730 debug_info * info1 = (debug_info *) v1;
5731 return info0->addr_base - info1->addr_base;
5734 /* Display the debug_addr section. */
5736 display_debug_addr (struct dwarf_section *section,
5739 debug_info **debug_addr_info;
5740 unsigned char *entry;
5745 if (section->size == 0)
5747 printf (_("\nThe %s section is empty.\n"), section->name);
5751 if (load_debug_info (file) == 0)
5753 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5758 printf (_("Contents of the %s section:\n\n"), section->name);
5760 /* PR 17531: file: cf38d01b.
5761 We use xcalloc because a corrupt file may not have initialised all of the
5762 fields in the debug_info structure, which means that the sort below might
5763 try to move uninitialised data. */
5764 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5765 sizeof (debug_info *));
5768 for (i = 0; i < num_debug_info_entries; i++)
5769 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5771 /* PR 17531: file: cf38d01b. */
5772 if (debug_information[i].addr_base >= section->size)
5773 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5774 (unsigned long) debug_information[i].addr_base, i);
5776 debug_addr_info [count++] = debug_information + i;
5779 /* Add a sentinel to make iteration convenient. */
5780 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5781 debug_addr_info [count]->addr_base = section->size;
5782 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5784 for (i = 0; i < count; i++)
5787 unsigned int address_size = debug_addr_info [i]->pointer_size;
5789 printf (_(" For compilation unit at offset 0x%s:\n"),
5790 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5792 printf (_("\tIndex\tAddress\n"));
5793 entry = section->start + debug_addr_info [i]->addr_base;
5794 end = section->start + debug_addr_info [i + 1]->addr_base;
5798 dwarf_vma base = byte_get (entry, address_size);
5799 printf (_("\t%d:\t"), idx);
5800 print_dwarf_vma (base, address_size);
5802 entry += address_size;
5808 free (debug_addr_info);
5812 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5814 display_debug_str_offsets (struct dwarf_section *section,
5815 void *file ATTRIBUTE_UNUSED)
5817 if (section->size == 0)
5819 printf (_("\nThe %s section is empty.\n"), section->name);
5822 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5823 what the offset size is for this section. */
5827 /* Each debug_information[x].range_lists[y] gets this representation for
5828 sorting purposes. */
5832 /* The debug_information[x].range_lists[y] value. */
5833 dwarf_vma ranges_offset;
5835 /* Original debug_information to find parameters of the data. */
5836 debug_info *debug_info_p;
5839 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5842 range_entry_compar (const void *ap, const void *bp)
5844 const struct range_entry *a_re = (const struct range_entry *) ap;
5845 const struct range_entry *b_re = (const struct range_entry *) bp;
5846 const dwarf_vma a = a_re->ranges_offset;
5847 const dwarf_vma b = b_re->ranges_offset;
5849 return (a > b) - (b > a);
5853 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
5854 unsigned int pointer_size, unsigned long offset,
5855 unsigned long base_address)
5857 while (start < finish)
5862 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5863 if (start >= finish)
5865 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5867 printf (" %8.8lx ", offset);
5869 if (begin == 0 && end == 0)
5871 printf (_("<End of list>\n"));
5875 /* Check base address specifiers. */
5876 if (is_max_address (begin, pointer_size)
5877 && !is_max_address (end, pointer_size))
5880 print_dwarf_vma (begin, pointer_size);
5881 print_dwarf_vma (end, pointer_size);
5882 printf ("(base address)\n");
5886 print_dwarf_vma (begin + base_address, pointer_size);
5887 print_dwarf_vma (end + base_address, pointer_size);
5890 fputs (_("(start == end)"), stdout);
5891 else if (begin > end)
5892 fputs (_("(start > end)"), stdout);
5899 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
5900 unsigned int pointer_size, unsigned long offset,
5901 unsigned long base_address)
5903 unsigned char *next = start;
5907 unsigned long off = offset + (start - next);
5908 enum dwarf_range_list_entry rlet;
5909 /* Initialize it due to a false compiler warning. */
5910 dwarf_vma begin = -1, length, end = -1;
5911 unsigned int bytes_read;
5913 if (start + 1 > finish)
5915 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
5920 printf (" %8.8lx ", off);
5922 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
5926 case DW_RLE_end_of_list:
5927 printf (_("<End of list>\n"));
5929 case DW_RLE_base_address:
5930 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
5931 print_dwarf_vma (base_address, pointer_size);
5932 printf (_("(base address)\n"));
5934 case DW_RLE_start_length:
5935 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5936 length = read_uleb128 (start, &bytes_read, finish);
5937 start += bytes_read;
5938 end = begin + length;
5940 case DW_RLE_offset_pair:
5941 begin = read_uleb128 (start, &bytes_read, finish);
5942 start += bytes_read;
5943 end = read_uleb128 (start, &bytes_read, finish);
5944 start += bytes_read;
5946 case DW_RLE_start_end:
5947 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5948 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5951 error (_("Invalid range list entry type %d\n"), rlet);
5952 rlet = DW_RLE_end_of_list;
5955 if (rlet == DW_RLE_end_of_list)
5957 if (rlet == DW_RLE_base_address)
5960 print_dwarf_vma (begin + base_address, pointer_size);
5961 print_dwarf_vma (end + base_address, pointer_size);
5964 fputs (_("(start == end)"), stdout);
5965 else if (begin > end)
5966 fputs (_("(start > end)"), stdout);
5973 display_debug_ranges (struct dwarf_section *section,
5974 void *file ATTRIBUTE_UNUSED)
5976 unsigned char *start = section->start;
5977 unsigned char *last_start = start;
5978 unsigned long bytes = section->size;
5979 unsigned char *section_begin = start;
5980 unsigned char *finish = start + bytes;
5981 unsigned int num_range_list, i;
5982 struct range_entry *range_entries, *range_entry_fill;
5983 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
5984 /* Initialize it due to a false compiler warning. */
5985 unsigned char address_size = 0;
5989 printf (_("\nThe %s section is empty.\n"), section->name);
5995 dwarf_vma initial_length;
5996 unsigned int initial_length_size;
5997 unsigned char segment_selector_size;
5998 unsigned int offset_size, offset_entry_count;
5999 unsigned short version;
6001 /* Get and check the length of the block. */
6002 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6004 if (initial_length == 0xffffffff)
6006 /* This section is 64-bit DWARF 3. */
6007 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6009 initial_length_size = 12;
6014 initial_length_size = 4;
6017 if (initial_length + initial_length_size > section->size)
6019 /* If the length field has a relocation against it, then we should
6020 not complain if it is inaccurate (and probably negative).
6021 It is copied from .debug_line handling code. */
6022 if (reloc_at (section, (start - section->start) - offset_size))
6024 initial_length = (finish - start) - initial_length_size;
6028 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6029 (long) initial_length);
6034 /* Get and check the version number. */
6035 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6039 warn (_("Only DWARF version 5 debug_rnglists info "
6040 "is currently supported.\n"));
6044 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6046 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6047 if (segment_selector_size != 0)
6049 warn (_("The %s section contains "
6050 "unsupported segment selector size: %d.\n"),
6051 section->name, segment_selector_size);
6055 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6056 if (offset_entry_count != 0)
6058 warn (_("The %s section contains "
6059 "unsupported offset entry count: %u.\n"),
6060 section->name, offset_entry_count);
6065 if (load_debug_info (file) == 0)
6067 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6073 for (i = 0; i < num_debug_info_entries; i++)
6074 num_range_list += debug_information [i].num_range_lists;
6076 if (num_range_list == 0)
6078 /* This can happen when the file was compiled with -gsplit-debug
6079 which removes references to range lists from the primary .o file. */
6080 printf (_("No range lists in .debug_info section.\n"));
6084 range_entries = (struct range_entry *)
6085 xmalloc (sizeof (*range_entries) * num_range_list);
6086 range_entry_fill = range_entries;
6088 for (i = 0; i < num_debug_info_entries; i++)
6090 debug_info *debug_info_p = &debug_information[i];
6093 for (j = 0; j < debug_info_p->num_range_lists; j++)
6095 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6096 range_entry_fill->debug_info_p = debug_info_p;
6101 qsort (range_entries, num_range_list, sizeof (*range_entries),
6102 range_entry_compar);
6104 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6105 warn (_("Range lists in %s section start at 0x%lx\n"),
6106 section->name, (unsigned long) range_entries[0].ranges_offset);
6108 printf (_("Contents of the %s section:\n\n"), section->name);
6109 printf (_(" Offset Begin End\n"));
6111 for (i = 0; i < num_range_list; i++)
6113 struct range_entry *range_entry = &range_entries[i];
6114 debug_info *debug_info_p = range_entry->debug_info_p;
6115 unsigned int pointer_size;
6117 unsigned char *next;
6118 dwarf_vma base_address;
6120 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6121 offset = range_entry->ranges_offset;
6122 next = section_begin + offset;
6123 base_address = debug_info_p->base_address;
6125 /* PR 17512: file: 001-101485-0.001:0.1. */
6126 if (pointer_size < 2 || pointer_size > 8)
6128 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6129 pointer_size, (unsigned long) offset);
6133 if (dwarf_check != 0 && i > 0)
6136 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6137 (unsigned long) (start - section_begin),
6138 (unsigned long) (next - section_begin), section->name);
6139 else if (start > next)
6141 if (next == last_start)
6143 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6144 (unsigned long) (start - section_begin),
6145 (unsigned long) (next - section_begin), section->name);
6151 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6152 (start, finish, pointer_size, offset, base_address);
6156 free (range_entries);
6161 typedef struct Frame_Chunk
6163 struct Frame_Chunk *next;
6164 unsigned char *chunk_start;
6166 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6167 short int *col_type;
6170 unsigned int code_factor;
6175 dwarf_vma cfa_offset;
6177 unsigned char fde_encoding;
6178 unsigned char cfa_exp;
6179 unsigned char ptr_size;
6180 unsigned char segment_size;
6184 static const char *const *dwarf_regnames;
6185 static unsigned int dwarf_regnames_count;
6187 /* A marker for a col_type that means this column was never referenced
6188 in the frame info. */
6189 #define DW_CFA_unreferenced (-1)
6191 /* Return 0 if no more space is needed, 1 if more space is needed,
6192 -1 for invalid reg. */
6195 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6197 unsigned int prev = fc->ncols;
6199 if (reg < (unsigned int) fc->ncols)
6202 if (dwarf_regnames_count
6203 && reg > dwarf_regnames_count)
6206 fc->ncols = reg + 1;
6207 /* PR 17512: file: 10450-2643-0.004.
6208 If reg == -1 then this can happen... */
6212 /* PR 17512: file: 2844a11d. */
6213 if (fc->ncols > 1024)
6215 error (_("Unfeasibly large register number: %u\n"), reg);
6217 /* FIXME: 1024 is an arbitrary limit. Increase it if
6218 we ever encounter a valid binary that exceeds it. */
6222 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6223 sizeof (short int));
6224 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6225 /* PR 17512: file:002-10025-0.005. */
6226 if (fc->col_type == NULL || fc->col_offset == NULL)
6228 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6234 while (prev < fc->ncols)
6236 fc->col_type[prev] = DW_CFA_unreferenced;
6237 fc->col_offset[prev] = 0;
6243 static const char *const dwarf_regnames_i386[] =
6245 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6246 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6247 "eip", "eflags", NULL, /* 8 - 10 */
6248 "st0", "st1", "st2", "st3", /* 11 - 14 */
6249 "st4", "st5", "st6", "st7", /* 15 - 18 */
6250 NULL, NULL, /* 19 - 20 */
6251 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6252 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6253 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6254 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6255 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6256 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6257 "tr", "ldtr", /* 48 - 49 */
6258 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6259 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6260 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6261 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6262 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6263 NULL, NULL, NULL, /* 90 - 92 */
6264 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6267 static const char *const dwarf_regnames_iamcu[] =
6269 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6270 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6271 "eip", "eflags", NULL, /* 8 - 10 */
6272 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6273 NULL, NULL, /* 19 - 20 */
6274 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6275 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6276 NULL, NULL, NULL, /* 37 - 39 */
6277 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6278 "tr", "ldtr", /* 48 - 49 */
6279 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6280 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6281 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6282 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6283 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6284 NULL, NULL, NULL, /* 90 - 92 */
6285 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6289 init_dwarf_regnames_i386 (void)
6291 dwarf_regnames = dwarf_regnames_i386;
6292 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6296 init_dwarf_regnames_iamcu (void)
6298 dwarf_regnames = dwarf_regnames_iamcu;
6299 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6302 static const char *const dwarf_regnames_x86_64[] =
6304 "rax", "rdx", "rcx", "rbx",
6305 "rsi", "rdi", "rbp", "rsp",
6306 "r8", "r9", "r10", "r11",
6307 "r12", "r13", "r14", "r15",
6309 "xmm0", "xmm1", "xmm2", "xmm3",
6310 "xmm4", "xmm5", "xmm6", "xmm7",
6311 "xmm8", "xmm9", "xmm10", "xmm11",
6312 "xmm12", "xmm13", "xmm14", "xmm15",
6313 "st0", "st1", "st2", "st3",
6314 "st4", "st5", "st6", "st7",
6315 "mm0", "mm1", "mm2", "mm3",
6316 "mm4", "mm5", "mm6", "mm7",
6318 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6319 "fs.base", "gs.base", NULL, NULL,
6321 "mxcsr", "fcw", "fsw",
6322 "xmm16", "xmm17", "xmm18", "xmm19",
6323 "xmm20", "xmm21", "xmm22", "xmm23",
6324 "xmm24", "xmm25", "xmm26", "xmm27",
6325 "xmm28", "xmm29", "xmm30", "xmm31",
6326 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6327 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6328 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6329 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6330 NULL, NULL, NULL, /* 115 - 117 */
6331 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6335 init_dwarf_regnames_x86_64 (void)
6337 dwarf_regnames = dwarf_regnames_x86_64;
6338 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6341 static const char *const dwarf_regnames_aarch64[] =
6343 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6344 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6345 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6346 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6347 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6348 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6349 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6350 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6351 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6352 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6353 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6354 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6358 init_dwarf_regnames_aarch64 (void)
6360 dwarf_regnames = dwarf_regnames_aarch64;
6361 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6364 static const char *const dwarf_regnames_s390[] =
6366 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6367 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6368 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6369 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6370 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6371 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6372 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6373 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6374 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6377 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6378 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6382 init_dwarf_regnames_s390 (void)
6384 dwarf_regnames = dwarf_regnames_s390;
6385 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6389 init_dwarf_regnames (unsigned int e_machine)
6394 init_dwarf_regnames_i386 ();
6398 init_dwarf_regnames_iamcu ();
6404 init_dwarf_regnames_x86_64 ();
6408 init_dwarf_regnames_aarch64 ();
6412 init_dwarf_regnames_s390 ();
6421 regname (unsigned int regno, int row)
6423 static char reg[64];
6425 && regno < dwarf_regnames_count
6426 && dwarf_regnames [regno] != NULL)
6429 return dwarf_regnames [regno];
6430 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6431 dwarf_regnames [regno]);
6434 snprintf (reg, sizeof (reg), "r%d", regno);
6439 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6444 if (*max_regs != fc->ncols)
6445 *max_regs = fc->ncols;
6447 if (*need_col_headers)
6449 static const char *sloc = " LOC";
6451 *need_col_headers = 0;
6453 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6455 for (r = 0; r < *max_regs; r++)
6456 if (fc->col_type[r] != DW_CFA_unreferenced)
6461 printf ("%-5s ", regname (r, 1));
6467 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6469 strcpy (tmp, "exp");
6471 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6472 printf ("%-8s ", tmp);
6474 for (r = 0; r < fc->ncols; r++)
6476 if (fc->col_type[r] != DW_CFA_unreferenced)
6478 switch (fc->col_type[r])
6480 case DW_CFA_undefined:
6483 case DW_CFA_same_value:
6487 sprintf (tmp, "c%+d", fc->col_offset[r]);
6489 case DW_CFA_val_offset:
6490 sprintf (tmp, "v%+d", fc->col_offset[r]);
6492 case DW_CFA_register:
6493 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6495 case DW_CFA_expression:
6496 strcpy (tmp, "exp");
6498 case DW_CFA_val_expression:
6499 strcpy (tmp, "vexp");
6502 strcpy (tmp, "n/a");
6505 printf ("%-5s ", tmp);
6511 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6512 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
6513 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
6515 static unsigned char *
6516 read_cie (unsigned char *start, unsigned char *end,
6517 Frame_Chunk **p_cie, int *p_version,
6518 unsigned long *p_aug_len, unsigned char **p_aug)
6522 unsigned int length_return;
6523 unsigned char *augmentation_data = NULL;
6524 unsigned long augmentation_data_len = 0;
6527 /* PR 17512: file: 001-228113-0.004. */
6531 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6532 memset (fc, 0, sizeof (Frame_Chunk));
6534 fc->col_type = (short int *) xmalloc (sizeof (short int));
6535 fc->col_offset = (int *) xmalloc (sizeof (int));
6539 fc->augmentation = (char *) start;
6540 /* PR 17512: file: 001-228113-0.004.
6541 Skip past augmentation name, but avoid running off the end of the data. */
6543 if (* start ++ == '\0')
6547 warn (_("No terminator for augmentation name\n"));
6551 if (strcmp (fc->augmentation, "eh") == 0)
6552 start += eh_addr_size;
6556 GET (fc->ptr_size, 1);
6557 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6559 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6563 GET (fc->segment_size, 1);
6564 /* PR 17512: file: e99d2804. */
6565 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6567 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6571 eh_addr_size = fc->ptr_size;
6575 fc->ptr_size = eh_addr_size;
6576 fc->segment_size = 0;
6578 fc->code_factor = LEB ();
6579 fc->data_factor = SLEB ();
6589 if (fc->augmentation[0] == 'z')
6591 augmentation_data_len = LEB ();
6592 augmentation_data = start;
6593 start += augmentation_data_len;
6594 /* PR 17512: file: 11042-2589-0.004. */
6597 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
6602 if (augmentation_data_len)
6606 unsigned char *qend;
6608 p = (unsigned char *) fc->augmentation + 1;
6609 q = augmentation_data;
6610 qend = q + augmentation_data_len;
6612 /* PR 17531: file: 015adfaa. */
6615 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
6616 augmentation_data_len = 0;
6619 while (p < end && q < augmentation_data + augmentation_data_len)
6624 q += 1 + size_of_encoded_value (*q);
6626 fc->fde_encoding = *q++;
6633 /* Note - it is OK if this loop terminates with q < qend.
6634 Padding may have been inserted to align the end of the CIE. */
6639 *p_version = version;
6642 *p_aug_len = augmentation_data_len;
6643 *p_aug = augmentation_data;
6649 display_debug_frames (struct dwarf_section *section,
6650 void *file ATTRIBUTE_UNUSED)
6652 unsigned char *start = section->start;
6653 unsigned char *end = start + section->size;
6654 unsigned char *section_start = start;
6655 Frame_Chunk *chunks = 0, *forward_refs = 0;
6656 Frame_Chunk *remembered_state = 0;
6658 int is_eh = strcmp (section->name, ".eh_frame") == 0;
6659 unsigned int length_return;
6660 unsigned int max_regs = 0;
6661 const char *bad_reg = _("bad register: ");
6662 unsigned int saved_eh_addr_size = eh_addr_size;
6664 printf (_("Contents of the %s section:\n"), section->name);
6668 unsigned char *saved_start;
6669 unsigned char *block_end;
6674 int need_col_headers = 1;
6675 unsigned char *augmentation_data = NULL;
6676 unsigned long augmentation_data_len = 0;
6677 unsigned int encoded_ptr_size = saved_eh_addr_size;
6678 unsigned int offset_size;
6679 unsigned int initial_length_size;
6680 bfd_boolean all_nops;
6682 saved_start = start;
6684 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
6688 printf ("\n%08lx ZERO terminator\n\n",
6689 (unsigned long)(saved_start - section_start));
6690 /* Skip any zero terminators that directly follow.
6691 A corrupt section size could have loaded a whole
6692 slew of zero filled memory bytes. eg
6693 PR 17512: file: 070-19381-0.004. */
6694 while (start < end && * start == 0)
6699 if (length == 0xffffffff)
6701 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
6703 initial_length_size = 12;
6708 initial_length_size = 4;
6711 block_end = saved_start + length + initial_length_size;
6712 if (block_end > end || block_end < start)
6714 warn ("Invalid length 0x%s in FDE at %#08lx\n",
6715 dwarf_vmatoa_1 (NULL, length, offset_size),
6716 (unsigned long) (saved_start - section_start));
6720 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
6722 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
6723 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
6728 start = read_cie (start, end, &cie, &version,
6729 &augmentation_data_len, &augmentation_data);
6730 /* PR 17512: file: 027-135133-0.005. */
6737 fc->chunk_start = saved_start;
6738 mreg = max_regs > 0 ? max_regs - 1 : 0;
6741 if (frame_need_space (fc, mreg) < 0)
6743 if (fc->fde_encoding)
6744 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6746 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
6747 print_dwarf_vma (length, fc->ptr_size);
6748 print_dwarf_vma (cie_id, offset_size);
6750 if (do_debug_frames_interp)
6752 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
6753 fc->code_factor, fc->data_factor, fc->ra);
6758 printf (" Version: %d\n", version);
6759 printf (" Augmentation: \"%s\"\n", fc->augmentation);
6762 printf (" Pointer Size: %u\n", fc->ptr_size);
6763 printf (" Segment Size: %u\n", fc->segment_size);
6765 printf (" Code alignment factor: %u\n", fc->code_factor);
6766 printf (" Data alignment factor: %d\n", fc->data_factor);
6767 printf (" Return address column: %d\n", fc->ra);
6769 if (augmentation_data_len)
6773 printf (" Augmentation data: ");
6774 for (i = 0; i < augmentation_data_len; ++i)
6775 /* FIXME: If do_wide is FALSE, then we should
6776 add carriage returns at 80 columns... */
6777 printf (" %02x", augmentation_data[i]);
6785 unsigned char *look_for;
6786 static Frame_Chunk fde_fc;
6787 unsigned long segment_selector;
6791 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
6792 look_for = start - 4 - ((cie_id ^ sign) - sign);
6795 look_for = section_start + cie_id;
6797 if (look_for <= saved_start)
6799 for (cie = chunks; cie ; cie = cie->next)
6800 if (cie->chunk_start == look_for)
6805 for (cie = forward_refs; cie ; cie = cie->next)
6806 if (cie->chunk_start == look_for)
6810 unsigned int off_size;
6811 unsigned char *cie_scan;
6813 cie_scan = look_for;
6815 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
6816 if (length == 0xffffffff)
6818 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
6825 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
6828 : ((off_size == 4 && c_id == DW_CIE_ID)
6829 || (off_size == 8 && c_id == DW64_CIE_ID)))
6834 read_cie (cie_scan, end, &cie, &version,
6835 &augmentation_data_len, &augmentation_data);
6836 /* PR 17512: file: 3450-2098-0.004. */
6839 warn (_("Failed to read CIE information\n"));
6842 cie->next = forward_refs;
6844 cie->chunk_start = look_for;
6845 mreg = max_regs > 0 ? max_regs - 1 : 0;
6848 if (frame_need_space (cie, mreg) < 0)
6850 warn (_("Invalid max register\n"));
6853 if (cie->fde_encoding)
6855 = size_of_encoded_value (cie->fde_encoding);
6862 memset (fc, 0, sizeof (Frame_Chunk));
6866 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6867 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6868 (unsigned long) (saved_start - section_start));
6870 fc->col_type = (short int *) xmalloc (sizeof (short int));
6871 fc->col_offset = (int *) xmalloc (sizeof (int));
6872 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
6874 warn (_("Invalid max register\n"));
6878 fc->augmentation = "";
6879 fc->fde_encoding = 0;
6880 fc->ptr_size = eh_addr_size;
6881 fc->segment_size = 0;
6885 fc->ncols = cie->ncols;
6886 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
6887 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
6888 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6889 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6890 fc->augmentation = cie->augmentation;
6891 fc->ptr_size = cie->ptr_size;
6892 eh_addr_size = cie->ptr_size;
6893 fc->segment_size = cie->segment_size;
6894 fc->code_factor = cie->code_factor;
6895 fc->data_factor = cie->data_factor;
6896 fc->cfa_reg = cie->cfa_reg;
6897 fc->cfa_offset = cie->cfa_offset;
6899 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
6901 warn (_("Invalid max register\n"));
6904 fc->fde_encoding = cie->fde_encoding;
6907 if (fc->fde_encoding)
6908 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6910 segment_selector = 0;
6911 if (fc->segment_size)
6913 if (fc->segment_size > sizeof (segment_selector))
6915 /* PR 17512: file: 9e196b3e. */
6916 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
6917 fc->segment_size = 4;
6919 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
6922 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
6924 /* FIXME: It appears that sometimes the final pc_range value is
6925 encoded in less than encoded_ptr_size bytes. See the x86_64
6926 run of the "objcopy on compressed debug sections" test for an
6928 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
6930 if (cie->augmentation[0] == 'z')
6932 augmentation_data_len = LEB ();
6933 augmentation_data = start;
6934 start += augmentation_data_len;
6935 /* PR 17512: file: 722-8446-0.004. */
6936 if (start >= end || ((signed long) augmentation_data_len) < 0)
6938 warn (_("Corrupt augmentation data length: %lx\n"),
6939 augmentation_data_len);
6941 augmentation_data = NULL;
6942 augmentation_data_len = 0;
6946 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6947 (unsigned long)(saved_start - section_start),
6948 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
6949 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6950 (unsigned long)(cie->chunk_start - section_start));
6952 if (fc->segment_size)
6953 printf ("%04lx:", segment_selector);
6956 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
6957 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
6959 if (! do_debug_frames_interp && augmentation_data_len)
6963 printf (" Augmentation data: ");
6964 for (i = 0; i < augmentation_data_len; ++i)
6965 printf (" %02x", augmentation_data[i]);
6971 /* At this point, fc is the current chunk, cie (if any) is set, and
6972 we're about to interpret instructions for the chunk. */
6973 /* ??? At present we need to do this always, since this sizes the
6974 fc->col_type and fc->col_offset arrays, which we write into always.
6975 We should probably split the interpreted and non-interpreted bits
6976 into two different routines, since there's so much that doesn't
6977 really overlap between them. */
6978 if (1 || do_debug_frames_interp)
6980 /* Start by making a pass over the chunk, allocating storage
6981 and taking note of what registers are used. */
6982 unsigned char *tmp = start;
6984 while (start < block_end)
6986 unsigned int reg, op, opa;
6988 unsigned char * new_start;
6995 /* Warning: if you add any more cases to this switch, be
6996 sure to add them to the corresponding switch below. */
6999 case DW_CFA_advance_loc:
7003 if (frame_need_space (fc, opa) >= 0)
7004 fc->col_type[opa] = DW_CFA_undefined;
7006 case DW_CFA_restore:
7007 if (frame_need_space (fc, opa) >= 0)
7008 fc->col_type[opa] = DW_CFA_undefined;
7010 case DW_CFA_set_loc:
7011 start += encoded_ptr_size;
7013 case DW_CFA_advance_loc1:
7016 case DW_CFA_advance_loc2:
7019 case DW_CFA_advance_loc4:
7022 case DW_CFA_offset_extended:
7023 case DW_CFA_val_offset:
7024 reg = LEB (); LEB ();
7025 if (frame_need_space (fc, reg) >= 0)
7026 fc->col_type[reg] = DW_CFA_undefined;
7028 case DW_CFA_restore_extended:
7030 if (frame_need_space (fc, reg) >= 0)
7031 fc->col_type[reg] = DW_CFA_undefined;
7033 case DW_CFA_undefined:
7035 if (frame_need_space (fc, reg) >= 0)
7036 fc->col_type[reg] = DW_CFA_undefined;
7038 case DW_CFA_same_value:
7040 if (frame_need_space (fc, reg) >= 0)
7041 fc->col_type[reg] = DW_CFA_undefined;
7043 case DW_CFA_register:
7044 reg = LEB (); LEB ();
7045 if (frame_need_space (fc, reg) >= 0)
7046 fc->col_type[reg] = DW_CFA_undefined;
7048 case DW_CFA_def_cfa:
7051 case DW_CFA_def_cfa_register:
7054 case DW_CFA_def_cfa_offset:
7057 case DW_CFA_def_cfa_expression:
7059 new_start = start + temp;
7060 if (new_start < start)
7062 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7068 case DW_CFA_expression:
7069 case DW_CFA_val_expression:
7072 new_start = start + temp;
7073 if (new_start < start)
7075 /* PR 17512: file:306-192417-0.005. */
7076 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7081 if (frame_need_space (fc, reg) >= 0)
7082 fc->col_type[reg] = DW_CFA_undefined;
7084 case DW_CFA_offset_extended_sf:
7085 case DW_CFA_val_offset_sf:
7086 reg = LEB (); SLEB ();
7087 if (frame_need_space (fc, reg) >= 0)
7088 fc->col_type[reg] = DW_CFA_undefined;
7090 case DW_CFA_def_cfa_sf:
7093 case DW_CFA_def_cfa_offset_sf:
7096 case DW_CFA_MIPS_advance_loc8:
7099 case DW_CFA_GNU_args_size:
7102 case DW_CFA_GNU_negative_offset_extended:
7103 reg = LEB (); LEB ();
7104 if (frame_need_space (fc, reg) >= 0)
7105 fc->col_type[reg] = DW_CFA_undefined;
7116 /* Now we know what registers are used, make a second pass over
7117 the chunk, this time actually printing out the info. */
7119 while (start < block_end)
7121 unsigned char * tmp;
7123 unsigned long ul, reg, roffs;
7127 const char *reg_prefix = "";
7134 /* Make a note if something other than DW_CFA_nop happens. */
7135 if (op != DW_CFA_nop)
7138 /* Warning: if you add any more cases to this switch, be
7139 sure to add them to the corresponding switch above. */
7142 case DW_CFA_advance_loc:
7143 if (do_debug_frames_interp)
7144 frame_display_row (fc, &need_col_headers, &max_regs);
7146 printf (" DW_CFA_advance_loc: %d to %s\n",
7147 opa * fc->code_factor,
7148 dwarf_vmatoa_1 (NULL,
7149 fc->pc_begin + opa * fc->code_factor,
7151 fc->pc_begin += opa * fc->code_factor;
7156 if (opa >= (unsigned int) fc->ncols)
7157 reg_prefix = bad_reg;
7158 if (! do_debug_frames_interp || *reg_prefix != '\0')
7159 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7160 reg_prefix, regname (opa, 0),
7161 roffs * fc->data_factor);
7162 if (*reg_prefix == '\0')
7164 fc->col_type[opa] = DW_CFA_offset;
7165 fc->col_offset[opa] = roffs * fc->data_factor;
7169 case DW_CFA_restore:
7170 if (opa >= (unsigned int) fc->ncols)
7171 reg_prefix = bad_reg;
7172 if (! do_debug_frames_interp || *reg_prefix != '\0')
7173 printf (" DW_CFA_restore: %s%s\n",
7174 reg_prefix, regname (opa, 0));
7175 if (*reg_prefix != '\0')
7178 if (opa >= (unsigned int) cie->ncols
7179 || (do_debug_frames_interp
7180 && cie->col_type[opa] == DW_CFA_unreferenced))
7182 fc->col_type[opa] = DW_CFA_undefined;
7183 fc->col_offset[opa] = 0;
7187 fc->col_type[opa] = cie->col_type[opa];
7188 fc->col_offset[opa] = cie->col_offset[opa];
7192 case DW_CFA_set_loc:
7193 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7194 if (do_debug_frames_interp)
7195 frame_display_row (fc, &need_col_headers, &max_regs);
7197 printf (" DW_CFA_set_loc: %s\n",
7198 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7202 case DW_CFA_advance_loc1:
7203 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7204 if (do_debug_frames_interp)
7205 frame_display_row (fc, &need_col_headers, &max_regs);
7207 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7208 (unsigned long) (ofs * fc->code_factor),
7209 dwarf_vmatoa_1 (NULL,
7210 fc->pc_begin + ofs * fc->code_factor,
7212 fc->pc_begin += ofs * fc->code_factor;
7215 case DW_CFA_advance_loc2:
7216 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7217 if (do_debug_frames_interp)
7218 frame_display_row (fc, &need_col_headers, &max_regs);
7220 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7221 (unsigned long) (ofs * fc->code_factor),
7222 dwarf_vmatoa_1 (NULL,
7223 fc->pc_begin + ofs * fc->code_factor,
7225 fc->pc_begin += ofs * fc->code_factor;
7228 case DW_CFA_advance_loc4:
7229 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7230 if (do_debug_frames_interp)
7231 frame_display_row (fc, &need_col_headers, &max_regs);
7233 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7234 (unsigned long) (ofs * fc->code_factor),
7235 dwarf_vmatoa_1 (NULL,
7236 fc->pc_begin + ofs * fc->code_factor,
7238 fc->pc_begin += ofs * fc->code_factor;
7241 case DW_CFA_offset_extended:
7244 if (reg >= (unsigned int) fc->ncols)
7245 reg_prefix = bad_reg;
7246 if (! do_debug_frames_interp || *reg_prefix != '\0')
7247 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7248 reg_prefix, regname (reg, 0),
7249 roffs * fc->data_factor);
7250 if (*reg_prefix == '\0')
7252 fc->col_type[reg] = DW_CFA_offset;
7253 fc->col_offset[reg] = roffs * fc->data_factor;
7257 case DW_CFA_val_offset:
7260 if (reg >= (unsigned int) fc->ncols)
7261 reg_prefix = bad_reg;
7262 if (! do_debug_frames_interp || *reg_prefix != '\0')
7263 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7264 reg_prefix, regname (reg, 0),
7265 roffs * fc->data_factor);
7266 if (*reg_prefix == '\0')
7268 fc->col_type[reg] = DW_CFA_val_offset;
7269 fc->col_offset[reg] = roffs * fc->data_factor;
7273 case DW_CFA_restore_extended:
7275 if (reg >= (unsigned int) fc->ncols)
7276 reg_prefix = bad_reg;
7277 if (! do_debug_frames_interp || *reg_prefix != '\0')
7278 printf (" DW_CFA_restore_extended: %s%s\n",
7279 reg_prefix, regname (reg, 0));
7280 if (*reg_prefix != '\0')
7283 if (reg >= (unsigned int) cie->ncols)
7285 fc->col_type[reg] = DW_CFA_undefined;
7286 fc->col_offset[reg] = 0;
7290 fc->col_type[reg] = cie->col_type[reg];
7291 fc->col_offset[reg] = cie->col_offset[reg];
7295 case DW_CFA_undefined:
7297 if (reg >= (unsigned int) fc->ncols)
7298 reg_prefix = bad_reg;
7299 if (! do_debug_frames_interp || *reg_prefix != '\0')
7300 printf (" DW_CFA_undefined: %s%s\n",
7301 reg_prefix, regname (reg, 0));
7302 if (*reg_prefix == '\0')
7304 fc->col_type[reg] = DW_CFA_undefined;
7305 fc->col_offset[reg] = 0;
7309 case DW_CFA_same_value:
7311 if (reg >= (unsigned int) fc->ncols)
7312 reg_prefix = bad_reg;
7313 if (! do_debug_frames_interp || *reg_prefix != '\0')
7314 printf (" DW_CFA_same_value: %s%s\n",
7315 reg_prefix, regname (reg, 0));
7316 if (*reg_prefix == '\0')
7318 fc->col_type[reg] = DW_CFA_same_value;
7319 fc->col_offset[reg] = 0;
7323 case DW_CFA_register:
7326 if (reg >= (unsigned int) fc->ncols)
7327 reg_prefix = bad_reg;
7328 if (! do_debug_frames_interp || *reg_prefix != '\0')
7330 printf (" DW_CFA_register: %s%s in ",
7331 reg_prefix, regname (reg, 0));
7332 puts (regname (roffs, 0));
7334 if (*reg_prefix == '\0')
7336 fc->col_type[reg] = DW_CFA_register;
7337 fc->col_offset[reg] = roffs;
7341 case DW_CFA_remember_state:
7342 if (! do_debug_frames_interp)
7343 printf (" DW_CFA_remember_state\n");
7344 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7345 rs->cfa_offset = fc->cfa_offset;
7346 rs->cfa_reg = fc->cfa_reg;
7348 rs->cfa_exp = fc->cfa_exp;
7349 rs->ncols = fc->ncols;
7350 rs->col_type = (short int *) xcmalloc (rs->ncols,
7351 sizeof (* rs->col_type));
7352 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7353 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7354 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7355 rs->next = remembered_state;
7356 remembered_state = rs;
7359 case DW_CFA_restore_state:
7360 if (! do_debug_frames_interp)
7361 printf (" DW_CFA_restore_state\n");
7362 rs = remembered_state;
7365 remembered_state = rs->next;
7366 fc->cfa_offset = rs->cfa_offset;
7367 fc->cfa_reg = rs->cfa_reg;
7369 fc->cfa_exp = rs->cfa_exp;
7370 if (frame_need_space (fc, rs->ncols - 1) < 0)
7372 warn (_("Invalid column number in saved frame state\n"));
7376 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7377 memcpy (fc->col_offset, rs->col_offset,
7378 rs->ncols * sizeof (* rs->col_offset));
7379 free (rs->col_type);
7380 free (rs->col_offset);
7383 else if (do_debug_frames_interp)
7384 printf ("Mismatched DW_CFA_restore_state\n");
7387 case DW_CFA_def_cfa:
7388 fc->cfa_reg = LEB ();
7389 fc->cfa_offset = LEB ();
7391 if (! do_debug_frames_interp)
7392 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7393 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7396 case DW_CFA_def_cfa_register:
7397 fc->cfa_reg = LEB ();
7399 if (! do_debug_frames_interp)
7400 printf (" DW_CFA_def_cfa_register: %s\n",
7401 regname (fc->cfa_reg, 0));
7404 case DW_CFA_def_cfa_offset:
7405 fc->cfa_offset = LEB ();
7406 if (! do_debug_frames_interp)
7407 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7411 if (! do_debug_frames_interp)
7412 printf (" DW_CFA_nop\n");
7415 case DW_CFA_def_cfa_expression:
7417 if (start >= block_end || ul > (unsigned long) (block_end - start))
7419 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7422 if (! do_debug_frames_interp)
7424 printf (" DW_CFA_def_cfa_expression (");
7425 decode_location_expression (start, eh_addr_size, 0, -1,
7433 case DW_CFA_expression:
7436 if (reg >= (unsigned int) fc->ncols)
7437 reg_prefix = bad_reg;
7438 /* PR 17512: file: 069-133014-0.006. */
7439 /* PR 17512: file: 98c02eb4. */
7441 if (start >= block_end || tmp > block_end || tmp < start)
7443 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7446 if (! do_debug_frames_interp || *reg_prefix != '\0')
7448 printf (" DW_CFA_expression: %s%s (",
7449 reg_prefix, regname (reg, 0));
7450 decode_location_expression (start, eh_addr_size, 0, -1,
7454 if (*reg_prefix == '\0')
7455 fc->col_type[reg] = DW_CFA_expression;
7459 case DW_CFA_val_expression:
7462 if (reg >= (unsigned int) fc->ncols)
7463 reg_prefix = bad_reg;
7465 if (start >= block_end || tmp > block_end || tmp < start)
7467 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7470 if (! do_debug_frames_interp || *reg_prefix != '\0')
7472 printf (" DW_CFA_val_expression: %s%s (",
7473 reg_prefix, regname (reg, 0));
7474 decode_location_expression (start, eh_addr_size, 0, -1,
7478 if (*reg_prefix == '\0')
7479 fc->col_type[reg] = DW_CFA_val_expression;
7483 case DW_CFA_offset_extended_sf:
7486 if (frame_need_space (fc, reg) < 0)
7487 reg_prefix = bad_reg;
7488 if (! do_debug_frames_interp || *reg_prefix != '\0')
7489 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7490 reg_prefix, regname (reg, 0),
7491 (long)(l * fc->data_factor));
7492 if (*reg_prefix == '\0')
7494 fc->col_type[reg] = DW_CFA_offset;
7495 fc->col_offset[reg] = l * fc->data_factor;
7499 case DW_CFA_val_offset_sf:
7502 if (frame_need_space (fc, reg) < 0)
7503 reg_prefix = bad_reg;
7504 if (! do_debug_frames_interp || *reg_prefix != '\0')
7505 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7506 reg_prefix, regname (reg, 0),
7507 (long)(l * fc->data_factor));
7508 if (*reg_prefix == '\0')
7510 fc->col_type[reg] = DW_CFA_val_offset;
7511 fc->col_offset[reg] = l * fc->data_factor;
7515 case DW_CFA_def_cfa_sf:
7516 fc->cfa_reg = LEB ();
7517 fc->cfa_offset = SLEB ();
7518 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7520 if (! do_debug_frames_interp)
7521 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7522 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7525 case DW_CFA_def_cfa_offset_sf:
7526 fc->cfa_offset = SLEB ();
7527 fc->cfa_offset *= fc->data_factor;
7528 if (! do_debug_frames_interp)
7529 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7532 case DW_CFA_MIPS_advance_loc8:
7533 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7534 if (do_debug_frames_interp)
7535 frame_display_row (fc, &need_col_headers, &max_regs);
7537 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7538 (unsigned long) (ofs * fc->code_factor),
7539 dwarf_vmatoa_1 (NULL,
7540 fc->pc_begin + ofs * fc->code_factor,
7542 fc->pc_begin += ofs * fc->code_factor;
7545 case DW_CFA_GNU_window_save:
7546 if (! do_debug_frames_interp)
7547 printf (" DW_CFA_GNU_window_save\n");
7550 case DW_CFA_GNU_args_size:
7552 if (! do_debug_frames_interp)
7553 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7556 case DW_CFA_GNU_negative_offset_extended:
7559 if (frame_need_space (fc, reg) < 0)
7560 reg_prefix = bad_reg;
7561 if (! do_debug_frames_interp || *reg_prefix != '\0')
7562 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7563 reg_prefix, regname (reg, 0),
7564 (long)(l * fc->data_factor));
7565 if (*reg_prefix == '\0')
7567 fc->col_type[reg] = DW_CFA_offset;
7568 fc->col_offset[reg] = l * fc->data_factor;
7573 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7574 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7576 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7581 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7582 if (do_debug_frames_interp && ! all_nops)
7583 frame_display_row (fc, &need_col_headers, &max_regs);
7586 eh_addr_size = saved_eh_addr_size;
7599 display_gdb_index (struct dwarf_section *section,
7600 void *file ATTRIBUTE_UNUSED)
7602 unsigned char *start = section->start;
7604 uint32_t cu_list_offset, tu_list_offset;
7605 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
7606 unsigned int cu_list_elements, tu_list_elements;
7607 unsigned int address_table_size, symbol_table_slots;
7608 unsigned char *cu_list, *tu_list;
7609 unsigned char *address_table, *symbol_table, *constant_pool;
7612 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
7614 printf (_("Contents of the %s section:\n"), section->name);
7616 if (section->size < 6 * sizeof (uint32_t))
7618 warn (_("Truncated header in the %s section.\n"), section->name);
7622 version = byte_get_little_endian (start, 4);
7623 printf (_("Version %ld\n"), (long) version);
7625 /* Prior versions are obsolete, and future versions may not be
7626 backwards compatible. */
7627 if (version < 3 || version > 8)
7629 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
7633 warn (_("The address table data in version 3 may be wrong.\n"));
7635 warn (_("Version 4 does not support case insensitive lookups.\n"));
7637 warn (_("Version 5 does not include inlined functions.\n"));
7639 warn (_("Version 6 does not include symbol attributes.\n"));
7640 /* Version 7 indices generated by Gold have bad type unit references,
7641 PR binutils/15021. But we don't know if the index was generated by
7642 Gold or not, so to avoid worrying users with gdb-generated indices
7643 we say nothing for version 7 here. */
7645 cu_list_offset = byte_get_little_endian (start + 4, 4);
7646 tu_list_offset = byte_get_little_endian (start + 8, 4);
7647 address_table_offset = byte_get_little_endian (start + 12, 4);
7648 symbol_table_offset = byte_get_little_endian (start + 16, 4);
7649 constant_pool_offset = byte_get_little_endian (start + 20, 4);
7651 if (cu_list_offset > section->size
7652 || tu_list_offset > section->size
7653 || address_table_offset > section->size
7654 || symbol_table_offset > section->size
7655 || constant_pool_offset > section->size)
7657 warn (_("Corrupt header in the %s section.\n"), section->name);
7661 /* PR 17531: file: 418d0a8a. */
7662 if (tu_list_offset < cu_list_offset)
7664 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
7665 tu_list_offset, cu_list_offset);
7669 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
7671 if (address_table_offset < tu_list_offset)
7673 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
7674 address_table_offset, tu_list_offset);
7678 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
7680 /* PR 17531: file: 18a47d3d. */
7681 if (symbol_table_offset < address_table_offset)
7683 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
7684 symbol_table_offset, address_table_offset);
7688 address_table_size = symbol_table_offset - address_table_offset;
7690 if (constant_pool_offset < symbol_table_offset)
7692 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
7693 constant_pool_offset, symbol_table_offset);
7697 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
7699 cu_list = start + cu_list_offset;
7700 tu_list = start + tu_list_offset;
7701 address_table = start + address_table_offset;
7702 symbol_table = start + symbol_table_offset;
7703 constant_pool = start + constant_pool_offset;
7705 if (address_table + address_table_size > section->start + section->size)
7707 warn (_("Address table extends beyond end of section.\n"));
7711 printf (_("\nCU table:\n"));
7712 for (i = 0; i < cu_list_elements; i += 2)
7714 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
7715 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
7717 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
7718 (unsigned long) cu_offset,
7719 (unsigned long) (cu_offset + cu_length - 1));
7722 printf (_("\nTU table:\n"));
7723 for (i = 0; i < tu_list_elements; i += 3)
7725 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
7726 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
7727 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
7729 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
7730 (unsigned long) tu_offset,
7731 (unsigned long) type_offset);
7732 print_dwarf_vma (signature, 8);
7736 printf (_("\nAddress table:\n"));
7737 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
7740 uint64_t low = byte_get_little_endian (address_table + i, 8);
7741 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
7742 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
7744 print_dwarf_vma (low, 8);
7745 print_dwarf_vma (high, 8);
7746 printf (_("%lu\n"), (unsigned long) cu_index);
7749 printf (_("\nSymbol table:\n"));
7750 for (i = 0; i < symbol_table_slots; ++i)
7752 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
7753 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
7754 uint32_t num_cus, cu;
7756 if (name_offset != 0
7757 || cu_vector_offset != 0)
7760 unsigned char * adr;
7762 adr = constant_pool + name_offset;
7763 /* PR 17531: file: 5b7b07ad. */
7764 if (adr < constant_pool || adr >= section->start + section->size)
7766 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
7767 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
7771 printf ("[%3u] %.*s:", i,
7772 (int) (section->size - (constant_pool_offset + name_offset)),
7773 constant_pool + name_offset);
7775 adr = constant_pool + cu_vector_offset;
7776 if (adr < constant_pool || adr >= section->start + section->size - 3)
7778 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
7779 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
7780 cu_vector_offset, i);
7784 num_cus = byte_get_little_endian (adr, 4);
7786 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
7787 if (num_cus * 4 < num_cus
7788 || adr >= section->start + section->size
7789 || adr < constant_pool)
7791 printf ("<invalid number of CUs: %d>\n", num_cus);
7792 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
7800 for (j = 0; j < num_cus; ++j)
7803 gdb_index_symbol_kind kind;
7805 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7806 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
7807 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
7808 cu = GDB_INDEX_CU_VALUE (cu);
7809 /* Convert to TU number if it's for a type unit. */
7810 if (cu >= cu_list_elements / 2)
7811 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
7812 (unsigned long) (cu - cu_list_elements / 2));
7814 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
7816 printf (" [%s, %s]",
7817 is_static ? _("static") : _("global"),
7818 get_gdb_index_symbol_kind_name (kind));
7830 /* Pre-allocate enough space for the CU/TU sets needed. */
7833 prealloc_cu_tu_list (unsigned int nshndx)
7835 if (shndx_pool == NULL)
7837 shndx_pool_size = nshndx;
7838 shndx_pool_used = 0;
7839 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
7840 sizeof (unsigned int));
7844 shndx_pool_size = shndx_pool_used + nshndx;
7845 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
7846 sizeof (unsigned int));
7851 add_shndx_to_cu_tu_entry (unsigned int shndx)
7853 if (shndx_pool_used >= shndx_pool_size)
7855 error (_("Internal error: out of space in the shndx pool.\n"));
7858 shndx_pool [shndx_pool_used++] = shndx;
7862 end_cu_tu_entry (void)
7864 if (shndx_pool_used >= shndx_pool_size)
7866 error (_("Internal error: out of space in the shndx pool.\n"));
7869 shndx_pool [shndx_pool_used++] = 0;
7872 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7875 get_DW_SECT_short_name (unsigned int dw_sect)
7877 static char buf[16];
7885 case DW_SECT_ABBREV:
7891 case DW_SECT_STR_OFFSETS:
7893 case DW_SECT_MACINFO:
7901 snprintf (buf, sizeof (buf), "%d", dw_sect);
7905 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7906 These sections are extensions for Fission.
7907 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7910 process_cu_tu_index (struct dwarf_section *section, int do_display)
7912 unsigned char *phdr = section->start;
7913 unsigned char *limit = phdr + section->size;
7914 unsigned char *phash;
7915 unsigned char *pindex;
7916 unsigned char *ppool;
7917 unsigned int version;
7918 unsigned int ncols = 0;
7920 unsigned int nslots;
7923 dwarf_vma signature_high;
7924 dwarf_vma signature_low;
7927 /* PR 17512: file: 002-168123-0.004. */
7930 warn (_("Section %s is empty\n"), section->name);
7933 /* PR 17512: file: 002-376-0.004. */
7934 if (section->size < 24)
7936 warn (_("Section %s is too small to contain a CU/TU header\n"),
7941 SAFE_BYTE_GET (version, phdr, 4, limit);
7943 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
7944 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
7945 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
7948 pindex = phash + nslots * 8;
7949 ppool = pindex + nslots * 4;
7951 /* PR 17531: file: 45d69832. */
7952 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
7954 warn (_("Section %s is too small for %d slots\n"),
7955 section->name, nslots);
7961 printf (_("Contents of the %s section:\n\n"), section->name);
7962 printf (_(" Version: %d\n"), version);
7964 printf (_(" Number of columns: %d\n"), ncols);
7965 printf (_(" Number of used entries: %d\n"), nused);
7966 printf (_(" Number of slots: %d\n\n"), nslots);
7969 if (ppool > limit || ppool < phdr)
7971 warn (_("Section %s too small for %d hash table entries\n"),
7972 section->name, nslots);
7979 prealloc_cu_tu_list ((limit - ppool) / 4);
7980 for (i = 0; i < nslots; i++)
7982 unsigned char *shndx_list;
7985 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
7986 if (signature_high != 0 || signature_low != 0)
7988 SAFE_BYTE_GET (j, pindex, 4, limit);
7989 shndx_list = ppool + j * 4;
7990 /* PR 17531: file: 705e010d. */
7991 if (shndx_list < ppool)
7993 warn (_("Section index pool located before start of section\n"));
7998 printf (_(" [%3d] Signature: 0x%s Sections: "),
7999 i, dwarf_vmatoa64 (signature_high, signature_low,
8000 buf, sizeof (buf)));
8003 if (shndx_list >= limit)
8005 warn (_("Section %s too small for shndx pool\n"),
8009 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
8013 printf (" %d", shndx);
8015 add_shndx_to_cu_tu_entry (shndx);
8027 else if (version == 2)
8030 unsigned int dw_sect;
8031 unsigned char *ph = phash;
8032 unsigned char *pi = pindex;
8033 unsigned char *poffsets = ppool + ncols * 4;
8034 unsigned char *psizes = poffsets + nused * ncols * 4;
8035 unsigned char *pend = psizes + nused * ncols * 4;
8036 bfd_boolean is_tu_index;
8037 struct cu_tu_set *this_set = NULL;
8039 unsigned char *prow;
8041 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8043 /* PR 17531: file: 0dd159bf.
8044 Check for wraparound with an overlarge ncols value. */
8045 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
8047 warn (_("Overlarge number of columns: %x\n"), ncols);
8053 warn (_("Section %s too small for offset and size tables\n"),
8060 printf (_(" Offset table\n"));
8061 printf (" slot %-16s ",
8062 is_tu_index ? _("signature") : _("dwo_id"));
8069 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8075 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8082 for (j = 0; j < ncols; j++)
8084 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8085 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8090 for (i = 0; i < nslots; i++)
8092 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8094 SAFE_BYTE_GET (row, pi, 4, limit);
8097 /* PR 17531: file: a05f6ab3. */
8100 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8106 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8108 prow = poffsets + (row - 1) * ncols * 4;
8109 /* PR 17531: file: b8ce60a8. */
8110 if (prow < poffsets || prow > limit)
8112 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8118 printf (_(" [%3d] 0x%s"),
8119 i, dwarf_vmatoa64 (signature_high, signature_low,
8120 buf, sizeof (buf)));
8121 for (j = 0; j < ncols; j++)
8123 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8125 printf (" %8d", val);
8128 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8130 /* PR 17531: file: 10796eb3. */
8131 if (dw_sect >= DW_SECT_MAX)
8132 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8134 this_set [row - 1].section_offsets [dw_sect] = val;
8150 printf (_(" Size table\n"));
8151 printf (" slot %-16s ",
8152 is_tu_index ? _("signature") : _("dwo_id"));
8155 for (j = 0; j < ncols; j++)
8157 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8159 printf (" %8s", get_DW_SECT_short_name (val));
8165 for (i = 0; i < nslots; i++)
8167 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8169 SAFE_BYTE_GET (row, pi, 4, limit);
8172 prow = psizes + (row - 1) * ncols * 4;
8175 printf (_(" [%3d] 0x%s"),
8176 i, dwarf_vmatoa64 (signature_high, signature_low,
8177 buf, sizeof (buf)));
8179 for (j = 0; j < ncols; j++)
8181 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8183 printf (" %8d", val);
8186 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8187 if (dw_sect >= DW_SECT_MAX)
8188 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8190 this_set [row - 1].section_sizes [dw_sect] = val;
8202 else if (do_display)
8203 printf (_(" Unsupported version (%d)\n"), version);
8211 /* Load the CU and TU indexes if present. This will build a list of
8212 section sets that we can use to associate a .debug_info.dwo section
8213 with its associated .debug_abbrev.dwo section in a .dwp file. */
8216 load_cu_tu_indexes (void *file)
8218 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8220 /* If we have already loaded (or tried to load) the CU and TU indexes
8221 then do not bother to repeat the task. */
8222 if (cu_tu_indexes_read == -1)
8224 cu_tu_indexes_read = TRUE;
8226 if (load_debug_section (dwp_cu_index, file))
8227 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8228 cu_tu_indexes_read = FALSE;
8230 if (load_debug_section (dwp_tu_index, file))
8231 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8232 cu_tu_indexes_read = FALSE;
8235 return (bfd_boolean) cu_tu_indexes_read;
8238 /* Find the set of sections that includes section SHNDX. */
8241 find_cu_tu_set (void *file, unsigned int shndx)
8245 if (! load_cu_tu_indexes (file))
8248 /* Find SHNDX in the shndx pool. */
8249 for (i = 0; i < shndx_pool_used; i++)
8250 if (shndx_pool [i] == shndx)
8253 if (i >= shndx_pool_used)
8256 /* Now backup to find the first entry in the set. */
8257 while (i > 0 && shndx_pool [i - 1] != 0)
8260 return shndx_pool + i;
8263 /* Display a .debug_cu_index or .debug_tu_index section. */
8266 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
8268 return process_cu_tu_index (section, 1);
8272 display_debug_not_supported (struct dwarf_section *section,
8273 void *file ATTRIBUTE_UNUSED)
8275 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8281 /* Like malloc, but takes two parameters like calloc.
8282 Verifies that the first parameter is not too large.
8283 Note: does *not* initialise the allocated memory to zero. */
8285 cmalloc (size_t nmemb, size_t size)
8287 /* Check for overflow. */
8288 if (nmemb >= ~(size_t) 0 / size)
8291 return xmalloc (nmemb * size);
8294 /* Like xmalloc, but takes two parameters like calloc.
8295 Verifies that the first parameter is not too large.
8296 Note: does *not* initialise the allocated memory to zero. */
8298 xcmalloc (size_t nmemb, size_t size)
8300 /* Check for overflow. */
8301 if (nmemb >= ~(size_t) 0 / size)
8304 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
8309 return xmalloc (nmemb * size);
8312 /* Like xrealloc, but takes three parameters.
8313 Verifies that the second parameter is not too large.
8314 Note: does *not* initialise any new memory to zero. */
8316 xcrealloc (void *ptr, size_t nmemb, size_t size)
8318 /* Check for overflow. */
8319 if (nmemb >= ~(size_t) 0 / size)
8322 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
8327 return xrealloc (ptr, nmemb * size);
8330 /* Like xcalloc, but verifies that the first parameter is not too large. */
8332 xcalloc2 (size_t nmemb, size_t size)
8334 /* Check for overflow. */
8335 if (nmemb >= ~(size_t) 0 / size)
8338 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
8343 return xcalloc (nmemb, size);
8347 free_debug_memory (void)
8353 for (i = 0; i < max; i++)
8354 free_debug_section ((enum dwarf_section_display_enum) i);
8356 if (debug_information != NULL)
8358 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
8360 for (i = 0; i < num_debug_info_entries; i++)
8362 if (!debug_information [i].max_loc_offsets)
8364 free (debug_information [i].loc_offsets);
8365 free (debug_information [i].have_frame_base);
8367 if (!debug_information [i].max_range_lists)
8368 free (debug_information [i].range_lists);
8371 free (debug_information);
8372 debug_information = NULL;
8373 alloc_num_debug_info_entries = num_debug_info_entries = 0;
8378 dwarf_select_sections_by_names (const char *names)
8382 const char * option;
8386 debug_dump_long_opts;
8388 static const debug_dump_long_opts opts_table [] =
8390 /* Please keep this table alpha- sorted. */
8391 { "Ranges", & do_debug_ranges, 1 },
8392 { "abbrev", & do_debug_abbrevs, 1 },
8393 { "addr", & do_debug_addr, 1 },
8394 { "aranges", & do_debug_aranges, 1 },
8395 { "cu_index", & do_debug_cu_index, 1 },
8396 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
8397 { "frames", & do_debug_frames, 1 },
8398 { "frames-interp", & do_debug_frames_interp, 1 },
8399 /* The special .gdb_index section. */
8400 { "gdb_index", & do_gdb_index, 1 },
8401 { "info", & do_debug_info, 1 },
8402 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
8403 { "loc", & do_debug_loc, 1 },
8404 { "macro", & do_debug_macinfo, 1 },
8405 { "pubnames", & do_debug_pubnames, 1 },
8406 { "pubtypes", & do_debug_pubtypes, 1 },
8407 /* This entry is for compatibility
8408 with earlier versions of readelf. */
8409 { "ranges", & do_debug_aranges, 1 },
8410 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
8411 { "str", & do_debug_str, 1 },
8412 /* These trace_* sections are used by Itanium VMS. */
8413 { "trace_abbrev", & do_trace_abbrevs, 1 },
8414 { "trace_aranges", & do_trace_aranges, 1 },
8415 { "trace_info", & do_trace_info, 1 },
8424 const debug_dump_long_opts * entry;
8426 for (entry = opts_table; entry->option; entry++)
8428 size_t len = strlen (entry->option);
8430 if (strncmp (p, entry->option, len) == 0
8431 && (p[len] == ',' || p[len] == '\0'))
8433 * entry->variable |= entry->val;
8435 /* The --debug-dump=frames-interp option also
8436 enables the --debug-dump=frames option. */
8437 if (do_debug_frames_interp)
8438 do_debug_frames = 1;
8445 if (entry->option == NULL)
8447 warn (_("Unrecognized debug option '%s'\n"), p);
8448 p = strchr (p, ',');
8459 dwarf_select_sections_by_letters (const char *letters)
8461 unsigned int lindex = 0;
8463 while (letters[lindex])
8464 switch (letters[lindex++])
8471 do_debug_abbrevs = 1;
8475 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
8479 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
8483 do_debug_pubnames = 1;
8487 do_debug_pubtypes = 1;
8491 do_debug_aranges = 1;
8495 do_debug_ranges = 1;
8499 do_debug_frames_interp = 1;
8502 do_debug_frames = 1;
8506 do_debug_macinfo = 1;
8518 warn (_("Unrecognized debug option '%s'\n"), letters);
8524 dwarf_select_sections_all (void)
8527 do_debug_abbrevs = 1;
8528 do_debug_lines = FLAG_DEBUG_LINES_RAW;
8529 do_debug_pubnames = 1;
8530 do_debug_pubtypes = 1;
8531 do_debug_aranges = 1;
8532 do_debug_ranges = 1;
8533 do_debug_frames = 1;
8534 do_debug_macinfo = 1;
8539 do_trace_abbrevs = 1;
8540 do_trace_aranges = 1;
8542 do_debug_cu_index = 1;
8545 struct dwarf_section_display debug_displays[] =
8547 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8548 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8549 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8550 display_debug_aranges, &do_debug_aranges, TRUE },
8551 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8552 display_debug_frames, &do_debug_frames, TRUE },
8553 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8554 display_debug_info, &do_debug_info, TRUE },
8555 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8556 display_debug_lines, &do_debug_lines, TRUE },
8557 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8558 display_debug_pubnames, &do_debug_pubnames, FALSE },
8559 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8560 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
8561 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8562 display_debug_frames, &do_debug_frames, TRUE },
8563 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8564 display_debug_macinfo, &do_debug_macinfo, FALSE },
8565 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8566 display_debug_macro, &do_debug_macinfo, TRUE },
8567 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8568 display_debug_str, &do_debug_str, FALSE },
8569 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8570 display_debug_str, &do_debug_str, FALSE },
8571 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8572 display_debug_loc, &do_debug_loc, TRUE },
8573 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8574 display_debug_loc, &do_debug_loc, TRUE },
8575 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8576 display_debug_pubnames, &do_debug_pubtypes, FALSE },
8577 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8578 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
8579 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8580 display_debug_ranges, &do_debug_ranges, TRUE },
8581 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8582 display_debug_ranges, &do_debug_ranges, TRUE },
8583 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8584 display_debug_not_supported, NULL, FALSE },
8585 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8586 display_debug_not_supported, NULL, FALSE },
8587 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
8588 display_debug_types, &do_debug_info, TRUE },
8589 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8590 display_debug_not_supported, NULL, FALSE },
8591 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8592 display_gdb_index, &do_gdb_index, FALSE },
8593 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
8594 display_trace_info, &do_trace_info, TRUE },
8595 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8596 display_debug_abbrev, &do_trace_abbrevs, FALSE },
8597 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8598 display_debug_aranges, &do_trace_aranges, FALSE },
8599 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8600 display_debug_info, &do_debug_info, TRUE },
8601 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8602 display_debug_abbrev, &do_debug_abbrevs, FALSE },
8603 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
8604 display_debug_types, &do_debug_info, TRUE },
8605 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8606 display_debug_lines, &do_debug_lines, TRUE },
8607 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8608 display_debug_loc, &do_debug_loc, TRUE },
8609 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8610 display_debug_macro, &do_debug_macinfo, TRUE },
8611 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8612 display_debug_macinfo, &do_debug_macinfo, FALSE },
8613 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8614 display_debug_str, &do_debug_str, TRUE },
8615 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8616 display_debug_str_offsets, NULL, FALSE },
8617 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8618 display_debug_str_offsets, NULL, FALSE },
8619 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8620 display_debug_addr, &do_debug_addr, TRUE },
8621 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8622 display_cu_index, &do_debug_cu_index, FALSE },
8623 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
8624 display_cu_index, &do_debug_cu_index, FALSE },
8627 /* A static assertion. */
8628 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];