1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2014 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 debug_info *debug_information = NULL;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames;
52 int do_debug_pubtypes;
56 int do_debug_frames_interp;
65 int do_debug_cu_index;
68 int dwarf_cutoff_level = -1;
69 unsigned long dwarf_start_die;
73 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
74 sections. For version 1 package files, each set is stored in SHNDX_POOL
75 as a zero-terminated list of section indexes comprising one set of debug
76 sections from a .dwo file. */
78 static int cu_tu_indexes_read = 0;
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 void load_cu_tu_indexes (void *file);
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 specifiying 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)
285 if (length_return != NULL)
286 *length_return = num_read;
288 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
289 result |= (dwarf_vma) -1 << shift;
294 /* Create a signed version to avoid painful typecasts. */
295 static inline dwarf_signed_vma
296 read_sleb128 (unsigned char * data,
297 unsigned int * length_return,
298 const unsigned char * const end)
300 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
303 static inline dwarf_vma
304 read_uleb128 (unsigned char * data,
305 unsigned int * length_return,
306 const unsigned char * const end)
308 return read_leb128 (data, length_return, FALSE, end);
311 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
314 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
315 unsigned int amount = (AMOUNT); \
316 if (((PTR) + amount) >= (END)) \
319 amount = (END) - (PTR); \
323 if (amount == 0 || amount > 8) \
326 VAL = byte_get ((PTR), amount); \
330 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
333 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
338 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
341 unsigned int amount = (AMOUNT); \
342 if (((PTR) + amount) >= (END)) \
345 amount = (END) - (PTR); \
350 VAL = byte_get_signed ((PTR), amount); \
356 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
359 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
364 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
367 if (((PTR) + 8) <= (END)) \
369 byte_get_64 ((PTR), (HIGH), (LOW)); \
373 * (LOW) = * (HIGH) = 0; \
378 typedef struct State_Machine_Registers
386 unsigned char op_index;
387 unsigned char end_sequence;
388 /* This variable hold the number of the last entry seen
389 in the File Table. */
390 unsigned int last_file_entry;
393 static SMR state_machine_regs;
396 reset_state_machine (int is_stmt)
398 state_machine_regs.address = 0;
399 state_machine_regs.op_index = 0;
400 state_machine_regs.file = 1;
401 state_machine_regs.line = 1;
402 state_machine_regs.column = 0;
403 state_machine_regs.is_stmt = is_stmt;
404 state_machine_regs.basic_block = 0;
405 state_machine_regs.end_sequence = 0;
406 state_machine_regs.last_file_entry = 0;
409 /* Handled an extend line op.
410 Returns the number of bytes read. */
413 process_extended_line_op (unsigned char * data,
417 unsigned char op_code;
418 unsigned int bytes_read;
421 unsigned char *orig_data = data;
424 len = read_uleb128 (data, & bytes_read, end);
427 if (len == 0 || data == end || len > (uintptr_t) (end - data))
429 warn (_("Badly formed extended line op encountered!\n"));
436 printf (_(" Extended opcode %d: "), op_code);
440 case DW_LNE_end_sequence:
441 printf (_("End of Sequence\n\n"));
442 reset_state_machine (is_stmt);
445 case DW_LNE_set_address:
446 /* PR 17512: file: 002-100480-0.004. */
447 if (len - bytes_read - 1 > 8)
448 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
449 len - bytes_read - 1);
450 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
451 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
452 state_machine_regs.address = adr;
453 state_machine_regs.op_index = 0;
456 case DW_LNE_define_file:
457 printf (_("define new File Table entry\n"));
458 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
459 printf (" %d\t", ++state_machine_regs.last_file_entry);
462 data += strnlen ((char *) data, end - data) + 1;
463 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
465 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
467 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
469 printf ("%s\n\n", name);
471 if (((unsigned int) (data - orig_data) != len) || data == end)
472 warn (_("DW_LNE_define_file: Bad opcode length\n"));
475 case DW_LNE_set_discriminator:
476 printf (_("set Discriminator to %s\n"),
477 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
481 case DW_LNE_HP_negate_is_UV_update:
482 printf ("DW_LNE_HP_negate_is_UV_update\n");
484 case DW_LNE_HP_push_context:
485 printf ("DW_LNE_HP_push_context\n");
487 case DW_LNE_HP_pop_context:
488 printf ("DW_LNE_HP_pop_context\n");
490 case DW_LNE_HP_set_file_line_column:
491 printf ("DW_LNE_HP_set_file_line_column\n");
493 case DW_LNE_HP_set_routine_name:
494 printf ("DW_LNE_HP_set_routine_name\n");
496 case DW_LNE_HP_set_sequence:
497 printf ("DW_LNE_HP_set_sequence\n");
499 case DW_LNE_HP_negate_post_semantics:
500 printf ("DW_LNE_HP_negate_post_semantics\n");
502 case DW_LNE_HP_negate_function_exit:
503 printf ("DW_LNE_HP_negate_function_exit\n");
505 case DW_LNE_HP_negate_front_end_logical:
506 printf ("DW_LNE_HP_negate_front_end_logical\n");
508 case DW_LNE_HP_define_proc:
509 printf ("DW_LNE_HP_define_proc\n");
511 case DW_LNE_HP_source_file_correlation:
513 unsigned char *edata = data + len - bytes_read - 1;
515 printf ("DW_LNE_HP_source_file_correlation\n");
521 opc = read_uleb128 (data, & bytes_read, edata);
526 case DW_LNE_HP_SFC_formfeed:
527 printf (" DW_LNE_HP_SFC_formfeed\n");
529 case DW_LNE_HP_SFC_set_listing_line:
530 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
532 read_uleb128 (data, & bytes_read, edata)));
535 case DW_LNE_HP_SFC_associate:
536 printf (" DW_LNE_HP_SFC_associate ");
539 read_uleb128 (data, & bytes_read, edata)));
543 read_uleb128 (data, & bytes_read, edata)));
547 read_uleb128 (data, & bytes_read, edata)));
551 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
561 unsigned int rlen = len - bytes_read - 1;
563 if (op_code >= DW_LNE_lo_user
564 /* The test against DW_LNW_hi_user is redundant due to
565 the limited range of the unsigned char data type used
567 /*&& op_code <= DW_LNE_hi_user*/)
568 printf (_("user defined: "));
570 printf (_("UNKNOWN: "));
571 printf (_("length %d ["), rlen);
573 printf (" %02x", *data++);
582 static const unsigned char *
583 fetch_indirect_string (dwarf_vma offset)
585 struct dwarf_section *section = &debug_displays [str].section;
587 if (section->start == NULL)
588 return (const unsigned char *) _("<no .debug_str section>");
590 if (offset > section->size)
592 warn (_("DW_FORM_strp offset too big: %s\n"),
593 dwarf_vmatoa ("x", offset));
594 return (const unsigned char *) _("<offset is too big>");
597 return (const unsigned char *) section->start + offset;
601 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
602 dwarf_vma offset_size, int dwo)
604 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
605 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
606 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
607 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
608 dwarf_vma index_offset = idx * offset_size;
609 dwarf_vma str_offset;
611 if (index_section->start == NULL)
612 return (dwo ? _("<no .debug_str_offsets.dwo section>")
613 : _("<no .debug_str_offsets section>"));
615 if (this_set != NULL)
616 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
617 if (index_offset > index_section->size)
619 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
620 dwarf_vmatoa ("x", index_offset));
621 return _("<index offset is too big>");
624 if (str_section->start == NULL)
625 return (dwo ? _("<no .debug_str.dwo section>")
626 : _("<no .debug_str section>"));
628 str_offset = byte_get (index_section->start + index_offset, offset_size);
629 str_offset -= str_section->address;
630 if (str_offset > str_section->size)
632 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
633 dwarf_vmatoa ("x", str_offset));
634 return _("<indirect index offset is too big>");
637 return (const char *) str_section->start + str_offset;
641 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
643 struct dwarf_section *section = &debug_displays [debug_addr].section;
645 if (section->start == NULL)
646 return (_("<no .debug_addr section>"));
648 if (offset + bytes > section->size)
650 warn (_("Offset into section %s too big: %s\n"),
651 section->name, dwarf_vmatoa ("x", offset));
652 return "<offset too big>";
655 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
659 /* FIXME: There are better and more efficient ways to handle
660 these structures. For now though, I just want something that
661 is simple to implement. */
662 typedef struct abbrev_attr
664 unsigned long attribute;
666 struct abbrev_attr *next;
670 typedef struct abbrev_entry
675 struct abbrev_attr *first_attr;
676 struct abbrev_attr *last_attr;
677 struct abbrev_entry *next;
681 static abbrev_entry *first_abbrev = NULL;
682 static abbrev_entry *last_abbrev = NULL;
689 for (abbrv = first_abbrev; abbrv;)
691 abbrev_entry *next_abbrev = abbrv->next;
694 for (attr = abbrv->first_attr; attr;)
696 abbrev_attr *next_attr = attr->next;
706 last_abbrev = first_abbrev = NULL;
710 add_abbrev (unsigned long number, unsigned long tag, int children)
714 entry = (abbrev_entry *) malloc (sizeof (*entry));
719 entry->entry = number;
721 entry->children = children;
722 entry->first_attr = NULL;
723 entry->last_attr = NULL;
726 if (first_abbrev == NULL)
727 first_abbrev = entry;
729 last_abbrev->next = entry;
735 add_abbrev_attr (unsigned long attribute, unsigned long form)
739 attr = (abbrev_attr *) malloc (sizeof (*attr));
744 attr->attribute = attribute;
748 if (last_abbrev->first_attr == NULL)
749 last_abbrev->first_attr = attr;
751 last_abbrev->last_attr->next = attr;
753 last_abbrev->last_attr = attr;
756 /* Processes the (partial) contents of a .debug_abbrev section.
757 Returns NULL if the end of the section was encountered.
758 Returns the address after the last byte read if the end of
759 an abbreviation set was found. */
761 static unsigned char *
762 process_abbrev_section (unsigned char *start, unsigned char *end)
764 if (first_abbrev != NULL)
769 unsigned int bytes_read;
772 unsigned long attribute;
775 entry = read_uleb128 (start, & bytes_read, end);
778 /* A single zero is supposed to end the section according
779 to the standard. If there's more, then signal that to
786 tag = read_uleb128 (start, & bytes_read, end);
793 add_abbrev (entry, tag, children);
799 attribute = read_uleb128 (start, & bytes_read, end);
804 form = read_uleb128 (start, & bytes_read, end);
809 add_abbrev_attr (attribute, form);
811 while (attribute != 0);
814 /* Report the missing single zero which ends the section. */
815 error (_(".debug_abbrev section not zero terminated\n"));
821 get_TAG_name (unsigned long tag)
823 const char *name = get_DW_TAG_name ((unsigned int)tag);
827 static char buffer[100];
829 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
837 get_FORM_name (unsigned long form)
842 return "DW_FORM value: 0";
844 name = get_DW_FORM_name (form);
847 static char buffer[100];
849 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
856 static unsigned char *
857 display_block (unsigned char *data,
859 const unsigned char * const end)
863 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
865 return (unsigned char *) end;
867 maxlen = (dwarf_vma) (end - data);
868 length = length > maxlen ? maxlen : length;
871 printf ("%lx ", (unsigned long) byte_get (data++, 1));
877 decode_location_expression (unsigned char * data,
878 unsigned int pointer_size,
879 unsigned int offset_size,
883 struct dwarf_section * section)
886 unsigned int bytes_read;
888 dwarf_signed_vma svalue;
889 unsigned char *end = data + length;
890 int need_frame_base = 0;
899 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
900 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
903 printf ("DW_OP_deref");
906 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
907 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
910 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
911 printf ("DW_OP_const1s: %ld", (long) svalue);
914 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
915 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
918 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
919 printf ("DW_OP_const2s: %ld", (long) svalue);
922 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
923 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
926 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
927 printf ("DW_OP_const4s: %ld", (long) svalue);
930 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
931 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
932 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
933 printf ("%lu", (unsigned long) uvalue);
936 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
937 printf ("DW_OP_const8s: %ld ", (long) svalue);
938 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
939 printf ("%ld", (long) svalue);
942 printf ("DW_OP_constu: %s",
943 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
947 printf ("DW_OP_consts: %s",
948 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
952 printf ("DW_OP_dup");
955 printf ("DW_OP_drop");
958 printf ("DW_OP_over");
961 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
962 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
965 printf ("DW_OP_swap");
968 printf ("DW_OP_rot");
971 printf ("DW_OP_xderef");
974 printf ("DW_OP_abs");
977 printf ("DW_OP_and");
980 printf ("DW_OP_div");
983 printf ("DW_OP_minus");
986 printf ("DW_OP_mod");
989 printf ("DW_OP_mul");
992 printf ("DW_OP_neg");
995 printf ("DW_OP_not");
1001 printf ("DW_OP_plus");
1003 case DW_OP_plus_uconst:
1004 printf ("DW_OP_plus_uconst: %s",
1005 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1009 printf ("DW_OP_shl");
1012 printf ("DW_OP_shr");
1015 printf ("DW_OP_shra");
1018 printf ("DW_OP_xor");
1021 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1022 printf ("DW_OP_bra: %ld", (long) svalue);
1025 printf ("DW_OP_eq");
1028 printf ("DW_OP_ge");
1031 printf ("DW_OP_gt");
1034 printf ("DW_OP_le");
1037 printf ("DW_OP_lt");
1040 printf ("DW_OP_ne");
1043 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1044 printf ("DW_OP_skip: %ld", (long) svalue);
1079 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1114 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1115 regname (op - DW_OP_reg0, 1));
1150 printf ("DW_OP_breg%d (%s): %s",
1152 regname (op - DW_OP_breg0, 1),
1153 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1158 uvalue = read_uleb128 (data, &bytes_read, end);
1160 printf ("DW_OP_regx: %s (%s)",
1161 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1164 need_frame_base = 1;
1165 printf ("DW_OP_fbreg: %s",
1166 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1170 uvalue = read_uleb128 (data, &bytes_read, end);
1172 printf ("DW_OP_bregx: %s (%s) %s",
1173 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1174 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1178 printf ("DW_OP_piece: %s",
1179 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1182 case DW_OP_deref_size:
1183 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1184 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1186 case DW_OP_xderef_size:
1187 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1188 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1191 printf ("DW_OP_nop");
1194 /* DWARF 3 extensions. */
1195 case DW_OP_push_object_address:
1196 printf ("DW_OP_push_object_address");
1199 /* XXX: Strictly speaking for 64-bit DWARF3 files
1200 this ought to be an 8-byte wide computation. */
1201 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1202 printf ("DW_OP_call2: <0x%s>",
1203 dwarf_vmatoa ("x", svalue + cu_offset));
1206 /* XXX: Strictly speaking for 64-bit DWARF3 files
1207 this ought to be an 8-byte wide computation. */
1208 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1209 printf ("DW_OP_call4: <0x%s>",
1210 dwarf_vmatoa ("x", svalue + cu_offset));
1212 case DW_OP_call_ref:
1213 /* XXX: Strictly speaking for 64-bit DWARF3 files
1214 this ought to be an 8-byte wide computation. */
1215 if (dwarf_version == -1)
1217 printf (_("(DW_OP_call_ref in frame info)"));
1218 /* No way to tell where the next op is, so just bail. */
1219 return need_frame_base;
1221 if (dwarf_version == 2)
1223 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1227 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1229 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1231 case DW_OP_form_tls_address:
1232 printf ("DW_OP_form_tls_address");
1234 case DW_OP_call_frame_cfa:
1235 printf ("DW_OP_call_frame_cfa");
1237 case DW_OP_bit_piece:
1238 printf ("DW_OP_bit_piece: ");
1239 printf (_("size: %s "),
1240 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1242 printf (_("offset: %s "),
1243 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1247 /* DWARF 4 extensions. */
1248 case DW_OP_stack_value:
1249 printf ("DW_OP_stack_value");
1252 case DW_OP_implicit_value:
1253 printf ("DW_OP_implicit_value");
1254 uvalue = read_uleb128 (data, &bytes_read, end);
1256 data = display_block (data, uvalue, end);
1259 /* GNU extensions. */
1260 case DW_OP_GNU_push_tls_address:
1261 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1263 case DW_OP_GNU_uninit:
1264 printf ("DW_OP_GNU_uninit");
1265 /* FIXME: Is there data associated with this OP ? */
1267 case DW_OP_GNU_encoded_addr:
1274 addr = get_encoded_value (&data, encoding, section, end);
1276 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1277 print_dwarf_vma (addr, pointer_size);
1280 case DW_OP_GNU_implicit_pointer:
1281 /* XXX: Strictly speaking for 64-bit DWARF3 files
1282 this ought to be an 8-byte wide computation. */
1283 if (dwarf_version == -1)
1285 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1286 /* No way to tell where the next op is, so just bail. */
1287 return need_frame_base;
1289 if (dwarf_version == 2)
1291 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1295 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1297 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1298 dwarf_vmatoa ("x", uvalue),
1299 dwarf_vmatoa ("d", read_sleb128 (data,
1300 &bytes_read, end)));
1303 case DW_OP_GNU_entry_value:
1304 uvalue = read_uleb128 (data, &bytes_read, end);
1306 /* PR 17531: file: 0cc9cd00. */
1307 if (uvalue > (dwarf_vma) (end - data))
1308 uvalue = end - data;
1309 printf ("DW_OP_GNU_entry_value: (");
1310 if (decode_location_expression (data, pointer_size, offset_size,
1311 dwarf_version, uvalue,
1312 cu_offset, section))
1313 need_frame_base = 1;
1319 case DW_OP_GNU_const_type:
1320 uvalue = read_uleb128 (data, &bytes_read, end);
1322 printf ("DW_OP_GNU_const_type: <0x%s> ",
1323 dwarf_vmatoa ("x", cu_offset + uvalue));
1324 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1325 data = display_block (data, uvalue, end);
1327 case DW_OP_GNU_regval_type:
1328 uvalue = read_uleb128 (data, &bytes_read, end);
1330 printf ("DW_OP_GNU_regval_type: %s (%s)",
1331 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1332 uvalue = read_uleb128 (data, &bytes_read, end);
1334 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1336 case DW_OP_GNU_deref_type:
1337 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1338 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
1339 uvalue = read_uleb128 (data, &bytes_read, end);
1341 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1343 case DW_OP_GNU_convert:
1344 uvalue = read_uleb128 (data, &bytes_read, end);
1346 printf ("DW_OP_GNU_convert <0x%s>",
1347 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1349 case DW_OP_GNU_reinterpret:
1350 uvalue = read_uleb128 (data, &bytes_read, end);
1352 printf ("DW_OP_GNU_reinterpret <0x%s>",
1353 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1355 case DW_OP_GNU_parameter_ref:
1356 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1357 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1358 dwarf_vmatoa ("x", cu_offset + uvalue));
1360 case DW_OP_GNU_addr_index:
1361 uvalue = read_uleb128 (data, &bytes_read, end);
1363 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1365 case DW_OP_GNU_const_index:
1366 uvalue = read_uleb128 (data, &bytes_read, end);
1368 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1371 /* HP extensions. */
1372 case DW_OP_HP_is_value:
1373 printf ("DW_OP_HP_is_value");
1374 /* FIXME: Is there data associated with this OP ? */
1376 case DW_OP_HP_fltconst4:
1377 printf ("DW_OP_HP_fltconst4");
1378 /* FIXME: Is there data associated with this OP ? */
1380 case DW_OP_HP_fltconst8:
1381 printf ("DW_OP_HP_fltconst8");
1382 /* FIXME: Is there data associated with this OP ? */
1384 case DW_OP_HP_mod_range:
1385 printf ("DW_OP_HP_mod_range");
1386 /* FIXME: Is there data associated with this OP ? */
1388 case DW_OP_HP_unmod_range:
1389 printf ("DW_OP_HP_unmod_range");
1390 /* FIXME: Is there data associated with this OP ? */
1393 printf ("DW_OP_HP_tls");
1394 /* FIXME: Is there data associated with this OP ? */
1397 /* PGI (STMicroelectronics) extensions. */
1398 case DW_OP_PGI_omp_thread_num:
1399 /* Pushes the thread number for the current thread as it would be
1400 returned by the standard OpenMP library function:
1401 omp_get_thread_num(). The "current thread" is the thread for
1402 which the expression is being evaluated. */
1403 printf ("DW_OP_PGI_omp_thread_num");
1407 if (op >= DW_OP_lo_user
1408 && op <= DW_OP_hi_user)
1409 printf (_("(User defined location op)"));
1411 printf (_("(Unknown location op)"));
1412 /* No way to tell where the next op is, so just bail. */
1413 return need_frame_base;
1416 /* Separate the ops. */
1421 return need_frame_base;
1424 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1425 This is used for DWARF package files. */
1427 static struct cu_tu_set *
1428 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1430 struct cu_tu_set *p;
1432 unsigned int dw_sect;
1438 dw_sect = DW_SECT_TYPES;
1444 dw_sect = DW_SECT_INFO;
1448 if (p->section_offsets [dw_sect] == cu_offset)
1456 /* Add INC to HIGH_BITS:LOW_BITS. */
1458 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1460 dwarf_vma tmp = * low_bits;
1464 /* FIXME: There is probably a better way of handling this:
1466 We need to cope with dwarf_vma being a 32-bit or 64-bit
1467 type. Plus regardless of its size LOW_BITS is meant to
1468 only hold 32-bits, so if there is overflow or wrap around
1469 we must propagate into HIGH_BITS. */
1470 if (tmp < * low_bits)
1474 else if (sizeof (tmp) > 8
1484 static unsigned char *
1485 read_and_display_attr_value (unsigned long attribute,
1487 unsigned char * data,
1488 unsigned char * end,
1489 dwarf_vma cu_offset,
1490 dwarf_vma pointer_size,
1491 dwarf_vma offset_size,
1493 debug_info * debug_info_p,
1495 struct dwarf_section * section,
1496 struct cu_tu_set * this_set)
1498 dwarf_vma uvalue = 0;
1499 unsigned char *block_start = NULL;
1500 unsigned char * orig_data = data;
1501 unsigned int bytes_read;
1503 if (data > end || (data == end && form != DW_FORM_flag_present))
1505 warn (_("Corrupt attribute\n"));
1514 case DW_FORM_ref_addr:
1515 if (dwarf_version == 2)
1516 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1517 else if (dwarf_version == 3 || dwarf_version == 4)
1518 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1520 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1525 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1529 case DW_FORM_sec_offset:
1530 case DW_FORM_GNU_ref_alt:
1531 case DW_FORM_GNU_strp_alt:
1532 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1535 case DW_FORM_flag_present:
1542 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1547 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1552 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1556 uvalue = read_sleb128 (data, & bytes_read, end);
1560 case DW_FORM_GNU_str_index:
1561 uvalue = read_uleb128 (data, & bytes_read, end);
1565 case DW_FORM_ref_udata:
1567 uvalue = read_uleb128 (data, & bytes_read, end);
1571 case DW_FORM_indirect:
1572 form = read_uleb128 (data, & bytes_read, end);
1575 printf (" %s", get_FORM_name (form));
1576 return read_and_display_attr_value (attribute, form, data, end,
1577 cu_offset, pointer_size,
1578 offset_size, dwarf_version,
1579 debug_info_p, do_loc,
1581 case DW_FORM_GNU_addr_index:
1582 uvalue = read_uleb128 (data, & bytes_read, end);
1589 case DW_FORM_ref_addr:
1591 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1594 case DW_FORM_GNU_ref_alt:
1596 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1602 case DW_FORM_ref_udata:
1604 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1609 case DW_FORM_sec_offset:
1611 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1614 case DW_FORM_flag_present:
1621 printf (" %s", dwarf_vmatoa ("d", uvalue));
1628 dwarf_vma high_bits;
1632 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1634 if (form == DW_FORM_ref8)
1635 add64 (& high_bits, & utmp, cu_offset);
1637 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1640 if ((do_loc || do_debug_loc || do_debug_ranges)
1641 && num_debug_info_entries == 0)
1643 if (sizeof (uvalue) == 8)
1644 SAFE_BYTE_GET (uvalue, data, 8, end);
1646 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1652 case DW_FORM_string:
1654 printf (" %.*s", (int) (end - data), data);
1655 data += strnlen ((char *) data, end - data) + 1;
1659 case DW_FORM_exprloc:
1660 uvalue = read_uleb128 (data, & bytes_read, end);
1661 block_start = data + bytes_read;
1662 if (block_start >= end)
1664 warn (_("Block ends prematurely\n"));
1668 /* PR 17512: file: 008-103549-0.001:0.1. */
1669 if (block_start + uvalue > end)
1671 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1672 uvalue = end - block_start;
1675 data = block_start + uvalue;
1677 data = display_block (block_start, uvalue, end);
1680 case DW_FORM_block1:
1681 SAFE_BYTE_GET (uvalue, data, 1, end);
1682 block_start = data + 1;
1683 if (block_start >= end)
1685 warn (_("Block ends prematurely\n"));
1689 if (block_start + uvalue > end)
1691 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1692 uvalue = end - block_start;
1695 data = block_start + uvalue;
1697 data = display_block (block_start, uvalue, end);
1700 case DW_FORM_block2:
1701 SAFE_BYTE_GET (uvalue, data, 2, end);
1702 block_start = data + 2;
1703 if (block_start >= end)
1705 warn (_("Block ends prematurely\n"));
1709 if (block_start + uvalue > end)
1711 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1712 uvalue = end - block_start;
1715 data = block_start + uvalue;
1717 data = display_block (block_start, uvalue, end);
1720 case DW_FORM_block4:
1721 SAFE_BYTE_GET (uvalue, data, 4, end);
1722 block_start = data + 4;
1723 /* PR 17512: file: 3371-3907-0.004. */
1724 if (block_start >= end)
1726 warn (_("Block ends prematurely\n"));
1730 if (block_start + uvalue > end)
1732 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1733 uvalue = end - block_start;
1736 data = block_start + uvalue;
1738 data = display_block (block_start, uvalue, end);
1743 printf (_(" (indirect string, offset: 0x%s): %s"),
1744 dwarf_vmatoa ("x", uvalue),
1745 fetch_indirect_string (uvalue));
1748 case DW_FORM_GNU_str_index:
1751 const char *suffix = strrchr (section->name, '.');
1752 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1754 printf (_(" (indexed string: 0x%s): %s"),
1755 dwarf_vmatoa ("x", uvalue),
1756 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1760 case DW_FORM_GNU_strp_alt:
1762 printf (_(" (alt indirect string, offset: 0x%s)"),
1763 dwarf_vmatoa ("x", uvalue));
1766 case DW_FORM_indirect:
1767 /* Handled above. */
1770 case DW_FORM_ref_sig8:
1773 dwarf_vma high_bits;
1776 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1777 printf (" signature: 0x%s",
1778 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1783 case DW_FORM_GNU_addr_index:
1785 printf (_(" (addr_index: 0x%s): %s"),
1786 dwarf_vmatoa ("x", uvalue),
1787 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1791 warn (_("Unrecognized form: %lu\n"), form);
1795 if ((do_loc || do_debug_loc || do_debug_ranges)
1796 && num_debug_info_entries == 0
1797 && debug_info_p != NULL)
1801 case DW_AT_frame_base:
1802 have_frame_base = 1;
1803 case DW_AT_location:
1804 case DW_AT_string_length:
1805 case DW_AT_return_addr:
1806 case DW_AT_data_member_location:
1807 case DW_AT_vtable_elem_location:
1809 case DW_AT_static_link:
1810 case DW_AT_use_location:
1811 case DW_AT_GNU_call_site_value:
1812 case DW_AT_GNU_call_site_data_value:
1813 case DW_AT_GNU_call_site_target:
1814 case DW_AT_GNU_call_site_target_clobbered:
1815 if ((dwarf_version < 4
1816 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1817 || form == DW_FORM_sec_offset)
1819 /* Process location list. */
1820 unsigned int lmax = debug_info_p->max_loc_offsets;
1821 unsigned int num = debug_info_p->num_loc_offsets;
1823 if (lmax == 0 || num >= lmax)
1826 debug_info_p->loc_offsets = (dwarf_vma *)
1827 xcrealloc (debug_info_p->loc_offsets,
1828 lmax, sizeof (*debug_info_p->loc_offsets));
1829 debug_info_p->have_frame_base = (int *)
1830 xcrealloc (debug_info_p->have_frame_base,
1831 lmax, sizeof (*debug_info_p->have_frame_base));
1832 debug_info_p->max_loc_offsets = lmax;
1834 if (this_set != NULL)
1835 uvalue += this_set->section_offsets [DW_SECT_LOC];
1836 debug_info_p->loc_offsets [num] = uvalue;
1837 debug_info_p->have_frame_base [num] = have_frame_base;
1838 debug_info_p->num_loc_offsets++;
1843 if (need_base_address)
1844 debug_info_p->base_address = uvalue;
1847 case DW_AT_GNU_addr_base:
1848 debug_info_p->addr_base = uvalue;
1851 case DW_AT_GNU_ranges_base:
1852 debug_info_p->ranges_base = uvalue;
1856 if ((dwarf_version < 4
1857 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1858 || form == DW_FORM_sec_offset)
1860 /* Process range list. */
1861 unsigned int lmax = debug_info_p->max_range_lists;
1862 unsigned int num = debug_info_p->num_range_lists;
1864 if (lmax == 0 || num >= lmax)
1867 debug_info_p->range_lists = (dwarf_vma *)
1868 xcrealloc (debug_info_p->range_lists,
1869 lmax, sizeof (*debug_info_p->range_lists));
1870 debug_info_p->max_range_lists = lmax;
1872 debug_info_p->range_lists [num] = uvalue;
1873 debug_info_p->num_range_lists++;
1882 if (do_loc || attribute == 0)
1885 /* For some attributes we can display further information. */
1892 case DW_INL_not_inlined:
1893 printf (_("(not inlined)"));
1895 case DW_INL_inlined:
1896 printf (_("(inlined)"));
1898 case DW_INL_declared_not_inlined:
1899 printf (_("(declared as inline but ignored)"));
1901 case DW_INL_declared_inlined:
1902 printf (_("(declared as inline and inlined)"));
1905 printf (_(" (Unknown inline attribute value: %s)"),
1906 dwarf_vmatoa ("x", uvalue));
1911 case DW_AT_language:
1915 /* Ordered by the numeric value of these constants. */
1916 case DW_LANG_C89: printf ("(ANSI C)"); break;
1917 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1918 case DW_LANG_Ada83: printf ("(Ada)"); break;
1919 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1920 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1921 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1922 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1923 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1924 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1925 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1926 /* DWARF 2.1 values. */
1927 case DW_LANG_Java: printf ("(Java)"); break;
1928 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1929 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1930 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1931 /* DWARF 3 values. */
1932 case DW_LANG_PLI: printf ("(PLI)"); break;
1933 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1934 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1935 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1936 case DW_LANG_D: printf ("(D)"); break;
1937 /* DWARF 4 values. */
1938 case DW_LANG_Python: printf ("(Python)"); break;
1939 /* DWARF 5 values. */
1940 case DW_LANG_Go: printf ("(Go)"); break;
1941 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
1942 case DW_LANG_C11: printf ("(C11)"); break;
1943 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
1944 /* MIPS extension. */
1945 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1946 /* UPC extension. */
1947 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1949 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1950 printf (_("(implementation defined: %s)"),
1951 dwarf_vmatoa ("x", uvalue));
1953 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1958 case DW_AT_encoding:
1962 case DW_ATE_void: printf ("(void)"); break;
1963 case DW_ATE_address: printf ("(machine address)"); break;
1964 case DW_ATE_boolean: printf ("(boolean)"); break;
1965 case DW_ATE_complex_float: printf ("(complex float)"); break;
1966 case DW_ATE_float: printf ("(float)"); break;
1967 case DW_ATE_signed: printf ("(signed)"); break;
1968 case DW_ATE_signed_char: printf ("(signed char)"); break;
1969 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1970 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1971 /* DWARF 2.1 values: */
1972 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1973 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1974 /* DWARF 3 values: */
1975 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1976 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1977 case DW_ATE_edited: printf ("(edited)"); break;
1978 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1979 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1980 /* HP extensions: */
1981 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1982 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1983 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1984 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1985 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1986 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1987 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1990 if (uvalue >= DW_ATE_lo_user
1991 && uvalue <= DW_ATE_hi_user)
1992 printf (_("(user defined type)"));
1994 printf (_("(unknown type)"));
1999 case DW_AT_accessibility:
2003 case DW_ACCESS_public: printf ("(public)"); break;
2004 case DW_ACCESS_protected: printf ("(protected)"); break;
2005 case DW_ACCESS_private: printf ("(private)"); break;
2007 printf (_("(unknown accessibility)"));
2012 case DW_AT_visibility:
2016 case DW_VIS_local: printf ("(local)"); break;
2017 case DW_VIS_exported: printf ("(exported)"); break;
2018 case DW_VIS_qualified: printf ("(qualified)"); break;
2019 default: printf (_("(unknown visibility)")); break;
2023 case DW_AT_virtuality:
2027 case DW_VIRTUALITY_none: printf ("(none)"); break;
2028 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2029 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2030 default: printf (_("(unknown virtuality)")); break;
2034 case DW_AT_identifier_case:
2038 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2039 case DW_ID_up_case: printf ("(up_case)"); break;
2040 case DW_ID_down_case: printf ("(down_case)"); break;
2041 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2042 default: printf (_("(unknown case)")); break;
2046 case DW_AT_calling_convention:
2050 case DW_CC_normal: printf ("(normal)"); break;
2051 case DW_CC_program: printf ("(program)"); break;
2052 case DW_CC_nocall: printf ("(nocall)"); break;
2054 if (uvalue >= DW_CC_lo_user
2055 && uvalue <= DW_CC_hi_user)
2056 printf (_("(user defined)"));
2058 printf (_("(unknown convention)"));
2062 case DW_AT_ordering:
2066 case -1: printf (_("(undefined)")); break;
2067 case 0: printf ("(row major)"); break;
2068 case 1: printf ("(column major)"); break;
2072 case DW_AT_frame_base:
2073 have_frame_base = 1;
2074 case DW_AT_location:
2075 case DW_AT_string_length:
2076 case DW_AT_return_addr:
2077 case DW_AT_data_member_location:
2078 case DW_AT_vtable_elem_location:
2080 case DW_AT_static_link:
2081 case DW_AT_use_location:
2082 case DW_AT_GNU_call_site_value:
2083 case DW_AT_GNU_call_site_data_value:
2084 case DW_AT_GNU_call_site_target:
2085 case DW_AT_GNU_call_site_target_clobbered:
2086 if ((dwarf_version < 4
2087 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2088 || form == DW_FORM_sec_offset)
2089 printf (_(" (location list)"));
2091 case DW_AT_allocated:
2092 case DW_AT_associated:
2093 case DW_AT_data_location:
2095 case DW_AT_upper_bound:
2096 case DW_AT_lower_bound:
2099 int need_frame_base;
2102 need_frame_base = decode_location_expression (block_start,
2107 cu_offset, section);
2109 if (need_frame_base && !have_frame_base)
2110 printf (_(" [without DW_AT_frame_base]"));
2116 if (form == DW_FORM_ref_sig8
2117 || form == DW_FORM_GNU_ref_alt)
2120 if (form == DW_FORM_ref1
2121 || form == DW_FORM_ref2
2122 || form == DW_FORM_ref4
2123 || form == DW_FORM_ref_udata)
2124 uvalue += cu_offset;
2126 if (uvalue >= section->size)
2127 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2128 dwarf_vmatoa ("x", uvalue),
2129 (unsigned long) (orig_data - section->start));
2132 unsigned long abbrev_number;
2133 abbrev_entry * entry;
2135 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2137 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2138 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2139 use different abbrev table, and we don't track .debug_info chunks
2141 if (form != DW_FORM_ref_addr)
2143 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2144 if (entry->entry == abbrev_number)
2147 printf (" (%s)", get_TAG_name (entry->tag));
2162 get_AT_name (unsigned long attribute)
2167 return "DW_AT value: 0";
2169 /* One value is shared by the MIPS and HP extensions: */
2170 if (attribute == DW_AT_MIPS_fde)
2171 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2173 name = get_DW_AT_name (attribute);
2177 static char buffer[100];
2179 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2187 static unsigned char *
2188 read_and_display_attr (unsigned long attribute,
2190 unsigned char * data,
2191 unsigned char * end,
2192 dwarf_vma cu_offset,
2193 dwarf_vma pointer_size,
2194 dwarf_vma offset_size,
2196 debug_info * debug_info_p,
2198 struct dwarf_section * section,
2199 struct cu_tu_set * this_set)
2202 printf (" %-18s:", get_AT_name (attribute));
2203 data = read_and_display_attr_value (attribute, form, data, end,
2204 cu_offset, pointer_size, offset_size,
2205 dwarf_version, debug_info_p,
2206 do_loc, section, this_set);
2212 /* Process the contents of a .debug_info section. If do_loc is non-zero
2213 then we are scanning for location lists and we do not want to display
2214 anything to the user. If do_types is non-zero, we are processing
2215 a .debug_types section instead of a .debug_info section. */
2218 process_debug_info (struct dwarf_section *section,
2220 enum dwarf_section_display_enum abbrev_sec,
2224 unsigned char *start = section->start;
2225 unsigned char *end = start + section->size;
2226 unsigned char *section_begin;
2228 unsigned int num_units = 0;
2230 if ((do_loc || do_debug_loc || do_debug_ranges)
2231 && num_debug_info_entries == 0
2236 /* First scan the section to get the number of comp units. */
2237 for (section_begin = start, num_units = 0; section_begin < end;
2240 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2241 will be the length. For a 64-bit DWARF section, it'll be
2242 the escape code 0xffffffff followed by an 8 byte length. */
2243 SAFE_BYTE_GET (length, section_begin, 4, end);
2245 if (length == 0xffffffff)
2247 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2248 section_begin += length + 12;
2250 else if (length >= 0xfffffff0 && length < 0xffffffff)
2252 warn (_("Reserved length value (0x%s) found in section %s\n"),
2253 dwarf_vmatoa ("x", length), section->name);
2257 section_begin += length + 4;
2259 /* Negative values are illegal, they may even cause infinite
2260 looping. This can happen if we can't accurately apply
2261 relocations to an object file. */
2262 if ((signed long) length <= 0)
2264 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2265 dwarf_vmatoa ("x", length), section->name);
2272 error (_("No comp units in %s section ?\n"), section->name);
2276 /* Then allocate an array to hold the information. */
2277 debug_information = (debug_info *) cmalloc (num_units,
2278 sizeof (* debug_information));
2279 if (debug_information == NULL)
2281 error (_("Not enough memory for a debug info array of %u entries\n"),
2289 if (dwarf_start_die == 0)
2290 printf (_("Contents of the %s section:\n\n"), section->name);
2292 load_debug_section (str, file);
2293 load_debug_section (str_dwo, file);
2294 load_debug_section (str_index, file);
2295 load_debug_section (str_index_dwo, file);
2296 load_debug_section (debug_addr, file);
2299 load_debug_section (abbrev_sec, file);
2300 if (debug_displays [abbrev_sec].section.start == NULL)
2302 warn (_("Unable to locate %s section!\n"),
2303 debug_displays [abbrev_sec].section.name);
2307 for (section_begin = start, unit = 0; start < end; unit++)
2309 DWARF2_Internal_CompUnit compunit;
2310 unsigned char *hdrptr;
2311 unsigned char *tags;
2312 int level, last_level, saved_level;
2313 dwarf_vma cu_offset;
2314 unsigned int offset_size;
2315 int initial_length_size;
2316 dwarf_vma signature_high = 0;
2317 dwarf_vma signature_low = 0;
2318 dwarf_vma type_offset = 0;
2319 struct cu_tu_set *this_set;
2320 dwarf_vma abbrev_base;
2325 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2327 if (compunit.cu_length == 0xffffffff)
2329 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2331 initial_length_size = 12;
2336 initial_length_size = 4;
2339 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2341 cu_offset = start - section_begin;
2343 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2345 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2347 if (this_set == NULL)
2350 abbrev_size = debug_displays [abbrev_sec].section.size;
2354 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2355 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2358 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2359 /* PR 17512: file: 001-108546-0.001:0.1. */
2360 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2362 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2363 compunit.cu_pointer_size, offset_size);
2364 compunit.cu_pointer_size = offset_size;
2369 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2371 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2374 if ((do_loc || do_debug_loc || do_debug_ranges)
2375 && num_debug_info_entries == 0
2378 debug_information [unit].cu_offset = cu_offset;
2379 debug_information [unit].pointer_size
2380 = compunit.cu_pointer_size;
2381 debug_information [unit].offset_size = offset_size;
2382 debug_information [unit].dwarf_version = compunit.cu_version;
2383 debug_information [unit].base_address = 0;
2384 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2385 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2386 debug_information [unit].loc_offsets = NULL;
2387 debug_information [unit].have_frame_base = NULL;
2388 debug_information [unit].max_loc_offsets = 0;
2389 debug_information [unit].num_loc_offsets = 0;
2390 debug_information [unit].range_lists = NULL;
2391 debug_information [unit].max_range_lists= 0;
2392 debug_information [unit].num_range_lists = 0;
2395 if (!do_loc && dwarf_start_die == 0)
2397 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2398 dwarf_vmatoa ("x", cu_offset));
2399 printf (_(" Length: 0x%s (%s)\n"),
2400 dwarf_vmatoa ("x", compunit.cu_length),
2401 offset_size == 8 ? "64-bit" : "32-bit");
2402 printf (_(" Version: %d\n"), compunit.cu_version);
2403 printf (_(" Abbrev Offset: 0x%s\n"),
2404 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2405 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2410 printf (_(" Signature: 0x%s\n"),
2411 dwarf_vmatoa64 (signature_high, signature_low,
2412 buf, sizeof (buf)));
2413 printf (_(" Type Offset: 0x%s\n"),
2414 dwarf_vmatoa ("x", type_offset));
2416 if (this_set != NULL)
2418 dwarf_vma *offsets = this_set->section_offsets;
2419 size_t *sizes = this_set->section_sizes;
2421 printf (_(" Section contributions:\n"));
2422 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2423 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2424 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2425 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2426 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2427 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2428 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2429 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2430 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2431 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2432 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2433 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2437 if (cu_offset + compunit.cu_length + initial_length_size
2440 warn (_("Debug info is corrupted, length of CU at %s"
2441 " extends beyond end of section (length = %s)\n"),
2442 dwarf_vmatoa ("x", cu_offset),
2443 dwarf_vmatoa ("x", compunit.cu_length));
2447 start += compunit.cu_length + initial_length_size;
2449 if (compunit.cu_version != 2
2450 && compunit.cu_version != 3
2451 && compunit.cu_version != 4)
2453 warn (_("CU at offset %s contains corrupt or "
2454 "unsupported version number: %d.\n"),
2455 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2461 /* Process the abbrevs used by this compilation unit. */
2462 if (compunit.cu_abbrev_offset >= abbrev_size)
2463 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2464 (unsigned long) compunit.cu_abbrev_offset,
2465 (unsigned long) abbrev_size);
2467 process_abbrev_section
2468 (((unsigned char *) debug_displays [abbrev_sec].section.start
2469 + abbrev_base + compunit.cu_abbrev_offset),
2470 ((unsigned char *) debug_displays [abbrev_sec].section.start
2471 + abbrev_base + abbrev_size));
2476 while (tags < start)
2478 unsigned int bytes_read;
2479 unsigned long abbrev_number;
2480 unsigned long die_offset;
2481 abbrev_entry *entry;
2483 int do_printing = 1;
2485 die_offset = tags - section_begin;
2487 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2490 /* A null DIE marks the end of a list of siblings or it may also be
2491 a section padding. */
2492 if (abbrev_number == 0)
2494 /* Check if it can be a section padding for the last CU. */
2495 if (level == 0 && start == end)
2499 for (chk = tags; chk < start; chk++)
2506 if (!do_loc && die_offset >= dwarf_start_die
2507 && (dwarf_cutoff_level == -1
2508 || level < dwarf_cutoff_level))
2509 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2515 static unsigned num_bogus_warns = 0;
2517 if (num_bogus_warns < 3)
2519 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2520 die_offset, section->name);
2522 if (num_bogus_warns == 3)
2523 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2526 if (dwarf_start_die != 0 && level < saved_level)
2533 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2537 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2538 saved_level = level;
2539 do_printing = (dwarf_cutoff_level == -1
2540 || level < dwarf_cutoff_level);
2542 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2543 level, die_offset, abbrev_number);
2544 else if (dwarf_cutoff_level == -1
2545 || last_level < dwarf_cutoff_level)
2546 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2551 /* Scan through the abbreviation list until we reach the
2553 for (entry = first_abbrev;
2554 entry && entry->entry != abbrev_number;
2555 entry = entry->next)
2560 if (!do_loc && do_printing)
2565 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2566 die_offset, abbrev_number);
2570 if (!do_loc && do_printing)
2571 printf (" (%s)\n", get_TAG_name (entry->tag));
2576 need_base_address = 0;
2578 case DW_TAG_compile_unit:
2579 need_base_address = 1;
2581 case DW_TAG_entry_point:
2582 case DW_TAG_subprogram:
2583 need_base_address = 0;
2584 /* Assuming that there is no DW_AT_frame_base. */
2585 have_frame_base = 0;
2589 for (attr = entry->first_attr;
2590 attr && attr->attribute;
2595 if (! do_loc && do_printing)
2596 /* Show the offset from where the tag was extracted. */
2597 printf (" <%lx>", (unsigned long)(tags - section_begin));
2599 arg = debug_information;
2600 if (debug_information)
2603 tags = read_and_display_attr (attr->attribute,
2608 compunit.cu_pointer_size,
2610 compunit.cu_version,
2612 do_loc || ! do_printing,
2617 if (entry->children)
2622 /* Set num_debug_info_entries here so that it can be used to check if
2623 we need to process .debug_loc and .debug_ranges sections. */
2624 if ((do_loc || do_debug_loc || do_debug_ranges)
2625 && num_debug_info_entries == 0
2627 num_debug_info_entries = num_units;
2635 /* Locate and scan the .debug_info section in the file and record the pointer
2636 sizes and offsets for the compilation units in it. Usually an executable
2637 will have just one pointer size, but this is not guaranteed, and so we try
2638 not to make any assumptions. Returns zero upon failure, or the number of
2639 compilation units upon success. */
2642 load_debug_info (void * file)
2644 /* Reset the last pointer size so that we can issue correct error
2645 messages if we are displaying the contents of more than one section. */
2646 last_pointer_size = 0;
2647 warned_about_missing_comp_units = FALSE;
2649 /* If we have already tried and failed to load the .debug_info
2650 section then do not bother to repeat the task. */
2651 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2654 /* If we already have the information there is nothing else to do. */
2655 if (num_debug_info_entries > 0)
2656 return num_debug_info_entries;
2658 /* If this is a DWARF package file, load the CU and TU indexes. */
2659 load_cu_tu_indexes (file);
2661 if (load_debug_section (info, file)
2662 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2663 return num_debug_info_entries;
2664 else if (load_debug_section (info_dwo, file)
2665 && process_debug_info (&debug_displays [info_dwo].section, file,
2667 return num_debug_info_entries;
2669 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2673 /* Read a DWARF .debug_line section header starting at DATA.
2674 Upon success returns an updated DATA pointer and the LINFO
2675 structure and the END_OF_SEQUENCE pointer will be filled in.
2676 Otherwise returns NULL. */
2678 static unsigned char *
2679 read_debug_line_header (struct dwarf_section * section,
2680 unsigned char * data,
2681 unsigned char * end,
2682 DWARF2_Internal_LineInfo * linfo,
2683 unsigned char ** end_of_sequence)
2685 unsigned char *hdrptr;
2686 unsigned int offset_size;
2687 unsigned int initial_length_size;
2689 /* Extract information from the Line Number Program Header.
2690 (section 6.2.4 in the Dwarf3 doc). */
2693 /* Get and check the length of the block. */
2694 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2696 if (linfo->li_length == 0xffffffff)
2698 /* This section is 64-bit DWARF 3. */
2699 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2701 initial_length_size = 12;
2706 initial_length_size = 4;
2709 if (linfo->li_length + initial_length_size > section->size)
2711 /* If the length is just a bias against the initial_length_size then
2712 this means that the field has a relocation against it which has not
2713 been applied. (Ie we are dealing with an object file, not a linked
2714 binary). Do not complain but instead assume that the rest of the
2715 section applies to this particular header. */
2716 if (linfo->li_length == - initial_length_size)
2718 linfo->li_length = section->size - initial_length_size;
2722 warn (_("The line info appears to be corrupt - the section is too small\n"));
2727 /* Get and check the version number. */
2728 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2730 if (linfo->li_version != 2
2731 && linfo->li_version != 3
2732 && linfo->li_version != 4)
2734 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2738 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2739 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2741 if (linfo->li_version >= 4)
2743 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2745 if (linfo->li_max_ops_per_insn == 0)
2747 warn (_("Invalid maximum operations per insn.\n"));
2752 linfo->li_max_ops_per_insn = 1;
2754 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2755 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2756 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2757 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2759 * end_of_sequence = data + linfo->li_length + initial_length_size;
2760 /* PR 17512: file:002-117414-0.004. */
2761 if (* end_of_sequence > end)
2763 warn (_("Line length %s extends beyond end of section\n"),
2764 dwarf_vmatoa ("u", linfo->li_length));
2765 * end_of_sequence = end;
2773 display_debug_lines_raw (struct dwarf_section *section,
2774 unsigned char *data,
2777 unsigned char *start = section->start;
2779 printf (_("Raw dump of debug contents of section %s:\n\n"),
2784 static DWARF2_Internal_LineInfo saved_linfo;
2785 DWARF2_Internal_LineInfo linfo;
2786 unsigned char *standard_opcodes;
2787 unsigned char *end_of_sequence;
2788 unsigned int last_dir_entry = 0;
2791 if (const_strneq (section->name, ".debug_line.")
2792 /* Note: the following does not apply to .debug_line.dwo sections.
2793 These are full debug_line sections. */
2794 && strcmp (section->name, ".debug_line.dwo") != 0)
2796 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2797 section containing just the Line Number Statements. They are
2798 created by the assembler and intended to be used alongside gcc's
2799 -ffunction-sections command line option. When the linker's
2800 garbage collection decides to discard a .text.<foo> section it
2801 can then also discard the line number information in .debug_line.<foo>.
2803 Since the section is a fragment it does not have the details
2804 needed to fill out a LineInfo structure, so instead we use the
2805 details from the last full debug_line section that we processed. */
2806 end_of_sequence = end;
2807 standard_opcodes = NULL;
2808 linfo = saved_linfo;
2809 /* PR 17531: file: 0522b371. */
2810 if (linfo.li_line_range == 0)
2812 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section"));
2815 reset_state_machine (linfo.li_default_is_stmt);
2819 unsigned char * hdrptr;
2821 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2822 & end_of_sequence)) == NULL)
2825 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2826 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2827 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2828 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2829 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2830 if (linfo.li_version >= 4)
2831 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2832 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2833 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2834 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2835 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2837 /* PR 17512: file: 1665-6428-0.004. */
2838 if (linfo.li_line_range == 0)
2840 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2841 linfo.li_line_range = 1;
2844 reset_state_machine (linfo.li_default_is_stmt);
2846 /* Display the contents of the Opcodes table. */
2847 standard_opcodes = hdrptr;
2849 /* PR 17512: file: 002-417945-0.004. */
2850 if (standard_opcodes + linfo.li_opcode_base >= end)
2852 warn (_("Line Base extends beyond end of section\n"));
2856 printf (_("\n Opcodes:\n"));
2858 for (i = 1; i < linfo.li_opcode_base; i++)
2859 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2861 /* Display the contents of the Directory table. */
2862 data = standard_opcodes + linfo.li_opcode_base - 1;
2865 printf (_("\n The Directory Table is empty.\n"));
2868 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2869 (long)(data - start));
2871 while (data < end && *data != 0)
2873 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
2875 data += strnlen ((char *) data, end - data) + 1;
2878 /* PR 17512: file: 002-132094-0.004. */
2879 if (data >= end - 1)
2883 /* Skip the NUL at the end of the table. */
2886 /* Display the contents of the File Name table. */
2888 printf (_("\n The File Name Table is empty.\n"));
2891 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2892 (long)(data - start));
2893 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2895 while (data < end && *data != 0)
2897 unsigned char *name;
2898 unsigned int bytes_read;
2900 printf (" %d\t", ++state_machine_regs.last_file_entry);
2902 data += strnlen ((char *) data, end - data) + 1;
2905 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2908 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2911 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2913 printf ("%.*s\n", (int)(end - name), name);
2917 warn (_("Corrupt file name table entry\n"));
2923 /* Skip the NUL at the end of the table. */
2926 saved_linfo = linfo;
2929 /* Now display the statements. */
2930 if (data >= end_of_sequence)
2931 printf (_(" No Line Number Statements.\n"));
2934 printf (_(" Line Number Statements:\n"));
2936 while (data < end_of_sequence)
2938 unsigned char op_code;
2939 dwarf_signed_vma adv;
2941 unsigned int bytes_read;
2943 printf (" [0x%08lx]", (long)(data - start));
2947 if (op_code >= linfo.li_opcode_base)
2949 op_code -= linfo.li_opcode_base;
2950 uladv = (op_code / linfo.li_line_range);
2951 if (linfo.li_max_ops_per_insn == 1)
2953 uladv *= linfo.li_min_insn_length;
2954 state_machine_regs.address += uladv;
2955 printf (_(" Special opcode %d: "
2956 "advance Address by %s to 0x%s"),
2957 op_code, dwarf_vmatoa ("u", uladv),
2958 dwarf_vmatoa ("x", state_machine_regs.address));
2962 state_machine_regs.address
2963 += ((state_machine_regs.op_index + uladv)
2964 / linfo.li_max_ops_per_insn)
2965 * linfo.li_min_insn_length;
2966 state_machine_regs.op_index
2967 = (state_machine_regs.op_index + uladv)
2968 % linfo.li_max_ops_per_insn;
2969 printf (_(" Special opcode %d: "
2970 "advance Address by %s to 0x%s[%d]"),
2971 op_code, dwarf_vmatoa ("u", uladv),
2972 dwarf_vmatoa ("x", state_machine_regs.address),
2973 state_machine_regs.op_index);
2975 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2976 state_machine_regs.line += adv;
2977 printf (_(" and Line by %s to %d\n"),
2978 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2980 else switch (op_code)
2982 case DW_LNS_extended_op:
2983 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
2987 printf (_(" Copy\n"));
2990 case DW_LNS_advance_pc:
2991 uladv = read_uleb128 (data, & bytes_read, end);
2993 if (linfo.li_max_ops_per_insn == 1)
2995 uladv *= linfo.li_min_insn_length;
2996 state_machine_regs.address += uladv;
2997 printf (_(" Advance PC by %s to 0x%s\n"),
2998 dwarf_vmatoa ("u", uladv),
2999 dwarf_vmatoa ("x", state_machine_regs.address));
3003 state_machine_regs.address
3004 += ((state_machine_regs.op_index + uladv)
3005 / linfo.li_max_ops_per_insn)
3006 * linfo.li_min_insn_length;
3007 state_machine_regs.op_index
3008 = (state_machine_regs.op_index + uladv)
3009 % linfo.li_max_ops_per_insn;
3010 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3011 dwarf_vmatoa ("u", uladv),
3012 dwarf_vmatoa ("x", state_machine_regs.address),
3013 state_machine_regs.op_index);
3017 case DW_LNS_advance_line:
3018 adv = read_sleb128 (data, & bytes_read, end);
3020 state_machine_regs.line += adv;
3021 printf (_(" Advance Line by %s to %d\n"),
3022 dwarf_vmatoa ("d", adv),
3023 state_machine_regs.line);
3026 case DW_LNS_set_file:
3027 adv = read_uleb128 (data, & bytes_read, end);
3029 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3030 dwarf_vmatoa ("d", adv));
3031 state_machine_regs.file = adv;
3034 case DW_LNS_set_column:
3035 uladv = read_uleb128 (data, & bytes_read, end);
3037 printf (_(" Set column to %s\n"),
3038 dwarf_vmatoa ("u", uladv));
3039 state_machine_regs.column = uladv;
3042 case DW_LNS_negate_stmt:
3043 adv = state_machine_regs.is_stmt;
3045 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3046 state_machine_regs.is_stmt = adv;
3049 case DW_LNS_set_basic_block:
3050 printf (_(" Set basic block\n"));
3051 state_machine_regs.basic_block = 1;
3054 case DW_LNS_const_add_pc:
3055 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3056 if (linfo.li_max_ops_per_insn)
3058 uladv *= linfo.li_min_insn_length;
3059 state_machine_regs.address += uladv;
3060 printf (_(" Advance PC by constant %s to 0x%s\n"),
3061 dwarf_vmatoa ("u", uladv),
3062 dwarf_vmatoa ("x", state_machine_regs.address));
3066 state_machine_regs.address
3067 += ((state_machine_regs.op_index + uladv)
3068 / linfo.li_max_ops_per_insn)
3069 * linfo.li_min_insn_length;
3070 state_machine_regs.op_index
3071 = (state_machine_regs.op_index + uladv)
3072 % linfo.li_max_ops_per_insn;
3073 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3074 dwarf_vmatoa ("u", uladv),
3075 dwarf_vmatoa ("x", state_machine_regs.address),
3076 state_machine_regs.op_index);
3080 case DW_LNS_fixed_advance_pc:
3081 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3082 state_machine_regs.address += uladv;
3083 state_machine_regs.op_index = 0;
3084 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3085 dwarf_vmatoa ("u", uladv),
3086 dwarf_vmatoa ("x", state_machine_regs.address));
3089 case DW_LNS_set_prologue_end:
3090 printf (_(" Set prologue_end to true\n"));
3093 case DW_LNS_set_epilogue_begin:
3094 printf (_(" Set epilogue_begin to true\n"));
3097 case DW_LNS_set_isa:
3098 uladv = read_uleb128 (data, & bytes_read, end);
3100 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3104 printf (_(" Unknown opcode %d with operands: "), op_code);
3106 if (standard_opcodes != NULL)
3107 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3109 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3111 i == 1 ? "" : ", ");
3127 unsigned char *name;
3128 unsigned int directory_index;
3129 unsigned int modification_date;
3130 unsigned int length;
3133 /* Output a decoded representation of the .debug_line section. */
3136 display_debug_lines_decoded (struct dwarf_section *section,
3137 unsigned char *data,
3140 static DWARF2_Internal_LineInfo saved_linfo;
3142 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3147 /* This loop amounts to one iteration per compilation unit. */
3148 DWARF2_Internal_LineInfo linfo;
3149 unsigned char *standard_opcodes;
3150 unsigned char *end_of_sequence;
3152 File_Entry *file_table = NULL;
3153 unsigned int n_files = 0;
3154 unsigned char **directory_table = NULL;
3155 unsigned int n_directories = 0;
3157 if (const_strneq (section->name, ".debug_line.")
3158 /* Note: the following does not apply to .debug_line.dwo sections.
3159 These are full debug_line sections. */
3160 && strcmp (section->name, ".debug_line.dwo") != 0)
3162 /* See comment in display_debug_lines_raw(). */
3163 end_of_sequence = end;
3164 standard_opcodes = NULL;
3165 linfo = saved_linfo;
3166 /* PR 17531: file: 0522b371. */
3167 if (linfo.li_line_range == 0)
3169 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section"));
3172 reset_state_machine (linfo.li_default_is_stmt);
3176 unsigned char *hdrptr;
3178 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3179 & end_of_sequence)) == NULL)
3182 /* PR 17531: file: 0522b371. */
3183 if (linfo.li_line_range == 0)
3185 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3186 linfo.li_line_range = 1;
3188 reset_state_machine (linfo.li_default_is_stmt);
3190 /* Save a pointer to the contents of the Opcodes table. */
3191 standard_opcodes = hdrptr;
3193 /* Traverse the Directory table just to count entries. */
3194 data = standard_opcodes + linfo.li_opcode_base - 1;
3197 unsigned char *ptr_directory_table = data;
3201 data += strnlen ((char *) data, end - data) + 1;
3205 /* Go through the directory table again to save the directories. */
3206 directory_table = (unsigned char **)
3207 xmalloc (n_directories * sizeof (unsigned char *));
3210 while (*ptr_directory_table != 0)
3212 directory_table[i] = ptr_directory_table;
3213 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3214 ptr_directory_table - end) + 1;
3218 /* Skip the NUL at the end of the table. */
3221 /* Traverse the File Name table just to count the entries. */
3224 unsigned char *ptr_file_name_table = data;
3228 unsigned int bytes_read;
3230 /* Skip Name, directory index, last modification time and length
3232 data += strnlen ((char *) data, end - data) + 1;
3233 read_uleb128 (data, & bytes_read, end);
3235 read_uleb128 (data, & bytes_read, end);
3237 read_uleb128 (data, & bytes_read, end);
3243 /* Go through the file table again to save the strings. */
3244 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3247 while (*ptr_file_name_table != 0)
3249 unsigned int bytes_read;
3251 file_table[i].name = ptr_file_name_table;
3252 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3253 end - ptr_file_name_table) + 1;
3255 /* We are not interested in directory, time or size. */
3256 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3258 ptr_file_name_table += bytes_read;
3259 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3261 ptr_file_name_table += bytes_read;
3262 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3263 ptr_file_name_table += bytes_read;
3268 /* Print the Compilation Unit's name and a header. */
3269 if (directory_table == NULL)
3271 printf (_("CU: %s:\n"), file_table[0].name);
3272 printf (_("File name Line number Starting address\n"));
3276 unsigned int ix = file_table[0].directory_index;
3277 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
3279 if (do_wide || strlen (directory) < 76)
3280 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3282 printf ("%s:\n", file_table[0].name);
3284 printf (_("File name Line number Starting address\n"));
3288 /* Skip the NUL at the end of the table. */
3291 saved_linfo = linfo;
3294 /* This loop iterates through the Dwarf Line Number Program. */
3295 while (data < end_of_sequence)
3297 unsigned char op_code;
3299 unsigned long int uladv;
3300 unsigned int bytes_read;
3301 int is_special_opcode = 0;
3305 if (op_code >= linfo.li_opcode_base)
3307 op_code -= linfo.li_opcode_base;
3308 uladv = (op_code / linfo.li_line_range);
3309 if (linfo.li_max_ops_per_insn == 1)
3311 uladv *= linfo.li_min_insn_length;
3312 state_machine_regs.address += uladv;
3316 state_machine_regs.address
3317 += ((state_machine_regs.op_index + uladv)
3318 / linfo.li_max_ops_per_insn)
3319 * linfo.li_min_insn_length;
3320 state_machine_regs.op_index
3321 = (state_machine_regs.op_index + uladv)
3322 % linfo.li_max_ops_per_insn;
3325 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3326 state_machine_regs.line += adv;
3327 is_special_opcode = 1;
3329 else switch (op_code)
3331 case DW_LNS_extended_op:
3333 unsigned int ext_op_code_len;
3334 unsigned char ext_op_code;
3335 unsigned char *op_code_data = data;
3337 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3339 op_code_data += bytes_read;
3341 if (ext_op_code_len == 0)
3343 warn (_("Badly formed extended line op encountered!\n"));
3346 ext_op_code_len += bytes_read;
3347 ext_op_code = *op_code_data++;
3349 switch (ext_op_code)
3351 case DW_LNE_end_sequence:
3352 reset_state_machine (linfo.li_default_is_stmt);
3354 case DW_LNE_set_address:
3355 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3357 ext_op_code_len - bytes_read - 1,
3359 state_machine_regs.op_index = 0;
3361 case DW_LNE_define_file:
3363 file_table = (File_Entry *) xrealloc
3364 (file_table, (n_files + 1) * sizeof (File_Entry));
3366 ++state_machine_regs.last_file_entry;
3367 /* Source file name. */
3368 file_table[n_files].name = op_code_data;
3369 op_code_data += strlen ((char *) op_code_data) + 1;
3370 /* Directory index. */
3371 file_table[n_files].directory_index =
3372 read_uleb128 (op_code_data, & bytes_read,
3374 op_code_data += bytes_read;
3375 /* Last modification time. */
3376 file_table[n_files].modification_date =
3377 read_uleb128 (op_code_data, & bytes_read,
3379 op_code_data += bytes_read;
3381 file_table[n_files].length =
3382 read_uleb128 (op_code_data, & bytes_read,
3388 case DW_LNE_set_discriminator:
3389 case DW_LNE_HP_set_sequence:
3390 /* Simply ignored. */
3394 printf (_("UNKNOWN (%u): length %d\n"),
3395 ext_op_code, ext_op_code_len - bytes_read);
3398 data += ext_op_code_len;
3404 case DW_LNS_advance_pc:
3405 uladv = read_uleb128 (data, & bytes_read, end);
3407 if (linfo.li_max_ops_per_insn == 1)
3409 uladv *= linfo.li_min_insn_length;
3410 state_machine_regs.address += uladv;
3414 state_machine_regs.address
3415 += ((state_machine_regs.op_index + uladv)
3416 / linfo.li_max_ops_per_insn)
3417 * linfo.li_min_insn_length;
3418 state_machine_regs.op_index
3419 = (state_machine_regs.op_index + uladv)
3420 % linfo.li_max_ops_per_insn;
3424 case DW_LNS_advance_line:
3425 adv = read_sleb128 (data, & bytes_read, end);
3427 state_machine_regs.line += adv;
3430 case DW_LNS_set_file:
3431 adv = read_uleb128 (data, & bytes_read, end);
3433 state_machine_regs.file = adv;
3435 if (file_table == NULL)
3436 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
3437 else if (file_table[state_machine_regs.file - 1].directory_index == 0)
3438 /* If directory index is 0, that means current directory. */
3439 printf ("\n./%s:[++]\n",
3440 file_table[state_machine_regs.file - 1].name);
3441 else if (directory_table == NULL)
3442 printf (_("\n [Use directory table entry %d]\n"),
3443 file_table[state_machine_regs.file - 1].directory_index - 1);
3445 /* The directory index starts counting at 1. */
3446 printf ("\n%s/%s:\n",
3447 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3448 file_table[state_machine_regs.file - 1].name);
3451 case DW_LNS_set_column:
3452 uladv = read_uleb128 (data, & bytes_read, end);
3454 state_machine_regs.column = uladv;
3457 case DW_LNS_negate_stmt:
3458 adv = state_machine_regs.is_stmt;
3460 state_machine_regs.is_stmt = adv;
3463 case DW_LNS_set_basic_block:
3464 state_machine_regs.basic_block = 1;
3467 case DW_LNS_const_add_pc:
3468 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3469 if (linfo.li_max_ops_per_insn == 1)
3471 uladv *= linfo.li_min_insn_length;
3472 state_machine_regs.address += uladv;
3476 state_machine_regs.address
3477 += ((state_machine_regs.op_index + uladv)
3478 / linfo.li_max_ops_per_insn)
3479 * linfo.li_min_insn_length;
3480 state_machine_regs.op_index
3481 = (state_machine_regs.op_index + uladv)
3482 % linfo.li_max_ops_per_insn;
3486 case DW_LNS_fixed_advance_pc:
3487 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3488 state_machine_regs.address += uladv;
3489 state_machine_regs.op_index = 0;
3492 case DW_LNS_set_prologue_end:
3495 case DW_LNS_set_epilogue_begin:
3498 case DW_LNS_set_isa:
3499 uladv = read_uleb128 (data, & bytes_read, end);
3501 printf (_(" Set ISA to %lu\n"), uladv);
3505 printf (_(" Unknown opcode %d with operands: "), op_code);
3507 if (standard_opcodes != NULL)
3508 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3510 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3512 i == 1 ? "" : ", ");
3519 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3520 to the DWARF address/line matrix. */
3521 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3522 || (op_code == DW_LNS_copy))
3524 const unsigned int MAX_FILENAME_LENGTH = 35;
3526 char *newFileName = NULL;
3527 size_t fileNameLength;
3530 fileName = (char *) file_table[state_machine_regs.file - 1].name;
3532 fileName = "<unknown>";
3534 fileNameLength = strlen (fileName);
3536 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3538 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3539 /* Truncate file name */
3540 strncpy (newFileName,
3541 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3542 MAX_FILENAME_LENGTH + 1);
3546 newFileName = (char *) xmalloc (fileNameLength + 1);
3547 strncpy (newFileName, fileName, fileNameLength + 1);
3550 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3552 if (linfo.li_max_ops_per_insn == 1)
3553 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3554 newFileName, state_machine_regs.line,
3555 state_machine_regs.address);
3557 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3558 newFileName, state_machine_regs.line,
3559 state_machine_regs.address,
3560 state_machine_regs.op_index);
3564 if (linfo.li_max_ops_per_insn == 1)
3565 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3566 newFileName, state_machine_regs.line,
3567 state_machine_regs.address);
3569 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3570 newFileName, state_machine_regs.line,
3571 state_machine_regs.address,
3572 state_machine_regs.op_index);
3575 if (op_code == DW_LNE_end_sequence)
3589 if (directory_table)
3591 free (directory_table);
3592 directory_table = NULL;
3603 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3605 unsigned char *data = section->start;
3606 unsigned char *end = data + section->size;
3608 int retValDecoded = 1;
3610 if (do_debug_lines == 0)
3611 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3613 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3614 retValRaw = display_debug_lines_raw (section, data, end);
3616 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3617 retValDecoded = display_debug_lines_decoded (section, data, end);
3619 if (!retValRaw || !retValDecoded)
3626 find_debug_info_for_offset (unsigned long offset)
3630 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3633 for (i = 0; i < num_debug_info_entries; i++)
3634 if (debug_information[i].cu_offset == offset)
3635 return debug_information + i;
3641 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3643 /* See gdb/gdb-index.h. */
3644 static const char * const kinds[] =
3656 return _ (kinds[kind]);
3660 display_debug_pubnames_worker (struct dwarf_section *section,
3661 void *file ATTRIBUTE_UNUSED,
3664 DWARF2_Internal_PubNames names;
3665 unsigned char *start = section->start;
3666 unsigned char *end = start + section->size;
3668 /* It does not matter if this load fails,
3669 we test for that later on. */
3670 load_debug_info (file);
3672 printf (_("Contents of the %s section:\n\n"), section->name);
3676 unsigned char *data;
3677 unsigned long offset;
3678 unsigned int offset_size, initial_length_size;
3682 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3683 if (names.pn_length == 0xffffffff)
3685 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3687 initial_length_size = 12;
3692 initial_length_size = 4;
3695 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3696 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3698 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3699 && num_debug_info_entries > 0
3700 && find_debug_info_for_offset (names.pn_offset) == NULL)
3701 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3702 (unsigned long) names.pn_offset, section->name);
3704 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3706 /* PR 17531: file: 7615b6b2. */
3707 if ((dwarf_signed_vma) names.pn_length < 0)
3709 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
3713 start += names.pn_length + initial_length_size;
3715 printf (_(" Length: %ld\n"),
3716 (long) names.pn_length);
3717 printf (_(" Version: %d\n"),
3719 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3720 (unsigned long) names.pn_offset);
3721 printf (_(" Size of area in .debug_info section: %ld\n"),
3722 (long) names.pn_size);
3724 if (names.pn_version != 2 && names.pn_version != 3)
3726 static int warned = 0;
3730 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3738 printf (_("\n Offset Kind Name\n"));
3740 printf (_("\n Offset\tName\n"));
3744 bfd_size_type maxprint;
3746 SAFE_BYTE_GET (offset, data, offset_size, end);
3750 data += offset_size;
3753 maxprint = (end - data) - 1;
3757 unsigned int kind_data;
3758 gdb_index_symbol_kind kind;
3759 const char *kind_name;
3762 SAFE_BYTE_GET (kind_data, data, 1, end);
3765 /* GCC computes the kind as the upper byte in the CU index
3766 word, and then right shifts it by the CU index size.
3767 Left shift KIND to where the gdb-index.h accessor macros
3769 kind_data <<= GDB_INDEX_CU_BITSIZE;
3770 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3771 kind_name = get_gdb_index_symbol_kind_name (kind);
3772 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3773 printf (" %-6lx %s,%-10s %.*s\n",
3774 offset, is_static ? _("s") : _("g"),
3775 kind_name, (int) maxprint, data);
3778 printf (" %-6lx\t%.*s\n", offset, (int) maxprint, data);
3780 data += strnlen ((char *) data, maxprint) + 1;
3785 while (offset != 0);
3793 display_debug_pubnames (struct dwarf_section *section, void *file)
3795 return display_debug_pubnames_worker (section, file, 0);
3799 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3801 return display_debug_pubnames_worker (section, file, 1);
3805 display_debug_macinfo (struct dwarf_section *section,
3806 void *file ATTRIBUTE_UNUSED)
3808 unsigned char *start = section->start;
3809 unsigned char *end = start + section->size;
3810 unsigned char *curr = start;
3811 unsigned int bytes_read;
3812 enum dwarf_macinfo_record_type op;
3814 printf (_("Contents of the %s section:\n\n"), section->name);
3818 unsigned int lineno;
3819 const unsigned char *string;
3821 op = (enum dwarf_macinfo_record_type) *curr;
3826 case DW_MACINFO_start_file:
3828 unsigned int filenum;
3830 lineno = read_uleb128 (curr, & bytes_read, end);
3832 filenum = read_uleb128 (curr, & bytes_read, end);
3835 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3840 case DW_MACINFO_end_file:
3841 printf (_(" DW_MACINFO_end_file\n"));
3844 case DW_MACINFO_define:
3845 lineno = read_uleb128 (curr, & bytes_read, end);
3848 curr += strnlen ((char *) string, end - string) + 1;
3849 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3853 case DW_MACINFO_undef:
3854 lineno = read_uleb128 (curr, & bytes_read, end);
3857 curr += strnlen ((char *) string, end - string) + 1;
3858 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3862 case DW_MACINFO_vendor_ext:
3864 unsigned int constant;
3866 constant = read_uleb128 (curr, & bytes_read, end);
3869 curr += strnlen ((char *) string, end - string) + 1;
3870 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3880 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3881 filename and dirname corresponding to file name table entry with index
3882 FILEIDX. Return NULL on failure. */
3884 static unsigned char *
3885 get_line_filename_and_dirname (dwarf_vma line_offset,
3887 unsigned char **dir_name)
3889 struct dwarf_section *section = &debug_displays [line].section;
3890 unsigned char *hdrptr, *dirtable, *file_name;
3891 unsigned int offset_size, initial_length_size;
3892 unsigned int version, opcode_base, bytes_read;
3893 dwarf_vma length, diridx;
3894 const unsigned char * end;
3897 if (section->start == NULL
3898 || line_offset >= section->size
3902 hdrptr = section->start + line_offset;
3903 end = section->start + section->size;
3905 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
3906 if (length == 0xffffffff)
3908 /* This section is 64-bit DWARF 3. */
3909 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
3911 initial_length_size = 12;
3916 initial_length_size = 4;
3918 if (length + initial_length_size > section->size)
3921 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
3922 if (version != 2 && version != 3 && version != 4)
3924 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3926 hdrptr++; /* Skip max_ops_per_insn. */
3927 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3929 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
3930 if (opcode_base == 0)
3933 hdrptr += opcode_base - 1;
3935 /* Skip over dirname table. */
3936 while (*hdrptr != '\0')
3937 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3938 hdrptr++; /* Skip the NUL at the end of the table. */
3939 /* Now skip over preceding filename table entries. */
3940 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3942 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3943 read_uleb128 (hdrptr, &bytes_read, end);
3944 hdrptr += bytes_read;
3945 read_uleb128 (hdrptr, &bytes_read, end);
3946 hdrptr += bytes_read;
3947 read_uleb128 (hdrptr, &bytes_read, end);
3948 hdrptr += bytes_read;
3950 if (hdrptr == end || *hdrptr == '\0')
3953 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3954 diridx = read_uleb128 (hdrptr, &bytes_read, end);
3957 for (; *dirtable != '\0' && diridx > 1; diridx--)
3958 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
3959 if (*dirtable == '\0')
3961 *dir_name = dirtable;
3966 display_debug_macro (struct dwarf_section *section,
3969 unsigned char *start = section->start;
3970 unsigned char *end = start + section->size;
3971 unsigned char *curr = start;
3972 unsigned char *extended_op_buf[256];
3973 unsigned int bytes_read;
3975 load_debug_section (str, file);
3976 load_debug_section (line, file);
3978 printf (_("Contents of the %s section:\n\n"), section->name);
3982 unsigned int lineno, version, flags;
3983 unsigned int offset_size = 4;
3984 const unsigned char *string;
3985 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3986 unsigned char **extended_ops = NULL;
3988 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
3991 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3996 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
3999 printf (_(" Offset: 0x%lx\n"),
4000 (unsigned long) sec_offset);
4001 printf (_(" Version: %d\n"), version);
4002 printf (_(" Offset size: %d\n"), offset_size);
4005 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4006 printf (_(" Offset into .debug_line: 0x%lx\n"),
4007 (unsigned long) line_offset);
4011 unsigned int i, count, op;
4014 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4016 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4017 extended_ops = extended_op_buf;
4020 printf (_(" Extension opcode arguments:\n"));
4021 for (i = 0; i < count; i++)
4023 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4024 extended_ops[op] = curr;
4025 nargs = read_uleb128 (curr, &bytes_read, end);
4028 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
4031 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
4032 for (n = 0; n < nargs; n++)
4036 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4037 printf ("%s%s", get_FORM_name (form),
4038 n == nargs - 1 ? "\n" : ", ");
4048 case DW_FORM_block1:
4049 case DW_FORM_block2:
4050 case DW_FORM_block4:
4052 case DW_FORM_string:
4054 case DW_FORM_sec_offset:
4057 error (_("Invalid extension opcode form %s\n"),
4058 get_FORM_name (form));
4074 error (_(".debug_macro section not zero terminated\n"));
4078 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4084 case DW_MACRO_GNU_start_file:
4086 unsigned int filenum;
4087 unsigned char *file_name = NULL, *dir_name = NULL;
4089 lineno = read_uleb128 (curr, &bytes_read, end);
4091 filenum = read_uleb128 (curr, &bytes_read, end);
4094 if ((flags & 2) == 0)
4095 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4098 = get_line_filename_and_dirname (line_offset, filenum,
4100 if (file_name == NULL)
4101 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4104 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4106 dir_name != NULL ? (const char *) dir_name : "",
4107 dir_name != NULL ? "/" : "", file_name);
4111 case DW_MACRO_GNU_end_file:
4112 printf (_(" DW_MACRO_GNU_end_file\n"));
4115 case DW_MACRO_GNU_define:
4116 lineno = read_uleb128 (curr, &bytes_read, end);
4119 curr += strnlen ((char *) string, end - string) + 1;
4120 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4124 case DW_MACRO_GNU_undef:
4125 lineno = read_uleb128 (curr, &bytes_read, end);
4128 curr += strnlen ((char *) string, end - string) + 1;
4129 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4133 case DW_MACRO_GNU_define_indirect:
4134 lineno = read_uleb128 (curr, &bytes_read, end);
4136 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4137 string = fetch_indirect_string (offset);
4138 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4142 case DW_MACRO_GNU_undef_indirect:
4143 lineno = read_uleb128 (curr, &bytes_read, end);
4145 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4146 string = fetch_indirect_string (offset);
4147 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4151 case DW_MACRO_GNU_transparent_include:
4152 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4153 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4154 (unsigned long) offset);
4157 case DW_MACRO_GNU_define_indirect_alt:
4158 lineno = read_uleb128 (curr, &bytes_read, end);
4160 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4161 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4162 lineno, (unsigned long) offset);
4165 case DW_MACRO_GNU_undef_indirect_alt:
4166 lineno = read_uleb128 (curr, &bytes_read, end);
4168 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4169 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4170 lineno, (unsigned long) offset);
4173 case DW_MACRO_GNU_transparent_include_alt:
4174 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4175 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4176 (unsigned long) offset);
4180 if (extended_ops == NULL || extended_ops[op] == NULL)
4182 error (_(" Unknown macro opcode %02x seen\n"), op);
4187 /* Skip over unhandled opcodes. */
4189 unsigned char *desc = extended_ops[op];
4190 nargs = read_uleb128 (desc, &bytes_read, end);
4194 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4197 printf (_(" DW_MACRO_GNU_%02x -"), op);
4198 for (n = 0; n < nargs; n++)
4202 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4204 = read_and_display_attr_value (0, val,
4205 curr, end, 0, 0, offset_size,
4206 version, NULL, 0, NULL,
4224 display_debug_abbrev (struct dwarf_section *section,
4225 void *file ATTRIBUTE_UNUSED)
4227 abbrev_entry *entry;
4228 unsigned char *start = section->start;
4229 unsigned char *end = start + section->size;
4231 printf (_("Contents of the %s section:\n\n"), section->name);
4235 unsigned char *last;
4240 start = process_abbrev_section (start, end);
4242 if (first_abbrev == NULL)
4245 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4247 for (entry = first_abbrev; entry; entry = entry->next)
4251 printf (" %ld %s [%s]\n",
4253 get_TAG_name (entry->tag),
4254 entry->children ? _("has children") : _("no children"));
4256 for (attr = entry->first_attr; attr; attr = attr->next)
4257 printf (" %-18s %s\n",
4258 get_AT_name (attr->attribute),
4259 get_FORM_name (attr->form));
4269 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4272 display_loc_list (struct dwarf_section *section,
4273 unsigned char **start_ptr,
4274 int debug_info_entry,
4275 unsigned long offset,
4276 unsigned long base_address,
4279 unsigned char *start = *start_ptr;
4280 unsigned char *section_end = section->start + section->size;
4281 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4282 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4283 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4284 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4288 unsigned short length;
4289 int need_frame_base;
4291 if (pointer_size < 2 || pointer_size > 8)
4293 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4294 pointer_size, debug_info_entry);
4300 if (start + 2 * pointer_size > section_end)
4302 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4307 printf (" %8.8lx ", offset + (start - *start_ptr));
4309 /* Note: we use sign extension here in order to be sure that we can detect
4310 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4311 address will not affect the values that we display since we always show
4312 hex values, and always the bottom 32-bits. */
4313 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4314 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4316 if (begin == 0 && end == 0)
4318 printf (_("<End of list>\n"));
4322 /* Check base address specifiers. */
4323 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4326 print_dwarf_vma (begin, pointer_size);
4327 print_dwarf_vma (end, pointer_size);
4328 printf (_("(base address)\n"));
4332 if (start + 2 > section_end)
4334 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4339 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4341 if (start + length > section_end)
4343 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4348 print_dwarf_vma (begin + base_address, pointer_size);
4349 print_dwarf_vma (end + base_address, pointer_size);
4352 need_frame_base = decode_location_expression (start,
4357 cu_offset, section);
4360 if (need_frame_base && !has_frame_base)
4361 printf (_(" [without DW_AT_frame_base]"));
4364 fputs (_(" (start == end)"), stdout);
4365 else if (begin > end)
4366 fputs (_(" (start > end)"), stdout);
4376 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4377 right-adjusted in a field of length LEN, and followed by a space. */
4380 print_addr_index (unsigned int idx, unsigned int len)
4382 static char buf[15];
4383 snprintf (buf, sizeof (buf), "[%d]", idx);
4384 printf ("%*s ", len, buf);
4387 /* Display a location list from a .dwo section. It uses address indexes rather
4388 than embedded addresses. This code closely follows display_loc_list, but the
4389 two are sufficiently different that combining things is very ugly. */
4392 display_loc_list_dwo (struct dwarf_section *section,
4393 unsigned char **start_ptr,
4394 int debug_info_entry,
4395 unsigned long offset,
4398 unsigned char *start = *start_ptr;
4399 unsigned char *section_end = section->start + section->size;
4400 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4401 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4402 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4403 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4405 unsigned short length;
4406 int need_frame_base;
4408 unsigned int bytes_read;
4410 if (pointer_size < 2 || pointer_size > 8)
4412 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4413 pointer_size, debug_info_entry);
4419 printf (" %8.8lx ", offset + (start - *start_ptr));
4421 if (start >= section_end)
4423 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4428 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4431 case 0: /* A terminating entry. */
4433 printf (_("<End of list>\n"));
4435 case 1: /* A base-address entry. */
4436 idx = read_uleb128 (start, &bytes_read, section_end);
4437 start += bytes_read;
4438 print_addr_index (idx, 8);
4440 printf (_("(base address selection entry)\n"));
4442 case 2: /* A start/end entry. */
4443 idx = read_uleb128 (start, &bytes_read, section_end);
4444 start += bytes_read;
4445 print_addr_index (idx, 8);
4446 idx = read_uleb128 (start, &bytes_read, section_end);
4447 start += bytes_read;
4448 print_addr_index (idx, 8);
4450 case 3: /* A start/length entry. */
4451 idx = read_uleb128 (start, &bytes_read, section_end);
4452 start += bytes_read;
4453 print_addr_index (idx, 8);
4454 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4455 printf ("%08x ", idx);
4457 case 4: /* An offset pair entry. */
4458 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4459 printf ("%08x ", idx);
4460 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4461 printf ("%08x ", idx);
4464 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4469 if (start + 2 > section_end)
4471 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4476 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4477 if (start + length > section_end)
4479 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4485 need_frame_base = decode_location_expression (start,
4490 cu_offset, section);
4493 if (need_frame_base && !has_frame_base)
4494 printf (_(" [without DW_AT_frame_base]"));
4504 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4506 static dwarf_vma *loc_offsets;
4509 loc_offsets_compar (const void *ap, const void *bp)
4511 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4512 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4514 return (a > b) - (b > a);
4518 display_debug_loc (struct dwarf_section *section, void *file)
4520 unsigned char *start = section->start;
4521 unsigned long bytes;
4522 unsigned char *section_begin = start;
4523 unsigned int num_loc_list = 0;
4524 unsigned long last_offset = 0;
4525 unsigned int first = 0;
4529 int seen_first_offset = 0;
4530 int locs_sorted = 1;
4531 unsigned char *next;
4532 unsigned int *array = NULL;
4533 const char *suffix = strrchr (section->name, '.');
4536 if (suffix && strcmp (suffix, ".dwo") == 0)
4539 bytes = section->size;
4543 printf (_("\nThe %s section is empty.\n"), section->name);
4547 if (load_debug_info (file) == 0)
4549 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4554 /* Check the order of location list in .debug_info section. If
4555 offsets of location lists are in the ascending order, we can
4556 use `debug_information' directly. */
4557 for (i = 0; i < num_debug_info_entries; i++)
4561 num = debug_information [i].num_loc_offsets;
4562 if (num > num_loc_list)
4565 /* Check if we can use `debug_information' directly. */
4566 if (locs_sorted && num != 0)
4568 if (!seen_first_offset)
4570 /* This is the first location list. */
4571 last_offset = debug_information [i].loc_offsets [0];
4573 seen_first_offset = 1;
4579 for (; j < num; j++)
4582 debug_information [i].loc_offsets [j])
4587 last_offset = debug_information [i].loc_offsets [j];
4592 if (!seen_first_offset)
4593 error (_("No location lists in .debug_info section!\n"));
4595 if (debug_information [first].num_loc_offsets > 0
4596 && debug_information [first].loc_offsets [0] != 0)
4597 warn (_("Location lists in %s section start at 0x%s\n"),
4599 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4602 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4603 printf (_("Contents of the %s section:\n\n"), section->name);
4604 printf (_(" Offset Begin End Expression\n"));
4606 seen_first_offset = 0;
4607 for (i = first; i < num_debug_info_entries; i++)
4609 unsigned long offset;
4610 unsigned long base_address;
4615 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4617 loc_offsets = debug_information [i].loc_offsets;
4618 qsort (array, debug_information [i].num_loc_offsets,
4619 sizeof (*array), loc_offsets_compar);
4622 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4624 j = locs_sorted ? k : array[k];
4626 && debug_information [i].loc_offsets [locs_sorted
4627 ? k - 1 : array [k - 1]]
4628 == debug_information [i].loc_offsets [j])
4630 has_frame_base = debug_information [i].have_frame_base [j];
4631 offset = debug_information [i].loc_offsets [j];
4632 next = section_begin + offset;
4633 base_address = debug_information [i].base_address;
4635 if (!seen_first_offset)
4636 seen_first_offset = 1;
4640 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4641 (unsigned long) (start - section_begin),
4642 (unsigned long) (next - section_begin));
4643 else if (start > next)
4644 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4645 (unsigned long) (start - section_begin),
4646 (unsigned long) (next - section_begin));
4650 if (offset >= bytes)
4652 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4658 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4660 display_loc_list (section, &start, i, offset, base_address,
4665 if (start < section->start + section->size)
4666 warn (_("There are %ld unused bytes at the end of section %s\n"),
4667 (long) (section->start + section->size - start), section->name);
4674 display_debug_str (struct dwarf_section *section,
4675 void *file ATTRIBUTE_UNUSED)
4677 unsigned char *start = section->start;
4678 unsigned long bytes = section->size;
4679 dwarf_vma addr = section->address;
4683 printf (_("\nThe %s section is empty.\n"), section->name);
4687 printf (_("Contents of the %s section:\n\n"), section->name);
4695 lbytes = (bytes > 16 ? 16 : bytes);
4697 printf (" 0x%8.8lx ", (unsigned long) addr);
4699 for (j = 0; j < 16; j++)
4702 printf ("%2.2x", start[j]);
4710 for (j = 0; j < lbytes; j++)
4713 if (k >= ' ' && k < 0x80)
4732 display_debug_info (struct dwarf_section *section, void *file)
4734 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4738 display_debug_types (struct dwarf_section *section, void *file)
4740 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4744 display_trace_info (struct dwarf_section *section, void *file)
4746 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4750 display_debug_aranges (struct dwarf_section *section,
4751 void *file ATTRIBUTE_UNUSED)
4753 unsigned char *start = section->start;
4754 unsigned char *end = start + section->size;
4756 printf (_("Contents of the %s section:\n\n"), section->name);
4758 /* It does not matter if this load fails,
4759 we test for that later on. */
4760 load_debug_info (file);
4764 unsigned char *hdrptr;
4765 DWARF2_Internal_ARange arange;
4766 unsigned char *addr_ranges;
4769 unsigned char address_size;
4771 unsigned int offset_size;
4772 unsigned int initial_length_size;
4776 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4777 if (arange.ar_length == 0xffffffff)
4779 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4781 initial_length_size = 12;
4786 initial_length_size = 4;
4789 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4790 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4792 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4793 && num_debug_info_entries > 0
4794 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4795 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4796 (unsigned long) arange.ar_info_offset, section->name);
4798 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4799 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4801 if (arange.ar_version != 2 && arange.ar_version != 3)
4803 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4807 printf (_(" Length: %ld\n"),
4808 (long) arange.ar_length);
4809 printf (_(" Version: %d\n"), arange.ar_version);
4810 printf (_(" Offset into .debug_info: 0x%lx\n"),
4811 (unsigned long) arange.ar_info_offset);
4812 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4813 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4815 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4817 /* PR 17512: file: 001-108546-0.001:0.1. */
4818 if (address_size == 0 || address_size > 8)
4820 error (_("Invalid address size in %s section!\n"),
4825 /* The DWARF spec does not require that the address size be a power
4826 of two, but we do. This will have to change if we ever encounter
4827 an uneven architecture. */
4828 if ((address_size & (address_size - 1)) != 0)
4830 warn (_("Pointer size + Segment size is not a power of two.\n"));
4834 if (address_size > 4)
4835 printf (_("\n Address Length\n"));
4837 printf (_("\n Address Length\n"));
4839 addr_ranges = hdrptr;
4841 /* Must pad to an alignment boundary that is twice the address size. */
4842 excess = (hdrptr - start) % (2 * address_size);
4844 addr_ranges += (2 * address_size) - excess;
4846 start += arange.ar_length + initial_length_size;
4848 while (addr_ranges + 2 * address_size <= start)
4850 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4851 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
4854 print_dwarf_vma (address, address_size);
4855 print_dwarf_vma (length, address_size);
4865 /* Comparison function for qsort. */
4867 comp_addr_base (const void * v0, const void * v1)
4869 debug_info * info0 = (debug_info *) v0;
4870 debug_info * info1 = (debug_info *) v1;
4871 return info0->addr_base - info1->addr_base;
4874 /* Display the debug_addr section. */
4876 display_debug_addr (struct dwarf_section *section,
4879 debug_info **debug_addr_info;
4880 unsigned char *entry;
4885 if (section->size == 0)
4887 printf (_("\nThe %s section is empty.\n"), section->name);
4891 if (load_debug_info (file) == 0)
4893 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4898 printf (_("Contents of the %s section:\n\n"), section->name);
4900 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4901 * sizeof (debug_info *));
4904 for (i = 0; i < num_debug_info_entries; i++)
4906 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4907 debug_addr_info [count++] = &debug_information [i];
4910 /* Add a sentinel to make iteration convenient. */
4911 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4912 debug_addr_info [count]->addr_base = section->size;
4914 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4915 for (i = 0; i < count; i++)
4918 unsigned int address_size = debug_addr_info [i]->pointer_size;
4920 printf (_(" For compilation unit at offset 0x%s:\n"),
4921 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4923 printf (_("\tIndex\tAddress\n"));
4924 entry = section->start + debug_addr_info [i]->addr_base;
4925 end = section->start + debug_addr_info [i + 1]->addr_base;
4929 dwarf_vma base = byte_get (entry, address_size);
4930 printf (_("\t%d:\t"), idx);
4931 print_dwarf_vma (base, address_size);
4933 entry += address_size;
4939 free (debug_addr_info);
4943 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4945 display_debug_str_offsets (struct dwarf_section *section,
4946 void *file ATTRIBUTE_UNUSED)
4948 if (section->size == 0)
4950 printf (_("\nThe %s section is empty.\n"), section->name);
4953 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4954 what the offset size is for this section. */
4958 /* Each debug_information[x].range_lists[y] gets this representation for
4959 sorting purposes. */
4963 /* The debug_information[x].range_lists[y] value. */
4964 unsigned long ranges_offset;
4966 /* Original debug_information to find parameters of the data. */
4967 debug_info *debug_info_p;
4970 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4973 range_entry_compar (const void *ap, const void *bp)
4975 const struct range_entry *a_re = (const struct range_entry *) ap;
4976 const struct range_entry *b_re = (const struct range_entry *) bp;
4977 const unsigned long a = a_re->ranges_offset;
4978 const unsigned long b = b_re->ranges_offset;
4980 return (a > b) - (b > a);
4984 display_debug_ranges (struct dwarf_section *section,
4985 void *file ATTRIBUTE_UNUSED)
4987 unsigned char *start = section->start;
4988 unsigned char *last_start = start;
4989 unsigned long bytes = section->size;
4990 unsigned char *section_begin = start;
4991 unsigned char *finish = start + bytes;
4992 unsigned int num_range_list, i;
4993 struct range_entry *range_entries, *range_entry_fill;
4997 printf (_("\nThe %s section is empty.\n"), section->name);
5001 if (load_debug_info (file) == 0)
5003 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5009 for (i = 0; i < num_debug_info_entries; i++)
5010 num_range_list += debug_information [i].num_range_lists;
5012 if (num_range_list == 0)
5014 /* This can happen when the file was compiled with -gsplit-debug
5015 which removes references to range lists from the primary .o file. */
5016 printf (_("No range lists in .debug_info section.\n"));
5020 range_entries = (struct range_entry *)
5021 xmalloc (sizeof (*range_entries) * num_range_list);
5022 range_entry_fill = range_entries;
5024 for (i = 0; i < num_debug_info_entries; i++)
5026 debug_info *debug_info_p = &debug_information[i];
5029 for (j = 0; j < debug_info_p->num_range_lists; j++)
5031 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
5032 range_entry_fill->debug_info_p = debug_info_p;
5037 qsort (range_entries, num_range_list, sizeof (*range_entries),
5038 range_entry_compar);
5040 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
5041 warn (_("Range lists in %s section start at 0x%lx\n"),
5042 section->name, range_entries[0].ranges_offset);
5044 printf (_("Contents of the %s section:\n\n"), section->name);
5045 printf (_(" Offset Begin End\n"));
5047 for (i = 0; i < num_range_list; i++)
5049 struct range_entry *range_entry = &range_entries[i];
5050 debug_info *debug_info_p = range_entry->debug_info_p;
5051 unsigned int pointer_size;
5052 unsigned long offset;
5053 unsigned char *next;
5054 unsigned long base_address;
5056 pointer_size = debug_info_p->pointer_size;
5057 offset = range_entry->ranges_offset;
5058 next = section_begin + offset;
5059 base_address = debug_info_p->base_address;
5061 /* PR 17512: file: 001-101485-0.001:0.1. */
5062 if (pointer_size < 2 || pointer_size > 8)
5064 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5065 pointer_size, offset);
5069 if (dwarf_check != 0 && i > 0)
5072 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5073 (unsigned long) (start - section_begin),
5074 (unsigned long) (next - section_begin), section->name);
5075 else if (start > next)
5077 if (next == last_start)
5079 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5080 (unsigned long) (start - section_begin),
5081 (unsigned long) (next - section_begin), section->name);
5087 while (start < finish)
5092 /* Note: we use sign extension here in order to be sure that
5093 we can detect the -1 escape value. Sign extension into the
5094 top 32 bits of a 32-bit address will not affect the values
5095 that we display since we always show hex values, and always
5096 the bottom 32-bits. */
5097 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5098 if (start >= finish)
5100 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5102 printf (" %8.8lx ", offset);
5104 if (begin == 0 && end == 0)
5106 printf (_("<End of list>\n"));
5110 /* Check base address specifiers. */
5111 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
5114 print_dwarf_vma (begin, pointer_size);
5115 print_dwarf_vma (end, pointer_size);
5116 printf ("(base address)\n");
5120 print_dwarf_vma (begin + base_address, pointer_size);
5121 print_dwarf_vma (end + base_address, pointer_size);
5124 fputs (_("(start == end)"), stdout);
5125 else if (begin > end)
5126 fputs (_("(start > end)"), stdout);
5133 free (range_entries);
5138 typedef struct Frame_Chunk
5140 struct Frame_Chunk *next;
5141 unsigned char *chunk_start;
5143 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5144 short int *col_type;
5147 unsigned int code_factor;
5154 unsigned char fde_encoding;
5155 unsigned char cfa_exp;
5156 unsigned char ptr_size;
5157 unsigned char segment_size;
5161 static const char *const *dwarf_regnames;
5162 static unsigned int dwarf_regnames_count;
5164 /* A marker for a col_type that means this column was never referenced
5165 in the frame info. */
5166 #define DW_CFA_unreferenced (-1)
5168 /* Return 0 if no more space is needed, 1 if more space is needed,
5169 -1 for invalid reg. */
5172 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5174 unsigned int prev = fc->ncols;
5176 if (reg < (unsigned int) fc->ncols)
5179 if (dwarf_regnames_count
5180 && reg > dwarf_regnames_count)
5183 fc->ncols = reg + 1;
5184 /* PR 17512: file: 10450-2643-0.004.
5185 If reg == -1 then this can happen... */
5189 /* PR 17512: file: 2844a11d. */
5190 if (fc->ncols > 1024)
5192 error (_("Unfeasibly large register number: %u\n"), reg);
5194 /* FIXME: 1024 is an arbitrary limit. Increase it if
5195 we ever encounter a valid binary that exceeds it. */
5199 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5200 sizeof (short int));
5201 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5202 /* PR 17512: file:002-10025-0.005. */
5203 if (fc->col_type == NULL || fc->col_offset == NULL)
5205 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5211 while (prev < fc->ncols)
5213 fc->col_type[prev] = DW_CFA_unreferenced;
5214 fc->col_offset[prev] = 0;
5220 static const char *const dwarf_regnames_i386[] =
5222 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5223 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5224 "eip", "eflags", NULL, /* 8 - 10 */
5225 "st0", "st1", "st2", "st3", /* 11 - 14 */
5226 "st4", "st5", "st6", "st7", /* 15 - 18 */
5227 NULL, NULL, /* 19 - 20 */
5228 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5229 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5230 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5231 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5232 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5233 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5234 "tr", "ldtr", /* 48 - 49 */
5235 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5236 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5237 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5238 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5239 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5240 NULL, NULL, NULL, /* 90 - 92 */
5241 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5245 init_dwarf_regnames_i386 (void)
5247 dwarf_regnames = dwarf_regnames_i386;
5248 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5251 static const char *const dwarf_regnames_x86_64[] =
5253 "rax", "rdx", "rcx", "rbx",
5254 "rsi", "rdi", "rbp", "rsp",
5255 "r8", "r9", "r10", "r11",
5256 "r12", "r13", "r14", "r15",
5258 "xmm0", "xmm1", "xmm2", "xmm3",
5259 "xmm4", "xmm5", "xmm6", "xmm7",
5260 "xmm8", "xmm9", "xmm10", "xmm11",
5261 "xmm12", "xmm13", "xmm14", "xmm15",
5262 "st0", "st1", "st2", "st3",
5263 "st4", "st5", "st6", "st7",
5264 "mm0", "mm1", "mm2", "mm3",
5265 "mm4", "mm5", "mm6", "mm7",
5267 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5268 "fs.base", "gs.base", NULL, NULL,
5270 "mxcsr", "fcw", "fsw",
5271 "xmm16", "xmm17", "xmm18", "xmm19",
5272 "xmm20", "xmm21", "xmm22", "xmm23",
5273 "xmm24", "xmm25", "xmm26", "xmm27",
5274 "xmm28", "xmm29", "xmm30", "xmm31",
5275 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5276 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5277 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5278 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5279 NULL, NULL, NULL, /* 115 - 117 */
5280 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5284 init_dwarf_regnames_x86_64 (void)
5286 dwarf_regnames = dwarf_regnames_x86_64;
5287 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5290 static const char *const dwarf_regnames_aarch64[] =
5292 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5293 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5294 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5295 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5296 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
5297 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5298 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5299 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5300 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5301 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5302 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5303 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5307 init_dwarf_regnames_aarch64 (void)
5309 dwarf_regnames = dwarf_regnames_aarch64;
5310 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
5314 init_dwarf_regnames (unsigned int e_machine)
5320 init_dwarf_regnames_i386 ();
5326 init_dwarf_regnames_x86_64 ();
5330 init_dwarf_regnames_aarch64 ();
5339 regname (unsigned int regno, int row)
5341 static char reg[64];
5343 && regno < dwarf_regnames_count
5344 && dwarf_regnames [regno] != NULL)
5347 return dwarf_regnames [regno];
5348 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5349 dwarf_regnames [regno]);
5352 snprintf (reg, sizeof (reg), "r%d", regno);
5357 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
5362 if (*max_regs < fc->ncols)
5363 *max_regs = fc->ncols;
5365 if (*need_col_headers)
5367 static const char *sloc = " LOC";
5369 *need_col_headers = 0;
5371 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5373 for (r = 0; r < *max_regs; r++)
5374 if (fc->col_type[r] != DW_CFA_unreferenced)
5379 printf ("%-5s ", regname (r, 1));
5385 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5387 strcpy (tmp, "exp");
5389 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
5390 printf ("%-8s ", tmp);
5392 for (r = 0; r < fc->ncols; r++)
5394 if (fc->col_type[r] != DW_CFA_unreferenced)
5396 switch (fc->col_type[r])
5398 case DW_CFA_undefined:
5401 case DW_CFA_same_value:
5405 sprintf (tmp, "c%+d", fc->col_offset[r]);
5407 case DW_CFA_val_offset:
5408 sprintf (tmp, "v%+d", fc->col_offset[r]);
5410 case DW_CFA_register:
5411 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5413 case DW_CFA_expression:
5414 strcpy (tmp, "exp");
5416 case DW_CFA_val_expression:
5417 strcpy (tmp, "vexp");
5420 strcpy (tmp, "n/a");
5423 printf ("%-5s ", tmp);
5429 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5430 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5431 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5433 static unsigned char *
5434 read_cie (unsigned char *start, unsigned char *end,
5435 Frame_Chunk **p_cie, int *p_version,
5436 unsigned long *p_aug_len, unsigned char **p_aug)
5440 unsigned int length_return;
5441 unsigned char *augmentation_data = NULL;
5442 unsigned long augmentation_data_len = 0;
5445 /* PR 17512: file: 001-228113-0.004. */
5449 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5450 memset (fc, 0, sizeof (Frame_Chunk));
5452 fc->col_type = (short int *) xmalloc (sizeof (short int));
5453 fc->col_offset = (int *) xmalloc (sizeof (int));
5457 fc->augmentation = (char *) start;
5458 /* PR 17512: file: 001-228113-0.004.
5459 Skip past augmentation name, but avoid running off the end of the data. */
5461 if (* start ++ == '\0')
5465 warn (_("No terminator for augmentation name\n"));
5469 if (strcmp (fc->augmentation, "eh") == 0)
5470 start += eh_addr_size;
5474 GET (fc->ptr_size, 1);
5475 GET (fc->segment_size, 1);
5476 eh_addr_size = fc->ptr_size;
5480 fc->ptr_size = eh_addr_size;
5481 fc->segment_size = 0;
5483 fc->code_factor = LEB ();
5484 fc->data_factor = SLEB ();
5494 if (fc->augmentation[0] == 'z')
5496 augmentation_data_len = LEB ();
5497 augmentation_data = start;
5498 start += augmentation_data_len;
5499 /* PR 17512: file: 11042-2589-0.004. */
5502 warn (_("Augmentation data too long: 0x%lx"), augmentation_data_len);
5507 if (augmentation_data_len)
5511 unsigned char *qend;
5513 p = (unsigned char *) fc->augmentation + 1;
5514 q = augmentation_data;
5515 qend = q + augmentation_data_len;
5517 /* PR 17531: file: 015adfaa. */
5520 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
5521 augmentation_data_len = 0;
5524 while (p < end && q < augmentation_data + augmentation_data_len)
5529 q += 1 + size_of_encoded_value (*q);
5531 fc->fde_encoding = *q++;
5538 /* Note - it is OK if this loop terminates with q < qend.
5539 Padding may have been inserted to align the end of the CIE. */
5544 *p_version = version;
5547 *p_aug_len = augmentation_data_len;
5548 *p_aug = augmentation_data;
5554 display_debug_frames (struct dwarf_section *section,
5555 void *file ATTRIBUTE_UNUSED)
5557 unsigned char *start = section->start;
5558 unsigned char *end = start + section->size;
5559 unsigned char *section_start = start;
5560 Frame_Chunk *chunks = 0, *forward_refs = 0;
5561 Frame_Chunk *remembered_state = 0;
5563 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5564 unsigned int length_return;
5565 unsigned int max_regs = 0;
5566 const char *bad_reg = _("bad register: ");
5567 int saved_eh_addr_size = eh_addr_size;
5569 printf (_("Contents of the %s section:\n"), section->name);
5573 unsigned char *saved_start;
5574 unsigned char *block_end;
5579 int need_col_headers = 1;
5580 unsigned char *augmentation_data = NULL;
5581 unsigned long augmentation_data_len = 0;
5582 unsigned int encoded_ptr_size = saved_eh_addr_size;
5583 unsigned int offset_size;
5584 unsigned int initial_length_size;
5586 saved_start = start;
5588 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5592 printf ("\n%08lx ZERO terminator\n\n",
5593 (unsigned long)(saved_start - section_start));
5594 /* Skip any zero terminators that directly follow.
5595 A corrupt section size could have loaded a whole
5596 slew of zero filled memory bytes. eg
5597 PR 17512: file: 070-19381-0.004. */
5598 while (start < end && * start == 0)
5603 if (length == 0xffffffff)
5605 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5607 initial_length_size = 12;
5612 initial_length_size = 4;
5615 block_end = saved_start + length + initial_length_size;
5616 if (block_end > end || block_end < start)
5618 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5619 dwarf_vmatoa_1 (NULL, length, offset_size),
5620 (unsigned long) (saved_start - section_start));
5624 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5626 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5627 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5632 start = read_cie (start, end, &cie, &version,
5633 &augmentation_data_len, &augmentation_data);
5634 /* PR 17512: file: 027-135133-0.005. */
5641 fc->chunk_start = saved_start;
5642 mreg = max_regs > 0 ? max_regs - 1 : 0;
5645 if (frame_need_space (fc, mreg) < 0)
5647 if (fc->fde_encoding)
5648 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5650 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5651 print_dwarf_vma (length, fc->ptr_size);
5652 print_dwarf_vma (cie_id, offset_size);
5654 if (do_debug_frames_interp)
5656 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5657 fc->code_factor, fc->data_factor, fc->ra);
5662 printf (" Version: %d\n", version);
5663 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5666 printf (" Pointer Size: %u\n", fc->ptr_size);
5667 printf (" Segment Size: %u\n", fc->segment_size);
5669 printf (" Code alignment factor: %u\n", fc->code_factor);
5670 printf (" Data alignment factor: %d\n", fc->data_factor);
5671 printf (" Return address column: %d\n", fc->ra);
5673 if (augmentation_data_len)
5677 printf (" Augmentation data: ");
5678 for (i = 0; i < augmentation_data_len; ++i)
5679 /* FIXME: If do_wide is FALSE, then we should
5680 add carriage returns at 80 columns... */
5681 printf (" %02x", augmentation_data[i]);
5689 unsigned char *look_for;
5690 static Frame_Chunk fde_fc;
5691 unsigned long segment_selector;
5695 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
5696 look_for = start - 4 - ((cie_id ^ sign) - sign);
5699 look_for = section_start + cie_id;
5701 if (look_for <= saved_start)
5703 for (cie = chunks; cie ; cie = cie->next)
5704 if (cie->chunk_start == look_for)
5709 for (cie = forward_refs; cie ; cie = cie->next)
5710 if (cie->chunk_start == look_for)
5714 unsigned int off_size;
5715 unsigned char *cie_scan;
5717 cie_scan = look_for;
5719 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
5720 if (length == 0xffffffff)
5722 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
5729 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
5732 : ((off_size == 4 && c_id == DW_CIE_ID)
5733 || (off_size == 8 && c_id == DW64_CIE_ID)))
5738 read_cie (cie_scan, end, &cie, &version,
5739 &augmentation_data_len, &augmentation_data);
5740 /* PR 17512: file: 3450-2098-0.004. */
5743 warn (_("Failed to read CIE information\n"));
5746 cie->next = forward_refs;
5748 cie->chunk_start = look_for;
5749 mreg = max_regs > 0 ? max_regs - 1 : 0;
5752 if (frame_need_space (cie, mreg) < 0)
5754 warn (_("Invalid max register\n"));
5757 if (cie->fde_encoding)
5759 = size_of_encoded_value (cie->fde_encoding);
5766 memset (fc, 0, sizeof (Frame_Chunk));
5770 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5771 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5772 (unsigned long) (saved_start - section_start));
5774 fc->col_type = (short int *) xmalloc (sizeof (short int));
5775 fc->col_offset = (int *) xmalloc (sizeof (int));
5776 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
5778 warn (_("Invalid max register\n"));
5782 fc->augmentation = "";
5783 fc->fde_encoding = 0;
5784 fc->ptr_size = eh_addr_size;
5785 fc->segment_size = 0;
5789 fc->ncols = cie->ncols;
5790 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5791 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5792 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5793 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5794 fc->augmentation = cie->augmentation;
5795 fc->ptr_size = cie->ptr_size;
5796 eh_addr_size = cie->ptr_size;
5797 fc->segment_size = cie->segment_size;
5798 fc->code_factor = cie->code_factor;
5799 fc->data_factor = cie->data_factor;
5800 fc->cfa_reg = cie->cfa_reg;
5801 fc->cfa_offset = cie->cfa_offset;
5803 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
5805 warn (_("Invalid max register\n"));
5808 fc->fde_encoding = cie->fde_encoding;
5811 if (fc->fde_encoding)
5812 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5814 segment_selector = 0;
5815 if (fc->segment_size)
5816 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
5818 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
5820 /* FIXME: It appears that sometimes the final pc_range value is
5821 encoded in less than encoded_ptr_size bytes. See the x86_64
5822 run of the "objcopy on compressed debug sections" test for an
5824 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5826 if (cie->augmentation[0] == 'z')
5828 augmentation_data_len = LEB ();
5829 augmentation_data = start;
5830 start += augmentation_data_len;
5831 /* PR 17512: file: 722-8446-0.004. */
5832 if (start >= end || ((signed long) augmentation_data_len) < 0)
5834 warn (_("Corrupt augmentation data length: %lx\n"),
5835 augmentation_data_len);
5837 augmentation_data = NULL;
5838 augmentation_data_len = 0;
5842 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5843 (unsigned long)(saved_start - section_start),
5844 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
5845 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5846 (unsigned long)(cie->chunk_start - section_start));
5848 if (fc->segment_size)
5849 printf ("%04lx:", segment_selector);
5852 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
5853 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
5855 if (! do_debug_frames_interp && augmentation_data_len)
5859 printf (" Augmentation data: ");
5860 for (i = 0; i < augmentation_data_len; ++i)
5861 printf (" %02x", augmentation_data[i]);
5867 /* At this point, fc is the current chunk, cie (if any) is set, and
5868 we're about to interpret instructions for the chunk. */
5869 /* ??? At present we need to do this always, since this sizes the
5870 fc->col_type and fc->col_offset arrays, which we write into always.
5871 We should probably split the interpreted and non-interpreted bits
5872 into two different routines, since there's so much that doesn't
5873 really overlap between them. */
5874 if (1 || do_debug_frames_interp)
5876 /* Start by making a pass over the chunk, allocating storage
5877 and taking note of what registers are used. */
5878 unsigned char *tmp = start;
5880 while (start < block_end)
5882 unsigned int reg, op, opa;
5890 /* Warning: if you add any more cases to this switch, be
5891 sure to add them to the corresponding switch below. */
5894 case DW_CFA_advance_loc:
5898 if (frame_need_space (fc, opa) >= 0)
5899 fc->col_type[opa] = DW_CFA_undefined;
5901 case DW_CFA_restore:
5902 if (frame_need_space (fc, opa) >= 0)
5903 fc->col_type[opa] = DW_CFA_undefined;
5905 case DW_CFA_set_loc:
5906 start += encoded_ptr_size;
5908 case DW_CFA_advance_loc1:
5911 case DW_CFA_advance_loc2:
5914 case DW_CFA_advance_loc4:
5917 case DW_CFA_offset_extended:
5918 case DW_CFA_val_offset:
5919 reg = LEB (); LEB ();
5920 if (frame_need_space (fc, reg) >= 0)
5921 fc->col_type[reg] = DW_CFA_undefined;
5923 case DW_CFA_restore_extended:
5925 if (frame_need_space (fc, reg) >= 0)
5926 fc->col_type[reg] = DW_CFA_undefined;
5928 case DW_CFA_undefined:
5930 if (frame_need_space (fc, reg) >= 0)
5931 fc->col_type[reg] = DW_CFA_undefined;
5933 case DW_CFA_same_value:
5935 if (frame_need_space (fc, reg) >= 0)
5936 fc->col_type[reg] = DW_CFA_undefined;
5938 case DW_CFA_register:
5939 reg = LEB (); LEB ();
5940 if (frame_need_space (fc, reg) >= 0)
5941 fc->col_type[reg] = DW_CFA_undefined;
5943 case DW_CFA_def_cfa:
5946 case DW_CFA_def_cfa_register:
5949 case DW_CFA_def_cfa_offset:
5952 case DW_CFA_def_cfa_expression:
5954 if (start + temp < start)
5956 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
5962 case DW_CFA_expression:
5963 case DW_CFA_val_expression:
5966 if (start + temp < start)
5968 /* PR 17512: file:306-192417-0.005. */
5969 warn (_("Corrupt CFA expression value: %lu\n"), temp);
5974 if (frame_need_space (fc, reg) >= 0)
5975 fc->col_type[reg] = DW_CFA_undefined;
5977 case DW_CFA_offset_extended_sf:
5978 case DW_CFA_val_offset_sf:
5979 reg = LEB (); SLEB ();
5980 if (frame_need_space (fc, reg) >= 0)
5981 fc->col_type[reg] = DW_CFA_undefined;
5983 case DW_CFA_def_cfa_sf:
5986 case DW_CFA_def_cfa_offset_sf:
5989 case DW_CFA_MIPS_advance_loc8:
5992 case DW_CFA_GNU_args_size:
5995 case DW_CFA_GNU_negative_offset_extended:
5996 reg = LEB (); LEB ();
5997 if (frame_need_space (fc, reg) >= 0)
5998 fc->col_type[reg] = DW_CFA_undefined;
6007 /* Now we know what registers are used, make a second pass over
6008 the chunk, this time actually printing out the info. */
6010 while (start < block_end)
6013 unsigned long ul, reg, roffs;
6017 const char *reg_prefix = "";
6024 /* Warning: if you add any more cases to this switch, be
6025 sure to add them to the corresponding switch above. */
6028 case DW_CFA_advance_loc:
6029 if (do_debug_frames_interp)
6030 frame_display_row (fc, &need_col_headers, &max_regs);
6032 printf (" DW_CFA_advance_loc: %d to %s\n",
6033 opa * fc->code_factor,
6034 dwarf_vmatoa_1 (NULL,
6035 fc->pc_begin + opa * fc->code_factor,
6037 fc->pc_begin += opa * fc->code_factor;
6042 if (opa >= (unsigned int) fc->ncols)
6043 reg_prefix = bad_reg;
6044 if (! do_debug_frames_interp || *reg_prefix != '\0')
6045 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6046 reg_prefix, regname (opa, 0),
6047 roffs * fc->data_factor);
6048 if (*reg_prefix == '\0')
6050 fc->col_type[opa] = DW_CFA_offset;
6051 fc->col_offset[opa] = roffs * fc->data_factor;
6055 case DW_CFA_restore:
6056 if (opa >= (unsigned int) cie->ncols
6057 || opa >= (unsigned int) fc->ncols)
6058 reg_prefix = bad_reg;
6059 if (! do_debug_frames_interp || *reg_prefix != '\0')
6060 printf (" DW_CFA_restore: %s%s\n",
6061 reg_prefix, regname (opa, 0));
6062 if (*reg_prefix == '\0')
6064 fc->col_type[opa] = cie->col_type[opa];
6065 fc->col_offset[opa] = cie->col_offset[opa];
6066 if (do_debug_frames_interp
6067 && fc->col_type[opa] == DW_CFA_unreferenced)
6068 fc->col_type[opa] = DW_CFA_undefined;
6072 case DW_CFA_set_loc:
6073 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
6074 if (do_debug_frames_interp)
6075 frame_display_row (fc, &need_col_headers, &max_regs);
6077 printf (" DW_CFA_set_loc: %s\n",
6078 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
6082 case DW_CFA_advance_loc1:
6083 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
6084 if (do_debug_frames_interp)
6085 frame_display_row (fc, &need_col_headers, &max_regs);
6087 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6088 (unsigned long) (ofs * fc->code_factor),
6089 dwarf_vmatoa_1 (NULL,
6090 fc->pc_begin + ofs * fc->code_factor,
6092 fc->pc_begin += ofs * fc->code_factor;
6095 case DW_CFA_advance_loc2:
6096 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
6097 if (do_debug_frames_interp)
6098 frame_display_row (fc, &need_col_headers, &max_regs);
6100 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6101 (unsigned long) (ofs * fc->code_factor),
6102 dwarf_vmatoa_1 (NULL,
6103 fc->pc_begin + ofs * fc->code_factor,
6105 fc->pc_begin += ofs * fc->code_factor;
6108 case DW_CFA_advance_loc4:
6109 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
6110 if (do_debug_frames_interp)
6111 frame_display_row (fc, &need_col_headers, &max_regs);
6113 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6114 (unsigned long) (ofs * fc->code_factor),
6115 dwarf_vmatoa_1 (NULL,
6116 fc->pc_begin + ofs * fc->code_factor,
6118 fc->pc_begin += ofs * fc->code_factor;
6121 case DW_CFA_offset_extended:
6124 if (reg >= (unsigned int) fc->ncols)
6125 reg_prefix = bad_reg;
6126 if (! do_debug_frames_interp || *reg_prefix != '\0')
6127 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6128 reg_prefix, regname (reg, 0),
6129 roffs * fc->data_factor);
6130 if (*reg_prefix == '\0')
6132 fc->col_type[reg] = DW_CFA_offset;
6133 fc->col_offset[reg] = roffs * fc->data_factor;
6137 case DW_CFA_val_offset:
6140 if (reg >= (unsigned int) fc->ncols)
6141 reg_prefix = bad_reg;
6142 if (! do_debug_frames_interp || *reg_prefix != '\0')
6143 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6144 reg_prefix, regname (reg, 0),
6145 roffs * fc->data_factor);
6146 if (*reg_prefix == '\0')
6148 fc->col_type[reg] = DW_CFA_val_offset;
6149 fc->col_offset[reg] = roffs * fc->data_factor;
6153 case DW_CFA_restore_extended:
6155 if (reg >= (unsigned int) cie->ncols
6156 || reg >= (unsigned int) fc->ncols)
6157 reg_prefix = bad_reg;
6158 if (! do_debug_frames_interp || *reg_prefix != '\0')
6159 printf (" DW_CFA_restore_extended: %s%s\n",
6160 reg_prefix, regname (reg, 0));
6161 if (*reg_prefix == '\0')
6163 fc->col_type[reg] = cie->col_type[reg];
6164 fc->col_offset[reg] = cie->col_offset[reg];
6168 case DW_CFA_undefined:
6170 if (reg >= (unsigned int) fc->ncols)
6171 reg_prefix = bad_reg;
6172 if (! do_debug_frames_interp || *reg_prefix != '\0')
6173 printf (" DW_CFA_undefined: %s%s\n",
6174 reg_prefix, regname (reg, 0));
6175 if (*reg_prefix == '\0')
6177 fc->col_type[reg] = DW_CFA_undefined;
6178 fc->col_offset[reg] = 0;
6182 case DW_CFA_same_value:
6184 if (reg >= (unsigned int) fc->ncols)
6185 reg_prefix = bad_reg;
6186 if (! do_debug_frames_interp || *reg_prefix != '\0')
6187 printf (" DW_CFA_same_value: %s%s\n",
6188 reg_prefix, regname (reg, 0));
6189 if (*reg_prefix == '\0')
6191 fc->col_type[reg] = DW_CFA_same_value;
6192 fc->col_offset[reg] = 0;
6196 case DW_CFA_register:
6199 if (reg >= (unsigned int) fc->ncols)
6200 reg_prefix = bad_reg;
6201 if (! do_debug_frames_interp || *reg_prefix != '\0')
6203 printf (" DW_CFA_register: %s%s in ",
6204 reg_prefix, regname (reg, 0));
6205 puts (regname (roffs, 0));
6207 if (*reg_prefix == '\0')
6209 fc->col_type[reg] = DW_CFA_register;
6210 fc->col_offset[reg] = roffs;
6214 case DW_CFA_remember_state:
6215 if (! do_debug_frames_interp)
6216 printf (" DW_CFA_remember_state\n");
6217 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6218 rs->cfa_offset = fc->cfa_offset;
6219 rs->cfa_reg = fc->cfa_reg;
6221 rs->cfa_exp = fc->cfa_exp;
6222 rs->ncols = fc->ncols;
6223 rs->col_type = (short int *) xcmalloc (rs->ncols,
6224 sizeof (* rs->col_type));
6225 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
6226 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
6227 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
6228 rs->next = remembered_state;
6229 remembered_state = rs;
6232 case DW_CFA_restore_state:
6233 if (! do_debug_frames_interp)
6234 printf (" DW_CFA_restore_state\n");
6235 rs = remembered_state;
6238 remembered_state = rs->next;
6239 fc->cfa_offset = rs->cfa_offset;
6240 fc->cfa_reg = rs->cfa_reg;
6242 fc->cfa_exp = rs->cfa_exp;
6243 if (frame_need_space (fc, rs->ncols - 1) < 0)
6245 warn (_("Invalid column number in saved frame state"));
6249 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
6250 memcpy (fc->col_offset, rs->col_offset,
6251 rs->ncols * sizeof (* rs->col_offset));
6252 free (rs->col_type);
6253 free (rs->col_offset);
6256 else if (do_debug_frames_interp)
6257 printf ("Mismatched DW_CFA_restore_state\n");
6260 case DW_CFA_def_cfa:
6261 fc->cfa_reg = LEB ();
6262 fc->cfa_offset = LEB ();
6264 if (! do_debug_frames_interp)
6265 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6266 regname (fc->cfa_reg, 0), fc->cfa_offset);
6269 case DW_CFA_def_cfa_register:
6270 fc->cfa_reg = LEB ();
6272 if (! do_debug_frames_interp)
6273 printf (" DW_CFA_def_cfa_register: %s\n",
6274 regname (fc->cfa_reg, 0));
6277 case DW_CFA_def_cfa_offset:
6278 fc->cfa_offset = LEB ();
6279 if (! do_debug_frames_interp)
6280 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
6284 if (! do_debug_frames_interp)
6285 printf (" DW_CFA_nop\n");
6288 case DW_CFA_def_cfa_expression:
6290 if (start >= block_end || start + ul > block_end || start + ul < start)
6292 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6295 if (! do_debug_frames_interp)
6297 printf (" DW_CFA_def_cfa_expression (");
6298 decode_location_expression (start, eh_addr_size, 0, -1,
6306 case DW_CFA_expression:
6309 if (reg >= (unsigned int) fc->ncols)
6310 reg_prefix = bad_reg;
6311 /* PR 17512: file: 069-133014-0.006. */
6312 /* PR 17512: file: 98c02eb4. */
6313 if (start >= block_end || start + ul > block_end || start + ul < start)
6315 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6318 if (! do_debug_frames_interp || *reg_prefix != '\0')
6320 printf (" DW_CFA_expression: %s%s (",
6321 reg_prefix, regname (reg, 0));
6322 decode_location_expression (start, eh_addr_size, 0, -1,
6326 if (*reg_prefix == '\0')
6327 fc->col_type[reg] = DW_CFA_expression;
6331 case DW_CFA_val_expression:
6334 if (reg >= (unsigned int) fc->ncols)
6335 reg_prefix = bad_reg;
6336 if (start >= block_end || start + ul > block_end || start + ul < start)
6338 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6341 if (! do_debug_frames_interp || *reg_prefix != '\0')
6343 printf (" DW_CFA_val_expression: %s%s (",
6344 reg_prefix, regname (reg, 0));
6345 decode_location_expression (start, eh_addr_size, 0, -1,
6349 if (*reg_prefix == '\0')
6350 fc->col_type[reg] = DW_CFA_val_expression;
6354 case DW_CFA_offset_extended_sf:
6357 if (frame_need_space (fc, reg) < 0)
6358 reg_prefix = bad_reg;
6359 if (! do_debug_frames_interp || *reg_prefix != '\0')
6360 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6361 reg_prefix, regname (reg, 0),
6362 l * fc->data_factor);
6363 if (*reg_prefix == '\0')
6365 fc->col_type[reg] = DW_CFA_offset;
6366 fc->col_offset[reg] = l * fc->data_factor;
6370 case DW_CFA_val_offset_sf:
6373 if (frame_need_space (fc, reg) < 0)
6374 reg_prefix = bad_reg;
6375 if (! do_debug_frames_interp || *reg_prefix != '\0')
6376 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6377 reg_prefix, regname (reg, 0),
6378 l * fc->data_factor);
6379 if (*reg_prefix == '\0')
6381 fc->col_type[reg] = DW_CFA_val_offset;
6382 fc->col_offset[reg] = l * fc->data_factor;
6386 case DW_CFA_def_cfa_sf:
6387 fc->cfa_reg = LEB ();
6388 fc->cfa_offset = SLEB ();
6389 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6391 if (! do_debug_frames_interp)
6392 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6393 regname (fc->cfa_reg, 0), fc->cfa_offset);
6396 case DW_CFA_def_cfa_offset_sf:
6397 fc->cfa_offset = SLEB ();
6398 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6399 if (! do_debug_frames_interp)
6400 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
6403 case DW_CFA_MIPS_advance_loc8:
6404 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
6405 if (do_debug_frames_interp)
6406 frame_display_row (fc, &need_col_headers, &max_regs);
6408 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6409 (unsigned long) (ofs * fc->code_factor),
6410 dwarf_vmatoa_1 (NULL,
6411 fc->pc_begin + ofs * fc->code_factor,
6413 fc->pc_begin += ofs * fc->code_factor;
6416 case DW_CFA_GNU_window_save:
6417 if (! do_debug_frames_interp)
6418 printf (" DW_CFA_GNU_window_save\n");
6421 case DW_CFA_GNU_args_size:
6423 if (! do_debug_frames_interp)
6424 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6427 case DW_CFA_GNU_negative_offset_extended:
6430 if (frame_need_space (fc, reg) < 0)
6431 reg_prefix = bad_reg;
6432 if (! do_debug_frames_interp || *reg_prefix != '\0')
6433 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6434 reg_prefix, regname (reg, 0),
6435 l * fc->data_factor);
6436 if (*reg_prefix == '\0')
6438 fc->col_type[reg] = DW_CFA_offset;
6439 fc->col_offset[reg] = l * fc->data_factor;
6444 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6445 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6447 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6452 if (do_debug_frames_interp)
6453 frame_display_row (fc, &need_col_headers, &max_regs);
6456 eh_addr_size = saved_eh_addr_size;
6469 display_gdb_index (struct dwarf_section *section,
6470 void *file ATTRIBUTE_UNUSED)
6472 unsigned char *start = section->start;
6474 uint32_t cu_list_offset, tu_list_offset;
6475 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6476 unsigned int cu_list_elements, tu_list_elements;
6477 unsigned int address_table_size, symbol_table_slots;
6478 unsigned char *cu_list, *tu_list;
6479 unsigned char *address_table, *symbol_table, *constant_pool;
6482 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6484 printf (_("Contents of the %s section:\n"), section->name);
6486 if (section->size < 6 * sizeof (uint32_t))
6488 warn (_("Truncated header in the %s section.\n"), section->name);
6492 version = byte_get_little_endian (start, 4);
6493 printf (_("Version %ld\n"), (long) version);
6495 /* Prior versions are obsolete, and future versions may not be
6496 backwards compatible. */
6497 if (version < 3 || version > 8)
6499 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6503 warn (_("The address table data in version 3 may be wrong.\n"));
6505 warn (_("Version 4 does not support case insensitive lookups.\n"));
6507 warn (_("Version 5 does not include inlined functions.\n"));
6509 warn (_("Version 6 does not include symbol attributes.\n"));
6510 /* Version 7 indices generated by Gold have bad type unit references,
6511 PR binutils/15021. But we don't know if the index was generated by
6512 Gold or not, so to avoid worrying users with gdb-generated indices
6513 we say nothing for version 7 here. */
6515 cu_list_offset = byte_get_little_endian (start + 4, 4);
6516 tu_list_offset = byte_get_little_endian (start + 8, 4);
6517 address_table_offset = byte_get_little_endian (start + 12, 4);
6518 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6519 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6521 if (cu_list_offset > section->size
6522 || tu_list_offset > section->size
6523 || address_table_offset > section->size
6524 || symbol_table_offset > section->size
6525 || constant_pool_offset > section->size)
6527 warn (_("Corrupt header in the %s section.\n"), section->name);
6531 /* PR 17531: file: 418d0a8a. */
6532 if (tu_list_offset < cu_list_offset)
6534 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6535 tu_list_offset, cu_list_offset);
6539 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6541 if (address_table_offset < tu_list_offset)
6543 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6544 address_table_offset, tu_list_offset);
6548 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6550 /* PR 17531: file: 18a47d3d. */
6551 if (symbol_table_offset < address_table_offset)
6553 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6554 symbol_table_offset, address_table_offset);
6558 address_table_size = symbol_table_offset - address_table_offset;
6560 if (constant_pool_offset < symbol_table_offset)
6562 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6563 constant_pool_offset, symbol_table_offset);
6567 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6569 cu_list = start + cu_list_offset;
6570 tu_list = start + tu_list_offset;
6571 address_table = start + address_table_offset;
6572 symbol_table = start + symbol_table_offset;
6573 constant_pool = start + constant_pool_offset;
6575 if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
6577 warn (_("Address table extends beyond end of section. %x"), address_table_size);
6581 printf (_("\nCU table:\n"));
6582 for (i = 0; i < cu_list_elements; i += 2)
6584 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6585 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6587 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6588 (unsigned long) cu_offset,
6589 (unsigned long) (cu_offset + cu_length - 1));
6592 printf (_("\nTU table:\n"));
6593 for (i = 0; i < tu_list_elements; i += 3)
6595 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6596 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6597 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6599 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6600 (unsigned long) tu_offset,
6601 (unsigned long) type_offset);
6602 print_dwarf_vma (signature, 8);
6606 printf (_("\nAddress table:\n"));
6607 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
6610 uint64_t low = byte_get_little_endian (address_table + i, 8);
6611 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6612 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6614 print_dwarf_vma (low, 8);
6615 print_dwarf_vma (high, 8);
6616 printf (_("%lu\n"), (unsigned long) cu_index);
6619 printf (_("\nSymbol table:\n"));
6620 for (i = 0; i < symbol_table_slots; ++i)
6622 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6623 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6624 uint32_t num_cus, cu;
6626 if (name_offset != 0
6627 || cu_vector_offset != 0)
6631 /* PR 17531: file: 5b7b07ad. */
6632 if (constant_pool + name_offset < constant_pool
6633 || constant_pool + name_offset >= section->start + section->size)
6635 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
6636 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6640 printf ("[%3u] %.*s:", i,
6641 (int) (section->size - (constant_pool_offset + name_offset)),
6642 constant_pool + name_offset);
6644 if (constant_pool + cu_vector_offset < constant_pool
6645 || constant_pool + cu_vector_offset >= section->start + section->size)
6647 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
6648 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6649 cu_vector_offset, i);
6653 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
6655 if (num_cus * 4 < num_cus
6656 || constant_pool + cu_vector_offset + 4 + num_cus * 4 >=
6657 section->start + section->size)
6659 printf ("<invalid number of CUs: %d>\n", num_cus);
6660 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6667 for (j = 0; j < num_cus; ++j)
6670 gdb_index_symbol_kind kind;
6672 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6673 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6674 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6675 cu = GDB_INDEX_CU_VALUE (cu);
6676 /* Convert to TU number if it's for a type unit. */
6677 if (cu >= cu_list_elements / 2)
6678 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6679 (unsigned long) (cu - cu_list_elements / 2));
6681 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6683 printf (" [%s, %s]",
6684 is_static ? _("static") : _("global"),
6685 get_gdb_index_symbol_kind_name (kind));
6697 /* Pre-allocate enough space for the CU/TU sets needed. */
6700 prealloc_cu_tu_list (unsigned int nshndx)
6702 if (shndx_pool == NULL)
6704 shndx_pool_size = nshndx;
6705 shndx_pool_used = 0;
6706 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6707 sizeof (unsigned int));
6711 shndx_pool_size = shndx_pool_used + nshndx;
6712 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6713 sizeof (unsigned int));
6718 add_shndx_to_cu_tu_entry (unsigned int shndx)
6720 if (shndx_pool_used >= shndx_pool_size)
6722 error (_("Internal error: out of space in the shndx pool.\n"));
6725 shndx_pool [shndx_pool_used++] = shndx;
6729 end_cu_tu_entry (void)
6731 if (shndx_pool_used >= shndx_pool_size)
6733 error (_("Internal error: out of space in the shndx pool.\n"));
6736 shndx_pool [shndx_pool_used++] = 0;
6739 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6742 get_DW_SECT_short_name (unsigned int dw_sect)
6744 static char buf[16];
6752 case DW_SECT_ABBREV:
6758 case DW_SECT_STR_OFFSETS:
6760 case DW_SECT_MACINFO:
6768 snprintf (buf, sizeof (buf), "%d", dw_sect);
6772 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6773 These sections are extensions for Fission.
6774 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6777 process_cu_tu_index (struct dwarf_section *section, int do_display)
6779 unsigned char *phdr = section->start;
6780 unsigned char *limit = phdr + section->size;
6781 unsigned char *phash;
6782 unsigned char *pindex;
6783 unsigned char *ppool;
6784 unsigned int version;
6785 unsigned int ncols = 0;
6787 unsigned int nslots;
6790 dwarf_vma signature_high;
6791 dwarf_vma signature_low;
6794 /* PR 17512: file: 002-168123-0.004. */
6797 warn (_("Section %s is empty\n"), section->name);
6800 /* PR 17512: file: 002-376-0.004. */
6801 if (section->size < 24)
6803 warn (_("Section %s is too small to contain a CU/TU header"),
6808 SAFE_BYTE_GET (version, phdr, 4, limit);
6810 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
6811 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
6812 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
6815 pindex = phash + nslots * 8;
6816 ppool = pindex + nslots * 4;
6820 printf (_("Contents of the %s section:\n\n"), section->name);
6821 printf (_(" Version: %d\n"), version);
6823 printf (_(" Number of columns: %d\n"), ncols);
6824 printf (_(" Number of used entries: %d\n"), nused);
6825 printf (_(" Number of slots: %d\n\n"), nslots);
6830 warn (_("Section %s too small for %d hash table entries\n"),
6831 section->name, nslots);
6838 prealloc_cu_tu_list ((limit - ppool) / 4);
6839 for (i = 0; i < nslots; i++)
6841 unsigned char *shndx_list;
6844 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
6845 if (signature_high != 0 || signature_low != 0)
6847 SAFE_BYTE_GET (j, pindex, 4, limit);
6848 shndx_list = ppool + j * 4;
6850 printf (_(" [%3d] Signature: 0x%s Sections: "),
6851 i, dwarf_vmatoa64 (signature_high, signature_low,
6852 buf, sizeof (buf)));
6855 if (shndx_list >= limit)
6857 warn (_("Section %s too small for shndx pool\n"),
6861 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
6865 printf (" %d", shndx);
6867 add_shndx_to_cu_tu_entry (shndx);
6879 else if (version == 2)
6882 unsigned int dw_sect;
6883 unsigned char *ph = phash;
6884 unsigned char *pi = pindex;
6885 unsigned char *poffsets = ppool + ncols * 4;
6886 unsigned char *psizes = poffsets + nused * ncols * 4;
6887 unsigned char *pend = psizes + nused * ncols * 4;
6888 bfd_boolean is_tu_index;
6889 struct cu_tu_set *this_set = NULL;
6891 unsigned char *prow;
6893 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6897 warn (_("Section %s too small for offset and size tables\n"),
6904 printf (_(" Offset table\n"));
6905 printf (" slot %-16s ",
6906 is_tu_index ? _("signature") : _("dwo_id"));
6913 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6919 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6926 for (j = 0; j < ncols; j++)
6928 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
6929 printf (" %8s", get_DW_SECT_short_name (dw_sect));
6934 for (i = 0; i < nslots; i++)
6936 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
6938 SAFE_BYTE_GET (row, pi, 4, limit);
6941 /* PR 17531: file: a05f6ab3. */
6944 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
6950 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6952 prow = poffsets + (row - 1) * ncols * 4;
6955 printf (_(" [%3d] 0x%s"),
6956 i, dwarf_vmatoa64 (signature_high, signature_low,
6957 buf, sizeof (buf)));
6958 for (j = 0; j < ncols; j++)
6960 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
6962 printf (" %8d", val);
6965 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
6966 this_set [row - 1].section_offsets [dw_sect] = val;
6982 printf (_(" Size table\n"));
6983 printf (" slot %-16s ",
6984 is_tu_index ? _("signature") : _("dwo_id"));
6987 for (j = 0; j < ncols; j++)
6989 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
6991 printf (" %8s", get_DW_SECT_short_name (val));
6997 for (i = 0; i < nslots; i++)
6999 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7001 SAFE_BYTE_GET (row, pi, 4, limit);
7004 prow = psizes + (row - 1) * ncols * 4;
7007 printf (_(" [%3d] 0x%s"),
7008 i, dwarf_vmatoa64 (signature_high, signature_low,
7009 buf, sizeof (buf)));
7011 for (j = 0; j < ncols; j++)
7013 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7015 printf (" %8d", val);
7018 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7019 this_set [row - 1].section_sizes [dw_sect] = val;
7031 else if (do_display)
7032 printf (_(" Unsupported version (%d)\n"), version);
7040 /* Load the CU and TU indexes if present. This will build a list of
7041 section sets that we can use to associate a .debug_info.dwo section
7042 with its associated .debug_abbrev.dwo section in a .dwp file. */
7045 load_cu_tu_indexes (void *file)
7047 /* If we have already loaded (or tried to load) the CU and TU indexes
7048 then do not bother to repeat the task. */
7049 if (cu_tu_indexes_read)
7052 if (load_debug_section (dwp_cu_index, file))
7053 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
7055 if (load_debug_section (dwp_tu_index, file))
7056 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
7058 cu_tu_indexes_read = 1;
7061 /* Find the set of sections that includes section SHNDX. */
7064 find_cu_tu_set (void *file, unsigned int shndx)
7068 load_cu_tu_indexes (file);
7070 /* Find SHNDX in the shndx pool. */
7071 for (i = 0; i < shndx_pool_used; i++)
7072 if (shndx_pool [i] == shndx)
7075 if (i >= shndx_pool_used)
7078 /* Now backup to find the first entry in the set. */
7079 while (i > 0 && shndx_pool [i - 1] != 0)
7082 return shndx_pool + i;
7085 /* Display a .debug_cu_index or .debug_tu_index section. */
7088 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
7090 return process_cu_tu_index (section, 1);
7094 display_debug_not_supported (struct dwarf_section *section,
7095 void *file ATTRIBUTE_UNUSED)
7097 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7104 cmalloc (size_t nmemb, size_t size)
7106 /* Check for overflow. */
7107 if (nmemb >= ~(size_t) 0 / size)
7110 return malloc (nmemb * size);
7114 xcmalloc (size_t nmemb, size_t size)
7116 /* Check for overflow. */
7117 if (nmemb >= ~(size_t) 0 / size)
7120 return xmalloc (nmemb * size);
7124 xcrealloc (void *ptr, size_t nmemb, size_t size)
7126 /* Check for overflow. */
7127 if (nmemb >= ~(size_t) 0 / size)
7130 return xrealloc (ptr, nmemb * size);
7134 free_debug_memory (void)
7140 for (i = 0; i < max; i++)
7141 free_debug_section ((enum dwarf_section_display_enum) i);
7143 if (debug_information != NULL)
7145 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
7147 for (i = 0; i < num_debug_info_entries; i++)
7149 if (!debug_information [i].max_loc_offsets)
7151 free (debug_information [i].loc_offsets);
7152 free (debug_information [i].have_frame_base);
7154 if (!debug_information [i].max_range_lists)
7155 free (debug_information [i].range_lists);
7159 free (debug_information);
7160 debug_information = NULL;
7161 num_debug_info_entries = 0;
7166 dwarf_select_sections_by_names (const char *names)
7170 const char * option;
7174 debug_dump_long_opts;
7176 static const debug_dump_long_opts opts_table [] =
7178 /* Please keep this table alpha- sorted. */
7179 { "Ranges", & do_debug_ranges, 1 },
7180 { "abbrev", & do_debug_abbrevs, 1 },
7181 { "addr", & do_debug_addr, 1 },
7182 { "aranges", & do_debug_aranges, 1 },
7183 { "cu_index", & do_debug_cu_index, 1 },
7184 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
7185 { "frames", & do_debug_frames, 1 },
7186 { "frames-interp", & do_debug_frames_interp, 1 },
7187 /* The special .gdb_index section. */
7188 { "gdb_index", & do_gdb_index, 1 },
7189 { "info", & do_debug_info, 1 },
7190 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
7191 { "loc", & do_debug_loc, 1 },
7192 { "macro", & do_debug_macinfo, 1 },
7193 { "pubnames", & do_debug_pubnames, 1 },
7194 { "pubtypes", & do_debug_pubtypes, 1 },
7195 /* This entry is for compatability
7196 with earlier versions of readelf. */
7197 { "ranges", & do_debug_aranges, 1 },
7198 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
7199 { "str", & do_debug_str, 1 },
7200 /* These trace_* sections are used by Itanium VMS. */
7201 { "trace_abbrev", & do_trace_abbrevs, 1 },
7202 { "trace_aranges", & do_trace_aranges, 1 },
7203 { "trace_info", & do_trace_info, 1 },
7212 const debug_dump_long_opts * entry;
7214 for (entry = opts_table; entry->option; entry++)
7216 size_t len = strlen (entry->option);
7218 if (strncmp (p, entry->option, len) == 0
7219 && (p[len] == ',' || p[len] == '\0'))
7221 * entry->variable |= entry->val;
7223 /* The --debug-dump=frames-interp option also
7224 enables the --debug-dump=frames option. */
7225 if (do_debug_frames_interp)
7226 do_debug_frames = 1;
7233 if (entry->option == NULL)
7235 warn (_("Unrecognized debug option '%s'\n"), p);
7236 p = strchr (p, ',');
7247 dwarf_select_sections_by_letters (const char *letters)
7249 unsigned int lindex = 0;
7251 while (letters[lindex])
7252 switch (letters[lindex++])
7259 do_debug_abbrevs = 1;
7263 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
7267 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
7271 do_debug_pubnames = 1;
7275 do_debug_pubtypes = 1;
7279 do_debug_aranges = 1;
7283 do_debug_ranges = 1;
7287 do_debug_frames_interp = 1;
7289 do_debug_frames = 1;
7293 do_debug_macinfo = 1;
7305 warn (_("Unrecognized debug option '%s'\n"), optarg);
7311 dwarf_select_sections_all (void)
7314 do_debug_abbrevs = 1;
7315 do_debug_lines = FLAG_DEBUG_LINES_RAW;
7316 do_debug_pubnames = 1;
7317 do_debug_pubtypes = 1;
7318 do_debug_aranges = 1;
7319 do_debug_ranges = 1;
7320 do_debug_frames = 1;
7321 do_debug_macinfo = 1;
7326 do_trace_abbrevs = 1;
7327 do_trace_aranges = 1;
7329 do_debug_cu_index = 1;
7332 struct dwarf_section_display debug_displays[] =
7334 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL },
7335 display_debug_abbrev, &do_debug_abbrevs, 0 },
7336 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL },
7337 display_debug_aranges, &do_debug_aranges, 1 },
7338 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL },
7339 display_debug_frames, &do_debug_frames, 1 },
7340 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL },
7341 display_debug_info, &do_debug_info, 1 },
7342 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL },
7343 display_debug_lines, &do_debug_lines, 1 },
7344 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL },
7345 display_debug_pubnames, &do_debug_pubnames, 0 },
7346 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL },
7347 display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
7348 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL },
7349 display_debug_frames, &do_debug_frames, 1 },
7350 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL },
7351 display_debug_macinfo, &do_debug_macinfo, 0 },
7352 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL },
7353 display_debug_macro, &do_debug_macinfo, 1 },
7354 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL },
7355 display_debug_str, &do_debug_str, 0 },
7356 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL },
7357 display_debug_loc, &do_debug_loc, 1 },
7358 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7359 display_debug_pubnames, &do_debug_pubtypes, 0 },
7360 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7361 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
7362 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL },
7363 display_debug_ranges, &do_debug_ranges, 1 },
7364 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL },
7365 display_debug_not_supported, NULL, 0 },
7366 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL },
7367 display_debug_not_supported, NULL, 0 },
7368 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL },
7369 display_debug_types, &do_debug_info, 1 },
7370 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL },
7371 display_debug_not_supported, NULL, 0 },
7372 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL },
7373 display_gdb_index, &do_gdb_index, 0 },
7374 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL },
7375 display_trace_info, &do_trace_info, 1 },
7376 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL },
7377 display_debug_abbrev, &do_trace_abbrevs, 0 },
7378 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL },
7379 display_debug_aranges, &do_trace_aranges, 0 },
7380 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7381 display_debug_info, &do_debug_info, 1 },
7382 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL },
7383 display_debug_abbrev, &do_debug_abbrevs, 0 },
7384 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7385 display_debug_types, &do_debug_info, 1 },
7386 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL },
7387 display_debug_lines, &do_debug_lines, 1 },
7388 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL },
7389 display_debug_loc, &do_debug_loc, 1 },
7390 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL },
7391 display_debug_macro, &do_debug_macinfo, 1 },
7392 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL },
7393 display_debug_macinfo, &do_debug_macinfo, 0 },
7394 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL },
7395 display_debug_str, &do_debug_str, 1 },
7396 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL },
7397 display_debug_str_offsets, NULL, 0 },
7398 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL },
7399 display_debug_str_offsets, NULL, 0 },
7400 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL },
7401 display_debug_addr, &do_debug_addr, 1 },
7402 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL },
7403 display_cu_index, &do_debug_cu_index, 0 },
7404 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL },
7405 display_cu_index, &do_debug_cu_index, 0 },