1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2017 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
35 #define MAX(a, b) ((a) > (b) ? (a) : (b))
36 #define MIN(a, b) ((a) < (b) ? (a) : (b))
38 static const char *regname (unsigned int regno, int row);
40 static int have_frame_base;
41 static int need_base_address;
43 static unsigned int num_debug_info_entries = 0;
44 static unsigned int alloc_num_debug_info_entries = 0;
45 static debug_info *debug_information = NULL;
46 /* Special value for num_debug_info_entries to indicate
47 that the .debug_info section could not be loaded/parsed. */
48 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
50 unsigned int eh_addr_size;
55 int do_debug_pubnames;
56 int do_debug_pubtypes;
60 int do_debug_frames_interp;
69 int do_debug_cu_index;
72 int dwarf_cutoff_level = -1;
73 unsigned long dwarf_start_die;
77 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
78 testing whether e.g. a locview list is present. */
79 static const dwarf_vma vm1 = -1;
81 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
82 sections. For version 1 package files, each set is stored in SHNDX_POOL
83 as a zero-terminated list of section indexes comprising one set of debug
84 sections from a .dwo file. */
86 static unsigned int *shndx_pool = NULL;
87 static unsigned int shndx_pool_size = 0;
88 static unsigned int shndx_pool_used = 0;
90 /* For version 2 package files, each set contains an array of section offsets
91 and an array of section sizes, giving the offset and size of the
92 contribution from a CU or TU within one of the debug sections.
93 When displaying debug info from a package file, we need to use these
94 tables to locate the corresponding contributions to each section. */
99 dwarf_vma section_offsets[DW_SECT_MAX];
100 size_t section_sizes[DW_SECT_MAX];
103 static int cu_count = 0;
104 static int tu_count = 0;
105 static struct cu_tu_set *cu_sets = NULL;
106 static struct cu_tu_set *tu_sets = NULL;
108 static bfd_boolean load_cu_tu_indexes (void *);
110 /* Values for do_debug_lines. */
111 #define FLAG_DEBUG_LINES_RAW 1
112 #define FLAG_DEBUG_LINES_DECODED 2
115 size_of_encoded_value (int encoding)
117 switch (encoding & 0x7)
120 case 0: return eh_addr_size;
128 get_encoded_value (unsigned char **pdata,
130 struct dwarf_section *section,
133 unsigned char * data = * pdata;
134 unsigned int size = size_of_encoded_value (encoding);
137 if (data + size >= end)
139 warn (_("Encoded value extends past end of section\n"));
144 /* PR 17512: file: 002-829853-0.004. */
147 warn (_("Encoded size of %d is too large to read\n"), size);
152 /* PR 17512: file: 1085-5603-0.004. */
155 warn (_("Encoded size of 0 is too small to read\n"));
160 if (encoding & DW_EH_PE_signed)
161 val = byte_get_signed (data, size);
163 val = byte_get (data, size);
165 if ((encoding & 0x70) == DW_EH_PE_pcrel)
166 val += section->address + (data - section->start);
168 * pdata = data + size;
172 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
174 # define DWARF_VMA_FMT "ll"
175 # define DWARF_VMA_FMT_LONG "%16.16llx"
177 # define DWARF_VMA_FMT "I64"
178 # define DWARF_VMA_FMT_LONG "%016I64x"
181 # define DWARF_VMA_FMT "l"
182 # define DWARF_VMA_FMT_LONG "%16.16lx"
185 /* Convert a dwarf vma value into a string. Returns a pointer to a static
186 buffer containing the converted VALUE. The value is converted according
187 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
188 it specifies the maximum number of bytes to be displayed in the converted
189 value and FMTCH is ignored - hex is always used. */
192 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
194 /* As dwarf_vmatoa is used more then once in a printf call
195 for output, we are cycling through an fixed array of pointers
196 for return address. */
197 static int buf_pos = 0;
198 static struct dwarf_vmatoa_buf
204 ret = buf[buf_pos++].place;
205 buf_pos %= ARRAY_SIZE (buf);
209 /* Printf does not have a way of specifying a maximum field width for an
210 integer value, so we print the full value into a buffer and then select
211 the precision we need. */
212 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
215 return ret + (16 - 2 * num_bytes);
222 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
224 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
225 snprintf (ret, sizeof (buf[0].place), fmt, value);
230 static inline const char *
231 dwarf_vmatoa (const char * fmtch, dwarf_vma value)
233 return dwarf_vmatoa_1 (fmtch, value, 0);
236 /* Print a dwarf_vma value (typically an address, offset or length) in
237 hexadecimal format, followed by a space. The length of the VALUE (and
238 hence the precision displayed) is determined by the NUM_BYTES parameter. */
241 print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
243 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
246 /* Print a view number in hexadecimal value, with the same width
247 print_dwarf_vma would have printed it with the same num_bytes.
248 Print blanks for zero view, unless force is nonzero. */
251 print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
259 assert (value == (unsigned long) value);
261 printf ("v%0*lx ", len - 1, (unsigned long) value);
263 printf ("%*s", len + 1, "");
266 /* Format a 64-bit value, given as two 32-bit values, in hex.
267 For reentrancy, this uses a buffer provided by the caller. */
270 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
271 unsigned int buf_len)
276 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
279 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
280 snprintf (buf + len, buf_len - len,
281 "%08" DWARF_VMA_FMT "x", lvalue);
287 /* Read in a LEB128 encoded value starting at address DATA.
288 If SIGN is true, return a signed LEB128 value.
289 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
290 No bytes will be read at address END or beyond. */
293 read_leb128 (unsigned char *data,
294 unsigned int *length_return,
296 const unsigned char * const end)
298 dwarf_vma result = 0;
299 unsigned int num_read = 0;
300 unsigned int shift = 0;
301 unsigned char byte = 0;
308 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
311 if ((byte & 0x80) == 0)
314 /* PR 17512: file: 0ca183b8.
315 FIXME: Should we signal this error somehow ? */
316 if (shift >= sizeof (result) * 8)
320 if (length_return != NULL)
321 *length_return = num_read;
323 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
324 result |= -((dwarf_vma) 1 << shift);
329 /* Create a signed version to avoid painful typecasts. */
330 static inline dwarf_signed_vma
331 read_sleb128 (unsigned char * data,
332 unsigned int * length_return,
333 const unsigned char * const end)
335 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
338 static inline dwarf_vma
339 read_uleb128 (unsigned char * data,
340 unsigned int * length_return,
341 const unsigned char * const end)
343 return read_leb128 (data, length_return, FALSE, end);
346 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
347 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
349 #define READ_ULEB(var) \
354 (var) = _val = read_uleb128 (start, &length_return, end); \
356 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
357 __FILE__, __LINE__, _val); \
358 start += length_return; \
362 #define READ_SLEB(var) \
365 dwarf_signed_vma _val; \
367 (var) = _val = read_sleb128 (start, &length_return, end); \
369 error (_("Internal error: %s%d: LEB value (%#" DWARF_VMA_FMT "x) too large for containing variable\n"), \
370 __FILE__, __LINE__, _val); \
371 start += length_return; \
375 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
378 unsigned int amount = (AMOUNT); \
379 if (sizeof (VAL) < amount) \
381 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
382 amount, (int) sizeof (VAL)); \
383 amount = sizeof (VAL); \
385 if (((PTR) + amount) >= (END)) \
388 amount = (END) - (PTR); \
392 if (amount == 0 || amount > 8) \
395 VAL = byte_get ((PTR), amount); \
399 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
402 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
407 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
410 unsigned int amount = (AMOUNT); \
411 if (((PTR) + amount) >= (END)) \
414 amount = (END) - (PTR); \
419 VAL = byte_get_signed ((PTR), amount); \
425 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
428 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
433 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
436 if (((PTR) + 8) <= (END)) \
438 byte_get_64 ((PTR), (HIGH), (LOW)); \
442 * (LOW) = * (HIGH) = 0; \
447 typedef struct State_Machine_Registers
456 unsigned char op_index;
457 unsigned char end_sequence;
458 /* This variable hold the number of the last entry seen
459 in the File Table. */
460 unsigned int last_file_entry;
463 static SMR state_machine_regs;
466 reset_state_machine (int is_stmt)
468 state_machine_regs.address = 0;
469 state_machine_regs.view = 0;
470 state_machine_regs.op_index = 0;
471 state_machine_regs.file = 1;
472 state_machine_regs.line = 1;
473 state_machine_regs.column = 0;
474 state_machine_regs.is_stmt = is_stmt;
475 state_machine_regs.basic_block = 0;
476 state_machine_regs.end_sequence = 0;
477 state_machine_regs.last_file_entry = 0;
480 /* Handled an extend line op.
481 Returns the number of bytes read. */
484 process_extended_line_op (unsigned char * data,
488 unsigned char op_code;
489 unsigned int bytes_read;
492 unsigned char *orig_data = data;
495 len = read_uleb128 (data, & bytes_read, end);
498 if (len == 0 || data == end || len > (uintptr_t) (end - data))
500 warn (_("Badly formed extended line op encountered!\n"));
507 printf (_(" Extended opcode %d: "), op_code);
511 case DW_LNE_end_sequence:
512 printf (_("End of Sequence\n\n"));
513 reset_state_machine (is_stmt);
516 case DW_LNE_set_address:
517 /* PR 17512: file: 002-100480-0.004. */
518 if (len - bytes_read - 1 > 8)
520 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
521 len - bytes_read - 1);
525 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
526 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
527 state_machine_regs.address = adr;
528 state_machine_regs.view = 0;
529 state_machine_regs.op_index = 0;
532 case DW_LNE_define_file:
533 printf (_("define new File Table entry\n"));
534 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
535 printf (" %d\t", ++state_machine_regs.last_file_entry);
541 l = strnlen ((char *) data, end - data);
543 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
545 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
547 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
549 printf ("%.*s\n\n", (int) l, name);
552 if (((unsigned int) (data - orig_data) != len) || data == end)
553 warn (_("DW_LNE_define_file: Bad opcode length\n"));
556 case DW_LNE_set_discriminator:
557 printf (_("set Discriminator to %s\n"),
558 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
562 case DW_LNE_HP_negate_is_UV_update:
563 printf ("DW_LNE_HP_negate_is_UV_update\n");
565 case DW_LNE_HP_push_context:
566 printf ("DW_LNE_HP_push_context\n");
568 case DW_LNE_HP_pop_context:
569 printf ("DW_LNE_HP_pop_context\n");
571 case DW_LNE_HP_set_file_line_column:
572 printf ("DW_LNE_HP_set_file_line_column\n");
574 case DW_LNE_HP_set_routine_name:
575 printf ("DW_LNE_HP_set_routine_name\n");
577 case DW_LNE_HP_set_sequence:
578 printf ("DW_LNE_HP_set_sequence\n");
580 case DW_LNE_HP_negate_post_semantics:
581 printf ("DW_LNE_HP_negate_post_semantics\n");
583 case DW_LNE_HP_negate_function_exit:
584 printf ("DW_LNE_HP_negate_function_exit\n");
586 case DW_LNE_HP_negate_front_end_logical:
587 printf ("DW_LNE_HP_negate_front_end_logical\n");
589 case DW_LNE_HP_define_proc:
590 printf ("DW_LNE_HP_define_proc\n");
592 case DW_LNE_HP_source_file_correlation:
594 unsigned char *edata = data + len - bytes_read - 1;
596 printf ("DW_LNE_HP_source_file_correlation\n");
602 opc = read_uleb128 (data, & bytes_read, edata);
607 case DW_LNE_HP_SFC_formfeed:
608 printf (" DW_LNE_HP_SFC_formfeed\n");
610 case DW_LNE_HP_SFC_set_listing_line:
611 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
613 read_uleb128 (data, & bytes_read, edata)));
616 case DW_LNE_HP_SFC_associate:
617 printf (" DW_LNE_HP_SFC_associate ");
620 read_uleb128 (data, & bytes_read, edata)));
624 read_uleb128 (data, & bytes_read, edata)));
628 read_uleb128 (data, & bytes_read, edata)));
632 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
642 unsigned int rlen = len - bytes_read - 1;
644 if (op_code >= DW_LNE_lo_user
645 /* The test against DW_LNW_hi_user is redundant due to
646 the limited range of the unsigned char data type used
648 /*&& op_code <= DW_LNE_hi_user*/)
649 printf (_("user defined: "));
651 printf (_("UNKNOWN: "));
652 printf (_("length %d ["), rlen);
654 printf (" %02x", *data++);
663 static const unsigned char *
664 fetch_indirect_string (dwarf_vma offset)
666 struct dwarf_section *section = &debug_displays [str].section;
667 const unsigned char * ret;
669 if (section->start == NULL)
670 return (const unsigned char *) _("<no .debug_str section>");
672 if (offset >= section->size)
674 warn (_("DW_FORM_strp offset too big: %s\n"),
675 dwarf_vmatoa ("x", offset));
676 return (const unsigned char *) _("<offset is too big>");
679 ret = section->start + offset;
680 /* Unfortunately we cannot rely upon the .debug_str section ending with a
681 NUL byte. Since our caller is expecting to receive a well formed C
682 string we test for the lack of a terminating byte here. */
683 if (strnlen ((const char *) ret, section->size - offset)
684 == section->size - offset)
685 ret = (const unsigned char *)
686 _("<no NUL byte at end of .debug_str section>");
691 static const unsigned char *
692 fetch_indirect_line_string (dwarf_vma offset)
694 struct dwarf_section *section = &debug_displays [line_str].section;
695 const unsigned char * ret;
697 if (section->start == NULL)
698 return (const unsigned char *) _("<no .debug_line_str section>");
700 if (offset >= section->size)
702 warn (_("DW_FORM_line_strp offset too big: %s\n"),
703 dwarf_vmatoa ("x", offset));
704 return (const unsigned char *) _("<offset is too big>");
707 ret = section->start + offset;
708 /* Unfortunately we cannot rely upon the .debug_line_str section ending
709 with a NUL byte. Since our caller is expecting to receive a well formed
710 C string we test for the lack of a terminating byte here. */
711 if (strnlen ((const char *) ret, section->size - offset)
712 == section->size - offset)
713 ret = (const unsigned char *)
714 _("<no NUL byte at end of .debug_line_str section>");
720 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
721 dwarf_vma offset_size, int dwo)
723 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
724 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
725 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
726 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
727 dwarf_vma index_offset = idx * offset_size;
728 dwarf_vma str_offset;
731 if (index_section->start == NULL)
732 return (dwo ? _("<no .debug_str_offsets.dwo section>")
733 : _("<no .debug_str_offsets section>"));
735 if (this_set != NULL)
736 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
737 if (index_offset >= index_section->size)
739 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
740 dwarf_vmatoa ("x", index_offset));
741 return _("<index offset is too big>");
744 if (str_section->start == NULL)
745 return (dwo ? _("<no .debug_str.dwo section>")
746 : _("<no .debug_str section>"));
748 str_offset = byte_get (index_section->start + index_offset, offset_size);
749 str_offset -= str_section->address;
750 if (str_offset >= str_section->size)
752 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
753 dwarf_vmatoa ("x", str_offset));
754 return _("<indirect index offset is too big>");
757 ret = (const char *) str_section->start + str_offset;
758 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
759 Since our caller is expecting to receive a well formed C string we test
760 for the lack of a terminating byte here. */
761 if (strnlen (ret, str_section->size - str_offset)
762 == str_section->size - str_offset)
763 ret = (const char *) _("<no NUL byte at end of section>");
769 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
771 struct dwarf_section *section = &debug_displays [debug_addr].section;
773 if (section->start == NULL)
774 return (_("<no .debug_addr section>"));
776 if (offset + bytes > section->size)
778 warn (_("Offset into section %s too big: %s\n"),
779 section->name, dwarf_vmatoa ("x", offset));
780 return "<offset too big>";
783 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
787 /* FIXME: There are better and more efficient ways to handle
788 these structures. For now though, I just want something that
789 is simple to implement. */
790 typedef struct abbrev_attr
792 unsigned long attribute;
794 bfd_signed_vma implicit_const;
795 struct abbrev_attr *next;
799 typedef struct abbrev_entry
804 struct abbrev_attr *first_attr;
805 struct abbrev_attr *last_attr;
806 struct abbrev_entry *next;
810 static abbrev_entry *first_abbrev = NULL;
811 static abbrev_entry *last_abbrev = NULL;
818 for (abbrv = first_abbrev; abbrv;)
820 abbrev_entry *next_abbrev = abbrv->next;
823 for (attr = abbrv->first_attr; attr;)
825 abbrev_attr *next_attr = attr->next;
835 last_abbrev = first_abbrev = NULL;
839 add_abbrev (unsigned long number, unsigned long tag, int children)
843 entry = (abbrev_entry *) malloc (sizeof (*entry));
848 entry->entry = number;
850 entry->children = children;
851 entry->first_attr = NULL;
852 entry->last_attr = NULL;
855 if (first_abbrev == NULL)
856 first_abbrev = entry;
858 last_abbrev->next = entry;
864 add_abbrev_attr (unsigned long attribute, unsigned long form,
865 bfd_signed_vma implicit_const)
869 attr = (abbrev_attr *) malloc (sizeof (*attr));
874 attr->attribute = attribute;
876 attr->implicit_const = implicit_const;
879 if (last_abbrev->first_attr == NULL)
880 last_abbrev->first_attr = attr;
882 last_abbrev->last_attr->next = attr;
884 last_abbrev->last_attr = attr;
887 /* Processes the (partial) contents of a .debug_abbrev section.
888 Returns NULL if the end of the section was encountered.
889 Returns the address after the last byte read if the end of
890 an abbreviation set was found. */
892 static unsigned char *
893 process_abbrev_section (unsigned char *start, unsigned char *end)
895 if (first_abbrev != NULL)
900 unsigned int bytes_read;
903 unsigned long attribute;
906 entry = read_uleb128 (start, & bytes_read, end);
909 /* A single zero is supposed to end the section according
910 to the standard. If there's more, then signal that to
917 tag = read_uleb128 (start, & bytes_read, end);
924 add_abbrev (entry, tag, children);
929 /* Initialize it due to a false compiler warning. */
930 bfd_signed_vma implicit_const = -1;
932 attribute = read_uleb128 (start, & bytes_read, end);
937 form = read_uleb128 (start, & bytes_read, end);
942 if (form == DW_FORM_implicit_const)
944 implicit_const = read_sleb128 (start, & bytes_read, end);
950 add_abbrev_attr (attribute, form, implicit_const);
952 while (attribute != 0);
955 /* Report the missing single zero which ends the section. */
956 error (_(".debug_abbrev section not zero terminated\n"));
962 get_TAG_name (unsigned long tag)
964 const char *name = get_DW_TAG_name ((unsigned int)tag);
968 static char buffer[100];
970 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
978 get_FORM_name (unsigned long form)
983 return "DW_FORM value: 0";
985 name = get_DW_FORM_name (form);
988 static char buffer[100];
990 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
998 get_IDX_name (unsigned long idx)
1000 const char *name = get_DW_IDX_name ((unsigned int) idx);
1004 static char buffer[100];
1006 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
1013 static unsigned char *
1014 display_block (unsigned char *data,
1016 const unsigned char * const end, char delimiter)
1020 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
1022 return (unsigned char *) end;
1024 maxlen = (dwarf_vma) (end - data);
1025 length = length > maxlen ? maxlen : length;
1028 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1034 decode_location_expression (unsigned char * data,
1035 unsigned int pointer_size,
1036 unsigned int offset_size,
1039 dwarf_vma cu_offset,
1040 struct dwarf_section * section)
1043 unsigned int bytes_read;
1045 dwarf_signed_vma svalue;
1046 unsigned char *end = data + length;
1047 int need_frame_base = 0;
1056 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1057 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
1060 printf ("DW_OP_deref");
1063 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1064 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
1067 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1068 printf ("DW_OP_const1s: %ld", (long) svalue);
1071 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1072 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
1075 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1076 printf ("DW_OP_const2s: %ld", (long) svalue);
1079 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1080 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
1083 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1084 printf ("DW_OP_const4s: %ld", (long) svalue);
1087 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1088 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1089 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1090 printf ("%lu", (unsigned long) uvalue);
1093 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1094 printf ("DW_OP_const8s: %ld ", (long) svalue);
1095 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1096 printf ("%ld", (long) svalue);
1099 printf ("DW_OP_constu: %s",
1100 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1104 printf ("DW_OP_consts: %s",
1105 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1109 printf ("DW_OP_dup");
1112 printf ("DW_OP_drop");
1115 printf ("DW_OP_over");
1118 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1119 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
1122 printf ("DW_OP_swap");
1125 printf ("DW_OP_rot");
1128 printf ("DW_OP_xderef");
1131 printf ("DW_OP_abs");
1134 printf ("DW_OP_and");
1137 printf ("DW_OP_div");
1140 printf ("DW_OP_minus");
1143 printf ("DW_OP_mod");
1146 printf ("DW_OP_mul");
1149 printf ("DW_OP_neg");
1152 printf ("DW_OP_not");
1155 printf ("DW_OP_or");
1158 printf ("DW_OP_plus");
1160 case DW_OP_plus_uconst:
1161 printf ("DW_OP_plus_uconst: %s",
1162 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1166 printf ("DW_OP_shl");
1169 printf ("DW_OP_shr");
1172 printf ("DW_OP_shra");
1175 printf ("DW_OP_xor");
1178 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1179 printf ("DW_OP_bra: %ld", (long) svalue);
1182 printf ("DW_OP_eq");
1185 printf ("DW_OP_ge");
1188 printf ("DW_OP_gt");
1191 printf ("DW_OP_le");
1194 printf ("DW_OP_lt");
1197 printf ("DW_OP_ne");
1200 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1201 printf ("DW_OP_skip: %ld", (long) svalue);
1236 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1271 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1272 regname (op - DW_OP_reg0, 1));
1307 printf ("DW_OP_breg%d (%s): %s",
1309 regname (op - DW_OP_breg0, 1),
1310 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1315 uvalue = read_uleb128 (data, &bytes_read, end);
1317 printf ("DW_OP_regx: %s (%s)",
1318 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1321 need_frame_base = 1;
1322 printf ("DW_OP_fbreg: %s",
1323 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1327 uvalue = read_uleb128 (data, &bytes_read, end);
1329 printf ("DW_OP_bregx: %s (%s) %s",
1330 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1331 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
1335 printf ("DW_OP_piece: %s",
1336 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1339 case DW_OP_deref_size:
1340 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1341 printf ("DW_OP_deref_size: %ld", (long) uvalue);
1343 case DW_OP_xderef_size:
1344 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1345 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
1348 printf ("DW_OP_nop");
1351 /* DWARF 3 extensions. */
1352 case DW_OP_push_object_address:
1353 printf ("DW_OP_push_object_address");
1356 /* XXX: Strictly speaking for 64-bit DWARF3 files
1357 this ought to be an 8-byte wide computation. */
1358 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1359 printf ("DW_OP_call2: <0x%s>",
1360 dwarf_vmatoa ("x", svalue + cu_offset));
1363 /* XXX: Strictly speaking for 64-bit DWARF3 files
1364 this ought to be an 8-byte wide computation. */
1365 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1366 printf ("DW_OP_call4: <0x%s>",
1367 dwarf_vmatoa ("x", svalue + cu_offset));
1369 case DW_OP_call_ref:
1370 /* XXX: Strictly speaking for 64-bit DWARF3 files
1371 this ought to be an 8-byte wide computation. */
1372 if (dwarf_version == -1)
1374 printf (_("(DW_OP_call_ref in frame info)"));
1375 /* No way to tell where the next op is, so just bail. */
1376 return need_frame_base;
1378 if (dwarf_version == 2)
1380 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1384 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1386 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
1388 case DW_OP_form_tls_address:
1389 printf ("DW_OP_form_tls_address");
1391 case DW_OP_call_frame_cfa:
1392 printf ("DW_OP_call_frame_cfa");
1394 case DW_OP_bit_piece:
1395 printf ("DW_OP_bit_piece: ");
1396 printf (_("size: %s "),
1397 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1399 printf (_("offset: %s "),
1400 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
1404 /* DWARF 4 extensions. */
1405 case DW_OP_stack_value:
1406 printf ("DW_OP_stack_value");
1409 case DW_OP_implicit_value:
1410 printf ("DW_OP_implicit_value");
1411 uvalue = read_uleb128 (data, &bytes_read, end);
1413 data = display_block (data, uvalue, end, ' ');
1416 /* GNU extensions. */
1417 case DW_OP_GNU_push_tls_address:
1418 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1420 case DW_OP_GNU_uninit:
1421 printf ("DW_OP_GNU_uninit");
1422 /* FIXME: Is there data associated with this OP ? */
1424 case DW_OP_GNU_encoded_addr:
1431 addr = get_encoded_value (&data, encoding, section, end);
1433 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1434 print_dwarf_vma (addr, pointer_size);
1437 case DW_OP_implicit_pointer:
1438 case DW_OP_GNU_implicit_pointer:
1439 /* XXX: Strictly speaking for 64-bit DWARF3 files
1440 this ought to be an 8-byte wide computation. */
1441 if (dwarf_version == -1)
1443 printf (_("(%s in frame info)"),
1444 (op == DW_OP_implicit_pointer
1445 ? "DW_OP_implicit_pointer"
1446 : "DW_OP_GNU_implicit_pointer"));
1447 /* No way to tell where the next op is, so just bail. */
1448 return need_frame_base;
1450 if (dwarf_version == 2)
1452 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1456 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1458 printf ("%s: <0x%s> %s",
1459 (op == DW_OP_implicit_pointer
1460 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1461 dwarf_vmatoa ("x", uvalue),
1462 dwarf_vmatoa ("d", read_sleb128 (data,
1463 &bytes_read, end)));
1466 case DW_OP_entry_value:
1467 case DW_OP_GNU_entry_value:
1468 uvalue = read_uleb128 (data, &bytes_read, end);
1470 /* PR 17531: file: 0cc9cd00. */
1471 if (uvalue > (dwarf_vma) (end - data))
1472 uvalue = end - data;
1473 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1474 : "DW_OP_GNU_entry_value"));
1475 if (decode_location_expression (data, pointer_size, offset_size,
1476 dwarf_version, uvalue,
1477 cu_offset, section))
1478 need_frame_base = 1;
1484 case DW_OP_const_type:
1485 case DW_OP_GNU_const_type:
1486 uvalue = read_uleb128 (data, &bytes_read, end);
1488 printf ("%s: <0x%s> ",
1489 (op == DW_OP_const_type ? "DW_OP_const_type"
1490 : "DW_OP_GNU_const_type"),
1491 dwarf_vmatoa ("x", cu_offset + uvalue));
1492 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1493 data = display_block (data, uvalue, end, ' ');
1495 case DW_OP_regval_type:
1496 case DW_OP_GNU_regval_type:
1497 uvalue = read_uleb128 (data, &bytes_read, end);
1499 printf ("%s: %s (%s)",
1500 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1501 : "DW_OP_GNU_regval_type"),
1502 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1503 uvalue = read_uleb128 (data, &bytes_read, end);
1505 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1507 case DW_OP_deref_type:
1508 case DW_OP_GNU_deref_type:
1509 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1511 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1512 : "DW_OP_GNU_deref_type"),
1514 uvalue = read_uleb128 (data, &bytes_read, end);
1516 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1519 case DW_OP_GNU_convert:
1520 uvalue = read_uleb128 (data, &bytes_read, end);
1522 printf ("%s <0x%s>",
1523 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
1524 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1526 case DW_OP_reinterpret:
1527 case DW_OP_GNU_reinterpret:
1528 uvalue = read_uleb128 (data, &bytes_read, end);
1530 printf ("%s <0x%s>",
1531 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1532 : "DW_OP_GNU_reinterpret"),
1533 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1535 case DW_OP_GNU_parameter_ref:
1536 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1537 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1538 dwarf_vmatoa ("x", cu_offset + uvalue));
1540 case DW_OP_GNU_addr_index:
1541 uvalue = read_uleb128 (data, &bytes_read, end);
1543 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1545 case DW_OP_GNU_const_index:
1546 uvalue = read_uleb128 (data, &bytes_read, end);
1548 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1551 /* HP extensions. */
1552 case DW_OP_HP_is_value:
1553 printf ("DW_OP_HP_is_value");
1554 /* FIXME: Is there data associated with this OP ? */
1556 case DW_OP_HP_fltconst4:
1557 printf ("DW_OP_HP_fltconst4");
1558 /* FIXME: Is there data associated with this OP ? */
1560 case DW_OP_HP_fltconst8:
1561 printf ("DW_OP_HP_fltconst8");
1562 /* FIXME: Is there data associated with this OP ? */
1564 case DW_OP_HP_mod_range:
1565 printf ("DW_OP_HP_mod_range");
1566 /* FIXME: Is there data associated with this OP ? */
1568 case DW_OP_HP_unmod_range:
1569 printf ("DW_OP_HP_unmod_range");
1570 /* FIXME: Is there data associated with this OP ? */
1573 printf ("DW_OP_HP_tls");
1574 /* FIXME: Is there data associated with this OP ? */
1577 /* PGI (STMicroelectronics) extensions. */
1578 case DW_OP_PGI_omp_thread_num:
1579 /* Pushes the thread number for the current thread as it would be
1580 returned by the standard OpenMP library function:
1581 omp_get_thread_num(). The "current thread" is the thread for
1582 which the expression is being evaluated. */
1583 printf ("DW_OP_PGI_omp_thread_num");
1587 if (op >= DW_OP_lo_user
1588 && op <= DW_OP_hi_user)
1589 printf (_("(User defined location op 0x%x)"), op);
1591 printf (_("(Unknown location op 0x%x)"), op);
1592 /* No way to tell where the next op is, so just bail. */
1593 return need_frame_base;
1596 /* Separate the ops. */
1601 return need_frame_base;
1604 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1605 This is used for DWARF package files. */
1607 static struct cu_tu_set *
1608 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1610 struct cu_tu_set *p;
1612 unsigned int dw_sect;
1618 dw_sect = DW_SECT_TYPES;
1624 dw_sect = DW_SECT_INFO;
1628 if (p->section_offsets [dw_sect] == cu_offset)
1636 /* Add INC to HIGH_BITS:LOW_BITS. */
1638 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1640 dwarf_vma tmp = * low_bits;
1644 /* FIXME: There is probably a better way of handling this:
1646 We need to cope with dwarf_vma being a 32-bit or 64-bit
1647 type. Plus regardless of its size LOW_BITS is meant to
1648 only hold 32-bits, so if there is overflow or wrap around
1649 we must propagate into HIGH_BITS. */
1650 if (tmp < * low_bits)
1654 else if (sizeof (tmp) > 8
1664 static unsigned char *
1665 read_and_display_attr_value (unsigned long attribute,
1667 dwarf_signed_vma implicit_const,
1668 unsigned char * data,
1669 unsigned char * end,
1670 dwarf_vma cu_offset,
1671 dwarf_vma pointer_size,
1672 dwarf_vma offset_size,
1674 debug_info * debug_info_p,
1676 struct dwarf_section * section,
1677 struct cu_tu_set * this_set, char delimiter)
1679 dwarf_vma uvalue = 0;
1680 unsigned char *block_start = NULL;
1681 unsigned char * orig_data = data;
1682 unsigned int bytes_read;
1684 if (data > end || (data == end && form != DW_FORM_flag_present))
1686 warn (_("Corrupt attribute\n"));
1695 case DW_FORM_ref_addr:
1696 if (dwarf_version == 2)
1697 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1698 else if (dwarf_version == 3 || dwarf_version == 4)
1699 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1701 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1706 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1710 case DW_FORM_line_strp:
1711 case DW_FORM_sec_offset:
1712 case DW_FORM_GNU_ref_alt:
1713 case DW_FORM_GNU_strp_alt:
1714 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1717 case DW_FORM_flag_present:
1724 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1729 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
1734 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1738 uvalue = read_sleb128 (data, & bytes_read, end);
1742 case DW_FORM_GNU_str_index:
1743 uvalue = read_uleb128 (data, & bytes_read, end);
1747 case DW_FORM_ref_udata:
1749 uvalue = read_uleb128 (data, & bytes_read, end);
1753 case DW_FORM_indirect:
1754 form = read_uleb128 (data, & bytes_read, end);
1757 printf ("%c%s", delimiter, get_FORM_name (form));
1758 if (form == DW_FORM_implicit_const)
1760 implicit_const = read_sleb128 (data, & bytes_read, end);
1763 return read_and_display_attr_value (attribute, form, implicit_const, data,
1764 end, cu_offset, pointer_size,
1765 offset_size, dwarf_version,
1766 debug_info_p, do_loc,
1767 section, this_set, delimiter);
1768 case DW_FORM_GNU_addr_index:
1769 uvalue = read_uleb128 (data, & bytes_read, end);
1776 case DW_FORM_ref_addr:
1778 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1781 case DW_FORM_GNU_ref_alt:
1783 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
1789 case DW_FORM_ref_udata:
1791 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
1796 case DW_FORM_sec_offset:
1798 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
1801 case DW_FORM_flag_present:
1808 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
1811 case DW_FORM_implicit_const:
1813 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1820 dwarf_vma high_bits;
1824 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1826 if (form == DW_FORM_ref8)
1827 add64 (& high_bits, & utmp, cu_offset);
1828 printf ("%c0x%s", delimiter,
1829 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
1832 if ((do_loc || do_debug_loc || do_debug_ranges)
1833 && num_debug_info_entries == 0)
1835 if (sizeof (uvalue) == 8)
1836 SAFE_BYTE_GET (uvalue, data, 8, end);
1838 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1844 case DW_FORM_data16:
1847 dwarf_vma left_high_bits, left_low_bits;
1848 dwarf_vma right_high_bits, right_low_bits;
1850 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1851 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1852 if (byte_get == byte_get_little_endian)
1855 left_high_bits ^= right_high_bits;
1856 right_high_bits ^= left_high_bits;
1857 left_high_bits ^= right_high_bits;
1858 left_low_bits ^= right_low_bits;
1859 right_low_bits ^= left_low_bits;
1860 left_low_bits ^= right_low_bits;
1862 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1863 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1864 left_high_bits, left_low_bits, right_high_bits,
1870 case DW_FORM_string:
1872 printf ("%c%.*s", delimiter, (int) (end - data), data);
1873 data += strnlen ((char *) data, end - data) + 1;
1877 case DW_FORM_exprloc:
1878 uvalue = read_uleb128 (data, & bytes_read, end);
1879 block_start = data + bytes_read;
1880 if (block_start >= end)
1882 warn (_("Block ends prematurely\n"));
1886 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1887 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1888 block_start + uvalue here. */
1889 data = block_start + uvalue;
1890 /* PR 17512: file: 008-103549-0.001:0.1. */
1891 if (block_start + uvalue > end || data < block_start)
1893 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1894 uvalue = end - block_start;
1897 data = block_start + uvalue;
1899 data = display_block (block_start, uvalue, end, delimiter);
1902 case DW_FORM_block1:
1903 SAFE_BYTE_GET (uvalue, data, 1, end);
1904 block_start = data + 1;
1905 if (block_start >= end)
1907 warn (_("Block ends prematurely\n"));
1911 data = block_start + uvalue;
1912 if (block_start + uvalue > end || data < block_start)
1914 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1915 uvalue = end - block_start;
1918 data = block_start + uvalue;
1920 data = display_block (block_start, uvalue, end, delimiter);
1923 case DW_FORM_block2:
1924 SAFE_BYTE_GET (uvalue, data, 2, end);
1925 block_start = data + 2;
1926 if (block_start >= end)
1928 warn (_("Block ends prematurely\n"));
1932 data = block_start + uvalue;
1933 if (block_start + uvalue > end || data < block_start)
1935 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1936 uvalue = end - block_start;
1939 data = block_start + uvalue;
1941 data = display_block (block_start, uvalue, end, delimiter);
1944 case DW_FORM_block4:
1945 SAFE_BYTE_GET (uvalue, data, 4, end);
1946 block_start = data + 4;
1947 /* PR 17512: file: 3371-3907-0.004. */
1948 if (block_start >= end)
1950 warn (_("Block ends prematurely\n"));
1954 data = block_start + uvalue;
1955 if (block_start + uvalue > end
1956 /* PR 17531: file: 5b5f0592. */
1957 || data < block_start)
1959 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1960 uvalue = end - block_start;
1963 data = block_start + uvalue;
1965 data = display_block (block_start, uvalue, end, delimiter);
1970 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
1971 dwarf_vmatoa ("x", uvalue),
1972 fetch_indirect_string (uvalue));
1975 case DW_FORM_line_strp:
1977 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
1978 dwarf_vmatoa ("x", uvalue),
1979 fetch_indirect_line_string (uvalue));
1982 case DW_FORM_GNU_str_index:
1985 const char *suffix = strrchr (section->name, '.');
1986 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1988 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
1989 dwarf_vmatoa ("x", uvalue),
1990 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1994 case DW_FORM_GNU_strp_alt:
1996 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter,
1997 dwarf_vmatoa ("x", uvalue));
2000 case DW_FORM_indirect:
2001 /* Handled above. */
2004 case DW_FORM_ref_sig8:
2007 dwarf_vma high_bits;
2010 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
2011 printf ("%csignature: 0x%s", delimiter,
2012 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2017 case DW_FORM_GNU_addr_index:
2019 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
2020 dwarf_vmatoa ("x", uvalue),
2021 fetch_indexed_value (uvalue * pointer_size, pointer_size));
2025 warn (_("Unrecognized form: %lu\n"), form);
2029 if ((do_loc || do_debug_loc || do_debug_ranges)
2030 && num_debug_info_entries == 0
2031 && debug_info_p != NULL)
2035 case DW_AT_frame_base:
2036 have_frame_base = 1;
2038 case DW_AT_location:
2039 case DW_AT_GNU_locviews:
2040 case DW_AT_string_length:
2041 case DW_AT_return_addr:
2042 case DW_AT_data_member_location:
2043 case DW_AT_vtable_elem_location:
2045 case DW_AT_static_link:
2046 case DW_AT_use_location:
2047 case DW_AT_call_value:
2048 case DW_AT_GNU_call_site_value:
2049 case DW_AT_call_data_value:
2050 case DW_AT_GNU_call_site_data_value:
2051 case DW_AT_call_target:
2052 case DW_AT_GNU_call_site_target:
2053 case DW_AT_call_target_clobbered:
2054 case DW_AT_GNU_call_site_target_clobbered:
2055 if ((dwarf_version < 4
2056 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2057 || form == DW_FORM_sec_offset)
2059 /* Process location list. */
2060 unsigned int lmax = debug_info_p->max_loc_offsets;
2061 unsigned int num = debug_info_p->num_loc_offsets;
2063 if (lmax == 0 || num >= lmax)
2066 debug_info_p->loc_offsets = (dwarf_vma *)
2067 xcrealloc (debug_info_p->loc_offsets,
2068 lmax, sizeof (*debug_info_p->loc_offsets));
2069 debug_info_p->loc_views = (dwarf_vma *)
2070 xcrealloc (debug_info_p->loc_views,
2071 lmax, sizeof (*debug_info_p->loc_views));
2072 debug_info_p->have_frame_base = (int *)
2073 xcrealloc (debug_info_p->have_frame_base,
2074 lmax, sizeof (*debug_info_p->have_frame_base));
2075 debug_info_p->max_loc_offsets = lmax;
2077 if (this_set != NULL)
2078 uvalue += this_set->section_offsets [DW_SECT_LOC];
2079 debug_info_p->have_frame_base [num] = have_frame_base;
2080 if (attribute != DW_AT_GNU_locviews)
2082 debug_info_p->loc_offsets [num] = uvalue;
2083 debug_info_p->num_loc_offsets++;
2084 assert (debug_info_p->num_loc_offsets
2085 - debug_info_p->num_loc_views <= 1);
2089 assert (debug_info_p->num_loc_views <= num);
2090 num = debug_info_p->num_loc_views;
2091 debug_info_p->loc_views [num] = uvalue;
2092 debug_info_p->num_loc_views++;
2093 assert (debug_info_p->num_loc_views
2094 - debug_info_p->num_loc_offsets <= 1);
2100 if (need_base_address)
2101 debug_info_p->base_address = uvalue;
2104 case DW_AT_GNU_addr_base:
2105 debug_info_p->addr_base = uvalue;
2108 case DW_AT_GNU_ranges_base:
2109 debug_info_p->ranges_base = uvalue;
2113 if ((dwarf_version < 4
2114 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2115 || form == DW_FORM_sec_offset)
2117 /* Process range list. */
2118 unsigned int lmax = debug_info_p->max_range_lists;
2119 unsigned int num = debug_info_p->num_range_lists;
2121 if (lmax == 0 || num >= lmax)
2124 debug_info_p->range_lists = (dwarf_vma *)
2125 xcrealloc (debug_info_p->range_lists,
2126 lmax, sizeof (*debug_info_p->range_lists));
2127 debug_info_p->max_range_lists = lmax;
2129 debug_info_p->range_lists [num] = uvalue;
2130 debug_info_p->num_range_lists++;
2139 if (do_loc || attribute == 0)
2142 /* For some attributes we can display further information. */
2149 case DW_INL_not_inlined:
2150 printf (_("(not inlined)"));
2152 case DW_INL_inlined:
2153 printf (_("(inlined)"));
2155 case DW_INL_declared_not_inlined:
2156 printf (_("(declared as inline but ignored)"));
2158 case DW_INL_declared_inlined:
2159 printf (_("(declared as inline and inlined)"));
2162 printf (_(" (Unknown inline attribute value: %s)"),
2163 dwarf_vmatoa ("x", uvalue));
2168 case DW_AT_language:
2172 /* Ordered by the numeric value of these constants. */
2173 case DW_LANG_C89: printf ("(ANSI C)"); break;
2174 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2175 case DW_LANG_Ada83: printf ("(Ada)"); break;
2176 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
2177 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2178 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
2179 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2180 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
2181 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
2182 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
2183 /* DWARF 2.1 values. */
2184 case DW_LANG_Java: printf ("(Java)"); break;
2185 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2186 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2187 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
2188 /* DWARF 3 values. */
2189 case DW_LANG_PLI: printf ("(PLI)"); break;
2190 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2191 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2192 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2193 case DW_LANG_D: printf ("(D)"); break;
2194 /* DWARF 4 values. */
2195 case DW_LANG_Python: printf ("(Python)"); break;
2196 /* DWARF 5 values. */
2197 case DW_LANG_Go: printf ("(Go)"); break;
2198 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2199 case DW_LANG_C11: printf ("(C11)"); break;
2200 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
2201 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2202 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2203 /* MIPS extension. */
2204 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2205 /* UPC extension. */
2206 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2208 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
2209 printf (_("(implementation defined: %s)"),
2210 dwarf_vmatoa ("x", uvalue));
2212 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
2217 case DW_AT_encoding:
2221 case DW_ATE_void: printf ("(void)"); break;
2222 case DW_ATE_address: printf ("(machine address)"); break;
2223 case DW_ATE_boolean: printf ("(boolean)"); break;
2224 case DW_ATE_complex_float: printf ("(complex float)"); break;
2225 case DW_ATE_float: printf ("(float)"); break;
2226 case DW_ATE_signed: printf ("(signed)"); break;
2227 case DW_ATE_signed_char: printf ("(signed char)"); break;
2228 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2229 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
2230 /* DWARF 2.1 values: */
2231 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2232 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
2233 /* DWARF 3 values: */
2234 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2235 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2236 case DW_ATE_edited: printf ("(edited)"); break;
2237 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2238 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
2239 /* HP extensions: */
2240 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2241 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2242 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2243 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2244 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2245 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2246 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2247 /* DWARF 4 values: */
2248 case DW_ATE_UTF: printf ("(unicode string)"); break;
2251 if (uvalue >= DW_ATE_lo_user
2252 && uvalue <= DW_ATE_hi_user)
2253 printf (_("(user defined type)"));
2255 printf (_("(unknown type)"));
2260 case DW_AT_accessibility:
2264 case DW_ACCESS_public: printf ("(public)"); break;
2265 case DW_ACCESS_protected: printf ("(protected)"); break;
2266 case DW_ACCESS_private: printf ("(private)"); break;
2268 printf (_("(unknown accessibility)"));
2273 case DW_AT_visibility:
2277 case DW_VIS_local: printf ("(local)"); break;
2278 case DW_VIS_exported: printf ("(exported)"); break;
2279 case DW_VIS_qualified: printf ("(qualified)"); break;
2280 default: printf (_("(unknown visibility)")); break;
2284 case DW_AT_virtuality:
2288 case DW_VIRTUALITY_none: printf ("(none)"); break;
2289 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2290 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
2291 default: printf (_("(unknown virtuality)")); break;
2295 case DW_AT_identifier_case:
2299 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2300 case DW_ID_up_case: printf ("(up_case)"); break;
2301 case DW_ID_down_case: printf ("(down_case)"); break;
2302 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
2303 default: printf (_("(unknown case)")); break;
2307 case DW_AT_calling_convention:
2311 case DW_CC_normal: printf ("(normal)"); break;
2312 case DW_CC_program: printf ("(program)"); break;
2313 case DW_CC_nocall: printf ("(nocall)"); break;
2315 if (uvalue >= DW_CC_lo_user
2316 && uvalue <= DW_CC_hi_user)
2317 printf (_("(user defined)"));
2319 printf (_("(unknown convention)"));
2323 case DW_AT_ordering:
2327 case -1: printf (_("(undefined)")); break;
2328 case 0: printf ("(row major)"); break;
2329 case 1: printf ("(column major)"); break;
2333 case DW_AT_frame_base:
2334 have_frame_base = 1;
2336 case DW_AT_location:
2337 case DW_AT_string_length:
2338 case DW_AT_return_addr:
2339 case DW_AT_data_member_location:
2340 case DW_AT_vtable_elem_location:
2342 case DW_AT_static_link:
2343 case DW_AT_use_location:
2344 case DW_AT_call_value:
2345 case DW_AT_GNU_call_site_value:
2346 case DW_AT_call_data_value:
2347 case DW_AT_GNU_call_site_data_value:
2348 case DW_AT_call_target:
2349 case DW_AT_GNU_call_site_target:
2350 case DW_AT_call_target_clobbered:
2351 case DW_AT_GNU_call_site_target_clobbered:
2352 if ((dwarf_version < 4
2353 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2354 || form == DW_FORM_sec_offset)
2355 printf (_(" (location list)"));
2357 case DW_AT_allocated:
2358 case DW_AT_associated:
2359 case DW_AT_data_location:
2361 case DW_AT_upper_bound:
2362 case DW_AT_lower_bound:
2365 int need_frame_base;
2368 need_frame_base = decode_location_expression (block_start,
2373 cu_offset, section);
2375 if (need_frame_base && !have_frame_base)
2376 printf (_(" [without DW_AT_frame_base]"));
2382 if (form == DW_FORM_ref_sig8
2383 || form == DW_FORM_GNU_ref_alt)
2386 if (form == DW_FORM_ref1
2387 || form == DW_FORM_ref2
2388 || form == DW_FORM_ref4
2389 || form == DW_FORM_ref_udata)
2390 uvalue += cu_offset;
2392 if (uvalue >= section->size)
2393 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2394 dwarf_vmatoa ("x", uvalue),
2395 (unsigned long) (orig_data - section->start));
2398 unsigned long abbrev_number;
2399 abbrev_entry * entry;
2401 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2403 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2404 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2405 use different abbrev table, and we don't track .debug_info chunks
2407 if (form != DW_FORM_ref_addr)
2409 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2410 if (entry->entry == abbrev_number)
2413 printf (" (%s)", get_TAG_name (entry->tag));
2428 get_AT_name (unsigned long attribute)
2433 return "DW_AT value: 0";
2435 /* One value is shared by the MIPS and HP extensions: */
2436 if (attribute == DW_AT_MIPS_fde)
2437 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2439 name = get_DW_AT_name (attribute);
2443 static char buffer[100];
2445 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2453 static unsigned char *
2454 read_and_display_attr (unsigned long attribute,
2456 dwarf_signed_vma implicit_const,
2457 unsigned char * data,
2458 unsigned char * end,
2459 dwarf_vma cu_offset,
2460 dwarf_vma pointer_size,
2461 dwarf_vma offset_size,
2463 debug_info * debug_info_p,
2465 struct dwarf_section * section,
2466 struct cu_tu_set * this_set)
2469 printf (" %-18s:", get_AT_name (attribute));
2470 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
2471 cu_offset, pointer_size, offset_size,
2472 dwarf_version, debug_info_p,
2473 do_loc, section, this_set, ' ');
2479 /* Process the contents of a .debug_info section. If do_loc is non-zero
2480 then we are scanning for location lists and we do not want to display
2481 anything to the user. If do_types is non-zero, we are processing
2482 a .debug_types section instead of a .debug_info section. */
2485 process_debug_info (struct dwarf_section *section,
2487 enum dwarf_section_display_enum abbrev_sec,
2491 unsigned char *start = section->start;
2492 unsigned char *end = start + section->size;
2493 unsigned char *section_begin;
2495 unsigned int num_units = 0;
2497 if ((do_loc || do_debug_loc || do_debug_ranges)
2498 && num_debug_info_entries == 0
2503 /* First scan the section to get the number of comp units. */
2504 for (section_begin = start, num_units = 0; section_begin < end;
2507 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2508 will be the length. For a 64-bit DWARF section, it'll be
2509 the escape code 0xffffffff followed by an 8 byte length. */
2510 SAFE_BYTE_GET (length, section_begin, 4, end);
2512 if (length == 0xffffffff)
2514 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2515 section_begin += length + 12;
2517 else if (length >= 0xfffffff0 && length < 0xffffffff)
2519 warn (_("Reserved length value (0x%s) found in section %s\n"),
2520 dwarf_vmatoa ("x", length), section->name);
2524 section_begin += length + 4;
2526 /* Negative values are illegal, they may even cause infinite
2527 looping. This can happen if we can't accurately apply
2528 relocations to an object file, or if the file is corrupt. */
2529 if ((signed long) length <= 0 || section_begin < start)
2531 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2532 dwarf_vmatoa ("x", length), section->name);
2539 error (_("No comp units in %s section ?\n"), section->name);
2543 /* Then allocate an array to hold the information. */
2544 debug_information = (debug_info *) cmalloc (num_units,
2545 sizeof (* debug_information));
2546 if (debug_information == NULL)
2548 error (_("Not enough memory for a debug info array of %u entries\n"),
2550 alloc_num_debug_info_entries = num_debug_info_entries = 0;
2553 /* PR 17531: file: 92ca3797.
2554 We cannot rely upon the debug_information array being initialised
2555 before it is used. A corrupt file could easily contain references
2556 to a unit for which information has not been made available. So
2557 we ensure that the array is zeroed here. */
2558 memset (debug_information, 0, num_units * sizeof (*debug_information));
2560 alloc_num_debug_info_entries = num_units;
2565 if (dwarf_start_die == 0)
2566 printf (_("Contents of the %s section:\n\n"), section->name);
2568 load_debug_section (str, file);
2569 load_debug_section (line_str, file);
2570 load_debug_section (str_dwo, file);
2571 load_debug_section (str_index, file);
2572 load_debug_section (str_index_dwo, file);
2573 load_debug_section (debug_addr, file);
2576 load_debug_section (abbrev_sec, file);
2577 if (debug_displays [abbrev_sec].section.start == NULL)
2579 warn (_("Unable to locate %s section!\n"),
2580 debug_displays [abbrev_sec].section.name);
2584 for (section_begin = start, unit = 0; start < end; unit++)
2586 DWARF2_Internal_CompUnit compunit;
2587 unsigned char *hdrptr;
2588 unsigned char *tags;
2589 int level, last_level, saved_level;
2590 dwarf_vma cu_offset;
2591 unsigned int offset_size;
2592 int initial_length_size;
2593 dwarf_vma signature_high = 0;
2594 dwarf_vma signature_low = 0;
2595 dwarf_vma type_offset = 0;
2596 struct cu_tu_set *this_set;
2597 dwarf_vma abbrev_base;
2602 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2604 if (compunit.cu_length == 0xffffffff)
2606 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2608 initial_length_size = 12;
2613 initial_length_size = 4;
2616 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2618 cu_offset = start - section_begin;
2620 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2622 if (compunit.cu_version < 5)
2624 compunit.cu_unit_type = DW_UT_compile;
2625 /* Initialize it due to a false compiler warning. */
2626 compunit.cu_pointer_size = -1;
2630 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2631 do_types = (compunit.cu_unit_type == DW_UT_type);
2633 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2636 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2638 if (this_set == NULL)
2641 abbrev_size = debug_displays [abbrev_sec].section.size;
2645 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2646 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2649 if (compunit.cu_version < 5)
2650 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2652 /* PR 17512: file: 001-108546-0.001:0.1. */
2653 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2655 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2656 compunit.cu_pointer_size, offset_size);
2657 compunit.cu_pointer_size = offset_size;
2662 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2664 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2667 if ((do_loc || do_debug_loc || do_debug_ranges)
2668 && num_debug_info_entries == 0
2671 debug_information [unit].cu_offset = cu_offset;
2672 debug_information [unit].pointer_size
2673 = compunit.cu_pointer_size;
2674 debug_information [unit].offset_size = offset_size;
2675 debug_information [unit].dwarf_version = compunit.cu_version;
2676 debug_information [unit].base_address = 0;
2677 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2678 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2679 debug_information [unit].loc_offsets = NULL;
2680 debug_information [unit].have_frame_base = NULL;
2681 debug_information [unit].max_loc_offsets = 0;
2682 debug_information [unit].num_loc_offsets = 0;
2683 debug_information [unit].range_lists = NULL;
2684 debug_information [unit].max_range_lists= 0;
2685 debug_information [unit].num_range_lists = 0;
2688 if (!do_loc && dwarf_start_die == 0)
2690 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2691 dwarf_vmatoa ("x", cu_offset));
2692 printf (_(" Length: 0x%s (%s)\n"),
2693 dwarf_vmatoa ("x", compunit.cu_length),
2694 offset_size == 8 ? "64-bit" : "32-bit");
2695 printf (_(" Version: %d\n"), compunit.cu_version);
2696 printf (_(" Abbrev Offset: 0x%s\n"),
2697 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2698 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2703 printf (_(" Signature: 0x%s\n"),
2704 dwarf_vmatoa64 (signature_high, signature_low,
2705 buf, sizeof (buf)));
2706 printf (_(" Type Offset: 0x%s\n"),
2707 dwarf_vmatoa ("x", type_offset));
2709 if (this_set != NULL)
2711 dwarf_vma *offsets = this_set->section_offsets;
2712 size_t *sizes = this_set->section_sizes;
2714 printf (_(" Section contributions:\n"));
2715 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2716 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2717 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2718 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2719 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2720 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2721 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2722 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2723 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2724 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2725 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2726 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2730 if (cu_offset + compunit.cu_length + initial_length_size
2733 warn (_("Debug info is corrupted, length of CU at %s"
2734 " extends beyond end of section (length = %s)\n"),
2735 dwarf_vmatoa ("x", cu_offset),
2736 dwarf_vmatoa ("x", compunit.cu_length));
2741 start += compunit.cu_length + initial_length_size;
2745 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2746 dwarf_vmatoa ("x", cu_offset));
2750 if (compunit.cu_version < 2 || compunit.cu_version > 5)
2752 warn (_("CU at offset %s contains corrupt or "
2753 "unsupported version number: %d.\n"),
2754 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2758 if (compunit.cu_unit_type != DW_UT_compile
2759 && compunit.cu_unit_type != DW_UT_type)
2761 warn (_("CU at offset %s contains corrupt or "
2762 "unsupported unit type: %d.\n"),
2763 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2769 /* Process the abbrevs used by this compilation unit. */
2770 if (compunit.cu_abbrev_offset >= abbrev_size)
2771 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2772 (unsigned long) compunit.cu_abbrev_offset,
2773 (unsigned long) abbrev_size);
2774 /* PR 17531: file:4bcd9ce9. */
2775 else if ((abbrev_base + abbrev_size)
2776 > debug_displays [abbrev_sec].section.size)
2777 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2778 (unsigned long) abbrev_base + abbrev_size,
2779 (unsigned long) debug_displays [abbrev_sec].section.size);
2781 process_abbrev_section
2782 (((unsigned char *) debug_displays [abbrev_sec].section.start
2783 + abbrev_base + compunit.cu_abbrev_offset),
2784 ((unsigned char *) debug_displays [abbrev_sec].section.start
2785 + abbrev_base + abbrev_size));
2790 while (tags < start)
2792 unsigned int bytes_read;
2793 unsigned long abbrev_number;
2794 unsigned long die_offset;
2795 abbrev_entry *entry;
2797 int do_printing = 1;
2799 die_offset = tags - section_begin;
2801 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2804 /* A null DIE marks the end of a list of siblings or it may also be
2805 a section padding. */
2806 if (abbrev_number == 0)
2808 /* Check if it can be a section padding for the last CU. */
2809 if (level == 0 && start == end)
2813 for (chk = tags; chk < start; chk++)
2820 if (!do_loc && die_offset >= dwarf_start_die
2821 && (dwarf_cutoff_level == -1
2822 || level < dwarf_cutoff_level))
2823 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2829 static unsigned num_bogus_warns = 0;
2831 if (num_bogus_warns < 3)
2833 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2834 die_offset, section->name);
2836 if (num_bogus_warns == 3)
2837 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2840 if (dwarf_start_die != 0 && level < saved_level)
2847 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2851 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2852 saved_level = level;
2853 do_printing = (dwarf_cutoff_level == -1
2854 || level < dwarf_cutoff_level);
2856 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2857 level, die_offset, abbrev_number);
2858 else if (dwarf_cutoff_level == -1
2859 || last_level < dwarf_cutoff_level)
2860 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2865 /* Scan through the abbreviation list until we reach the
2867 for (entry = first_abbrev;
2868 entry && entry->entry != abbrev_number;
2869 entry = entry->next)
2874 if (!do_loc && do_printing)
2879 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2880 die_offset, abbrev_number);
2884 if (!do_loc && do_printing)
2885 printf (" (%s)\n", get_TAG_name (entry->tag));
2890 need_base_address = 0;
2892 case DW_TAG_compile_unit:
2893 need_base_address = 1;
2895 case DW_TAG_entry_point:
2896 case DW_TAG_subprogram:
2897 need_base_address = 0;
2898 /* Assuming that there is no DW_AT_frame_base. */
2899 have_frame_base = 0;
2903 debug_info *debug_info_p =
2904 (debug_information && unit < alloc_num_debug_info_entries)
2905 ? debug_information + unit : NULL;
2907 assert (!debug_info_p
2908 || (debug_info_p->num_loc_offsets
2909 == debug_info_p->num_loc_views));
2911 for (attr = entry->first_attr;
2912 attr && attr->attribute;
2915 if (! do_loc && do_printing)
2916 /* Show the offset from where the tag was extracted. */
2917 printf (" <%lx>", (unsigned long)(tags - section_begin));
2919 tags = read_and_display_attr (attr->attribute,
2921 attr->implicit_const,
2925 compunit.cu_pointer_size,
2927 compunit.cu_version,
2929 do_loc || ! do_printing,
2934 /* If a locview attribute appears before a location one,
2935 make sure we don't associate it with an earlier
2938 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
2941 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
2942 debug_info_p->num_loc_views++;
2943 assert (debug_info_p->num_loc_views
2944 == debug_info_p->num_loc_offsets);
2951 warn(_("DIE has locviews without loclist\n"));
2952 debug_info_p->num_loc_views--;
2959 if (entry->children)
2964 /* Set num_debug_info_entries here so that it can be used to check if
2965 we need to process .debug_loc and .debug_ranges sections. */
2966 if ((do_loc || do_debug_loc || do_debug_ranges)
2967 && num_debug_info_entries == 0
2970 if (num_units > alloc_num_debug_info_entries)
2971 num_debug_info_entries = alloc_num_debug_info_entries;
2973 num_debug_info_entries = num_units;
2982 /* Locate and scan the .debug_info section in the file and record the pointer
2983 sizes and offsets for the compilation units in it. Usually an executable
2984 will have just one pointer size, but this is not guaranteed, and so we try
2985 not to make any assumptions. Returns zero upon failure, or the number of
2986 compilation units upon success. */
2989 load_debug_info (void * file)
2991 /* If we have already tried and failed to load the .debug_info
2992 section then do not bother to repeat the task. */
2993 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2996 /* If we already have the information there is nothing else to do. */
2997 if (num_debug_info_entries > 0)
2998 return num_debug_info_entries;
3000 /* If this is a DWARF package file, load the CU and TU indexes. */
3001 (void) load_cu_tu_indexes (file);
3003 if (load_debug_section (info, file)
3004 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
3005 return num_debug_info_entries;
3007 if (load_debug_section (info_dwo, file)
3008 && process_debug_info (&debug_displays [info_dwo].section, file,
3010 return num_debug_info_entries;
3012 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
3016 /* Read a DWARF .debug_line section header starting at DATA.
3017 Upon success returns an updated DATA pointer and the LINFO
3018 structure and the END_OF_SEQUENCE pointer will be filled in.
3019 Otherwise returns NULL. */
3021 static unsigned char *
3022 read_debug_line_header (struct dwarf_section * section,
3023 unsigned char * data,
3024 unsigned char * end,
3025 DWARF2_Internal_LineInfo * linfo,
3026 unsigned char ** end_of_sequence)
3028 unsigned char *hdrptr;
3029 unsigned int initial_length_size;
3030 unsigned char address_size, segment_selector_size;
3032 /* Extract information from the Line Number Program Header.
3033 (section 6.2.4 in the Dwarf3 doc). */
3036 /* Get and check the length of the block. */
3037 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
3039 if (linfo->li_length == 0xffffffff)
3041 /* This section is 64-bit DWARF 3. */
3042 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
3043 linfo->li_offset_size = 8;
3044 initial_length_size = 12;
3048 linfo->li_offset_size = 4;
3049 initial_length_size = 4;
3052 if (linfo->li_length + initial_length_size > section->size)
3054 /* If the length field has a relocation against it, then we should
3055 not complain if it is inaccurate (and probably negative). This
3056 happens in object files when the .debug_line section is actually
3057 comprised of several different .debug_line.* sections, (some of
3058 which may be removed by linker garbage collection), and a relocation
3059 is used to compute the correct length once that is done. */
3060 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
3062 linfo->li_length = (end - data) - initial_length_size;
3066 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3067 (long) linfo->li_length);
3072 /* Get and check the version number. */
3073 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3075 if (linfo->li_version != 2
3076 && linfo->li_version != 3
3077 && linfo->li_version != 4
3078 && linfo->li_version != 5)
3080 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3081 "is currently supported.\n"));
3085 if (linfo->li_version >= 5)
3087 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3089 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3090 if (segment_selector_size != 0)
3092 warn (_("The %s section contains "
3093 "unsupported segment selector size: %d.\n"),
3094 section->name, segment_selector_size);
3099 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3100 linfo->li_offset_size, end);
3101 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
3103 if (linfo->li_version >= 4)
3105 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
3107 if (linfo->li_max_ops_per_insn == 0)
3109 warn (_("Invalid maximum operations per insn.\n"));
3114 linfo->li_max_ops_per_insn = 1;
3116 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
3117 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
3118 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3119 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
3121 * end_of_sequence = data + linfo->li_length + initial_length_size;
3122 /* PR 17512: file:002-117414-0.004. */
3123 if (* end_of_sequence > end)
3125 warn (_("Line length %s extends beyond end of section\n"),
3126 dwarf_vmatoa ("u", linfo->li_length));
3127 * end_of_sequence = end;
3134 static unsigned char *
3135 display_formatted_table (unsigned char *data,
3136 unsigned char *start, unsigned char *end,
3137 const DWARF2_Internal_LineInfo *linfo,
3138 struct dwarf_section *section, const char *what)
3140 unsigned char *format_start, format_count, *format, formati;
3141 dwarf_vma data_count, datai;
3142 unsigned int bytes_read, namepass, last_entry = 0;
3144 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3145 format_start = data;
3146 for (formati = 0; formati < format_count; formati++)
3148 read_uleb128 (data, & bytes_read, end);
3150 read_uleb128 (data, & bytes_read, end);
3154 warn (_("Corrupt %s format table entry\n"), what);
3159 data_count = read_uleb128 (data, & bytes_read, end);
3163 warn (_("Corrupt %s list\n"), what);
3167 if (data_count == 0)
3169 printf (_("\n The %s Table is empty.\n"), what);
3173 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3174 (long)(data - start));
3176 printf (_(" Entry"));
3177 /* Delay displaying name as the last entry for better screen layout. */
3178 for (namepass = 0; namepass < 2; namepass++)
3180 format = format_start;
3181 for (formati = 0; formati < format_count; formati++)
3183 dwarf_vma content_type;
3185 content_type = read_uleb128 (format, & bytes_read, end);
3186 format += bytes_read;
3187 if ((content_type == DW_LNCT_path) == (namepass == 1))
3188 switch (content_type)
3191 printf (_("\tName"));
3193 case DW_LNCT_directory_index:
3194 printf (_("\tDir"));
3196 case DW_LNCT_timestamp:
3197 printf (_("\tTime"));
3200 printf (_("\tSize"));
3203 printf (_("\tMD5"));
3206 printf (_("\t(Unknown format content type %s)"),
3207 dwarf_vmatoa ("u", content_type));
3209 read_uleb128 (format, & bytes_read, end);
3210 format += bytes_read;
3215 for (datai = 0; datai < data_count; datai++)
3217 unsigned char *datapass = data;
3219 printf (" %d", last_entry++);
3220 /* Delay displaying name as the last entry for better screen layout. */
3221 for (namepass = 0; namepass < 2; namepass++)
3223 format = format_start;
3225 for (formati = 0; formati < format_count; formati++)
3227 dwarf_vma content_type, form;
3229 content_type = read_uleb128 (format, & bytes_read, end);
3230 format += bytes_read;
3231 form = read_uleb128 (format, & bytes_read, end);
3232 format += bytes_read;
3233 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3234 linfo->li_offset_size,
3235 linfo->li_version, NULL,
3236 ((content_type == DW_LNCT_path) != (namepass == 1)),
3237 section, NULL, '\t');
3242 warn (_("Corrupt %s entries list\n"), what);
3251 display_debug_lines_raw (struct dwarf_section *section,
3252 unsigned char *data,
3253 unsigned char *end, void *file)
3255 unsigned char *start = section->start;
3256 int verbose_view = 0;
3258 printf (_("Raw dump of debug contents of section %s:\n\n"),
3263 static DWARF2_Internal_LineInfo saved_linfo;
3264 DWARF2_Internal_LineInfo linfo;
3265 unsigned char *standard_opcodes;
3266 unsigned char *end_of_sequence;
3269 if (const_strneq (section->name, ".debug_line.")
3270 /* Note: the following does not apply to .debug_line.dwo sections.
3271 These are full debug_line sections. */
3272 && strcmp (section->name, ".debug_line.dwo") != 0)
3274 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3275 section containing just the Line Number Statements. They are
3276 created by the assembler and intended to be used alongside gcc's
3277 -ffunction-sections command line option. When the linker's
3278 garbage collection decides to discard a .text.<foo> section it
3279 can then also discard the line number information in .debug_line.<foo>.
3281 Since the section is a fragment it does not have the details
3282 needed to fill out a LineInfo structure, so instead we use the
3283 details from the last full debug_line section that we processed. */
3284 end_of_sequence = end;
3285 standard_opcodes = NULL;
3286 linfo = saved_linfo;
3287 /* PR 17531: file: 0522b371. */
3288 if (linfo.li_line_range == 0)
3290 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3293 reset_state_machine (linfo.li_default_is_stmt);
3297 unsigned char * hdrptr;
3299 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3300 & end_of_sequence)) == NULL)
3303 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3304 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3305 printf (_(" DWARF Version: %d\n"), linfo.li_version);
3306 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
3307 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3308 if (linfo.li_version >= 4)
3309 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3310 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3311 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3312 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3313 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
3315 /* PR 17512: file: 1665-6428-0.004. */
3316 if (linfo.li_line_range == 0)
3318 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3319 linfo.li_line_range = 1;
3322 reset_state_machine (linfo.li_default_is_stmt);
3324 /* Display the contents of the Opcodes table. */
3325 standard_opcodes = hdrptr;
3327 /* PR 17512: file: 002-417945-0.004. */
3328 if (standard_opcodes + linfo.li_opcode_base >= end)
3330 warn (_("Line Base extends beyond end of section\n"));
3334 printf (_("\n Opcodes:\n"));
3336 for (i = 1; i < linfo.li_opcode_base; i++)
3337 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
3339 /* Display the contents of the Directory table. */
3340 data = standard_opcodes + linfo.li_opcode_base - 1;
3342 if (linfo.li_version >= 5)
3344 load_debug_section (line_str, file);
3346 data = display_formatted_table (data, start, end, &linfo, section,
3348 data = display_formatted_table (data, start, end, &linfo, section,
3354 printf (_("\n The Directory Table is empty.\n"));
3357 unsigned int last_dir_entry = 0;
3359 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3360 (long)(data - start));
3362 while (data < end && *data != 0)
3364 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
3366 data += strnlen ((char *) data, end - data) + 1;
3369 /* PR 17512: file: 002-132094-0.004. */
3370 if (data >= end - 1)
3374 /* Skip the NUL at the end of the table. */
3377 /* Display the contents of the File Name table. */
3379 printf (_("\n The File Name Table is empty.\n"));
3382 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3383 (long)(data - start));
3384 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3386 while (data < end && *data != 0)
3388 unsigned char *name;
3389 unsigned int bytes_read;
3391 printf (" %d\t", ++state_machine_regs.last_file_entry);
3393 data += strnlen ((char *) data, end - data) + 1;
3396 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3399 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3402 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3404 printf ("%.*s\n", (int)(end - name), name);
3408 warn (_("Corrupt file name table entry\n"));
3414 /* Skip the NUL at the end of the table. */
3419 saved_linfo = linfo;
3422 /* Now display the statements. */
3423 if (data >= end_of_sequence)
3424 printf (_(" No Line Number Statements.\n"));
3427 printf (_(" Line Number Statements:\n"));
3429 while (data < end_of_sequence)
3431 unsigned char op_code;
3432 dwarf_signed_vma adv;
3434 unsigned int bytes_read;
3436 printf (" [0x%08lx]", (long)(data - start));
3440 if (op_code >= linfo.li_opcode_base)
3442 op_code -= linfo.li_opcode_base;
3443 uladv = (op_code / linfo.li_line_range);
3444 if (linfo.li_max_ops_per_insn == 1)
3446 uladv *= linfo.li_min_insn_length;
3447 state_machine_regs.address += uladv;
3449 state_machine_regs.view = 0;
3450 printf (_(" Special opcode %d: "
3451 "advance Address by %s to 0x%s%s"),
3452 op_code, dwarf_vmatoa ("u", uladv),
3453 dwarf_vmatoa ("x", state_machine_regs.address),
3454 verbose_view && uladv
3455 ? _(" (reset view)") : "");
3460 = ((state_machine_regs.op_index + uladv)
3461 / linfo.li_max_ops_per_insn)
3462 * linfo.li_min_insn_length;
3464 state_machine_regs.address += addrdelta;
3465 state_machine_regs.op_index
3466 = (state_machine_regs.op_index + uladv)
3467 % linfo.li_max_ops_per_insn;
3469 state_machine_regs.view = 0;
3470 printf (_(" Special opcode %d: "
3471 "advance Address by %s to 0x%s[%d]%s"),
3472 op_code, dwarf_vmatoa ("u", uladv),
3473 dwarf_vmatoa ("x", state_machine_regs.address),
3474 state_machine_regs.op_index,
3475 verbose_view && addrdelta
3476 ? _(" (reset view)") : "");
3478 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3479 state_machine_regs.line += adv;
3480 printf (_(" and Line by %s to %d"),
3481 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3482 if (verbose_view || state_machine_regs.view)
3483 printf (_(" (view %u)\n"), state_machine_regs.view);
3486 state_machine_regs.view++;
3488 else switch (op_code)
3490 case DW_LNS_extended_op:
3491 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3495 printf (_(" Copy"));
3496 if (verbose_view || state_machine_regs.view)
3497 printf (_(" (view %u)\n"), state_machine_regs.view);
3500 state_machine_regs.view++;
3503 case DW_LNS_advance_pc:
3504 uladv = read_uleb128 (data, & bytes_read, end);
3506 if (linfo.li_max_ops_per_insn == 1)
3508 uladv *= linfo.li_min_insn_length;
3509 state_machine_regs.address += uladv;
3511 state_machine_regs.view = 0;
3512 printf (_(" Advance PC by %s to 0x%s%s\n"),
3513 dwarf_vmatoa ("u", uladv),
3514 dwarf_vmatoa ("x", state_machine_regs.address),
3515 verbose_view && uladv
3516 ? _(" (reset view)") : "");
3521 = ((state_machine_regs.op_index + uladv)
3522 / linfo.li_max_ops_per_insn)
3523 * linfo.li_min_insn_length;
3524 state_machine_regs.address
3526 state_machine_regs.op_index
3527 = (state_machine_regs.op_index + uladv)
3528 % linfo.li_max_ops_per_insn;
3530 state_machine_regs.view = 0;
3531 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3532 dwarf_vmatoa ("u", uladv),
3533 dwarf_vmatoa ("x", state_machine_regs.address),
3534 state_machine_regs.op_index,
3535 verbose_view && addrdelta
3536 ? _(" (reset view)") : "");
3540 case DW_LNS_advance_line:
3541 adv = read_sleb128 (data, & bytes_read, end);
3543 state_machine_regs.line += adv;
3544 printf (_(" Advance Line by %s to %d\n"),
3545 dwarf_vmatoa ("d", adv),
3546 state_machine_regs.line);
3549 case DW_LNS_set_file:
3550 adv = read_uleb128 (data, & bytes_read, end);
3552 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3553 dwarf_vmatoa ("d", adv));
3554 state_machine_regs.file = adv;
3557 case DW_LNS_set_column:
3558 uladv = read_uleb128 (data, & bytes_read, end);
3560 printf (_(" Set column to %s\n"),
3561 dwarf_vmatoa ("u", uladv));
3562 state_machine_regs.column = uladv;
3565 case DW_LNS_negate_stmt:
3566 adv = state_machine_regs.is_stmt;
3568 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3569 state_machine_regs.is_stmt = adv;
3572 case DW_LNS_set_basic_block:
3573 printf (_(" Set basic block\n"));
3574 state_machine_regs.basic_block = 1;
3577 case DW_LNS_const_add_pc:
3578 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3579 if (linfo.li_max_ops_per_insn)
3581 uladv *= linfo.li_min_insn_length;
3582 state_machine_regs.address += uladv;
3584 state_machine_regs.view = 0;
3585 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3586 dwarf_vmatoa ("u", uladv),
3587 dwarf_vmatoa ("x", state_machine_regs.address),
3588 verbose_view && uladv
3589 ? _(" (reset view)") : "");
3594 = ((state_machine_regs.op_index + uladv)
3595 / linfo.li_max_ops_per_insn)
3596 * linfo.li_min_insn_length;
3597 state_machine_regs.address
3599 state_machine_regs.op_index
3600 = (state_machine_regs.op_index + uladv)
3601 % linfo.li_max_ops_per_insn;
3603 state_machine_regs.view = 0;
3604 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3605 dwarf_vmatoa ("u", uladv),
3606 dwarf_vmatoa ("x", state_machine_regs.address),
3607 state_machine_regs.op_index,
3608 verbose_view && addrdelta
3609 ? _(" (reset view)") : "");
3613 case DW_LNS_fixed_advance_pc:
3614 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3615 state_machine_regs.address += uladv;
3616 state_machine_regs.op_index = 0;
3617 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3618 dwarf_vmatoa ("u", uladv),
3619 dwarf_vmatoa ("x", state_machine_regs.address));
3620 /* Do NOT reset view. */
3623 case DW_LNS_set_prologue_end:
3624 printf (_(" Set prologue_end to true\n"));
3627 case DW_LNS_set_epilogue_begin:
3628 printf (_(" Set epilogue_begin to true\n"));
3631 case DW_LNS_set_isa:
3632 uladv = read_uleb128 (data, & bytes_read, end);
3634 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3638 printf (_(" Unknown opcode %d with operands: "), op_code);
3640 if (standard_opcodes != NULL)
3641 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3643 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3645 i == 1 ? "" : ", ");
3661 unsigned char *name;
3662 unsigned int directory_index;
3663 unsigned int modification_date;
3664 unsigned int length;
3667 /* Output a decoded representation of the .debug_line section. */
3670 display_debug_lines_decoded (struct dwarf_section *section,
3671 unsigned char *data,
3672 unsigned char *end, void *fileptr)
3674 static DWARF2_Internal_LineInfo saved_linfo;
3676 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3681 /* This loop amounts to one iteration per compilation unit. */
3682 DWARF2_Internal_LineInfo linfo;
3683 unsigned char *standard_opcodes;
3684 unsigned char *end_of_sequence;
3686 File_Entry *file_table = NULL;
3687 unsigned int n_files = 0;
3688 unsigned char **directory_table = NULL;
3689 dwarf_vma n_directories = 0;
3691 if (const_strneq (section->name, ".debug_line.")
3692 /* Note: the following does not apply to .debug_line.dwo sections.
3693 These are full debug_line sections. */
3694 && strcmp (section->name, ".debug_line.dwo") != 0)
3696 /* See comment in display_debug_lines_raw(). */
3697 end_of_sequence = end;
3698 standard_opcodes = NULL;
3699 linfo = saved_linfo;
3700 /* PR 17531: file: 0522b371. */
3701 if (linfo.li_line_range == 0)
3703 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3706 reset_state_machine (linfo.li_default_is_stmt);
3710 unsigned char *hdrptr;
3712 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3713 & end_of_sequence)) == NULL)
3716 /* PR 17531: file: 0522b371. */
3717 if (linfo.li_line_range == 0)
3719 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3720 linfo.li_line_range = 1;
3722 reset_state_machine (linfo.li_default_is_stmt);
3724 /* Save a pointer to the contents of the Opcodes table. */
3725 standard_opcodes = hdrptr;
3727 /* Traverse the Directory table just to count entries. */
3728 data = standard_opcodes + linfo.li_opcode_base - 1;
3732 warn (_("opcode base of %d extends beyond end of section\n"),
3733 linfo.li_opcode_base);
3737 if (linfo.li_version >= 5)
3739 unsigned char *format_start, format_count, *format;
3740 dwarf_vma formati, entryi;
3741 unsigned int bytes_read;
3743 load_debug_section (line_str, fileptr);
3745 /* Skip directories format. */
3746 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3747 format_start = data;
3748 for (formati = 0; formati < format_count; formati++)
3750 read_uleb128 (data, & bytes_read, end);
3752 read_uleb128 (data, & bytes_read, end);
3756 n_directories = read_uleb128 (data, & bytes_read, end);
3760 warn (_("Corrupt directories list\n"));
3764 directory_table = (unsigned char **)
3765 xmalloc (n_directories * sizeof (unsigned char *));
3767 for (entryi = 0; entryi < n_directories; entryi++)
3769 unsigned char **pathp = &directory_table[entryi];
3771 format = format_start;
3772 for (formati = 0; formati < format_count; formati++)
3774 dwarf_vma content_type, form;
3777 content_type = read_uleb128 (format, & bytes_read, end);
3778 format += bytes_read;
3779 form = read_uleb128 (format, & bytes_read, end);
3780 format += bytes_read;
3783 warn (_("Corrupt directories list\n"));
3786 switch (content_type)
3791 case DW_FORM_string:
3794 case DW_FORM_line_strp:
3795 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3797 /* Remove const by the cast. */
3798 *pathp = (unsigned char *)
3799 fetch_indirect_line_string (uvalue);
3804 data = read_and_display_attr_value (0, form, 0, data, end,
3806 linfo.li_offset_size,
3813 warn (_("Corrupt directories list\n"));
3818 /* Skip files format. */
3819 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3820 format_start = data;
3821 for (formati = 0; formati < format_count; formati++)
3823 read_uleb128 (data, & bytes_read, end);
3825 read_uleb128 (data, & bytes_read, end);
3829 n_files = read_uleb128 (data, & bytes_read, end);
3833 warn (_("Corrupt file name list\n"));
3837 file_table = (File_Entry *) xcalloc (1, n_files
3838 * sizeof (File_Entry));
3840 for (entryi = 0; entryi < n_files; entryi++)
3842 File_Entry *file = &file_table[entryi];
3844 format = format_start;
3845 for (formati = 0; formati < format_count; formati++)
3847 dwarf_vma content_type, form;
3850 content_type = read_uleb128 (format, & bytes_read, end);
3851 format += bytes_read;
3852 form = read_uleb128 (format, & bytes_read, end);
3853 format += bytes_read;
3856 warn (_("Corrupt file name list\n"));
3859 switch (content_type)
3864 case DW_FORM_string:
3867 case DW_FORM_line_strp:
3868 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3870 /* Remove const by the cast. */
3871 file->name = (unsigned char *)
3872 fetch_indirect_line_string (uvalue);
3876 case DW_LNCT_directory_index:
3880 SAFE_BYTE_GET (file->directory_index, data, 1,
3884 SAFE_BYTE_GET (file->directory_index, data, 2,
3888 file->directory_index = read_uleb128 (data, NULL,
3894 data = read_and_display_attr_value (0, form, 0, data, end,
3896 linfo.li_offset_size,
3903 warn (_("Corrupt file name list\n"));
3912 unsigned char *ptr_directory_table = data;
3914 while (data < end && *data != 0)
3916 data += strnlen ((char *) data, end - data) + 1;
3923 warn (_("directory table ends unexpectedly\n"));
3928 /* Go through the directory table again to save the directories. */
3929 directory_table = (unsigned char **)
3930 xmalloc (n_directories * sizeof (unsigned char *));
3933 while (*ptr_directory_table != 0)
3935 directory_table[i] = ptr_directory_table;
3936 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3937 ptr_directory_table - end) + 1;
3941 /* Skip the NUL at the end of the table. */
3944 /* Traverse the File Name table just to count the entries. */
3945 if (data < end && *data != 0)
3947 unsigned char *ptr_file_name_table = data;
3949 while (data < end && *data != 0)
3951 unsigned int bytes_read;
3953 /* Skip Name, directory index, last modification time and length
3955 data += strnlen ((char *) data, end - data) + 1;
3956 read_uleb128 (data, & bytes_read, end);
3958 read_uleb128 (data, & bytes_read, end);
3960 read_uleb128 (data, & bytes_read, end);
3968 warn (_("file table ends unexpectedly\n"));
3973 /* Go through the file table again to save the strings. */
3974 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3977 while (*ptr_file_name_table != 0)
3979 unsigned int bytes_read;
3981 file_table[i].name = ptr_file_name_table;
3982 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3983 end - ptr_file_name_table) + 1;
3985 /* We are not interested in directory, time or size. */
3986 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3988 ptr_file_name_table += bytes_read;
3989 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3991 ptr_file_name_table += bytes_read;
3992 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3993 ptr_file_name_table += bytes_read;
3999 /* Skip the NUL at the end of the table. */
4003 /* Print the Compilation Unit's name and a header. */
4004 if (file_table == NULL)
4006 else if (directory_table == NULL)
4007 printf (_("CU: %s:\n"), file_table[0].name);
4010 unsigned int ix = file_table[0].directory_index;
4011 const char *directory;
4016 else if (n_directories == 0)
4017 directory = _("<unknown>");
4018 else if (ix > n_directories)
4020 warn (_("directory index %u > number of directories %s\n"),
4021 ix, dwarf_vmatoa ("u", n_directories));
4022 directory = _("<corrupt>");
4025 directory = (char *) directory_table[ix - 1];
4027 if (do_wide || strlen (directory) < 76)
4028 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4030 printf ("%s:\n", file_table[0].name);
4033 printf (_("File name Line number Starting address View\n"));
4034 saved_linfo = linfo;
4037 /* This loop iterates through the Dwarf Line Number Program. */
4038 while (data < end_of_sequence)
4040 unsigned char op_code;
4043 unsigned long int uladv;
4044 unsigned int bytes_read;
4045 int is_special_opcode = 0;
4050 if (op_code >= linfo.li_opcode_base)
4052 op_code -= linfo.li_opcode_base;
4053 uladv = (op_code / linfo.li_line_range);
4054 if (linfo.li_max_ops_per_insn == 1)
4056 uladv *= linfo.li_min_insn_length;
4057 state_machine_regs.address += uladv;
4059 state_machine_regs.view = 0;
4064 = ((state_machine_regs.op_index + uladv)
4065 / linfo.li_max_ops_per_insn)
4066 * linfo.li_min_insn_length;
4067 state_machine_regs.address
4069 state_machine_regs.op_index
4070 = (state_machine_regs.op_index + uladv)
4071 % linfo.li_max_ops_per_insn;
4073 state_machine_regs.view = 0;
4076 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4077 state_machine_regs.line += adv;
4078 is_special_opcode = 1;
4079 /* Increment view after printing this row. */
4081 else switch (op_code)
4083 case DW_LNS_extended_op:
4085 unsigned int ext_op_code_len;
4086 unsigned char ext_op_code;
4087 unsigned char *op_code_data = data;
4089 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4091 op_code_data += bytes_read;
4093 if (ext_op_code_len == 0)
4095 warn (_("Badly formed extended line op encountered!\n"));
4098 ext_op_code_len += bytes_read;
4099 ext_op_code = *op_code_data++;
4103 switch (ext_op_code)
4105 case DW_LNE_end_sequence:
4106 /* Reset stuff after printing this row. */
4108 case DW_LNE_set_address:
4109 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
4111 ext_op_code_len - bytes_read - 1,
4113 state_machine_regs.op_index = 0;
4114 state_machine_regs.view = 0;
4116 case DW_LNE_define_file:
4118 file_table = (File_Entry *) xrealloc
4119 (file_table, (n_files + 1) * sizeof (File_Entry));
4121 ++state_machine_regs.last_file_entry;
4122 /* Source file name. */
4123 file_table[n_files].name = op_code_data;
4124 op_code_data += strlen ((char *) op_code_data) + 1;
4125 /* Directory index. */
4126 file_table[n_files].directory_index =
4127 read_uleb128 (op_code_data, & bytes_read,
4129 op_code_data += bytes_read;
4130 /* Last modification time. */
4131 file_table[n_files].modification_date =
4132 read_uleb128 (op_code_data, & bytes_read,
4134 op_code_data += bytes_read;
4136 file_table[n_files].length =
4137 read_uleb128 (op_code_data, & bytes_read,
4143 case DW_LNE_set_discriminator:
4144 case DW_LNE_HP_set_sequence:
4145 /* Simply ignored. */
4149 printf (_("UNKNOWN (%u): length %d\n"),
4150 ext_op_code, ext_op_code_len - bytes_read);
4153 data += ext_op_code_len;
4157 /* Increment view after printing this row. */
4160 case DW_LNS_advance_pc:
4161 uladv = read_uleb128 (data, & bytes_read, end);
4163 if (linfo.li_max_ops_per_insn == 1)
4165 uladv *= linfo.li_min_insn_length;
4166 state_machine_regs.address += uladv;
4168 state_machine_regs.view = 0;
4173 = ((state_machine_regs.op_index + uladv)
4174 / linfo.li_max_ops_per_insn)
4175 * linfo.li_min_insn_length;
4176 state_machine_regs.address
4178 state_machine_regs.op_index
4179 = (state_machine_regs.op_index + uladv)
4180 % linfo.li_max_ops_per_insn;
4182 state_machine_regs.view = 0;
4186 case DW_LNS_advance_line:
4187 adv = read_sleb128 (data, & bytes_read, end);
4189 state_machine_regs.line += adv;
4192 case DW_LNS_set_file:
4193 adv = read_uleb128 (data, & bytes_read, end);
4195 state_machine_regs.file = adv;
4198 unsigned file = state_machine_regs.file - 1;
4201 if (file_table == NULL || n_files == 0)
4202 printf (_("\n [Use file table entry %d]\n"), file);
4204 else if (file >= n_files)
4206 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4207 printf (_("\n <over large file table index %u>"), file);
4209 else if ((dir = file_table[file].directory_index) == 0)
4210 /* If directory index is 0, that means current directory. */
4211 printf ("\n./%s:[++]\n", file_table[file].name);
4212 else if (directory_table == NULL || n_directories == 0)
4213 printf (_("\n [Use file %s in directory table entry %d]\n"),
4214 file_table[file].name, dir);
4216 else if (dir > n_directories)
4218 warn (_("directory index %u > number of directories %s\n"),
4219 dir, dwarf_vmatoa ("u", n_directories));
4220 printf (_("\n <over large directory table entry %u>\n"), dir);
4223 printf ("\n%s/%s:\n",
4224 /* The directory index starts counting at 1. */
4225 directory_table[dir - 1], file_table[file].name);
4229 case DW_LNS_set_column:
4230 uladv = read_uleb128 (data, & bytes_read, end);
4232 state_machine_regs.column = uladv;
4235 case DW_LNS_negate_stmt:
4236 adv = state_machine_regs.is_stmt;
4238 state_machine_regs.is_stmt = adv;
4241 case DW_LNS_set_basic_block:
4242 state_machine_regs.basic_block = 1;
4245 case DW_LNS_const_add_pc:
4246 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4247 if (linfo.li_max_ops_per_insn == 1)
4249 uladv *= linfo.li_min_insn_length;
4250 state_machine_regs.address += uladv;
4252 state_machine_regs.view = 0;
4257 = ((state_machine_regs.op_index + uladv)
4258 / linfo.li_max_ops_per_insn)
4259 * linfo.li_min_insn_length;
4260 state_machine_regs.address
4262 state_machine_regs.op_index
4263 = (state_machine_regs.op_index + uladv)
4264 % linfo.li_max_ops_per_insn;
4266 state_machine_regs.view = 0;
4270 case DW_LNS_fixed_advance_pc:
4271 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4272 state_machine_regs.address += uladv;
4273 state_machine_regs.op_index = 0;
4274 /* Do NOT reset view. */
4277 case DW_LNS_set_prologue_end:
4280 case DW_LNS_set_epilogue_begin:
4283 case DW_LNS_set_isa:
4284 uladv = read_uleb128 (data, & bytes_read, end);
4286 printf (_(" Set ISA to %lu\n"), uladv);
4290 printf (_(" Unknown opcode %d with operands: "), op_code);
4292 if (standard_opcodes != NULL)
4293 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4295 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4297 i == 1 ? "" : ", ");
4304 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4305 to the DWARF address/line matrix. */
4306 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4307 || (xop == DW_LNS_copy))
4309 const unsigned int MAX_FILENAME_LENGTH = 35;
4311 char *newFileName = NULL;
4312 size_t fileNameLength;
4316 unsigned indx = state_machine_regs.file - 1;
4318 if (indx >= n_files)
4320 warn (_("corrupt file index %u encountered\n"), indx);
4321 fileName = _("<corrupt>");
4324 fileName = (char *) file_table[indx].name;
4327 fileName = _("<unknown>");
4329 fileNameLength = strlen (fileName);
4331 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4333 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4334 /* Truncate file name */
4335 strncpy (newFileName,
4336 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4337 MAX_FILENAME_LENGTH + 1);
4341 newFileName = (char *) xmalloc (fileNameLength + 1);
4342 strncpy (newFileName, fileName, fileNameLength + 1);
4345 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4347 if (linfo.li_max_ops_per_insn == 1)
4348 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
4349 newFileName, state_machine_regs.line,
4350 state_machine_regs.address);
4352 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
4353 newFileName, state_machine_regs.line,
4354 state_machine_regs.address,
4355 state_machine_regs.op_index);
4359 if (linfo.li_max_ops_per_insn == 1)
4360 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
4361 newFileName, state_machine_regs.line,
4362 state_machine_regs.address);
4364 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
4365 newFileName, state_machine_regs.line,
4366 state_machine_regs.address,
4367 state_machine_regs.op_index);
4370 if (state_machine_regs.view)
4371 printf (" %6u\n", state_machine_regs.view);
4374 state_machine_regs.view++;
4376 if (xop == -DW_LNE_end_sequence)
4378 reset_state_machine (linfo.li_default_is_stmt);
4393 if (directory_table)
4395 free (directory_table);
4396 directory_table = NULL;
4407 display_debug_lines (struct dwarf_section *section, void *file)
4409 unsigned char *data = section->start;
4410 unsigned char *end = data + section->size;
4412 int retValDecoded = 1;
4414 if (do_debug_lines == 0)
4415 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4417 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
4418 retValRaw = display_debug_lines_raw (section, data, end, file);
4420 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
4421 retValDecoded = display_debug_lines_decoded (section, data, end, file);
4423 if (!retValRaw || !retValDecoded)
4430 find_debug_info_for_offset (unsigned long offset)
4434 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4437 for (i = 0; i < num_debug_info_entries; i++)
4438 if (debug_information[i].cu_offset == offset)
4439 return debug_information + i;
4445 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4447 /* See gdb/gdb-index.h. */
4448 static const char * const kinds[] =
4460 return _ (kinds[kind]);
4464 display_debug_pubnames_worker (struct dwarf_section *section,
4465 void *file ATTRIBUTE_UNUSED,
4468 DWARF2_Internal_PubNames names;
4469 unsigned char *start = section->start;
4470 unsigned char *end = start + section->size;
4472 /* It does not matter if this load fails,
4473 we test for that later on. */
4474 load_debug_info (file);
4476 printf (_("Contents of the %s section:\n\n"), section->name);
4480 unsigned char *data;
4483 unsigned int offset_size, initial_length_size;
4487 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
4488 if (names.pn_length == 0xffffffff)
4490 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
4492 initial_length_size = 12;
4497 initial_length_size = 4;
4500 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4501 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
4503 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4504 && num_debug_info_entries > 0
4505 && find_debug_info_for_offset (names.pn_offset) == NULL)
4506 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4507 (unsigned long) names.pn_offset, section->name);
4509 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
4511 adr = start + names.pn_length + initial_length_size;
4512 /* PR 17531: file: 7615b6b2. */
4513 if ((dwarf_signed_vma) names.pn_length < 0
4514 /* PR 17531: file: a5dbeaa7. */
4517 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4523 printf (_(" Length: %ld\n"),
4524 (long) names.pn_length);
4525 printf (_(" Version: %d\n"),
4527 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4528 (unsigned long) names.pn_offset);
4529 printf (_(" Size of area in .debug_info section: %ld\n"),
4530 (long) names.pn_size);
4532 if (names.pn_version != 2 && names.pn_version != 3)
4534 static int warned = 0;
4538 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4546 printf (_("\n Offset Kind Name\n"));
4548 printf (_("\n Offset\tName\n"));
4552 bfd_size_type maxprint;
4554 SAFE_BYTE_GET (offset, data, offset_size, end);
4558 data += offset_size;
4561 maxprint = (end - data) - 1;
4565 unsigned int kind_data;
4566 gdb_index_symbol_kind kind;
4567 const char *kind_name;
4570 SAFE_BYTE_GET (kind_data, data, 1, end);
4573 /* GCC computes the kind as the upper byte in the CU index
4574 word, and then right shifts it by the CU index size.
4575 Left shift KIND to where the gdb-index.h accessor macros
4577 kind_data <<= GDB_INDEX_CU_BITSIZE;
4578 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4579 kind_name = get_gdb_index_symbol_kind_name (kind);
4580 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4581 printf (" %-6lx %s,%-10s %.*s\n",
4582 (unsigned long) offset, is_static ? _("s") : _("g"),
4583 kind_name, (int) maxprint, data);
4586 printf (" %-6lx\t%.*s\n",
4587 (unsigned long) offset, (int) maxprint, data);
4589 data += strnlen ((char *) data, maxprint) + 1;
4594 while (offset != 0);
4602 display_debug_pubnames (struct dwarf_section *section, void *file)
4604 return display_debug_pubnames_worker (section, file, 0);
4608 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4610 return display_debug_pubnames_worker (section, file, 1);
4614 display_debug_macinfo (struct dwarf_section *section,
4615 void *file ATTRIBUTE_UNUSED)
4617 unsigned char *start = section->start;
4618 unsigned char *end = start + section->size;
4619 unsigned char *curr = start;
4620 unsigned int bytes_read;
4621 enum dwarf_macinfo_record_type op;
4623 printf (_("Contents of the %s section:\n\n"), section->name);
4627 unsigned int lineno;
4628 const unsigned char *string;
4630 op = (enum dwarf_macinfo_record_type) *curr;
4635 case DW_MACINFO_start_file:
4637 unsigned int filenum;
4639 lineno = read_uleb128 (curr, & bytes_read, end);
4641 filenum = read_uleb128 (curr, & bytes_read, end);
4644 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4649 case DW_MACINFO_end_file:
4650 printf (_(" DW_MACINFO_end_file\n"));
4653 case DW_MACINFO_define:
4654 lineno = read_uleb128 (curr, & bytes_read, end);
4657 curr += strnlen ((char *) string, end - string) + 1;
4658 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4662 case DW_MACINFO_undef:
4663 lineno = read_uleb128 (curr, & bytes_read, end);
4666 curr += strnlen ((char *) string, end - string) + 1;
4667 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4671 case DW_MACINFO_vendor_ext:
4673 unsigned int constant;
4675 constant = read_uleb128 (curr, & bytes_read, end);
4678 curr += strnlen ((char *) string, end - string) + 1;
4679 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4689 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4690 filename and dirname corresponding to file name table entry with index
4691 FILEIDX. Return NULL on failure. */
4693 static unsigned char *
4694 get_line_filename_and_dirname (dwarf_vma line_offset,
4696 unsigned char **dir_name)
4698 struct dwarf_section *section = &debug_displays [line].section;
4699 unsigned char *hdrptr, *dirtable, *file_name;
4700 unsigned int offset_size, initial_length_size;
4701 unsigned int version, opcode_base, bytes_read;
4702 dwarf_vma length, diridx;
4703 const unsigned char * end;
4706 if (section->start == NULL
4707 || line_offset >= section->size
4711 hdrptr = section->start + line_offset;
4712 end = section->start + section->size;
4714 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4715 if (length == 0xffffffff)
4717 /* This section is 64-bit DWARF 3. */
4718 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4720 initial_length_size = 12;
4725 initial_length_size = 4;
4727 if (length + initial_length_size > section->size)
4730 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4731 if (version != 2 && version != 3 && version != 4)
4733 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4735 hdrptr++; /* Skip max_ops_per_insn. */
4736 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
4738 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4739 if (opcode_base == 0)
4742 hdrptr += opcode_base - 1;
4744 /* Skip over dirname table. */
4745 while (*hdrptr != '\0')
4746 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4747 hdrptr++; /* Skip the NUL at the end of the table. */
4748 /* Now skip over preceding filename table entries. */
4749 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
4751 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4752 read_uleb128 (hdrptr, &bytes_read, end);
4753 hdrptr += bytes_read;
4754 read_uleb128 (hdrptr, &bytes_read, end);
4755 hdrptr += bytes_read;
4756 read_uleb128 (hdrptr, &bytes_read, end);
4757 hdrptr += bytes_read;
4759 if (hdrptr == end || *hdrptr == '\0')
4762 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4763 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4766 for (; *dirtable != '\0' && diridx > 1; diridx--)
4767 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4768 if (*dirtable == '\0')
4770 *dir_name = dirtable;
4775 display_debug_macro (struct dwarf_section *section,
4778 unsigned char *start = section->start;
4779 unsigned char *end = start + section->size;
4780 unsigned char *curr = start;
4781 unsigned char *extended_op_buf[256];
4782 unsigned int bytes_read;
4784 load_debug_section (str, file);
4785 load_debug_section (line, file);
4787 printf (_("Contents of the %s section:\n\n"), section->name);
4791 unsigned int lineno, version, flags;
4792 unsigned int offset_size = 4;
4793 const unsigned char *string;
4794 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4795 unsigned char **extended_ops = NULL;
4797 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4798 if (version != 4 && version != 5)
4800 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4805 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4808 printf (_(" Offset: 0x%lx\n"),
4809 (unsigned long) sec_offset);
4810 printf (_(" Version: %d\n"), version);
4811 printf (_(" Offset size: %d\n"), offset_size);
4814 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4815 printf (_(" Offset into .debug_line: 0x%lx\n"),
4816 (unsigned long) line_offset);
4820 unsigned int i, count, op;
4823 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4825 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4826 extended_ops = extended_op_buf;
4829 printf (_(" Extension opcode arguments:\n"));
4830 for (i = 0; i < count; i++)
4832 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4833 extended_ops[op] = curr;
4834 nargs = read_uleb128 (curr, &bytes_read, end);
4837 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4840 printf (_(" DW_MACRO_%02x arguments: "), op);
4841 for (n = 0; n < nargs; n++)
4845 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4846 printf ("%s%s", get_FORM_name (form),
4847 n == nargs - 1 ? "\n" : ", ");
4857 case DW_FORM_block1:
4858 case DW_FORM_block2:
4859 case DW_FORM_block4:
4861 case DW_FORM_string:
4863 case DW_FORM_sec_offset:
4866 error (_("Invalid extension opcode form %s\n"),
4867 get_FORM_name (form));
4883 error (_(".debug_macro section not zero terminated\n"));
4887 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4893 case DW_MACRO_start_file:
4895 unsigned int filenum;
4896 unsigned char *file_name = NULL, *dir_name = NULL;
4898 lineno = read_uleb128 (curr, &bytes_read, end);
4900 filenum = read_uleb128 (curr, &bytes_read, end);
4903 if ((flags & 2) == 0)
4904 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4907 = get_line_filename_and_dirname (line_offset, filenum,
4909 if (file_name == NULL)
4910 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4913 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4915 dir_name != NULL ? (const char *) dir_name : "",
4916 dir_name != NULL ? "/" : "", file_name);
4920 case DW_MACRO_end_file:
4921 printf (_(" DW_MACRO_end_file\n"));
4924 case DW_MACRO_define:
4925 lineno = read_uleb128 (curr, &bytes_read, end);
4928 curr += strnlen ((char *) string, end - string) + 1;
4929 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4933 case DW_MACRO_undef:
4934 lineno = read_uleb128 (curr, &bytes_read, end);
4937 curr += strnlen ((char *) string, end - string) + 1;
4938 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4942 case DW_MACRO_define_strp:
4943 lineno = read_uleb128 (curr, &bytes_read, end);
4945 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4946 string = fetch_indirect_string (offset);
4947 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4951 case DW_MACRO_undef_strp:
4952 lineno = read_uleb128 (curr, &bytes_read, end);
4954 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4955 string = fetch_indirect_string (offset);
4956 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4960 case DW_MACRO_import:
4961 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4962 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4963 (unsigned long) offset);
4966 case DW_MACRO_define_sup:
4967 lineno = read_uleb128 (curr, &bytes_read, end);
4969 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4970 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4971 lineno, (unsigned long) offset);
4974 case DW_MACRO_undef_sup:
4975 lineno = read_uleb128 (curr, &bytes_read, end);
4977 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4978 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4979 lineno, (unsigned long) offset);
4982 case DW_MACRO_import_sup:
4983 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4984 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4985 (unsigned long) offset);
4989 if (extended_ops == NULL || extended_ops[op] == NULL)
4991 error (_(" Unknown macro opcode %02x seen\n"), op);
4996 /* Skip over unhandled opcodes. */
4998 unsigned char *desc = extended_ops[op];
4999 nargs = read_uleb128 (desc, &bytes_read, end);
5003 printf (_(" DW_MACRO_%02x\n"), op);
5006 printf (_(" DW_MACRO_%02x -"), op);
5007 for (n = 0; n < nargs; n++)
5011 /* DW_FORM_implicit_const is not expected here. */
5012 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
5014 = read_and_display_attr_value (0, val, 0,
5015 curr, end, 0, 0, offset_size,
5016 version, NULL, 0, NULL,
5034 display_debug_abbrev (struct dwarf_section *section,
5035 void *file ATTRIBUTE_UNUSED)
5037 abbrev_entry *entry;
5038 unsigned char *start = section->start;
5039 unsigned char *end = start + section->size;
5041 printf (_("Contents of the %s section:\n\n"), section->name);
5045 unsigned char *last;
5050 start = process_abbrev_section (start, end);
5052 if (first_abbrev == NULL)
5055 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
5057 for (entry = first_abbrev; entry; entry = entry->next)
5061 printf (" %ld %s [%s]\n",
5063 get_TAG_name (entry->tag),
5064 entry->children ? _("has children") : _("no children"));
5066 for (attr = entry->first_attr; attr; attr = attr->next)
5068 printf (" %-18s %s",
5069 get_AT_name (attr->attribute),
5070 get_FORM_name (attr->form));
5071 if (attr->form == DW_FORM_implicit_const)
5072 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5084 /* Return true when ADDR is the maximum address, when addresses are
5085 POINTER_SIZE bytes long. */
5088 is_max_address (dwarf_vma addr, unsigned int pointer_size)
5090 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5091 return ((addr & mask) == mask);
5094 /* Display a view pair list starting at *VSTART_PTR and ending at
5095 VLISTEND within SECTION. */
5098 display_view_pair_list (struct dwarf_section *section,
5099 unsigned char **vstart_ptr,
5100 unsigned int debug_info_entry,
5101 unsigned char *vlistend)
5103 unsigned char *vstart = *vstart_ptr;
5104 unsigned char *section_end = section->start + section->size;
5105 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5107 if (vlistend < section_end)
5108 section_end = vlistend;
5112 while (vstart < section_end)
5114 dwarf_vma off = vstart - section->start;
5115 dwarf_vma vbegin, vend;
5117 unsigned int bytes_read;
5118 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5119 vstart += bytes_read;
5120 if (vstart == section_end)
5122 vstart -= bytes_read;
5126 vend = read_uleb128 (vstart, &bytes_read, section_end);
5127 vstart += bytes_read;
5129 printf (" %8.8lx ", (unsigned long) off);
5131 print_dwarf_view (vbegin, pointer_size, 1);
5132 print_dwarf_view (vend, pointer_size, 1);
5133 printf (_("location view pair\n"));
5137 *vstart_ptr = vstart;
5140 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5143 display_loc_list (struct dwarf_section *section,
5144 unsigned char **start_ptr,
5145 unsigned int debug_info_entry,
5147 dwarf_vma base_address,
5148 unsigned char **vstart_ptr,
5151 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5152 unsigned char *section_end = section->start + section->size;
5153 unsigned long cu_offset;
5154 unsigned int pointer_size;
5155 unsigned int offset_size;
5160 unsigned short length;
5161 int need_frame_base;
5163 if (debug_info_entry >= num_debug_info_entries)
5165 warn (_("No debug information available for loc lists of entry: %u\n"),
5170 cu_offset = debug_information [debug_info_entry].cu_offset;
5171 pointer_size = debug_information [debug_info_entry].pointer_size;
5172 offset_size = debug_information [debug_info_entry].offset_size;
5173 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5175 if (pointer_size < 2 || pointer_size > 8)
5177 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5178 pointer_size, debug_info_entry);
5184 dwarf_vma off = offset + (start - *start_ptr);
5185 dwarf_vma vbegin = vm1, vend = vm1;
5187 if (start + 2 * pointer_size > section_end)
5189 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5190 (unsigned long) offset);
5194 printf (" %8.8lx ", (unsigned long) off);
5196 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5197 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
5199 if (begin == 0 && end == 0)
5201 /* PR 18374: In a object file we can have a location list that
5202 starts with a begin and end of 0 because there are relocations
5203 that need to be applied to the addresses. Actually applying
5204 the relocations now does not help as they will probably resolve
5205 to 0, since the object file has not been fully linked. Real
5206 end of list markers will not have any relocations against them. */
5207 if (! reloc_at (section, off)
5208 && ! reloc_at (section, off + pointer_size))
5210 printf (_("<End of list>\n"));
5215 /* Check base address specifiers. */
5216 if (is_max_address (begin, pointer_size)
5217 && !is_max_address (end, pointer_size))
5220 print_dwarf_vma (begin, pointer_size);
5221 print_dwarf_vma (end, pointer_size);
5222 printf (_("(base address)\n"));
5228 unsigned int bytes_read;
5230 off = offset + (vstart - *start_ptr);
5232 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5233 vstart += bytes_read;
5234 print_dwarf_view (vbegin, pointer_size, 1);
5236 vend = read_uleb128 (vstart, &bytes_read, section_end);
5237 vstart += bytes_read;
5238 print_dwarf_view (vend, pointer_size, 1);
5240 printf (_("views at %8.8lx for:\n %*s "),
5241 (unsigned long) off, 8, "");
5244 if (start + 2 > section_end)
5246 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5247 (unsigned long) offset);
5251 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5253 if (start + length > section_end)
5255 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5256 (unsigned long) offset);
5260 print_dwarf_vma (begin + base_address, pointer_size);
5261 print_dwarf_vma (end + base_address, pointer_size);
5264 need_frame_base = decode_location_expression (start,
5269 cu_offset, section);
5272 if (need_frame_base && !has_frame_base)
5273 printf (_(" [without DW_AT_frame_base]"));
5275 if (begin == end && vbegin == vend)
5276 fputs (_(" (start == end)"), stdout);
5277 else if (begin > end || (begin == end && vbegin > vend))
5278 fputs (_(" (start > end)"), stdout);
5286 *vstart_ptr = vstart;
5289 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5292 display_loclists_list (struct dwarf_section *section,
5293 unsigned char **start_ptr,
5294 unsigned int debug_info_entry,
5296 dwarf_vma base_address,
5297 unsigned char **vstart_ptr,
5300 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5301 unsigned char *section_end = section->start + section->size;
5302 unsigned long cu_offset;
5303 unsigned int pointer_size;
5304 unsigned int offset_size;
5306 unsigned int bytes_read;
5308 /* Initialize it due to a false compiler warning. */
5309 dwarf_vma begin = -1, vbegin = -1;
5310 dwarf_vma end = -1, vend = -1;
5312 int need_frame_base;
5314 if (debug_info_entry >= num_debug_info_entries)
5316 warn (_("No debug information available for "
5317 "loclists lists of entry: %u\n"),
5322 cu_offset = debug_information [debug_info_entry].cu_offset;
5323 pointer_size = debug_information [debug_info_entry].pointer_size;
5324 offset_size = debug_information [debug_info_entry].offset_size;
5325 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5327 if (pointer_size < 2 || pointer_size > 8)
5329 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5330 pointer_size, debug_info_entry);
5336 dwarf_vma off = offset + (start - *start_ptr);
5337 enum dwarf_location_list_entry_type llet;
5339 if (start + 1 > section_end)
5341 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5342 (unsigned long) offset);
5346 printf (" %8.8lx ", (unsigned long) off);
5348 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5350 if (vstart && llet == DW_LLE_offset_pair)
5352 off = offset + (vstart - *start_ptr);
5354 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5355 vstart += bytes_read;
5356 print_dwarf_view (vbegin, pointer_size, 1);
5358 vend = read_uleb128 (vstart, &bytes_read, section_end);
5359 vstart += bytes_read;
5360 print_dwarf_view (vend, pointer_size, 1);
5362 printf (_("views at %8.8lx for:\n %*s "),
5363 (unsigned long) off, 8, "");
5368 case DW_LLE_end_of_list:
5369 printf (_("<End of list>\n"));
5371 case DW_LLE_offset_pair:
5372 begin = read_uleb128 (start, &bytes_read, section_end);
5373 start += bytes_read;
5374 end = read_uleb128 (start, &bytes_read, section_end);
5375 start += bytes_read;
5377 case DW_LLE_base_address:
5378 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5380 print_dwarf_vma (base_address, pointer_size);
5381 printf (_("(base address)\n"));
5383 #ifdef DW_LLE_view_pair
5384 case DW_LLE_view_pair:
5386 printf (_("View pair entry in loclist with locviews attribute\n"));
5387 vbegin = read_uleb128 (start, &bytes_read, section_end);
5388 start += bytes_read;
5389 print_dwarf_view (vbegin, pointer_size, 1);
5391 vend = read_uleb128 (start, &bytes_read, section_end);
5392 start += bytes_read;
5393 print_dwarf_view (vend, pointer_size, 1);
5395 printf (_("views for:\n"));
5399 error (_("Invalid location list entry type %d\n"), llet);
5402 if (llet == DW_LLE_end_of_list)
5404 if (llet != DW_LLE_offset_pair)
5407 if (start + 2 > section_end)
5409 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5410 (unsigned long) offset);
5414 length = read_uleb128 (start, &bytes_read, section_end);
5415 start += bytes_read;
5417 print_dwarf_vma (begin + base_address, pointer_size);
5418 print_dwarf_vma (end + base_address, pointer_size);
5421 need_frame_base = decode_location_expression (start,
5426 cu_offset, section);
5429 if (need_frame_base && !has_frame_base)
5430 printf (_(" [without DW_AT_frame_base]"));
5432 if (begin == end && vbegin == vend)
5433 fputs (_(" (start == end)"), stdout);
5434 else if (begin > end || (begin == end && vbegin > vend))
5435 fputs (_(" (start > end)"), stdout);
5443 if (vbegin != vm1 || vend != vm1)
5444 printf (_("Trailing view pair not used in a range"));
5447 *vstart_ptr = vstart;
5450 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5451 right-adjusted in a field of length LEN, and followed by a space. */
5454 print_addr_index (unsigned int idx, unsigned int len)
5456 static char buf[15];
5457 snprintf (buf, sizeof (buf), "[%d]", idx);
5458 printf ("%*s ", len, buf);
5461 /* Display a location list from a .dwo section. It uses address indexes rather
5462 than embedded addresses. This code closely follows display_loc_list, but the
5463 two are sufficiently different that combining things is very ugly. */
5466 display_loc_list_dwo (struct dwarf_section *section,
5467 unsigned char **start_ptr,
5468 unsigned int debug_info_entry,
5470 unsigned char **vstart_ptr,
5473 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
5474 unsigned char *section_end = section->start + section->size;
5475 unsigned long cu_offset;
5476 unsigned int pointer_size;
5477 unsigned int offset_size;
5480 unsigned short length;
5481 int need_frame_base;
5483 unsigned int bytes_read;
5485 if (debug_info_entry >= num_debug_info_entries)
5487 warn (_("No debug information for loc lists of entry: %u\n"),
5492 cu_offset = debug_information [debug_info_entry].cu_offset;
5493 pointer_size = debug_information [debug_info_entry].pointer_size;
5494 offset_size = debug_information [debug_info_entry].offset_size;
5495 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5497 if (pointer_size < 2 || pointer_size > 8)
5499 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5500 pointer_size, debug_info_entry);
5506 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
5508 if (start >= section_end)
5510 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5511 (unsigned long) offset);
5515 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
5528 dwarf_vma off = offset + (vstart - *start_ptr);
5530 view = read_uleb128 (vstart, &bytes_read, section_end);
5531 vstart += bytes_read;
5532 print_dwarf_view (view, 8, 1);
5534 view = read_uleb128 (vstart, &bytes_read, section_end);
5535 vstart += bytes_read;
5536 print_dwarf_view (view, 8, 1);
5538 printf (_("views at %8.8lx for:\n %*s "),
5539 (unsigned long) off, 8, "");
5547 case 0: /* A terminating entry. */
5549 *vstart_ptr = vstart;
5550 printf (_("<End of list>\n"));
5552 case 1: /* A base-address entry. */
5553 idx = read_uleb128 (start, &bytes_read, section_end);
5554 start += bytes_read;
5555 print_addr_index (idx, 8);
5556 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
5557 printf (_("(base address selection entry)\n"));
5559 case 2: /* A start/end entry. */
5560 idx = read_uleb128 (start, &bytes_read, section_end);
5561 start += bytes_read;
5562 print_addr_index (idx, 8);
5563 idx = read_uleb128 (start, &bytes_read, section_end);
5564 start += bytes_read;
5565 print_addr_index (idx, 8);
5567 case 3: /* A start/length entry. */
5568 idx = read_uleb128 (start, &bytes_read, section_end);
5569 start += bytes_read;
5570 print_addr_index (idx, 8);
5571 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5572 printf ("%08x ", idx);
5574 case 4: /* An offset pair entry. */
5575 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5576 printf ("%08x ", idx);
5577 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5578 printf ("%08x ", idx);
5581 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5583 *vstart_ptr = vstart;
5587 if (start + 2 > section_end)
5589 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5590 (unsigned long) offset);
5594 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
5595 if (start + length > section_end)
5597 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5598 (unsigned long) offset);
5603 need_frame_base = decode_location_expression (start,
5608 cu_offset, section);
5611 if (need_frame_base && !has_frame_base)
5612 printf (_(" [without DW_AT_frame_base]"));
5620 *vstart_ptr = vstart;
5623 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5626 static dwarf_vma *loc_offsets, *loc_views;
5629 loc_offsets_compar (const void *ap, const void *bp)
5631 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5632 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5634 int ret = (a > b) - (b > a);
5638 a = loc_views[*(const unsigned int *) ap];
5639 b = loc_views[*(const unsigned int *) bp];
5641 ret = (a > b) - (b > a);
5647 display_debug_loc (struct dwarf_section *section, void *file)
5649 unsigned char *start = section->start, *vstart = NULL;
5650 unsigned long bytes;
5651 unsigned char *section_begin = start;
5652 unsigned int num_loc_list = 0;
5653 unsigned long last_offset = 0;
5654 unsigned long last_view = 0;
5655 unsigned int first = 0;
5658 int seen_first_offset = 0;
5659 int locs_sorted = 1;
5660 unsigned char *next = start, *vnext = vstart;
5661 unsigned int *array = NULL;
5662 const char *suffix = strrchr (section->name, '.');
5664 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5665 dwarf_vma expected_start = 0;
5667 if (suffix && strcmp (suffix, ".dwo") == 0)
5670 bytes = section->size;
5674 printf (_("\nThe %s section is empty.\n"), section->name);
5680 unsigned char *hdrptr = section_begin;
5681 dwarf_vma ll_length;
5682 unsigned short ll_version;
5683 unsigned char *end = section_begin + section->size;
5684 unsigned char address_size, segment_selector_size;
5685 uint32_t offset_entry_count;
5687 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5688 if (ll_length == 0xffffffff)
5689 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5691 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5692 if (ll_version != 5)
5694 warn (_("The %s section contains corrupt or "
5695 "unsupported version number: %d.\n"),
5696 section->name, ll_version);
5700 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5702 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5703 if (segment_selector_size != 0)
5705 warn (_("The %s section contains "
5706 "unsupported segment selector size: %d.\n"),
5707 section->name, segment_selector_size);
5711 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5712 if (offset_entry_count != 0)
5714 warn (_("The %s section contains "
5715 "unsupported offset entry count: %d.\n"),
5716 section->name, offset_entry_count);
5720 expected_start = hdrptr - section_begin;
5723 if (load_debug_info (file) == 0)
5725 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5730 /* Check the order of location list in .debug_info section. If
5731 offsets of location lists are in the ascending order, we can
5732 use `debug_information' directly. */
5733 for (i = 0; i < num_debug_info_entries; i++)
5737 num = debug_information [i].num_loc_offsets;
5738 if (num > num_loc_list)
5741 /* Check if we can use `debug_information' directly. */
5742 if (locs_sorted && num != 0)
5744 if (!seen_first_offset)
5746 /* This is the first location list. */
5747 last_offset = debug_information [i].loc_offsets [0];
5748 last_view = debug_information [i].loc_views [0];
5750 seen_first_offset = 1;
5756 for (; j < num; j++)
5759 debug_information [i].loc_offsets [j]
5760 || (last_offset == debug_information [i].loc_offsets [j]
5761 && last_view > debug_information [i].loc_views [j]))
5766 last_offset = debug_information [i].loc_offsets [j];
5767 last_view = debug_information [i].loc_views [j];
5772 if (!seen_first_offset)
5773 error (_("No location lists in .debug_info section!\n"));
5775 if (debug_information [first].num_loc_offsets > 0
5776 && debug_information [first].loc_offsets [0] != expected_start
5777 && debug_information [first].loc_views [0] != expected_start)
5778 warn (_("Location lists in %s section start at 0x%s\n"),
5780 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
5783 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
5784 printf (_("Contents of the %s section:\n\n"), section->name);
5785 if (reloc_at (section, 0))
5786 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5787 printf (_(" Offset Begin End Expression\n"));
5789 seen_first_offset = 0;
5790 for (i = first; i < num_debug_info_entries; i++)
5792 dwarf_vma offset, voffset;
5793 dwarf_vma base_address;
5799 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5801 loc_offsets = debug_information [i].loc_offsets;
5802 loc_views = debug_information [i].loc_views;
5803 qsort (array, debug_information [i].num_loc_offsets,
5804 sizeof (*array), loc_offsets_compar);
5807 int adjacent_view_loclists = 1;
5808 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5810 j = locs_sorted ? k : array[k];
5812 && (debug_information [i].loc_offsets [locs_sorted
5813 ? k - 1 : array [k - 1]]
5814 == debug_information [i].loc_offsets [j])
5815 && (debug_information [i].loc_views [locs_sorted
5816 ? k - 1 : array [k - 1]]
5817 == debug_information [i].loc_views [j]))
5819 has_frame_base = debug_information [i].have_frame_base [j];
5820 offset = debug_information [i].loc_offsets [j];
5821 next = section_begin + offset;
5822 voffset = debug_information [i].loc_views [j];
5824 vnext = section_begin + voffset;
5827 base_address = debug_information [i].base_address;
5829 if (vnext && vnext < next)
5832 display_view_pair_list (section, &vstart, i, next);
5837 if (!seen_first_offset || !adjacent_view_loclists)
5838 seen_first_offset = 1;
5842 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5843 (unsigned long) (start - section_begin),
5844 (unsigned long) offset);
5845 else if (start > next)
5846 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5847 (unsigned long) (start - section_begin),
5848 (unsigned long) offset);
5853 if (offset >= bytes)
5855 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5856 (unsigned long) offset);
5860 if (vnext && voffset >= bytes)
5862 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
5863 (unsigned long) voffset);
5870 display_loc_list_dwo (section, &start, i, offset,
5871 &vstart, has_frame_base);
5873 display_loc_list (section, &start, i, offset, base_address,
5874 &vstart, has_frame_base);
5879 warn (_("DWO is not yet supported.\n"));
5881 display_loclists_list (section, &start, i, offset, base_address,
5882 &vstart, has_frame_base);
5885 /* FIXME: this arrangement is quite simplistic. Nothing
5886 requires locview lists to be adjacent to corresponding
5887 loclists, and a single loclist could be augmented by
5888 different locview lists, and vice-versa, unlikely as it
5889 is that it would make sense to do so. Hopefully we'll
5890 have view pair support built into loclists before we ever
5891 need to address all these possibilities. */
5892 if (adjacent_view_loclists && vnext
5893 && vnext != start && vstart != next)
5895 adjacent_view_loclists = 0;
5896 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
5899 if (vnext && vnext == start)
5900 display_view_pair_list (section, &start, i, vstart);
5904 if (start < section->start + section->size)
5905 warn (_("There are %ld unused bytes at the end of section %s\n"),
5906 (long) (section->start + section->size - start), section->name);
5913 display_debug_str (struct dwarf_section *section,
5914 void *file ATTRIBUTE_UNUSED)
5916 unsigned char *start = section->start;
5917 unsigned long bytes = section->size;
5918 dwarf_vma addr = section->address;
5922 printf (_("\nThe %s section is empty.\n"), section->name);
5926 printf (_("Contents of the %s section:\n\n"), section->name);
5934 lbytes = (bytes > 16 ? 16 : bytes);
5936 printf (" 0x%8.8lx ", (unsigned long) addr);
5938 for (j = 0; j < 16; j++)
5941 printf ("%2.2x", start[j]);
5949 for (j = 0; j < lbytes; j++)
5952 if (k >= ' ' && k < 0x80)
5971 display_debug_info (struct dwarf_section *section, void *file)
5973 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5977 display_debug_types (struct dwarf_section *section, void *file)
5979 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
5983 display_trace_info (struct dwarf_section *section, void *file)
5985 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
5989 display_debug_aranges (struct dwarf_section *section,
5990 void *file ATTRIBUTE_UNUSED)
5992 unsigned char *start = section->start;
5993 unsigned char *end = start + section->size;
5995 printf (_("Contents of the %s section:\n\n"), section->name);
5997 /* It does not matter if this load fails,
5998 we test for that later on. */
5999 load_debug_info (file);
6003 unsigned char *hdrptr;
6004 DWARF2_Internal_ARange arange;
6005 unsigned char *addr_ranges;
6008 unsigned char address_size;
6010 unsigned int offset_size;
6011 unsigned int initial_length_size;
6015 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
6016 if (arange.ar_length == 0xffffffff)
6018 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
6020 initial_length_size = 12;
6025 initial_length_size = 4;
6028 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6029 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
6031 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6032 && num_debug_info_entries > 0
6033 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6034 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6035 (unsigned long) arange.ar_info_offset, section->name);
6037 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6038 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
6040 if (arange.ar_version != 2 && arange.ar_version != 3)
6042 /* PR 19872: A version number of 0 probably means that there is
6043 padding at the end of the .debug_aranges section. Gold puts
6044 it there when performing an incremental link, for example.
6045 So do not generate a warning in this case. */
6046 if (arange.ar_version)
6047 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6051 printf (_(" Length: %ld\n"),
6052 (long) arange.ar_length);
6053 printf (_(" Version: %d\n"), arange.ar_version);
6054 printf (_(" Offset into .debug_info: 0x%lx\n"),
6055 (unsigned long) arange.ar_info_offset);
6056 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6057 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6059 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6061 /* PR 17512: file: 001-108546-0.001:0.1. */
6062 if (address_size == 0 || address_size > 8)
6064 error (_("Invalid address size in %s section!\n"),
6069 /* The DWARF spec does not require that the address size be a power
6070 of two, but we do. This will have to change if we ever encounter
6071 an uneven architecture. */
6072 if ((address_size & (address_size - 1)) != 0)
6074 warn (_("Pointer size + Segment size is not a power of two.\n"));
6078 if (address_size > 4)
6079 printf (_("\n Address Length\n"));
6081 printf (_("\n Address Length\n"));
6083 addr_ranges = hdrptr;
6085 /* Must pad to an alignment boundary that is twice the address size. */
6086 excess = (hdrptr - start) % (2 * address_size);
6088 addr_ranges += (2 * address_size) - excess;
6090 hdrptr = start + arange.ar_length + initial_length_size;
6091 if (hdrptr < start || hdrptr > end)
6093 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
6098 while (addr_ranges + 2 * address_size <= start)
6100 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6101 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
6104 print_dwarf_vma (address, address_size);
6105 print_dwarf_vma (length, address_size);
6115 /* Comparison function for qsort. */
6117 comp_addr_base (const void * v0, const void * v1)
6119 debug_info * info0 = (debug_info *) v0;
6120 debug_info * info1 = (debug_info *) v1;
6121 return info0->addr_base - info1->addr_base;
6124 /* Display the debug_addr section. */
6126 display_debug_addr (struct dwarf_section *section,
6129 debug_info **debug_addr_info;
6130 unsigned char *entry;
6135 if (section->size == 0)
6137 printf (_("\nThe %s section is empty.\n"), section->name);
6141 if (load_debug_info (file) == 0)
6143 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6148 printf (_("Contents of the %s section:\n\n"), section->name);
6150 /* PR 17531: file: cf38d01b.
6151 We use xcalloc because a corrupt file may not have initialised all of the
6152 fields in the debug_info structure, which means that the sort below might
6153 try to move uninitialised data. */
6154 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
6155 sizeof (debug_info *));
6158 for (i = 0; i < num_debug_info_entries; i++)
6159 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
6161 /* PR 17531: file: cf38d01b. */
6162 if (debug_information[i].addr_base >= section->size)
6163 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6164 (unsigned long) debug_information[i].addr_base, i);
6166 debug_addr_info [count++] = debug_information + i;
6169 /* Add a sentinel to make iteration convenient. */
6170 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6171 debug_addr_info [count]->addr_base = section->size;
6172 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
6174 for (i = 0; i < count; i++)
6177 unsigned int address_size = debug_addr_info [i]->pointer_size;
6179 printf (_(" For compilation unit at offset 0x%s:\n"),
6180 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
6182 printf (_("\tIndex\tAddress\n"));
6183 entry = section->start + debug_addr_info [i]->addr_base;
6184 end = section->start + debug_addr_info [i + 1]->addr_base;
6188 dwarf_vma base = byte_get (entry, address_size);
6189 printf (_("\t%d:\t"), idx);
6190 print_dwarf_vma (base, address_size);
6192 entry += address_size;
6198 free (debug_addr_info);
6202 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6204 display_debug_str_offsets (struct dwarf_section *section,
6205 void *file ATTRIBUTE_UNUSED)
6207 if (section->size == 0)
6209 printf (_("\nThe %s section is empty.\n"), section->name);
6212 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6213 what the offset size is for this section. */
6217 /* Each debug_information[x].range_lists[y] gets this representation for
6218 sorting purposes. */
6222 /* The debug_information[x].range_lists[y] value. */
6223 dwarf_vma ranges_offset;
6225 /* Original debug_information to find parameters of the data. */
6226 debug_info *debug_info_p;
6229 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6232 range_entry_compar (const void *ap, const void *bp)
6234 const struct range_entry *a_re = (const struct range_entry *) ap;
6235 const struct range_entry *b_re = (const struct range_entry *) bp;
6236 const dwarf_vma a = a_re->ranges_offset;
6237 const dwarf_vma b = b_re->ranges_offset;
6239 return (a > b) - (b > a);
6243 display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6244 unsigned int pointer_size, unsigned long offset,
6245 unsigned long base_address)
6247 while (start < finish)
6252 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6253 if (start >= finish)
6255 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6257 printf (" %8.8lx ", offset);
6259 if (begin == 0 && end == 0)
6261 printf (_("<End of list>\n"));
6265 /* Check base address specifiers. */
6266 if (is_max_address (begin, pointer_size)
6267 && !is_max_address (end, pointer_size))
6270 print_dwarf_vma (begin, pointer_size);
6271 print_dwarf_vma (end, pointer_size);
6272 printf ("(base address)\n");
6276 print_dwarf_vma (begin + base_address, pointer_size);
6277 print_dwarf_vma (end + base_address, pointer_size);
6280 fputs (_("(start == end)"), stdout);
6281 else if (begin > end)
6282 fputs (_("(start > end)"), stdout);
6289 display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6290 unsigned int pointer_size, unsigned long offset,
6291 unsigned long base_address)
6293 unsigned char *next = start;
6297 unsigned long off = offset + (start - next);
6298 enum dwarf_range_list_entry rlet;
6299 /* Initialize it due to a false compiler warning. */
6300 dwarf_vma begin = -1, length, end = -1;
6301 unsigned int bytes_read;
6303 if (start + 1 > finish)
6305 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6310 printf (" %8.8lx ", off);
6312 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6316 case DW_RLE_end_of_list:
6317 printf (_("<End of list>\n"));
6319 case DW_RLE_base_address:
6320 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6321 print_dwarf_vma (base_address, pointer_size);
6322 printf (_("(base address)\n"));
6324 case DW_RLE_start_length:
6325 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6326 length = read_uleb128 (start, &bytes_read, finish);
6327 start += bytes_read;
6328 end = begin + length;
6330 case DW_RLE_offset_pair:
6331 begin = read_uleb128 (start, &bytes_read, finish);
6332 start += bytes_read;
6333 end = read_uleb128 (start, &bytes_read, finish);
6334 start += bytes_read;
6336 case DW_RLE_start_end:
6337 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6338 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6341 error (_("Invalid range list entry type %d\n"), rlet);
6342 rlet = DW_RLE_end_of_list;
6345 if (rlet == DW_RLE_end_of_list)
6347 if (rlet == DW_RLE_base_address)
6350 print_dwarf_vma (begin + base_address, pointer_size);
6351 print_dwarf_vma (end + base_address, pointer_size);
6354 fputs (_("(start == end)"), stdout);
6355 else if (begin > end)
6356 fputs (_("(start > end)"), stdout);
6363 display_debug_ranges (struct dwarf_section *section,
6364 void *file ATTRIBUTE_UNUSED)
6366 unsigned char *start = section->start;
6367 unsigned char *last_start = start;
6368 unsigned long bytes = section->size;
6369 unsigned char *section_begin = start;
6370 unsigned char *finish = start + bytes;
6371 unsigned int num_range_list, i;
6372 struct range_entry *range_entries, *range_entry_fill;
6373 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6374 /* Initialize it due to a false compiler warning. */
6375 unsigned char address_size = 0;
6379 printf (_("\nThe %s section is empty.\n"), section->name);
6385 dwarf_vma initial_length;
6386 unsigned int initial_length_size;
6387 unsigned char segment_selector_size;
6388 unsigned int offset_size, offset_entry_count;
6389 unsigned short version;
6391 /* Get and check the length of the block. */
6392 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6394 if (initial_length == 0xffffffff)
6396 /* This section is 64-bit DWARF 3. */
6397 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6399 initial_length_size = 12;
6404 initial_length_size = 4;
6407 if (initial_length + initial_length_size > section->size)
6409 /* If the length field has a relocation against it, then we should
6410 not complain if it is inaccurate (and probably negative).
6411 It is copied from .debug_line handling code. */
6412 if (reloc_at (section, (start - section->start) - offset_size))
6414 initial_length = (finish - start) - initial_length_size;
6418 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6419 (long) initial_length);
6424 /* Get and check the version number. */
6425 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6429 warn (_("Only DWARF version 5 debug_rnglists info "
6430 "is currently supported.\n"));
6434 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6436 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6437 if (segment_selector_size != 0)
6439 warn (_("The %s section contains "
6440 "unsupported segment selector size: %d.\n"),
6441 section->name, segment_selector_size);
6445 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6446 if (offset_entry_count != 0)
6448 warn (_("The %s section contains "
6449 "unsupported offset entry count: %u.\n"),
6450 section->name, offset_entry_count);
6455 if (load_debug_info (file) == 0)
6457 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6463 for (i = 0; i < num_debug_info_entries; i++)
6464 num_range_list += debug_information [i].num_range_lists;
6466 if (num_range_list == 0)
6468 /* This can happen when the file was compiled with -gsplit-debug
6469 which removes references to range lists from the primary .o file. */
6470 printf (_("No range lists in .debug_info section.\n"));
6474 range_entries = (struct range_entry *)
6475 xmalloc (sizeof (*range_entries) * num_range_list);
6476 range_entry_fill = range_entries;
6478 for (i = 0; i < num_debug_info_entries; i++)
6480 debug_info *debug_info_p = &debug_information[i];
6483 for (j = 0; j < debug_info_p->num_range_lists; j++)
6485 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6486 range_entry_fill->debug_info_p = debug_info_p;
6491 qsort (range_entries, num_range_list, sizeof (*range_entries),
6492 range_entry_compar);
6494 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
6495 warn (_("Range lists in %s section start at 0x%lx\n"),
6496 section->name, (unsigned long) range_entries[0].ranges_offset);
6498 printf (_("Contents of the %s section:\n\n"), section->name);
6499 printf (_(" Offset Begin End\n"));
6501 for (i = 0; i < num_range_list; i++)
6503 struct range_entry *range_entry = &range_entries[i];
6504 debug_info *debug_info_p = range_entry->debug_info_p;
6505 unsigned int pointer_size;
6507 unsigned char *next;
6508 dwarf_vma base_address;
6510 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
6511 offset = range_entry->ranges_offset;
6512 next = section_begin + offset;
6513 base_address = debug_info_p->base_address;
6515 /* PR 17512: file: 001-101485-0.001:0.1. */
6516 if (pointer_size < 2 || pointer_size > 8)
6518 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6519 pointer_size, (unsigned long) offset);
6523 if (dwarf_check != 0 && i > 0)
6526 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6527 (unsigned long) (start - section_begin),
6528 (unsigned long) (next - section_begin), section->name);
6529 else if (start > next)
6531 if (next == last_start)
6533 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6534 (unsigned long) (start - section_begin),
6535 (unsigned long) (next - section_begin), section->name);
6541 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6542 (start, finish, pointer_size, offset, base_address);
6546 free (range_entries);
6551 typedef struct Frame_Chunk
6553 struct Frame_Chunk *next;
6554 unsigned char *chunk_start;
6556 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6557 short int *col_type;
6560 unsigned int code_factor;
6565 dwarf_vma cfa_offset;
6567 unsigned char fde_encoding;
6568 unsigned char cfa_exp;
6569 unsigned char ptr_size;
6570 unsigned char segment_size;
6574 static const char *const *dwarf_regnames;
6575 static unsigned int dwarf_regnames_count;
6577 /* A marker for a col_type that means this column was never referenced
6578 in the frame info. */
6579 #define DW_CFA_unreferenced (-1)
6581 /* Return 0 if no more space is needed, 1 if more space is needed,
6582 -1 for invalid reg. */
6585 frame_need_space (Frame_Chunk *fc, unsigned int reg)
6587 unsigned int prev = fc->ncols;
6589 if (reg < (unsigned int) fc->ncols)
6592 if (dwarf_regnames_count
6593 && reg > dwarf_regnames_count)
6596 fc->ncols = reg + 1;
6597 /* PR 17512: file: 10450-2643-0.004.
6598 If reg == -1 then this can happen... */
6602 /* PR 17512: file: 2844a11d. */
6603 if (fc->ncols > 1024)
6605 error (_("Unfeasibly large register number: %u\n"), reg);
6607 /* FIXME: 1024 is an arbitrary limit. Increase it if
6608 we ever encounter a valid binary that exceeds it. */
6612 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
6613 sizeof (short int));
6614 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
6615 /* PR 17512: file:002-10025-0.005. */
6616 if (fc->col_type == NULL || fc->col_offset == NULL)
6618 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6624 while (prev < fc->ncols)
6626 fc->col_type[prev] = DW_CFA_unreferenced;
6627 fc->col_offset[prev] = 0;
6633 static const char *const dwarf_regnames_i386[] =
6635 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6636 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6637 "eip", "eflags", NULL, /* 8 - 10 */
6638 "st0", "st1", "st2", "st3", /* 11 - 14 */
6639 "st4", "st5", "st6", "st7", /* 15 - 18 */
6640 NULL, NULL, /* 19 - 20 */
6641 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6642 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6643 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6644 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6645 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6646 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6647 "tr", "ldtr", /* 48 - 49 */
6648 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6649 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6650 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6651 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6652 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6653 NULL, NULL, NULL, /* 90 - 92 */
6654 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6657 static const char *const dwarf_regnames_iamcu[] =
6659 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6660 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6661 "eip", "eflags", NULL, /* 8 - 10 */
6662 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6663 NULL, NULL, /* 19 - 20 */
6664 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6665 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6666 NULL, NULL, NULL, /* 37 - 39 */
6667 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6668 "tr", "ldtr", /* 48 - 49 */
6669 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6670 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6671 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6672 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6673 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6674 NULL, NULL, NULL, /* 90 - 92 */
6675 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6679 init_dwarf_regnames_i386 (void)
6681 dwarf_regnames = dwarf_regnames_i386;
6682 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6686 init_dwarf_regnames_iamcu (void)
6688 dwarf_regnames = dwarf_regnames_iamcu;
6689 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6692 static const char *const dwarf_regnames_x86_64[] =
6694 "rax", "rdx", "rcx", "rbx",
6695 "rsi", "rdi", "rbp", "rsp",
6696 "r8", "r9", "r10", "r11",
6697 "r12", "r13", "r14", "r15",
6699 "xmm0", "xmm1", "xmm2", "xmm3",
6700 "xmm4", "xmm5", "xmm6", "xmm7",
6701 "xmm8", "xmm9", "xmm10", "xmm11",
6702 "xmm12", "xmm13", "xmm14", "xmm15",
6703 "st0", "st1", "st2", "st3",
6704 "st4", "st5", "st6", "st7",
6705 "mm0", "mm1", "mm2", "mm3",
6706 "mm4", "mm5", "mm6", "mm7",
6708 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6709 "fs.base", "gs.base", NULL, NULL,
6711 "mxcsr", "fcw", "fsw",
6712 "xmm16", "xmm17", "xmm18", "xmm19",
6713 "xmm20", "xmm21", "xmm22", "xmm23",
6714 "xmm24", "xmm25", "xmm26", "xmm27",
6715 "xmm28", "xmm29", "xmm30", "xmm31",
6716 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6717 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6718 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6719 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6720 NULL, NULL, NULL, /* 115 - 117 */
6721 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6725 init_dwarf_regnames_x86_64 (void)
6727 dwarf_regnames = dwarf_regnames_x86_64;
6728 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6731 static const char *const dwarf_regnames_aarch64[] =
6733 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6734 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6735 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6736 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6737 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6738 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6739 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6740 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6741 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6742 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6743 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6744 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6748 init_dwarf_regnames_aarch64 (void)
6750 dwarf_regnames = dwarf_regnames_aarch64;
6751 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6754 static const char *const dwarf_regnames_s390[] =
6756 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6757 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6758 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6759 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6760 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6761 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6762 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6763 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6764 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6767 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6768 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6772 init_dwarf_regnames_s390 (void)
6774 dwarf_regnames = dwarf_regnames_s390;
6775 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6779 init_dwarf_regnames (unsigned int e_machine)
6784 init_dwarf_regnames_i386 ();
6788 init_dwarf_regnames_iamcu ();
6794 init_dwarf_regnames_x86_64 ();
6798 init_dwarf_regnames_aarch64 ();
6802 init_dwarf_regnames_s390 ();
6811 regname (unsigned int regno, int row)
6813 static char reg[64];
6816 && regno < dwarf_regnames_count
6817 && dwarf_regnames [regno] != NULL)
6820 return dwarf_regnames [regno];
6821 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6822 dwarf_regnames [regno]);
6825 snprintf (reg, sizeof (reg), "r%d", regno);
6830 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
6835 if (*max_regs != fc->ncols)
6836 *max_regs = fc->ncols;
6838 if (*need_col_headers)
6840 static const char *sloc = " LOC";
6842 *need_col_headers = 0;
6844 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
6846 for (r = 0; r < *max_regs; r++)
6847 if (fc->col_type[r] != DW_CFA_unreferenced)
6852 printf ("%-5s ", regname (r, 1));
6858 print_dwarf_vma (fc->pc_begin, eh_addr_size);
6860 strcpy (tmp, "exp");
6862 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
6863 printf ("%-8s ", tmp);
6865 for (r = 0; r < fc->ncols; r++)
6867 if (fc->col_type[r] != DW_CFA_unreferenced)
6869 switch (fc->col_type[r])
6871 case DW_CFA_undefined:
6874 case DW_CFA_same_value:
6878 sprintf (tmp, "c%+d", fc->col_offset[r]);
6880 case DW_CFA_val_offset:
6881 sprintf (tmp, "v%+d", fc->col_offset[r]);
6883 case DW_CFA_register:
6884 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
6886 case DW_CFA_expression:
6887 strcpy (tmp, "exp");
6889 case DW_CFA_val_expression:
6890 strcpy (tmp, "vexp");
6893 strcpy (tmp, "n/a");
6896 printf ("%-5s ", tmp);
6902 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6904 static unsigned char *
6905 read_cie (unsigned char *start, unsigned char *end,
6906 Frame_Chunk **p_cie, int *p_version,
6907 unsigned long *p_aug_len, unsigned char **p_aug)
6911 unsigned int length_return;
6912 unsigned char *augmentation_data = NULL;
6913 unsigned long augmentation_data_len = 0;
6916 /* PR 17512: file: 001-228113-0.004. */
6920 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6921 memset (fc, 0, sizeof (Frame_Chunk));
6923 fc->col_type = (short int *) xmalloc (sizeof (short int));
6924 fc->col_offset = (int *) xmalloc (sizeof (int));
6928 fc->augmentation = (char *) start;
6929 /* PR 17512: file: 001-228113-0.004.
6930 Skip past augmentation name, but avoid running off the end of the data. */
6932 if (* start ++ == '\0')
6936 warn (_("No terminator for augmentation name\n"));
6940 if (strcmp (fc->augmentation, "eh") == 0)
6941 start += eh_addr_size;
6945 GET (fc->ptr_size, 1);
6946 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6948 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6952 GET (fc->segment_size, 1);
6953 /* PR 17512: file: e99d2804. */
6954 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6956 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6960 eh_addr_size = fc->ptr_size;
6964 fc->ptr_size = eh_addr_size;
6965 fc->segment_size = 0;
6967 READ_ULEB (fc->code_factor);
6968 READ_SLEB (fc->data_factor);
6978 if (fc->augmentation[0] == 'z')
6980 READ_ULEB (augmentation_data_len);
6981 augmentation_data = start;
6982 start += augmentation_data_len;
6983 /* PR 17512: file: 11042-2589-0.004. */
6986 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
6987 augmentation_data_len, (long)((end - start) + augmentation_data_len));
6992 if (augmentation_data_len)
6996 unsigned char *qend;
6998 p = (unsigned char *) fc->augmentation + 1;
6999 q = augmentation_data;
7000 qend = q + augmentation_data_len;
7002 /* PR 17531: file: 015adfaa. */
7005 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
7006 augmentation_data_len = 0;
7009 while (p < end && q < augmentation_data + augmentation_data_len)
7014 q += 1 + size_of_encoded_value (*q);
7016 fc->fde_encoding = *q++;
7023 /* Note - it is OK if this loop terminates with q < qend.
7024 Padding may have been inserted to align the end of the CIE. */
7029 *p_version = version;
7032 *p_aug_len = augmentation_data_len;
7033 *p_aug = augmentation_data;
7039 display_debug_frames (struct dwarf_section *section,
7040 void *file ATTRIBUTE_UNUSED)
7042 unsigned char *start = section->start;
7043 unsigned char *end = start + section->size;
7044 unsigned char *section_start = start;
7045 Frame_Chunk *chunks = 0, *forward_refs = 0;
7046 Frame_Chunk *remembered_state = 0;
7048 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7049 unsigned int length_return;
7050 unsigned int max_regs = 0;
7051 const char *bad_reg = _("bad register: ");
7052 unsigned int saved_eh_addr_size = eh_addr_size;
7054 printf (_("Contents of the %s section:\n"), section->name);
7058 unsigned char *saved_start;
7059 unsigned char *block_end;
7064 int need_col_headers = 1;
7065 unsigned char *augmentation_data = NULL;
7066 unsigned long augmentation_data_len = 0;
7067 unsigned int encoded_ptr_size = saved_eh_addr_size;
7068 unsigned int offset_size;
7069 unsigned int initial_length_size;
7070 bfd_boolean all_nops;
7072 saved_start = start;
7074 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
7078 printf ("\n%08lx ZERO terminator\n\n",
7079 (unsigned long)(saved_start - section_start));
7080 /* Skip any zero terminators that directly follow.
7081 A corrupt section size could have loaded a whole
7082 slew of zero filled memory bytes. eg
7083 PR 17512: file: 070-19381-0.004. */
7084 while (start < end && * start == 0)
7089 if (length == 0xffffffff)
7091 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
7093 initial_length_size = 12;
7098 initial_length_size = 4;
7101 block_end = saved_start + length + initial_length_size;
7102 if (block_end > end || block_end < start)
7104 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7105 dwarf_vmatoa_1 (NULL, length, offset_size),
7106 (unsigned long) (saved_start - section_start));
7110 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
7112 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7113 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
7118 start = read_cie (start, end, &cie, &version,
7119 &augmentation_data_len, &augmentation_data);
7120 /* PR 17512: file: 027-135133-0.005. */
7127 fc->chunk_start = saved_start;
7128 mreg = max_regs > 0 ? max_regs - 1 : 0;
7131 if (frame_need_space (fc, mreg) < 0)
7133 if (fc->fde_encoding)
7134 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7136 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7137 print_dwarf_vma (length, fc->ptr_size);
7138 print_dwarf_vma (cie_id, offset_size);
7140 if (do_debug_frames_interp)
7142 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7143 fc->code_factor, fc->data_factor, fc->ra);
7148 printf (" Version: %d\n", version);
7149 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7152 printf (" Pointer Size: %u\n", fc->ptr_size);
7153 printf (" Segment Size: %u\n", fc->segment_size);
7155 printf (" Code alignment factor: %u\n", fc->code_factor);
7156 printf (" Data alignment factor: %d\n", fc->data_factor);
7157 printf (" Return address column: %d\n", fc->ra);
7159 if (augmentation_data_len)
7163 printf (" Augmentation data: ");
7164 for (i = 0; i < augmentation_data_len; ++i)
7165 /* FIXME: If do_wide is FALSE, then we should
7166 add carriage returns at 80 columns... */
7167 printf (" %02x", augmentation_data[i]);
7175 unsigned char *look_for;
7176 static Frame_Chunk fde_fc;
7177 unsigned long segment_selector;
7181 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7182 look_for = start - 4 - ((cie_id ^ sign) - sign);
7185 look_for = section_start + cie_id;
7187 if (look_for <= saved_start)
7189 for (cie = chunks; cie ; cie = cie->next)
7190 if (cie->chunk_start == look_for)
7195 for (cie = forward_refs; cie ; cie = cie->next)
7196 if (cie->chunk_start == look_for)
7200 unsigned int off_size;
7201 unsigned char *cie_scan;
7203 cie_scan = look_for;
7205 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7206 if (length == 0xffffffff)
7208 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7215 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7218 : ((off_size == 4 && c_id == DW_CIE_ID)
7219 || (off_size == 8 && c_id == DW64_CIE_ID)))
7224 read_cie (cie_scan, end, &cie, &version,
7225 &augmentation_data_len, &augmentation_data);
7226 /* PR 17512: file: 3450-2098-0.004. */
7229 warn (_("Failed to read CIE information\n"));
7232 cie->next = forward_refs;
7234 cie->chunk_start = look_for;
7235 mreg = max_regs > 0 ? max_regs - 1 : 0;
7238 if (frame_need_space (cie, mreg) < 0)
7240 warn (_("Invalid max register\n"));
7243 if (cie->fde_encoding)
7245 = size_of_encoded_value (cie->fde_encoding);
7252 memset (fc, 0, sizeof (Frame_Chunk));
7256 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7257 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7258 (unsigned long) (saved_start - section_start));
7260 fc->col_type = (short int *) xmalloc (sizeof (short int));
7261 fc->col_offset = (int *) xmalloc (sizeof (int));
7262 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7264 warn (_("Invalid max register\n"));
7268 fc->augmentation = "";
7269 fc->fde_encoding = 0;
7270 fc->ptr_size = eh_addr_size;
7271 fc->segment_size = 0;
7275 fc->ncols = cie->ncols;
7276 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7277 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
7278 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7279 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7280 fc->augmentation = cie->augmentation;
7281 fc->ptr_size = cie->ptr_size;
7282 eh_addr_size = cie->ptr_size;
7283 fc->segment_size = cie->segment_size;
7284 fc->code_factor = cie->code_factor;
7285 fc->data_factor = cie->data_factor;
7286 fc->cfa_reg = cie->cfa_reg;
7287 fc->cfa_offset = cie->cfa_offset;
7289 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7291 warn (_("Invalid max register\n"));
7294 fc->fde_encoding = cie->fde_encoding;
7297 if (fc->fde_encoding)
7298 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7300 segment_selector = 0;
7301 if (fc->segment_size)
7303 if (fc->segment_size > sizeof (segment_selector))
7305 /* PR 17512: file: 9e196b3e. */
7306 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7307 fc->segment_size = 4;
7309 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7312 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
7314 /* FIXME: It appears that sometimes the final pc_range value is
7315 encoded in less than encoded_ptr_size bytes. See the x86_64
7316 run of the "objcopy on compressed debug sections" test for an
7318 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
7320 if (cie->augmentation[0] == 'z')
7322 READ_ULEB (augmentation_data_len);
7323 augmentation_data = start;
7324 start += augmentation_data_len;
7325 /* PR 17512: file: 722-8446-0.004. */
7326 if (start >= end || ((signed long) augmentation_data_len) < 0)
7328 warn (_("Corrupt augmentation data length: %lx\n"),
7329 augmentation_data_len);
7331 augmentation_data = NULL;
7332 augmentation_data_len = 0;
7336 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7337 (unsigned long)(saved_start - section_start),
7338 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
7339 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7340 (unsigned long)(cie->chunk_start - section_start));
7342 if (fc->segment_size)
7343 printf ("%04lx:", segment_selector);
7346 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7347 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7349 if (! do_debug_frames_interp && augmentation_data_len)
7353 printf (" Augmentation data: ");
7354 for (i = 0; i < augmentation_data_len; ++i)
7355 printf (" %02x", augmentation_data[i]);
7361 /* At this point, fc is the current chunk, cie (if any) is set, and
7362 we're about to interpret instructions for the chunk. */
7363 /* ??? At present we need to do this always, since this sizes the
7364 fc->col_type and fc->col_offset arrays, which we write into always.
7365 We should probably split the interpreted and non-interpreted bits
7366 into two different routines, since there's so much that doesn't
7367 really overlap between them. */
7368 if (1 || do_debug_frames_interp)
7370 /* Start by making a pass over the chunk, allocating storage
7371 and taking note of what registers are used. */
7372 unsigned char *tmp = start;
7374 while (start < block_end)
7376 unsigned int reg, op, opa;
7378 unsigned char * new_start;
7385 /* Warning: if you add any more cases to this switch, be
7386 sure to add them to the corresponding switch below. */
7389 case DW_CFA_advance_loc:
7393 if (frame_need_space (fc, opa) >= 0)
7394 fc->col_type[opa] = DW_CFA_undefined;
7396 case DW_CFA_restore:
7397 if (frame_need_space (fc, opa) >= 0)
7398 fc->col_type[opa] = DW_CFA_undefined;
7400 case DW_CFA_set_loc:
7401 start += encoded_ptr_size;
7403 case DW_CFA_advance_loc1:
7406 case DW_CFA_advance_loc2:
7409 case DW_CFA_advance_loc4:
7412 case DW_CFA_offset_extended:
7413 case DW_CFA_val_offset:
7416 if (frame_need_space (fc, reg) >= 0)
7417 fc->col_type[reg] = DW_CFA_undefined;
7419 case DW_CFA_restore_extended:
7421 if (frame_need_space (fc, reg) >= 0)
7422 fc->col_type[reg] = DW_CFA_undefined;
7424 case DW_CFA_undefined:
7426 if (frame_need_space (fc, reg) >= 0)
7427 fc->col_type[reg] = DW_CFA_undefined;
7429 case DW_CFA_same_value:
7431 if (frame_need_space (fc, reg) >= 0)
7432 fc->col_type[reg] = DW_CFA_undefined;
7434 case DW_CFA_register:
7437 if (frame_need_space (fc, reg) >= 0)
7438 fc->col_type[reg] = DW_CFA_undefined;
7440 case DW_CFA_def_cfa:
7444 case DW_CFA_def_cfa_register:
7447 case DW_CFA_def_cfa_offset:
7450 case DW_CFA_def_cfa_expression:
7452 new_start = start + temp;
7453 if (new_start < start)
7455 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7461 case DW_CFA_expression:
7462 case DW_CFA_val_expression:
7465 new_start = start + temp;
7466 if (new_start < start)
7468 /* PR 17512: file:306-192417-0.005. */
7469 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7474 if (frame_need_space (fc, reg) >= 0)
7475 fc->col_type[reg] = DW_CFA_undefined;
7477 case DW_CFA_offset_extended_sf:
7478 case DW_CFA_val_offset_sf:
7481 if (frame_need_space (fc, reg) >= 0)
7482 fc->col_type[reg] = DW_CFA_undefined;
7484 case DW_CFA_def_cfa_sf:
7488 case DW_CFA_def_cfa_offset_sf:
7491 case DW_CFA_MIPS_advance_loc8:
7494 case DW_CFA_GNU_args_size:
7497 case DW_CFA_GNU_negative_offset_extended:
7500 if (frame_need_space (fc, reg) >= 0)
7501 fc->col_type[reg] = DW_CFA_undefined;
7512 /* Now we know what registers are used, make a second pass over
7513 the chunk, this time actually printing out the info. */
7515 while (start < block_end)
7517 unsigned char * tmp;
7519 unsigned long ul, roffs;
7520 /* Note: It is tempting to use an unsigned long for 'reg' but there
7521 are various functions, notably frame_space_needed() that assume that
7522 reg is an unsigned int. */
7527 const char *reg_prefix = "";
7534 /* Make a note if something other than DW_CFA_nop happens. */
7535 if (op != DW_CFA_nop)
7538 /* Warning: if you add any more cases to this switch, be
7539 sure to add them to the corresponding switch above. */
7542 case DW_CFA_advance_loc:
7543 if (do_debug_frames_interp)
7544 frame_display_row (fc, &need_col_headers, &max_regs);
7546 printf (" DW_CFA_advance_loc: %d to %s\n",
7547 opa * fc->code_factor,
7548 dwarf_vmatoa_1 (NULL,
7549 fc->pc_begin + opa * fc->code_factor,
7551 fc->pc_begin += opa * fc->code_factor;
7556 if (opa >= (unsigned int) fc->ncols)
7557 reg_prefix = bad_reg;
7558 if (! do_debug_frames_interp || *reg_prefix != '\0')
7559 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7560 reg_prefix, regname (opa, 0),
7561 roffs * fc->data_factor);
7562 if (*reg_prefix == '\0')
7564 fc->col_type[opa] = DW_CFA_offset;
7565 fc->col_offset[opa] = roffs * fc->data_factor;
7569 case DW_CFA_restore:
7570 if (opa >= (unsigned int) fc->ncols)
7571 reg_prefix = bad_reg;
7572 if (! do_debug_frames_interp || *reg_prefix != '\0')
7573 printf (" DW_CFA_restore: %s%s\n",
7574 reg_prefix, regname (opa, 0));
7575 if (*reg_prefix != '\0')
7578 if (opa >= (unsigned int) cie->ncols
7579 || (do_debug_frames_interp
7580 && cie->col_type[opa] == DW_CFA_unreferenced))
7582 fc->col_type[opa] = DW_CFA_undefined;
7583 fc->col_offset[opa] = 0;
7587 fc->col_type[opa] = cie->col_type[opa];
7588 fc->col_offset[opa] = cie->col_offset[opa];
7592 case DW_CFA_set_loc:
7593 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
7594 if (do_debug_frames_interp)
7595 frame_display_row (fc, &need_col_headers, &max_regs);
7597 printf (" DW_CFA_set_loc: %s\n",
7598 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
7602 case DW_CFA_advance_loc1:
7603 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
7604 if (do_debug_frames_interp)
7605 frame_display_row (fc, &need_col_headers, &max_regs);
7607 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7608 (unsigned long) (ofs * fc->code_factor),
7609 dwarf_vmatoa_1 (NULL,
7610 fc->pc_begin + ofs * fc->code_factor,
7612 fc->pc_begin += ofs * fc->code_factor;
7615 case DW_CFA_advance_loc2:
7616 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
7617 if (do_debug_frames_interp)
7618 frame_display_row (fc, &need_col_headers, &max_regs);
7620 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7621 (unsigned long) (ofs * fc->code_factor),
7622 dwarf_vmatoa_1 (NULL,
7623 fc->pc_begin + ofs * fc->code_factor,
7625 fc->pc_begin += ofs * fc->code_factor;
7628 case DW_CFA_advance_loc4:
7629 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
7630 if (do_debug_frames_interp)
7631 frame_display_row (fc, &need_col_headers, &max_regs);
7633 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7634 (unsigned long) (ofs * fc->code_factor),
7635 dwarf_vmatoa_1 (NULL,
7636 fc->pc_begin + ofs * fc->code_factor,
7638 fc->pc_begin += ofs * fc->code_factor;
7641 case DW_CFA_offset_extended:
7644 if (reg >= (unsigned int) fc->ncols)
7645 reg_prefix = bad_reg;
7646 if (! do_debug_frames_interp || *reg_prefix != '\0')
7647 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7648 reg_prefix, regname (reg, 0),
7649 roffs * fc->data_factor);
7650 if (*reg_prefix == '\0')
7652 fc->col_type[reg] = DW_CFA_offset;
7653 fc->col_offset[reg] = roffs * fc->data_factor;
7657 case DW_CFA_val_offset:
7660 if (reg >= (unsigned int) fc->ncols)
7661 reg_prefix = bad_reg;
7662 if (! do_debug_frames_interp || *reg_prefix != '\0')
7663 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7664 reg_prefix, regname (reg, 0),
7665 roffs * fc->data_factor);
7666 if (*reg_prefix == '\0')
7668 fc->col_type[reg] = DW_CFA_val_offset;
7669 fc->col_offset[reg] = roffs * fc->data_factor;
7673 case DW_CFA_restore_extended:
7675 if (reg >= (unsigned int) fc->ncols)
7676 reg_prefix = bad_reg;
7677 if (! do_debug_frames_interp || *reg_prefix != '\0')
7678 printf (" DW_CFA_restore_extended: %s%s\n",
7679 reg_prefix, regname (reg, 0));
7680 if (*reg_prefix != '\0')
7683 if (reg >= (unsigned int) cie->ncols)
7685 fc->col_type[reg] = DW_CFA_undefined;
7686 fc->col_offset[reg] = 0;
7690 fc->col_type[reg] = cie->col_type[reg];
7691 fc->col_offset[reg] = cie->col_offset[reg];
7695 case DW_CFA_undefined:
7697 if (reg >= (unsigned int) fc->ncols)
7698 reg_prefix = bad_reg;
7699 if (! do_debug_frames_interp || *reg_prefix != '\0')
7700 printf (" DW_CFA_undefined: %s%s\n",
7701 reg_prefix, regname (reg, 0));
7702 if (*reg_prefix == '\0')
7704 fc->col_type[reg] = DW_CFA_undefined;
7705 fc->col_offset[reg] = 0;
7709 case DW_CFA_same_value:
7711 if (reg >= (unsigned int) fc->ncols)
7712 reg_prefix = bad_reg;
7713 if (! do_debug_frames_interp || *reg_prefix != '\0')
7714 printf (" DW_CFA_same_value: %s%s\n",
7715 reg_prefix, regname (reg, 0));
7716 if (*reg_prefix == '\0')
7718 fc->col_type[reg] = DW_CFA_same_value;
7719 fc->col_offset[reg] = 0;
7723 case DW_CFA_register:
7726 if (reg >= (unsigned int) fc->ncols)
7727 reg_prefix = bad_reg;
7728 if (! do_debug_frames_interp || *reg_prefix != '\0')
7730 printf (" DW_CFA_register: %s%s in ",
7731 reg_prefix, regname (reg, 0));
7732 puts (regname (roffs, 0));
7734 if (*reg_prefix == '\0')
7736 fc->col_type[reg] = DW_CFA_register;
7737 fc->col_offset[reg] = roffs;
7741 case DW_CFA_remember_state:
7742 if (! do_debug_frames_interp)
7743 printf (" DW_CFA_remember_state\n");
7744 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7745 rs->cfa_offset = fc->cfa_offset;
7746 rs->cfa_reg = fc->cfa_reg;
7748 rs->cfa_exp = fc->cfa_exp;
7749 rs->ncols = fc->ncols;
7750 rs->col_type = (short int *) xcmalloc (rs->ncols,
7751 sizeof (* rs->col_type));
7752 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7753 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7754 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
7755 rs->next = remembered_state;
7756 remembered_state = rs;
7759 case DW_CFA_restore_state:
7760 if (! do_debug_frames_interp)
7761 printf (" DW_CFA_restore_state\n");
7762 rs = remembered_state;
7765 remembered_state = rs->next;
7766 fc->cfa_offset = rs->cfa_offset;
7767 fc->cfa_reg = rs->cfa_reg;
7769 fc->cfa_exp = rs->cfa_exp;
7770 if (frame_need_space (fc, rs->ncols - 1) < 0)
7772 warn (_("Invalid column number in saved frame state\n"));
7776 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
7777 memcpy (fc->col_offset, rs->col_offset,
7778 rs->ncols * sizeof (* rs->col_offset));
7779 free (rs->col_type);
7780 free (rs->col_offset);
7783 else if (do_debug_frames_interp)
7784 printf ("Mismatched DW_CFA_restore_state\n");
7787 case DW_CFA_def_cfa:
7788 READ_SLEB (fc->cfa_reg);
7789 READ_ULEB (fc->cfa_offset);
7791 if (! do_debug_frames_interp)
7792 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7793 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7796 case DW_CFA_def_cfa_register:
7797 READ_SLEB (fc->cfa_reg);
7799 if (! do_debug_frames_interp)
7800 printf (" DW_CFA_def_cfa_register: %s\n",
7801 regname (fc->cfa_reg, 0));
7804 case DW_CFA_def_cfa_offset:
7805 READ_ULEB (fc->cfa_offset);
7806 if (! do_debug_frames_interp)
7807 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
7811 if (! do_debug_frames_interp)
7812 printf (" DW_CFA_nop\n");
7815 case DW_CFA_def_cfa_expression:
7817 if (start >= block_end || ul > (unsigned long) (block_end - start))
7819 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
7822 if (! do_debug_frames_interp)
7824 printf (" DW_CFA_def_cfa_expression (");
7825 decode_location_expression (start, eh_addr_size, 0, -1,
7833 case DW_CFA_expression:
7836 if (reg >= (unsigned int) fc->ncols)
7837 reg_prefix = bad_reg;
7838 /* PR 17512: file: 069-133014-0.006. */
7839 /* PR 17512: file: 98c02eb4. */
7841 if (start >= block_end || tmp > block_end || tmp < start)
7843 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
7846 if (! do_debug_frames_interp || *reg_prefix != '\0')
7848 printf (" DW_CFA_expression: %s%s (",
7849 reg_prefix, regname (reg, 0));
7850 decode_location_expression (start, eh_addr_size, 0, -1,
7854 if (*reg_prefix == '\0')
7855 fc->col_type[reg] = DW_CFA_expression;
7859 case DW_CFA_val_expression:
7862 if (reg >= (unsigned int) fc->ncols)
7863 reg_prefix = bad_reg;
7865 if (start >= block_end || tmp > block_end || tmp < start)
7867 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
7870 if (! do_debug_frames_interp || *reg_prefix != '\0')
7872 printf (" DW_CFA_val_expression: %s%s (",
7873 reg_prefix, regname (reg, 0));
7874 decode_location_expression (start, eh_addr_size, 0, -1,
7878 if (*reg_prefix == '\0')
7879 fc->col_type[reg] = DW_CFA_val_expression;
7883 case DW_CFA_offset_extended_sf:
7886 if (frame_need_space (fc, reg) < 0)
7887 reg_prefix = bad_reg;
7888 if (! do_debug_frames_interp || *reg_prefix != '\0')
7889 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7890 reg_prefix, regname (reg, 0),
7891 (long)(l * fc->data_factor));
7892 if (*reg_prefix == '\0')
7894 fc->col_type[reg] = DW_CFA_offset;
7895 fc->col_offset[reg] = l * fc->data_factor;
7899 case DW_CFA_val_offset_sf:
7902 if (frame_need_space (fc, reg) < 0)
7903 reg_prefix = bad_reg;
7904 if (! do_debug_frames_interp || *reg_prefix != '\0')
7905 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7906 reg_prefix, regname (reg, 0),
7907 (long)(l * fc->data_factor));
7908 if (*reg_prefix == '\0')
7910 fc->col_type[reg] = DW_CFA_val_offset;
7911 fc->col_offset[reg] = l * fc->data_factor;
7915 case DW_CFA_def_cfa_sf:
7916 READ_SLEB (fc->cfa_reg);
7917 READ_ULEB (fc->cfa_offset);
7918 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7920 if (! do_debug_frames_interp)
7921 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7922 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
7925 case DW_CFA_def_cfa_offset_sf:
7926 READ_ULEB (fc->cfa_offset);
7927 fc->cfa_offset *= fc->data_factor;
7928 if (! do_debug_frames_interp)
7929 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
7932 case DW_CFA_MIPS_advance_loc8:
7933 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
7934 if (do_debug_frames_interp)
7935 frame_display_row (fc, &need_col_headers, &max_regs);
7937 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7938 (unsigned long) (ofs * fc->code_factor),
7939 dwarf_vmatoa_1 (NULL,
7940 fc->pc_begin + ofs * fc->code_factor,
7942 fc->pc_begin += ofs * fc->code_factor;
7945 case DW_CFA_GNU_window_save:
7946 if (! do_debug_frames_interp)
7947 printf (" DW_CFA_GNU_window_save\n");
7950 case DW_CFA_GNU_args_size:
7952 if (! do_debug_frames_interp)
7953 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7956 case DW_CFA_GNU_negative_offset_extended:
7960 if (frame_need_space (fc, reg) < 0)
7961 reg_prefix = bad_reg;
7962 if (! do_debug_frames_interp || *reg_prefix != '\0')
7963 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7964 reg_prefix, regname (reg, 0),
7965 (long)(l * fc->data_factor));
7966 if (*reg_prefix == '\0')
7968 fc->col_type[reg] = DW_CFA_offset;
7969 fc->col_offset[reg] = l * fc->data_factor;
7974 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7975 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7977 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
7982 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7983 if (do_debug_frames_interp && ! all_nops)
7984 frame_display_row (fc, &need_col_headers, &max_regs);
7987 eh_addr_size = saved_eh_addr_size;
7998 display_debug_names (struct dwarf_section *section, void *file)
8000 unsigned char *hdrptr = section->start;
8001 dwarf_vma unit_length;
8002 unsigned char *unit_start;
8003 const unsigned char *const section_end = section->start + section->size;
8004 unsigned char *unit_end;
8006 printf (_("Contents of the %s section:\n"), section->name);
8008 load_debug_section (str, file);
8010 for (; hdrptr < section_end; hdrptr = unit_end)
8012 unsigned int offset_size;
8013 uint16_t dwarf_version, padding;
8014 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8015 uint32_t bucket_count, name_count, abbrev_table_size;
8016 uint32_t augmentation_string_size;
8019 unit_start = hdrptr;
8021 /* Get and check the length of the block. */
8022 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8024 if (unit_length == 0xffffffff)
8026 /* This section is 64-bit DWARF. */
8027 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8032 unit_end = hdrptr + unit_length;
8034 if ((hdrptr - section->start) + unit_length > section->size)
8036 warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names "
8037 "header is wrong - the section is too small\n"),
8038 (long) unit_length, (long) (unit_start - section->start));
8042 /* Get and check the version number. */
8043 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8044 printf (_("Version %ld\n"), (long) dwarf_version);
8046 /* Prior versions did not exist, and future versions may not be
8047 backwards compatible. */
8048 if (dwarf_version != 5)
8050 warn (_("Only DWARF version 5 .debug_names "
8051 "is currently supported.\n"));
8055 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8057 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8060 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8061 if (comp_unit_count == 0)
8062 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8064 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8065 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8066 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8067 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8068 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8070 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8071 if (augmentation_string_size % 4 != 0)
8073 warn (_("Augmentation string length %u must be rounded up "
8074 "to a multiple of 4 in .debug_names.\n"),
8075 augmentation_string_size);
8076 augmentation_string_size += (-augmentation_string_size) & 3;
8078 printf (_("Augmentation string:"));
8079 for (i = 0; i < augmentation_string_size; i++)
8083 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8084 printf (" %02x", uc);
8089 printf (_("CU table:\n"));
8090 for (i = 0; i < comp_unit_count; i++)
8094 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8095 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8099 printf (_("TU table:\n"));
8100 for (i = 0; i < local_type_unit_count; i++)
8104 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8105 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8109 printf (_("Foreign TU table:\n"));
8110 for (i = 0; i < foreign_type_unit_count; i++)
8114 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8115 printf (_("[%3u] "), i);
8116 print_dwarf_vma (signature, 8);
8121 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8122 hdrptr += bucket_count * sizeof (uint32_t);
8123 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8124 hdrptr += name_count * sizeof (uint32_t);
8125 unsigned char *const name_table_string_offsets = hdrptr;
8126 hdrptr += name_count * offset_size;
8127 unsigned char *const name_table_entry_offsets = hdrptr;
8128 hdrptr += name_count * offset_size;
8129 unsigned char *const abbrev_table = hdrptr;
8130 hdrptr += abbrev_table_size;
8131 const unsigned char *const abbrev_table_end = hdrptr;
8132 unsigned char *const entry_pool = hdrptr;
8133 if (hdrptr > unit_end)
8135 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8136 "for unit 0x%lx in the debug_names\n"),
8137 (long) (hdrptr - section->start),
8138 (long) (unit_end - section->start),
8139 (long) (unit_start - section->start));
8143 size_t buckets_filled = 0;
8145 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8147 const uint32_t bucket = hash_table_buckets[bucketi];
8152 printf (_("Used %zu of %lu buckets.\n"), buckets_filled,
8153 (unsigned long) bucket_count);
8155 uint32_t hash_prev = 0;
8156 size_t hash_clash_count = 0;
8157 size_t longest_clash = 0;
8158 size_t this_length = 0;
8160 for (hashi = 0; hashi < name_count; hashi++)
8162 const uint32_t hash_this = hash_table_hashes[hashi];
8166 if (hash_prev % bucket_count == hash_this % bucket_count)
8170 longest_clash = MAX (longest_clash, this_length);
8175 hash_prev = hash_this;
8177 printf (_("Out of %lu items there are %zu bucket clashes"
8178 " (longest of %zu entries).\n"),
8179 (unsigned long) name_count, hash_clash_count, longest_clash);
8180 assert (name_count == buckets_filled + hash_clash_count);
8182 struct abbrev_lookup_entry
8184 dwarf_vma abbrev_tag;
8185 unsigned char *abbrev_lookup_ptr;
8187 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8188 size_t abbrev_lookup_used = 0;
8189 size_t abbrev_lookup_allocated = 0;
8191 unsigned char *abbrevptr = abbrev_table;
8194 unsigned int bytes_read;
8195 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8197 abbrevptr += bytes_read;
8198 if (abbrev_tag == 0)
8200 if (abbrev_lookup_used == abbrev_lookup_allocated)
8202 abbrev_lookup_allocated = MAX (0x100,
8203 abbrev_lookup_allocated * 2);
8204 abbrev_lookup = xrealloc (abbrev_lookup,
8205 (abbrev_lookup_allocated
8206 * sizeof (*abbrev_lookup)));
8208 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8209 struct abbrev_lookup_entry *entry;
8210 for (entry = abbrev_lookup;
8211 entry < abbrev_lookup + abbrev_lookup_used;
8213 if (entry->abbrev_tag == abbrev_tag)
8215 warn (_("Duplicate abbreviation tag %lu "
8216 "in unit 0x%lx in the debug_names\n"),
8217 (long) abbrev_tag, (long) (unit_start - section->start));
8220 entry = &abbrev_lookup[abbrev_lookup_used++];
8221 entry->abbrev_tag = abbrev_tag;
8222 entry->abbrev_lookup_ptr = abbrevptr;
8224 /* Skip DWARF tag. */
8225 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8226 abbrevptr += bytes_read;
8229 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8232 abbrevptr += bytes_read;
8233 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8235 abbrevptr += bytes_read;
8236 if (xindex == 0 && form == 0)
8241 printf (_("\nSymbol table:\n"));
8243 for (namei = 0; namei < name_count; ++namei)
8245 uint64_t string_offset, entry_offset;
8247 SAFE_BYTE_GET (string_offset,
8248 name_table_string_offsets + namei * offset_size,
8249 offset_size, unit_end);
8250 SAFE_BYTE_GET (entry_offset,
8251 name_table_entry_offsets + namei * offset_size,
8252 offset_size, unit_end);
8254 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8255 fetch_indirect_string (string_offset));
8257 unsigned char *entryptr = entry_pool + entry_offset;
8259 // We need to scan first whether there is a single or multiple
8260 // entries. TAGNO is -2 for the first entry, it is -1 for the
8261 // initial tag read of the second entry, then it becomes 0 for the
8262 // first entry for real printing etc.
8264 /* Initialize it due to a false compiler warning. */
8265 dwarf_vma second_abbrev_tag = -1;
8268 unsigned int bytes_read;
8269 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8271 entryptr += bytes_read;
8274 second_abbrev_tag = abbrev_tag;
8276 entryptr = entry_pool + entry_offset;
8279 if (abbrev_tag == 0)
8283 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8284 (unsigned long) abbrev_tag);
8286 const struct abbrev_lookup_entry *entry;
8287 for (entry = abbrev_lookup;
8288 entry < abbrev_lookup + abbrev_lookup_used;
8290 if (entry->abbrev_tag == abbrev_tag)
8292 if (entry >= abbrev_lookup + abbrev_lookup_used)
8294 warn (_("Undefined abbreviation tag %lu "
8295 "in unit 0x%lx in the debug_names\n"),
8297 (long) (unit_start - section->start));
8300 abbrevptr = entry->abbrev_lookup_ptr;
8301 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8303 abbrevptr += bytes_read;
8305 printf (" %s", get_TAG_name (dwarf_tag));
8308 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8311 abbrevptr += bytes_read;
8312 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8314 abbrevptr += bytes_read;
8315 if (xindex == 0 && form == 0)
8319 printf (" %s", get_IDX_name (xindex));
8320 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8323 dwarf_version, NULL,
8330 printf (_(" <no entries>"));
8334 free (abbrev_lookup);
8341 display_gdb_index (struct dwarf_section *section,
8342 void *file ATTRIBUTE_UNUSED)
8344 unsigned char *start = section->start;
8346 uint32_t cu_list_offset, tu_list_offset;
8347 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8348 unsigned int cu_list_elements, tu_list_elements;
8349 unsigned int address_table_size, symbol_table_slots;
8350 unsigned char *cu_list, *tu_list;
8351 unsigned char *address_table, *symbol_table, *constant_pool;
8354 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8356 printf (_("Contents of the %s section:\n"), section->name);
8358 if (section->size < 6 * sizeof (uint32_t))
8360 warn (_("Truncated header in the %s section.\n"), section->name);
8364 version = byte_get_little_endian (start, 4);
8365 printf (_("Version %ld\n"), (long) version);
8367 /* Prior versions are obsolete, and future versions may not be
8368 backwards compatible. */
8369 if (version < 3 || version > 8)
8371 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
8375 warn (_("The address table data in version 3 may be wrong.\n"));
8377 warn (_("Version 4 does not support case insensitive lookups.\n"));
8379 warn (_("Version 5 does not include inlined functions.\n"));
8381 warn (_("Version 6 does not include symbol attributes.\n"));
8382 /* Version 7 indices generated by Gold have bad type unit references,
8383 PR binutils/15021. But we don't know if the index was generated by
8384 Gold or not, so to avoid worrying users with gdb-generated indices
8385 we say nothing for version 7 here. */
8387 cu_list_offset = byte_get_little_endian (start + 4, 4);
8388 tu_list_offset = byte_get_little_endian (start + 8, 4);
8389 address_table_offset = byte_get_little_endian (start + 12, 4);
8390 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8391 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8393 if (cu_list_offset > section->size
8394 || tu_list_offset > section->size
8395 || address_table_offset > section->size
8396 || symbol_table_offset > section->size
8397 || constant_pool_offset > section->size)
8399 warn (_("Corrupt header in the %s section.\n"), section->name);
8403 /* PR 17531: file: 418d0a8a. */
8404 if (tu_list_offset < cu_list_offset)
8406 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8407 tu_list_offset, cu_list_offset);
8411 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
8413 if (address_table_offset < tu_list_offset)
8415 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8416 address_table_offset, tu_list_offset);
8420 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
8422 /* PR 17531: file: 18a47d3d. */
8423 if (symbol_table_offset < address_table_offset)
8425 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8426 symbol_table_offset, address_table_offset);
8430 address_table_size = symbol_table_offset - address_table_offset;
8432 if (constant_pool_offset < symbol_table_offset)
8434 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8435 constant_pool_offset, symbol_table_offset);
8439 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8441 cu_list = start + cu_list_offset;
8442 tu_list = start + tu_list_offset;
8443 address_table = start + address_table_offset;
8444 symbol_table = start + symbol_table_offset;
8445 constant_pool = start + constant_pool_offset;
8447 if (address_table + address_table_size > section->start + section->size)
8449 warn (_("Address table extends beyond end of section.\n"));
8453 printf (_("\nCU table:\n"));
8454 for (i = 0; i < cu_list_elements; i += 2)
8456 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8457 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8459 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8460 (unsigned long) cu_offset,
8461 (unsigned long) (cu_offset + cu_length - 1));
8464 printf (_("\nTU table:\n"));
8465 for (i = 0; i < tu_list_elements; i += 3)
8467 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8468 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8469 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8471 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8472 (unsigned long) tu_offset,
8473 (unsigned long) type_offset);
8474 print_dwarf_vma (signature, 8);
8478 printf (_("\nAddress table:\n"));
8479 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8482 uint64_t low = byte_get_little_endian (address_table + i, 8);
8483 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8484 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8486 print_dwarf_vma (low, 8);
8487 print_dwarf_vma (high, 8);
8488 printf (_("%lu\n"), (unsigned long) cu_index);
8491 printf (_("\nSymbol table:\n"));
8492 for (i = 0; i < symbol_table_slots; ++i)
8494 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8495 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8496 uint32_t num_cus, cu;
8498 if (name_offset != 0
8499 || cu_vector_offset != 0)
8502 unsigned char * adr;
8504 adr = constant_pool + name_offset;
8505 /* PR 17531: file: 5b7b07ad. */
8506 if (adr < constant_pool || adr >= section->start + section->size)
8508 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8509 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8513 printf ("[%3u] %.*s:", i,
8514 (int) (section->size - (constant_pool_offset + name_offset)),
8515 constant_pool + name_offset);
8517 adr = constant_pool + cu_vector_offset;
8518 if (adr < constant_pool || adr >= section->start + section->size - 3)
8520 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8521 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8522 cu_vector_offset, i);
8526 num_cus = byte_get_little_endian (adr, 4);
8528 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
8529 if (num_cus * 4 < num_cus
8530 || adr >= section->start + section->size
8531 || adr < constant_pool)
8533 printf ("<invalid number of CUs: %d>\n", num_cus);
8534 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8542 for (j = 0; j < num_cus; ++j)
8545 gdb_index_symbol_kind kind;
8547 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
8548 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8549 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8550 cu = GDB_INDEX_CU_VALUE (cu);
8551 /* Convert to TU number if it's for a type unit. */
8552 if (cu >= cu_list_elements / 2)
8553 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8554 (unsigned long) (cu - cu_list_elements / 2));
8556 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8558 printf (" [%s, %s]",
8559 is_static ? _("static") : _("global"),
8560 get_gdb_index_symbol_kind_name (kind));
8572 /* Pre-allocate enough space for the CU/TU sets needed. */
8575 prealloc_cu_tu_list (unsigned int nshndx)
8577 if (shndx_pool == NULL)
8579 shndx_pool_size = nshndx;
8580 shndx_pool_used = 0;
8581 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8582 sizeof (unsigned int));
8586 shndx_pool_size = shndx_pool_used + nshndx;
8587 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8588 sizeof (unsigned int));
8593 add_shndx_to_cu_tu_entry (unsigned int shndx)
8595 if (shndx_pool_used >= shndx_pool_size)
8597 error (_("Internal error: out of space in the shndx pool.\n"));
8600 shndx_pool [shndx_pool_used++] = shndx;
8604 end_cu_tu_entry (void)
8606 if (shndx_pool_used >= shndx_pool_size)
8608 error (_("Internal error: out of space in the shndx pool.\n"));
8611 shndx_pool [shndx_pool_used++] = 0;
8614 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8617 get_DW_SECT_short_name (unsigned int dw_sect)
8619 static char buf[16];
8627 case DW_SECT_ABBREV:
8633 case DW_SECT_STR_OFFSETS:
8635 case DW_SECT_MACINFO:
8643 snprintf (buf, sizeof (buf), "%d", dw_sect);
8647 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8648 These sections are extensions for Fission.
8649 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8652 process_cu_tu_index (struct dwarf_section *section, int do_display)
8654 unsigned char *phdr = section->start;
8655 unsigned char *limit = phdr + section->size;
8656 unsigned char *phash;
8657 unsigned char *pindex;
8658 unsigned char *ppool;
8659 unsigned int version;
8660 unsigned int ncols = 0;
8662 unsigned int nslots;
8665 dwarf_vma signature_high;
8666 dwarf_vma signature_low;
8669 /* PR 17512: file: 002-168123-0.004. */
8672 warn (_("Section %s is empty\n"), section->name);
8675 /* PR 17512: file: 002-376-0.004. */
8676 if (section->size < 24)
8678 warn (_("Section %s is too small to contain a CU/TU header\n"),
8683 SAFE_BYTE_GET (version, phdr, 4, limit);
8685 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8686 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8687 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8690 pindex = phash + nslots * 8;
8691 ppool = pindex + nslots * 4;
8693 /* PR 17531: file: 45d69832. */
8694 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
8696 warn (_("Section %s is too small for %d slots\n"),
8697 section->name, nslots);
8703 printf (_("Contents of the %s section:\n\n"), section->name);
8704 printf (_(" Version: %d\n"), version);
8706 printf (_(" Number of columns: %d\n"), ncols);
8707 printf (_(" Number of used entries: %d\n"), nused);
8708 printf (_(" Number of slots: %d\n\n"), nslots);
8711 if (ppool > limit || ppool < phdr)
8713 warn (_("Section %s too small for %d hash table entries\n"),
8714 section->name, nslots);
8721 prealloc_cu_tu_list ((limit - ppool) / 4);
8722 for (i = 0; i < nslots; i++)
8724 unsigned char *shndx_list;
8727 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
8728 if (signature_high != 0 || signature_low != 0)
8730 SAFE_BYTE_GET (j, pindex, 4, limit);
8731 shndx_list = ppool + j * 4;
8732 /* PR 17531: file: 705e010d. */
8733 if (shndx_list < ppool)
8735 warn (_("Section index pool located before start of section\n"));
8740 printf (_(" [%3d] Signature: 0x%s Sections: "),
8741 i, dwarf_vmatoa64 (signature_high, signature_low,
8742 buf, sizeof (buf)));
8745 if (shndx_list >= limit)
8747 warn (_("Section %s too small for shndx pool\n"),
8751 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
8755 printf (" %d", shndx);
8757 add_shndx_to_cu_tu_entry (shndx);
8769 else if (version == 2)
8772 unsigned int dw_sect;
8773 unsigned char *ph = phash;
8774 unsigned char *pi = pindex;
8775 unsigned char *poffsets = ppool + ncols * 4;
8776 unsigned char *psizes = poffsets + nused * ncols * 4;
8777 unsigned char *pend = psizes + nused * ncols * 4;
8778 bfd_boolean is_tu_index;
8779 struct cu_tu_set *this_set = NULL;
8781 unsigned char *prow;
8783 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8785 /* PR 17531: file: 0dd159bf.
8786 Check for wraparound with an overlarge ncols value. */
8787 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
8789 warn (_("Overlarge number of columns: %x\n"), ncols);
8795 warn (_("Section %s too small for offset and size tables\n"),
8802 printf (_(" Offset table\n"));
8803 printf (" slot %-16s ",
8804 is_tu_index ? _("signature") : _("dwo_id"));
8811 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8817 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
8824 for (j = 0; j < ncols; j++)
8826 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8827 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8832 for (i = 0; i < nslots; i++)
8834 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8836 SAFE_BYTE_GET (row, pi, 4, limit);
8839 /* PR 17531: file: a05f6ab3. */
8842 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8848 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
8850 prow = poffsets + (row - 1) * ncols * 4;
8851 /* PR 17531: file: b8ce60a8. */
8852 if (prow < poffsets || prow > limit)
8854 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8860 printf (_(" [%3d] 0x%s"),
8861 i, dwarf_vmatoa64 (signature_high, signature_low,
8862 buf, sizeof (buf)));
8863 for (j = 0; j < ncols; j++)
8865 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8867 printf (" %8d", val);
8870 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8872 /* PR 17531: file: 10796eb3. */
8873 if (dw_sect >= DW_SECT_MAX)
8874 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8876 this_set [row - 1].section_offsets [dw_sect] = val;
8892 printf (_(" Size table\n"));
8893 printf (" slot %-16s ",
8894 is_tu_index ? _("signature") : _("dwo_id"));
8897 for (j = 0; j < ncols; j++)
8899 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
8901 printf (" %8s", get_DW_SECT_short_name (val));
8907 for (i = 0; i < nslots; i++)
8909 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8911 SAFE_BYTE_GET (row, pi, 4, limit);
8914 prow = psizes + (row - 1) * ncols * 4;
8917 printf (_(" [%3d] 0x%s"),
8918 i, dwarf_vmatoa64 (signature_high, signature_low,
8919 buf, sizeof (buf)));
8921 for (j = 0; j < ncols; j++)
8923 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
8925 printf (" %8d", val);
8928 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
8929 if (dw_sect >= DW_SECT_MAX)
8930 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8932 this_set [row - 1].section_sizes [dw_sect] = val;
8944 else if (do_display)
8945 printf (_(" Unsupported version (%d)\n"), version);
8953 /* Load the CU and TU indexes if present. This will build a list of
8954 section sets that we can use to associate a .debug_info.dwo section
8955 with its associated .debug_abbrev.dwo section in a .dwp file. */
8958 load_cu_tu_indexes (void *file)
8960 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8962 /* If we have already loaded (or tried to load) the CU and TU indexes
8963 then do not bother to repeat the task. */
8964 if (cu_tu_indexes_read == -1)
8966 cu_tu_indexes_read = TRUE;
8968 if (load_debug_section (dwp_cu_index, file))
8969 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8970 cu_tu_indexes_read = FALSE;
8972 if (load_debug_section (dwp_tu_index, file))
8973 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8974 cu_tu_indexes_read = FALSE;
8977 return (bfd_boolean) cu_tu_indexes_read;
8980 /* Find the set of sections that includes section SHNDX. */
8983 find_cu_tu_set (void *file, unsigned int shndx)
8987 if (! load_cu_tu_indexes (file))
8990 /* Find SHNDX in the shndx pool. */
8991 for (i = 0; i < shndx_pool_used; i++)
8992 if (shndx_pool [i] == shndx)
8995 if (i >= shndx_pool_used)
8998 /* Now backup to find the first entry in the set. */
8999 while (i > 0 && shndx_pool [i - 1] != 0)
9002 return shndx_pool + i;
9005 /* Display a .debug_cu_index or .debug_tu_index section. */
9008 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9010 return process_cu_tu_index (section, 1);
9014 display_debug_not_supported (struct dwarf_section *section,
9015 void *file ATTRIBUTE_UNUSED)
9017 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9023 /* Like malloc, but takes two parameters like calloc.
9024 Verifies that the first parameter is not too large.
9025 Note: does *not* initialise the allocated memory to zero. */
9027 cmalloc (size_t nmemb, size_t size)
9029 /* Check for overflow. */
9030 if (nmemb >= ~(size_t) 0 / size)
9033 return xmalloc (nmemb * size);
9036 /* Like xmalloc, but takes two parameters like calloc.
9037 Verifies that the first parameter is not too large.
9038 Note: does *not* initialise the allocated memory to zero. */
9040 xcmalloc (size_t nmemb, size_t size)
9042 /* Check for overflow. */
9043 if (nmemb >= ~(size_t) 0 / size)
9046 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9051 return xmalloc (nmemb * size);
9054 /* Like xrealloc, but takes three parameters.
9055 Verifies that the second parameter is not too large.
9056 Note: does *not* initialise any new memory to zero. */
9058 xcrealloc (void *ptr, size_t nmemb, size_t size)
9060 /* Check for overflow. */
9061 if (nmemb >= ~(size_t) 0 / size)
9064 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9069 return xrealloc (ptr, nmemb * size);
9072 /* Like xcalloc, but verifies that the first parameter is not too large. */
9074 xcalloc2 (size_t nmemb, size_t size)
9076 /* Check for overflow. */
9077 if (nmemb >= ~(size_t) 0 / size)
9080 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9085 return xcalloc (nmemb, size);
9089 free_debug_memory (void)
9095 for (i = 0; i < max; i++)
9096 free_debug_section ((enum dwarf_section_display_enum) i);
9098 if (debug_information != NULL)
9100 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
9102 for (i = 0; i < num_debug_info_entries; i++)
9104 if (!debug_information [i].max_loc_offsets)
9106 free (debug_information [i].loc_offsets);
9107 free (debug_information [i].have_frame_base);
9109 if (!debug_information [i].max_range_lists)
9110 free (debug_information [i].range_lists);
9113 free (debug_information);
9114 debug_information = NULL;
9115 alloc_num_debug_info_entries = num_debug_info_entries = 0;
9120 dwarf_select_sections_by_names (const char *names)
9124 const char * option;
9128 debug_dump_long_opts;
9130 static const debug_dump_long_opts opts_table [] =
9132 /* Please keep this table alpha- sorted. */
9133 { "Ranges", & do_debug_ranges, 1 },
9134 { "abbrev", & do_debug_abbrevs, 1 },
9135 { "addr", & do_debug_addr, 1 },
9136 { "aranges", & do_debug_aranges, 1 },
9137 { "cu_index", & do_debug_cu_index, 1 },
9138 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
9139 { "frames", & do_debug_frames, 1 },
9140 { "frames-interp", & do_debug_frames_interp, 1 },
9141 /* The special .gdb_index section. */
9142 { "gdb_index", & do_gdb_index, 1 },
9143 { "info", & do_debug_info, 1 },
9144 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
9145 { "loc", & do_debug_loc, 1 },
9146 { "macro", & do_debug_macinfo, 1 },
9147 { "pubnames", & do_debug_pubnames, 1 },
9148 { "pubtypes", & do_debug_pubtypes, 1 },
9149 /* This entry is for compatibility
9150 with earlier versions of readelf. */
9151 { "ranges", & do_debug_aranges, 1 },
9152 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
9153 { "str", & do_debug_str, 1 },
9154 /* These trace_* sections are used by Itanium VMS. */
9155 { "trace_abbrev", & do_trace_abbrevs, 1 },
9156 { "trace_aranges", & do_trace_aranges, 1 },
9157 { "trace_info", & do_trace_info, 1 },
9166 const debug_dump_long_opts * entry;
9168 for (entry = opts_table; entry->option; entry++)
9170 size_t len = strlen (entry->option);
9172 if (strncmp (p, entry->option, len) == 0
9173 && (p[len] == ',' || p[len] == '\0'))
9175 * entry->variable |= entry->val;
9177 /* The --debug-dump=frames-interp option also
9178 enables the --debug-dump=frames option. */
9179 if (do_debug_frames_interp)
9180 do_debug_frames = 1;
9187 if (entry->option == NULL)
9189 warn (_("Unrecognized debug option '%s'\n"), p);
9190 p = strchr (p, ',');
9201 dwarf_select_sections_by_letters (const char *letters)
9203 unsigned int lindex = 0;
9205 while (letters[lindex])
9206 switch (letters[lindex++])
9213 do_debug_abbrevs = 1;
9217 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
9221 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
9225 do_debug_pubnames = 1;
9229 do_debug_pubtypes = 1;
9233 do_debug_aranges = 1;
9237 do_debug_ranges = 1;
9241 do_debug_frames_interp = 1;
9244 do_debug_frames = 1;
9248 do_debug_macinfo = 1;
9260 warn (_("Unrecognized debug option '%s'\n"), letters);
9266 dwarf_select_sections_all (void)
9269 do_debug_abbrevs = 1;
9270 do_debug_lines = FLAG_DEBUG_LINES_RAW;
9271 do_debug_pubnames = 1;
9272 do_debug_pubtypes = 1;
9273 do_debug_aranges = 1;
9274 do_debug_ranges = 1;
9275 do_debug_frames = 1;
9276 do_debug_macinfo = 1;
9281 do_trace_abbrevs = 1;
9282 do_trace_aranges = 1;
9284 do_debug_cu_index = 1;
9287 struct dwarf_section_display debug_displays[] =
9289 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9290 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9291 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9292 display_debug_aranges, &do_debug_aranges, TRUE },
9293 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9294 display_debug_frames, &do_debug_frames, TRUE },
9295 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9296 display_debug_info, &do_debug_info, TRUE },
9297 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9298 display_debug_lines, &do_debug_lines, TRUE },
9299 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9300 display_debug_pubnames, &do_debug_pubnames, FALSE },
9301 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9302 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
9303 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9304 display_debug_frames, &do_debug_frames, TRUE },
9305 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9306 display_debug_macinfo, &do_debug_macinfo, FALSE },
9307 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9308 display_debug_macro, &do_debug_macinfo, TRUE },
9309 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9310 display_debug_str, &do_debug_str, FALSE },
9311 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9312 display_debug_str, &do_debug_str, FALSE },
9313 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9314 display_debug_loc, &do_debug_loc, TRUE },
9315 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9316 display_debug_loc, &do_debug_loc, TRUE },
9317 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9318 display_debug_pubnames, &do_debug_pubtypes, FALSE },
9319 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9320 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
9321 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9322 display_debug_ranges, &do_debug_ranges, TRUE },
9323 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9324 display_debug_ranges, &do_debug_ranges, TRUE },
9325 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9326 display_debug_not_supported, NULL, FALSE },
9327 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9328 display_debug_not_supported, NULL, FALSE },
9329 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9330 display_debug_types, &do_debug_info, TRUE },
9331 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9332 display_debug_not_supported, NULL, FALSE },
9333 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9334 display_gdb_index, &do_gdb_index, FALSE },
9335 { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9336 display_debug_names, &do_gdb_index, FALSE },
9337 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
9338 display_trace_info, &do_trace_info, TRUE },
9339 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9340 display_debug_abbrev, &do_trace_abbrevs, FALSE },
9341 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9342 display_debug_aranges, &do_trace_aranges, FALSE },
9343 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9344 display_debug_info, &do_debug_info, TRUE },
9345 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9346 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9347 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9348 display_debug_types, &do_debug_info, TRUE },
9349 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9350 display_debug_lines, &do_debug_lines, TRUE },
9351 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9352 display_debug_loc, &do_debug_loc, TRUE },
9353 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9354 display_debug_macro, &do_debug_macinfo, TRUE },
9355 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9356 display_debug_macinfo, &do_debug_macinfo, FALSE },
9357 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9358 display_debug_str, &do_debug_str, TRUE },
9359 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9360 display_debug_str_offsets, NULL, FALSE },
9361 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9362 display_debug_str_offsets, NULL, FALSE },
9363 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9364 display_debug_addr, &do_debug_addr, TRUE },
9365 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9366 display_cu_index, &do_debug_cu_index, FALSE },
9367 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9368 display_cu_index, &do_debug_cu_index, FALSE },
9371 /* A static assertion. */
9372 extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];