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);
476 data += strnlen ((char *) data, end - data) + 1;
477 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
479 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
481 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
483 printf ("%s\n\n", name);
485 if (((unsigned int) (data - orig_data) != len) || data == end)
486 warn (_("DW_LNE_define_file: Bad opcode length\n"));
489 case DW_LNE_set_discriminator:
490 printf (_("set Discriminator to %s\n"),
491 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
495 case DW_LNE_HP_negate_is_UV_update:
496 printf ("DW_LNE_HP_negate_is_UV_update\n");
498 case DW_LNE_HP_push_context:
499 printf ("DW_LNE_HP_push_context\n");
501 case DW_LNE_HP_pop_context:
502 printf ("DW_LNE_HP_pop_context\n");
504 case DW_LNE_HP_set_file_line_column:
505 printf ("DW_LNE_HP_set_file_line_column\n");
507 case DW_LNE_HP_set_routine_name:
508 printf ("DW_LNE_HP_set_routine_name\n");
510 case DW_LNE_HP_set_sequence:
511 printf ("DW_LNE_HP_set_sequence\n");
513 case DW_LNE_HP_negate_post_semantics:
514 printf ("DW_LNE_HP_negate_post_semantics\n");
516 case DW_LNE_HP_negate_function_exit:
517 printf ("DW_LNE_HP_negate_function_exit\n");
519 case DW_LNE_HP_negate_front_end_logical:
520 printf ("DW_LNE_HP_negate_front_end_logical\n");
522 case DW_LNE_HP_define_proc:
523 printf ("DW_LNE_HP_define_proc\n");
525 case DW_LNE_HP_source_file_correlation:
527 unsigned char *edata = data + len - bytes_read - 1;
529 printf ("DW_LNE_HP_source_file_correlation\n");
535 opc = read_uleb128 (data, & bytes_read, edata);
540 case DW_LNE_HP_SFC_formfeed:
541 printf (" DW_LNE_HP_SFC_formfeed\n");
543 case DW_LNE_HP_SFC_set_listing_line:
544 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
546 read_uleb128 (data, & bytes_read, edata)));
549 case DW_LNE_HP_SFC_associate:
550 printf (" DW_LNE_HP_SFC_associate ");
553 read_uleb128 (data, & bytes_read, edata)));
557 read_uleb128 (data, & bytes_read, edata)));
561 read_uleb128 (data, & bytes_read, edata)));
565 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
575 unsigned int rlen = len - bytes_read - 1;
577 if (op_code >= DW_LNE_lo_user
578 /* The test against DW_LNW_hi_user is redundant due to
579 the limited range of the unsigned char data type used
581 /*&& op_code <= DW_LNE_hi_user*/)
582 printf (_("user defined: "));
584 printf (_("UNKNOWN: "));
585 printf (_("length %d ["), rlen);
587 printf (" %02x", *data++);
596 static const unsigned char *
597 fetch_indirect_string (dwarf_vma offset)
599 struct dwarf_section *section = &debug_displays [str].section;
601 if (section->start == NULL)
602 return (const unsigned char *) _("<no .debug_str section>");
604 if (offset > section->size)
606 warn (_("DW_FORM_strp offset too big: %s\n"),
607 dwarf_vmatoa ("x", offset));
608 return (const unsigned char *) _("<offset is too big>");
611 return (const unsigned char *) section->start + offset;
615 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
616 dwarf_vma offset_size, int dwo)
618 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
619 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
620 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
621 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
622 dwarf_vma index_offset = idx * offset_size;
623 dwarf_vma str_offset;
625 if (index_section->start == NULL)
626 return (dwo ? _("<no .debug_str_offsets.dwo section>")
627 : _("<no .debug_str_offsets section>"));
629 if (this_set != NULL)
630 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
631 if (index_offset > index_section->size)
633 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
634 dwarf_vmatoa ("x", index_offset));
635 return _("<index offset is too big>");
638 if (str_section->start == NULL)
639 return (dwo ? _("<no .debug_str.dwo section>")
640 : _("<no .debug_str section>"));
642 str_offset = byte_get (index_section->start + index_offset, offset_size);
643 str_offset -= str_section->address;
644 if (str_offset > str_section->size)
646 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
647 dwarf_vmatoa ("x", str_offset));
648 return _("<indirect index offset is too big>");
651 return (const char *) str_section->start + str_offset;
655 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
657 struct dwarf_section *section = &debug_displays [debug_addr].section;
659 if (section->start == NULL)
660 return (_("<no .debug_addr section>"));
662 if (offset + bytes > section->size)
664 warn (_("Offset into section %s too big: %s\n"),
665 section->name, dwarf_vmatoa ("x", offset));
666 return "<offset too big>";
669 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
673 /* FIXME: There are better and more efficient ways to handle
674 these structures. For now though, I just want something that
675 is simple to implement. */
676 typedef struct abbrev_attr
678 unsigned long attribute;
680 struct abbrev_attr *next;
684 typedef struct abbrev_entry
689 struct abbrev_attr *first_attr;
690 struct abbrev_attr *last_attr;
691 struct abbrev_entry *next;
695 static abbrev_entry *first_abbrev = NULL;
696 static abbrev_entry *last_abbrev = NULL;
703 for (abbrv = first_abbrev; abbrv;)
705 abbrev_entry *next_abbrev = abbrv->next;
708 for (attr = abbrv->first_attr; attr;)
710 abbrev_attr *next_attr = attr->next;
720 last_abbrev = first_abbrev = NULL;
724 add_abbrev (unsigned long number, unsigned long tag, int children)
728 entry = (abbrev_entry *) malloc (sizeof (*entry));
733 entry->entry = number;
735 entry->children = children;
736 entry->first_attr = NULL;
737 entry->last_attr = NULL;
740 if (first_abbrev == NULL)
741 first_abbrev = entry;
743 last_abbrev->next = entry;
749 add_abbrev_attr (unsigned long attribute, unsigned long form)
753 attr = (abbrev_attr *) malloc (sizeof (*attr));
758 attr->attribute = attribute;
762 if (last_abbrev->first_attr == NULL)
763 last_abbrev->first_attr = attr;
765 last_abbrev->last_attr->next = attr;
767 last_abbrev->last_attr = attr;
770 /* Processes the (partial) contents of a .debug_abbrev section.
771 Returns NULL if the end of the section was encountered.
772 Returns the address after the last byte read if the end of
773 an abbreviation set was found. */
775 static unsigned char *
776 process_abbrev_section (unsigned char *start, unsigned char *end)
778 if (first_abbrev != NULL)
783 unsigned int bytes_read;
786 unsigned long attribute;
789 entry = read_uleb128 (start, & bytes_read, end);
792 /* A single zero is supposed to end the section according
793 to the standard. If there's more, then signal that to
800 tag = read_uleb128 (start, & bytes_read, end);
807 add_abbrev (entry, tag, children);
813 attribute = read_uleb128 (start, & bytes_read, end);
818 form = read_uleb128 (start, & bytes_read, end);
823 add_abbrev_attr (attribute, form);
825 while (attribute != 0);
828 /* Report the missing single zero which ends the section. */
829 error (_(".debug_abbrev section not zero terminated\n"));
835 get_TAG_name (unsigned long tag)
837 const char *name = get_DW_TAG_name ((unsigned int)tag);
841 static char buffer[100];
843 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
851 get_FORM_name (unsigned long form)
856 return "DW_FORM value: 0";
858 name = get_DW_FORM_name (form);
861 static char buffer[100];
863 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
870 static unsigned char *
871 display_block (unsigned char *data,
873 const unsigned char * const end)
877 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
879 return (unsigned char *) end;
881 maxlen = (dwarf_vma) (end - data);
882 length = length > maxlen ? maxlen : length;
885 printf ("%lx ", (unsigned long) byte_get (data++, 1));
891 decode_location_expression (unsigned char * data,
892 unsigned int pointer_size,
893 unsigned int offset_size,
897 struct dwarf_section * section)
900 unsigned int bytes_read;
902 dwarf_signed_vma svalue;
903 unsigned char *end = data + length;
904 int need_frame_base = 0;
913 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
914 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
917 printf ("DW_OP_deref");
920 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
921 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
924 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
925 printf ("DW_OP_const1s: %ld", (long) svalue);
928 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
929 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
932 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
933 printf ("DW_OP_const2s: %ld", (long) svalue);
936 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
937 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
940 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
941 printf ("DW_OP_const4s: %ld", (long) svalue);
944 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
945 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
946 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
947 printf ("%lu", (unsigned long) uvalue);
950 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
951 printf ("DW_OP_const8s: %ld ", (long) svalue);
952 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
953 printf ("%ld", (long) svalue);
956 printf ("DW_OP_constu: %s",
957 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
961 printf ("DW_OP_consts: %s",
962 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
966 printf ("DW_OP_dup");
969 printf ("DW_OP_drop");
972 printf ("DW_OP_over");
975 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
976 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
979 printf ("DW_OP_swap");
982 printf ("DW_OP_rot");
985 printf ("DW_OP_xderef");
988 printf ("DW_OP_abs");
991 printf ("DW_OP_and");
994 printf ("DW_OP_div");
997 printf ("DW_OP_minus");
1000 printf ("DW_OP_mod");
1003 printf ("DW_OP_mul");
1006 printf ("DW_OP_neg");
1009 printf ("DW_OP_not");
1012 printf ("DW_OP_or");
1015 printf ("DW_OP_plus");
1017 case DW_OP_plus_uconst:
1018 printf ("DW_OP_plus_uconst: %s",
1019 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1023 printf ("DW_OP_shl");
1026 printf ("DW_OP_shr");
1029 printf ("DW_OP_shra");
1032 printf ("DW_OP_xor");
1035 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1036 printf ("DW_OP_bra: %ld", (long) svalue);
1039 printf ("DW_OP_eq");
1042 printf ("DW_OP_ge");
1045 printf ("DW_OP_gt");
1048 printf ("DW_OP_le");
1051 printf ("DW_OP_lt");
1054 printf ("DW_OP_ne");
1057 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1058 printf ("DW_OP_skip: %ld", (long) svalue);
1093 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1128 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1129 regname (op - DW_OP_reg0, 1));
1164 printf ("DW_OP_breg%d (%s): %s",
1166 regname (op - DW_OP_breg0, 1),
1167 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1172 uvalue = read_uleb128 (data, &bytes_read, end);
1174 printf ("DW_OP_regx: %s (%s)",
1175 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1178 need_frame_base = 1;
1179 printf ("DW_OP_fbreg: %s",
1180 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1184 uvalue = read_uleb128 (data, &bytes_read, end);
1186 printf ("DW_OP_bregx: %s (%s) %s",
1187 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1188 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1192 printf ("DW_OP_piece: %s",
1193 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1196 case DW_OP_deref_size:
1197 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1198 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1200 case DW_OP_xderef_size:
1201 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1202 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1205 printf ("DW_OP_nop");
1208 /* DWARF 3 extensions. */
1209 case DW_OP_push_object_address:
1210 printf ("DW_OP_push_object_address");
1213 /* XXX: Strictly speaking for 64-bit DWARF3 files
1214 this ought to be an 8-byte wide computation. */
1215 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1216 printf ("DW_OP_call2: <0x%s>",
1217 dwarf_vmatoa ("x", svalue + cu_offset));
1220 /* XXX: Strictly speaking for 64-bit DWARF3 files
1221 this ought to be an 8-byte wide computation. */
1222 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1223 printf ("DW_OP_call4: <0x%s>",
1224 dwarf_vmatoa ("x", svalue + cu_offset));
1226 case DW_OP_call_ref:
1227 /* XXX: Strictly speaking for 64-bit DWARF3 files
1228 this ought to be an 8-byte wide computation. */
1229 if (dwarf_version == -1)
1231 printf (_("(DW_OP_call_ref in frame info)"));
1232 /* No way to tell where the next op is, so just bail. */
1233 return need_frame_base;
1235 if (dwarf_version == 2)
1237 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1241 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1243 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1245 case DW_OP_form_tls_address:
1246 printf ("DW_OP_form_tls_address");
1248 case DW_OP_call_frame_cfa:
1249 printf ("DW_OP_call_frame_cfa");
1251 case DW_OP_bit_piece:
1252 printf ("DW_OP_bit_piece: ");
1253 printf (_("size: %s "),
1254 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1256 printf (_("offset: %s "),
1257 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1261 /* DWARF 4 extensions. */
1262 case DW_OP_stack_value:
1263 printf ("DW_OP_stack_value");
1266 case DW_OP_implicit_value:
1267 printf ("DW_OP_implicit_value");
1268 uvalue = read_uleb128 (data, &bytes_read, end);
1270 data = display_block (data, uvalue, end);
1273 /* GNU extensions. */
1274 case DW_OP_GNU_push_tls_address:
1275 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1277 case DW_OP_GNU_uninit:
1278 printf ("DW_OP_GNU_uninit");
1279 /* FIXME: Is there data associated with this OP ? */
1281 case DW_OP_GNU_encoded_addr:
1288 addr = get_encoded_value (&data, encoding, section, end);
1290 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1291 print_dwarf_vma (addr, pointer_size);
1294 case DW_OP_GNU_implicit_pointer:
1295 /* XXX: Strictly speaking for 64-bit DWARF3 files
1296 this ought to be an 8-byte wide computation. */
1297 if (dwarf_version == -1)
1299 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1300 /* No way to tell where the next op is, so just bail. */
1301 return need_frame_base;
1303 if (dwarf_version == 2)
1305 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1309 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1311 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1312 dwarf_vmatoa ("x", uvalue),
1313 dwarf_vmatoa ("d", read_sleb128 (data,
1314 &bytes_read, end)));
1317 case DW_OP_GNU_entry_value:
1318 uvalue = read_uleb128 (data, &bytes_read, end);
1320 /* PR 17531: file: 0cc9cd00. */
1321 if (uvalue > (dwarf_vma) (end - data))
1322 uvalue = end - data;
1323 printf ("DW_OP_GNU_entry_value: (");
1324 if (decode_location_expression (data, pointer_size, offset_size,
1325 dwarf_version, uvalue,
1326 cu_offset, section))
1327 need_frame_base = 1;
1333 case DW_OP_GNU_const_type:
1334 uvalue = read_uleb128 (data, &bytes_read, end);
1336 printf ("DW_OP_GNU_const_type: <0x%s> ",
1337 dwarf_vmatoa ("x", cu_offset + uvalue));
1338 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1339 data = display_block (data, uvalue, end);
1341 case DW_OP_GNU_regval_type:
1342 uvalue = read_uleb128 (data, &bytes_read, end);
1344 printf ("DW_OP_GNU_regval_type: %s (%s)",
1345 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1346 uvalue = read_uleb128 (data, &bytes_read, end);
1348 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1350 case DW_OP_GNU_deref_type:
1351 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1352 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
1353 uvalue = read_uleb128 (data, &bytes_read, end);
1355 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1357 case DW_OP_GNU_convert:
1358 uvalue = read_uleb128 (data, &bytes_read, end);
1360 printf ("DW_OP_GNU_convert <0x%s>",
1361 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1363 case DW_OP_GNU_reinterpret:
1364 uvalue = read_uleb128 (data, &bytes_read, end);
1366 printf ("DW_OP_GNU_reinterpret <0x%s>",
1367 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1369 case DW_OP_GNU_parameter_ref:
1370 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1371 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1372 dwarf_vmatoa ("x", cu_offset + uvalue));
1374 case DW_OP_GNU_addr_index:
1375 uvalue = read_uleb128 (data, &bytes_read, end);
1377 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1379 case DW_OP_GNU_const_index:
1380 uvalue = read_uleb128 (data, &bytes_read, end);
1382 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1385 /* HP extensions. */
1386 case DW_OP_HP_is_value:
1387 printf ("DW_OP_HP_is_value");
1388 /* FIXME: Is there data associated with this OP ? */
1390 case DW_OP_HP_fltconst4:
1391 printf ("DW_OP_HP_fltconst4");
1392 /* FIXME: Is there data associated with this OP ? */
1394 case DW_OP_HP_fltconst8:
1395 printf ("DW_OP_HP_fltconst8");
1396 /* FIXME: Is there data associated with this OP ? */
1398 case DW_OP_HP_mod_range:
1399 printf ("DW_OP_HP_mod_range");
1400 /* FIXME: Is there data associated with this OP ? */
1402 case DW_OP_HP_unmod_range:
1403 printf ("DW_OP_HP_unmod_range");
1404 /* FIXME: Is there data associated with this OP ? */
1407 printf ("DW_OP_HP_tls");
1408 /* FIXME: Is there data associated with this OP ? */
1411 /* PGI (STMicroelectronics) extensions. */
1412 case DW_OP_PGI_omp_thread_num:
1413 /* Pushes the thread number for the current thread as it would be
1414 returned by the standard OpenMP library function:
1415 omp_get_thread_num(). The "current thread" is the thread for
1416 which the expression is being evaluated. */
1417 printf ("DW_OP_PGI_omp_thread_num");
1421 if (op >= DW_OP_lo_user
1422 && op <= DW_OP_hi_user)
1423 printf (_("(User defined location op)"));
1425 printf (_("(Unknown location op)"));
1426 /* No way to tell where the next op is, so just bail. */
1427 return need_frame_base;
1430 /* Separate the ops. */
1435 return need_frame_base;
1438 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1439 This is used for DWARF package files. */
1441 static struct cu_tu_set *
1442 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1444 struct cu_tu_set *p;
1446 unsigned int dw_sect;
1452 dw_sect = DW_SECT_TYPES;
1458 dw_sect = DW_SECT_INFO;
1462 if (p->section_offsets [dw_sect] == cu_offset)
1470 /* Add INC to HIGH_BITS:LOW_BITS. */
1472 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1474 dwarf_vma tmp = * low_bits;
1478 /* FIXME: There is probably a better way of handling this:
1480 We need to cope with dwarf_vma being a 32-bit or 64-bit
1481 type. Plus regardless of its size LOW_BITS is meant to
1482 only hold 32-bits, so if there is overflow or wrap around
1483 we must propagate into HIGH_BITS. */
1484 if (tmp < * low_bits)
1488 else if (sizeof (tmp) > 8
1498 static unsigned char *
1499 read_and_display_attr_value (unsigned long attribute,
1501 unsigned char * data,
1502 unsigned char * end,
1503 dwarf_vma cu_offset,
1504 dwarf_vma pointer_size,
1505 dwarf_vma offset_size,
1507 debug_info * debug_info_p,
1509 struct dwarf_section * section,
1510 struct cu_tu_set * this_set)
1512 dwarf_vma uvalue = 0;
1513 unsigned char *block_start = NULL;
1514 unsigned char * orig_data = data;
1515 unsigned int bytes_read;
1517 if (data > end || (data == end && form != DW_FORM_flag_present))
1519 warn (_("Corrupt attribute\n"));
1528 case DW_FORM_ref_addr:
1529 if (dwarf_version == 2)
1530 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1531 else if (dwarf_version == 3 || dwarf_version == 4)
1532 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1534 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1539 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1543 case DW_FORM_sec_offset:
1544 case DW_FORM_GNU_ref_alt:
1545 case DW_FORM_GNU_strp_alt:
1546 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1549 case DW_FORM_flag_present:
1556 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1561 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1566 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1570 uvalue = read_sleb128 (data, & bytes_read, end);
1574 case DW_FORM_GNU_str_index:
1575 uvalue = read_uleb128 (data, & bytes_read, end);
1579 case DW_FORM_ref_udata:
1581 uvalue = read_uleb128 (data, & bytes_read, end);
1585 case DW_FORM_indirect:
1586 form = read_uleb128 (data, & bytes_read, end);
1589 printf (" %s", get_FORM_name (form));
1590 return read_and_display_attr_value (attribute, form, data, end,
1591 cu_offset, pointer_size,
1592 offset_size, dwarf_version,
1593 debug_info_p, do_loc,
1595 case DW_FORM_GNU_addr_index:
1596 uvalue = read_uleb128 (data, & bytes_read, end);
1603 case DW_FORM_ref_addr:
1605 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1608 case DW_FORM_GNU_ref_alt:
1610 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1616 case DW_FORM_ref_udata:
1618 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1623 case DW_FORM_sec_offset:
1625 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1628 case DW_FORM_flag_present:
1635 printf (" %s", dwarf_vmatoa ("d", uvalue));
1642 dwarf_vma high_bits;
1646 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1648 if (form == DW_FORM_ref8)
1649 add64 (& high_bits, & utmp, cu_offset);
1651 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1654 if ((do_loc || do_debug_loc || do_debug_ranges)
1655 && num_debug_info_entries == 0)
1657 if (sizeof (uvalue) == 8)
1658 SAFE_BYTE_GET (uvalue, data, 8, end);
1660 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1666 case DW_FORM_string:
1668 printf (" %.*s", (int) (end - data), data);
1669 data += strnlen ((char *) data, end - data) + 1;
1673 case DW_FORM_exprloc:
1674 uvalue = read_uleb128 (data, & bytes_read, end);
1675 block_start = data + bytes_read;
1676 if (block_start >= end)
1678 warn (_("Block ends prematurely\n"));
1682 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1683 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1684 block_start + uvalue here. */
1685 data = block_start + uvalue;
1686 /* PR 17512: file: 008-103549-0.001:0.1. */
1687 if (block_start + uvalue > end || data < block_start)
1689 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1690 uvalue = end - block_start;
1693 data = block_start + uvalue;
1695 data = display_block (block_start, uvalue, end);
1698 case DW_FORM_block1:
1699 SAFE_BYTE_GET (uvalue, data, 1, end);
1700 block_start = data + 1;
1701 if (block_start >= end)
1703 warn (_("Block ends prematurely\n"));
1707 data = block_start + uvalue;
1708 if (block_start + uvalue > end || data < block_start)
1710 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1711 uvalue = end - block_start;
1714 data = block_start + uvalue;
1716 data = display_block (block_start, uvalue, end);
1719 case DW_FORM_block2:
1720 SAFE_BYTE_GET (uvalue, data, 2, end);
1721 block_start = data + 2;
1722 if (block_start >= end)
1724 warn (_("Block ends prematurely\n"));
1728 data = block_start + uvalue;
1729 if (block_start + uvalue > end || data < block_start)
1731 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1732 uvalue = end - block_start;
1735 data = block_start + uvalue;
1737 data = display_block (block_start, uvalue, end);
1740 case DW_FORM_block4:
1741 SAFE_BYTE_GET (uvalue, data, 4, end);
1742 block_start = data + 4;
1743 /* PR 17512: file: 3371-3907-0.004. */
1744 if (block_start >= end)
1746 warn (_("Block ends prematurely\n"));
1750 data = block_start + uvalue;
1751 if (block_start + uvalue > end
1752 /* PR 17531: file: 5b5f0592. */
1753 || data < block_start)
1755 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1756 uvalue = end - block_start;
1759 data = block_start + uvalue;
1761 data = display_block (block_start, uvalue, end);
1766 printf (_(" (indirect string, offset: 0x%s): %s"),
1767 dwarf_vmatoa ("x", uvalue),
1768 fetch_indirect_string (uvalue));
1771 case DW_FORM_GNU_str_index:
1774 const char *suffix = strrchr (section->name, '.');
1775 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1777 printf (_(" (indexed string: 0x%s): %s"),
1778 dwarf_vmatoa ("x", uvalue),
1779 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1783 case DW_FORM_GNU_strp_alt:
1785 printf (_(" (alt indirect string, offset: 0x%s)"),
1786 dwarf_vmatoa ("x", uvalue));
1789 case DW_FORM_indirect:
1790 /* Handled above. */
1793 case DW_FORM_ref_sig8:
1796 dwarf_vma high_bits;
1799 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1800 printf (" signature: 0x%s",
1801 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1806 case DW_FORM_GNU_addr_index:
1808 printf (_(" (addr_index: 0x%s): %s"),
1809 dwarf_vmatoa ("x", uvalue),
1810 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1814 warn (_("Unrecognized form: %lu\n"), form);
1818 if ((do_loc || do_debug_loc || do_debug_ranges)
1819 && num_debug_info_entries == 0
1820 && debug_info_p != NULL)
1824 case DW_AT_frame_base:
1825 have_frame_base = 1;
1827 case DW_AT_location:
1828 case DW_AT_string_length:
1829 case DW_AT_return_addr:
1830 case DW_AT_data_member_location:
1831 case DW_AT_vtable_elem_location:
1833 case DW_AT_static_link:
1834 case DW_AT_use_location:
1835 case DW_AT_GNU_call_site_value:
1836 case DW_AT_GNU_call_site_data_value:
1837 case DW_AT_GNU_call_site_target:
1838 case DW_AT_GNU_call_site_target_clobbered:
1839 if ((dwarf_version < 4
1840 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1841 || form == DW_FORM_sec_offset)
1843 /* Process location list. */
1844 unsigned int lmax = debug_info_p->max_loc_offsets;
1845 unsigned int num = debug_info_p->num_loc_offsets;
1847 if (lmax == 0 || num >= lmax)
1850 debug_info_p->loc_offsets = (dwarf_vma *)
1851 xcrealloc (debug_info_p->loc_offsets,
1852 lmax, sizeof (*debug_info_p->loc_offsets));
1853 debug_info_p->have_frame_base = (int *)
1854 xcrealloc (debug_info_p->have_frame_base,
1855 lmax, sizeof (*debug_info_p->have_frame_base));
1856 debug_info_p->max_loc_offsets = lmax;
1858 if (this_set != NULL)
1859 uvalue += this_set->section_offsets [DW_SECT_LOC];
1860 debug_info_p->loc_offsets [num] = uvalue;
1861 debug_info_p->have_frame_base [num] = have_frame_base;
1862 debug_info_p->num_loc_offsets++;
1867 if (need_base_address)
1868 debug_info_p->base_address = uvalue;
1871 case DW_AT_GNU_addr_base:
1872 debug_info_p->addr_base = uvalue;
1875 case DW_AT_GNU_ranges_base:
1876 debug_info_p->ranges_base = uvalue;
1880 if ((dwarf_version < 4
1881 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1882 || form == DW_FORM_sec_offset)
1884 /* Process range list. */
1885 unsigned int lmax = debug_info_p->max_range_lists;
1886 unsigned int num = debug_info_p->num_range_lists;
1888 if (lmax == 0 || num >= lmax)
1891 debug_info_p->range_lists = (dwarf_vma *)
1892 xcrealloc (debug_info_p->range_lists,
1893 lmax, sizeof (*debug_info_p->range_lists));
1894 debug_info_p->max_range_lists = lmax;
1896 debug_info_p->range_lists [num] = uvalue;
1897 debug_info_p->num_range_lists++;
1906 if (do_loc || attribute == 0)
1909 /* For some attributes we can display further information. */
1916 case DW_INL_not_inlined:
1917 printf (_("(not inlined)"));
1919 case DW_INL_inlined:
1920 printf (_("(inlined)"));
1922 case DW_INL_declared_not_inlined:
1923 printf (_("(declared as inline but ignored)"));
1925 case DW_INL_declared_inlined:
1926 printf (_("(declared as inline and inlined)"));
1929 printf (_(" (Unknown inline attribute value: %s)"),
1930 dwarf_vmatoa ("x", uvalue));
1935 case DW_AT_language:
1939 /* Ordered by the numeric value of these constants. */
1940 case DW_LANG_C89: printf ("(ANSI C)"); break;
1941 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1942 case DW_LANG_Ada83: printf ("(Ada)"); break;
1943 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1944 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1945 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1946 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1947 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1948 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1949 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1950 /* DWARF 2.1 values. */
1951 case DW_LANG_Java: printf ("(Java)"); break;
1952 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1953 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1954 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1955 /* DWARF 3 values. */
1956 case DW_LANG_PLI: printf ("(PLI)"); break;
1957 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1958 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1959 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1960 case DW_LANG_D: printf ("(D)"); break;
1961 /* DWARF 4 values. */
1962 case DW_LANG_Python: printf ("(Python)"); break;
1963 /* DWARF 5 values. */
1964 case DW_LANG_Go: printf ("(Go)"); break;
1965 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
1966 case DW_LANG_C11: printf ("(C11)"); break;
1967 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
1968 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
1969 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
1970 /* MIPS extension. */
1971 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1972 /* UPC extension. */
1973 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1975 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1976 printf (_("(implementation defined: %s)"),
1977 dwarf_vmatoa ("x", uvalue));
1979 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1984 case DW_AT_encoding:
1988 case DW_ATE_void: printf ("(void)"); break;
1989 case DW_ATE_address: printf ("(machine address)"); break;
1990 case DW_ATE_boolean: printf ("(boolean)"); break;
1991 case DW_ATE_complex_float: printf ("(complex float)"); break;
1992 case DW_ATE_float: printf ("(float)"); break;
1993 case DW_ATE_signed: printf ("(signed)"); break;
1994 case DW_ATE_signed_char: printf ("(signed char)"); break;
1995 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1996 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1997 /* DWARF 2.1 values: */
1998 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1999 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2000 /* DWARF 3 values: */
2001 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2002 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2003 case DW_ATE_edited: printf ("(edited)"); break;
2004 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2005 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2006 /* HP extensions: */
2007 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2008 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2009 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2010 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2011 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2012 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2013 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2014 /* DWARF 4 values: */
2015 case DW_ATE_UTF: printf ("(unicode string)"); break;
2018 if (uvalue >= DW_ATE_lo_user
2019 && uvalue <= DW_ATE_hi_user)
2020 printf (_("(user defined type)"));
2022 printf (_("(unknown type)"));
2027 case DW_AT_accessibility:
2031 case DW_ACCESS_public: printf ("(public)"); break;
2032 case DW_ACCESS_protected: printf ("(protected)"); break;
2033 case DW_ACCESS_private: printf ("(private)"); break;
2035 printf (_("(unknown accessibility)"));
2040 case DW_AT_visibility:
2044 case DW_VIS_local: printf ("(local)"); break;
2045 case DW_VIS_exported: printf ("(exported)"); break;
2046 case DW_VIS_qualified: printf ("(qualified)"); break;
2047 default: printf (_("(unknown visibility)")); break;
2051 case DW_AT_virtuality:
2055 case DW_VIRTUALITY_none: printf ("(none)"); break;
2056 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2057 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2058 default: printf (_("(unknown virtuality)")); break;
2062 case DW_AT_identifier_case:
2066 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2067 case DW_ID_up_case: printf ("(up_case)"); break;
2068 case DW_ID_down_case: printf ("(down_case)"); break;
2069 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2070 default: printf (_("(unknown case)")); break;
2074 case DW_AT_calling_convention:
2078 case DW_CC_normal: printf ("(normal)"); break;
2079 case DW_CC_program: printf ("(program)"); break;
2080 case DW_CC_nocall: printf ("(nocall)"); break;
2082 if (uvalue >= DW_CC_lo_user
2083 && uvalue <= DW_CC_hi_user)
2084 printf (_("(user defined)"));
2086 printf (_("(unknown convention)"));
2090 case DW_AT_ordering:
2094 case -1: printf (_("(undefined)")); break;
2095 case 0: printf ("(row major)"); break;
2096 case 1: printf ("(column major)"); break;
2100 case DW_AT_frame_base:
2101 have_frame_base = 1;
2103 case DW_AT_location:
2104 case DW_AT_string_length:
2105 case DW_AT_return_addr:
2106 case DW_AT_data_member_location:
2107 case DW_AT_vtable_elem_location:
2109 case DW_AT_static_link:
2110 case DW_AT_use_location:
2111 case DW_AT_GNU_call_site_value:
2112 case DW_AT_GNU_call_site_data_value:
2113 case DW_AT_GNU_call_site_target:
2114 case DW_AT_GNU_call_site_target_clobbered:
2115 if ((dwarf_version < 4
2116 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2117 || form == DW_FORM_sec_offset)
2118 printf (_(" (location list)"));
2120 case DW_AT_allocated:
2121 case DW_AT_associated:
2122 case DW_AT_data_location:
2124 case DW_AT_upper_bound:
2125 case DW_AT_lower_bound:
2128 int need_frame_base;
2131 need_frame_base = decode_location_expression (block_start,
2136 cu_offset, section);
2138 if (need_frame_base && !have_frame_base)
2139 printf (_(" [without DW_AT_frame_base]"));
2145 if (form == DW_FORM_ref_sig8
2146 || form == DW_FORM_GNU_ref_alt)
2149 if (form == DW_FORM_ref1
2150 || form == DW_FORM_ref2
2151 || form == DW_FORM_ref4
2152 || form == DW_FORM_ref_udata)
2153 uvalue += cu_offset;
2155 if (uvalue >= section->size)
2156 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2157 dwarf_vmatoa ("x", uvalue),
2158 (unsigned long) (orig_data - section->start));
2161 unsigned long abbrev_number;
2162 abbrev_entry * entry;
2164 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2166 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2167 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2168 use different abbrev table, and we don't track .debug_info chunks
2170 if (form != DW_FORM_ref_addr)
2172 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2173 if (entry->entry == abbrev_number)
2176 printf (" (%s)", get_TAG_name (entry->tag));
2191 get_AT_name (unsigned long attribute)
2196 return "DW_AT value: 0";
2198 /* One value is shared by the MIPS and HP extensions: */
2199 if (attribute == DW_AT_MIPS_fde)
2200 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2202 name = get_DW_AT_name (attribute);
2206 static char buffer[100];
2208 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2216 static unsigned char *
2217 read_and_display_attr (unsigned long attribute,
2219 unsigned char * data,
2220 unsigned char * end,
2221 dwarf_vma cu_offset,
2222 dwarf_vma pointer_size,
2223 dwarf_vma offset_size,
2225 debug_info * debug_info_p,
2227 struct dwarf_section * section,
2228 struct cu_tu_set * this_set)
2231 printf (" %-18s:", get_AT_name (attribute));
2232 data = read_and_display_attr_value (attribute, form, data, end,
2233 cu_offset, pointer_size, offset_size,
2234 dwarf_version, debug_info_p,
2235 do_loc, section, this_set);
2241 /* Process the contents of a .debug_info section. If do_loc is non-zero
2242 then we are scanning for location lists and we do not want to display
2243 anything to the user. If do_types is non-zero, we are processing
2244 a .debug_types section instead of a .debug_info section. */
2247 process_debug_info (struct dwarf_section *section,
2249 enum dwarf_section_display_enum abbrev_sec,
2253 unsigned char *start = section->start;
2254 unsigned char *end = start + section->size;
2255 unsigned char *section_begin;
2257 unsigned int num_units = 0;
2259 if ((do_loc || do_debug_loc || do_debug_ranges)
2260 && num_debug_info_entries == 0
2265 /* First scan the section to get the number of comp units. */
2266 for (section_begin = start, num_units = 0; section_begin < end;
2269 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2270 will be the length. For a 64-bit DWARF section, it'll be
2271 the escape code 0xffffffff followed by an 8 byte length. */
2272 SAFE_BYTE_GET (length, section_begin, 4, end);
2274 if (length == 0xffffffff)
2276 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2277 section_begin += length + 12;
2279 else if (length >= 0xfffffff0 && length < 0xffffffff)
2281 warn (_("Reserved length value (0x%s) found in section %s\n"),
2282 dwarf_vmatoa ("x", length), section->name);
2286 section_begin += length + 4;
2288 /* Negative values are illegal, they may even cause infinite
2289 looping. This can happen if we can't accurately apply
2290 relocations to an object file, or if the file is corrupt. */
2291 if ((signed long) length <= 0 || section_begin < start)
2293 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2294 dwarf_vmatoa ("x", length), section->name);
2301 error (_("No comp units in %s section ?\n"), section->name);
2305 /* Then allocate an array to hold the information. */
2306 debug_information = (debug_info *) cmalloc (num_units,
2307 sizeof (* debug_information));
2308 if (debug_information == NULL)
2310 error (_("Not enough memory for a debug info array of %u entries\n"),
2312 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2315 /* PR 17531: file: 92ca3797.
2316 We cannot rely upon the debug_information array being initialised
2317 before it is used. A corrupt file could easily contain references
2318 to a unit for which information has not been made available. So
2319 we ensure that the array is zeroed here. */
2320 memset (debug_information, 0, num_units * sizeof (*debug_information));
2322 alloc_num_debug_info_entries = num_units;
2327 if (dwarf_start_die == 0)
2328 printf (_("Contents of the %s section:\n\n"), section->name);
2330 load_debug_section (str, file);
2331 load_debug_section (str_dwo, file);
2332 load_debug_section (str_index, file);
2333 load_debug_section (str_index_dwo, file);
2334 load_debug_section (debug_addr, file);
2337 load_debug_section (abbrev_sec, file);
2338 if (debug_displays [abbrev_sec].section.start == NULL)
2340 warn (_("Unable to locate %s section!\n"),
2341 debug_displays [abbrev_sec].section.name);
2345 for (section_begin = start, unit = 0; start < end; unit++)
2347 DWARF2_Internal_CompUnit compunit;
2348 unsigned char *hdrptr;
2349 unsigned char *tags;
2350 int level, last_level, saved_level;
2351 dwarf_vma cu_offset;
2352 unsigned int offset_size;
2353 int initial_length_size;
2354 dwarf_vma signature_high = 0;
2355 dwarf_vma signature_low = 0;
2356 dwarf_vma type_offset = 0;
2357 struct cu_tu_set *this_set;
2358 dwarf_vma abbrev_base;
2363 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2365 if (compunit.cu_length == 0xffffffff)
2367 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2369 initial_length_size = 12;
2374 initial_length_size = 4;
2377 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2379 cu_offset = start - section_begin;
2381 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2383 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2385 if (this_set == NULL)
2388 abbrev_size = debug_displays [abbrev_sec].section.size;
2392 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2393 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2396 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2397 /* PR 17512: file: 001-108546-0.001:0.1. */
2398 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2400 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2401 compunit.cu_pointer_size, offset_size);
2402 compunit.cu_pointer_size = offset_size;
2407 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2409 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2412 if ((do_loc || do_debug_loc || do_debug_ranges)
2413 && num_debug_info_entries == 0
2416 debug_information [unit].cu_offset = cu_offset;
2417 debug_information [unit].pointer_size
2418 = compunit.cu_pointer_size;
2419 debug_information [unit].offset_size = offset_size;
2420 debug_information [unit].dwarf_version = compunit.cu_version;
2421 debug_information [unit].base_address = 0;
2422 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2423 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2424 debug_information [unit].loc_offsets = NULL;
2425 debug_information [unit].have_frame_base = NULL;
2426 debug_information [unit].max_loc_offsets = 0;
2427 debug_information [unit].num_loc_offsets = 0;
2428 debug_information [unit].range_lists = NULL;
2429 debug_information [unit].max_range_lists= 0;
2430 debug_information [unit].num_range_lists = 0;
2433 if (!do_loc && dwarf_start_die == 0)
2435 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2436 dwarf_vmatoa ("x", cu_offset));
2437 printf (_(" Length: 0x%s (%s)\n"),
2438 dwarf_vmatoa ("x", compunit.cu_length),
2439 offset_size == 8 ? "64-bit" : "32-bit");
2440 printf (_(" Version: %d\n"), compunit.cu_version);
2441 printf (_(" Abbrev Offset: 0x%s\n"),
2442 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2443 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2448 printf (_(" Signature: 0x%s\n"),
2449 dwarf_vmatoa64 (signature_high, signature_low,
2450 buf, sizeof (buf)));
2451 printf (_(" Type Offset: 0x%s\n"),
2452 dwarf_vmatoa ("x", type_offset));
2454 if (this_set != NULL)
2456 dwarf_vma *offsets = this_set->section_offsets;
2457 size_t *sizes = this_set->section_sizes;
2459 printf (_(" Section contributions:\n"));
2460 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2461 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2462 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2463 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2464 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2465 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2466 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2467 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2468 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2469 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2470 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2471 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2475 if (cu_offset + compunit.cu_length + initial_length_size
2478 warn (_("Debug info is corrupted, length of CU at %s"
2479 " extends beyond end of section (length = %s)\n"),
2480 dwarf_vmatoa ("x", cu_offset),
2481 dwarf_vmatoa ("x", compunit.cu_length));
2486 start += compunit.cu_length + initial_length_size;
2490 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2491 dwarf_vmatoa ("x", cu_offset));
2495 if (compunit.cu_version != 2
2496 && compunit.cu_version != 3
2497 && compunit.cu_version != 4)
2499 warn (_("CU at offset %s contains corrupt or "
2500 "unsupported version number: %d.\n"),
2501 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2507 /* Process the abbrevs used by this compilation unit. */
2508 if (compunit.cu_abbrev_offset >= abbrev_size)
2509 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2510 (unsigned long) compunit.cu_abbrev_offset,
2511 (unsigned long) abbrev_size);
2512 /* PR 17531: file:4bcd9ce9. */
2513 else if ((abbrev_base + abbrev_size)
2514 > debug_displays [abbrev_sec].section.size)
2515 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2516 (unsigned long) abbrev_base + abbrev_size,
2517 (unsigned long) debug_displays [abbrev_sec].section.size);
2519 process_abbrev_section
2520 (((unsigned char *) debug_displays [abbrev_sec].section.start
2521 + abbrev_base + compunit.cu_abbrev_offset),
2522 ((unsigned char *) debug_displays [abbrev_sec].section.start
2523 + abbrev_base + abbrev_size));
2528 while (tags < start)
2530 unsigned int bytes_read;
2531 unsigned long abbrev_number;
2532 unsigned long die_offset;
2533 abbrev_entry *entry;
2535 int do_printing = 1;
2537 die_offset = tags - section_begin;
2539 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2542 /* A null DIE marks the end of a list of siblings or it may also be
2543 a section padding. */
2544 if (abbrev_number == 0)
2546 /* Check if it can be a section padding for the last CU. */
2547 if (level == 0 && start == end)
2551 for (chk = tags; chk < start; chk++)
2558 if (!do_loc && die_offset >= dwarf_start_die
2559 && (dwarf_cutoff_level == -1
2560 || level < dwarf_cutoff_level))
2561 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2567 static unsigned num_bogus_warns = 0;
2569 if (num_bogus_warns < 3)
2571 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2572 die_offset, section->name);
2574 if (num_bogus_warns == 3)
2575 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2578 if (dwarf_start_die != 0 && level < saved_level)
2585 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2589 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2590 saved_level = level;
2591 do_printing = (dwarf_cutoff_level == -1
2592 || level < dwarf_cutoff_level);
2594 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2595 level, die_offset, abbrev_number);
2596 else if (dwarf_cutoff_level == -1
2597 || last_level < dwarf_cutoff_level)
2598 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2603 /* Scan through the abbreviation list until we reach the
2605 for (entry = first_abbrev;
2606 entry && entry->entry != abbrev_number;
2607 entry = entry->next)
2612 if (!do_loc && do_printing)
2617 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2618 die_offset, abbrev_number);
2622 if (!do_loc && do_printing)
2623 printf (" (%s)\n", get_TAG_name (entry->tag));
2628 need_base_address = 0;
2630 case DW_TAG_compile_unit:
2631 need_base_address = 1;
2633 case DW_TAG_entry_point:
2634 case DW_TAG_subprogram:
2635 need_base_address = 0;
2636 /* Assuming that there is no DW_AT_frame_base. */
2637 have_frame_base = 0;
2641 for (attr = entry->first_attr;
2642 attr && attr->attribute;
2647 if (! do_loc && do_printing)
2648 /* Show the offset from where the tag was extracted. */
2649 printf (" <%lx>", (unsigned long)(tags - section_begin));
2651 if (debug_information && unit < alloc_num_debug_info_entries)
2652 arg = debug_information + unit;
2656 tags = read_and_display_attr (attr->attribute,
2661 compunit.cu_pointer_size,
2663 compunit.cu_version,
2665 do_loc || ! do_printing,
2670 if (entry->children)
2675 /* Set num_debug_info_entries here so that it can be used to check if
2676 we need to process .debug_loc and .debug_ranges sections. */
2677 if ((do_loc || do_debug_loc || do_debug_ranges)
2678 && num_debug_info_entries == 0
2681 if (num_units > alloc_num_debug_info_entries)
2682 num_debug_info_entries = alloc_num_debug_info_entries;
2684 num_debug_info_entries = num_units;
2693 /* Locate and scan the .debug_info section in the file and record the pointer
2694 sizes and offsets for the compilation units in it. Usually an executable
2695 will have just one pointer size, but this is not guaranteed, and so we try
2696 not to make any assumptions. Returns zero upon failure, or the number of
2697 compilation units upon success. */
2700 load_debug_info (void * file)
2702 /* Reset the last pointer size so that we can issue correct error
2703 messages if we are displaying the contents of more than one section. */
2704 last_pointer_size = 0;
2705 warned_about_missing_comp_units = FALSE;
2707 /* If we have already tried and failed to load the .debug_info
2708 section then do not bother to repeat the task. */
2709 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2712 /* If we already have the information there is nothing else to do. */
2713 if (num_debug_info_entries > 0)
2714 return num_debug_info_entries;
2716 /* If this is a DWARF package file, load the CU and TU indexes. */
2717 (void) load_cu_tu_indexes (file);
2719 if (load_debug_section (info, file)
2720 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2721 return num_debug_info_entries;
2723 if (load_debug_section (info_dwo, file)
2724 && process_debug_info (&debug_displays [info_dwo].section, file,
2726 return num_debug_info_entries;
2728 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2732 /* Read a DWARF .debug_line section header starting at DATA.
2733 Upon success returns an updated DATA pointer and the LINFO
2734 structure and the END_OF_SEQUENCE pointer will be filled in.
2735 Otherwise returns NULL. */
2737 static unsigned char *
2738 read_debug_line_header (struct dwarf_section * section,
2739 unsigned char * data,
2740 unsigned char * end,
2741 DWARF2_Internal_LineInfo * linfo,
2742 unsigned char ** end_of_sequence)
2744 unsigned char *hdrptr;
2745 unsigned int offset_size;
2746 unsigned int initial_length_size;
2748 /* Extract information from the Line Number Program Header.
2749 (section 6.2.4 in the Dwarf3 doc). */
2752 /* Get and check the length of the block. */
2753 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2755 if (linfo->li_length == 0xffffffff)
2757 /* This section is 64-bit DWARF 3. */
2758 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2760 initial_length_size = 12;
2765 initial_length_size = 4;
2768 if (linfo->li_length + initial_length_size > section->size)
2770 /* If the length field has a relocation against it, then we should
2771 not complain if it is inaccurate (and probably negative). This
2772 happens in object files when the .debug_line section is actually
2773 comprised of several different .debug_line.* sections, (some of
2774 which may be removed by linker garbage collection), and a relocation
2775 is used to compute the correct length once that is done. */
2776 if (reloc_at (section, (hdrptr - section->start) - offset_size))
2778 linfo->li_length = (end - data) - initial_length_size;
2782 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2783 (long) linfo->li_length);
2788 /* Get and check the version number. */
2789 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2791 if (linfo->li_version != 2
2792 && linfo->li_version != 3
2793 && linfo->li_version != 4)
2795 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2799 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2800 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2802 if (linfo->li_version >= 4)
2804 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2806 if (linfo->li_max_ops_per_insn == 0)
2808 warn (_("Invalid maximum operations per insn.\n"));
2813 linfo->li_max_ops_per_insn = 1;
2815 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2816 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2817 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2818 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2820 * end_of_sequence = data + linfo->li_length + initial_length_size;
2821 /* PR 17512: file:002-117414-0.004. */
2822 if (* end_of_sequence > end)
2824 warn (_("Line length %s extends beyond end of section\n"),
2825 dwarf_vmatoa ("u", linfo->li_length));
2826 * end_of_sequence = end;
2834 display_debug_lines_raw (struct dwarf_section *section,
2835 unsigned char *data,
2838 unsigned char *start = section->start;
2840 printf (_("Raw dump of debug contents of section %s:\n\n"),
2845 static DWARF2_Internal_LineInfo saved_linfo;
2846 DWARF2_Internal_LineInfo linfo;
2847 unsigned char *standard_opcodes;
2848 unsigned char *end_of_sequence;
2849 unsigned int last_dir_entry = 0;
2852 if (const_strneq (section->name, ".debug_line.")
2853 /* Note: the following does not apply to .debug_line.dwo sections.
2854 These are full debug_line sections. */
2855 && strcmp (section->name, ".debug_line.dwo") != 0)
2857 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2858 section containing just the Line Number Statements. They are
2859 created by the assembler and intended to be used alongside gcc's
2860 -ffunction-sections command line option. When the linker's
2861 garbage collection decides to discard a .text.<foo> section it
2862 can then also discard the line number information in .debug_line.<foo>.
2864 Since the section is a fragment it does not have the details
2865 needed to fill out a LineInfo structure, so instead we use the
2866 details from the last full debug_line section that we processed. */
2867 end_of_sequence = end;
2868 standard_opcodes = NULL;
2869 linfo = saved_linfo;
2870 /* PR 17531: file: 0522b371. */
2871 if (linfo.li_line_range == 0)
2873 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
2876 reset_state_machine (linfo.li_default_is_stmt);
2880 unsigned char * hdrptr;
2882 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2883 & end_of_sequence)) == NULL)
2886 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2887 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2888 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2889 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
2890 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2891 if (linfo.li_version >= 4)
2892 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2893 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2894 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2895 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2896 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2898 /* PR 17512: file: 1665-6428-0.004. */
2899 if (linfo.li_line_range == 0)
2901 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2902 linfo.li_line_range = 1;
2905 reset_state_machine (linfo.li_default_is_stmt);
2907 /* Display the contents of the Opcodes table. */
2908 standard_opcodes = hdrptr;
2910 /* PR 17512: file: 002-417945-0.004. */
2911 if (standard_opcodes + linfo.li_opcode_base >= end)
2913 warn (_("Line Base extends beyond end of section\n"));
2917 printf (_("\n Opcodes:\n"));
2919 for (i = 1; i < linfo.li_opcode_base; i++)
2920 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2922 /* Display the contents of the Directory table. */
2923 data = standard_opcodes + linfo.li_opcode_base - 1;
2926 printf (_("\n The Directory Table is empty.\n"));
2929 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2930 (long)(data - start));
2932 while (data < end && *data != 0)
2934 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
2936 data += strnlen ((char *) data, end - data) + 1;
2939 /* PR 17512: file: 002-132094-0.004. */
2940 if (data >= end - 1)
2944 /* Skip the NUL at the end of the table. */
2947 /* Display the contents of the File Name table. */
2949 printf (_("\n The File Name Table is empty.\n"));
2952 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2953 (long)(data - start));
2954 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2956 while (data < end && *data != 0)
2958 unsigned char *name;
2959 unsigned int bytes_read;
2961 printf (" %d\t", ++state_machine_regs.last_file_entry);
2963 data += strnlen ((char *) data, end - data) + 1;
2966 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2969 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2972 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2974 printf ("%.*s\n", (int)(end - name), name);
2978 warn (_("Corrupt file name table entry\n"));
2984 /* Skip the NUL at the end of the table. */
2987 saved_linfo = linfo;
2990 /* Now display the statements. */
2991 if (data >= end_of_sequence)
2992 printf (_(" No Line Number Statements.\n"));
2995 printf (_(" Line Number Statements:\n"));
2997 while (data < end_of_sequence)
2999 unsigned char op_code;
3000 dwarf_signed_vma adv;
3002 unsigned int bytes_read;
3004 printf (" [0x%08lx]", (long)(data - start));
3008 if (op_code >= linfo.li_opcode_base)
3010 op_code -= linfo.li_opcode_base;
3011 uladv = (op_code / linfo.li_line_range);
3012 if (linfo.li_max_ops_per_insn == 1)
3014 uladv *= linfo.li_min_insn_length;
3015 state_machine_regs.address += uladv;
3016 printf (_(" Special opcode %d: "
3017 "advance Address by %s to 0x%s"),
3018 op_code, dwarf_vmatoa ("u", uladv),
3019 dwarf_vmatoa ("x", state_machine_regs.address));
3023 state_machine_regs.address
3024 += ((state_machine_regs.op_index + uladv)
3025 / linfo.li_max_ops_per_insn)
3026 * linfo.li_min_insn_length;
3027 state_machine_regs.op_index
3028 = (state_machine_regs.op_index + uladv)
3029 % linfo.li_max_ops_per_insn;
3030 printf (_(" Special opcode %d: "
3031 "advance Address by %s to 0x%s[%d]"),
3032 op_code, dwarf_vmatoa ("u", uladv),
3033 dwarf_vmatoa ("x", state_machine_regs.address),
3034 state_machine_regs.op_index);
3036 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3037 state_machine_regs.line += adv;
3038 printf (_(" and Line by %s to %d\n"),
3039 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3041 else switch (op_code)
3043 case DW_LNS_extended_op:
3044 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3048 printf (_(" Copy\n"));
3051 case DW_LNS_advance_pc:
3052 uladv = read_uleb128 (data, & bytes_read, end);
3054 if (linfo.li_max_ops_per_insn == 1)
3056 uladv *= linfo.li_min_insn_length;
3057 state_machine_regs.address += uladv;
3058 printf (_(" Advance PC by %s to 0x%s\n"),
3059 dwarf_vmatoa ("u", uladv),
3060 dwarf_vmatoa ("x", state_machine_regs.address));
3064 state_machine_regs.address
3065 += ((state_machine_regs.op_index + uladv)
3066 / linfo.li_max_ops_per_insn)
3067 * linfo.li_min_insn_length;
3068 state_machine_regs.op_index
3069 = (state_machine_regs.op_index + uladv)
3070 % linfo.li_max_ops_per_insn;
3071 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3072 dwarf_vmatoa ("u", uladv),
3073 dwarf_vmatoa ("x", state_machine_regs.address),
3074 state_machine_regs.op_index);
3078 case DW_LNS_advance_line:
3079 adv = read_sleb128 (data, & bytes_read, end);
3081 state_machine_regs.line += adv;
3082 printf (_(" Advance Line by %s to %d\n"),
3083 dwarf_vmatoa ("d", adv),
3084 state_machine_regs.line);
3087 case DW_LNS_set_file:
3088 adv = read_uleb128 (data, & bytes_read, end);
3090 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3091 dwarf_vmatoa ("d", adv));
3092 state_machine_regs.file = adv;
3095 case DW_LNS_set_column:
3096 uladv = read_uleb128 (data, & bytes_read, end);
3098 printf (_(" Set column to %s\n"),
3099 dwarf_vmatoa ("u", uladv));
3100 state_machine_regs.column = uladv;
3103 case DW_LNS_negate_stmt:
3104 adv = state_machine_regs.is_stmt;
3106 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3107 state_machine_regs.is_stmt = adv;
3110 case DW_LNS_set_basic_block:
3111 printf (_(" Set basic block\n"));
3112 state_machine_regs.basic_block = 1;
3115 case DW_LNS_const_add_pc:
3116 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3117 if (linfo.li_max_ops_per_insn)
3119 uladv *= linfo.li_min_insn_length;
3120 state_machine_regs.address += uladv;
3121 printf (_(" Advance PC by constant %s to 0x%s\n"),
3122 dwarf_vmatoa ("u", uladv),
3123 dwarf_vmatoa ("x", state_machine_regs.address));
3127 state_machine_regs.address
3128 += ((state_machine_regs.op_index + uladv)
3129 / linfo.li_max_ops_per_insn)
3130 * linfo.li_min_insn_length;
3131 state_machine_regs.op_index
3132 = (state_machine_regs.op_index + uladv)
3133 % linfo.li_max_ops_per_insn;
3134 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3135 dwarf_vmatoa ("u", uladv),
3136 dwarf_vmatoa ("x", state_machine_regs.address),
3137 state_machine_regs.op_index);
3141 case DW_LNS_fixed_advance_pc:
3142 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3143 state_machine_regs.address += uladv;
3144 state_machine_regs.op_index = 0;
3145 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3146 dwarf_vmatoa ("u", uladv),
3147 dwarf_vmatoa ("x", state_machine_regs.address));
3150 case DW_LNS_set_prologue_end:
3151 printf (_(" Set prologue_end to true\n"));
3154 case DW_LNS_set_epilogue_begin:
3155 printf (_(" Set epilogue_begin to true\n"));
3158 case DW_LNS_set_isa:
3159 uladv = read_uleb128 (data, & bytes_read, end);
3161 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3165 printf (_(" Unknown opcode %d with operands: "), op_code);
3167 if (standard_opcodes != NULL)
3168 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3170 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3172 i == 1 ? "" : ", ");
3188 unsigned char *name;
3189 unsigned int directory_index;
3190 unsigned int modification_date;
3191 unsigned int length;
3194 /* Output a decoded representation of the .debug_line section. */
3197 display_debug_lines_decoded (struct dwarf_section *section,
3198 unsigned char *data,
3201 static DWARF2_Internal_LineInfo saved_linfo;
3203 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3208 /* This loop amounts to one iteration per compilation unit. */
3209 DWARF2_Internal_LineInfo linfo;
3210 unsigned char *standard_opcodes;
3211 unsigned char *end_of_sequence;
3213 File_Entry *file_table = NULL;
3214 unsigned int n_files = 0;
3215 unsigned char **directory_table = NULL;
3216 unsigned int n_directories = 0;
3218 if (const_strneq (section->name, ".debug_line.")
3219 /* Note: the following does not apply to .debug_line.dwo sections.
3220 These are full debug_line sections. */
3221 && strcmp (section->name, ".debug_line.dwo") != 0)
3223 /* See comment in display_debug_lines_raw(). */
3224 end_of_sequence = end;
3225 standard_opcodes = NULL;
3226 linfo = saved_linfo;
3227 /* PR 17531: file: 0522b371. */
3228 if (linfo.li_line_range == 0)
3230 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3233 reset_state_machine (linfo.li_default_is_stmt);
3237 unsigned char *hdrptr;
3239 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3240 & end_of_sequence)) == NULL)
3243 /* PR 17531: file: 0522b371. */
3244 if (linfo.li_line_range == 0)
3246 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3247 linfo.li_line_range = 1;
3249 reset_state_machine (linfo.li_default_is_stmt);
3251 /* Save a pointer to the contents of the Opcodes table. */
3252 standard_opcodes = hdrptr;
3254 /* Traverse the Directory table just to count entries. */
3255 data = standard_opcodes + linfo.li_opcode_base - 1;
3259 warn (_("opcode base of %d extends beyond end of section\n"),
3260 linfo.li_opcode_base);
3266 unsigned char *ptr_directory_table = data;
3268 while (data < end && *data != 0)
3270 data += strnlen ((char *) data, end - data) + 1;
3277 warn (_("directory table ends unexpectedly\n"));
3282 /* Go through the directory table again to save the directories. */
3283 directory_table = (unsigned char **)
3284 xmalloc (n_directories * sizeof (unsigned char *));
3287 while (*ptr_directory_table != 0)
3289 directory_table[i] = ptr_directory_table;
3290 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3291 ptr_directory_table - end) + 1;
3295 /* Skip the NUL at the end of the table. */
3298 /* Traverse the File Name table just to count the entries. */
3299 if (data < end && *data != 0)
3301 unsigned char *ptr_file_name_table = data;
3303 while (data < end && *data != 0)
3305 unsigned int bytes_read;
3307 /* Skip Name, directory index, last modification time and length
3309 data += strnlen ((char *) data, end - data) + 1;
3310 read_uleb128 (data, & bytes_read, end);
3312 read_uleb128 (data, & bytes_read, end);
3314 read_uleb128 (data, & bytes_read, end);
3322 warn (_("file table ends unexpectedly\n"));
3327 /* Go through the file table again to save the strings. */
3328 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3331 while (*ptr_file_name_table != 0)
3333 unsigned int bytes_read;
3335 file_table[i].name = ptr_file_name_table;
3336 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3337 end - ptr_file_name_table) + 1;
3339 /* We are not interested in directory, time or size. */
3340 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3342 ptr_file_name_table += bytes_read;
3343 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3345 ptr_file_name_table += bytes_read;
3346 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3347 ptr_file_name_table += bytes_read;
3352 /* Print the Compilation Unit's name and a header. */
3353 if (directory_table == NULL)
3355 printf (_("CU: %s:\n"), file_table[0].name);
3356 printf (_("File name Line number Starting address\n"));
3360 unsigned int ix = file_table[0].directory_index;
3361 const char *directory;
3366 else if (n_directories == 0)
3367 directory = _("<unknown>");
3368 else if (ix > n_directories)
3370 warn (_("directory index %u > number of directories %u\n"), ix, n_directories);
3371 directory = _("<corrupt>");
3374 directory = (char *) directory_table[ix - 1];
3376 if (do_wide || strlen (directory) < 76)
3377 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3379 printf ("%s:\n", file_table[0].name);
3381 printf (_("File name Line number Starting address\n"));
3385 /* Skip the NUL at the end of the table. */
3388 saved_linfo = linfo;
3391 /* This loop iterates through the Dwarf Line Number Program. */
3392 while (data < end_of_sequence)
3394 unsigned char op_code;
3396 unsigned long int uladv;
3397 unsigned int bytes_read;
3398 int is_special_opcode = 0;
3402 if (op_code >= linfo.li_opcode_base)
3404 op_code -= linfo.li_opcode_base;
3405 uladv = (op_code / linfo.li_line_range);
3406 if (linfo.li_max_ops_per_insn == 1)
3408 uladv *= linfo.li_min_insn_length;
3409 state_machine_regs.address += uladv;
3413 state_machine_regs.address
3414 += ((state_machine_regs.op_index + uladv)
3415 / linfo.li_max_ops_per_insn)
3416 * linfo.li_min_insn_length;
3417 state_machine_regs.op_index
3418 = (state_machine_regs.op_index + uladv)
3419 % linfo.li_max_ops_per_insn;
3422 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3423 state_machine_regs.line += adv;
3424 is_special_opcode = 1;
3426 else switch (op_code)
3428 case DW_LNS_extended_op:
3430 unsigned int ext_op_code_len;
3431 unsigned char ext_op_code;
3432 unsigned char *op_code_data = data;
3434 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3436 op_code_data += bytes_read;
3438 if (ext_op_code_len == 0)
3440 warn (_("Badly formed extended line op encountered!\n"));
3443 ext_op_code_len += bytes_read;
3444 ext_op_code = *op_code_data++;
3446 switch (ext_op_code)
3448 case DW_LNE_end_sequence:
3449 reset_state_machine (linfo.li_default_is_stmt);
3451 case DW_LNE_set_address:
3452 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3454 ext_op_code_len - bytes_read - 1,
3456 state_machine_regs.op_index = 0;
3458 case DW_LNE_define_file:
3460 file_table = (File_Entry *) xrealloc
3461 (file_table, (n_files + 1) * sizeof (File_Entry));
3463 ++state_machine_regs.last_file_entry;
3464 /* Source file name. */
3465 file_table[n_files].name = op_code_data;
3466 op_code_data += strlen ((char *) op_code_data) + 1;
3467 /* Directory index. */
3468 file_table[n_files].directory_index =
3469 read_uleb128 (op_code_data, & bytes_read,
3471 op_code_data += bytes_read;
3472 /* Last modification time. */
3473 file_table[n_files].modification_date =
3474 read_uleb128 (op_code_data, & bytes_read,
3476 op_code_data += bytes_read;
3478 file_table[n_files].length =
3479 read_uleb128 (op_code_data, & bytes_read,
3485 case DW_LNE_set_discriminator:
3486 case DW_LNE_HP_set_sequence:
3487 /* Simply ignored. */
3491 printf (_("UNKNOWN (%u): length %d\n"),
3492 ext_op_code, ext_op_code_len - bytes_read);
3495 data += ext_op_code_len;
3501 case DW_LNS_advance_pc:
3502 uladv = read_uleb128 (data, & bytes_read, end);
3504 if (linfo.li_max_ops_per_insn == 1)
3506 uladv *= linfo.li_min_insn_length;
3507 state_machine_regs.address += uladv;
3511 state_machine_regs.address
3512 += ((state_machine_regs.op_index + uladv)
3513 / linfo.li_max_ops_per_insn)
3514 * linfo.li_min_insn_length;
3515 state_machine_regs.op_index
3516 = (state_machine_regs.op_index + uladv)
3517 % linfo.li_max_ops_per_insn;
3521 case DW_LNS_advance_line:
3522 adv = read_sleb128 (data, & bytes_read, end);
3524 state_machine_regs.line += adv;
3527 case DW_LNS_set_file:
3528 adv = read_uleb128 (data, & bytes_read, end);
3530 state_machine_regs.file = adv;
3533 unsigned file = state_machine_regs.file - 1;
3536 if (file_table == NULL || n_files == 0)
3537 printf (_("\n [Use file table entry %d]\n"), file);
3539 else if (file >= n_files)
3541 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
3542 printf (_("\n <over large file table index %u>"), file);
3544 else if ((dir = file_table[file].directory_index) == 0)
3545 /* If directory index is 0, that means current directory. */
3546 printf ("\n./%s:[++]\n", file_table[file].name);
3547 else if (directory_table == NULL || n_directories == 0)
3548 printf (_("\n [Use file %s in directory table entry %d]\n"),
3549 file_table[file].name, dir);
3551 else if (dir > n_directories)
3553 warn (_("directory index %u > number of directories %u\n"), dir, n_directories);
3554 printf (_("\n <over large directory table entry %u>\n"), dir);
3557 printf ("\n%s/%s:\n",
3558 /* The directory index starts counting at 1. */
3559 directory_table[dir - 1], file_table[file].name);
3563 case DW_LNS_set_column:
3564 uladv = read_uleb128 (data, & bytes_read, end);
3566 state_machine_regs.column = uladv;
3569 case DW_LNS_negate_stmt:
3570 adv = state_machine_regs.is_stmt;
3572 state_machine_regs.is_stmt = adv;
3575 case DW_LNS_set_basic_block:
3576 state_machine_regs.basic_block = 1;
3579 case DW_LNS_const_add_pc:
3580 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3581 if (linfo.li_max_ops_per_insn == 1)
3583 uladv *= linfo.li_min_insn_length;
3584 state_machine_regs.address += uladv;
3588 state_machine_regs.address
3589 += ((state_machine_regs.op_index + uladv)
3590 / linfo.li_max_ops_per_insn)
3591 * linfo.li_min_insn_length;
3592 state_machine_regs.op_index
3593 = (state_machine_regs.op_index + uladv)
3594 % linfo.li_max_ops_per_insn;
3598 case DW_LNS_fixed_advance_pc:
3599 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3600 state_machine_regs.address += uladv;
3601 state_machine_regs.op_index = 0;
3604 case DW_LNS_set_prologue_end:
3607 case DW_LNS_set_epilogue_begin:
3610 case DW_LNS_set_isa:
3611 uladv = read_uleb128 (data, & bytes_read, end);
3613 printf (_(" Set ISA to %lu\n"), uladv);
3617 printf (_(" Unknown opcode %d with operands: "), op_code);
3619 if (standard_opcodes != NULL)
3620 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3622 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3624 i == 1 ? "" : ", ");
3631 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3632 to the DWARF address/line matrix. */
3633 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3634 || (op_code == DW_LNS_copy))
3636 const unsigned int MAX_FILENAME_LENGTH = 35;
3638 char *newFileName = NULL;
3639 size_t fileNameLength;
3643 unsigned indx = state_machine_regs.file - 1;
3645 if (indx >= n_files)
3647 warn (_("corrupt file index %u encountered\n"), indx);
3648 fileName = _("<corrupt>");
3651 fileName = (char *) file_table[indx].name;
3654 fileName = _("<unknown>");
3656 fileNameLength = strlen (fileName);
3658 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3660 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3661 /* Truncate file name */
3662 strncpy (newFileName,
3663 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3664 MAX_FILENAME_LENGTH + 1);
3668 newFileName = (char *) xmalloc (fileNameLength + 1);
3669 strncpy (newFileName, fileName, fileNameLength + 1);
3672 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3674 if (linfo.li_max_ops_per_insn == 1)
3675 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3676 newFileName, state_machine_regs.line,
3677 state_machine_regs.address);
3679 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3680 newFileName, state_machine_regs.line,
3681 state_machine_regs.address,
3682 state_machine_regs.op_index);
3686 if (linfo.li_max_ops_per_insn == 1)
3687 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3688 newFileName, state_machine_regs.line,
3689 state_machine_regs.address);
3691 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3692 newFileName, state_machine_regs.line,
3693 state_machine_regs.address,
3694 state_machine_regs.op_index);
3697 if (op_code == DW_LNE_end_sequence)
3711 if (directory_table)
3713 free (directory_table);
3714 directory_table = NULL;
3725 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3727 unsigned char *data = section->start;
3728 unsigned char *end = data + section->size;
3730 int retValDecoded = 1;
3732 if (do_debug_lines == 0)
3733 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3735 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3736 retValRaw = display_debug_lines_raw (section, data, end);
3738 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3739 retValDecoded = display_debug_lines_decoded (section, data, end);
3741 if (!retValRaw || !retValDecoded)
3748 find_debug_info_for_offset (unsigned long offset)
3752 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3755 for (i = 0; i < num_debug_info_entries; i++)
3756 if (debug_information[i].cu_offset == offset)
3757 return debug_information + i;
3763 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3765 /* See gdb/gdb-index.h. */
3766 static const char * const kinds[] =
3778 return _ (kinds[kind]);
3782 display_debug_pubnames_worker (struct dwarf_section *section,
3783 void *file ATTRIBUTE_UNUSED,
3786 DWARF2_Internal_PubNames names;
3787 unsigned char *start = section->start;
3788 unsigned char *end = start + section->size;
3790 /* It does not matter if this load fails,
3791 we test for that later on. */
3792 load_debug_info (file);
3794 printf (_("Contents of the %s section:\n\n"), section->name);
3798 unsigned char *data;
3801 unsigned int offset_size, initial_length_size;
3805 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3806 if (names.pn_length == 0xffffffff)
3808 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3810 initial_length_size = 12;
3815 initial_length_size = 4;
3818 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3819 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3821 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3822 && num_debug_info_entries > 0
3823 && find_debug_info_for_offset (names.pn_offset) == NULL)
3824 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3825 (unsigned long) names.pn_offset, section->name);
3827 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3829 adr = start + names.pn_length + initial_length_size;
3830 /* PR 17531: file: 7615b6b2. */
3831 if ((dwarf_signed_vma) names.pn_length < 0
3832 /* PR 17531: file: a5dbeaa7. */
3835 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
3841 printf (_(" Length: %ld\n"),
3842 (long) names.pn_length);
3843 printf (_(" Version: %d\n"),
3845 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3846 (unsigned long) names.pn_offset);
3847 printf (_(" Size of area in .debug_info section: %ld\n"),
3848 (long) names.pn_size);
3850 if (names.pn_version != 2 && names.pn_version != 3)
3852 static int warned = 0;
3856 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3864 printf (_("\n Offset Kind Name\n"));
3866 printf (_("\n Offset\tName\n"));
3870 bfd_size_type maxprint;
3872 SAFE_BYTE_GET (offset, data, offset_size, end);
3876 data += offset_size;
3879 maxprint = (end - data) - 1;
3883 unsigned int kind_data;
3884 gdb_index_symbol_kind kind;
3885 const char *kind_name;
3888 SAFE_BYTE_GET (kind_data, data, 1, end);
3891 /* GCC computes the kind as the upper byte in the CU index
3892 word, and then right shifts it by the CU index size.
3893 Left shift KIND to where the gdb-index.h accessor macros
3895 kind_data <<= GDB_INDEX_CU_BITSIZE;
3896 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3897 kind_name = get_gdb_index_symbol_kind_name (kind);
3898 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3899 printf (" %-6lx %s,%-10s %.*s\n",
3900 (unsigned long) offset, is_static ? _("s") : _("g"),
3901 kind_name, (int) maxprint, data);
3904 printf (" %-6lx\t%.*s\n",
3905 (unsigned long) offset, (int) maxprint, data);
3907 data += strnlen ((char *) data, maxprint) + 1;
3912 while (offset != 0);
3920 display_debug_pubnames (struct dwarf_section *section, void *file)
3922 return display_debug_pubnames_worker (section, file, 0);
3926 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3928 return display_debug_pubnames_worker (section, file, 1);
3932 display_debug_macinfo (struct dwarf_section *section,
3933 void *file ATTRIBUTE_UNUSED)
3935 unsigned char *start = section->start;
3936 unsigned char *end = start + section->size;
3937 unsigned char *curr = start;
3938 unsigned int bytes_read;
3939 enum dwarf_macinfo_record_type op;
3941 printf (_("Contents of the %s section:\n\n"), section->name);
3945 unsigned int lineno;
3946 const unsigned char *string;
3948 op = (enum dwarf_macinfo_record_type) *curr;
3953 case DW_MACINFO_start_file:
3955 unsigned int filenum;
3957 lineno = read_uleb128 (curr, & bytes_read, end);
3959 filenum = read_uleb128 (curr, & bytes_read, end);
3962 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3967 case DW_MACINFO_end_file:
3968 printf (_(" DW_MACINFO_end_file\n"));
3971 case DW_MACINFO_define:
3972 lineno = read_uleb128 (curr, & bytes_read, end);
3975 curr += strnlen ((char *) string, end - string) + 1;
3976 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3980 case DW_MACINFO_undef:
3981 lineno = read_uleb128 (curr, & bytes_read, end);
3984 curr += strnlen ((char *) string, end - string) + 1;
3985 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3989 case DW_MACINFO_vendor_ext:
3991 unsigned int constant;
3993 constant = read_uleb128 (curr, & bytes_read, end);
3996 curr += strnlen ((char *) string, end - string) + 1;
3997 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4007 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4008 filename and dirname corresponding to file name table entry with index
4009 FILEIDX. Return NULL on failure. */
4011 static unsigned char *
4012 get_line_filename_and_dirname (dwarf_vma line_offset,
4014 unsigned char **dir_name)
4016 struct dwarf_section *section = &debug_displays [line].section;
4017 unsigned char *hdrptr, *dirtable, *file_name;
4018 unsigned int offset_size, initial_length_size;
4019 unsigned int version, opcode_base, bytes_read;
4020 dwarf_vma length, diridx;
4021 const unsigned char * end;
4024 if (section->start == NULL
4025 || line_offset >= section->size
4029 hdrptr = section->start + line_offset;
4030 end = section->start + section->size;
4032 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4033 if (length == 0xffffffff)
4035 /* This section is 64-bit DWARF 3. */
4036 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4038 initial_length_size = 12;
4043 initial_length_size = 4;
4045 if (length + initial_length_size > section->size)
4048 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4049 if (version != 2 && version != 3 && version != 4)
4051 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4053 hdrptr++; /* Skip max_ops_per_insn. */
4054 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4056 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4057 if (opcode_base == 0)
4060 hdrptr += opcode_base - 1;
4062 /* Skip over dirname table. */
4063 while (*hdrptr != '\0')
4064 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4065 hdrptr++; /* Skip the NUL at the end of the table. */
4066 /* Now skip over preceding filename table entries. */
4067 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4069 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4070 read_uleb128 (hdrptr, &bytes_read, end);
4071 hdrptr += bytes_read;
4072 read_uleb128 (hdrptr, &bytes_read, end);
4073 hdrptr += bytes_read;
4074 read_uleb128 (hdrptr, &bytes_read, end);
4075 hdrptr += bytes_read;
4077 if (hdrptr == end || *hdrptr == '\0')
4080 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4081 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4084 for (; *dirtable != '\0' && diridx > 1; diridx--)
4085 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4086 if (*dirtable == '\0')
4088 *dir_name = dirtable;
4093 display_debug_macro (struct dwarf_section *section,
4096 unsigned char *start = section->start;
4097 unsigned char *end = start + section->size;
4098 unsigned char *curr = start;
4099 unsigned char *extended_op_buf[256];
4100 unsigned int bytes_read;
4102 load_debug_section (str, file);
4103 load_debug_section (line, file);
4105 printf (_("Contents of the %s section:\n\n"), section->name);
4109 unsigned int lineno, version, flags;
4110 unsigned int offset_size = 4;
4111 const unsigned char *string;
4112 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4113 unsigned char **extended_ops = NULL;
4115 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4118 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4123 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4126 printf (_(" Offset: 0x%lx\n"),
4127 (unsigned long) sec_offset);
4128 printf (_(" Version: %d\n"), version);
4129 printf (_(" Offset size: %d\n"), offset_size);
4132 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4133 printf (_(" Offset into .debug_line: 0x%lx\n"),
4134 (unsigned long) line_offset);
4138 unsigned int i, count, op;
4141 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4143 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4144 extended_ops = extended_op_buf;
4147 printf (_(" Extension opcode arguments:\n"));
4148 for (i = 0; i < count; i++)
4150 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4151 extended_ops[op] = curr;
4152 nargs = read_uleb128 (curr, &bytes_read, end);
4155 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
4158 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
4159 for (n = 0; n < nargs; n++)
4163 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4164 printf ("%s%s", get_FORM_name (form),
4165 n == nargs - 1 ? "\n" : ", ");
4175 case DW_FORM_block1:
4176 case DW_FORM_block2:
4177 case DW_FORM_block4:
4179 case DW_FORM_string:
4181 case DW_FORM_sec_offset:
4184 error (_("Invalid extension opcode form %s\n"),
4185 get_FORM_name (form));
4201 error (_(".debug_macro section not zero terminated\n"));
4205 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4211 case DW_MACRO_GNU_start_file:
4213 unsigned int filenum;
4214 unsigned char *file_name = NULL, *dir_name = NULL;
4216 lineno = read_uleb128 (curr, &bytes_read, end);
4218 filenum = read_uleb128 (curr, &bytes_read, end);
4221 if ((flags & 2) == 0)
4222 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4225 = get_line_filename_and_dirname (line_offset, filenum,
4227 if (file_name == NULL)
4228 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4231 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4233 dir_name != NULL ? (const char *) dir_name : "",
4234 dir_name != NULL ? "/" : "", file_name);
4238 case DW_MACRO_GNU_end_file:
4239 printf (_(" DW_MACRO_GNU_end_file\n"));
4242 case DW_MACRO_GNU_define:
4243 lineno = read_uleb128 (curr, &bytes_read, end);
4246 curr += strnlen ((char *) string, end - string) + 1;
4247 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4251 case DW_MACRO_GNU_undef:
4252 lineno = read_uleb128 (curr, &bytes_read, end);
4255 curr += strnlen ((char *) string, end - string) + 1;
4256 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4260 case DW_MACRO_GNU_define_indirect:
4261 lineno = read_uleb128 (curr, &bytes_read, end);
4263 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4264 string = fetch_indirect_string (offset);
4265 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4269 case DW_MACRO_GNU_undef_indirect:
4270 lineno = read_uleb128 (curr, &bytes_read, end);
4272 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4273 string = fetch_indirect_string (offset);
4274 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4278 case DW_MACRO_GNU_transparent_include:
4279 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4280 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4281 (unsigned long) offset);
4284 case DW_MACRO_GNU_define_indirect_alt:
4285 lineno = read_uleb128 (curr, &bytes_read, end);
4287 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4288 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4289 lineno, (unsigned long) offset);
4292 case DW_MACRO_GNU_undef_indirect_alt:
4293 lineno = read_uleb128 (curr, &bytes_read, end);
4295 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4296 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4297 lineno, (unsigned long) offset);
4300 case DW_MACRO_GNU_transparent_include_alt:
4301 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4302 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4303 (unsigned long) offset);
4307 if (extended_ops == NULL || extended_ops[op] == NULL)
4309 error (_(" Unknown macro opcode %02x seen\n"), op);
4314 /* Skip over unhandled opcodes. */
4316 unsigned char *desc = extended_ops[op];
4317 nargs = read_uleb128 (desc, &bytes_read, end);
4321 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4324 printf (_(" DW_MACRO_GNU_%02x -"), op);
4325 for (n = 0; n < nargs; n++)
4329 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4331 = read_and_display_attr_value (0, val,
4332 curr, end, 0, 0, offset_size,
4333 version, NULL, 0, NULL,
4351 display_debug_abbrev (struct dwarf_section *section,
4352 void *file ATTRIBUTE_UNUSED)
4354 abbrev_entry *entry;
4355 unsigned char *start = section->start;
4356 unsigned char *end = start + section->size;
4358 printf (_("Contents of the %s section:\n\n"), section->name);
4362 unsigned char *last;
4367 start = process_abbrev_section (start, end);
4369 if (first_abbrev == NULL)
4372 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4374 for (entry = first_abbrev; entry; entry = entry->next)
4378 printf (" %ld %s [%s]\n",
4380 get_TAG_name (entry->tag),
4381 entry->children ? _("has children") : _("no children"));
4383 for (attr = entry->first_attr; attr; attr = attr->next)
4384 printf (" %-18s %s\n",
4385 get_AT_name (attr->attribute),
4386 get_FORM_name (attr->form));
4396 /* Return true when ADDR is the maximum address, when addresses are
4397 POINTER_SIZE bytes long. */
4400 is_max_address (dwarf_vma addr, unsigned int pointer_size)
4402 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
4403 return ((addr & mask) == mask);
4406 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4409 display_loc_list (struct dwarf_section *section,
4410 unsigned char **start_ptr,
4411 unsigned int debug_info_entry,
4412 unsigned long offset,
4413 unsigned long base_address,
4416 unsigned char *start = *start_ptr;
4417 unsigned char *section_end = section->start + section->size;
4418 unsigned long cu_offset;
4419 unsigned int pointer_size;
4420 unsigned int offset_size;
4425 unsigned short length;
4426 int need_frame_base;
4428 if (debug_info_entry >= num_debug_info_entries)
4430 warn (_("No debug information available for loc lists of entry: %u\n"),
4435 cu_offset = debug_information [debug_info_entry].cu_offset;
4436 pointer_size = debug_information [debug_info_entry].pointer_size;
4437 offset_size = debug_information [debug_info_entry].offset_size;
4438 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4440 if (pointer_size < 2 || pointer_size > 8)
4442 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4443 pointer_size, debug_info_entry);
4449 unsigned long off = offset + (start - *start_ptr);
4451 if (start + 2 * pointer_size > section_end)
4453 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4458 printf (" %8.8lx ", off);
4460 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4461 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4463 if (begin == 0 && end == 0)
4465 /* PR 18374: In a object file we can have a location list that
4466 starts with a begin and end of 0 because there are relocations
4467 that need to be applied to the addresses. Actually applying
4468 the relocations now does not help as they will probably resolve
4469 to 0, since the object file has not been fully linked. Real
4470 end of list markers will not have any relocations against them. */
4471 if (! reloc_at (section, off)
4472 && ! reloc_at (section, off + pointer_size))
4474 printf (_("<End of list>\n"));
4479 /* Check base address specifiers. */
4480 if (is_max_address (begin, pointer_size)
4481 && !is_max_address (end, pointer_size))
4484 print_dwarf_vma (begin, pointer_size);
4485 print_dwarf_vma (end, pointer_size);
4486 printf (_("(base address)\n"));
4490 if (start + 2 > section_end)
4492 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4497 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4499 if (start + length > section_end)
4501 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4506 print_dwarf_vma (begin + base_address, pointer_size);
4507 print_dwarf_vma (end + base_address, pointer_size);
4510 need_frame_base = decode_location_expression (start,
4515 cu_offset, section);
4518 if (need_frame_base && !has_frame_base)
4519 printf (_(" [without DW_AT_frame_base]"));
4522 fputs (_(" (start == end)"), stdout);
4523 else if (begin > end)
4524 fputs (_(" (start > end)"), stdout);
4534 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4535 right-adjusted in a field of length LEN, and followed by a space. */
4538 print_addr_index (unsigned int idx, unsigned int len)
4540 static char buf[15];
4541 snprintf (buf, sizeof (buf), "[%d]", idx);
4542 printf ("%*s ", len, buf);
4545 /* Display a location list from a .dwo section. It uses address indexes rather
4546 than embedded addresses. This code closely follows display_loc_list, but the
4547 two are sufficiently different that combining things is very ugly. */
4550 display_loc_list_dwo (struct dwarf_section *section,
4551 unsigned char **start_ptr,
4552 unsigned int debug_info_entry,
4553 unsigned long offset,
4556 unsigned char *start = *start_ptr;
4557 unsigned char *section_end = section->start + section->size;
4558 unsigned long cu_offset;
4559 unsigned int pointer_size;
4560 unsigned int offset_size;
4563 unsigned short length;
4564 int need_frame_base;
4566 unsigned int bytes_read;
4568 if (debug_info_entry >= num_debug_info_entries)
4570 warn (_("No debug information for loc lists of entry: %u\n"),
4575 cu_offset = debug_information [debug_info_entry].cu_offset;
4576 pointer_size = debug_information [debug_info_entry].pointer_size;
4577 offset_size = debug_information [debug_info_entry].offset_size;
4578 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4580 if (pointer_size < 2 || pointer_size > 8)
4582 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4583 pointer_size, debug_info_entry);
4589 printf (" %8.8lx ", offset + (start - *start_ptr));
4591 if (start >= section_end)
4593 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4598 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4601 case 0: /* A terminating entry. */
4603 printf (_("<End of list>\n"));
4605 case 1: /* A base-address entry. */
4606 idx = read_uleb128 (start, &bytes_read, section_end);
4607 start += bytes_read;
4608 print_addr_index (idx, 8);
4610 printf (_("(base address selection entry)\n"));
4612 case 2: /* A start/end entry. */
4613 idx = read_uleb128 (start, &bytes_read, section_end);
4614 start += bytes_read;
4615 print_addr_index (idx, 8);
4616 idx = read_uleb128 (start, &bytes_read, section_end);
4617 start += bytes_read;
4618 print_addr_index (idx, 8);
4620 case 3: /* A start/length entry. */
4621 idx = read_uleb128 (start, &bytes_read, section_end);
4622 start += bytes_read;
4623 print_addr_index (idx, 8);
4624 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4625 printf ("%08x ", idx);
4627 case 4: /* An offset pair entry. */
4628 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4629 printf ("%08x ", idx);
4630 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4631 printf ("%08x ", idx);
4634 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4639 if (start + 2 > section_end)
4641 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4646 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4647 if (start + length > section_end)
4649 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4655 need_frame_base = decode_location_expression (start,
4660 cu_offset, section);
4663 if (need_frame_base && !has_frame_base)
4664 printf (_(" [without DW_AT_frame_base]"));
4674 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4676 static dwarf_vma *loc_offsets;
4679 loc_offsets_compar (const void *ap, const void *bp)
4681 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4682 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4684 return (a > b) - (b > a);
4688 display_debug_loc (struct dwarf_section *section, void *file)
4690 unsigned char *start = section->start;
4691 unsigned long bytes;
4692 unsigned char *section_begin = start;
4693 unsigned int num_loc_list = 0;
4694 unsigned long last_offset = 0;
4695 unsigned int first = 0;
4698 int seen_first_offset = 0;
4699 int locs_sorted = 1;
4700 unsigned char *next;
4701 unsigned int *array = NULL;
4702 const char *suffix = strrchr (section->name, '.');
4705 if (suffix && strcmp (suffix, ".dwo") == 0)
4708 bytes = section->size;
4712 printf (_("\nThe %s section is empty.\n"), section->name);
4716 if (load_debug_info (file) == 0)
4718 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4723 /* Check the order of location list in .debug_info section. If
4724 offsets of location lists are in the ascending order, we can
4725 use `debug_information' directly. */
4726 for (i = 0; i < num_debug_info_entries; i++)
4730 num = debug_information [i].num_loc_offsets;
4731 if (num > num_loc_list)
4734 /* Check if we can use `debug_information' directly. */
4735 if (locs_sorted && num != 0)
4737 if (!seen_first_offset)
4739 /* This is the first location list. */
4740 last_offset = debug_information [i].loc_offsets [0];
4742 seen_first_offset = 1;
4748 for (; j < num; j++)
4751 debug_information [i].loc_offsets [j])
4756 last_offset = debug_information [i].loc_offsets [j];
4761 if (!seen_first_offset)
4762 error (_("No location lists in .debug_info section!\n"));
4764 if (debug_information [first].num_loc_offsets > 0
4765 && debug_information [first].loc_offsets [0] != 0)
4766 warn (_("Location lists in %s section start at 0x%s\n"),
4768 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4771 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4772 printf (_("Contents of the %s section:\n\n"), section->name);
4773 if (reloc_at (section, 0))
4774 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
4775 printf (_(" Offset Begin End Expression\n"));
4777 seen_first_offset = 0;
4778 for (i = first; i < num_debug_info_entries; i++)
4780 unsigned long offset;
4781 unsigned long base_address;
4787 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4789 loc_offsets = debug_information [i].loc_offsets;
4790 qsort (array, debug_information [i].num_loc_offsets,
4791 sizeof (*array), loc_offsets_compar);
4794 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4796 j = locs_sorted ? k : array[k];
4798 && debug_information [i].loc_offsets [locs_sorted
4799 ? k - 1 : array [k - 1]]
4800 == debug_information [i].loc_offsets [j])
4802 has_frame_base = debug_information [i].have_frame_base [j];
4803 offset = debug_information [i].loc_offsets [j];
4804 next = section_begin + offset;
4805 base_address = debug_information [i].base_address;
4807 if (!seen_first_offset)
4808 seen_first_offset = 1;
4812 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4813 (unsigned long) (start - section_begin),
4814 (unsigned long) offset);
4815 else if (start > next)
4816 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4817 (unsigned long) (start - section_begin),
4818 (unsigned long) offset);
4822 if (offset >= bytes)
4824 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4830 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4832 display_loc_list (section, &start, i, offset, base_address,
4837 if (start < section->start + section->size)
4838 warn (_("There are %ld unused bytes at the end of section %s\n"),
4839 (long) (section->start + section->size - start), section->name);
4846 display_debug_str (struct dwarf_section *section,
4847 void *file ATTRIBUTE_UNUSED)
4849 unsigned char *start = section->start;
4850 unsigned long bytes = section->size;
4851 dwarf_vma addr = section->address;
4855 printf (_("\nThe %s section is empty.\n"), section->name);
4859 printf (_("Contents of the %s section:\n\n"), section->name);
4867 lbytes = (bytes > 16 ? 16 : bytes);
4869 printf (" 0x%8.8lx ", (unsigned long) addr);
4871 for (j = 0; j < 16; j++)
4874 printf ("%2.2x", start[j]);
4882 for (j = 0; j < lbytes; j++)
4885 if (k >= ' ' && k < 0x80)
4904 display_debug_info (struct dwarf_section *section, void *file)
4906 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4910 display_debug_types (struct dwarf_section *section, void *file)
4912 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4916 display_trace_info (struct dwarf_section *section, void *file)
4918 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4922 display_debug_aranges (struct dwarf_section *section,
4923 void *file ATTRIBUTE_UNUSED)
4925 unsigned char *start = section->start;
4926 unsigned char *end = start + section->size;
4928 printf (_("Contents of the %s section:\n\n"), section->name);
4930 /* It does not matter if this load fails,
4931 we test for that later on. */
4932 load_debug_info (file);
4936 unsigned char *hdrptr;
4937 DWARF2_Internal_ARange arange;
4938 unsigned char *addr_ranges;
4941 unsigned char address_size;
4943 unsigned int offset_size;
4944 unsigned int initial_length_size;
4948 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4949 if (arange.ar_length == 0xffffffff)
4951 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4953 initial_length_size = 12;
4958 initial_length_size = 4;
4961 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4962 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4964 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4965 && num_debug_info_entries > 0
4966 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4967 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4968 (unsigned long) arange.ar_info_offset, section->name);
4970 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4971 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4973 if (arange.ar_version != 2 && arange.ar_version != 3)
4975 /* PR 19872: A version number of 0 probably means that there is
4976 padding at the end of the .debug_aranges section. Gold puts
4977 it there when performing an incremental link, for example.
4978 So do not generate a warning in this case. */
4979 if (arange.ar_version)
4980 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4984 printf (_(" Length: %ld\n"),
4985 (long) arange.ar_length);
4986 printf (_(" Version: %d\n"), arange.ar_version);
4987 printf (_(" Offset into .debug_info: 0x%lx\n"),
4988 (unsigned long) arange.ar_info_offset);
4989 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4990 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4992 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4994 /* PR 17512: file: 001-108546-0.001:0.1. */
4995 if (address_size == 0 || address_size > 8)
4997 error (_("Invalid address size in %s section!\n"),
5002 /* The DWARF spec does not require that the address size be a power
5003 of two, but we do. This will have to change if we ever encounter
5004 an uneven architecture. */
5005 if ((address_size & (address_size - 1)) != 0)
5007 warn (_("Pointer size + Segment size is not a power of two.\n"));
5011 if (address_size > 4)
5012 printf (_("\n Address Length\n"));
5014 printf (_("\n Address Length\n"));
5016 addr_ranges = hdrptr;
5018 /* Must pad to an alignment boundary that is twice the address size. */
5019 excess = (hdrptr - start) % (2 * address_size);
5021 addr_ranges += (2 * address_size) - excess;
5023 hdrptr = start + arange.ar_length + initial_length_size;
5024 if (hdrptr < start || hdrptr > end)
5026 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
5031 while (addr_ranges + 2 * address_size <= start)
5033 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
5034 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
5037 print_dwarf_vma (address, address_size);
5038 print_dwarf_vma (length, address_size);
5048 /* Comparison function for qsort. */
5050 comp_addr_base (const void * v0, const void * v1)
5052 debug_info * info0 = (debug_info *) v0;
5053 debug_info * info1 = (debug_info *) v1;
5054 return info0->addr_base - info1->addr_base;
5057 /* Display the debug_addr section. */
5059 display_debug_addr (struct dwarf_section *section,
5062 debug_info **debug_addr_info;
5063 unsigned char *entry;
5068 if (section->size == 0)
5070 printf (_("\nThe %s section is empty.\n"), section->name);
5074 if (load_debug_info (file) == 0)
5076 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5081 printf (_("Contents of the %s section:\n\n"), section->name);
5083 /* PR 17531: file: cf38d01b.
5084 We use xcalloc because a corrupt file may not have initialised all of the
5085 fields in the debug_info structure, which means that the sort below might
5086 try to move uninitialised data. */
5087 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
5088 sizeof (debug_info *));
5091 for (i = 0; i < num_debug_info_entries; i++)
5092 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
5094 /* PR 17531: file: cf38d01b. */
5095 if (debug_information[i].addr_base >= section->size)
5096 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5097 (unsigned long) debug_information[i].addr_base, i);
5099 debug_addr_info [count++] = debug_information + i;
5102 /* Add a sentinel to make iteration convenient. */
5103 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
5104 debug_addr_info [count]->addr_base = section->size;
5105 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
5107 for (i = 0; i < count; i++)
5110 unsigned int address_size = debug_addr_info [i]->pointer_size;
5112 printf (_(" For compilation unit at offset 0x%s:\n"),
5113 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5115 printf (_("\tIndex\tAddress\n"));
5116 entry = section->start + debug_addr_info [i]->addr_base;
5117 end = section->start + debug_addr_info [i + 1]->addr_base;
5121 dwarf_vma base = byte_get (entry, address_size);
5122 printf (_("\t%d:\t"), idx);
5123 print_dwarf_vma (base, address_size);
5125 entry += address_size;
5131 free (debug_addr_info);
5135 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5137 display_debug_str_offsets (struct dwarf_section *section,
5138 void *file ATTRIBUTE_UNUSED)
5140 if (section->size == 0)
5142 printf (_("\nThe %s section is empty.\n"), section->name);
5145 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5146 what the offset size is for this section. */
5150 /* Each debug_information[x].range_lists[y] gets this representation for
5151 sorting purposes. */
5155 /* The debug_information[x].range_lists[y] value. */
5156 unsigned long ranges_offset;
5158 /* Original debug_information to find parameters of the data. */
5159 debug_info *debug_info_p;
5162 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5165 range_entry_compar (const void *ap, const void *bp)
5167 const struct range_entry *a_re = (const struct range_entry *) ap;
5168 const struct range_entry *b_re = (const struct range_entry *) bp;
5169 const unsigned long a = a_re->ranges_offset;
5170 const unsigned long b = b_re->ranges_offset;
5172 return (a > b) - (b > a);
5176 display_debug_ranges (struct dwarf_section *section,
5177 void *file ATTRIBUTE_UNUSED)
5179 unsigned char *start = section->start;
5180 unsigned char *last_start = start;
5181 unsigned long bytes = section->size;
5182 unsigned char *section_begin = start;
5183 unsigned char *finish = start + bytes;
5184 unsigned int num_range_list, i;
5185 struct range_entry *range_entries, *range_entry_fill;
5189 printf (_("\nThe %s section is empty.\n"), section->name);
5193 if (load_debug_info (file) == 0)
5195 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5201 for (i = 0; i < num_debug_info_entries; i++)
5202 num_range_list += debug_information [i].num_range_lists;
5204 if (num_range_list == 0)
5206 /* This can happen when the file was compiled with -gsplit-debug
5207 which removes references to range lists from the primary .o file. */
5208 printf (_("No range lists in .debug_info section.\n"));
5212 range_entries = (struct range_entry *)
5213 xmalloc (sizeof (*range_entries) * num_range_list);
5214 range_entry_fill = range_entries;
5216 for (i = 0; i < num_debug_info_entries; i++)
5218 debug_info *debug_info_p = &debug_information[i];
5221 for (j = 0; j < debug_info_p->num_range_lists; j++)
5223 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
5224 range_entry_fill->debug_info_p = debug_info_p;
5229 qsort (range_entries, num_range_list, sizeof (*range_entries),
5230 range_entry_compar);
5232 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
5233 warn (_("Range lists in %s section start at 0x%lx\n"),
5234 section->name, range_entries[0].ranges_offset);
5236 printf (_("Contents of the %s section:\n\n"), section->name);
5237 printf (_(" Offset Begin End\n"));
5239 for (i = 0; i < num_range_list; i++)
5241 struct range_entry *range_entry = &range_entries[i];
5242 debug_info *debug_info_p = range_entry->debug_info_p;
5243 unsigned int pointer_size;
5244 unsigned long offset;
5245 unsigned char *next;
5246 unsigned long base_address;
5248 pointer_size = debug_info_p->pointer_size;
5249 offset = range_entry->ranges_offset;
5250 next = section_begin + offset;
5251 base_address = debug_info_p->base_address;
5253 /* PR 17512: file: 001-101485-0.001:0.1. */
5254 if (pointer_size < 2 || pointer_size > 8)
5256 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5257 pointer_size, offset);
5261 if (dwarf_check != 0 && i > 0)
5264 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5265 (unsigned long) (start - section_begin),
5266 (unsigned long) (next - section_begin), section->name);
5267 else if (start > next)
5269 if (next == last_start)
5271 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5272 (unsigned long) (start - section_begin),
5273 (unsigned long) (next - section_begin), section->name);
5279 while (start < finish)
5284 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5285 if (start >= finish)
5287 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5289 printf (" %8.8lx ", offset);
5291 if (begin == 0 && end == 0)
5293 printf (_("<End of list>\n"));
5297 /* Check base address specifiers. */
5298 if (is_max_address (begin, pointer_size)
5299 && !is_max_address (end, pointer_size))
5302 print_dwarf_vma (begin, pointer_size);
5303 print_dwarf_vma (end, pointer_size);
5304 printf ("(base address)\n");
5308 print_dwarf_vma (begin + base_address, pointer_size);
5309 print_dwarf_vma (end + base_address, pointer_size);
5312 fputs (_("(start == end)"), stdout);
5313 else if (begin > end)
5314 fputs (_("(start > end)"), stdout);
5321 free (range_entries);
5326 typedef struct Frame_Chunk
5328 struct Frame_Chunk *next;
5329 unsigned char *chunk_start;
5331 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5332 short int *col_type;
5335 unsigned int code_factor;
5340 dwarf_vma cfa_offset;
5342 unsigned char fde_encoding;
5343 unsigned char cfa_exp;
5344 unsigned char ptr_size;
5345 unsigned char segment_size;
5349 static const char *const *dwarf_regnames;
5350 static unsigned int dwarf_regnames_count;
5352 /* A marker for a col_type that means this column was never referenced
5353 in the frame info. */
5354 #define DW_CFA_unreferenced (-1)
5356 /* Return 0 if no more space is needed, 1 if more space is needed,
5357 -1 for invalid reg. */
5360 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5362 unsigned int prev = fc->ncols;
5364 if (reg < (unsigned int) fc->ncols)
5367 if (dwarf_regnames_count
5368 && reg > dwarf_regnames_count)
5371 fc->ncols = reg + 1;
5372 /* PR 17512: file: 10450-2643-0.004.
5373 If reg == -1 then this can happen... */
5377 /* PR 17512: file: 2844a11d. */
5378 if (fc->ncols > 1024)
5380 error (_("Unfeasibly large register number: %u\n"), reg);
5382 /* FIXME: 1024 is an arbitrary limit. Increase it if
5383 we ever encounter a valid binary that exceeds it. */
5387 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5388 sizeof (short int));
5389 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5390 /* PR 17512: file:002-10025-0.005. */
5391 if (fc->col_type == NULL || fc->col_offset == NULL)
5393 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5399 while (prev < fc->ncols)
5401 fc->col_type[prev] = DW_CFA_unreferenced;
5402 fc->col_offset[prev] = 0;
5408 static const char *const dwarf_regnames_i386[] =
5410 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5411 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5412 "eip", "eflags", NULL, /* 8 - 10 */
5413 "st0", "st1", "st2", "st3", /* 11 - 14 */
5414 "st4", "st5", "st6", "st7", /* 15 - 18 */
5415 NULL, NULL, /* 19 - 20 */
5416 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5417 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5418 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5419 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5420 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5421 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5422 "tr", "ldtr", /* 48 - 49 */
5423 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5424 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5425 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5426 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5427 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5428 NULL, NULL, NULL, /* 90 - 92 */
5429 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5432 static const char *const dwarf_regnames_iamcu[] =
5434 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5435 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5436 "eip", "eflags", NULL, /* 8 - 10 */
5437 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
5438 NULL, NULL, /* 19 - 20 */
5439 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
5440 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
5441 NULL, NULL, NULL, /* 37 - 39 */
5442 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5443 "tr", "ldtr", /* 48 - 49 */
5444 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5445 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5446 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5447 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5448 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5449 NULL, NULL, NULL, /* 90 - 92 */
5450 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
5454 init_dwarf_regnames_i386 (void)
5456 dwarf_regnames = dwarf_regnames_i386;
5457 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5461 init_dwarf_regnames_iamcu (void)
5463 dwarf_regnames = dwarf_regnames_iamcu;
5464 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
5467 static const char *const dwarf_regnames_x86_64[] =
5469 "rax", "rdx", "rcx", "rbx",
5470 "rsi", "rdi", "rbp", "rsp",
5471 "r8", "r9", "r10", "r11",
5472 "r12", "r13", "r14", "r15",
5474 "xmm0", "xmm1", "xmm2", "xmm3",
5475 "xmm4", "xmm5", "xmm6", "xmm7",
5476 "xmm8", "xmm9", "xmm10", "xmm11",
5477 "xmm12", "xmm13", "xmm14", "xmm15",
5478 "st0", "st1", "st2", "st3",
5479 "st4", "st5", "st6", "st7",
5480 "mm0", "mm1", "mm2", "mm3",
5481 "mm4", "mm5", "mm6", "mm7",
5483 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5484 "fs.base", "gs.base", NULL, NULL,
5486 "mxcsr", "fcw", "fsw",
5487 "xmm16", "xmm17", "xmm18", "xmm19",
5488 "xmm20", "xmm21", "xmm22", "xmm23",
5489 "xmm24", "xmm25", "xmm26", "xmm27",
5490 "xmm28", "xmm29", "xmm30", "xmm31",
5491 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5492 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5493 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5494 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5495 NULL, NULL, NULL, /* 115 - 117 */
5496 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5500 init_dwarf_regnames_x86_64 (void)
5502 dwarf_regnames = dwarf_regnames_x86_64;
5503 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5506 static const char *const dwarf_regnames_aarch64[] =
5508 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5509 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5510 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5511 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5512 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
5513 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5514 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5515 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5516 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5517 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5518 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5519 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5523 init_dwarf_regnames_aarch64 (void)
5525 dwarf_regnames = dwarf_regnames_aarch64;
5526 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
5529 static const char *const dwarf_regnames_s390[] =
5531 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
5532 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5533 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5534 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
5535 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
5536 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
5537 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
5538 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
5539 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
5542 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
5543 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
5547 init_dwarf_regnames_s390 (void)
5549 dwarf_regnames = dwarf_regnames_s390;
5550 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
5554 init_dwarf_regnames (unsigned int e_machine)
5559 init_dwarf_regnames_i386 ();
5563 init_dwarf_regnames_iamcu ();
5569 init_dwarf_regnames_x86_64 ();
5573 init_dwarf_regnames_aarch64 ();
5577 init_dwarf_regnames_s390 ();
5586 regname (unsigned int regno, int row)
5588 static char reg[64];
5590 && regno < dwarf_regnames_count
5591 && dwarf_regnames [regno] != NULL)
5594 return dwarf_regnames [regno];
5595 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5596 dwarf_regnames [regno]);
5599 snprintf (reg, sizeof (reg), "r%d", regno);
5604 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
5609 if (*max_regs != fc->ncols)
5610 *max_regs = fc->ncols;
5612 if (*need_col_headers)
5614 static const char *sloc = " LOC";
5616 *need_col_headers = 0;
5618 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5620 for (r = 0; r < *max_regs; r++)
5621 if (fc->col_type[r] != DW_CFA_unreferenced)
5626 printf ("%-5s ", regname (r, 1));
5632 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5634 strcpy (tmp, "exp");
5636 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
5637 printf ("%-8s ", tmp);
5639 for (r = 0; r < fc->ncols; r++)
5641 if (fc->col_type[r] != DW_CFA_unreferenced)
5643 switch (fc->col_type[r])
5645 case DW_CFA_undefined:
5648 case DW_CFA_same_value:
5652 sprintf (tmp, "c%+d", fc->col_offset[r]);
5654 case DW_CFA_val_offset:
5655 sprintf (tmp, "v%+d", fc->col_offset[r]);
5657 case DW_CFA_register:
5658 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5660 case DW_CFA_expression:
5661 strcpy (tmp, "exp");
5663 case DW_CFA_val_expression:
5664 strcpy (tmp, "vexp");
5667 strcpy (tmp, "n/a");
5670 printf ("%-5s ", tmp);
5676 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5677 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5678 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5680 static unsigned char *
5681 read_cie (unsigned char *start, unsigned char *end,
5682 Frame_Chunk **p_cie, int *p_version,
5683 unsigned long *p_aug_len, unsigned char **p_aug)
5687 unsigned int length_return;
5688 unsigned char *augmentation_data = NULL;
5689 unsigned long augmentation_data_len = 0;
5692 /* PR 17512: file: 001-228113-0.004. */
5696 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5697 memset (fc, 0, sizeof (Frame_Chunk));
5699 fc->col_type = (short int *) xmalloc (sizeof (short int));
5700 fc->col_offset = (int *) xmalloc (sizeof (int));
5704 fc->augmentation = (char *) start;
5705 /* PR 17512: file: 001-228113-0.004.
5706 Skip past augmentation name, but avoid running off the end of the data. */
5708 if (* start ++ == '\0')
5712 warn (_("No terminator for augmentation name\n"));
5716 if (strcmp (fc->augmentation, "eh") == 0)
5717 start += eh_addr_size;
5721 GET (fc->ptr_size, 1);
5722 if (fc->ptr_size < 1 || fc->ptr_size > 8)
5724 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
5728 GET (fc->segment_size, 1);
5729 /* PR 17512: file: e99d2804. */
5730 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
5732 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
5736 eh_addr_size = fc->ptr_size;
5740 fc->ptr_size = eh_addr_size;
5741 fc->segment_size = 0;
5743 fc->code_factor = LEB ();
5744 fc->data_factor = SLEB ();
5754 if (fc->augmentation[0] == 'z')
5756 augmentation_data_len = LEB ();
5757 augmentation_data = start;
5758 start += augmentation_data_len;
5759 /* PR 17512: file: 11042-2589-0.004. */
5762 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
5767 if (augmentation_data_len)
5771 unsigned char *qend;
5773 p = (unsigned char *) fc->augmentation + 1;
5774 q = augmentation_data;
5775 qend = q + augmentation_data_len;
5777 /* PR 17531: file: 015adfaa. */
5780 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
5781 augmentation_data_len = 0;
5784 while (p < end && q < augmentation_data + augmentation_data_len)
5789 q += 1 + size_of_encoded_value (*q);
5791 fc->fde_encoding = *q++;
5798 /* Note - it is OK if this loop terminates with q < qend.
5799 Padding may have been inserted to align the end of the CIE. */
5804 *p_version = version;
5807 *p_aug_len = augmentation_data_len;
5808 *p_aug = augmentation_data;
5814 display_debug_frames (struct dwarf_section *section,
5815 void *file ATTRIBUTE_UNUSED)
5817 unsigned char *start = section->start;
5818 unsigned char *end = start + section->size;
5819 unsigned char *section_start = start;
5820 Frame_Chunk *chunks = 0, *forward_refs = 0;
5821 Frame_Chunk *remembered_state = 0;
5823 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5824 unsigned int length_return;
5825 unsigned int max_regs = 0;
5826 const char *bad_reg = _("bad register: ");
5827 unsigned int saved_eh_addr_size = eh_addr_size;
5829 printf (_("Contents of the %s section:\n"), section->name);
5833 unsigned char *saved_start;
5834 unsigned char *block_end;
5839 int need_col_headers = 1;
5840 unsigned char *augmentation_data = NULL;
5841 unsigned long augmentation_data_len = 0;
5842 unsigned int encoded_ptr_size = saved_eh_addr_size;
5843 unsigned int offset_size;
5844 unsigned int initial_length_size;
5845 bfd_boolean all_nops;
5847 saved_start = start;
5849 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5853 printf ("\n%08lx ZERO terminator\n\n",
5854 (unsigned long)(saved_start - section_start));
5855 /* Skip any zero terminators that directly follow.
5856 A corrupt section size could have loaded a whole
5857 slew of zero filled memory bytes. eg
5858 PR 17512: file: 070-19381-0.004. */
5859 while (start < end && * start == 0)
5864 if (length == 0xffffffff)
5866 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5868 initial_length_size = 12;
5873 initial_length_size = 4;
5876 block_end = saved_start + length + initial_length_size;
5877 if (block_end > end || block_end < start)
5879 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5880 dwarf_vmatoa_1 (NULL, length, offset_size),
5881 (unsigned long) (saved_start - section_start));
5885 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5887 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5888 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5893 start = read_cie (start, end, &cie, &version,
5894 &augmentation_data_len, &augmentation_data);
5895 /* PR 17512: file: 027-135133-0.005. */
5902 fc->chunk_start = saved_start;
5903 mreg = max_regs > 0 ? max_regs - 1 : 0;
5906 if (frame_need_space (fc, mreg) < 0)
5908 if (fc->fde_encoding)
5909 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5911 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5912 print_dwarf_vma (length, fc->ptr_size);
5913 print_dwarf_vma (cie_id, offset_size);
5915 if (do_debug_frames_interp)
5917 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5918 fc->code_factor, fc->data_factor, fc->ra);
5923 printf (" Version: %d\n", version);
5924 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5927 printf (" Pointer Size: %u\n", fc->ptr_size);
5928 printf (" Segment Size: %u\n", fc->segment_size);
5930 printf (" Code alignment factor: %u\n", fc->code_factor);
5931 printf (" Data alignment factor: %d\n", fc->data_factor);
5932 printf (" Return address column: %d\n", fc->ra);
5934 if (augmentation_data_len)
5938 printf (" Augmentation data: ");
5939 for (i = 0; i < augmentation_data_len; ++i)
5940 /* FIXME: If do_wide is FALSE, then we should
5941 add carriage returns at 80 columns... */
5942 printf (" %02x", augmentation_data[i]);
5950 unsigned char *look_for;
5951 static Frame_Chunk fde_fc;
5952 unsigned long segment_selector;
5956 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
5957 look_for = start - 4 - ((cie_id ^ sign) - sign);
5960 look_for = section_start + cie_id;
5962 if (look_for <= saved_start)
5964 for (cie = chunks; cie ; cie = cie->next)
5965 if (cie->chunk_start == look_for)
5970 for (cie = forward_refs; cie ; cie = cie->next)
5971 if (cie->chunk_start == look_for)
5975 unsigned int off_size;
5976 unsigned char *cie_scan;
5978 cie_scan = look_for;
5980 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
5981 if (length == 0xffffffff)
5983 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
5990 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
5993 : ((off_size == 4 && c_id == DW_CIE_ID)
5994 || (off_size == 8 && c_id == DW64_CIE_ID)))
5999 read_cie (cie_scan, end, &cie, &version,
6000 &augmentation_data_len, &augmentation_data);
6001 /* PR 17512: file: 3450-2098-0.004. */
6004 warn (_("Failed to read CIE information\n"));
6007 cie->next = forward_refs;
6009 cie->chunk_start = look_for;
6010 mreg = max_regs > 0 ? max_regs - 1 : 0;
6013 if (frame_need_space (cie, mreg) < 0)
6015 warn (_("Invalid max register\n"));
6018 if (cie->fde_encoding)
6020 = size_of_encoded_value (cie->fde_encoding);
6027 memset (fc, 0, sizeof (Frame_Chunk));
6031 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6032 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6033 (unsigned long) (saved_start - section_start));
6035 fc->col_type = (short int *) xmalloc (sizeof (short int));
6036 fc->col_offset = (int *) xmalloc (sizeof (int));
6037 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
6039 warn (_("Invalid max register\n"));
6043 fc->augmentation = "";
6044 fc->fde_encoding = 0;
6045 fc->ptr_size = eh_addr_size;
6046 fc->segment_size = 0;
6050 fc->ncols = cie->ncols;
6051 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
6052 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
6053 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6054 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6055 fc->augmentation = cie->augmentation;
6056 fc->ptr_size = cie->ptr_size;
6057 eh_addr_size = cie->ptr_size;
6058 fc->segment_size = cie->segment_size;
6059 fc->code_factor = cie->code_factor;
6060 fc->data_factor = cie->data_factor;
6061 fc->cfa_reg = cie->cfa_reg;
6062 fc->cfa_offset = cie->cfa_offset;
6064 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
6066 warn (_("Invalid max register\n"));
6069 fc->fde_encoding = cie->fde_encoding;
6072 if (fc->fde_encoding)
6073 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
6075 segment_selector = 0;
6076 if (fc->segment_size)
6078 if (fc->segment_size > sizeof (segment_selector))
6080 /* PR 17512: file: 9e196b3e. */
6081 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
6082 fc->segment_size = 4;
6084 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
6087 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
6089 /* FIXME: It appears that sometimes the final pc_range value is
6090 encoded in less than encoded_ptr_size bytes. See the x86_64
6091 run of the "objcopy on compressed debug sections" test for an
6093 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
6095 if (cie->augmentation[0] == 'z')
6097 augmentation_data_len = LEB ();
6098 augmentation_data = start;
6099 start += augmentation_data_len;
6100 /* PR 17512: file: 722-8446-0.004. */
6101 if (start >= end || ((signed long) augmentation_data_len) < 0)
6103 warn (_("Corrupt augmentation data length: %lx\n"),
6104 augmentation_data_len);
6106 augmentation_data = NULL;
6107 augmentation_data_len = 0;
6111 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6112 (unsigned long)(saved_start - section_start),
6113 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
6114 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
6115 (unsigned long)(cie->chunk_start - section_start));
6117 if (fc->segment_size)
6118 printf ("%04lx:", segment_selector);
6121 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
6122 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
6124 if (! do_debug_frames_interp && augmentation_data_len)
6128 printf (" Augmentation data: ");
6129 for (i = 0; i < augmentation_data_len; ++i)
6130 printf (" %02x", augmentation_data[i]);
6136 /* At this point, fc is the current chunk, cie (if any) is set, and
6137 we're about to interpret instructions for the chunk. */
6138 /* ??? At present we need to do this always, since this sizes the
6139 fc->col_type and fc->col_offset arrays, which we write into always.
6140 We should probably split the interpreted and non-interpreted bits
6141 into two different routines, since there's so much that doesn't
6142 really overlap between them. */
6143 if (1 || do_debug_frames_interp)
6145 /* Start by making a pass over the chunk, allocating storage
6146 and taking note of what registers are used. */
6147 unsigned char *tmp = start;
6149 while (start < block_end)
6151 unsigned int reg, op, opa;
6153 unsigned char * new_start;
6160 /* Warning: if you add any more cases to this switch, be
6161 sure to add them to the corresponding switch below. */
6164 case DW_CFA_advance_loc:
6168 if (frame_need_space (fc, opa) >= 0)
6169 fc->col_type[opa] = DW_CFA_undefined;
6171 case DW_CFA_restore:
6172 if (frame_need_space (fc, opa) >= 0)
6173 fc->col_type[opa] = DW_CFA_undefined;
6175 case DW_CFA_set_loc:
6176 start += encoded_ptr_size;
6178 case DW_CFA_advance_loc1:
6181 case DW_CFA_advance_loc2:
6184 case DW_CFA_advance_loc4:
6187 case DW_CFA_offset_extended:
6188 case DW_CFA_val_offset:
6189 reg = LEB (); LEB ();
6190 if (frame_need_space (fc, reg) >= 0)
6191 fc->col_type[reg] = DW_CFA_undefined;
6193 case DW_CFA_restore_extended:
6195 if (frame_need_space (fc, reg) >= 0)
6196 fc->col_type[reg] = DW_CFA_undefined;
6198 case DW_CFA_undefined:
6200 if (frame_need_space (fc, reg) >= 0)
6201 fc->col_type[reg] = DW_CFA_undefined;
6203 case DW_CFA_same_value:
6205 if (frame_need_space (fc, reg) >= 0)
6206 fc->col_type[reg] = DW_CFA_undefined;
6208 case DW_CFA_register:
6209 reg = LEB (); LEB ();
6210 if (frame_need_space (fc, reg) >= 0)
6211 fc->col_type[reg] = DW_CFA_undefined;
6213 case DW_CFA_def_cfa:
6216 case DW_CFA_def_cfa_register:
6219 case DW_CFA_def_cfa_offset:
6222 case DW_CFA_def_cfa_expression:
6224 new_start = start + temp;
6225 if (new_start < start)
6227 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
6233 case DW_CFA_expression:
6234 case DW_CFA_val_expression:
6237 new_start = start + temp;
6238 if (new_start < start)
6240 /* PR 17512: file:306-192417-0.005. */
6241 warn (_("Corrupt CFA expression value: %lu\n"), temp);
6246 if (frame_need_space (fc, reg) >= 0)
6247 fc->col_type[reg] = DW_CFA_undefined;
6249 case DW_CFA_offset_extended_sf:
6250 case DW_CFA_val_offset_sf:
6251 reg = LEB (); SLEB ();
6252 if (frame_need_space (fc, reg) >= 0)
6253 fc->col_type[reg] = DW_CFA_undefined;
6255 case DW_CFA_def_cfa_sf:
6258 case DW_CFA_def_cfa_offset_sf:
6261 case DW_CFA_MIPS_advance_loc8:
6264 case DW_CFA_GNU_args_size:
6267 case DW_CFA_GNU_negative_offset_extended:
6268 reg = LEB (); LEB ();
6269 if (frame_need_space (fc, reg) >= 0)
6270 fc->col_type[reg] = DW_CFA_undefined;
6281 /* Now we know what registers are used, make a second pass over
6282 the chunk, this time actually printing out the info. */
6284 while (start < block_end)
6286 unsigned char * tmp;
6288 unsigned long ul, reg, roffs;
6292 const char *reg_prefix = "";
6299 /* Make a note if something other than DW_CFA_nop happens. */
6300 if (op != DW_CFA_nop)
6303 /* Warning: if you add any more cases to this switch, be
6304 sure to add them to the corresponding switch above. */
6307 case DW_CFA_advance_loc:
6308 if (do_debug_frames_interp)
6309 frame_display_row (fc, &need_col_headers, &max_regs);
6311 printf (" DW_CFA_advance_loc: %d to %s\n",
6312 opa * fc->code_factor,
6313 dwarf_vmatoa_1 (NULL,
6314 fc->pc_begin + opa * fc->code_factor,
6316 fc->pc_begin += opa * fc->code_factor;
6321 if (opa >= (unsigned int) fc->ncols)
6322 reg_prefix = bad_reg;
6323 if (! do_debug_frames_interp || *reg_prefix != '\0')
6324 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6325 reg_prefix, regname (opa, 0),
6326 roffs * fc->data_factor);
6327 if (*reg_prefix == '\0')
6329 fc->col_type[opa] = DW_CFA_offset;
6330 fc->col_offset[opa] = roffs * fc->data_factor;
6334 case DW_CFA_restore:
6335 if (opa >= (unsigned int) fc->ncols)
6336 reg_prefix = bad_reg;
6337 if (! do_debug_frames_interp || *reg_prefix != '\0')
6338 printf (" DW_CFA_restore: %s%s\n",
6339 reg_prefix, regname (opa, 0));
6340 if (*reg_prefix != '\0')
6343 if (opa >= (unsigned int) cie->ncols
6344 || (do_debug_frames_interp
6345 && cie->col_type[opa] == DW_CFA_unreferenced))
6347 fc->col_type[opa] = DW_CFA_undefined;
6348 fc->col_offset[opa] = 0;
6352 fc->col_type[opa] = cie->col_type[opa];
6353 fc->col_offset[opa] = cie->col_offset[opa];
6357 case DW_CFA_set_loc:
6358 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
6359 if (do_debug_frames_interp)
6360 frame_display_row (fc, &need_col_headers, &max_regs);
6362 printf (" DW_CFA_set_loc: %s\n",
6363 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
6367 case DW_CFA_advance_loc1:
6368 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
6369 if (do_debug_frames_interp)
6370 frame_display_row (fc, &need_col_headers, &max_regs);
6372 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6373 (unsigned long) (ofs * fc->code_factor),
6374 dwarf_vmatoa_1 (NULL,
6375 fc->pc_begin + ofs * fc->code_factor,
6377 fc->pc_begin += ofs * fc->code_factor;
6380 case DW_CFA_advance_loc2:
6381 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
6382 if (do_debug_frames_interp)
6383 frame_display_row (fc, &need_col_headers, &max_regs);
6385 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6386 (unsigned long) (ofs * fc->code_factor),
6387 dwarf_vmatoa_1 (NULL,
6388 fc->pc_begin + ofs * fc->code_factor,
6390 fc->pc_begin += ofs * fc->code_factor;
6393 case DW_CFA_advance_loc4:
6394 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
6395 if (do_debug_frames_interp)
6396 frame_display_row (fc, &need_col_headers, &max_regs);
6398 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6399 (unsigned long) (ofs * fc->code_factor),
6400 dwarf_vmatoa_1 (NULL,
6401 fc->pc_begin + ofs * fc->code_factor,
6403 fc->pc_begin += ofs * fc->code_factor;
6406 case DW_CFA_offset_extended:
6409 if (reg >= (unsigned int) fc->ncols)
6410 reg_prefix = bad_reg;
6411 if (! do_debug_frames_interp || *reg_prefix != '\0')
6412 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6413 reg_prefix, regname (reg, 0),
6414 roffs * fc->data_factor);
6415 if (*reg_prefix == '\0')
6417 fc->col_type[reg] = DW_CFA_offset;
6418 fc->col_offset[reg] = roffs * fc->data_factor;
6422 case DW_CFA_val_offset:
6425 if (reg >= (unsigned int) fc->ncols)
6426 reg_prefix = bad_reg;
6427 if (! do_debug_frames_interp || *reg_prefix != '\0')
6428 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
6429 reg_prefix, regname (reg, 0),
6430 roffs * fc->data_factor);
6431 if (*reg_prefix == '\0')
6433 fc->col_type[reg] = DW_CFA_val_offset;
6434 fc->col_offset[reg] = roffs * fc->data_factor;
6438 case DW_CFA_restore_extended:
6440 if (reg >= (unsigned int) fc->ncols)
6441 reg_prefix = bad_reg;
6442 if (! do_debug_frames_interp || *reg_prefix != '\0')
6443 printf (" DW_CFA_restore_extended: %s%s\n",
6444 reg_prefix, regname (reg, 0));
6445 if (*reg_prefix != '\0')
6448 if (reg >= (unsigned int) cie->ncols)
6450 fc->col_type[reg] = DW_CFA_undefined;
6451 fc->col_offset[reg] = 0;
6455 fc->col_type[reg] = cie->col_type[reg];
6456 fc->col_offset[reg] = cie->col_offset[reg];
6460 case DW_CFA_undefined:
6462 if (reg >= (unsigned int) fc->ncols)
6463 reg_prefix = bad_reg;
6464 if (! do_debug_frames_interp || *reg_prefix != '\0')
6465 printf (" DW_CFA_undefined: %s%s\n",
6466 reg_prefix, regname (reg, 0));
6467 if (*reg_prefix == '\0')
6469 fc->col_type[reg] = DW_CFA_undefined;
6470 fc->col_offset[reg] = 0;
6474 case DW_CFA_same_value:
6476 if (reg >= (unsigned int) fc->ncols)
6477 reg_prefix = bad_reg;
6478 if (! do_debug_frames_interp || *reg_prefix != '\0')
6479 printf (" DW_CFA_same_value: %s%s\n",
6480 reg_prefix, regname (reg, 0));
6481 if (*reg_prefix == '\0')
6483 fc->col_type[reg] = DW_CFA_same_value;
6484 fc->col_offset[reg] = 0;
6488 case DW_CFA_register:
6491 if (reg >= (unsigned int) fc->ncols)
6492 reg_prefix = bad_reg;
6493 if (! do_debug_frames_interp || *reg_prefix != '\0')
6495 printf (" DW_CFA_register: %s%s in ",
6496 reg_prefix, regname (reg, 0));
6497 puts (regname (roffs, 0));
6499 if (*reg_prefix == '\0')
6501 fc->col_type[reg] = DW_CFA_register;
6502 fc->col_offset[reg] = roffs;
6506 case DW_CFA_remember_state:
6507 if (! do_debug_frames_interp)
6508 printf (" DW_CFA_remember_state\n");
6509 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6510 rs->cfa_offset = fc->cfa_offset;
6511 rs->cfa_reg = fc->cfa_reg;
6513 rs->cfa_exp = fc->cfa_exp;
6514 rs->ncols = fc->ncols;
6515 rs->col_type = (short int *) xcmalloc (rs->ncols,
6516 sizeof (* rs->col_type));
6517 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
6518 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
6519 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
6520 rs->next = remembered_state;
6521 remembered_state = rs;
6524 case DW_CFA_restore_state:
6525 if (! do_debug_frames_interp)
6526 printf (" DW_CFA_restore_state\n");
6527 rs = remembered_state;
6530 remembered_state = rs->next;
6531 fc->cfa_offset = rs->cfa_offset;
6532 fc->cfa_reg = rs->cfa_reg;
6534 fc->cfa_exp = rs->cfa_exp;
6535 if (frame_need_space (fc, rs->ncols - 1) < 0)
6537 warn (_("Invalid column number in saved frame state\n"));
6541 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
6542 memcpy (fc->col_offset, rs->col_offset,
6543 rs->ncols * sizeof (* rs->col_offset));
6544 free (rs->col_type);
6545 free (rs->col_offset);
6548 else if (do_debug_frames_interp)
6549 printf ("Mismatched DW_CFA_restore_state\n");
6552 case DW_CFA_def_cfa:
6553 fc->cfa_reg = LEB ();
6554 fc->cfa_offset = LEB ();
6556 if (! do_debug_frames_interp)
6557 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6558 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
6561 case DW_CFA_def_cfa_register:
6562 fc->cfa_reg = LEB ();
6564 if (! do_debug_frames_interp)
6565 printf (" DW_CFA_def_cfa_register: %s\n",
6566 regname (fc->cfa_reg, 0));
6569 case DW_CFA_def_cfa_offset:
6570 fc->cfa_offset = LEB ();
6571 if (! do_debug_frames_interp)
6572 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
6576 if (! do_debug_frames_interp)
6577 printf (" DW_CFA_nop\n");
6580 case DW_CFA_def_cfa_expression:
6582 if (start >= block_end || ul > (unsigned long) (block_end - start))
6584 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6587 if (! do_debug_frames_interp)
6589 printf (" DW_CFA_def_cfa_expression (");
6590 decode_location_expression (start, eh_addr_size, 0, -1,
6598 case DW_CFA_expression:
6601 if (reg >= (unsigned int) fc->ncols)
6602 reg_prefix = bad_reg;
6603 /* PR 17512: file: 069-133014-0.006. */
6604 /* PR 17512: file: 98c02eb4. */
6606 if (start >= block_end || tmp > block_end || tmp < start)
6608 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6611 if (! do_debug_frames_interp || *reg_prefix != '\0')
6613 printf (" DW_CFA_expression: %s%s (",
6614 reg_prefix, regname (reg, 0));
6615 decode_location_expression (start, eh_addr_size, 0, -1,
6619 if (*reg_prefix == '\0')
6620 fc->col_type[reg] = DW_CFA_expression;
6624 case DW_CFA_val_expression:
6627 if (reg >= (unsigned int) fc->ncols)
6628 reg_prefix = bad_reg;
6630 if (start >= block_end || tmp > block_end || tmp < start)
6632 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6635 if (! do_debug_frames_interp || *reg_prefix != '\0')
6637 printf (" DW_CFA_val_expression: %s%s (",
6638 reg_prefix, regname (reg, 0));
6639 decode_location_expression (start, eh_addr_size, 0, -1,
6643 if (*reg_prefix == '\0')
6644 fc->col_type[reg] = DW_CFA_val_expression;
6648 case DW_CFA_offset_extended_sf:
6651 if (frame_need_space (fc, reg) < 0)
6652 reg_prefix = bad_reg;
6653 if (! do_debug_frames_interp || *reg_prefix != '\0')
6654 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6655 reg_prefix, regname (reg, 0),
6656 (long)(l * fc->data_factor));
6657 if (*reg_prefix == '\0')
6659 fc->col_type[reg] = DW_CFA_offset;
6660 fc->col_offset[reg] = l * fc->data_factor;
6664 case DW_CFA_val_offset_sf:
6667 if (frame_need_space (fc, reg) < 0)
6668 reg_prefix = bad_reg;
6669 if (! do_debug_frames_interp || *reg_prefix != '\0')
6670 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
6671 reg_prefix, regname (reg, 0),
6672 (long)(l * fc->data_factor));
6673 if (*reg_prefix == '\0')
6675 fc->col_type[reg] = DW_CFA_val_offset;
6676 fc->col_offset[reg] = l * fc->data_factor;
6680 case DW_CFA_def_cfa_sf:
6681 fc->cfa_reg = LEB ();
6682 fc->cfa_offset = SLEB ();
6683 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6685 if (! do_debug_frames_interp)
6686 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6687 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
6690 case DW_CFA_def_cfa_offset_sf:
6691 fc->cfa_offset = SLEB ();
6692 fc->cfa_offset *= fc->data_factor;
6693 if (! do_debug_frames_interp)
6694 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
6697 case DW_CFA_MIPS_advance_loc8:
6698 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
6699 if (do_debug_frames_interp)
6700 frame_display_row (fc, &need_col_headers, &max_regs);
6702 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6703 (unsigned long) (ofs * fc->code_factor),
6704 dwarf_vmatoa_1 (NULL,
6705 fc->pc_begin + ofs * fc->code_factor,
6707 fc->pc_begin += ofs * fc->code_factor;
6710 case DW_CFA_GNU_window_save:
6711 if (! do_debug_frames_interp)
6712 printf (" DW_CFA_GNU_window_save\n");
6715 case DW_CFA_GNU_args_size:
6717 if (! do_debug_frames_interp)
6718 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6721 case DW_CFA_GNU_negative_offset_extended:
6724 if (frame_need_space (fc, reg) < 0)
6725 reg_prefix = bad_reg;
6726 if (! do_debug_frames_interp || *reg_prefix != '\0')
6727 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6728 reg_prefix, regname (reg, 0),
6729 (long)(l * fc->data_factor));
6730 if (*reg_prefix == '\0')
6732 fc->col_type[reg] = DW_CFA_offset;
6733 fc->col_offset[reg] = l * fc->data_factor;
6738 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6739 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6741 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6746 /* Interpret the CFA - as long as it is not completely full of NOPs. */
6747 if (do_debug_frames_interp && ! all_nops)
6748 frame_display_row (fc, &need_col_headers, &max_regs);
6751 eh_addr_size = saved_eh_addr_size;
6764 display_gdb_index (struct dwarf_section *section,
6765 void *file ATTRIBUTE_UNUSED)
6767 unsigned char *start = section->start;
6769 uint32_t cu_list_offset, tu_list_offset;
6770 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6771 unsigned int cu_list_elements, tu_list_elements;
6772 unsigned int address_table_size, symbol_table_slots;
6773 unsigned char *cu_list, *tu_list;
6774 unsigned char *address_table, *symbol_table, *constant_pool;
6777 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6779 printf (_("Contents of the %s section:\n"), section->name);
6781 if (section->size < 6 * sizeof (uint32_t))
6783 warn (_("Truncated header in the %s section.\n"), section->name);
6787 version = byte_get_little_endian (start, 4);
6788 printf (_("Version %ld\n"), (long) version);
6790 /* Prior versions are obsolete, and future versions may not be
6791 backwards compatible. */
6792 if (version < 3 || version > 8)
6794 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6798 warn (_("The address table data in version 3 may be wrong.\n"));
6800 warn (_("Version 4 does not support case insensitive lookups.\n"));
6802 warn (_("Version 5 does not include inlined functions.\n"));
6804 warn (_("Version 6 does not include symbol attributes.\n"));
6805 /* Version 7 indices generated by Gold have bad type unit references,
6806 PR binutils/15021. But we don't know if the index was generated by
6807 Gold or not, so to avoid worrying users with gdb-generated indices
6808 we say nothing for version 7 here. */
6810 cu_list_offset = byte_get_little_endian (start + 4, 4);
6811 tu_list_offset = byte_get_little_endian (start + 8, 4);
6812 address_table_offset = byte_get_little_endian (start + 12, 4);
6813 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6814 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6816 if (cu_list_offset > section->size
6817 || tu_list_offset > section->size
6818 || address_table_offset > section->size
6819 || symbol_table_offset > section->size
6820 || constant_pool_offset > section->size)
6822 warn (_("Corrupt header in the %s section.\n"), section->name);
6826 /* PR 17531: file: 418d0a8a. */
6827 if (tu_list_offset < cu_list_offset)
6829 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6830 tu_list_offset, cu_list_offset);
6834 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6836 if (address_table_offset < tu_list_offset)
6838 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6839 address_table_offset, tu_list_offset);
6843 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6845 /* PR 17531: file: 18a47d3d. */
6846 if (symbol_table_offset < address_table_offset)
6848 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6849 symbol_table_offset, address_table_offset);
6853 address_table_size = symbol_table_offset - address_table_offset;
6855 if (constant_pool_offset < symbol_table_offset)
6857 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6858 constant_pool_offset, symbol_table_offset);
6862 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6864 cu_list = start + cu_list_offset;
6865 tu_list = start + tu_list_offset;
6866 address_table = start + address_table_offset;
6867 symbol_table = start + symbol_table_offset;
6868 constant_pool = start + constant_pool_offset;
6870 if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
6872 warn (_("Address table extends beyond end of section.\n"));
6876 printf (_("\nCU table:\n"));
6877 for (i = 0; i < cu_list_elements; i += 2)
6879 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6880 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6882 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6883 (unsigned long) cu_offset,
6884 (unsigned long) (cu_offset + cu_length - 1));
6887 printf (_("\nTU table:\n"));
6888 for (i = 0; i < tu_list_elements; i += 3)
6890 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6891 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6892 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6894 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6895 (unsigned long) tu_offset,
6896 (unsigned long) type_offset);
6897 print_dwarf_vma (signature, 8);
6901 printf (_("\nAddress table:\n"));
6902 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
6905 uint64_t low = byte_get_little_endian (address_table + i, 8);
6906 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6907 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6909 print_dwarf_vma (low, 8);
6910 print_dwarf_vma (high, 8);
6911 printf (_("%lu\n"), (unsigned long) cu_index);
6914 printf (_("\nSymbol table:\n"));
6915 for (i = 0; i < symbol_table_slots; ++i)
6917 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6918 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6919 uint32_t num_cus, cu;
6921 if (name_offset != 0
6922 || cu_vector_offset != 0)
6925 unsigned char * adr;
6927 adr = constant_pool + name_offset;
6928 /* PR 17531: file: 5b7b07ad. */
6929 if (adr < constant_pool || adr >= section->start + section->size)
6931 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
6932 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6936 printf ("[%3u] %.*s:", i,
6937 (int) (section->size - (constant_pool_offset + name_offset)),
6938 constant_pool + name_offset);
6940 adr = constant_pool + cu_vector_offset;
6941 if (adr < constant_pool || adr >= section->start + section->size - 3)
6943 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
6944 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6945 cu_vector_offset, i);
6949 num_cus = byte_get_little_endian (adr, 4);
6951 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
6952 if (num_cus * 4 < num_cus
6953 || adr >= section->start + section->size
6954 || adr < constant_pool)
6956 printf ("<invalid number of CUs: %d>\n", num_cus);
6957 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6965 for (j = 0; j < num_cus; ++j)
6968 gdb_index_symbol_kind kind;
6970 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6971 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6972 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6973 cu = GDB_INDEX_CU_VALUE (cu);
6974 /* Convert to TU number if it's for a type unit. */
6975 if (cu >= cu_list_elements / 2)
6976 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6977 (unsigned long) (cu - cu_list_elements / 2));
6979 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6981 printf (" [%s, %s]",
6982 is_static ? _("static") : _("global"),
6983 get_gdb_index_symbol_kind_name (kind));
6995 /* Pre-allocate enough space for the CU/TU sets needed. */
6998 prealloc_cu_tu_list (unsigned int nshndx)
7000 if (shndx_pool == NULL)
7002 shndx_pool_size = nshndx;
7003 shndx_pool_used = 0;
7004 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
7005 sizeof (unsigned int));
7009 shndx_pool_size = shndx_pool_used + nshndx;
7010 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
7011 sizeof (unsigned int));
7016 add_shndx_to_cu_tu_entry (unsigned int shndx)
7018 if (shndx_pool_used >= shndx_pool_size)
7020 error (_("Internal error: out of space in the shndx pool.\n"));
7023 shndx_pool [shndx_pool_used++] = shndx;
7027 end_cu_tu_entry (void)
7029 if (shndx_pool_used >= shndx_pool_size)
7031 error (_("Internal error: out of space in the shndx pool.\n"));
7034 shndx_pool [shndx_pool_used++] = 0;
7037 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7040 get_DW_SECT_short_name (unsigned int dw_sect)
7042 static char buf[16];
7050 case DW_SECT_ABBREV:
7056 case DW_SECT_STR_OFFSETS:
7058 case DW_SECT_MACINFO:
7066 snprintf (buf, sizeof (buf), "%d", dw_sect);
7070 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7071 These sections are extensions for Fission.
7072 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7075 process_cu_tu_index (struct dwarf_section *section, int do_display)
7077 unsigned char *phdr = section->start;
7078 unsigned char *limit = phdr + section->size;
7079 unsigned char *phash;
7080 unsigned char *pindex;
7081 unsigned char *ppool;
7082 unsigned int version;
7083 unsigned int ncols = 0;
7085 unsigned int nslots;
7088 dwarf_vma signature_high;
7089 dwarf_vma signature_low;
7092 /* PR 17512: file: 002-168123-0.004. */
7095 warn (_("Section %s is empty\n"), section->name);
7098 /* PR 17512: file: 002-376-0.004. */
7099 if (section->size < 24)
7101 warn (_("Section %s is too small to contain a CU/TU header\n"),
7106 SAFE_BYTE_GET (version, phdr, 4, limit);
7108 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
7109 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
7110 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
7113 pindex = phash + nslots * 8;
7114 ppool = pindex + nslots * 4;
7116 /* PR 17531: file: 45d69832. */
7117 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
7119 warn (_("Section %s is too small for %d slots\n"),
7120 section->name, nslots);
7126 printf (_("Contents of the %s section:\n\n"), section->name);
7127 printf (_(" Version: %d\n"), version);
7129 printf (_(" Number of columns: %d\n"), ncols);
7130 printf (_(" Number of used entries: %d\n"), nused);
7131 printf (_(" Number of slots: %d\n\n"), nslots);
7134 if (ppool > limit || ppool < phdr)
7136 warn (_("Section %s too small for %d hash table entries\n"),
7137 section->name, nslots);
7144 prealloc_cu_tu_list ((limit - ppool) / 4);
7145 for (i = 0; i < nslots; i++)
7147 unsigned char *shndx_list;
7150 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
7151 if (signature_high != 0 || signature_low != 0)
7153 SAFE_BYTE_GET (j, pindex, 4, limit);
7154 shndx_list = ppool + j * 4;
7155 /* PR 17531: file: 705e010d. */
7156 if (shndx_list < ppool)
7158 warn (_("Section index pool located before start of section\n"));
7163 printf (_(" [%3d] Signature: 0x%s Sections: "),
7164 i, dwarf_vmatoa64 (signature_high, signature_low,
7165 buf, sizeof (buf)));
7168 if (shndx_list >= limit)
7170 warn (_("Section %s too small for shndx pool\n"),
7174 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
7178 printf (" %d", shndx);
7180 add_shndx_to_cu_tu_entry (shndx);
7192 else if (version == 2)
7195 unsigned int dw_sect;
7196 unsigned char *ph = phash;
7197 unsigned char *pi = pindex;
7198 unsigned char *poffsets = ppool + ncols * 4;
7199 unsigned char *psizes = poffsets + nused * ncols * 4;
7200 unsigned char *pend = psizes + nused * ncols * 4;
7201 bfd_boolean is_tu_index;
7202 struct cu_tu_set *this_set = NULL;
7204 unsigned char *prow;
7206 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
7208 /* PR 17531: file: 0dd159bf.
7209 Check for wraparound with an overlarge ncols value. */
7210 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
7212 warn (_("Overlarge number of columns: %x\n"), ncols);
7218 warn (_("Section %s too small for offset and size tables\n"),
7225 printf (_(" Offset table\n"));
7226 printf (" slot %-16s ",
7227 is_tu_index ? _("signature") : _("dwo_id"));
7234 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7240 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7247 for (j = 0; j < ncols; j++)
7249 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7250 printf (" %8s", get_DW_SECT_short_name (dw_sect));
7255 for (i = 0; i < nslots; i++)
7257 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7259 SAFE_BYTE_GET (row, pi, 4, limit);
7262 /* PR 17531: file: a05f6ab3. */
7265 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
7271 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
7273 prow = poffsets + (row - 1) * ncols * 4;
7274 /* PR 17531: file: b8ce60a8. */
7275 if (prow < poffsets || prow > limit)
7277 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
7283 printf (_(" [%3d] 0x%s"),
7284 i, dwarf_vmatoa64 (signature_high, signature_low,
7285 buf, sizeof (buf)));
7286 for (j = 0; j < ncols; j++)
7288 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7290 printf (" %8d", val);
7293 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7295 /* PR 17531: file: 10796eb3. */
7296 if (dw_sect >= DW_SECT_MAX)
7297 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7299 this_set [row - 1].section_offsets [dw_sect] = val;
7315 printf (_(" Size table\n"));
7316 printf (" slot %-16s ",
7317 is_tu_index ? _("signature") : _("dwo_id"));
7320 for (j = 0; j < ncols; j++)
7322 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
7324 printf (" %8s", get_DW_SECT_short_name (val));
7330 for (i = 0; i < nslots; i++)
7332 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7334 SAFE_BYTE_GET (row, pi, 4, limit);
7337 prow = psizes + (row - 1) * ncols * 4;
7340 printf (_(" [%3d] 0x%s"),
7341 i, dwarf_vmatoa64 (signature_high, signature_low,
7342 buf, sizeof (buf)));
7344 for (j = 0; j < ncols; j++)
7346 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7348 printf (" %8d", val);
7351 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7352 if (dw_sect >= DW_SECT_MAX)
7353 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7355 this_set [row - 1].section_sizes [dw_sect] = val;
7367 else if (do_display)
7368 printf (_(" Unsupported version (%d)\n"), version);
7376 /* Load the CU and TU indexes if present. This will build a list of
7377 section sets that we can use to associate a .debug_info.dwo section
7378 with its associated .debug_abbrev.dwo section in a .dwp file. */
7381 load_cu_tu_indexes (void *file)
7383 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
7385 /* If we have already loaded (or tried to load) the CU and TU indexes
7386 then do not bother to repeat the task. */
7387 if (cu_tu_indexes_read == -1)
7389 cu_tu_indexes_read = TRUE;
7391 if (load_debug_section (dwp_cu_index, file))
7392 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
7393 cu_tu_indexes_read = FALSE;
7395 if (load_debug_section (dwp_tu_index, file))
7396 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
7397 cu_tu_indexes_read = FALSE;
7400 return (bfd_boolean) cu_tu_indexes_read;
7403 /* Find the set of sections that includes section SHNDX. */
7406 find_cu_tu_set (void *file, unsigned int shndx)
7410 if (! load_cu_tu_indexes (file))
7413 /* Find SHNDX in the shndx pool. */
7414 for (i = 0; i < shndx_pool_used; i++)
7415 if (shndx_pool [i] == shndx)
7418 if (i >= shndx_pool_used)
7421 /* Now backup to find the first entry in the set. */
7422 while (i > 0 && shndx_pool [i - 1] != 0)
7425 return shndx_pool + i;
7428 /* Display a .debug_cu_index or .debug_tu_index section. */
7431 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
7433 return process_cu_tu_index (section, 1);
7437 display_debug_not_supported (struct dwarf_section *section,
7438 void *file ATTRIBUTE_UNUSED)
7440 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7446 /* Like malloc, but takes two parameters like calloc.
7447 Verifies that the first parameter is not too large.
7448 Note: does *not* initialise the allocated memory to zero. */
7450 cmalloc (size_t nmemb, size_t size)
7452 /* Check for overflow. */
7453 if (nmemb >= ~(size_t) 0 / size)
7456 return xmalloc (nmemb * size);
7459 /* Like xmalloc, but takes two parameters like calloc.
7460 Verifies that the first parameter is not too large.
7461 Note: does *not* initialise the allocated memory to zero. */
7463 xcmalloc (size_t nmemb, size_t size)
7465 /* Check for overflow. */
7466 if (nmemb >= ~(size_t) 0 / size)
7469 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
7474 return xmalloc (nmemb * size);
7477 /* Like xrealloc, but takes three parameters.
7478 Verifies that the second parameter is not too large.
7479 Note: does *not* initialise any new memory to zero. */
7481 xcrealloc (void *ptr, size_t nmemb, size_t size)
7483 /* Check for overflow. */
7484 if (nmemb >= ~(size_t) 0 / size)
7487 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
7492 return xrealloc (ptr, nmemb * size);
7495 /* Like xcalloc, but verifies that the first parameter is not too large. */
7497 xcalloc2 (size_t nmemb, size_t size)
7499 /* Check for overflow. */
7500 if (nmemb >= ~(size_t) 0 / size)
7503 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
7508 return xcalloc (nmemb, size);
7512 free_debug_memory (void)
7518 for (i = 0; i < max; i++)
7519 free_debug_section ((enum dwarf_section_display_enum) i);
7521 if (debug_information != NULL)
7523 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
7525 for (i = 0; i < num_debug_info_entries; i++)
7527 if (!debug_information [i].max_loc_offsets)
7529 free (debug_information [i].loc_offsets);
7530 free (debug_information [i].have_frame_base);
7532 if (!debug_information [i].max_range_lists)
7533 free (debug_information [i].range_lists);
7536 free (debug_information);
7537 debug_information = NULL;
7538 alloc_num_debug_info_entries = num_debug_info_entries = 0;
7543 dwarf_select_sections_by_names (const char *names)
7547 const char * option;
7551 debug_dump_long_opts;
7553 static const debug_dump_long_opts opts_table [] =
7555 /* Please keep this table alpha- sorted. */
7556 { "Ranges", & do_debug_ranges, 1 },
7557 { "abbrev", & do_debug_abbrevs, 1 },
7558 { "addr", & do_debug_addr, 1 },
7559 { "aranges", & do_debug_aranges, 1 },
7560 { "cu_index", & do_debug_cu_index, 1 },
7561 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
7562 { "frames", & do_debug_frames, 1 },
7563 { "frames-interp", & do_debug_frames_interp, 1 },
7564 /* The special .gdb_index section. */
7565 { "gdb_index", & do_gdb_index, 1 },
7566 { "info", & do_debug_info, 1 },
7567 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
7568 { "loc", & do_debug_loc, 1 },
7569 { "macro", & do_debug_macinfo, 1 },
7570 { "pubnames", & do_debug_pubnames, 1 },
7571 { "pubtypes", & do_debug_pubtypes, 1 },
7572 /* This entry is for compatibility
7573 with earlier versions of readelf. */
7574 { "ranges", & do_debug_aranges, 1 },
7575 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
7576 { "str", & do_debug_str, 1 },
7577 /* These trace_* sections are used by Itanium VMS. */
7578 { "trace_abbrev", & do_trace_abbrevs, 1 },
7579 { "trace_aranges", & do_trace_aranges, 1 },
7580 { "trace_info", & do_trace_info, 1 },
7589 const debug_dump_long_opts * entry;
7591 for (entry = opts_table; entry->option; entry++)
7593 size_t len = strlen (entry->option);
7595 if (strncmp (p, entry->option, len) == 0
7596 && (p[len] == ',' || p[len] == '\0'))
7598 * entry->variable |= entry->val;
7600 /* The --debug-dump=frames-interp option also
7601 enables the --debug-dump=frames option. */
7602 if (do_debug_frames_interp)
7603 do_debug_frames = 1;
7610 if (entry->option == NULL)
7612 warn (_("Unrecognized debug option '%s'\n"), p);
7613 p = strchr (p, ',');
7624 dwarf_select_sections_by_letters (const char *letters)
7626 unsigned int lindex = 0;
7628 while (letters[lindex])
7629 switch (letters[lindex++])
7636 do_debug_abbrevs = 1;
7640 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
7644 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
7648 do_debug_pubnames = 1;
7652 do_debug_pubtypes = 1;
7656 do_debug_aranges = 1;
7660 do_debug_ranges = 1;
7664 do_debug_frames_interp = 1;
7667 do_debug_frames = 1;
7671 do_debug_macinfo = 1;
7683 warn (_("Unrecognized debug option '%s'\n"), letters);
7689 dwarf_select_sections_all (void)
7692 do_debug_abbrevs = 1;
7693 do_debug_lines = FLAG_DEBUG_LINES_RAW;
7694 do_debug_pubnames = 1;
7695 do_debug_pubtypes = 1;
7696 do_debug_aranges = 1;
7697 do_debug_ranges = 1;
7698 do_debug_frames = 1;
7699 do_debug_macinfo = 1;
7704 do_trace_abbrevs = 1;
7705 do_trace_aranges = 1;
7707 do_debug_cu_index = 1;
7710 struct dwarf_section_display debug_displays[] =
7712 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7713 display_debug_abbrev, &do_debug_abbrevs, FALSE },
7714 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7715 display_debug_aranges, &do_debug_aranges, TRUE },
7716 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7717 display_debug_frames, &do_debug_frames, TRUE },
7718 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
7719 display_debug_info, &do_debug_info, TRUE },
7720 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7721 display_debug_lines, &do_debug_lines, TRUE },
7722 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7723 display_debug_pubnames, &do_debug_pubnames, FALSE },
7724 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7725 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
7726 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7727 display_debug_frames, &do_debug_frames, TRUE },
7728 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7729 display_debug_macinfo, &do_debug_macinfo, FALSE },
7730 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7731 display_debug_macro, &do_debug_macinfo, TRUE },
7732 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7733 display_debug_str, &do_debug_str, FALSE },
7734 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7735 display_debug_loc, &do_debug_loc, TRUE },
7736 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7737 display_debug_pubnames, &do_debug_pubtypes, FALSE },
7738 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7739 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
7740 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7741 display_debug_ranges, &do_debug_ranges, TRUE },
7742 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7743 display_debug_not_supported, NULL, FALSE },
7744 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7745 display_debug_not_supported, NULL, FALSE },
7746 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
7747 display_debug_types, &do_debug_info, TRUE },
7748 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7749 display_debug_not_supported, NULL, FALSE },
7750 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7751 display_gdb_index, &do_gdb_index, FALSE },
7752 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
7753 display_trace_info, &do_trace_info, TRUE },
7754 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7755 display_debug_abbrev, &do_trace_abbrevs, FALSE },
7756 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7757 display_debug_aranges, &do_trace_aranges, FALSE },
7758 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
7759 display_debug_info, &do_debug_info, TRUE },
7760 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7761 display_debug_abbrev, &do_debug_abbrevs, FALSE },
7762 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
7763 display_debug_types, &do_debug_info, TRUE },
7764 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7765 display_debug_lines, &do_debug_lines, TRUE },
7766 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7767 display_debug_loc, &do_debug_loc, TRUE },
7768 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7769 display_debug_macro, &do_debug_macinfo, TRUE },
7770 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7771 display_debug_macinfo, &do_debug_macinfo, FALSE },
7772 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7773 display_debug_str, &do_debug_str, TRUE },
7774 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7775 display_debug_str_offsets, NULL, FALSE },
7776 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7777 display_debug_str_offsets, NULL, FALSE },
7778 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7779 display_debug_addr, &do_debug_addr, TRUE },
7780 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7781 display_cu_index, &do_debug_cu_index, FALSE },
7782 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
7783 display_cu_index, &do_debug_cu_index, FALSE },