1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2023 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"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
123 sections. For version 1 package files, each set is stored in SHNDX_POOL
124 as a zero-terminated list of section indexes comprising one set of debug
125 sections from a .dwo file. */
127 static unsigned int *shndx_pool
= NULL
;
128 static unsigned int shndx_pool_size
= 0;
129 static unsigned int shndx_pool_used
= 0;
131 /* For version 2 package files, each set contains an array of section offsets
132 and an array of section sizes, giving the offset and size of the
133 contribution from a CU or TU within one of the debug sections.
134 When displaying debug info from a package file, we need to use these
135 tables to locate the corresponding contributions to each section. */
140 uint64_t section_offsets
[DW_SECT_MAX
];
141 size_t section_sizes
[DW_SECT_MAX
];
144 static int cu_count
= 0;
145 static int tu_count
= 0;
146 static struct cu_tu_set
*cu_sets
= NULL
;
147 static struct cu_tu_set
*tu_sets
= NULL
;
149 static bool load_cu_tu_indexes (void *);
151 /* An array that indicates for a given level of CU nesting whether
152 the latest DW_AT_type seen for that level was a signed type or
154 #define MAX_CU_NESTING (1 << 8)
155 static bool level_type_signed
[MAX_CU_NESTING
];
157 /* Values for do_debug_lines. */
158 #define FLAG_DEBUG_LINES_RAW 1
159 #define FLAG_DEBUG_LINES_DECODED 2
162 size_of_encoded_value (int encoding
)
164 switch (encoding
& 0x7)
167 case 0: return eh_addr_size
;
175 get_encoded_value (unsigned char **pdata
,
177 struct dwarf_section
*section
,
180 unsigned char * data
= * pdata
;
181 unsigned int size
= size_of_encoded_value (encoding
);
184 if (data
>= end
|| size
> (size_t) (end
- data
))
186 warn (_("Encoded value extends past end of section\n"));
191 /* PR 17512: file: 002-829853-0.004. */
194 warn (_("Encoded size of %d is too large to read\n"), size
);
199 /* PR 17512: file: 1085-5603-0.004. */
202 warn (_("Encoded size of 0 is too small to read\n"));
207 if (encoding
& DW_EH_PE_signed
)
208 val
= byte_get_signed (data
, size
);
210 val
= byte_get (data
, size
);
212 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
213 val
+= section
->address
+ (data
- section
->start
);
215 * pdata
= data
+ size
;
219 /* Print a uint64_t value (typically an address, offset or length) in
220 hexadecimal format, followed by a space. The precision displayed is
221 determined by the NUM_BYTES parameter. */
224 print_hex (uint64_t value
, unsigned num_bytes
)
229 printf ("%0*" PRIx64
" ", num_bytes
* 2,
230 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
233 /* Like print_hex, but no trailing space. */
236 print_hex_ns (uint64_t value
, unsigned num_bytes
)
241 printf ("%0*" PRIx64
, num_bytes
* 2,
242 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
245 /* Print a view number in hexadecimal value, with the same width as
246 print_hex would have printed it. */
249 print_view (uint64_t value
, unsigned num_bytes
)
254 printf ("v%0*" PRIx64
" ", num_bytes
* 2 - 1,
255 value
& ~(~(uint64_t) 0 << num_bytes
* 4 << num_bytes
* 4));
259 null_name (const char *p
)
266 /* Read in a LEB128 encoded value starting at address DATA.
267 If SIGN is true, return a signed LEB128 value.
268 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
269 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
270 terminating byte was not found and with bit 1 set if the value
271 overflows a uint64_t.
272 No bytes will be read at address END or beyond. */
275 read_leb128 (unsigned char *data
,
276 const unsigned char *const end
,
278 unsigned int *length_return
,
282 unsigned int num_read
= 0;
283 unsigned int shift
= 0;
288 unsigned char byte
= *data
++;
289 unsigned char lost
, mask
;
293 if (shift
< CHAR_BIT
* sizeof (result
))
295 result
|= ((uint64_t) (byte
& 0x7f)) << shift
;
296 /* These bits overflowed. */
297 lost
= byte
^ (result
>> shift
);
298 /* And this is the mask of possible overflow bits. */
299 mask
= 0x7f ^ ((uint64_t) 0x7f << shift
>> shift
);
307 if ((lost
& mask
) != (sign
&& (int64_t) result
< 0 ? mask
: 0))
310 if ((byte
& 0x80) == 0)
313 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
314 result
|= -((uint64_t) 1 << shift
);
319 if (length_return
!= NULL
)
320 *length_return
= num_read
;
321 if (status_return
!= NULL
)
322 *status_return
= status
;
327 /* Read AMOUNT bytes from PTR and store them in VAL.
328 Checks to make sure that the read will not reach or pass END.
329 FUNC chooses whether the value read is unsigned or signed, and may
330 be either byte_get or byte_get_signed. If INC is true, PTR is
331 incremented after reading the value.
332 This macro cannot protect against PTR values derived from user input.
333 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
334 pointers is undefined behaviour. */
335 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
338 size_t amount = (AMOUNT); \
339 if (sizeof (VAL) < amount) \
341 error (ngettext ("internal error: attempt to read %d byte " \
342 "of data in to %d sized variable", \
343 "internal error: attempt to read %d bytes " \
344 "of data in to %d sized variable", \
346 (int) amount, (int) sizeof (VAL)); \
347 amount = sizeof (VAL); \
349 if (ENABLE_CHECKING) \
350 assert ((PTR) <= (END)); \
351 size_t avail = (END) - (PTR); \
354 if (amount > avail) \
359 (VAL) = (FUNC) ((PTR), amount); \
365 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
366 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
368 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
369 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
371 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
372 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
374 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
375 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
377 typedef struct State_Machine_Registers
386 unsigned char op_index
;
387 unsigned char end_sequence
;
388 /* This variable hold the number of the last entry seen
389 in the File Table. */
390 unsigned int last_file_entry
;
393 static SMR state_machine_regs
;
396 reset_state_machine (int is_stmt
)
398 state_machine_regs
.address
= 0;
399 state_machine_regs
.view
= 0;
400 state_machine_regs
.op_index
= 0;
401 state_machine_regs
.file
= 1;
402 state_machine_regs
.line
= 1;
403 state_machine_regs
.column
= 0;
404 state_machine_regs
.is_stmt
= is_stmt
;
405 state_machine_regs
.basic_block
= 0;
406 state_machine_regs
.end_sequence
= 0;
407 state_machine_regs
.last_file_entry
= 0;
410 /* Handled an extend line op.
411 Returns the number of bytes read. */
414 process_extended_line_op (unsigned char * data
,
418 unsigned char op_code
;
419 size_t len
, header_len
;
421 unsigned char *orig_data
= data
;
424 READ_ULEB (len
, data
, end
);
425 header_len
= data
- orig_data
;
427 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
429 warn (_("Badly formed extended line op encountered!\n"));
435 printf (_(" Extended opcode %d: "), op_code
);
439 case DW_LNE_end_sequence
:
440 printf (_("End of Sequence\n\n"));
441 reset_state_machine (is_stmt
);
444 case DW_LNE_set_address
:
445 /* PR 17512: file: 002-100480-0.004. */
448 warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"),
453 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
454 printf (_("set Address to %#" PRIx64
"\n"), adr
);
455 state_machine_regs
.address
= adr
;
456 state_machine_regs
.view
= 0;
457 state_machine_regs
.op_index
= 0;
460 case DW_LNE_define_file
:
461 printf (_("define new File Table entry\n"));
462 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
463 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
469 l
= strnlen ((char *) data
, end
- data
);
473 READ_ULEB (val
, data
, end
);
474 printf ("%" PRIu64
"\t", val
);
475 READ_ULEB (val
, data
, end
);
476 printf ("%" PRIu64
"\t", val
);
477 READ_ULEB (val
, data
, end
);
478 printf ("%" PRIu64
"\t", val
);
479 printf ("%.*s\n\n", (int) l
, name
);
482 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
483 warn (_("DW_LNE_define_file: Bad opcode length\n"));
486 case DW_LNE_set_discriminator
:
487 READ_ULEB (val
, data
, end
);
488 printf (_("set Discriminator to %" PRIu64
"\n"), val
);
492 case DW_LNE_HP_negate_is_UV_update
:
493 printf ("DW_LNE_HP_negate_is_UV_update\n");
495 case DW_LNE_HP_push_context
:
496 printf ("DW_LNE_HP_push_context\n");
498 case DW_LNE_HP_pop_context
:
499 printf ("DW_LNE_HP_pop_context\n");
501 case DW_LNE_HP_set_file_line_column
:
502 printf ("DW_LNE_HP_set_file_line_column\n");
504 case DW_LNE_HP_set_routine_name
:
505 printf ("DW_LNE_HP_set_routine_name\n");
507 case DW_LNE_HP_set_sequence
:
508 printf ("DW_LNE_HP_set_sequence\n");
510 case DW_LNE_HP_negate_post_semantics
:
511 printf ("DW_LNE_HP_negate_post_semantics\n");
513 case DW_LNE_HP_negate_function_exit
:
514 printf ("DW_LNE_HP_negate_function_exit\n");
516 case DW_LNE_HP_negate_front_end_logical
:
517 printf ("DW_LNE_HP_negate_front_end_logical\n");
519 case DW_LNE_HP_define_proc
:
520 printf ("DW_LNE_HP_define_proc\n");
522 case DW_LNE_HP_source_file_correlation
:
524 unsigned char *edata
= data
+ len
- 1;
526 printf ("DW_LNE_HP_source_file_correlation\n");
532 READ_ULEB (opc
, data
, edata
);
536 case DW_LNE_HP_SFC_formfeed
:
537 printf (" DW_LNE_HP_SFC_formfeed\n");
539 case DW_LNE_HP_SFC_set_listing_line
:
540 READ_ULEB (val
, data
, edata
);
541 printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64
")\n",
544 case DW_LNE_HP_SFC_associate
:
545 printf (" DW_LNE_HP_SFC_associate ");
546 READ_ULEB (val
, data
, edata
);
547 printf ("(%" PRIu64
, val
);
548 READ_ULEB (val
, data
, edata
);
549 printf (",%" PRIu64
, val
);
550 READ_ULEB (val
, data
, edata
);
551 printf (",%" PRIu64
")\n", val
);
554 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
564 unsigned int rlen
= len
- 1;
566 if (op_code
>= DW_LNE_lo_user
567 /* The test against DW_LNW_hi_user is redundant due to
568 the limited range of the unsigned char data type used
570 /*&& op_code <= DW_LNE_hi_user*/)
571 printf (_("user defined: "));
573 printf (_("UNKNOWN: "));
574 printf (_("length %d ["), rlen
);
576 printf (" %02x", *data
++);
582 return len
+ header_len
;
585 static const unsigned char *
586 fetch_indirect_string (uint64_t offset
)
588 struct dwarf_section
*section
= &debug_displays
[str
].section
;
589 const unsigned char * ret
;
591 if (section
->start
== NULL
)
592 return (const unsigned char *) _("<no .debug_str section>");
594 if (offset
>= section
->size
)
596 warn (_("DW_FORM_strp offset too big: %#" PRIx64
"\n"), offset
);
597 return (const unsigned char *) _("<offset is too big>");
600 ret
= section
->start
+ offset
;
601 /* Unfortunately we cannot rely upon the .debug_str section ending with a
602 NUL byte. Since our caller is expecting to receive a well formed C
603 string we test for the lack of a terminating byte here. */
604 if (strnlen ((const char *) ret
, section
->size
- offset
)
605 == section
->size
- offset
)
606 ret
= (const unsigned char *)
607 _("<no NUL byte at end of .debug_str section>");
612 static const unsigned char *
613 fetch_indirect_line_string (uint64_t offset
)
615 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
616 const unsigned char * ret
;
618 if (section
->start
== NULL
)
619 return (const unsigned char *) _("<no .debug_line_str section>");
621 if (offset
>= section
->size
)
623 warn (_("DW_FORM_line_strp offset too big: %#" PRIx64
"\n"), offset
);
624 return (const unsigned char *) _("<offset is too big>");
627 ret
= section
->start
+ offset
;
628 /* Unfortunately we cannot rely upon the .debug_line_str section ending
629 with a NUL byte. Since our caller is expecting to receive a well formed
630 C string we test for the lack of a terminating byte here. */
631 if (strnlen ((const char *) ret
, section
->size
- offset
)
632 == section
->size
- offset
)
633 ret
= (const unsigned char *)
634 _("<no NUL byte at end of .debug_line_str section>");
640 fetch_indexed_string (uint64_t idx
,
641 struct cu_tu_set
*this_set
,
642 uint64_t offset_size
,
644 uint64_t str_offsets_base
)
646 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
647 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
648 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
649 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
650 uint64_t index_offset
;
654 if (index_section
->start
== NULL
)
655 return (dwo
? _("<no .debug_str_offsets.dwo section>")
656 : _("<no .debug_str_offsets section>"));
658 if (str_section
->start
== NULL
)
659 return (dwo
? _("<no .debug_str.dwo section>")
660 : _("<no .debug_str section>"));
662 if (_mul_overflow (idx
, offset_size
, &index_offset
)
664 && ((index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
])
665 < this_set
->section_offsets
[DW_SECT_STR_OFFSETS
]))
666 || (index_offset
+= str_offsets_base
) < str_offsets_base
667 || index_offset
+ offset_size
< offset_size
668 || index_offset
+ offset_size
> index_section
->size
)
670 warn (_("string index of %" PRIu64
" converts to an offset of %#" PRIx64
671 " which is too big for section %s"),
672 idx
, index_offset
, str_section
->name
);
674 return _("<string index too big>");
677 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
679 str_offset
-= str_section
->address
;
680 if (str_offset
>= str_section
->size
)
682 warn (_("indirect offset too big: %#" PRIx64
"\n"), str_offset
);
683 return _("<indirect index offset is too big>");
686 ret
= (const char *) str_section
->start
+ str_offset
;
688 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
689 Since our caller is expecting to receive a well formed C string we test
690 for the lack of a terminating byte here. */
691 if (strnlen (ret
, str_section
->size
- str_offset
)
692 == str_section
->size
- str_offset
)
693 return _("<no NUL byte at end of section>");
699 fetch_indexed_addr (uint64_t offset
, uint32_t num_bytes
)
701 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
703 if (section
->start
== NULL
)
705 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
709 if (offset
+ num_bytes
> section
->size
)
711 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
712 section
->name
, offset
);
716 return byte_get (section
->start
+ offset
, num_bytes
);
719 /* Fetch a value from a debug section that has been indexed by
720 something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
721 Returns -1 if the value could not be found. */
724 fetch_indexed_value (uint64_t idx
,
725 enum dwarf_section_display_enum sec_enum
,
726 uint64_t base_address
)
728 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
730 if (section
->start
== NULL
)
732 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
736 if (section
->size
< 4)
738 warn (_("Section %s is too small to contain an value indexed from another section!\n"),
743 uint32_t pointer_size
, bias
;
745 if (byte_get (section
->start
, 4) == 0xffffffff)
756 uint64_t offset
= idx
* pointer_size
;
758 /* Offsets are biased by the size of the section header
761 offset
+= base_address
;
765 if (offset
+ pointer_size
> section
->size
)
767 warn (_("Offset into section %s too big: %#" PRIx64
"\n"),
768 section
->name
, offset
);
772 return byte_get (section
->start
+ offset
, pointer_size
);
775 /* FIXME: There are better and more efficient ways to handle
776 these structures. For now though, I just want something that
777 is simple to implement. */
778 /* Records a single attribute in an abbrev. */
779 typedef struct abbrev_attr
781 unsigned long attribute
;
783 int64_t implicit_const
;
784 struct abbrev_attr
*next
;
788 /* Records a single abbrev. */
789 typedef struct abbrev_entry
791 unsigned long number
;
794 struct abbrev_attr
* first_attr
;
795 struct abbrev_attr
* last_attr
;
796 struct abbrev_entry
* next
;
800 /* Records a set of abbreviations. */
801 typedef struct abbrev_list
803 abbrev_entry
* first_abbrev
;
804 abbrev_entry
* last_abbrev
;
806 struct abbrev_list
* next
;
807 unsigned char * start_of_next_abbrevs
;
811 /* Records all the abbrevs found so far. */
812 static struct abbrev_list
* abbrev_lists
= NULL
;
814 typedef struct abbrev_map
821 /* Maps between CU offsets and abbrev sets. */
822 static abbrev_map
* cu_abbrev_map
= NULL
;
823 static unsigned long num_abbrev_map_entries
= 0;
824 static unsigned long next_free_abbrev_map_entry
= 0;
826 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
827 #define ABBREV_MAP_ENTRIES_INCREMENT 8
830 record_abbrev_list_for_cu (uint64_t start
, uint64_t end
,
831 abbrev_list
*list
, abbrev_list
*free_list
)
833 if (free_list
!= NULL
)
835 list
->next
= abbrev_lists
;
839 if (cu_abbrev_map
== NULL
)
841 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
842 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
844 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
846 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
847 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
850 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
851 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
852 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
853 next_free_abbrev_map_entry
++;
857 free_abbrev_list (abbrev_list
*list
)
859 abbrev_entry
*abbrv
= list
->first_abbrev
;
863 abbrev_attr
*attr
= abbrv
->first_attr
;
867 abbrev_attr
*next_attr
= attr
->next
;
872 abbrev_entry
*next_abbrev
= abbrv
->next
;
877 abbrev_list
*next
= list
->next
;
883 free_all_abbrevs (void)
886 abbrev_lists
= free_abbrev_list (abbrev_lists
);
888 free (cu_abbrev_map
);
889 cu_abbrev_map
= NULL
;
890 next_free_abbrev_map_entry
= 0;
894 find_abbrev_list_by_raw_abbrev (unsigned char *raw
)
898 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
899 if (list
->raw
== raw
)
905 /* Find the abbreviation map for the CU that includes OFFSET.
906 OFFSET is an absolute offset from the start of the .debug_info section. */
907 /* FIXME: This function is going to slow down readelf & objdump.
908 Not caching abbrevs is likely the answer. */
911 find_abbrev_map_by_offset (uint64_t offset
)
915 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
916 if (cu_abbrev_map
[i
].start
<= offset
917 && cu_abbrev_map
[i
].end
> offset
)
918 return cu_abbrev_map
+ i
;
924 add_abbrev (unsigned long number
,
929 abbrev_entry
* entry
;
931 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
933 entry
->number
= number
;
935 entry
->children
= children
;
936 entry
->first_attr
= NULL
;
937 entry
->last_attr
= NULL
;
940 assert (list
!= NULL
);
942 if (list
->first_abbrev
== NULL
)
943 list
->first_abbrev
= entry
;
945 list
->last_abbrev
->next
= entry
;
947 list
->last_abbrev
= entry
;
951 add_abbrev_attr (unsigned long attribute
,
953 int64_t implicit_const
,
958 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
960 attr
->attribute
= attribute
;
962 attr
->implicit_const
= implicit_const
;
965 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
967 if (list
->last_abbrev
->first_attr
== NULL
)
968 list
->last_abbrev
->first_attr
= attr
;
970 list
->last_abbrev
->last_attr
->next
= attr
;
972 list
->last_abbrev
->last_attr
= attr
;
975 /* Return processed (partial) contents of a .debug_abbrev section.
976 Returns NULL on errors. */
979 process_abbrev_set (struct dwarf_section
*section
,
980 unsigned char *start
,
983 abbrev_list
*list
= xmalloc (sizeof (*list
));
984 list
->first_abbrev
= NULL
;
985 list
->last_abbrev
= NULL
;
993 unsigned long attribute
;
996 READ_ULEB (entry
, start
, end
);
998 /* A single zero is supposed to end the set according
999 to the standard. If there's more, then signal that to
1001 if (start
== end
|| entry
== 0)
1003 list
->start_of_next_abbrevs
= start
!= end
? start
: NULL
;
1007 READ_ULEB (tag
, start
, end
);
1009 return free_abbrev_list (list
);
1011 children
= *start
++;
1013 add_abbrev (entry
, tag
, children
, list
);
1018 /* Initialize it due to a false compiler warning. */
1019 int64_t implicit_const
= -1;
1021 READ_ULEB (attribute
, start
, end
);
1025 READ_ULEB (form
, start
, end
);
1029 if (form
== DW_FORM_implicit_const
)
1031 READ_SLEB (implicit_const
, start
, end
);
1036 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1038 while (attribute
!= 0);
1041 /* Report the missing single zero which ends the section. */
1042 error (_("%s section not zero terminated\n"), section
->name
);
1044 return free_abbrev_list (list
);
1047 /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE
1048 plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE.
1049 If FREE_LIST is non-NULL search the already decoded abbrevs on
1050 abbrev_lists first and if found set *FREE_LIST to NULL. If
1051 searching doesn't find a matching abbrev, set *FREE_LIST to the
1052 newly allocated list. If FREE_LIST is NULL, no search is done and
1053 the returned abbrev_list is always newly allocated. */
1055 static abbrev_list
*
1056 find_and_process_abbrev_set (struct dwarf_section
*section
,
1057 uint64_t abbrev_base
,
1058 uint64_t abbrev_size
,
1059 uint64_t abbrev_offset
,
1060 abbrev_list
**free_list
)
1065 if (abbrev_base
>= section
->size
1066 || abbrev_size
> section
->size
- abbrev_base
)
1068 /* PR 17531: file:4bcd9ce9. */
1069 warn (_("Debug info is corrupted, abbrev size (%#" PRIx64
")"
1070 " is larger than abbrev section size (%#" PRIx64
")\n"),
1071 abbrev_base
+ abbrev_size
, section
->size
);
1074 if (abbrev_offset
>= abbrev_size
)
1076 warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64
")"
1077 " is larger than abbrev section size (%#" PRIx64
")\n"),
1078 abbrev_offset
, abbrev_size
);
1082 unsigned char *start
= section
->start
+ abbrev_base
+ abbrev_offset
;
1083 unsigned char *end
= section
->start
+ abbrev_base
+ abbrev_size
;
1084 abbrev_list
*list
= NULL
;
1086 list
= find_abbrev_list_by_raw_abbrev (start
);
1089 list
= process_abbrev_set (section
, start
, end
);
1097 get_TAG_name (uint64_t tag
)
1099 const char *name
= NULL
;
1101 if ((unsigned int) tag
== tag
)
1102 name
= get_DW_TAG_name ((unsigned int) tag
);
1105 static char buffer
[100];
1107 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1108 snprintf (buffer
, sizeof (buffer
),
1109 _("User TAG value: %#" PRIx64
), tag
);
1111 snprintf (buffer
, sizeof (buffer
),
1112 _("Unknown TAG value: %#" PRIx64
), tag
);
1120 get_FORM_name (unsigned long form
)
1122 const char *name
= NULL
;
1125 return "DW_FORM value: 0";
1127 if ((unsigned int) form
== form
)
1128 name
= get_DW_FORM_name ((unsigned int) form
);
1131 static char buffer
[100];
1133 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1141 get_IDX_name (unsigned long idx
)
1143 const char *name
= NULL
;
1145 if ((unsigned int) idx
== idx
)
1146 name
= get_DW_IDX_name ((unsigned int) idx
);
1149 static char buffer
[100];
1151 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1158 static unsigned char *
1159 display_block (unsigned char *data
,
1161 const unsigned char * const end
, char delimiter
)
1165 printf (_("%c%" PRIu64
" byte block: "), delimiter
, length
);
1167 return (unsigned char *) end
;
1169 maxlen
= end
- data
;
1170 length
= length
> maxlen
? maxlen
: length
;
1173 printf ("%" PRIx64
" ", byte_get (data
++, 1));
1179 decode_location_expression (unsigned char * data
,
1180 unsigned int pointer_size
,
1181 unsigned int offset_size
,
1185 struct dwarf_section
* section
)
1190 unsigned char *end
= data
+ length
;
1191 int need_frame_base
= 0;
1200 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1201 printf ("DW_OP_addr: %" PRIx64
, uvalue
);
1204 printf ("DW_OP_deref");
1207 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1208 printf ("DW_OP_const1u: %" PRIu64
, uvalue
);
1211 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1212 printf ("DW_OP_const1s: %" PRId64
, svalue
);
1215 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1216 printf ("DW_OP_const2u: %" PRIu64
, uvalue
);
1219 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1220 printf ("DW_OP_const2s: %" PRId64
, svalue
);
1223 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1224 printf ("DW_OP_const4u: %" PRIu64
, uvalue
);
1227 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1228 printf ("DW_OP_const4s: %" PRId64
, svalue
);
1231 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1232 printf ("DW_OP_const8u: %" PRIu64
, uvalue
);
1235 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 8, end
);
1236 printf ("DW_OP_const8s: %" PRId64
, svalue
);
1239 READ_ULEB (uvalue
, data
, end
);
1240 printf ("DW_OP_constu: %" PRIu64
, uvalue
);
1243 READ_SLEB (svalue
, data
, end
);
1244 printf ("DW_OP_consts: %" PRId64
, svalue
);
1247 printf ("DW_OP_dup");
1250 printf ("DW_OP_drop");
1253 printf ("DW_OP_over");
1256 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1257 printf ("DW_OP_pick: %" PRIu64
, uvalue
);
1260 printf ("DW_OP_swap");
1263 printf ("DW_OP_rot");
1266 printf ("DW_OP_xderef");
1269 printf ("DW_OP_abs");
1272 printf ("DW_OP_and");
1275 printf ("DW_OP_div");
1278 printf ("DW_OP_minus");
1281 printf ("DW_OP_mod");
1284 printf ("DW_OP_mul");
1287 printf ("DW_OP_neg");
1290 printf ("DW_OP_not");
1293 printf ("DW_OP_or");
1296 printf ("DW_OP_plus");
1298 case DW_OP_plus_uconst
:
1299 READ_ULEB (uvalue
, data
, end
);
1300 printf ("DW_OP_plus_uconst: %" PRIu64
, uvalue
);
1303 printf ("DW_OP_shl");
1306 printf ("DW_OP_shr");
1309 printf ("DW_OP_shra");
1312 printf ("DW_OP_xor");
1315 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1316 printf ("DW_OP_bra: %" PRId64
, svalue
);
1319 printf ("DW_OP_eq");
1322 printf ("DW_OP_ge");
1325 printf ("DW_OP_gt");
1328 printf ("DW_OP_le");
1331 printf ("DW_OP_lt");
1334 printf ("DW_OP_ne");
1337 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1338 printf ("DW_OP_skip: %" PRId64
, svalue
);
1373 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1408 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1409 regname (op
- DW_OP_reg0
, 1));
1444 READ_SLEB (svalue
, data
, end
);
1445 printf ("DW_OP_breg%d (%s): %" PRId64
,
1446 op
- DW_OP_breg0
, regname (op
- DW_OP_breg0
, 1), svalue
);
1450 READ_ULEB (uvalue
, data
, end
);
1451 printf ("DW_OP_regx: %" PRIu64
" (%s)",
1452 uvalue
, regname (uvalue
, 1));
1455 need_frame_base
= 1;
1456 READ_SLEB (svalue
, data
, end
);
1457 printf ("DW_OP_fbreg: %" PRId64
, svalue
);
1460 READ_ULEB (uvalue
, data
, end
);
1461 READ_SLEB (svalue
, data
, end
);
1462 printf ("DW_OP_bregx: %" PRIu64
" (%s) %" PRId64
,
1463 uvalue
, regname (uvalue
, 1), svalue
);
1466 READ_ULEB (uvalue
, data
, end
);
1467 printf ("DW_OP_piece: %" PRIu64
, uvalue
);
1469 case DW_OP_deref_size
:
1470 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1471 printf ("DW_OP_deref_size: %" PRIu64
, uvalue
);
1473 case DW_OP_xderef_size
:
1474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1475 printf ("DW_OP_xderef_size: %" PRIu64
, uvalue
);
1478 printf ("DW_OP_nop");
1481 /* DWARF 3 extensions. */
1482 case DW_OP_push_object_address
:
1483 printf ("DW_OP_push_object_address");
1486 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1487 this ought to be an 8-byte wide computation. */
1488 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1489 printf ("DW_OP_call2: <%#" PRIx64
">", svalue
+ cu_offset
);
1492 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1493 this ought to be an 8-byte wide computation. */
1494 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1495 printf ("DW_OP_call4: <%#" PRIx64
">", svalue
+ cu_offset
);
1497 case DW_OP_call_ref
:
1498 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1499 this ought to be an 8-byte wide computation. */
1500 if (dwarf_version
== -1)
1502 printf (_("(DW_OP_call_ref in frame info)"));
1503 /* No way to tell where the next op is, so just bail. */
1504 return need_frame_base
;
1506 if (dwarf_version
== 2)
1508 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1512 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1514 printf ("DW_OP_call_ref: <%#" PRIx64
">", uvalue
);
1516 case DW_OP_form_tls_address
:
1517 printf ("DW_OP_form_tls_address");
1519 case DW_OP_call_frame_cfa
:
1520 printf ("DW_OP_call_frame_cfa");
1522 case DW_OP_bit_piece
:
1523 printf ("DW_OP_bit_piece: ");
1524 READ_ULEB (uvalue
, data
, end
);
1525 printf (_("size: %" PRIu64
" "), uvalue
);
1526 READ_ULEB (uvalue
, data
, end
);
1527 printf (_("offset: %" PRIu64
" "), uvalue
);
1530 /* DWARF 4 extensions. */
1531 case DW_OP_stack_value
:
1532 printf ("DW_OP_stack_value");
1535 case DW_OP_implicit_value
:
1536 printf ("DW_OP_implicit_value");
1537 READ_ULEB (uvalue
, data
, end
);
1538 data
= display_block (data
, uvalue
, end
, ' ');
1541 /* GNU extensions. */
1542 case DW_OP_GNU_push_tls_address
:
1543 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1545 case DW_OP_GNU_uninit
:
1546 printf ("DW_OP_GNU_uninit");
1547 /* FIXME: Is there data associated with this OP ? */
1549 case DW_OP_GNU_encoded_addr
:
1556 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1558 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1559 print_hex_ns (addr
, pointer_size
);
1562 case DW_OP_implicit_pointer
:
1563 case DW_OP_GNU_implicit_pointer
:
1564 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1565 this ought to be an 8-byte wide computation. */
1566 if (dwarf_version
== -1)
1568 printf (_("(%s in frame info)"),
1569 (op
== DW_OP_implicit_pointer
1570 ? "DW_OP_implicit_pointer"
1571 : "DW_OP_GNU_implicit_pointer"));
1572 /* No way to tell where the next op is, so just bail. */
1573 return need_frame_base
;
1575 if (dwarf_version
== 2)
1577 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1581 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1583 READ_SLEB (svalue
, data
, end
);
1584 printf ("%s: <%#" PRIx64
"> %" PRId64
,
1585 (op
== DW_OP_implicit_pointer
1586 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1589 case DW_OP_entry_value
:
1590 case DW_OP_GNU_entry_value
:
1591 READ_ULEB (uvalue
, data
, end
);
1592 /* PR 17531: file: 0cc9cd00. */
1593 if (uvalue
> (size_t) (end
- data
))
1594 uvalue
= end
- data
;
1595 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1596 : "DW_OP_GNU_entry_value"));
1597 if (decode_location_expression (data
, pointer_size
, offset_size
,
1598 dwarf_version
, uvalue
,
1599 cu_offset
, section
))
1600 need_frame_base
= 1;
1604 case DW_OP_const_type
:
1605 case DW_OP_GNU_const_type
:
1606 READ_ULEB (uvalue
, data
, end
);
1607 printf ("%s: <%#" PRIx64
"> ",
1608 (op
== DW_OP_const_type
? "DW_OP_const_type"
1609 : "DW_OP_GNU_const_type"),
1610 cu_offset
+ uvalue
);
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1612 data
= display_block (data
, uvalue
, end
, ' ');
1614 case DW_OP_regval_type
:
1615 case DW_OP_GNU_regval_type
:
1616 READ_ULEB (uvalue
, data
, end
);
1617 printf ("%s: %" PRIu64
" (%s)",
1618 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1619 : "DW_OP_GNU_regval_type"),
1620 uvalue
, regname (uvalue
, 1));
1621 READ_ULEB (uvalue
, data
, end
);
1622 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1624 case DW_OP_deref_type
:
1625 case DW_OP_GNU_deref_type
:
1626 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1627 printf ("%s: %" PRId64
,
1628 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1629 : "DW_OP_GNU_deref_type"),
1631 READ_ULEB (uvalue
, data
, end
);
1632 printf (" <%#" PRIx64
">", cu_offset
+ uvalue
);
1635 case DW_OP_GNU_convert
:
1636 READ_ULEB (uvalue
, data
, end
);
1637 printf ("%s <%#" PRIx64
">",
1638 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1639 uvalue
? cu_offset
+ uvalue
: uvalue
);
1641 case DW_OP_reinterpret
:
1642 case DW_OP_GNU_reinterpret
:
1643 READ_ULEB (uvalue
, data
, end
);
1644 printf ("%s <%#" PRIx64
">",
1645 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1646 : "DW_OP_GNU_reinterpret"),
1647 uvalue
? cu_offset
+ uvalue
: uvalue
);
1649 case DW_OP_GNU_parameter_ref
:
1650 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1651 printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64
">",
1652 cu_offset
+ uvalue
);
1655 READ_ULEB (uvalue
, data
, end
);
1656 printf ("DW_OP_addrx <%#" PRIx64
">", uvalue
);
1658 case DW_OP_GNU_addr_index
:
1659 READ_ULEB (uvalue
, data
, end
);
1660 printf ("DW_OP_GNU_addr_index <%#" PRIx64
">", uvalue
);
1662 case DW_OP_GNU_const_index
:
1663 READ_ULEB (uvalue
, data
, end
);
1664 printf ("DW_OP_GNU_const_index <%#" PRIx64
">", uvalue
);
1666 case DW_OP_GNU_variable_value
:
1667 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1668 this ought to be an 8-byte wide computation. */
1669 if (dwarf_version
== -1)
1671 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1672 /* No way to tell where the next op is, so just bail. */
1673 return need_frame_base
;
1675 if (dwarf_version
== 2)
1677 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1683 printf ("DW_OP_GNU_variable_value: <%#" PRIx64
">", uvalue
);
1686 /* HP extensions. */
1687 case DW_OP_HP_is_value
:
1688 printf ("DW_OP_HP_is_value");
1689 /* FIXME: Is there data associated with this OP ? */
1691 case DW_OP_HP_fltconst4
:
1692 printf ("DW_OP_HP_fltconst4");
1693 /* FIXME: Is there data associated with this OP ? */
1695 case DW_OP_HP_fltconst8
:
1696 printf ("DW_OP_HP_fltconst8");
1697 /* FIXME: Is there data associated with this OP ? */
1699 case DW_OP_HP_mod_range
:
1700 printf ("DW_OP_HP_mod_range");
1701 /* FIXME: Is there data associated with this OP ? */
1703 case DW_OP_HP_unmod_range
:
1704 printf ("DW_OP_HP_unmod_range");
1705 /* FIXME: Is there data associated with this OP ? */
1708 printf ("DW_OP_HP_tls");
1709 /* FIXME: Is there data associated with this OP ? */
1712 /* PGI (STMicroelectronics) extensions. */
1713 case DW_OP_PGI_omp_thread_num
:
1714 /* Pushes the thread number for the current thread as it would be
1715 returned by the standard OpenMP library function:
1716 omp_get_thread_num(). The "current thread" is the thread for
1717 which the expression is being evaluated. */
1718 printf ("DW_OP_PGI_omp_thread_num");
1722 if (op
>= DW_OP_lo_user
1723 && op
<= DW_OP_hi_user
)
1724 printf (_("(User defined location op %#x)"), op
);
1726 printf (_("(Unknown location op %#x)"), op
);
1727 /* No way to tell where the next op is, so just bail. */
1728 return need_frame_base
;
1731 /* Separate the ops. */
1736 return need_frame_base
;
1739 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1740 This is used for DWARF package files. */
1742 static struct cu_tu_set
*
1743 find_cu_tu_set_v2 (uint64_t cu_offset
, int do_types
)
1745 struct cu_tu_set
*p
;
1747 unsigned int dw_sect
;
1753 dw_sect
= DW_SECT_TYPES
;
1759 dw_sect
= DW_SECT_INFO
;
1763 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1772 fetch_alt_indirect_string (uint64_t offset
)
1776 if (! do_follow_links
)
1779 if (first_separate_info
== NULL
)
1780 return _("<no links available>");
1782 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1784 struct dwarf_section
* section
;
1787 if (! load_debug_section (separate_debug_str
, i
->handle
))
1790 section
= &debug_displays
[separate_debug_str
].section
;
1792 if (section
->start
== NULL
)
1795 if (offset
>= section
->size
)
1798 ret
= (const char *) (section
->start
+ offset
);
1799 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1800 NUL byte. Since our caller is expecting to receive a well formed C
1801 string we test for the lack of a terminating byte here. */
1802 if (strnlen ((const char *) ret
, section
->size
- offset
)
1803 == section
->size
- offset
)
1804 return _("<no NUL byte at end of alt .debug_str section>");
1809 warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64
")"
1810 " too big or no string sections available\n"), offset
);
1811 return _("<offset is too big>");
1815 get_AT_name (unsigned long attribute
)
1820 return "DW_AT value: 0";
1822 /* One value is shared by the MIPS and HP extensions: */
1823 if (attribute
== DW_AT_MIPS_fde
)
1824 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1826 name
= get_DW_AT_name (attribute
);
1830 static char buffer
[100];
1832 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1841 add_dwo_info (const char * value
, uint64_t cu_offset
, dwo_type type
)
1843 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1845 dwinfo
->type
= type
;
1846 dwinfo
->value
= value
;
1847 dwinfo
->cu_offset
= cu_offset
;
1848 dwinfo
->next
= first_dwo_info
;
1849 first_dwo_info
= dwinfo
;
1853 add_dwo_name (const char * name
, uint64_t cu_offset
)
1855 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1859 add_dwo_dir (const char * dir
, uint64_t cu_offset
)
1861 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1865 add_dwo_id (const char * id
, uint64_t cu_offset
)
1867 add_dwo_info (id
, cu_offset
, DWO_ID
);
1871 free_dwo_info (void)
1876 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1878 next
= dwinfo
->next
;
1881 first_dwo_info
= NULL
;
1884 /* Ensure that START + UVALUE is less than END.
1885 Return an adjusted UVALUE if necessary to ensure this relationship. */
1887 static inline uint64_t
1888 check_uvalue (const unsigned char *start
,
1890 const unsigned char *end
)
1892 uint64_t max_uvalue
= end
- start
;
1894 /* See PR 17512: file: 008-103549-0.001:0.1.
1895 and PR 24829 for examples of where these tests are triggered. */
1896 if (uvalue
> max_uvalue
)
1898 warn (_("Corrupt attribute block length: %#" PRIx64
"\n"), uvalue
);
1899 uvalue
= max_uvalue
;
1905 static unsigned char *
1906 skip_attr_bytes (unsigned long form
,
1907 unsigned char *data
,
1909 uint64_t pointer_size
,
1910 uint64_t offset_size
,
1912 uint64_t *value_return
)
1915 uint64_t uvalue
= 0;
1922 case DW_FORM_ref_addr
:
1923 if (dwarf_version
== 2)
1924 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1925 else if (dwarf_version
> 2)
1926 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1932 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1936 case DW_FORM_line_strp
:
1937 case DW_FORM_sec_offset
:
1938 case DW_FORM_GNU_ref_alt
:
1939 case DW_FORM_GNU_strp_alt
:
1940 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1943 case DW_FORM_flag_present
:
1951 case DW_FORM_addrx1
:
1952 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1956 case DW_FORM_addrx3
:
1957 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1963 case DW_FORM_addrx2
:
1964 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1970 case DW_FORM_addrx4
:
1971 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1975 READ_SLEB (svalue
, data
, end
);
1979 case DW_FORM_ref_udata
:
1981 case DW_FORM_GNU_str_index
:
1983 case DW_FORM_GNU_addr_index
:
1985 case DW_FORM_loclistx
:
1986 case DW_FORM_rnglistx
:
1987 READ_ULEB (uvalue
, data
, end
);
1991 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
1995 case DW_FORM_ref_sig8
:
1999 case DW_FORM_data16
:
2003 case DW_FORM_string
:
2004 inc
= strnlen ((char *) data
, end
- data
) + 1;
2008 case DW_FORM_exprloc
:
2009 READ_ULEB (uvalue
, data
, end
);
2013 case DW_FORM_block1
:
2014 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2018 case DW_FORM_block2
:
2019 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2023 case DW_FORM_block4
:
2024 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2028 case DW_FORM_indirect
:
2029 READ_ULEB (form
, data
, end
);
2030 if (form
== DW_FORM_implicit_const
)
2031 SKIP_ULEB (data
, end
);
2032 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2033 dwarf_version
, value_return
);
2039 * value_return
= uvalue
;
2040 if (inc
<= (size_t) (end
- data
))
2047 /* Given form FORM with value UVALUE, locate and return the abbreviation
2048 associated with it. */
2050 static abbrev_entry
*
2051 get_type_abbrev_from_form (unsigned long form
,
2052 unsigned long uvalue
,
2054 unsigned char *cu_end
,
2055 const struct dwarf_section
*section
,
2056 unsigned long *abbrev_num_return
,
2057 unsigned char **data_return
,
2058 abbrev_map
**map_return
)
2060 unsigned long abbrev_number
;
2062 abbrev_entry
* entry
;
2063 unsigned char * data
;
2065 if (abbrev_num_return
!= NULL
)
2066 * abbrev_num_return
= 0;
2067 if (data_return
!= NULL
)
2068 * data_return
= NULL
;
2072 case DW_FORM_GNU_ref_alt
:
2073 case DW_FORM_ref_sig8
:
2074 /* FIXME: We are unable to handle this form at the moment. */
2077 case DW_FORM_ref_addr
:
2078 if (uvalue
>= section
->size
)
2080 warn (_("Unable to resolve ref_addr form: uvalue %lx "
2081 "> section size %" PRIx64
" (%s)\n"),
2082 uvalue
, section
->size
, section
->name
);
2087 case DW_FORM_ref_sup4
:
2088 case DW_FORM_ref_sup8
:
2095 case DW_FORM_ref_udata
:
2096 if (uvalue
+ cu_offset
< uvalue
2097 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2099 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %" PRIx64
2100 " > CU size %tx\n"),
2101 uvalue
, cu_offset
, cu_end
- section
->start
);
2104 uvalue
+= cu_offset
;
2107 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2110 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2114 data
= (unsigned char *) section
->start
+ uvalue
;
2115 map
= find_abbrev_map_by_offset (uvalue
);
2119 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2122 if (map
->list
== NULL
)
2124 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2128 if (map_return
!= NULL
)
2130 if (form
== DW_FORM_ref_addr
)
2136 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2138 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2139 if (entry
->number
== abbrev_number
)
2142 if (abbrev_num_return
!= NULL
)
2143 * abbrev_num_return
= abbrev_number
;
2145 if (data_return
!= NULL
)
2146 * data_return
= data
;
2149 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2154 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2155 can be determined to be a signed type. The data for ENTRY can be
2156 found starting at DATA. */
2159 get_type_signedness (abbrev_entry
*entry
,
2160 const struct dwarf_section
*section
,
2161 unsigned char *data
,
2164 uint64_t pointer_size
,
2165 uint64_t offset_size
,
2168 unsigned int nesting
)
2172 * is_signed
= false;
2174 #define MAX_NESTING 20
2175 if (nesting
> MAX_NESTING
)
2177 /* FIXME: Warn - or is this expected ?
2178 NB/ We need to avoid infinite recursion. */
2182 for (attr
= entry
->first_attr
;
2183 attr
!= NULL
&& attr
->attribute
;
2186 unsigned char * orig_data
= data
;
2187 uint64_t uvalue
= 0;
2189 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2190 offset_size
, dwarf_version
, & uvalue
);
2194 switch (attr
->attribute
)
2196 case DW_AT_linkage_name
:
2200 if (attr
->form
== DW_FORM_strp
)
2201 printf (", %s", fetch_indirect_string (uvalue
));
2202 else if (attr
->form
== DW_FORM_string
)
2203 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2210 abbrev_entry
*type_abbrev
;
2211 unsigned char *type_data
;
2214 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2219 NULL
/* abbrev num return */,
2222 if (type_abbrev
== NULL
)
2225 get_type_signedness (type_abbrev
, section
, type_data
,
2226 map
? section
->start
+ map
->end
: end
,
2227 map
? map
->start
: cu_offset
,
2228 pointer_size
, offset_size
, dwarf_version
,
2229 is_signed
, nesting
+ 1);
2233 case DW_AT_encoding
:
2234 /* Determine signness. */
2237 case DW_ATE_address
:
2238 /* FIXME - some architectures have signed addresses. */
2239 case DW_ATE_boolean
:
2240 case DW_ATE_unsigned
:
2241 case DW_ATE_unsigned_char
:
2242 case DW_ATE_unsigned_fixed
:
2243 * is_signed
= false;
2247 case DW_ATE_complex_float
:
2250 case DW_ATE_signed_char
:
2251 case DW_ATE_imaginary_float
:
2252 case DW_ATE_decimal_float
:
2253 case DW_ATE_signed_fixed
:
2263 read_and_print_leb128 (unsigned char *data
,
2264 unsigned int *bytes_read
,
2265 unsigned const char *end
,
2269 uint64_t val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2271 report_leb_status (status
);
2273 printf ("%" PRId64
, val
);
2275 printf ("%" PRIu64
, val
);
2279 display_discr_list (unsigned long form
,
2281 unsigned char *data
,
2284 unsigned char *end
= data
;
2288 printf ("[default]");
2295 case DW_FORM_block1
:
2296 case DW_FORM_block2
:
2297 case DW_FORM_block4
:
2298 /* Move data pointer back to the start of the byte array. */
2302 printf ("<corrupt>\n");
2303 warn (_("corrupt discr_list - not using a block form\n"));
2309 printf ("<corrupt>\n");
2310 warn (_("corrupt discr_list - block not long enough\n"));
2314 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2315 ? level_type_signed
[level
- 1] : false);
2320 unsigned char discriminant
;
2321 unsigned int bytes_read
;
2323 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2325 switch (discriminant
)
2329 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2335 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2339 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2344 printf ("<corrupt>\n");
2345 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2355 printf (")(signed)");
2357 printf (")(unsigned)");
2360 static unsigned char *
2361 read_and_display_attr_value (unsigned long attribute
,
2363 int64_t implicit_const
,
2364 unsigned char *start
,
2365 unsigned char *data
,
2368 uint64_t pointer_size
,
2369 uint64_t offset_size
,
2371 debug_info
*debug_info_p
,
2373 struct dwarf_section
*section
,
2374 struct cu_tu_set
*this_set
,
2379 uint64_t uvalue
= 0;
2380 uint64_t uvalue_hi
= 0;
2381 unsigned char *block_start
= NULL
;
2382 unsigned char *orig_data
= data
;
2384 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2386 warn (_("Corrupt attribute\n"));
2390 if (do_wide
&& ! do_loc
)
2392 /* PR 26847: Display the name of the form. */
2393 const char * name
= get_FORM_name (form
);
2395 /* For convenience we skip the DW_FORM_ prefix to the name. */
2397 name
+= 8; /* strlen ("DW_FORM_") */
2398 printf ("%c(%s)", delimiter
, name
);
2403 case DW_FORM_ref_addr
:
2404 if (dwarf_version
== 2)
2405 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2406 else if (dwarf_version
> 2)
2407 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2409 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2413 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2416 case DW_FORM_strp_sup
:
2418 case DW_FORM_line_strp
:
2419 case DW_FORM_sec_offset
:
2420 case DW_FORM_GNU_ref_alt
:
2421 case DW_FORM_GNU_strp_alt
:
2422 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2425 case DW_FORM_flag_present
:
2433 case DW_FORM_addrx1
:
2434 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2440 case DW_FORM_addrx2
:
2441 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2445 case DW_FORM_addrx3
:
2446 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2449 case DW_FORM_ref_sup4
:
2453 case DW_FORM_addrx4
:
2454 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2457 case DW_FORM_ref_sup8
:
2460 case DW_FORM_ref_sig8
:
2461 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2464 case DW_FORM_data16
:
2465 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2466 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2467 if (byte_get
!= byte_get_little_endian
)
2469 uint64_t utmp
= uvalue
;
2476 READ_SLEB (svalue
, data
, end
);
2480 case DW_FORM_GNU_str_index
:
2482 case DW_FORM_ref_udata
:
2484 case DW_FORM_GNU_addr_index
:
2486 case DW_FORM_loclistx
:
2487 case DW_FORM_rnglistx
:
2488 READ_ULEB (uvalue
, data
, end
);
2491 case DW_FORM_indirect
:
2492 READ_ULEB (form
, data
, end
);
2494 printf ("%c%s", delimiter
, get_FORM_name (form
));
2495 if (form
== DW_FORM_implicit_const
)
2496 READ_SLEB (implicit_const
, data
, end
);
2497 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2499 cu_offset
, pointer_size
,
2500 offset_size
, dwarf_version
,
2501 debug_info_p
, do_loc
,
2502 section
, this_set
, delimiter
, level
);
2504 case DW_FORM_implicit_const
:
2505 uvalue
= implicit_const
;
2514 case DW_FORM_ref_addr
:
2516 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2519 case DW_FORM_GNU_ref_alt
:
2523 /* We have already printed the form name. */
2524 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
);
2526 printf ("%c<alt %#" PRIx64
">", delimiter
, uvalue
);
2528 /* FIXME: Follow the reference... */
2534 case DW_FORM_ref_sup4
:
2535 case DW_FORM_ref_udata
:
2537 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2542 case DW_FORM_sec_offset
:
2544 printf ("%c%#" PRIx64
, delimiter
, uvalue
);
2547 case DW_FORM_flag_present
:
2553 printf ("%c%" PRId64
, delimiter
, uvalue
);
2558 printf ("%c%" PRIu64
, delimiter
, uvalue
);
2561 case DW_FORM_implicit_const
:
2563 printf ("%c%" PRId64
, delimiter
, implicit_const
);
2566 case DW_FORM_ref_sup8
:
2571 uint64_t utmp
= uvalue
;
2572 if (form
== DW_FORM_ref8
)
2574 printf ("%c%#" PRIx64
, delimiter
, utmp
);
2578 case DW_FORM_data16
:
2582 printf (" %#" PRIx64
, uvalue
);
2584 printf (" %#" PRIx64
"%016" PRIx64
, uvalue_hi
, uvalue
);
2588 case DW_FORM_string
:
2590 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2591 data
+= strnlen ((char *) data
, end
- data
);
2597 case DW_FORM_exprloc
:
2598 READ_ULEB (uvalue
, data
, end
);
2601 if (block_start
>= end
)
2603 warn (_("Block ends prematurely\n"));
2608 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2610 data
= block_start
+ uvalue
;
2615 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2616 if (op
!= DW_OP_addrx
)
2617 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2621 case DW_FORM_block1
:
2622 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2625 case DW_FORM_block2
:
2626 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2629 case DW_FORM_block4
:
2630 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2637 /* We have already displayed the form name. */
2638 printf (_("%c(offset: %#" PRIx64
"): %s"),
2639 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2641 printf (_("%c(indirect string, offset: %#" PRIx64
"): %s"),
2642 delimiter
, uvalue
, fetch_indirect_string (uvalue
));
2646 case DW_FORM_line_strp
:
2650 /* We have already displayed the form name. */
2651 printf (_("%c(offset: %#" PRIx64
"): %s"),
2652 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2654 printf (_("%c(indirect line string, offset: %#" PRIx64
"): %s"),
2655 delimiter
, uvalue
, fetch_indirect_line_string (uvalue
));
2659 case DW_FORM_GNU_str_index
:
2667 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2668 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2671 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2672 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2674 /* We have already displayed the form name. */
2675 printf (_("%c(offset: %#" PRIx64
"): %s"),
2676 delimiter
, uvalue
, strng
);
2678 printf (_("%c(indexed string: %#" PRIx64
"): %s"),
2679 delimiter
, uvalue
, strng
);
2683 case DW_FORM_GNU_strp_alt
:
2687 /* We have already displayed the form name. */
2688 printf (_("%c(offset: %#" PRIx64
") %s"),
2689 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2691 printf (_("%c(alt indirect string, offset: %#" PRIx64
") %s"),
2692 delimiter
, uvalue
, fetch_alt_indirect_string (uvalue
));
2696 case DW_FORM_indirect
:
2697 /* Handled above. */
2700 case DW_FORM_ref_sig8
:
2702 printf ("%c%s: %#" PRIx64
, delimiter
, do_wide
? "" : "signature",
2706 case DW_FORM_GNU_addr_index
:
2708 case DW_FORM_addrx1
:
2709 case DW_FORM_addrx2
:
2710 case DW_FORM_addrx3
:
2711 case DW_FORM_addrx4
:
2712 case DW_FORM_loclistx
:
2713 case DW_FORM_rnglistx
:
2717 const char *suffix
= strrchr (section
->name
, '.');
2718 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2720 if (form
== DW_FORM_loclistx
)
2724 idx
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2725 if (idx
!= (uint64_t) -1)
2726 idx
+= (offset_size
== 8) ? 20 : 12;
2728 else if (debug_info_p
== NULL
|| dwarf_version
> 4)
2730 idx
= fetch_indexed_value (uvalue
, loclists
, 0);
2734 /* We want to compute:
2735 idx = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2736 idx += debug_info_p->loclists_base;
2737 Fortunately we already have that sum cached in the
2738 loc_offsets array. */
2739 if (uvalue
< debug_info_p
->num_loc_offsets
)
2740 idx
= debug_info_p
->loc_offsets
[uvalue
];
2743 warn (_("loc_offset %" PRIu64
" too big\n"), uvalue
);
2748 else if (form
== DW_FORM_rnglistx
)
2752 idx
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2753 if (idx
!= (uint64_t) -1)
2754 idx
+= (offset_size
== 8) ? 20 : 12;
2758 if (debug_info_p
== NULL
)
2761 base
= debug_info_p
->rnglists_base
;
2762 /* We do not have a cached value this time, so we perform the
2763 computation manually. */
2764 idx
= fetch_indexed_value (uvalue
, rnglists
, base
);
2765 if (idx
!= (uint64_t) -1)
2771 if (debug_info_p
== NULL
)
2773 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2776 base
= debug_info_p
->addr_base
;
2778 base
+= uvalue
* pointer_size
;
2779 idx
= fetch_indexed_addr (base
, pointer_size
);
2782 /* We have already displayed the form name. */
2783 if (idx
!= (uint64_t) -1)
2784 printf (_("%c(index: %#" PRIx64
"): %#" PRIx64
),
2785 delimiter
, uvalue
, idx
);
2789 case DW_FORM_strp_sup
:
2791 printf ("%c<%#" PRIx64
">", delimiter
, uvalue
+ cu_offset
);
2795 warn (_("Unrecognized form: %#lx"), form
);
2796 /* What to do? Consume a byte maybe? */
2801 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2802 && num_debug_info_entries
== 0
2803 && debug_info_p
!= NULL
)
2807 case DW_AT_loclists_base
:
2808 if (debug_info_p
->loclists_base
)
2809 warn (_("CU @ %#" PRIx64
" has multiple loclists_base values "
2810 "(%#" PRIx64
" and %#" PRIx64
")"),
2811 debug_info_p
->cu_offset
,
2812 debug_info_p
->loclists_base
, uvalue
);
2816 warn (_("CU @ %#" PRIx64
" has has a negative loclists_base "
2817 "value of %#" PRIx64
" - treating as zero"),
2818 debug_info_p
->cu_offset
, svalue
);
2821 debug_info_p
->loclists_base
= uvalue
;
2824 case DW_AT_rnglists_base
:
2825 if (debug_info_p
->rnglists_base
)
2826 warn (_("CU @ %#" PRIx64
" has multiple rnglists_base values "
2827 "(%#" PRIx64
" and %#" PRIx64
")"),
2828 debug_info_p
->cu_offset
,
2829 debug_info_p
->rnglists_base
, uvalue
);
2833 warn (_("CU @ %#" PRIx64
" has has a negative rnglists_base "
2834 "value of %#" PRIx64
" - treating as zero"),
2835 debug_info_p
->cu_offset
, svalue
);
2838 debug_info_p
->rnglists_base
= uvalue
;
2841 case DW_AT_str_offsets_base
:
2842 if (debug_info_p
->str_offsets_base
)
2843 warn (_("CU @ %#" PRIx64
" has multiple str_offsets_base values "
2844 "%#" PRIx64
" and %#" PRIx64
")"),
2845 debug_info_p
->cu_offset
,
2846 debug_info_p
->str_offsets_base
, uvalue
);
2850 warn (_("CU @ %#" PRIx64
" has has a negative stroffsets_base "
2851 "value of %#" PRIx64
" - treating as zero"),
2852 debug_info_p
->cu_offset
, svalue
);
2855 debug_info_p
->str_offsets_base
= uvalue
;
2858 case DW_AT_frame_base
:
2859 have_frame_base
= 1;
2861 case DW_AT_location
:
2862 case DW_AT_GNU_locviews
:
2863 case DW_AT_string_length
:
2864 case DW_AT_return_addr
:
2865 case DW_AT_data_member_location
:
2866 case DW_AT_vtable_elem_location
:
2868 case DW_AT_static_link
:
2869 case DW_AT_use_location
:
2870 case DW_AT_call_value
:
2871 case DW_AT_GNU_call_site_value
:
2872 case DW_AT_call_data_value
:
2873 case DW_AT_GNU_call_site_data_value
:
2874 case DW_AT_call_target
:
2875 case DW_AT_GNU_call_site_target
:
2876 case DW_AT_call_target_clobbered
:
2877 case DW_AT_GNU_call_site_target_clobbered
:
2878 if ((dwarf_version
< 4
2879 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2880 || form
== DW_FORM_sec_offset
2881 || form
== DW_FORM_loclistx
)
2883 /* Process location list. */
2884 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2885 unsigned int num
= debug_info_p
->num_loc_offsets
;
2887 if (lmax
== 0 || num
>= lmax
)
2890 debug_info_p
->loc_offsets
= (uint64_t *)
2891 xcrealloc (debug_info_p
->loc_offsets
,
2892 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2893 debug_info_p
->loc_views
= (uint64_t *)
2894 xcrealloc (debug_info_p
->loc_views
,
2895 lmax
, sizeof (*debug_info_p
->loc_views
));
2896 debug_info_p
->have_frame_base
= (int *)
2897 xcrealloc (debug_info_p
->have_frame_base
,
2898 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2899 debug_info_p
->max_loc_offsets
= lmax
;
2901 if (form
== DW_FORM_loclistx
)
2902 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2903 else if (this_set
!= NULL
)
2904 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2906 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2907 if (attribute
!= DW_AT_GNU_locviews
)
2909 uvalue
+= debug_info_p
->loclists_base
;
2911 /* Corrupt DWARF info can produce more offsets than views.
2912 See PR 23062 for an example. */
2913 if (debug_info_p
->num_loc_offsets
2914 > debug_info_p
->num_loc_views
)
2915 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2918 debug_info_p
->loc_offsets
[num
] = uvalue
;
2919 debug_info_p
->num_loc_offsets
++;
2924 if (debug_info_p
->num_loc_views
> num
)
2926 warn (_("The number of views (%u) is greater than the number of locations (%u)\n"),
2927 debug_info_p
->num_loc_views
, num
);
2928 debug_info_p
->num_loc_views
= num
;
2931 num
= debug_info_p
->num_loc_views
;
2932 if (num
> debug_info_p
->num_loc_offsets
)
2933 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2936 debug_info_p
->loc_views
[num
] = uvalue
;
2937 debug_info_p
->num_loc_views
++;
2944 if (need_base_address
)
2945 debug_info_p
->base_address
= uvalue
;
2948 case DW_AT_GNU_addr_base
:
2949 case DW_AT_addr_base
:
2950 debug_info_p
->addr_base
= uvalue
;
2953 case DW_AT_GNU_ranges_base
:
2954 debug_info_p
->ranges_base
= uvalue
;
2958 if ((dwarf_version
< 4
2959 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2960 || form
== DW_FORM_sec_offset
2961 || form
== DW_FORM_rnglistx
)
2963 /* Process range list. */
2964 unsigned int lmax
= debug_info_p
->max_range_lists
;
2965 unsigned int num
= debug_info_p
->num_range_lists
;
2967 if (lmax
== 0 || num
>= lmax
)
2970 debug_info_p
->range_lists
= (uint64_t *)
2971 xcrealloc (debug_info_p
->range_lists
,
2972 lmax
, sizeof (*debug_info_p
->range_lists
));
2973 debug_info_p
->max_range_lists
= lmax
;
2976 if (form
== DW_FORM_rnglistx
)
2977 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2979 debug_info_p
->range_lists
[num
] = uvalue
;
2980 debug_info_p
->num_range_lists
++;
2984 case DW_AT_GNU_dwo_name
:
2985 case DW_AT_dwo_name
:
2990 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2992 case DW_FORM_GNU_strp_alt
:
2993 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2995 case DW_FORM_GNU_str_index
:
3001 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3002 debug_info_p
->str_offsets_base
),
3005 case DW_FORM_string
:
3006 add_dwo_name ((const char *) orig_data
, cu_offset
);
3009 warn (_("Unsupported form (%s) for attribute %s\n"),
3010 get_FORM_name (form
), get_AT_name (attribute
));
3015 case DW_AT_comp_dir
:
3016 /* FIXME: Also extract a build-id in a CU/TU. */
3021 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3023 case DW_FORM_GNU_strp_alt
:
3024 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3026 case DW_FORM_line_strp
:
3027 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3029 case DW_FORM_GNU_str_index
:
3035 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3036 debug_info_p
->str_offsets_base
),
3039 case DW_FORM_string
:
3040 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3043 warn (_("Unsupported form (%s) for attribute %s\n"),
3044 get_FORM_name (form
), get_AT_name (attribute
));
3049 case DW_AT_GNU_dwo_id
:
3054 /* FIXME: Record the length of the ID as well ? */
3055 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3058 warn (_("Unsupported form (%s) for attribute %s\n"),
3059 get_FORM_name (form
), get_AT_name (attribute
));
3069 if (do_loc
|| attribute
== 0)
3072 /* For some attributes we can display further information. */
3076 if (level
>= 0 && level
< MAX_CU_NESTING
3077 && uvalue
< (size_t) (end
- start
))
3079 bool is_signed
= false;
3080 abbrev_entry
*type_abbrev
;
3081 unsigned char *type_data
;
3084 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3088 if (type_abbrev
!= NULL
)
3090 get_type_signedness (type_abbrev
, section
, type_data
,
3091 map
? section
->start
+ map
->end
: end
,
3092 map
? map
->start
: cu_offset
,
3093 pointer_size
, offset_size
, dwarf_version
,
3096 level_type_signed
[level
] = is_signed
;
3104 case DW_INL_not_inlined
:
3105 printf (_("(not inlined)"));
3107 case DW_INL_inlined
:
3108 printf (_("(inlined)"));
3110 case DW_INL_declared_not_inlined
:
3111 printf (_("(declared as inline but ignored)"));
3113 case DW_INL_declared_inlined
:
3114 printf (_("(declared as inline and inlined)"));
3117 printf (_(" (Unknown inline attribute value: %#" PRIx64
")"),
3123 case DW_AT_language
:
3127 /* Ordered by the numeric value of these constants. */
3128 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3129 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3130 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3131 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3132 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3133 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3134 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3135 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3136 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3137 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3138 /* DWARF 2.1 values. */
3139 case DW_LANG_Java
: printf ("(Java)"); break;
3140 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3141 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3142 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3143 /* DWARF 3 values. */
3144 case DW_LANG_PLI
: printf ("(PLI)"); break;
3145 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3146 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3147 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3148 case DW_LANG_D
: printf ("(D)"); break;
3149 /* DWARF 4 values. */
3150 case DW_LANG_Python
: printf ("(Python)"); break;
3151 /* DWARF 5 values. */
3152 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3153 case DW_LANG_Go
: printf ("(Go)"); break;
3154 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3155 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3156 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3157 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3158 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3159 case DW_LANG_Rust
: printf ("(Rust)"); break;
3160 case DW_LANG_C11
: printf ("(C11)"); break;
3161 case DW_LANG_Swift
: printf ("(Swift)"); break;
3162 case DW_LANG_Julia
: printf ("(Julia)"); break;
3163 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3164 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3165 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3166 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3167 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3168 /* MIPS extension. */
3169 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3170 /* UPC extension. */
3171 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3173 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3174 printf (_("(implementation defined: %#" PRIx64
")"), uvalue
);
3176 printf (_("(unknown: %#" PRIx64
")"), uvalue
);
3181 case DW_AT_encoding
:
3185 case DW_ATE_void
: printf ("(void)"); break;
3186 case DW_ATE_address
: printf ("(machine address)"); break;
3187 case DW_ATE_boolean
: printf ("(boolean)"); break;
3188 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3189 case DW_ATE_float
: printf ("(float)"); break;
3190 case DW_ATE_signed
: printf ("(signed)"); break;
3191 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3192 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3193 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3194 /* DWARF 2.1 values: */
3195 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3196 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3197 /* DWARF 3 values: */
3198 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3199 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3200 case DW_ATE_edited
: printf ("(edited)"); break;
3201 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3202 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3203 /* DWARF 4 values: */
3204 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3205 /* DWARF 5 values: */
3206 case DW_ATE_UCS
: printf ("(UCS)"); break;
3207 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3209 /* HP extensions: */
3210 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3211 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3212 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3213 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3214 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3215 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3216 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3219 if (uvalue
>= DW_ATE_lo_user
3220 && uvalue
<= DW_ATE_hi_user
)
3221 printf (_("(user defined type)"));
3223 printf (_("(unknown type)"));
3228 case DW_AT_accessibility
:
3232 case DW_ACCESS_public
: printf ("(public)"); break;
3233 case DW_ACCESS_protected
: printf ("(protected)"); break;
3234 case DW_ACCESS_private
: printf ("(private)"); break;
3236 printf (_("(unknown accessibility)"));
3241 case DW_AT_visibility
:
3245 case DW_VIS_local
: printf ("(local)"); break;
3246 case DW_VIS_exported
: printf ("(exported)"); break;
3247 case DW_VIS_qualified
: printf ("(qualified)"); break;
3248 default: printf (_("(unknown visibility)")); break;
3252 case DW_AT_endianity
:
3256 case DW_END_default
: printf ("(default)"); break;
3257 case DW_END_big
: printf ("(big)"); break;
3258 case DW_END_little
: printf ("(little)"); break;
3260 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3261 printf (_("(user specified)"));
3263 printf (_("(unknown endianity)"));
3268 case DW_AT_virtuality
:
3272 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3273 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3274 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3275 default: printf (_("(unknown virtuality)")); break;
3279 case DW_AT_identifier_case
:
3283 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3284 case DW_ID_up_case
: printf ("(up_case)"); break;
3285 case DW_ID_down_case
: printf ("(down_case)"); break;
3286 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3287 default: printf (_("(unknown case)")); break;
3291 case DW_AT_calling_convention
:
3295 case DW_CC_normal
: printf ("(normal)"); break;
3296 case DW_CC_program
: printf ("(program)"); break;
3297 case DW_CC_nocall
: printf ("(nocall)"); break;
3298 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3299 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3300 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3301 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3303 if (uvalue
>= DW_CC_lo_user
3304 && uvalue
<= DW_CC_hi_user
)
3305 printf (_("(user defined)"));
3307 printf (_("(unknown convention)"));
3311 case DW_AT_ordering
:
3316 case -1: printf (_("(undefined)")); break;
3317 case 0: printf ("(row major)"); break;
3318 case 1: printf ("(column major)"); break;
3322 case DW_AT_decimal_sign
:
3326 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3327 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3328 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3329 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3330 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3331 default: printf (_("(unrecognised)")); break;
3335 case DW_AT_defaulted
:
3339 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3340 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3341 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3342 default: printf (_("(unrecognised)")); break;
3346 case DW_AT_discr_list
:
3348 display_discr_list (form
, uvalue
, data
, level
);
3351 case DW_AT_frame_base
:
3352 have_frame_base
= 1;
3354 case DW_AT_location
:
3355 case DW_AT_loclists_base
:
3356 case DW_AT_rnglists_base
:
3357 case DW_AT_str_offsets_base
:
3358 case DW_AT_string_length
:
3359 case DW_AT_return_addr
:
3360 case DW_AT_data_member_location
:
3361 case DW_AT_vtable_elem_location
:
3363 case DW_AT_static_link
:
3364 case DW_AT_use_location
:
3365 case DW_AT_call_value
:
3366 case DW_AT_GNU_call_site_value
:
3367 case DW_AT_call_data_value
:
3368 case DW_AT_GNU_call_site_data_value
:
3369 case DW_AT_call_target
:
3370 case DW_AT_GNU_call_site_target
:
3371 case DW_AT_call_target_clobbered
:
3372 case DW_AT_GNU_call_site_target_clobbered
:
3373 if ((dwarf_version
< 4
3374 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3375 || form
== DW_FORM_sec_offset
3376 || form
== DW_FORM_loclistx
)
3378 if (attribute
!= DW_AT_rnglists_base
3379 && attribute
!= DW_AT_str_offsets_base
)
3380 printf (_(" (location list)"));
3383 case DW_AT_allocated
:
3384 case DW_AT_associated
:
3385 case DW_AT_data_location
:
3387 case DW_AT_upper_bound
:
3388 case DW_AT_lower_bound
:
3392 int need_frame_base
;
3395 need_frame_base
= decode_location_expression (block_start
,
3400 cu_offset
, section
);
3402 if (need_frame_base
&& !have_frame_base
)
3403 printf (_(" [without DW_AT_frame_base]"));
3407 case DW_AT_data_bit_offset
:
3408 case DW_AT_byte_size
:
3409 case DW_AT_bit_size
:
3410 case DW_AT_string_length_byte_size
:
3411 case DW_AT_string_length_bit_size
:
3412 case DW_AT_bit_stride
:
3413 if (form
== DW_FORM_exprloc
)
3416 (void) decode_location_expression (block_start
, pointer_size
,
3417 offset_size
, dwarf_version
,
3418 uvalue
, cu_offset
, section
);
3425 unsigned long abbrev_number
;
3426 abbrev_entry
*entry
;
3428 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3429 section
, & abbrev_number
, NULL
, NULL
);
3432 if (form
!= DW_FORM_GNU_ref_alt
)
3433 warn (_("Offset %#" PRIx64
" used as value for DW_AT_import attribute of DIE at offset %#tx is too big.\n"),
3435 orig_data
- section
->start
);
3439 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3440 printf (" (%s)", get_TAG_name (entry
->tag
));
3453 static unsigned char *
3454 read_and_display_attr (unsigned long attribute
,
3456 int64_t implicit_const
,
3457 unsigned char *start
,
3458 unsigned char *data
,
3461 uint64_t pointer_size
,
3462 uint64_t offset_size
,
3464 debug_info
*debug_info_p
,
3466 struct dwarf_section
*section
,
3467 struct cu_tu_set
*this_set
,
3471 printf (" %-18s:", get_AT_name (attribute
));
3472 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3474 cu_offset
, pointer_size
, offset_size
,
3475 dwarf_version
, debug_info_p
,
3476 do_loc
, section
, this_set
, ' ', level
);
3482 /* Like load_debug_section, but if the ordinary call fails, and we are
3483 following debug links, then attempt to load the requested section
3484 from one of the separate debug info files. */
3487 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3490 if (load_debug_section (sec_enum
, handle
))
3492 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3494 /* See if we can associate a filename with this section. */
3497 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3498 if (i
->handle
== handle
)
3500 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3508 if (do_follow_links
)
3512 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3514 if (load_debug_section (sec_enum
, i
->handle
))
3516 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3518 /* FIXME: We should check to see if any of the remaining debug info
3519 files also contain this section, and, umm, do something about it. */
3529 introduce (struct dwarf_section
* section
, bool raw
)
3533 if (do_follow_links
&& section
->filename
)
3534 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3535 section
->name
, section
->filename
);
3537 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3541 if (do_follow_links
&& section
->filename
)
3542 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3543 section
->name
, section
->filename
);
3545 printf (_("Contents of the %s section:\n\n"), section
->name
);
3549 /* Free memory allocated for one unit in debug_information. */
3552 free_debug_information (debug_info
*ent
)
3554 if (ent
->max_loc_offsets
)
3556 free (ent
->loc_offsets
);
3557 free (ent
->loc_views
);
3558 free (ent
->have_frame_base
);
3560 if (ent
->max_range_lists
)
3561 free (ent
->range_lists
);
3564 /* Process the contents of a .debug_info section.
3565 If do_loc is TRUE then we are scanning for location lists and dwo tags
3566 and we do not want to display anything to the user.
3567 If do_types is TRUE, we are processing a .debug_types section instead of
3568 a .debug_info section.
3569 The information displayed is restricted by the values in DWARF_START_DIE
3570 and DWARF_CUTOFF_LEVEL.
3571 Returns TRUE upon success. Otherwise an error or warning message is
3572 printed and FALSE is returned. */
3575 process_debug_info (struct dwarf_section
* section
,
3577 enum dwarf_section_display_enum abbrev_sec
,
3581 unsigned char *start
= section
->start
;
3582 unsigned char *end
= start
+ section
->size
;
3583 unsigned char *section_begin
;
3585 unsigned int num_units
= 0;
3587 /* First scan the section to get the number of comp units.
3588 Length sanity checks are done here. */
3589 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3594 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3595 will be the length. For a 64-bit DWARF section, it'll be
3596 the escape code 0xffffffff followed by an 8 byte length. */
3597 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3599 if (length
== 0xffffffff)
3600 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3601 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3603 warn (_("Reserved length value (%#" PRIx64
") found in section %s\n"),
3604 length
, section
->name
);
3608 /* Negative values are illegal, they may even cause infinite
3609 looping. This can happen if we can't accurately apply
3610 relocations to an object file, or if the file is corrupt. */
3611 if (length
> (size_t) (end
- section_begin
))
3613 warn (_("Corrupt unit length (got %#" PRIx64
3614 " expected at most %#tx) in section %s\n"),
3615 length
, end
- section_begin
, section
->name
);
3618 section_begin
+= length
;
3623 error (_("No comp units in %s section ?\n"), section
->name
);
3627 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3628 && num_debug_info_entries
== 0
3632 /* Then allocate an array to hold the information. */
3633 debug_information
= (debug_info
*) cmalloc (num_units
,
3634 sizeof (* debug_information
));
3635 if (debug_information
== NULL
)
3637 error (_("Not enough memory for a debug info array of %u entries\n"),
3639 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3643 /* PR 17531: file: 92ca3797.
3644 We cannot rely upon the debug_information array being initialised
3645 before it is used. A corrupt file could easily contain references
3646 to a unit for which information has not been made available. So
3647 we ensure that the array is zeroed here. */
3648 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3650 alloc_num_debug_info_entries
= num_units
;
3655 load_debug_section_with_follow (str
, file
);
3656 load_debug_section_with_follow (line_str
, file
);
3657 load_debug_section_with_follow (str_dwo
, file
);
3658 load_debug_section_with_follow (str_index
, file
);
3659 load_debug_section_with_follow (str_index_dwo
, file
);
3660 load_debug_section_with_follow (debug_addr
, file
);
3663 load_debug_section_with_follow (abbrev_sec
, file
);
3664 load_debug_section_with_follow (loclists
, file
);
3665 load_debug_section_with_follow (rnglists
, file
);
3666 load_debug_section_with_follow (loclists_dwo
, file
);
3667 load_debug_section_with_follow (rnglists_dwo
, file
);
3669 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3671 warn (_("Unable to locate %s section!\n"),
3672 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3676 if (!do_loc
&& dwarf_start_die
== 0)
3677 introduce (section
, false);
3679 free_all_abbrevs ();
3681 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3682 to load *all* of the abbrevs for all CUs in this .debug_info
3683 section. This does effectively mean that we (partially) read
3684 every CU header twice. */
3685 for (section_begin
= start
; start
< end
;)
3687 DWARF2_Internal_CompUnit compunit
;
3688 unsigned char *hdrptr
;
3689 uint64_t abbrev_base
;
3692 unsigned int offset_size
;
3693 struct cu_tu_set
*this_set
;
3694 unsigned char *end_cu
;
3697 cu_offset
= start
- section_begin
;
3699 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3701 if (compunit
.cu_length
== 0xffffffff)
3703 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3708 end_cu
= hdrptr
+ compunit
.cu_length
;
3710 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3712 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3714 if (compunit
.cu_version
< 5)
3716 compunit
.cu_unit_type
= DW_UT_compile
;
3717 /* Initialize it due to a false compiler warning. */
3718 compunit
.cu_pointer_size
= -1;
3722 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3723 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3725 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3728 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3731 if (compunit
.cu_unit_type
== DW_UT_split_compile
3732 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3735 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3738 if (this_set
== NULL
)
3741 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3745 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3746 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3750 abbrev_list
*free_list
;
3751 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3752 abbrev_base
, abbrev_size
,
3753 compunit
.cu_abbrev_offset
,
3756 if (list
!= NULL
&& list
->first_abbrev
!= NULL
)
3757 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
,
3759 else if (free_list
!= NULL
)
3760 free_abbrev_list (free_list
);
3763 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3765 DWARF2_Internal_CompUnit compunit
;
3766 unsigned char *hdrptr
;
3767 unsigned char *tags
;
3768 int level
, last_level
, saved_level
;
3770 unsigned int offset_size
;
3771 uint64_t signature
= 0;
3772 uint64_t type_offset
= 0;
3773 struct cu_tu_set
*this_set
;
3774 uint64_t abbrev_base
;
3776 unsigned char *end_cu
;
3779 cu_offset
= start
- section_begin
;
3781 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3783 if (compunit
.cu_length
== 0xffffffff)
3785 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3790 end_cu
= hdrptr
+ compunit
.cu_length
;
3792 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3794 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3796 if (compunit
.cu_version
< 5)
3798 compunit
.cu_unit_type
= DW_UT_compile
;
3799 /* Initialize it due to a false compiler warning. */
3800 compunit
.cu_pointer_size
= -1;
3804 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3805 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3807 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3810 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3812 if (this_set
== NULL
)
3815 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3819 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3820 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3823 if (compunit
.cu_version
< 5)
3824 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3826 bool do_dwo_id
= false;
3827 uint64_t dwo_id
= 0;
3828 if (compunit
.cu_unit_type
== DW_UT_split_compile
3829 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3831 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3835 /* PR 17512: file: 001-108546-0.001:0.1. */
3836 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3838 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3839 compunit
.cu_pointer_size
, offset_size
);
3840 compunit
.cu_pointer_size
= offset_size
;
3845 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3846 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3849 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3855 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3856 && num_debug_info_entries
== 0
3857 && alloc_num_debug_info_entries
> unit
3860 free_debug_information (&debug_information
[unit
]);
3861 memset (&debug_information
[unit
], 0, sizeof (*debug_information
));
3862 debug_information
[unit
].pointer_size
= compunit
.cu_pointer_size
;
3863 debug_information
[unit
].offset_size
= offset_size
;
3864 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3865 debug_information
[unit
].cu_offset
= cu_offset
;
3866 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3867 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3870 if (!do_loc
&& dwarf_start_die
== 0)
3872 printf (_(" Compilation Unit @ offset %#" PRIx64
":\n"),
3874 printf (_(" Length: %#" PRIx64
" (%s)\n"),
3876 offset_size
== 8 ? "64-bit" : "32-bit");
3877 printf (_(" Version: %d\n"), compunit
.cu_version
);
3878 if (compunit
.cu_version
>= 5)
3880 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3882 printf (_(" Unit Type: %s (%x)\n"),
3884 compunit
.cu_unit_type
);
3886 printf (_(" Abbrev Offset: %#" PRIx64
"\n"),
3887 compunit
.cu_abbrev_offset
);
3888 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3891 printf (_(" Signature: %#" PRIx64
"\n"), signature
);
3892 printf (_(" Type Offset: %#" PRIx64
"\n"), type_offset
);
3895 printf (_(" DWO ID: %#" PRIx64
"\n"), dwo_id
);
3896 if (this_set
!= NULL
)
3898 uint64_t *offsets
= this_set
->section_offsets
;
3899 size_t *sizes
= this_set
->section_sizes
;
3901 printf (_(" Section contributions:\n"));
3902 printf (_(" .debug_abbrev.dwo: %#" PRIx64
" %#zx\n"),
3903 offsets
[DW_SECT_ABBREV
], sizes
[DW_SECT_ABBREV
]);
3904 printf (_(" .debug_line.dwo: %#" PRIx64
" %#zx\n"),
3905 offsets
[DW_SECT_LINE
], sizes
[DW_SECT_LINE
]);
3906 printf (_(" .debug_loc.dwo: %#" PRIx64
" %#zx\n"),
3907 offsets
[DW_SECT_LOC
], sizes
[DW_SECT_LOC
]);
3908 printf (_(" .debug_str_offsets.dwo: %#" PRIx64
" %#zx\n"),
3909 offsets
[DW_SECT_STR_OFFSETS
], sizes
[DW_SECT_STR_OFFSETS
]);
3916 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3918 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3919 "unsupported version number: %d.\n"),
3920 cu_offset
, compunit
.cu_version
);
3924 if (compunit
.cu_unit_type
!= DW_UT_compile
3925 && compunit
.cu_unit_type
!= DW_UT_partial
3926 && compunit
.cu_unit_type
!= DW_UT_type
3927 && compunit
.cu_unit_type
!= DW_UT_split_compile
3928 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3930 warn (_("CU at offset %#" PRIx64
" contains corrupt or "
3931 "unsupported unit type: %d.\n"),
3932 cu_offset
, compunit
.cu_unit_type
);
3936 /* Process the abbrevs used by this compilation unit. */
3938 list
= find_and_process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3939 abbrev_base
, abbrev_size
,
3940 compunit
.cu_abbrev_offset
, NULL
);
3944 while (tags
< start
)
3946 unsigned long abbrev_number
;
3947 unsigned long die_offset
;
3948 abbrev_entry
*entry
;
3950 int do_printing
= 1;
3952 die_offset
= tags
- section_begin
;
3954 READ_ULEB (abbrev_number
, tags
, start
);
3956 /* A null DIE marks the end of a list of siblings or it may also be
3957 a section padding. */
3958 if (abbrev_number
== 0)
3960 /* Check if it can be a section padding for the last CU. */
3961 if (level
== 0 && start
== end
)
3965 for (chk
= tags
; chk
< start
; chk
++)
3972 if (!do_loc
&& die_offset
>= dwarf_start_die
3973 && (dwarf_cutoff_level
== -1
3974 || level
< dwarf_cutoff_level
))
3975 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3981 static unsigned num_bogus_warns
= 0;
3983 if (num_bogus_warns
< 3)
3985 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3986 die_offset
, section
->name
);
3988 if (num_bogus_warns
== 3)
3989 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3992 if (dwarf_start_die
!= 0 && level
< saved_level
)
3999 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4003 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4004 saved_level
= level
;
4005 do_printing
= (dwarf_cutoff_level
== -1
4006 || level
< dwarf_cutoff_level
);
4008 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4009 level
, die_offset
, abbrev_number
);
4010 else if (dwarf_cutoff_level
== -1
4011 || last_level
< dwarf_cutoff_level
)
4012 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4017 /* Scan through the abbreviation list until we reach the
4021 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4022 if (entry
->number
== abbrev_number
)
4027 if (!do_loc
&& do_printing
)
4032 warn (_("DIE at offset %#lx refers to abbreviation number %lu which does not exist\n"),
4033 die_offset
, abbrev_number
);
4037 if (!do_loc
&& do_printing
)
4038 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4043 need_base_address
= 0;
4045 case DW_TAG_compile_unit
:
4046 case DW_TAG_skeleton_unit
:
4047 need_base_address
= 1;
4048 need_dwo_info
= do_loc
;
4050 case DW_TAG_entry_point
:
4051 case DW_TAG_subprogram
:
4052 need_base_address
= 0;
4053 /* Assuming that there is no DW_AT_frame_base. */
4054 have_frame_base
= 0;
4058 debug_info
*debug_info_p
=
4059 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4060 ? debug_information
+ unit
: NULL
;
4062 assert (!debug_info_p
4063 || (debug_info_p
->num_loc_offsets
4064 == debug_info_p
->num_loc_views
));
4066 for (attr
= entry
->first_attr
;
4067 attr
&& attr
->attribute
;
4070 if (! do_loc
&& do_printing
)
4071 /* Show the offset from where the tag was extracted. */
4072 printf (" <%tx>", tags
- section_begin
);
4073 tags
= read_and_display_attr (attr
->attribute
,
4075 attr
->implicit_const
,
4080 compunit
.cu_pointer_size
,
4082 compunit
.cu_version
,
4084 do_loc
|| ! do_printing
,
4090 /* If a locview attribute appears before a location one,
4091 make sure we don't associate it with an earlier
4094 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4097 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = -1;
4098 debug_info_p
->num_loc_views
++;
4099 assert (debug_info_p
->num_loc_views
4100 == debug_info_p
->num_loc_offsets
);
4107 warn(_("DIE has locviews without loclist\n"));
4108 debug_info_p
->num_loc_views
--;
4115 if (entry
->children
)
4119 free_abbrev_list (list
);
4122 /* Set num_debug_info_entries here so that it can be used to check if
4123 we need to process .debug_loc and .debug_ranges sections. */
4124 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4125 && num_debug_info_entries
== 0
4128 if (num_units
> alloc_num_debug_info_entries
)
4129 num_debug_info_entries
= alloc_num_debug_info_entries
;
4131 num_debug_info_entries
= num_units
;
4140 /* Locate and scan the .debug_info section in the file and record the pointer
4141 sizes and offsets for the compilation units in it. Usually an executable
4142 will have just one pointer size, but this is not guaranteed, and so we try
4143 not to make any assumptions. Returns zero upon failure, or the number of
4144 compilation units upon success. */
4147 load_debug_info (void * file
)
4149 /* If we have already tried and failed to load the .debug_info
4150 section then do not bother to repeat the task. */
4151 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4154 /* If we already have the information there is nothing else to do. */
4155 if (num_debug_info_entries
> 0)
4156 return num_debug_info_entries
;
4158 /* If this is a DWARF package file, load the CU and TU indexes. */
4159 (void) load_cu_tu_indexes (file
);
4161 if (load_debug_section_with_follow (info
, file
)
4162 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4163 return num_debug_info_entries
;
4165 if (load_debug_section_with_follow (info_dwo
, file
)
4166 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4167 abbrev_dwo
, true, false))
4168 return num_debug_info_entries
;
4170 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4174 /* Read a DWARF .debug_line section header starting at DATA.
4175 Upon success returns an updated DATA pointer and the LINFO
4176 structure and the END_OF_SEQUENCE pointer will be filled in.
4177 Otherwise returns NULL. */
4179 static unsigned char *
4180 read_debug_line_header (struct dwarf_section
* section
,
4181 unsigned char * data
,
4182 unsigned char * end
,
4183 DWARF2_Internal_LineInfo
* linfo
,
4184 unsigned char ** end_of_sequence
)
4186 unsigned char *hdrptr
;
4188 /* Extract information from the Line Number Program Header.
4189 (section 6.2.4 in the Dwarf3 doc). */
4192 /* Get and check the length of the block. */
4193 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4195 if (linfo
->li_length
== 0xffffffff)
4197 /* This section is 64-bit DWARF 3. */
4198 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4199 linfo
->li_offset_size
= 8;
4202 linfo
->li_offset_size
= 4;
4204 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4206 /* If the length field has a relocation against it, then we should
4207 not complain if it is inaccurate (and probably negative). This
4208 happens in object files when the .debug_line section is actually
4209 comprised of several different .debug_line.* sections, (some of
4210 which may be removed by linker garbage collection), and a relocation
4211 is used to compute the correct length once that is done. */
4212 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4214 linfo
->li_length
= end
- hdrptr
;
4218 warn (_("The length field (%#" PRIx64
")"
4219 " in the debug_line header is wrong"
4220 " - the section is too small\n"),
4225 end
= hdrptr
+ linfo
->li_length
;
4227 /* Get and check the version number. */
4228 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4230 if (linfo
->li_version
!= 2
4231 && linfo
->li_version
!= 3
4232 && linfo
->li_version
!= 4
4233 && linfo
->li_version
!= 5)
4235 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4236 "is currently supported.\n"));
4240 if (linfo
->li_version
>= 5)
4242 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4244 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4245 if (linfo
->li_segment_size
!= 0)
4247 warn (_("The %s section contains "
4248 "unsupported segment selector size: %d.\n"),
4249 section
->name
, linfo
->li_segment_size
);
4254 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4255 linfo
->li_offset_size
, end
);
4256 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4258 if (linfo
->li_version
>= 4)
4260 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4262 if (linfo
->li_max_ops_per_insn
== 0)
4264 warn (_("Invalid maximum operations per insn.\n"));
4269 linfo
->li_max_ops_per_insn
= 1;
4271 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4272 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4273 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4274 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4276 *end_of_sequence
= end
;
4280 static unsigned char *
4281 display_formatted_table (unsigned char *data
,
4282 unsigned char *start
,
4284 const DWARF2_Internal_LineInfo
*linfo
,
4285 struct dwarf_section
*section
,
4288 unsigned char *format_start
, format_count
, *format
, formati
;
4289 uint64_t data_count
, datai
;
4290 unsigned int namepass
, last_entry
= 0;
4291 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4293 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4294 if (do_checks
&& format_count
> 5)
4295 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4296 table_name
, format_count
);
4298 format_start
= data
;
4299 for (formati
= 0; formati
< format_count
; formati
++)
4301 SKIP_ULEB (data
, end
);
4302 SKIP_ULEB (data
, end
);
4305 warn (_("%s: Corrupt format description entry\n"), table_name
);
4310 READ_ULEB (data_count
, data
, end
);
4311 if (data_count
== 0)
4313 printf (_("\n The %s is empty.\n"), table_name
);
4316 else if (data
>= end
)
4318 warn (_("%s: Corrupt entry count - expected %#" PRIx64
4319 " but none found\n"), table_name
, data_count
);
4323 else if (format_count
== 0)
4325 warn (_("%s: format count is zero, but the table is not empty\n"),
4330 printf (_("\n The %s (offset %#tx, lines %" PRIu64
", columns %u):\n"),
4331 table_name
, data
- start
, data_count
, format_count
);
4333 printf (_(" Entry"));
4334 /* Delay displaying name as the last entry for better screen layout. */
4335 for (namepass
= 0; namepass
< 2; namepass
++)
4337 format
= format_start
;
4338 for (formati
= 0; formati
< format_count
; formati
++)
4340 uint64_t content_type
;
4342 READ_ULEB (content_type
, format
, end
);
4343 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4344 switch (content_type
)
4347 printf (_("\tName"));
4349 case DW_LNCT_directory_index
:
4350 printf (_("\tDir"));
4352 case DW_LNCT_timestamp
:
4353 printf (_("\tTime"));
4356 printf (_("\tSize"));
4359 printf (_("\tMD5\t\t\t"));
4362 printf (_("\t(Unknown format content type %" PRIu64
")"),
4365 SKIP_ULEB (format
, end
);
4370 for (datai
= 0; datai
< data_count
; datai
++)
4372 unsigned char *datapass
= data
;
4374 printf (" %d", last_entry
++);
4375 /* Delay displaying name as the last entry for better screen layout. */
4376 for (namepass
= 0; namepass
< 2; namepass
++)
4378 format
= format_start
;
4380 for (formati
= 0; formati
< format_count
; formati
++)
4382 uint64_t content_type
, form
;
4384 READ_ULEB (content_type
, format
, end
);
4385 READ_ULEB (form
, format
, end
);
4386 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4387 0, 0, linfo
->li_offset_size
,
4388 linfo
->li_version
, NULL
,
4389 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4390 section
, NULL
, '\t', -1);
4394 if (data
>= end
&& (datai
< data_count
- 1))
4396 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4405 display_debug_sup (struct dwarf_section
* section
,
4406 void * file ATTRIBUTE_UNUSED
)
4408 unsigned char * start
= section
->start
;
4409 unsigned char * end
= section
->start
+ section
->size
;
4410 unsigned int version
;
4411 char is_supplementary
;
4412 const unsigned char * sup_filename
;
4413 size_t sup_filename_len
;
4414 unsigned int num_read
;
4416 uint64_t checksum_len
;
4419 introduce (section
, true);
4420 if (section
->size
< 4)
4422 error (_("corrupt .debug_sup section: size is too small\n"));
4426 /* Read the data. */
4427 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4429 warn (_("corrupt .debug_sup section: version < 5"));
4431 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4432 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4433 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4435 sup_filename
= start
;
4436 if (is_supplementary
&& sup_filename
[0] != 0)
4437 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4439 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4440 if (sup_filename_len
== (size_t) (end
- start
))
4442 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4445 start
+= sup_filename_len
+ 1;
4447 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4450 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4454 if (checksum_len
> (size_t) (end
- start
))
4456 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4457 checksum_len
= end
- start
;
4459 else if (checksum_len
< (size_t) (end
- start
))
4461 warn (_("corrupt .debug_sup section: there are %#" PRIx64
4462 " extra, unused bytes at the end of the section\n"),
4463 (end
- start
) - checksum_len
);
4466 printf (_(" Version: %u\n"), version
);
4467 printf (_(" Is Supp: %u\n"), is_supplementary
);
4468 printf (_(" Filename: %s\n"), sup_filename
);
4469 printf (_(" Checksum Len: %" PRIu64
"\n"), checksum_len
);
4470 if (checksum_len
> 0)
4472 printf (_(" Checksum: "));
4473 while (checksum_len
--)
4474 printf ("0x%x ", * start
++ );
4481 display_debug_lines_raw (struct dwarf_section
* section
,
4482 unsigned char * data
,
4483 unsigned char * end
,
4486 unsigned char *start
= section
->start
;
4487 int verbose_view
= 0;
4489 introduce (section
, true);
4493 static DWARF2_Internal_LineInfo saved_linfo
;
4494 DWARF2_Internal_LineInfo linfo
;
4495 unsigned char *standard_opcodes
;
4496 unsigned char *end_of_sequence
;
4499 if (startswith (section
->name
, ".debug_line.")
4500 /* Note: the following does not apply to .debug_line.dwo sections.
4501 These are full debug_line sections. */
4502 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4504 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4505 section containing just the Line Number Statements. They are
4506 created by the assembler and intended to be used alongside gcc's
4507 -ffunction-sections command line option. When the linker's
4508 garbage collection decides to discard a .text.<foo> section it
4509 can then also discard the line number information in .debug_line.<foo>.
4511 Since the section is a fragment it does not have the details
4512 needed to fill out a LineInfo structure, so instead we use the
4513 details from the last full debug_line section that we processed. */
4514 end_of_sequence
= end
;
4515 standard_opcodes
= NULL
;
4516 linfo
= saved_linfo
;
4517 /* PR 17531: file: 0522b371. */
4518 if (linfo
.li_line_range
== 0)
4520 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4523 reset_state_machine (linfo
.li_default_is_stmt
);
4527 unsigned char * hdrptr
;
4529 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4530 & end_of_sequence
)) == NULL
)
4533 printf (_(" Offset: %#tx\n"), data
- start
);
4534 printf (_(" Length: %" PRId64
"\n"), linfo
.li_length
);
4535 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4536 if (linfo
.li_version
>= 5)
4538 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4539 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4541 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4542 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4543 if (linfo
.li_version
>= 4)
4544 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4545 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4546 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4547 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4548 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4550 /* PR 17512: file: 1665-6428-0.004. */
4551 if (linfo
.li_line_range
== 0)
4553 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4554 linfo
.li_line_range
= 1;
4557 reset_state_machine (linfo
.li_default_is_stmt
);
4559 /* Display the contents of the Opcodes table. */
4560 standard_opcodes
= hdrptr
;
4562 /* PR 17512: file: 002-417945-0.004. */
4563 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4565 warn (_("Line Base extends beyond end of section\n"));
4569 printf (_("\n Opcodes:\n"));
4571 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4572 printf (ngettext (" Opcode %d has %d arg\n",
4573 " Opcode %d has %d args\n",
4574 standard_opcodes
[i
- 1]),
4575 i
, standard_opcodes
[i
- 1]);
4577 /* Display the contents of the Directory table. */
4578 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4580 if (linfo
.li_version
>= 5)
4582 load_debug_section_with_follow (line_str
, file
);
4584 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4586 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4592 printf (_("\n The Directory Table is empty.\n"));
4595 unsigned int last_dir_entry
= 0;
4597 printf (_("\n The Directory Table (offset %#tx):\n"),
4600 while (data
< end
&& *data
!= 0)
4602 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4604 data
+= strnlen ((char *) data
, end
- data
);
4609 /* PR 17512: file: 002-132094-0.004. */
4610 if (data
>= end
- 1)
4614 /* Skip the NUL at the end of the table. */
4618 /* Display the contents of the File Name table. */
4619 if (data
>= end
|| *data
== 0)
4620 printf (_("\n The File Name Table is empty.\n"));
4623 printf (_("\n The File Name Table (offset %#tx):\n"),
4625 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4627 while (data
< end
&& *data
!= 0)
4629 unsigned char *name
;
4632 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4634 data
+= strnlen ((char *) data
, end
- data
);
4638 READ_ULEB (val
, data
, end
);
4639 printf ("%" PRIu64
"\t", val
);
4640 READ_ULEB (val
, data
, end
);
4641 printf ("%" PRIu64
"\t", val
);
4642 READ_ULEB (val
, data
, end
);
4643 printf ("%" PRIu64
"\t", val
);
4644 printf ("%.*s\n", (int)(end
- name
), name
);
4648 warn (_("Corrupt file name table entry\n"));
4654 /* Skip the NUL at the end of the table. */
4660 saved_linfo
= linfo
;
4663 /* Now display the statements. */
4664 if (data
>= end_of_sequence
)
4665 printf (_(" No Line Number Statements.\n"));
4668 printf (_(" Line Number Statements:\n"));
4670 while (data
< end_of_sequence
)
4672 unsigned char op_code
;
4676 printf (" [0x%08tx]", data
- start
);
4680 if (op_code
>= linfo
.li_opcode_base
)
4682 op_code
-= linfo
.li_opcode_base
;
4683 uladv
= (op_code
/ linfo
.li_line_range
);
4684 if (linfo
.li_max_ops_per_insn
== 1)
4686 uladv
*= linfo
.li_min_insn_length
;
4687 state_machine_regs
.address
+= uladv
;
4689 state_machine_regs
.view
= 0;
4690 printf (_(" Special opcode %d: "
4691 "advance Address by %" PRIu64
4692 " to %#" PRIx64
"%s"),
4693 op_code
, uladv
, state_machine_regs
.address
,
4694 verbose_view
&& uladv
4695 ? _(" (reset view)") : "");
4700 = ((state_machine_regs
.op_index
+ uladv
)
4701 / linfo
.li_max_ops_per_insn
)
4702 * linfo
.li_min_insn_length
;
4704 state_machine_regs
.address
+= addrdelta
;
4705 state_machine_regs
.op_index
4706 = (state_machine_regs
.op_index
+ uladv
)
4707 % linfo
.li_max_ops_per_insn
;
4709 state_machine_regs
.view
= 0;
4710 printf (_(" Special opcode %d: "
4711 "advance Address by %" PRIu64
4712 " to %#" PRIx64
"[%d]%s"),
4713 op_code
, uladv
, state_machine_regs
.address
,
4714 state_machine_regs
.op_index
,
4715 verbose_view
&& addrdelta
4716 ? _(" (reset view)") : "");
4718 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4719 state_machine_regs
.line
+= adv
;
4720 printf (_(" and Line by %d to %d"),
4721 adv
, state_machine_regs
.line
);
4722 if (verbose_view
|| state_machine_regs
.view
)
4723 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4726 state_machine_regs
.view
++;
4731 case DW_LNS_extended_op
:
4732 data
+= process_extended_line_op (data
,
4733 linfo
.li_default_is_stmt
,
4738 printf (_(" Copy"));
4739 if (verbose_view
|| state_machine_regs
.view
)
4740 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4743 state_machine_regs
.view
++;
4746 case DW_LNS_advance_pc
:
4747 READ_ULEB (uladv
, data
, end
);
4748 if (linfo
.li_max_ops_per_insn
== 1)
4750 uladv
*= linfo
.li_min_insn_length
;
4751 state_machine_regs
.address
+= uladv
;
4753 state_machine_regs
.view
= 0;
4754 printf (_(" Advance PC by %" PRIu64
4755 " to %#" PRIx64
"%s\n"),
4756 uladv
, state_machine_regs
.address
,
4757 verbose_view
&& uladv
4758 ? _(" (reset view)") : "");
4763 = ((state_machine_regs
.op_index
+ uladv
)
4764 / linfo
.li_max_ops_per_insn
)
4765 * linfo
.li_min_insn_length
;
4766 state_machine_regs
.address
4768 state_machine_regs
.op_index
4769 = (state_machine_regs
.op_index
+ uladv
)
4770 % linfo
.li_max_ops_per_insn
;
4772 state_machine_regs
.view
= 0;
4773 printf (_(" Advance PC by %" PRIu64
4774 " to %#" PRIx64
"[%d]%s\n"),
4775 uladv
, state_machine_regs
.address
,
4776 state_machine_regs
.op_index
,
4777 verbose_view
&& addrdelta
4778 ? _(" (reset view)") : "");
4782 case DW_LNS_advance_line
:
4783 READ_SLEB (adv
, data
, end
);
4784 state_machine_regs
.line
+= adv
;
4785 printf (_(" Advance Line by %d to %d\n"),
4786 adv
, state_machine_regs
.line
);
4789 case DW_LNS_set_file
:
4790 READ_ULEB (uladv
, data
, end
);
4791 printf (_(" Set File Name to entry %" PRIu64
4792 " in the File Name Table\n"), uladv
);
4793 state_machine_regs
.file
= uladv
;
4796 case DW_LNS_set_column
:
4797 READ_ULEB (uladv
, data
, end
);
4798 printf (_(" Set column to %" PRIu64
"\n"), uladv
);
4799 state_machine_regs
.column
= uladv
;
4802 case DW_LNS_negate_stmt
:
4803 adv
= state_machine_regs
.is_stmt
;
4805 printf (_(" Set is_stmt to %d\n"), adv
);
4806 state_machine_regs
.is_stmt
= adv
;
4809 case DW_LNS_set_basic_block
:
4810 printf (_(" Set basic block\n"));
4811 state_machine_regs
.basic_block
= 1;
4814 case DW_LNS_const_add_pc
:
4815 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4816 if (linfo
.li_max_ops_per_insn
)
4818 uladv
*= linfo
.li_min_insn_length
;
4819 state_machine_regs
.address
+= uladv
;
4821 state_machine_regs
.view
= 0;
4822 printf (_(" Advance PC by constant %" PRIu64
4823 " to %#" PRIx64
"%s\n"),
4824 uladv
, state_machine_regs
.address
,
4825 verbose_view
&& uladv
4826 ? _(" (reset view)") : "");
4831 = ((state_machine_regs
.op_index
+ uladv
)
4832 / linfo
.li_max_ops_per_insn
)
4833 * linfo
.li_min_insn_length
;
4834 state_machine_regs
.address
4836 state_machine_regs
.op_index
4837 = (state_machine_regs
.op_index
+ uladv
)
4838 % linfo
.li_max_ops_per_insn
;
4840 state_machine_regs
.view
= 0;
4841 printf (_(" Advance PC by constant %" PRIu64
4842 " to %#" PRIx64
"[%d]%s\n"),
4843 uladv
, state_machine_regs
.address
,
4844 state_machine_regs
.op_index
,
4845 verbose_view
&& addrdelta
4846 ? _(" (reset view)") : "");
4850 case DW_LNS_fixed_advance_pc
:
4851 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4852 state_machine_regs
.address
+= uladv
;
4853 state_machine_regs
.op_index
= 0;
4854 printf (_(" Advance PC by fixed size amount %" PRIu64
4855 " to %#" PRIx64
"\n"),
4856 uladv
, state_machine_regs
.address
);
4857 /* Do NOT reset view. */
4860 case DW_LNS_set_prologue_end
:
4861 printf (_(" Set prologue_end to true\n"));
4864 case DW_LNS_set_epilogue_begin
:
4865 printf (_(" Set epilogue_begin to true\n"));
4868 case DW_LNS_set_isa
:
4869 READ_ULEB (uladv
, data
, end
);
4870 printf (_(" Set ISA to %" PRIu64
"\n"), uladv
);
4874 printf (_(" Unknown opcode %d with operands: "), op_code
);
4876 if (standard_opcodes
!= NULL
)
4877 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4879 READ_ULEB (uladv
, data
, end
);
4880 printf ("%#" PRIx64
"%s", uladv
, i
== 1 ? "" : ", ");
4896 unsigned int directory_index
;
4897 unsigned int modification_date
;
4898 unsigned int length
;
4901 /* Output a decoded representation of the .debug_line section. */
4904 display_debug_lines_decoded (struct dwarf_section
* section
,
4905 unsigned char * start
,
4906 unsigned char * data
,
4907 unsigned char * end
,
4910 static DWARF2_Internal_LineInfo saved_linfo
;
4912 introduce (section
, false);
4916 /* This loop amounts to one iteration per compilation unit. */
4917 DWARF2_Internal_LineInfo linfo
;
4918 unsigned char *standard_opcodes
;
4919 unsigned char *end_of_sequence
;
4921 File_Entry
*file_table
= NULL
;
4922 unsigned int n_files
= 0;
4923 char **directory_table
= NULL
;
4924 unsigned int n_directories
= 0;
4926 if (startswith (section
->name
, ".debug_line.")
4927 /* Note: the following does not apply to .debug_line.dwo sections.
4928 These are full debug_line sections. */
4929 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4931 /* See comment in display_debug_lines_raw(). */
4932 end_of_sequence
= end
;
4933 standard_opcodes
= NULL
;
4934 linfo
= saved_linfo
;
4935 /* PR 17531: file: 0522b371. */
4936 if (linfo
.li_line_range
== 0)
4938 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4941 reset_state_machine (linfo
.li_default_is_stmt
);
4945 unsigned char *hdrptr
;
4947 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4948 & end_of_sequence
)) == NULL
)
4951 /* PR 17531: file: 0522b371. */
4952 if (linfo
.li_line_range
== 0)
4954 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4955 linfo
.li_line_range
= 1;
4957 reset_state_machine (linfo
.li_default_is_stmt
);
4959 /* Save a pointer to the contents of the Opcodes table. */
4960 standard_opcodes
= hdrptr
;
4962 /* Traverse the Directory table just to count entries. */
4963 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4967 warn (_("opcode base of %d extends beyond end of section\n"),
4968 linfo
.li_opcode_base
);
4972 if (linfo
.li_version
>= 5)
4974 unsigned char *format_start
, *format
;
4975 unsigned int format_count
, formati
, entryi
;
4977 load_debug_section_with_follow (line_str
, fileptr
);
4979 /* Skip directories format. */
4980 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4981 if (do_checks
&& format_count
> 1)
4982 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4984 format_start
= data
;
4985 for (formati
= 0; formati
< format_count
; formati
++)
4987 SKIP_ULEB (data
, end
);
4988 SKIP_ULEB (data
, end
);
4991 READ_ULEB (n_directories
, data
, end
);
4994 warn (_("Corrupt directories list\n"));
4998 if (n_directories
== 0)
4999 directory_table
= NULL
;
5000 else if (n_directories
> section
->size
)
5002 warn (_("number of directories (0x%x) exceeds size of section %s\n"),
5003 n_directories
, section
->name
);
5007 directory_table
= (char **)
5008 xcalloc (n_directories
, sizeof (unsigned char *));
5010 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5012 char **pathp
= &directory_table
[entryi
];
5014 format
= format_start
;
5015 for (formati
= 0; formati
< format_count
; formati
++)
5017 uint64_t content_type
, form
;
5020 READ_ULEB (content_type
, format
, end
);
5021 READ_ULEB (form
, format
, end
);
5024 warn (_("Corrupt directories list\n"));
5027 switch (content_type
)
5032 case DW_FORM_string
:
5033 *pathp
= (char *) data
;
5035 case DW_FORM_line_strp
:
5036 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5038 /* Remove const by the cast. */
5040 fetch_indirect_line_string (uvalue
);
5045 data
= read_and_display_attr_value (0, form
, 0, start
,
5047 linfo
.li_offset_size
,
5054 warn (_("Corrupt directories list\n"));
5059 /* Skip files format. */
5060 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5061 if (do_checks
&& format_count
> 5)
5062 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5065 format_start
= data
;
5066 for (formati
= 0; formati
< format_count
; formati
++)
5068 SKIP_ULEB (data
, end
);
5069 SKIP_ULEB (data
, end
);
5072 READ_ULEB (n_files
, data
, end
);
5073 if (data
>= end
&& n_files
> 0)
5075 warn (_("Corrupt file name list\n"));
5081 else if (n_files
> section
->size
)
5083 warn (_("number of files (0x%x) exceeds size of section %s\n"),
5084 n_files
, section
->name
);
5088 file_table
= (File_Entry
*) xcalloc (n_files
,
5089 sizeof (File_Entry
));
5091 for (entryi
= 0; entryi
< n_files
; entryi
++)
5093 File_Entry
*file
= &file_table
[entryi
];
5095 format
= format_start
;
5096 for (formati
= 0; formati
< format_count
; formati
++)
5098 uint64_t content_type
, form
;
5102 READ_ULEB (content_type
, format
, end
);
5103 READ_ULEB (form
, format
, end
);
5106 warn (_("Corrupt file name list\n"));
5109 switch (content_type
)
5114 case DW_FORM_string
:
5115 file
->name
= (char *) data
;
5117 case DW_FORM_line_strp
:
5118 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5120 /* Remove const by the cast. */
5121 file
->name
= (char *)
5122 fetch_indirect_line_string (uvalue
);
5126 case DW_LNCT_directory_index
:
5130 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5134 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5139 READ_ULEB (file
->directory_index
, tmp
, end
);
5144 data
= read_and_display_attr_value (0, form
, 0, start
,
5146 linfo
.li_offset_size
,
5153 warn (_("Corrupt file name list\n"));
5162 char *ptr_directory_table
= (char *) data
;
5164 while (data
< end
&& *data
!= 0)
5166 data
+= strnlen ((char *) data
, end
- data
);
5175 warn (_("directory table ends unexpectedly\n"));
5180 /* Go through the directory table again to save the directories. */
5181 directory_table
= (char **)
5182 xmalloc (n_directories
* sizeof (unsigned char *));
5185 while (*ptr_directory_table
!= 0)
5187 directory_table
[i
] = ptr_directory_table
;
5188 ptr_directory_table
+= strlen (ptr_directory_table
) + 1;
5192 /* Skip the NUL at the end of the table. */
5195 /* Traverse the File Name table just to count the entries. */
5196 if (data
< end
&& *data
!= 0)
5198 unsigned char *ptr_file_name_table
= data
;
5200 while (data
< end
&& *data
!= 0)
5202 /* Skip Name, directory index, last modification
5203 time and length of file. */
5204 data
+= strnlen ((char *) data
, end
- data
);
5207 SKIP_ULEB (data
, end
);
5208 SKIP_ULEB (data
, end
);
5209 SKIP_ULEB (data
, end
);
5215 warn (_("file table ends unexpectedly\n"));
5220 /* Go through the file table again to save the strings. */
5221 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5224 while (*ptr_file_name_table
!= 0)
5226 file_table
[i
].name
= (char *) ptr_file_name_table
;
5228 += strlen ((char *) ptr_file_name_table
) + 1;
5230 /* We are not interested in directory, time or size. */
5231 READ_ULEB (file_table
[i
].directory_index
,
5232 ptr_file_name_table
, end
);
5233 READ_ULEB (file_table
[i
].modification_date
,
5234 ptr_file_name_table
, end
);
5235 READ_ULEB (file_table
[i
].length
,
5236 ptr_file_name_table
, end
);
5242 /* Skip the NUL at the end of the table. */
5246 /* Print the Compilation Unit's name and a header. */
5247 if (file_table
== NULL
)
5248 printf (_("CU: No directory table\n"));
5249 else if (directory_table
== NULL
)
5250 printf (_("CU: %s:\n"), null_name (file_table
[0].name
));
5253 unsigned int ix
= file_table
[0].directory_index
;
5254 const char *directory
;
5256 if (ix
== 0 && linfo
.li_version
< 5)
5259 else if (n_directories
== 0)
5260 directory
= _("<unknown>");
5263 if (linfo
.li_version
< 5)
5265 if (ix
>= n_directories
)
5267 warn (_("directory index %u "
5268 ">= number of directories %u\n"),
5270 directory
= _("<corrupt>");
5273 directory
= directory_table
[ix
];
5276 printf (_("CU: %s/%s:\n"),
5277 null_name (directory
),
5278 null_name (file_table
[0].name
));
5280 printf ("%s:\n", null_name (file_table
[0].name
));
5286 printf (_("File name Line number Starting address View Stmt\n"));
5288 printf (_("File name Line number Starting address View Stmt\n"));
5291 printf (_("CU: Empty file name table\n"));
5292 saved_linfo
= linfo
;
5295 /* This loop iterates through the Dwarf Line Number Program. */
5296 while (data
< end_of_sequence
)
5298 unsigned char op_code
;
5301 unsigned long int uladv
;
5302 int is_special_opcode
= 0;
5307 if (op_code
>= linfo
.li_opcode_base
)
5309 op_code
-= linfo
.li_opcode_base
;
5310 uladv
= (op_code
/ linfo
.li_line_range
);
5311 if (linfo
.li_max_ops_per_insn
== 1)
5313 uladv
*= linfo
.li_min_insn_length
;
5314 state_machine_regs
.address
+= uladv
;
5316 state_machine_regs
.view
= 0;
5321 = ((state_machine_regs
.op_index
+ uladv
)
5322 / linfo
.li_max_ops_per_insn
)
5323 * linfo
.li_min_insn_length
;
5324 state_machine_regs
.address
5326 state_machine_regs
.op_index
5327 = (state_machine_regs
.op_index
+ uladv
)
5328 % linfo
.li_max_ops_per_insn
;
5330 state_machine_regs
.view
= 0;
5333 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5334 state_machine_regs
.line
+= adv
;
5335 is_special_opcode
= 1;
5336 /* Increment view after printing this row. */
5341 case DW_LNS_extended_op
:
5343 unsigned int ext_op_code_len
;
5344 unsigned char ext_op_code
;
5345 unsigned char *op_code_end
;
5346 unsigned char *op_code_data
= data
;
5348 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5349 op_code_end
= op_code_data
+ ext_op_code_len
;
5350 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5352 warn (_("Badly formed extended line op encountered!\n"));
5355 ext_op_code
= *op_code_data
++;
5359 switch (ext_op_code
)
5361 case DW_LNE_end_sequence
:
5362 /* Reset stuff after printing this row. */
5364 case DW_LNE_set_address
:
5365 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5367 op_code_end
- op_code_data
,
5369 state_machine_regs
.op_index
= 0;
5370 state_machine_regs
.view
= 0;
5372 case DW_LNE_define_file
:
5373 file_table
= (File_Entry
*) xrealloc
5374 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5376 ++state_machine_regs
.last_file_entry
;
5377 /* Source file name. */
5378 file_table
[n_files
].name
= (char *) op_code_data
;
5379 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5380 /* Directory index. */
5381 READ_ULEB (file_table
[n_files
].directory_index
,
5382 op_code_data
, op_code_end
);
5383 /* Last modification time. */
5384 READ_ULEB (file_table
[n_files
].modification_date
,
5385 op_code_data
, op_code_end
);
5387 READ_ULEB (file_table
[n_files
].length
,
5388 op_code_data
, op_code_end
);
5392 case DW_LNE_set_discriminator
:
5393 case DW_LNE_HP_set_sequence
:
5394 /* Simply ignored. */
5398 printf (_("UNKNOWN (%u): length %ld\n"),
5399 ext_op_code
, (long int) (op_code_data
- data
));
5406 /* Increment view after printing this row. */
5409 case DW_LNS_advance_pc
:
5410 READ_ULEB (uladv
, data
, end
);
5411 if (linfo
.li_max_ops_per_insn
== 1)
5413 uladv
*= linfo
.li_min_insn_length
;
5414 state_machine_regs
.address
+= uladv
;
5416 state_machine_regs
.view
= 0;
5421 = ((state_machine_regs
.op_index
+ uladv
)
5422 / linfo
.li_max_ops_per_insn
)
5423 * linfo
.li_min_insn_length
;
5424 state_machine_regs
.address
5426 state_machine_regs
.op_index
5427 = (state_machine_regs
.op_index
+ uladv
)
5428 % linfo
.li_max_ops_per_insn
;
5430 state_machine_regs
.view
= 0;
5434 case DW_LNS_advance_line
:
5435 READ_SLEB (adv
, data
, end
);
5436 state_machine_regs
.line
+= adv
;
5439 case DW_LNS_set_file
:
5440 READ_ULEB (uladv
, data
, end
);
5441 state_machine_regs
.file
= uladv
;
5443 unsigned file
= state_machine_regs
.file
;
5444 if (linfo
.li_version
< 5)
5447 if (file_table
== NULL
|| n_files
== 0)
5448 printf (_("\n [Use file table entry %d]\n"), file
);
5450 else if (file
>= n_files
)
5452 warn (_("file index %u >= number of files %u\n"),
5454 printf (_("\n <over large file table index %u>"), file
);
5458 unsigned dir
= file_table
[file
].directory_index
;
5459 if (dir
== 0 && linfo
.li_version
< 5)
5460 /* If directory index is 0, that means compilation
5461 current directory. bfd/dwarf2.c shows
5462 DW_AT_comp_dir here but in keeping with the
5463 readelf practice of minimal interpretation of
5464 file data, we show "./". */
5465 printf ("\n./%s:[++]\n",
5466 null_name (file_table
[file
].name
));
5467 else if (directory_table
== NULL
|| n_directories
== 0)
5468 printf (_("\n [Use file %s "
5469 "in directory table entry %d]\n"),
5470 null_name (file_table
[file
].name
), dir
);
5473 if (linfo
.li_version
< 5)
5476 if (dir
>= n_directories
)
5478 warn (_("directory index %u "
5479 ">= number of directories %u\n"),
5480 dir
, n_directories
);
5481 printf (_("\n <over large directory table entry "
5485 printf ("\n%s/%s:\n",
5486 null_name (directory_table
[dir
]),
5487 null_name (file_table
[file
].name
));
5492 case DW_LNS_set_column
:
5493 READ_ULEB (uladv
, data
, end
);
5494 state_machine_regs
.column
= uladv
;
5497 case DW_LNS_negate_stmt
:
5498 adv
= state_machine_regs
.is_stmt
;
5500 state_machine_regs
.is_stmt
= adv
;
5503 case DW_LNS_set_basic_block
:
5504 state_machine_regs
.basic_block
= 1;
5507 case DW_LNS_const_add_pc
:
5508 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5509 if (linfo
.li_max_ops_per_insn
== 1)
5511 uladv
*= linfo
.li_min_insn_length
;
5512 state_machine_regs
.address
+= uladv
;
5514 state_machine_regs
.view
= 0;
5519 = ((state_machine_regs
.op_index
+ uladv
)
5520 / linfo
.li_max_ops_per_insn
)
5521 * linfo
.li_min_insn_length
;
5522 state_machine_regs
.address
5524 state_machine_regs
.op_index
5525 = (state_machine_regs
.op_index
+ uladv
)
5526 % linfo
.li_max_ops_per_insn
;
5528 state_machine_regs
.view
= 0;
5532 case DW_LNS_fixed_advance_pc
:
5533 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5534 state_machine_regs
.address
+= uladv
;
5535 state_machine_regs
.op_index
= 0;
5536 /* Do NOT reset view. */
5539 case DW_LNS_set_prologue_end
:
5542 case DW_LNS_set_epilogue_begin
:
5545 case DW_LNS_set_isa
:
5546 READ_ULEB (uladv
, data
, end
);
5547 printf (_(" Set ISA to %lu\n"), uladv
);
5551 printf (_(" Unknown opcode %d with operands: "), op_code
);
5553 if (standard_opcodes
!= NULL
)
5554 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5558 READ_ULEB (val
, data
, end
);
5559 printf ("%#" PRIx64
"%s", val
, i
== 1 ? "" : ", ");
5565 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5566 to the DWARF address/line matrix. */
5567 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5568 || (xop
== DW_LNS_copy
))
5570 const unsigned int MAX_FILENAME_LENGTH
= 35;
5571 char *fileName
= NULL
;
5572 char *newFileName
= NULL
;
5573 size_t fileNameLength
;
5577 unsigned indx
= state_machine_regs
.file
;
5579 if (linfo
.li_version
< 5)
5582 if (indx
>= n_files
)
5584 warn (_("file index %u >= number of files %u\n"),
5586 fileName
= _("<corrupt>");
5589 fileName
= (char *) file_table
[indx
].name
;
5592 fileName
= _("<unknown>");
5594 fileNameLength
= strlen (fileName
);
5595 newFileName
= fileName
;
5596 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5598 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5599 /* Truncate file name */
5600 memcpy (newFileName
,
5601 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5602 MAX_FILENAME_LENGTH
);
5603 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5606 /* A row with end_seq set to true has a meaningful address, but
5607 the other information in the same row is not significant.
5608 In such a row, print line as "-", and don't print
5610 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5612 if (linfo
.li_max_ops_per_insn
== 1)
5614 if (xop
== -DW_LNE_end_sequence
)
5615 printf ("%-31s %11s %#18" PRIx64
,
5617 state_machine_regs
.address
);
5619 printf ("%-31s %11d %#18" PRIx64
,
5620 newFileName
, state_machine_regs
.line
,
5621 state_machine_regs
.address
);
5625 if (xop
== -DW_LNE_end_sequence
)
5626 printf ("%-31s %11s %#18" PRIx64
"[%d]",
5628 state_machine_regs
.address
,
5629 state_machine_regs
.op_index
);
5631 printf ("%-31s %11d %#18" PRIx64
"[%d]",
5632 newFileName
, state_machine_regs
.line
,
5633 state_machine_regs
.address
,
5634 state_machine_regs
.op_index
);
5639 if (linfo
.li_max_ops_per_insn
== 1)
5641 if (xop
== -DW_LNE_end_sequence
)
5642 printf ("%s %11s %#18" PRIx64
,
5644 state_machine_regs
.address
);
5646 printf ("%s %11d %#18" PRIx64
,
5647 newFileName
, state_machine_regs
.line
,
5648 state_machine_regs
.address
);
5652 if (xop
== -DW_LNE_end_sequence
)
5653 printf ("%s %11s %#18" PRIx64
"[%d]",
5655 state_machine_regs
.address
,
5656 state_machine_regs
.op_index
);
5658 printf ("%s %11d %#18" PRIx64
"[%d]",
5659 newFileName
, state_machine_regs
.line
,
5660 state_machine_regs
.address
,
5661 state_machine_regs
.op_index
);
5665 if (xop
!= -DW_LNE_end_sequence
)
5667 if (state_machine_regs
.view
)
5668 printf (" %6u", state_machine_regs
.view
);
5672 if (state_machine_regs
.is_stmt
)
5677 state_machine_regs
.view
++;
5679 if (xop
== -DW_LNE_end_sequence
)
5681 reset_state_machine (linfo
.li_default_is_stmt
);
5685 if (newFileName
!= fileName
)
5697 if (directory_table
)
5699 free (directory_table
);
5700 directory_table
= NULL
;
5711 display_debug_lines (struct dwarf_section
*section
, void *file
)
5713 unsigned char *data
= section
->start
;
5714 unsigned char *end
= data
+ section
->size
;
5716 int retValDecoded
= 1;
5718 if (do_debug_lines
== 0)
5719 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5721 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5722 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5724 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5725 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5727 if (!retValRaw
|| !retValDecoded
)
5734 find_debug_info_for_offset (uint64_t offset
)
5738 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5741 for (i
= 0; i
< num_debug_info_entries
; i
++)
5742 if (debug_information
[i
].cu_offset
== offset
)
5743 return debug_information
+ i
;
5749 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5751 /* See gdb/gdb-index.h. */
5752 static const char * const kinds
[] =
5764 return _ (kinds
[kind
]);
5768 display_debug_pubnames_worker (struct dwarf_section
*section
,
5769 void *file ATTRIBUTE_UNUSED
,
5772 DWARF2_Internal_PubNames names
;
5773 unsigned char *start
= section
->start
;
5774 unsigned char *end
= start
+ section
->size
;
5776 /* It does not matter if this load fails,
5777 we test for that later on. */
5778 load_debug_info (file
);
5780 introduce (section
, false);
5784 unsigned char *data
;
5785 unsigned long sec_off
= start
- section
->start
;
5786 unsigned int offset_size
;
5788 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5789 if (names
.pn_length
== 0xffffffff)
5791 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5797 if (names
.pn_length
> (size_t) (end
- start
))
5799 warn (_("Debug info is corrupted, "
5800 "%s header at %#lx has length %#" PRIx64
"\n"),
5801 section
->name
, sec_off
, names
.pn_length
);
5806 start
+= names
.pn_length
;
5808 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5809 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5811 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5812 && num_debug_info_entries
> 0
5813 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5814 warn (_(".debug_info offset of %#" PRIx64
5815 " in %s section does not point to a CU header.\n"),
5816 names
.pn_offset
, section
->name
);
5818 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5820 printf (_(" Length: %" PRId64
"\n"),
5822 printf (_(" Version: %d\n"),
5824 printf (_(" Offset into .debug_info section: %#" PRIx64
"\n"),
5826 printf (_(" Size of area in .debug_info section: %" PRId64
"\n"),
5829 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5831 static int warned
= 0;
5835 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5843 printf (_("\n Offset Kind Name\n"));
5845 printf (_("\n Offset\tName\n"));
5852 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5859 maxprint
= (start
- data
) - 1;
5863 unsigned int kind_data
;
5864 gdb_index_symbol_kind kind
;
5865 const char *kind_name
;
5868 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5870 /* GCC computes the kind as the upper byte in the CU index
5871 word, and then right shifts it by the CU index size.
5872 Left shift KIND to where the gdb-index.h accessor macros
5874 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5875 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5876 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5877 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5878 printf (" %-6" PRIx64
" %s,%-10s %.*s\n",
5879 offset
, is_static
? _("s") : _("g"),
5880 kind_name
, (int) maxprint
, data
);
5883 printf (" %-6" PRIx64
"\t%.*s\n",
5884 offset
, (int) maxprint
, data
);
5886 data
+= strnlen ((char *) data
, maxprint
);
5899 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5901 return display_debug_pubnames_worker (section
, file
, 0);
5905 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5907 return display_debug_pubnames_worker (section
, file
, 1);
5911 display_debug_macinfo (struct dwarf_section
*section
,
5912 void *file ATTRIBUTE_UNUSED
)
5914 unsigned char *start
= section
->start
;
5915 unsigned char *end
= start
+ section
->size
;
5916 unsigned char *curr
= start
;
5917 enum dwarf_macinfo_record_type op
;
5919 introduce (section
, false);
5923 unsigned int lineno
;
5924 const unsigned char *string
;
5926 op
= (enum dwarf_macinfo_record_type
) *curr
;
5931 case DW_MACINFO_start_file
:
5933 unsigned int filenum
;
5935 READ_ULEB (lineno
, curr
, end
);
5936 READ_ULEB (filenum
, curr
, end
);
5937 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5942 case DW_MACINFO_end_file
:
5943 printf (_(" DW_MACINFO_end_file\n"));
5946 case DW_MACINFO_define
:
5947 READ_ULEB (lineno
, curr
, end
);
5949 curr
+= strnlen ((char *) string
, end
- string
);
5950 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5951 lineno
, (int) (curr
- string
), string
);
5956 case DW_MACINFO_undef
:
5957 READ_ULEB (lineno
, curr
, end
);
5959 curr
+= strnlen ((char *) string
, end
- string
);
5960 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5961 lineno
, (int) (curr
- string
), string
);
5966 case DW_MACINFO_vendor_ext
:
5968 unsigned int constant
;
5970 READ_ULEB (constant
, curr
, end
);
5972 curr
+= strnlen ((char *) string
, end
- string
);
5973 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5974 constant
, (int) (curr
- string
), string
);
5985 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5986 filename and dirname corresponding to file name table entry with index
5987 FILEIDX. Return NULL on failure. */
5989 static unsigned char *
5990 get_line_filename_and_dirname (uint64_t line_offset
,
5992 unsigned char **dir_name
)
5994 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5995 unsigned char *hdrptr
, *dirtable
, *file_name
;
5996 unsigned int offset_size
;
5997 unsigned int version
, opcode_base
;
5998 uint64_t length
, diridx
;
5999 const unsigned char * end
;
6002 if (section
->start
== NULL
6003 || line_offset
>= section
->size
6007 hdrptr
= section
->start
+ line_offset
;
6008 end
= section
->start
+ section
->size
;
6010 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
6011 if (length
== 0xffffffff)
6013 /* This section is 64-bit DWARF 3. */
6014 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
6020 if (length
> (size_t) (end
- hdrptr
)
6021 || length
< 2 + offset_size
+ 1 + 3 + 1)
6023 end
= hdrptr
+ length
;
6025 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
6026 if (version
!= 2 && version
!= 3 && version
!= 4)
6028 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6030 hdrptr
++; /* Skip max_ops_per_insn. */
6031 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6033 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6034 if (opcode_base
== 0
6035 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6038 hdrptr
+= opcode_base
- 1;
6041 /* Skip over dirname table. */
6042 while (*hdrptr
!= '\0')
6044 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6050 hdrptr
++; /* Skip the NUL at the end of the table. */
6052 /* Now skip over preceding filename table entries. */
6053 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6055 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6058 SKIP_ULEB (hdrptr
, end
);
6059 SKIP_ULEB (hdrptr
, end
);
6060 SKIP_ULEB (hdrptr
, end
);
6062 if (hdrptr
>= end
|| *hdrptr
== '\0')
6066 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6071 READ_ULEB (diridx
, hdrptr
, end
);
6074 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6076 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6080 if (dirtable
>= end
|| *dirtable
== '\0')
6082 *dir_name
= dirtable
;
6087 display_debug_macro (struct dwarf_section
*section
,
6090 unsigned char *start
= section
->start
;
6091 unsigned char *end
= start
+ section
->size
;
6092 unsigned char *curr
= start
;
6093 unsigned char *extended_op_buf
[256];
6094 bool is_dwo
= false;
6095 const char *suffix
= strrchr (section
->name
, '.');
6097 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6100 load_debug_section_with_follow (str
, file
);
6101 load_debug_section_with_follow (line
, file
);
6102 load_debug_section_with_follow (str_index
, file
);
6104 introduce (section
, false);
6108 unsigned int lineno
, version
, flags
;
6109 unsigned int offset_size
;
6110 const unsigned char *string
;
6111 uint64_t line_offset
= 0, sec_offset
= curr
- start
, offset
;
6112 unsigned char **extended_ops
= NULL
;
6114 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6115 if (version
!= 4 && version
!= 5)
6117 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6118 section
->name
, version
);
6122 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6123 offset_size
= (flags
& 1) ? 8 : 4;
6124 printf (_(" Offset: %#" PRIx64
"\n"), sec_offset
);
6125 printf (_(" Version: %d\n"), version
);
6126 printf (_(" Offset size: %d\n"), offset_size
);
6129 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6130 printf (_(" Offset into .debug_line: %#" PRIx64
"\n"),
6135 unsigned int i
, count
, op
;
6138 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6140 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6141 extended_ops
= extended_op_buf
;
6144 printf (_(" Extension opcode arguments:\n"));
6145 for (i
= 0; i
< count
; i
++)
6147 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6148 extended_ops
[op
] = curr
;
6149 READ_ULEB (nargs
, curr
, end
);
6151 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6154 printf (_(" DW_MACRO_%02x arguments: "), op
);
6155 for (n
= 0; n
< nargs
; n
++)
6159 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6160 printf ("%s%s", get_FORM_name (form
),
6161 n
== nargs
- 1 ? "\n" : ", ");
6171 case DW_FORM_block1
:
6172 case DW_FORM_block2
:
6173 case DW_FORM_block4
:
6175 case DW_FORM_string
:
6177 case DW_FORM_sec_offset
:
6180 error (_("Invalid extension opcode form %s\n"),
6181 get_FORM_name (form
));
6197 error (_(".debug_macro section not zero terminated\n"));
6201 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6207 case DW_MACRO_define
:
6208 READ_ULEB (lineno
, curr
, end
);
6210 curr
+= strnlen ((char *) string
, end
- string
);
6211 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6212 lineno
, (int) (curr
- string
), string
);
6217 case DW_MACRO_undef
:
6218 READ_ULEB (lineno
, curr
, end
);
6220 curr
+= strnlen ((char *) string
, end
- string
);
6221 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6222 lineno
, (int) (curr
- string
), string
);
6227 case DW_MACRO_start_file
:
6229 unsigned int filenum
;
6230 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6232 READ_ULEB (lineno
, curr
, end
);
6233 READ_ULEB (filenum
, curr
, end
);
6235 if ((flags
& 2) == 0)
6236 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6239 = get_line_filename_and_dirname (line_offset
, filenum
,
6241 if (file_name
== NULL
)
6242 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6245 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6247 dir_name
!= NULL
? (const char *) dir_name
: "",
6248 dir_name
!= NULL
? "/" : "", file_name
);
6252 case DW_MACRO_end_file
:
6253 printf (_(" DW_MACRO_end_file\n"));
6256 case DW_MACRO_define_strp
:
6257 READ_ULEB (lineno
, curr
, end
);
6258 if (version
== 4 && is_dwo
)
6259 READ_ULEB (offset
, curr
, end
);
6261 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6262 string
= fetch_indirect_string (offset
);
6263 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6267 case DW_MACRO_undef_strp
:
6268 READ_ULEB (lineno
, curr
, end
);
6269 if (version
== 4 && is_dwo
)
6270 READ_ULEB (offset
, curr
, end
);
6272 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6273 string
= fetch_indirect_string (offset
);
6274 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6278 case DW_MACRO_import
:
6279 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6280 printf (_(" DW_MACRO_import - offset : %#" PRIx64
"\n"),
6284 case DW_MACRO_define_sup
:
6285 READ_ULEB (lineno
, curr
, end
);
6286 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6287 printf (_(" DW_MACRO_define_sup - lineno : %d"
6288 " macro offset : %#" PRIx64
"\n"),
6292 case DW_MACRO_undef_sup
:
6293 READ_ULEB (lineno
, curr
, end
);
6294 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6295 printf (_(" DW_MACRO_undef_sup - lineno : %d"
6296 " macro offset : %#" PRIx64
"\n"),
6300 case DW_MACRO_import_sup
:
6301 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6302 printf (_(" DW_MACRO_import_sup - offset : %#" PRIx64
"\n"),
6306 case DW_MACRO_define_strx
:
6307 case DW_MACRO_undef_strx
:
6308 READ_ULEB (lineno
, curr
, end
);
6309 READ_ULEB (offset
, curr
, end
);
6310 string
= (const unsigned char *)
6311 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6312 if (op
== DW_MACRO_define_strx
)
6313 printf (" DW_MACRO_define_strx ");
6315 printf (" DW_MACRO_undef_strx ");
6317 printf (_("(with offset %#" PRIx64
") "), offset
);
6318 printf (_("lineno : %d macro : %s\n"),
6323 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6325 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6329 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6331 error (_(" Unknown macro opcode %02x seen\n"), op
);
6336 /* Skip over unhandled opcodes. */
6338 unsigned char *desc
= extended_ops
[op
];
6339 READ_ULEB (nargs
, desc
, end
);
6342 printf (_(" DW_MACRO_%02x\n"), op
);
6345 printf (_(" DW_MACRO_%02x -"), op
);
6346 for (n
= 0; n
< nargs
; n
++)
6350 /* DW_FORM_implicit_const is not expected here. */
6351 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6353 = read_and_display_attr_value (0, val
, 0,
6354 start
, curr
, end
, 0, 0,
6355 offset_size
, version
,
6374 display_debug_abbrev (struct dwarf_section
*section
,
6375 void *file ATTRIBUTE_UNUSED
)
6377 abbrev_entry
*entry
;
6378 unsigned char *start
= section
->start
;
6380 introduce (section
, false);
6384 uint64_t offset
= start
- section
->start
;
6385 abbrev_list
*list
= find_and_process_abbrev_set (section
, 0,
6386 section
->size
, offset
,
6391 if (list
->first_abbrev
)
6392 printf (_(" Number TAG (%#" PRIx64
")\n"), offset
);
6394 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6398 printf (" %ld %s [%s]\n",
6400 get_TAG_name (entry
->tag
),
6401 entry
->children
? _("has children") : _("no children"));
6403 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6405 printf (" %-18s %s",
6406 get_AT_name (attr
->attribute
),
6407 get_FORM_name (attr
->form
));
6408 if (attr
->form
== DW_FORM_implicit_const
)
6409 printf (": %" PRId64
, attr
->implicit_const
);
6413 start
= list
->start_of_next_abbrevs
;
6414 free_abbrev_list (list
);
6423 /* Return true when ADDR is the maximum address, when addresses are
6424 POINTER_SIZE bytes long. */
6427 is_max_address (uint64_t addr
, unsigned int pointer_size
)
6429 uint64_t mask
= ~(~(uint64_t) 0 << 1 << (pointer_size
* 8 - 1));
6430 return ((addr
& mask
) == mask
);
6433 /* Display a view pair list starting at *VSTART_PTR and ending at
6434 VLISTEND within SECTION. */
6437 display_view_pair_list (struct dwarf_section
*section
,
6438 unsigned char **vstart_ptr
,
6439 unsigned int debug_info_entry
,
6440 unsigned char *vlistend
)
6442 unsigned char *vstart
= *vstart_ptr
;
6443 unsigned char *section_end
= section
->start
+ section
->size
;
6444 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6446 if (vlistend
< section_end
)
6447 section_end
= vlistend
;
6451 while (vstart
< section_end
)
6453 uint64_t off
= vstart
- section
->start
;
6454 uint64_t vbegin
, vend
;
6456 READ_ULEB (vbegin
, vstart
, section_end
);
6457 if (vstart
== section_end
)
6460 READ_ULEB (vend
, vstart
, section_end
);
6461 printf (" %8.8" PRIx64
" ", off
);
6463 print_view (vbegin
, pointer_size
);
6464 print_view (vend
, pointer_size
);
6465 printf (_("location view pair\n"));
6469 *vstart_ptr
= vstart
;
6472 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6475 display_loc_list (struct dwarf_section
*section
,
6476 unsigned char **start_ptr
,
6477 unsigned int debug_info_entry
,
6479 uint64_t base_address
,
6480 unsigned char **vstart_ptr
,
6483 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6484 unsigned char *section_end
= section
->start
+ section
->size
;
6486 unsigned int pointer_size
;
6487 unsigned int offset_size
;
6491 unsigned short length
;
6492 int need_frame_base
;
6494 if (debug_info_entry
>= num_debug_info_entries
)
6496 warn (_("No debug information available for loc lists of entry: %u\n"),
6501 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6502 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6503 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6504 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6506 if (pointer_size
< 2 || pointer_size
> 8)
6508 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6509 pointer_size
, debug_info_entry
);
6515 uint64_t off
= offset
+ (start
- *start_ptr
);
6516 uint64_t vbegin
= -1, vend
= -1;
6518 if (2 * pointer_size
> (size_t) (section_end
- start
))
6520 warn (_("Location list starting at offset %#" PRIx64
6521 " is not terminated.\n"), offset
);
6528 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6529 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6531 if (begin
== 0 && end
== 0)
6533 /* PR 18374: In a object file we can have a location list that
6534 starts with a begin and end of 0 because there are relocations
6535 that need to be applied to the addresses. Actually applying
6536 the relocations now does not help as they will probably resolve
6537 to 0, since the object file has not been fully linked. Real
6538 end of list markers will not have any relocations against them. */
6539 if (! reloc_at (section
, off
)
6540 && ! reloc_at (section
, off
+ pointer_size
))
6542 printf (_("<End of list>\n"));
6547 /* Check base address specifiers. */
6548 if (is_max_address (begin
, pointer_size
)
6549 && !is_max_address (end
, pointer_size
))
6552 print_hex (begin
, pointer_size
);
6553 print_hex (end
, pointer_size
);
6554 printf (_("(base address)\n"));
6560 off
= offset
+ (vstart
- *start_ptr
);
6562 READ_ULEB (vbegin
, vstart
, section_end
);
6563 print_view (vbegin
, pointer_size
);
6565 READ_ULEB (vend
, vstart
, section_end
);
6566 print_view (vend
, pointer_size
);
6568 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6571 if (2 > (size_t) (section_end
- start
))
6573 warn (_("Location list starting at offset %#" PRIx64
6574 " is not terminated.\n"), offset
);
6578 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6580 if (length
> (size_t) (section_end
- start
))
6582 warn (_("Location list starting at offset %#" PRIx64
6583 " is not terminated.\n"), offset
);
6587 print_hex (begin
+ base_address
, pointer_size
);
6588 print_hex (end
+ base_address
, pointer_size
);
6591 need_frame_base
= decode_location_expression (start
,
6596 cu_offset
, section
);
6599 if (need_frame_base
&& !has_frame_base
)
6600 printf (_(" [without DW_AT_frame_base]"));
6602 if (begin
== end
&& vbegin
== vend
)
6603 fputs (_(" (start == end)"), stdout
);
6604 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6605 fputs (_(" (start > end)"), stdout
);
6613 *vstart_ptr
= vstart
;
6616 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6619 display_loclists_list (struct dwarf_section
* section
,
6620 unsigned char ** start_ptr
,
6621 unsigned int debug_info_entry
,
6623 uint64_t base_address
,
6624 unsigned char ** vstart_ptr
,
6627 unsigned char *start
= *start_ptr
;
6628 unsigned char *vstart
= *vstart_ptr
;
6629 unsigned char *section_end
= section
->start
+ section
->size
;
6631 unsigned int pointer_size
;
6632 unsigned int offset_size
;
6633 unsigned int dwarf_version
;
6635 /* Initialize it due to a false compiler warning. */
6636 uint64_t begin
= -1, vbegin
= -1;
6637 uint64_t end
= -1, vend
= -1;
6639 int need_frame_base
;
6641 if (debug_info_entry
>= num_debug_info_entries
)
6643 warn (_("No debug information available for "
6644 "loclists lists of entry: %u\n"),
6649 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6650 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6651 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6652 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6654 if (pointer_size
< 2 || pointer_size
> 8)
6656 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6657 pointer_size
, debug_info_entry
);
6663 uint64_t off
= offset
+ (start
- *start_ptr
);
6664 enum dwarf_location_list_entry_type llet
;
6666 if (start
+ 1 > section_end
)
6668 warn (_("Location list starting at offset %#" PRIx64
6669 " is not terminated.\n"), offset
);
6676 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6678 if (vstart
&& (llet
== DW_LLE_offset_pair
6679 || llet
== DW_LLE_start_end
6680 || llet
== DW_LLE_start_length
))
6682 off
= offset
+ (vstart
- *start_ptr
);
6684 READ_ULEB (vbegin
, vstart
, section_end
);
6685 print_view (vbegin
, pointer_size
);
6687 READ_ULEB (vend
, vstart
, section_end
);
6688 print_view (vend
, pointer_size
);
6690 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6695 case DW_LLE_end_of_list
:
6696 printf (_("<End of list>\n"));
6699 case DW_LLE_base_addressx
:
6700 READ_ULEB (base_address
, start
, section_end
);
6701 print_hex (base_address
, pointer_size
);
6702 printf (_("(index into .debug_addr) "));
6703 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6704 print_hex (base_address
, pointer_size
);
6705 printf (_("(base address)\n"));
6708 case DW_LLE_startx_endx
:
6709 READ_ULEB (begin
, start
, section_end
);
6710 begin
= fetch_indexed_addr (begin
, pointer_size
);
6711 READ_ULEB (end
, start
, section_end
);
6712 end
= fetch_indexed_addr (end
, pointer_size
);
6715 case DW_LLE_startx_length
:
6716 READ_ULEB (begin
, start
, section_end
);
6717 begin
= fetch_indexed_addr (begin
, pointer_size
);
6718 READ_ULEB (end
, start
, section_end
);
6722 case DW_LLE_default_location
:
6726 case DW_LLE_offset_pair
:
6727 READ_ULEB (begin
, start
, section_end
);
6728 begin
+= base_address
;
6729 READ_ULEB (end
, start
, section_end
);
6730 end
+= base_address
;
6733 case DW_LLE_base_address
:
6734 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6736 print_hex (base_address
, pointer_size
);
6737 printf (_("(base address)\n"));
6740 case DW_LLE_start_end
:
6741 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6742 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6745 case DW_LLE_start_length
:
6746 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6747 READ_ULEB (end
, start
, section_end
);
6751 #ifdef DW_LLE_view_pair
6752 case DW_LLE_view_pair
:
6754 printf (_("View pair entry in loclist with locviews attribute\n"));
6755 READ_ULEB (vbegin
, start
, section_end
);
6756 print_view (vbegin
, pointer_size
);
6758 READ_ULEB (vend
, start
, section_end
);
6759 print_view (vend
, pointer_size
);
6761 printf (_("views for:\n"));
6766 error (_("Invalid location list entry type %d\n"), llet
);
6770 if (llet
== DW_LLE_end_of_list
)
6773 if (llet
== DW_LLE_base_address
6774 || llet
== DW_LLE_base_addressx
)
6777 if (start
== section_end
)
6779 warn (_("Location list starting at offset %#" PRIx64
6780 " is not terminated.\n"), offset
);
6783 READ_ULEB (length
, start
, section_end
);
6785 if (length
> (size_t) (section_end
- start
))
6787 warn (_("Location list starting at offset %#" PRIx64
6788 " is not terminated.\n"), offset
);
6792 print_hex (begin
, pointer_size
);
6793 print_hex (end
, pointer_size
);
6796 need_frame_base
= decode_location_expression (start
,
6801 cu_offset
, section
);
6804 if (need_frame_base
&& !has_frame_base
)
6805 printf (_(" [without DW_AT_frame_base]"));
6807 if (begin
== end
&& vbegin
== vend
)
6808 fputs (_(" (start == end)"), stdout
);
6809 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6810 fputs (_(" (start > end)"), stdout
);
6818 if (vbegin
!= (uint64_t) -1 || vend
!= (uint64_t) -1)
6819 printf (_("Trailing view pair not used in a range"));
6822 *vstart_ptr
= vstart
;
6825 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6826 right-adjusted in a field of length LEN, and followed by a space. */
6829 print_addr_index (unsigned int idx
, unsigned int len
)
6831 static char buf
[15];
6832 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6833 printf ("%*s ", len
, buf
);
6836 /* Display a location list from a .dwo section. It uses address indexes rather
6837 than embedded addresses. This code closely follows display_loc_list, but the
6838 two are sufficiently different that combining things is very ugly. */
6841 display_loc_list_dwo (struct dwarf_section
*section
,
6842 unsigned char **start_ptr
,
6843 unsigned int debug_info_entry
,
6845 unsigned char **vstart_ptr
,
6848 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6849 unsigned char *section_end
= section
->start
+ section
->size
;
6851 unsigned int pointer_size
;
6852 unsigned int offset_size
;
6855 unsigned short length
;
6856 int need_frame_base
;
6859 if (debug_info_entry
>= num_debug_info_entries
)
6861 warn (_("No debug information for loc lists of entry: %u\n"),
6866 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6867 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6868 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6869 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6871 if (pointer_size
< 2 || pointer_size
> 8)
6873 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6874 pointer_size
, debug_info_entry
);
6881 print_hex (offset
+ (start
- *start_ptr
), 4);
6883 if (start
>= section_end
)
6885 warn (_("Location list starting at offset %#" PRIx64
6886 " is not terminated.\n"), offset
);
6890 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6903 uint64_t off
= offset
+ (vstart
- *start_ptr
);
6905 READ_ULEB (view
, vstart
, section_end
);
6906 print_view (view
, 8);
6908 READ_ULEB (view
, vstart
, section_end
);
6909 print_view (view
, 8);
6911 printf (_("views at %8.8" PRIx64
" for:\n %*s "), off
, 8, "");
6919 case 0: /* A terminating entry. */
6921 *vstart_ptr
= vstart
;
6922 printf (_("<End of list>\n"));
6924 case 1: /* A base-address entry. */
6925 READ_ULEB (idx
, start
, section_end
);
6926 print_addr_index (idx
, 8);
6927 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6928 printf (_("(base address selection entry)\n"));
6930 case 2: /* A start/end entry. */
6931 READ_ULEB (idx
, start
, section_end
);
6932 print_addr_index (idx
, 8);
6933 READ_ULEB (idx
, start
, section_end
);
6934 print_addr_index (idx
, 8);
6936 case 3: /* A start/length entry. */
6937 READ_ULEB (idx
, start
, section_end
);
6938 print_addr_index (idx
, 8);
6939 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6940 printf ("%08x ", idx
);
6942 case 4: /* An offset pair entry. */
6943 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6944 printf ("%08x ", idx
);
6945 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6946 printf ("%08x ", idx
);
6949 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6951 *vstart_ptr
= vstart
;
6955 if (2 > (size_t) (section_end
- start
))
6957 warn (_("Location list starting at offset %#" PRIx64
6958 " is not terminated.\n"), offset
);
6962 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6963 if (length
> (size_t) (section_end
- start
))
6965 warn (_("Location list starting at offset %#" PRIx64
6966 " is not terminated.\n"), offset
);
6971 need_frame_base
= decode_location_expression (start
,
6976 cu_offset
, section
);
6979 if (need_frame_base
&& !has_frame_base
)
6980 printf (_(" [without DW_AT_frame_base]"));
6988 *vstart_ptr
= vstart
;
6991 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6994 static uint64_t *loc_offsets
, *loc_views
;
6997 loc_offsets_compar (const void *ap
, const void *bp
)
6999 uint64_t a
= loc_offsets
[*(const unsigned int *) ap
];
7000 uint64_t b
= loc_offsets
[*(const unsigned int *) bp
];
7002 int ret
= (a
> b
) - (b
> a
);
7006 a
= loc_views
[*(const unsigned int *) ap
];
7007 b
= loc_views
[*(const unsigned int *) bp
];
7009 ret
= (a
> b
) - (b
> a
);
7015 display_offset_entry_loclists (struct dwarf_section
*section
)
7017 unsigned char * start
= section
->start
;
7018 unsigned char * const end
= start
+ section
->size
;
7020 introduce (section
, false);
7025 unsigned short version
;
7026 unsigned char address_size
;
7027 unsigned char segment_selector_size
;
7028 uint32_t offset_entry_count
;
7032 printf (_("Table at Offset %#tx\n"), start
- section
->start
);
7034 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7035 if (length
== 0xffffffff)
7038 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7043 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7044 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7045 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7046 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7048 printf (_(" Length: %#" PRIx64
"\n"), length
);
7049 printf (_(" DWARF version: %u\n"), version
);
7050 printf (_(" Address size: %u\n"), address_size
);
7051 printf (_(" Segment size: %u\n"), segment_selector_size
);
7052 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7056 warn (_("The %s section contains a corrupt or "
7057 "unsupported version number: %d.\n"),
7058 section
->name
, version
);
7062 if (segment_selector_size
!= 0)
7064 warn (_("The %s section contains an "
7065 "unsupported segment selector size: %d.\n"),
7066 section
->name
, segment_selector_size
);
7070 if (offset_entry_count
== 0)
7072 warn (_("The %s section contains a table without offset\n"),
7077 printf (_("\n Offset Entries starting at %#tx:\n"),
7078 start
- section
->start
);
7080 for (i
= 0; i
< offset_entry_count
; i
++)
7084 SAFE_BYTE_GET_AND_INC (entry
, start
, is_64bit
? 8 : 4, end
);
7085 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
7092 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7095 uint64_t base_address
= 0;
7098 uint64_t off
= start
- section
->start
;
7102 printf (_(" Offset Entry %u\n"), i
);
7109 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7113 case DW_LLE_end_of_list
:
7114 printf (_("<End of list>\n\n"));
7118 case DW_LLE_base_addressx
:
7119 READ_ULEB (base_address
, start
, end
);
7120 print_hex (base_address
, address_size
);
7121 printf (_("(index into .debug_addr) "));
7122 base_address
= fetch_indexed_addr (base_address
, address_size
);
7123 print_hex (base_address
, address_size
);
7124 printf (_("(base address)\n"));
7127 case DW_LLE_startx_endx
:
7128 READ_ULEB (begin
, start
, end
);
7129 begin
= fetch_indexed_addr (begin
, address_size
);
7130 READ_ULEB (finish
, start
, end
);
7131 finish
= fetch_indexed_addr (finish
, address_size
);
7134 case DW_LLE_startx_length
:
7135 READ_ULEB (begin
, start
, end
);
7136 begin
= fetch_indexed_addr (begin
, address_size
);
7137 READ_ULEB (finish
, start
, end
);
7141 case DW_LLE_offset_pair
:
7142 READ_ULEB (begin
, start
, end
);
7143 begin
+= base_address
;
7144 READ_ULEB (finish
, start
, end
);
7145 finish
+= base_address
;
7148 case DW_LLE_default_location
:
7152 case DW_LLE_base_address
:
7153 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7154 print_hex (base_address
, address_size
);
7155 printf (_("(base address)\n"));
7158 case DW_LLE_start_end
:
7159 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7160 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7163 case DW_LLE_start_length
:
7164 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7165 READ_ULEB (finish
, start
, end
);
7170 error (_("Invalid location list entry type %d\n"), lle
);
7176 warn (_("Location list starting at offset %#" PRIx64
7177 " is not terminated.\n"), off
);
7181 print_hex (begin
, address_size
);
7182 print_hex (finish
, address_size
);
7184 if (begin
== finish
)
7185 fputs (_("(start == end)"), stdout
);
7186 else if (begin
> finish
)
7187 fputs (_("(start > end)"), stdout
);
7189 /* Read the counted location descriptions. */
7190 READ_ULEB (length
, start
, end
);
7192 if (length
> (size_t) (end
- start
))
7194 warn (_("Location list starting at offset %#" PRIx64
7195 " is not terminated.\n"), off
);
7199 (void) decode_location_expression (start
, address_size
, address_size
,
7200 version
, length
, 0, section
);
7207 while (start
< end
);
7213 display_debug_loc (struct dwarf_section
*section
, void *file
)
7215 unsigned char *start
= section
->start
, *vstart
= NULL
;
7217 unsigned char *section_begin
= start
;
7218 unsigned int num_loc_list
= 0;
7219 uint64_t last_offset
= 0;
7220 uint64_t last_view
= 0;
7221 unsigned int first
= 0;
7224 int seen_first_offset
= 0;
7225 int locs_sorted
= 1;
7226 unsigned char *next
= start
, *vnext
= vstart
;
7227 unsigned int *array
= NULL
;
7228 const char *suffix
= strrchr (section
->name
, '.');
7229 bool is_dwo
= false;
7230 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7231 uint64_t header_size
= 0;
7233 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7236 bytes
= section
->size
;
7240 printf (_("\nThe %s section is empty.\n"), section
->name
);
7246 unsigned char *hdrptr
= section_begin
;
7248 unsigned short ll_version
;
7249 unsigned char *end
= section_begin
+ section
->size
;
7250 unsigned char address_size
, segment_selector_size
;
7251 uint32_t offset_entry_count
;
7253 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7254 if (ll_length
== 0xffffffff)
7255 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7257 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7258 if (ll_version
!= 5)
7260 warn (_("The %s section contains corrupt or "
7261 "unsupported version number: %d.\n"),
7262 section
->name
, ll_version
);
7266 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7268 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7269 if (segment_selector_size
!= 0)
7271 warn (_("The %s section contains "
7272 "unsupported segment selector size: %d.\n"),
7273 section
->name
, segment_selector_size
);
7277 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7279 if (offset_entry_count
!= 0)
7280 return display_offset_entry_loclists (section
);
7282 header_size
= hdrptr
- section_begin
;
7285 if (load_debug_info (file
) == 0)
7287 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7292 /* Check the order of location list in .debug_info section. If
7293 offsets of location lists are in the ascending order, we can
7294 use `debug_information' directly. */
7295 for (i
= 0; i
< num_debug_info_entries
; i
++)
7299 num
= debug_information
[i
].num_loc_offsets
;
7300 if (num
> num_loc_list
)
7303 /* Check if we can use `debug_information' directly. */
7304 if (locs_sorted
&& num
!= 0)
7306 if (!seen_first_offset
)
7308 /* This is the first location list. */
7309 last_offset
= debug_information
[i
].loc_offsets
[0];
7310 last_view
= debug_information
[i
].loc_views
[0];
7312 seen_first_offset
= 1;
7318 for (; j
< num
; j
++)
7321 debug_information
[i
].loc_offsets
[j
]
7322 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7323 && last_view
> debug_information
[i
].loc_views
[j
]))
7328 last_offset
= debug_information
[i
].loc_offsets
[j
];
7329 last_view
= debug_information
[i
].loc_views
[j
];
7334 if (!seen_first_offset
)
7335 error (_("No location lists in .debug_info section!\n"));
7337 if (debug_information
[first
].num_loc_offsets
> 0
7338 && debug_information
[first
].loc_offsets
[0] != header_size
7339 && debug_information
[first
].loc_views
[0] != header_size
)
7340 warn (_("Location lists in %s section start at %#" PRIx64
7341 " rather than %#" PRIx64
"\n"),
7342 section
->name
, debug_information
[first
].loc_offsets
[0],
7346 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7348 introduce (section
, false);
7350 if (reloc_at (section
, 0))
7351 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7353 printf (_(" Offset Begin End Expression\n"));
7355 for (i
= first
; i
< num_debug_info_entries
; i
++)
7357 uint64_t offset
= 0, voffset
= 0;
7358 uint64_t base_address
;
7364 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7366 loc_offsets
= debug_information
[i
].loc_offsets
;
7367 loc_views
= debug_information
[i
].loc_views
;
7368 qsort (array
, debug_information
[i
].num_loc_offsets
,
7369 sizeof (*array
), loc_offsets_compar
);
7372 /* .debug_loclists has a per-unit header.
7373 Update start if we are detecting it. */
7374 if (debug_information
[i
].dwarf_version
== 5)
7376 j
= locs_sorted
? 0 : array
[0];
7378 if (debug_information
[i
].num_loc_offsets
)
7379 offset
= debug_information
[i
].loc_offsets
[j
];
7381 if (debug_information
[i
].num_loc_views
)
7382 voffset
= debug_information
[i
].loc_views
[j
];
7384 /* Assume that the size of the header is constant across CUs. */
7385 if (((start
- section_begin
) + header_size
== offset
)
7386 || ((start
-section_begin
) + header_size
== voffset
))
7387 start
+= header_size
;
7390 int adjacent_view_loclists
= 1;
7391 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7393 j
= locs_sorted
? k
: array
[k
];
7395 && (debug_information
[i
].loc_offsets
[locs_sorted
7396 ? k
- 1 : array
[k
- 1]]
7397 == debug_information
[i
].loc_offsets
[j
])
7398 && (debug_information
[i
].loc_views
[locs_sorted
7399 ? k
- 1 : array
[k
- 1]]
7400 == debug_information
[i
].loc_views
[j
]))
7402 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7403 offset
= debug_information
[i
].loc_offsets
[j
];
7404 next
= section_begin
+ offset
;
7405 voffset
= debug_information
[i
].loc_views
[j
];
7406 if (voffset
!= (uint64_t) -1)
7407 vnext
= section_begin
+ voffset
;
7410 base_address
= debug_information
[i
].base_address
;
7412 if (vnext
&& vnext
< next
)
7415 display_view_pair_list (section
, &vstart
, i
, next
);
7422 if (vnext
&& vnext
< next
)
7423 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7424 " in %s section.\n"),
7425 start
- section_begin
, voffset
, section
->name
);
7427 warn (_("There is a hole [%#tx - %#" PRIx64
"]"
7428 " in %s section.\n"),
7429 start
- section_begin
, offset
, section
->name
);
7431 else if (start
> next
)
7432 warn (_("There is an overlap [%#tx - %#" PRIx64
"]"
7433 " in %s section.\n"),
7434 start
- section_begin
, offset
, section
->name
);
7438 if (offset
>= bytes
)
7440 warn (_("Offset %#" PRIx64
" is bigger than %s section size.\n"),
7441 offset
, section
->name
);
7445 if (vnext
&& voffset
>= bytes
)
7447 warn (_("View Offset %#" PRIx64
" is bigger than %s section size.\n"),
7448 voffset
, section
->name
);
7455 display_loc_list_dwo (section
, &start
, i
, offset
,
7456 &vstart
, has_frame_base
);
7458 display_loc_list (section
, &start
, i
, offset
, base_address
,
7459 &vstart
, has_frame_base
);
7464 warn (_("DWO is not yet supported.\n"));
7466 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7467 &vstart
, has_frame_base
);
7470 /* FIXME: this arrangement is quite simplistic. Nothing
7471 requires locview lists to be adjacent to corresponding
7472 loclists, and a single loclist could be augmented by
7473 different locview lists, and vice-versa, unlikely as it
7474 is that it would make sense to do so. Hopefully we'll
7475 have view pair support built into loclists before we ever
7476 need to address all these possibilities. */
7477 if (adjacent_view_loclists
&& vnext
7478 && vnext
!= start
&& vstart
!= next
)
7480 adjacent_view_loclists
= 0;
7481 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7484 if (vnext
&& vnext
== start
)
7485 display_view_pair_list (section
, &start
, i
, vstart
);
7489 if (start
< section
->start
+ section
->size
)
7490 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7491 "There are %ld unused bytes at the end of section %s\n",
7492 (long) (section
->start
+ section
->size
- start
)),
7493 (long) (section
->start
+ section
->size
- start
), section
->name
);
7500 display_debug_str (struct dwarf_section
*section
,
7501 void *file ATTRIBUTE_UNUSED
)
7503 unsigned char *start
= section
->start
;
7504 uint64_t bytes
= section
->size
;
7505 uint64_t addr
= section
->address
;
7509 printf (_("\nThe %s section is empty.\n"), section
->name
);
7513 introduce (section
, false);
7521 lbytes
= (bytes
> 16 ? 16 : bytes
);
7523 printf (" 0x%8.8" PRIx64
" ", addr
);
7525 for (j
= 0; j
< 16; j
++)
7528 printf ("%2.2x", start
[j
]);
7536 for (j
= 0; j
< lbytes
; j
++)
7539 if (k
>= ' ' && k
< 0x80)
7558 display_debug_info (struct dwarf_section
*section
, void *file
)
7560 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7564 display_debug_types (struct dwarf_section
*section
, void *file
)
7566 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7570 display_trace_info (struct dwarf_section
*section
, void *file
)
7572 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7576 display_debug_aranges (struct dwarf_section
*section
,
7577 void *file ATTRIBUTE_UNUSED
)
7579 unsigned char *start
= section
->start
;
7580 unsigned char *end
= start
+ section
->size
;
7582 introduce (section
, false);
7584 /* It does not matter if this load fails,
7585 we test for that later on. */
7586 load_debug_info (file
);
7590 unsigned char *hdrptr
;
7591 DWARF2_Internal_ARange arange
;
7592 unsigned char *addr_ranges
;
7596 unsigned char address_size
;
7597 unsigned int offset_size
;
7598 unsigned char *end_ranges
;
7601 sec_off
= hdrptr
- section
->start
;
7603 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7604 if (arange
.ar_length
== 0xffffffff)
7606 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7612 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7614 warn (_("Debug info is corrupted, %s header at %#" PRIx64
7615 " has length %#" PRIx64
"\n"),
7616 section
->name
, sec_off
, arange
.ar_length
);
7619 end_ranges
= hdrptr
+ arange
.ar_length
;
7621 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7622 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7625 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7626 && num_debug_info_entries
> 0
7627 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7628 warn (_(".debug_info offset of %#" PRIx64
7629 " in %s section does not point to a CU header.\n"),
7630 arange
.ar_info_offset
, section
->name
);
7632 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7633 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7635 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7637 /* PR 19872: A version number of 0 probably means that there is
7638 padding at the end of the .debug_aranges section. Gold puts
7639 it there when performing an incremental link, for example.
7640 So do not generate a warning in this case. */
7641 if (arange
.ar_version
)
7642 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7646 printf (_(" Length: %" PRId64
"\n"), arange
.ar_length
);
7647 printf (_(" Version: %d\n"), arange
.ar_version
);
7648 printf (_(" Offset into .debug_info: %#" PRIx64
"\n"),
7649 arange
.ar_info_offset
);
7650 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7651 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7653 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7655 /* PR 17512: file: 001-108546-0.001:0.1. */
7656 if (address_size
== 0 || address_size
> 8)
7658 error (_("Invalid address size in %s section!\n"),
7663 /* The DWARF spec does not require that the address size be a power
7664 of two, but we do. This will have to change if we ever encounter
7665 an uneven architecture. */
7666 if ((address_size
& (address_size
- 1)) != 0)
7668 warn (_("Pointer size + Segment size is not a power of two.\n"));
7672 if (address_size
> 4)
7673 printf (_("\n Address Length\n"));
7675 printf (_("\n Address Length\n"));
7677 addr_ranges
= hdrptr
;
7679 /* Must pad to an alignment boundary that is twice the address size. */
7680 addr_ranges
+= (2 * address_size
- 1
7681 - (hdrptr
- start
- 1) % (2 * address_size
));
7683 while (2 * address_size
<= end_ranges
- addr_ranges
)
7685 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7687 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7690 print_hex (address
, address_size
);
7691 print_hex_ns (length
, address_size
);
7703 /* Comparison function for qsort. */
7705 comp_addr_base (const void * v0
, const void * v1
)
7707 debug_info
*info0
= *(debug_info
**) v0
;
7708 debug_info
*info1
= *(debug_info
**) v1
;
7709 return info0
->addr_base
- info1
->addr_base
;
7712 /* Display the debug_addr section. */
7714 display_debug_addr (struct dwarf_section
*section
,
7717 debug_info
**debug_addr_info
;
7718 unsigned char *entry
;
7722 unsigned char * header
;
7724 if (section
->size
== 0)
7726 printf (_("\nThe %s section is empty.\n"), section
->name
);
7730 if (load_debug_info (file
) == 0)
7732 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7737 introduce (section
, false);
7739 /* PR 17531: file: cf38d01b.
7740 We use xcalloc because a corrupt file may not have initialised all of the
7741 fields in the debug_info structure, which means that the sort below might
7742 try to move uninitialised data. */
7743 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7744 sizeof (debug_info
*));
7747 for (i
= 0; i
< num_debug_info_entries
; i
++)
7748 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7750 /* PR 17531: file: cf38d01b. */
7751 if (debug_information
[i
].addr_base
>= section
->size
)
7752 warn (_("Corrupt address base (%#" PRIx64
")"
7753 " found in debug section %u\n"),
7754 debug_information
[i
].addr_base
, i
);
7756 debug_addr_info
[count
++] = debug_information
+ i
;
7759 /* Add a sentinel to make iteration convenient. */
7760 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7761 debug_addr_info
[count
]->addr_base
= section
->size
;
7762 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7764 header
= section
->start
;
7765 for (i
= 0; i
< count
; i
++)
7768 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7770 printf (_(" For compilation unit at offset %#" PRIx64
":\n"),
7771 debug_addr_info
[i
]->cu_offset
);
7773 printf (_("\tIndex\tAddress\n"));
7774 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7775 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7777 size_t header_size
= entry
- header
;
7778 unsigned char *curr_header
= header
;
7781 int segment_selector_size
;
7783 if (header_size
!= 8 && header_size
!= 16)
7785 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %zd instead\n"),
7786 section
->name
, header_size
);
7790 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7791 if (length
== 0xffffffff)
7792 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7793 if (length
> (size_t) (section
->start
+ section
->size
- curr_header
)
7794 || length
< (size_t) (entry
- curr_header
))
7796 warn (_("Corrupt %s section: unit_length field of %#" PRIx64
7797 " is invalid\n"), section
->name
, length
);
7800 end
= curr_header
+ length
;
7801 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7803 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7804 section
->name
, version
);
7806 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7807 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7808 address_size
+= segment_selector_size
;
7811 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7816 if (address_size
< 1 || address_size
> sizeof (uint64_t))
7818 warn (_("Corrupt %s section: address size (%x) is wrong"),
7819 section
->name
, address_size
);
7823 while ((size_t) (end
- entry
) >= address_size
)
7825 uint64_t base
= byte_get (entry
, address_size
);
7826 printf (_("\t%d:\t"), idx
);
7827 print_hex_ns (base
, address_size
);
7829 entry
+= address_size
;
7835 free (debug_addr_info
);
7839 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7842 display_debug_str_offsets (struct dwarf_section
*section
,
7843 void *file ATTRIBUTE_UNUSED
)
7847 if (section
->size
== 0)
7849 printf (_("\nThe %s section is empty.\n"), section
->name
);
7853 unsigned char *start
= section
->start
;
7854 unsigned char *end
= start
+ section
->size
;
7855 unsigned char *curr
= start
;
7856 uint64_t debug_str_offsets_hdr_len
;
7858 const char *suffix
= strrchr (section
->name
, '.');
7859 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7862 load_debug_section_with_follow (str_dwo
, file
);
7864 load_debug_section_with_follow (str
, file
);
7866 introduce (section
, false);
7871 uint64_t entry_length
;
7873 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7874 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7875 if (length
== 0xffffffff)
7877 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7879 debug_str_offsets_hdr_len
= 16;
7884 debug_str_offsets_hdr_len
= 8;
7887 unsigned char *entries_end
;
7890 /* This is probably an old style .debug_str_offset section which
7891 just contains offsets and no header (and the first offset is 0). */
7892 length
= section
->size
;
7893 curr
= section
->start
;
7896 printf (_(" Length: %#" PRIx64
"\n"), length
);
7897 printf (_(" Index Offset [String]\n"));
7901 if (length
<= (size_t) (end
- curr
))
7902 entries_end
= curr
+ length
;
7905 warn (_("Section %s is too small %#" PRIx64
"\n"),
7906 section
->name
, section
->size
);
7911 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7913 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7916 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7918 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7920 printf (_(" Length: %#" PRIx64
"\n"), length
);
7921 printf (_(" Version: %#x\n"), version
);
7922 printf (_(" Index Offset [String]\n"));
7925 for (idx
= 0; curr
< entries_end
; idx
++)
7928 const unsigned char * string
;
7930 if ((size_t) (entries_end
- curr
) < entry_length
)
7931 /* Not enough space to read one entry_length, give up. */
7934 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7936 string
= (const unsigned char *)
7937 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7939 string
= fetch_indirect_string (offset
);
7941 printf (" %8lu ", idx
);
7942 print_hex (offset
, entry_length
);
7943 printf (" %s\n", string
);
7950 /* Each debug_information[x].range_lists[y] gets this representation for
7951 sorting purposes. */
7955 /* The debug_information[x].range_lists[y] value. */
7956 uint64_t ranges_offset
;
7958 /* Original debug_information to find parameters of the data. */
7959 debug_info
*debug_info_p
;
7962 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7965 range_entry_compar (const void *ap
, const void *bp
)
7967 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7968 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7969 const uint64_t a
= a_re
->ranges_offset
;
7970 const uint64_t b
= b_re
->ranges_offset
;
7972 return (a
> b
) - (b
> a
);
7976 display_debug_ranges_list (unsigned char * start
,
7977 unsigned char * finish
,
7978 unsigned int pointer_size
,
7980 uint64_t base_address
)
7982 while (start
< finish
)
7987 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7988 if (start
>= finish
)
7990 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7993 print_hex (offset
, 4);
7995 if (begin
== 0 && end
== 0)
7997 printf (_("<End of list>\n"));
8001 /* Check base address specifiers. */
8002 if (is_max_address (begin
, pointer_size
)
8003 && !is_max_address (end
, pointer_size
))
8006 print_hex (begin
, pointer_size
);
8007 print_hex (end
, pointer_size
);
8008 printf ("(base address)\n");
8012 print_hex (begin
+ base_address
, pointer_size
);
8013 print_hex_ns (end
+ base_address
, pointer_size
);
8016 fputs (_(" (start == end)"), stdout
);
8017 else if (begin
> end
)
8018 fputs (_(" (start > end)"), stdout
);
8024 static unsigned char *
8025 display_debug_rnglists_list (unsigned char * start
,
8026 unsigned char * finish
,
8027 unsigned int pointer_size
,
8029 uint64_t base_address
,
8030 unsigned int offset_size
)
8032 unsigned char *next
= start
;
8033 unsigned int debug_addr_section_hdr_len
;
8035 if (offset_size
== 4)
8036 debug_addr_section_hdr_len
= 8;
8038 debug_addr_section_hdr_len
= 16;
8042 uint64_t off
= offset
+ (start
- next
);
8043 enum dwarf_range_list_entry rlet
;
8044 /* Initialize it due to a false compiler warning. */
8045 uint64_t begin
= -1, length
, end
= -1;
8047 if (start
>= finish
)
8049 warn (_("Range list starting at offset %#" PRIx64
8050 " is not terminated.\n"), offset
);
8057 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8061 case DW_RLE_end_of_list
:
8062 printf (_("<End of list>\n"));
8064 case DW_RLE_base_addressx
:
8065 READ_ULEB (base_address
, start
, finish
);
8066 print_hex (base_address
, pointer_size
);
8067 printf (_("(base address index) "));
8068 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8069 + debug_addr_section_hdr_len
, pointer_size
);
8070 print_hex (base_address
, pointer_size
);
8071 printf (_("(base address)\n"));
8073 case DW_RLE_startx_endx
:
8074 READ_ULEB (begin
, start
, finish
);
8075 READ_ULEB (end
, start
, finish
);
8076 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8077 + debug_addr_section_hdr_len
, pointer_size
);
8078 end
= fetch_indexed_addr ((begin
* pointer_size
)
8079 + debug_addr_section_hdr_len
, pointer_size
);
8081 case DW_RLE_startx_length
:
8082 READ_ULEB (begin
, start
, finish
);
8083 READ_ULEB (length
, start
, finish
);
8084 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8085 + debug_addr_section_hdr_len
, pointer_size
);
8086 end
= begin
+ length
;
8088 case DW_RLE_offset_pair
:
8089 READ_ULEB (begin
, start
, finish
);
8090 READ_ULEB (end
, start
, finish
);
8092 case DW_RLE_base_address
:
8093 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8094 print_hex (base_address
, pointer_size
);
8095 printf (_("(base address)\n"));
8097 case DW_RLE_start_end
:
8098 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8099 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8101 case DW_RLE_start_length
:
8102 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8103 READ_ULEB (length
, start
, finish
);
8104 end
= begin
+ length
;
8107 error (_("Invalid range list entry type %d\n"), rlet
);
8108 rlet
= DW_RLE_end_of_list
;
8112 if (rlet
== DW_RLE_end_of_list
)
8114 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8117 /* Only a DW_RLE_offset_pair needs the base address added. */
8118 if (rlet
== DW_RLE_offset_pair
)
8120 begin
+= base_address
;
8121 end
+= base_address
;
8124 print_hex (begin
, pointer_size
);
8125 print_hex (end
, pointer_size
);
8128 fputs (_(" (start == end)"), stdout
);
8129 else if (begin
> end
)
8130 fputs (_(" (start > end)"), stdout
);
8139 display_debug_rnglists (struct dwarf_section
*section
)
8141 unsigned char *start
= section
->start
;
8142 unsigned char *finish
= start
+ section
->size
;
8144 while (start
< finish
)
8146 unsigned char *table_start
;
8147 uint64_t offset
= start
- section
->start
;
8149 uint64_t initial_length
;
8150 unsigned char segment_selector_size
;
8151 unsigned int offset_entry_count
;
8153 unsigned short version
;
8154 unsigned char address_size
= 0;
8155 unsigned char offset_size
;
8157 /* Get and check the length of the block. */
8158 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8160 if (initial_length
== 0xffffffff)
8162 /* This section is 64-bit DWARF 3. */
8163 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8169 if (initial_length
> (size_t) (finish
- start
))
8171 /* If the length field has a relocation against it, then we should
8172 not complain if it is inaccurate (and probably negative).
8173 It is copied from .debug_line handling code. */
8174 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8175 initial_length
= finish
- start
;
8178 warn (_("The length field (%#" PRIx64
8179 ") in the debug_rnglists header is wrong"
8180 " - the section is too small\n"),
8186 end
= start
+ initial_length
;
8188 /* Get the other fields in the header. */
8189 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8190 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8191 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8192 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8194 printf (_(" Table at Offset: %#" PRIx64
":\n"), offset
);
8195 printf (_(" Length: %#" PRIx64
"\n"), initial_length
);
8196 printf (_(" DWARF version: %u\n"), version
);
8197 printf (_(" Address size: %u\n"), address_size
);
8198 printf (_(" Segment size: %u\n"), segment_selector_size
);
8199 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8201 /* Check the fields. */
8202 if (segment_selector_size
!= 0)
8204 warn (_("The %s section contains "
8205 "unsupported segment selector size: %d.\n"),
8206 section
->name
, segment_selector_size
);
8212 warn (_("Only DWARF version 5+ debug_rnglists info "
8213 "is currently supported.\n"));
8217 table_start
= start
;
8219 if (offset_entry_count
!= 0)
8221 printf (_("\n Offsets starting at %#tx:\n"),
8222 start
- section
->start
);
8224 for (i
= 0; i
< offset_entry_count
; i
++)
8228 SAFE_BYTE_GET_AND_INC (entry
, start
, offset_size
, finish
);
8229 printf (_(" [%6u] %#" PRIx64
"\n"), i
, entry
);
8233 offset_entry_count
= 1;
8235 for (i
= 0; i
< offset_entry_count
; i
++)
8237 uint64_t indx
= start
- table_start
;
8239 offset
= start
- section
->start
;
8240 printf (_("\n Offset: %#" PRIx64
", Index: %#" PRIx64
"\n"),
8242 printf (_(" Offset Begin End\n"));
8243 start
= display_debug_rnglists_list
8244 (start
, end
, address_size
, offset
, 0, offset_size
);
8260 display_debug_ranges (struct dwarf_section
*section
,
8261 void *file ATTRIBUTE_UNUSED
)
8263 unsigned char *start
= section
->start
;
8264 unsigned char *last_start
= start
;
8265 uint64_t bytes
= section
->size
;
8266 unsigned char *section_begin
= start
;
8267 unsigned char *finish
= start
+ bytes
;
8268 unsigned int num_range_list
, i
;
8269 struct range_entry
*range_entries
;
8270 struct range_entry
*range_entry_fill
;
8271 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8272 /* Initialize it due to a false compiler warning. */
8273 unsigned char address_size
= 0;
8274 uint64_t last_offset
= 0;
8278 printf (_("\nThe %s section is empty.\n"), section
->name
);
8282 introduce (section
, false);
8285 return display_debug_rnglists (section
);
8287 if (load_debug_info (file
) == 0)
8289 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8295 for (i
= 0; i
< num_debug_info_entries
; i
++)
8296 num_range_list
+= debug_information
[i
].num_range_lists
;
8298 if (num_range_list
== 0)
8300 /* This can happen when the file was compiled with -gsplit-debug
8301 which removes references to range lists from the primary .o file. */
8302 printf (_("No range lists in .debug_info section.\n"));
8306 range_entries
= (struct range_entry
*)
8307 xmalloc (sizeof (*range_entries
) * num_range_list
);
8308 range_entry_fill
= range_entries
;
8310 for (i
= 0; i
< num_debug_info_entries
; i
++)
8312 debug_info
*debug_info_p
= &debug_information
[i
];
8315 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8317 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8318 range_entry_fill
->debug_info_p
= debug_info_p
;
8323 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8324 range_entry_compar
);
8326 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8327 warn (_("Range lists in %s section start at %#" PRIx64
"\n"),
8328 section
->name
, range_entries
[0].ranges_offset
);
8331 printf (_(" Offset Begin End\n"));
8333 for (i
= 0; i
< num_range_list
; i
++)
8335 struct range_entry
*range_entry
= &range_entries
[i
];
8336 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8337 unsigned int pointer_size
;
8339 unsigned char *next
;
8340 uint64_t base_address
;
8342 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8343 offset
= range_entry
->ranges_offset
;
8344 base_address
= debug_info_p
->base_address
;
8346 /* PR 17512: file: 001-101485-0.001:0.1. */
8347 if (pointer_size
< 2 || pointer_size
> 8)
8349 warn (_("Corrupt pointer size (%d) in debug entry at offset %#" PRIx64
"\n"),
8350 pointer_size
, offset
);
8354 if (offset
> (size_t) (finish
- section_begin
))
8356 warn (_("Corrupt offset (%#" PRIx64
") in range entry %u\n"),
8361 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8363 /* If multiple DWARF entities reference the same range then we will
8364 have multiple entries in the `range_entries' list for the same
8365 offset. Thanks to the sort above these will all be consecutive in
8366 the `range_entries' list, so we can easily ignore duplicates
8368 if (i
> 0 && last_offset
== offset
)
8370 last_offset
= offset
;
8372 if (dwarf_check
!= 0 && i
> 0)
8375 warn (_("There is a hole [%#tx - %#tx] in %s section.\n"),
8376 start
- section_begin
, next
- section_begin
, section
->name
);
8377 else if (start
> next
)
8379 if (next
== last_start
)
8381 warn (_("There is an overlap [%#tx - %#tx] in %s section.\n"),
8382 start
- section_begin
, next
- section_begin
, section
->name
);
8389 display_debug_ranges_list
8390 (start
, finish
, pointer_size
, offset
, base_address
);
8394 free (range_entries
);
8399 typedef struct Frame_Chunk
8401 struct Frame_Chunk
*next
;
8402 unsigned char *chunk_start
;
8404 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8405 short int *col_type
;
8406 int64_t *col_offset
;
8408 unsigned int code_factor
;
8412 unsigned int cfa_reg
;
8413 uint64_t cfa_offset
;
8415 unsigned char fde_encoding
;
8416 unsigned char cfa_exp
;
8417 unsigned char ptr_size
;
8418 unsigned char segment_size
;
8422 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8423 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8424 static const char *const *dwarf_regnames
;
8425 static unsigned int dwarf_regnames_count
;
8426 static bool is_aarch64
;
8428 /* A marker for a col_type that means this column was never referenced
8429 in the frame info. */
8430 #define DW_CFA_unreferenced (-1)
8432 /* Return 0 if no more space is needed, 1 if more space is needed,
8433 -1 for invalid reg. */
8436 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8438 unsigned int prev
= fc
->ncols
;
8440 if (reg
< (unsigned int) fc
->ncols
)
8443 if (dwarf_regnames_count
> 0
8444 && reg
> dwarf_regnames_count
)
8447 fc
->ncols
= reg
+ 1;
8448 /* PR 17512: file: 10450-2643-0.004.
8449 If reg == -1 then this can happen... */
8453 /* PR 17512: file: 2844a11d. */
8454 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8456 error (_("Unfeasibly large register number: %u\n"), reg
);
8458 /* FIXME: 1024 is an arbitrary limit. Increase it if
8459 we ever encounter a valid binary that exceeds it. */
8463 fc
->col_type
= xcrealloc (fc
->col_type
, fc
->ncols
,
8464 sizeof (*fc
->col_type
));
8465 fc
->col_offset
= xcrealloc (fc
->col_offset
, fc
->ncols
,
8466 sizeof (*fc
->col_offset
));
8467 /* PR 17512: file:002-10025-0.005. */
8468 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8470 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8476 while (prev
< fc
->ncols
)
8478 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8479 fc
->col_offset
[prev
] = 0;
8485 static const char *const dwarf_regnames_i386
[] =
8487 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8488 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8489 "eip", "eflags", NULL
, /* 8 - 10 */
8490 "st0", "st1", "st2", "st3", /* 11 - 14 */
8491 "st4", "st5", "st6", "st7", /* 15 - 18 */
8492 NULL
, NULL
, /* 19 - 20 */
8493 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8494 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8495 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8496 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8497 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8498 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8499 "tr", "ldtr", /* 48 - 49 */
8500 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8501 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8502 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8503 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8504 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8505 NULL
, NULL
, NULL
, /* 90 - 92 */
8506 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8509 static const char *const dwarf_regnames_iamcu
[] =
8511 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8512 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8513 "eip", "eflags", NULL
, /* 8 - 10 */
8514 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8515 NULL
, NULL
, /* 19 - 20 */
8516 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8517 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8518 NULL
, NULL
, NULL
, /* 37 - 39 */
8519 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8520 "tr", "ldtr", /* 48 - 49 */
8521 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8522 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8523 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8524 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8525 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8526 NULL
, NULL
, NULL
, /* 90 - 92 */
8527 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8531 init_dwarf_regnames_i386 (void)
8533 dwarf_regnames
= dwarf_regnames_i386
;
8534 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8535 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8539 init_dwarf_regnames_iamcu (void)
8541 dwarf_regnames
= dwarf_regnames_iamcu
;
8542 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8543 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8546 static const char *const DW_CFA_GNU_window_save_name
[] =
8548 "DW_CFA_GNU_window_save",
8549 "DW_CFA_AARCH64_negate_ra_state"
8552 static const char *const dwarf_regnames_x86_64
[] =
8554 "rax", "rdx", "rcx", "rbx",
8555 "rsi", "rdi", "rbp", "rsp",
8556 "r8", "r9", "r10", "r11",
8557 "r12", "r13", "r14", "r15",
8559 "xmm0", "xmm1", "xmm2", "xmm3",
8560 "xmm4", "xmm5", "xmm6", "xmm7",
8561 "xmm8", "xmm9", "xmm10", "xmm11",
8562 "xmm12", "xmm13", "xmm14", "xmm15",
8563 "st0", "st1", "st2", "st3",
8564 "st4", "st5", "st6", "st7",
8565 "mm0", "mm1", "mm2", "mm3",
8566 "mm4", "mm5", "mm6", "mm7",
8568 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8569 "fs.base", "gs.base", NULL
, NULL
,
8571 "mxcsr", "fcw", "fsw",
8572 "xmm16", "xmm17", "xmm18", "xmm19",
8573 "xmm20", "xmm21", "xmm22", "xmm23",
8574 "xmm24", "xmm25", "xmm26", "xmm27",
8575 "xmm28", "xmm29", "xmm30", "xmm31",
8576 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8577 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8578 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8579 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8580 NULL
, NULL
, NULL
, /* 115 - 117 */
8581 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8585 init_dwarf_regnames_x86_64 (void)
8587 dwarf_regnames
= dwarf_regnames_x86_64
;
8588 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8589 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8592 static const char *const dwarf_regnames_aarch64
[] =
8594 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8595 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8596 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8597 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8598 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8599 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8600 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8601 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8602 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8603 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8604 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8605 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8606 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8607 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8608 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8609 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8613 init_dwarf_regnames_aarch64 (void)
8615 dwarf_regnames
= dwarf_regnames_aarch64
;
8616 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8617 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8621 static const char *const dwarf_regnames_s390
[] =
8623 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8624 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8625 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8626 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8627 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8628 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8629 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8630 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8631 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8634 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8635 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8639 init_dwarf_regnames_s390 (void)
8641 dwarf_regnames
= dwarf_regnames_s390
;
8642 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8643 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8646 static const char *const dwarf_regnames_riscv
[] =
8648 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8649 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8650 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8651 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8652 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8653 "fs0", "fs1", /* 40 - 41 */
8654 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8655 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8656 "fs10", "fs11", /* 58 - 59 */
8657 "ft8", "ft9", "ft10", "ft11", /* 60 - 63 */
8658 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 64 - 71 */
8659 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 72 - 79 */
8660 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 80 - 87 */
8661 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 88 - 95 */
8662 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", /* 96 - 103 */
8663 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", /* 104 - 111 */
8664 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", /* 112 - 119 */
8665 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", /* 120 - 127 */
8668 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8669 the large number of CSRs. */
8672 regname_internal_riscv (unsigned int regno
)
8674 const char *name
= NULL
;
8676 /* Lookup in the table first, this covers GPR and FPR. */
8677 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8678 name
= dwarf_regnames_riscv
[regno
];
8679 else if (regno
>= 4096 && regno
<= 8191)
8681 /* This might be a CSR, these live in a sparse number space from 4096
8682 to 8191 These numbers are defined in the RISC-V ELF ABI
8686 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8687 case VALUE + 4096: name = #NAME; break;
8688 #include "opcode/riscv-opc.h"
8693 static char csr_name
[10];
8694 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8705 init_dwarf_regnames_riscv (void)
8707 dwarf_regnames
= NULL
;
8708 dwarf_regnames_count
= 8192;
8709 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8713 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8715 dwarf_regnames_lookup_func
= NULL
;
8721 init_dwarf_regnames_i386 ();
8725 init_dwarf_regnames_iamcu ();
8731 init_dwarf_regnames_x86_64 ();
8735 init_dwarf_regnames_aarch64 ();
8739 init_dwarf_regnames_s390 ();
8743 init_dwarf_regnames_riscv ();
8751 /* Initialize the DWARF register name lookup state based on the
8752 architecture and specific machine type of a BFD. */
8755 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8758 dwarf_regnames_lookup_func
= NULL
;
8766 case bfd_mach_x86_64
:
8767 case bfd_mach_x86_64_intel_syntax
:
8768 case bfd_mach_x64_32
:
8769 case bfd_mach_x64_32_intel_syntax
:
8770 init_dwarf_regnames_x86_64 ();
8774 init_dwarf_regnames_i386 ();
8779 case bfd_arch_iamcu
:
8780 init_dwarf_regnames_iamcu ();
8783 case bfd_arch_aarch64
:
8784 init_dwarf_regnames_aarch64();
8788 init_dwarf_regnames_s390 ();
8791 case bfd_arch_riscv
:
8792 init_dwarf_regnames_riscv ();
8801 regname_internal_by_table_only (unsigned int regno
)
8803 if (dwarf_regnames
!= NULL
8804 && regno
< dwarf_regnames_count
8805 && dwarf_regnames
[regno
] != NULL
)
8806 return dwarf_regnames
[regno
];
8812 regname (unsigned int regno
, int name_only_p
)
8814 static char reg
[64];
8816 const char *name
= NULL
;
8818 if (dwarf_regnames_lookup_func
!= NULL
)
8819 name
= dwarf_regnames_lookup_func (regno
);
8825 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8828 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8833 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8838 if (*max_regs
!= fc
->ncols
)
8839 *max_regs
= fc
->ncols
;
8841 if (*need_col_headers
)
8843 *need_col_headers
= 0;
8845 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8847 for (r
= 0; r
< *max_regs
; r
++)
8848 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8853 printf ("%-5s ", regname (r
, 1));
8859 print_hex (fc
->pc_begin
, eh_addr_size
);
8861 strcpy (tmp
, "exp");
8863 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8864 printf ("%-8s ", tmp
);
8866 for (r
= 0; r
< fc
->ncols
; r
++)
8868 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8870 switch (fc
->col_type
[r
])
8872 case DW_CFA_undefined
:
8875 case DW_CFA_same_value
:
8879 sprintf (tmp
, "c%+" PRId64
, fc
->col_offset
[r
]);
8881 case DW_CFA_val_offset
:
8882 sprintf (tmp
, "v%+" PRId64
, fc
->col_offset
[r
]);
8884 case DW_CFA_register
:
8885 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8887 case DW_CFA_expression
:
8888 strcpy (tmp
, "exp");
8890 case DW_CFA_val_expression
:
8891 strcpy (tmp
, "vexp");
8894 strcpy (tmp
, "n/a");
8897 printf ("%-5s ", tmp
);
8903 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8905 static unsigned char *
8906 read_cie (unsigned char *start
, unsigned char *end
,
8907 Frame_Chunk
**p_cie
, int *p_version
,
8908 uint64_t *p_aug_len
, unsigned char **p_aug
)
8912 unsigned char *augmentation_data
= NULL
;
8913 uint64_t augmentation_data_len
= 0;
8916 /* PR 17512: file: 001-228113-0.004. */
8920 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8921 memset (fc
, 0, sizeof (Frame_Chunk
));
8923 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
8924 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
8928 fc
->augmentation
= (char *) start
;
8929 /* PR 17512: file: 001-228113-0.004.
8930 Skip past augmentation name, but avoid running off the end of the data. */
8932 if (* start
++ == '\0')
8936 warn (_("No terminator for augmentation name\n"));
8940 if (strcmp (fc
->augmentation
, "eh") == 0)
8942 if (eh_addr_size
> (size_t) (end
- start
))
8944 start
+= eh_addr_size
;
8949 if (2 > (size_t) (end
- start
))
8951 GET (fc
->ptr_size
, 1);
8952 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8954 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8958 GET (fc
->segment_size
, 1);
8959 /* PR 17512: file: e99d2804. */
8960 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8962 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8966 eh_addr_size
= fc
->ptr_size
;
8970 fc
->ptr_size
= eh_addr_size
;
8971 fc
->segment_size
= 0;
8974 READ_ULEB (fc
->code_factor
, start
, end
);
8975 READ_SLEB (fc
->data_factor
, start
, end
);
8986 READ_ULEB (fc
->ra
, start
, end
);
8989 if (fc
->augmentation
[0] == 'z')
8993 READ_ULEB (augmentation_data_len
, start
, end
);
8994 augmentation_data
= start
;
8995 /* PR 17512: file: 11042-2589-0.004. */
8996 if (augmentation_data_len
> (size_t) (end
- start
))
8998 warn (_("Augmentation data too long: %#" PRIx64
8999 ", expected at most %#tx\n"),
9000 augmentation_data_len
, end
- start
);
9003 start
+= augmentation_data_len
;
9006 if (augmentation_data_len
)
9010 unsigned char *qend
;
9012 p
= (unsigned char *) fc
->augmentation
+ 1;
9013 q
= augmentation_data
;
9014 qend
= q
+ augmentation_data_len
;
9016 while (p
< end
&& q
< qend
)
9021 q
+= 1 + size_of_encoded_value (*q
);
9023 fc
->fde_encoding
= *q
++;
9032 /* Note - it is OK if this loop terminates with q < qend.
9033 Padding may have been inserted to align the end of the CIE. */
9038 *p_version
= version
;
9041 *p_aug_len
= augmentation_data_len
;
9042 *p_aug
= augmentation_data
;
9047 free (fc
->col_offset
);
9048 free (fc
->col_type
);
9053 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9054 If do_wide is not enabled, then formats the output to fit into 80 columns.
9055 PRINTED contains the number of characters already written to the current
9059 display_data (size_t printed
, const unsigned char *data
, size_t len
)
9061 if (do_wide
|| len
< ((80 - printed
) / 3))
9062 for (printed
= 0; printed
< len
; ++printed
)
9063 printf (" %02x", data
[printed
]);
9066 for (printed
= 0; printed
< len
; ++printed
)
9068 if (printed
% (80 / 3) == 0)
9070 printf (" %02x", data
[printed
]);
9075 /* Prints out the contents on the augmentation data array.
9076 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9079 display_augmentation_data (const unsigned char * data
, uint64_t len
)
9083 i
= printf (_(" Augmentation data: "));
9084 display_data (i
, data
, len
);
9088 display_debug_frames (struct dwarf_section
*section
,
9089 void *file ATTRIBUTE_UNUSED
)
9091 unsigned char *start
= section
->start
;
9092 unsigned char *end
= start
+ section
->size
;
9093 unsigned char *section_start
= start
;
9094 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9095 Frame_Chunk
*remembered_state
= NULL
;
9097 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9098 unsigned int max_regs
= 0;
9099 const char *bad_reg
= _("bad register: ");
9100 unsigned int saved_eh_addr_size
= eh_addr_size
;
9102 introduce (section
, false);
9106 unsigned char *saved_start
;
9107 unsigned char *block_end
;
9112 int need_col_headers
= 1;
9113 unsigned char *augmentation_data
= NULL
;
9114 uint64_t augmentation_data_len
= 0;
9115 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9116 unsigned int offset_size
;
9118 static Frame_Chunk fde_fc
;
9120 saved_start
= start
;
9122 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9126 printf ("\n%08tx ZERO terminator\n\n",
9127 saved_start
- section_start
);
9128 /* Skip any zero terminators that directly follow.
9129 A corrupt section size could have loaded a whole
9130 slew of zero filled memory bytes. eg
9131 PR 17512: file: 070-19381-0.004. */
9132 while (start
< end
&& * start
== 0)
9137 if (length
== 0xffffffff)
9139 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9145 if (length
> (size_t) (end
- start
))
9147 warn ("Invalid length %#" PRIx64
" in FDE at %#tx\n",
9148 length
, saved_start
- section_start
);
9152 block_end
= start
+ length
;
9154 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9156 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9157 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9162 start
= read_cie (start
, block_end
, &cie
, &version
,
9163 &augmentation_data_len
, &augmentation_data
);
9164 /* PR 17512: file: 027-135133-0.005. */
9171 fc
->chunk_start
= saved_start
;
9172 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9175 if (frame_need_space (fc
, mreg
) < 0)
9177 if (fc
->fde_encoding
)
9178 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9180 printf ("\n%08tx ", saved_start
- section_start
);
9181 print_hex (length
, fc
->ptr_size
);
9182 print_hex (cie_id
, offset_size
);
9184 if (do_debug_frames_interp
)
9186 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9187 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9192 printf (" Version: %d\n", version
);
9193 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9196 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9197 printf (" Segment Size: %u\n", fc
->segment_size
);
9199 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9200 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9201 printf (" Return address column: %d\n", fc
->ra
);
9203 if (augmentation_data_len
)
9204 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9211 unsigned char *look_for
;
9212 unsigned long segment_selector
;
9218 uint64_t sign
= (uint64_t) 1 << (offset_size
* 8 - 1);
9219 cie_off
= (cie_off
^ sign
) - sign
;
9220 cie_off
= start
- 4 - section_start
- cie_off
;
9223 look_for
= section_start
+ cie_off
;
9224 if (cie_off
<= (size_t) (saved_start
- section_start
))
9226 for (cie
= chunks
; cie
; cie
= cie
->next
)
9227 if (cie
->chunk_start
== look_for
)
9230 else if (cie_off
>= section
->size
)
9234 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9235 if (cie
->chunk_start
== look_for
)
9239 unsigned int off_size
;
9240 unsigned char *cie_scan
;
9242 cie_scan
= look_for
;
9244 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9245 if (length
== 0xffffffff)
9247 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9250 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9253 unsigned char *cie_end
= cie_scan
+ length
;
9255 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9259 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9260 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9265 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9266 &augmentation_data_len
, &augmentation_data
);
9267 /* PR 17512: file: 3450-2098-0.004. */
9270 warn (_("Failed to read CIE information\n"));
9273 cie
->next
= forward_refs
;
9275 cie
->chunk_start
= look_for
;
9276 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9279 if (frame_need_space (cie
, mreg
) < 0)
9281 warn (_("Invalid max register\n"));
9284 if (cie
->fde_encoding
)
9286 = size_of_encoded_value (cie
->fde_encoding
);
9293 memset (fc
, 0, sizeof (Frame_Chunk
));
9298 fc
->col_type
= xmalloc (sizeof (*fc
->col_type
));
9299 fc
->col_offset
= xmalloc (sizeof (*fc
->col_offset
));
9300 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9302 warn (_("Invalid max register\n"));
9306 fc
->augmentation
= "";
9307 fc
->fde_encoding
= 0;
9308 fc
->ptr_size
= eh_addr_size
;
9309 fc
->segment_size
= 0;
9313 fc
->ncols
= cie
->ncols
;
9314 fc
->col_type
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_type
));
9315 fc
->col_offset
= xcmalloc (fc
->ncols
, sizeof (*fc
->col_offset
));
9316 memcpy (fc
->col_type
, cie
->col_type
,
9317 fc
->ncols
* sizeof (*fc
->col_type
));
9318 memcpy (fc
->col_offset
, cie
->col_offset
,
9319 fc
->ncols
* sizeof (*fc
->col_offset
));
9320 fc
->augmentation
= cie
->augmentation
;
9321 fc
->ptr_size
= cie
->ptr_size
;
9322 eh_addr_size
= cie
->ptr_size
;
9323 fc
->segment_size
= cie
->segment_size
;
9324 fc
->code_factor
= cie
->code_factor
;
9325 fc
->data_factor
= cie
->data_factor
;
9326 fc
->cfa_reg
= cie
->cfa_reg
;
9327 fc
->cfa_offset
= cie
->cfa_offset
;
9329 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9331 warn (_("Invalid max register\n"));
9334 fc
->fde_encoding
= cie
->fde_encoding
;
9337 if (fc
->fde_encoding
)
9338 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9340 segment_selector
= 0;
9341 if (fc
->segment_size
)
9343 if (fc
->segment_size
> sizeof (segment_selector
))
9345 /* PR 17512: file: 9e196b3e. */
9346 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9347 fc
->segment_size
= 4;
9349 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9350 fc
->segment_size
, block_end
);
9353 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9356 /* FIXME: It appears that sometimes the final pc_range value is
9357 encoded in less than encoded_ptr_size bytes. See the x86_64
9358 run of the "objcopy on compressed debug sections" test for an
9360 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9363 if (cie
->augmentation
[0] == 'z')
9365 READ_ULEB (augmentation_data_len
, start
, block_end
);
9366 augmentation_data
= start
;
9367 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9368 if (augmentation_data_len
> (size_t) (block_end
- start
))
9370 warn (_("Augmentation data too long: %#" PRIx64
", "
9371 "expected at most %#tx\n"),
9372 augmentation_data_len
, block_end
- start
);
9374 augmentation_data
= NULL
;
9375 augmentation_data_len
= 0;
9377 start
+= augmentation_data_len
;
9380 printf ("\n%08tx ", saved_start
- section_start
);
9381 print_hex (length
, fc
->ptr_size
);
9382 print_hex (cie_id
, offset_size
);
9385 if (cie
->chunk_start
)
9386 printf ("cie=%08tx", cie
->chunk_start
- section_start
);
9388 /* Ideally translate "invalid " to 8 chars, trailing space
9390 printf (_("cie=invalid "));
9393 if (fc
->segment_size
)
9394 printf ("%04lx:", segment_selector
);
9396 print_hex_ns (fc
->pc_begin
, fc
->ptr_size
);
9398 print_hex_ns (fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
);
9401 if (! do_debug_frames_interp
&& augmentation_data_len
)
9403 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9408 /* At this point, fc is the current chunk, cie (if any) is set, and
9409 we're about to interpret instructions for the chunk. */
9410 /* ??? At present we need to do this always, since this sizes the
9411 fc->col_type and fc->col_offset arrays, which we write into always.
9412 We should probably split the interpreted and non-interpreted bits
9413 into two different routines, since there's so much that doesn't
9414 really overlap between them. */
9415 if (1 || do_debug_frames_interp
)
9417 /* Start by making a pass over the chunk, allocating storage
9418 and taking note of what registers are used. */
9419 unsigned char *tmp
= start
;
9421 while (start
< block_end
)
9423 unsigned int reg
, op
, opa
;
9431 /* Warning: if you add any more cases to this switch, be
9432 sure to add them to the corresponding switch below. */
9436 case DW_CFA_advance_loc
:
9439 SKIP_ULEB (start
, block_end
);
9442 case DW_CFA_restore
:
9445 case DW_CFA_set_loc
:
9446 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9449 start
+= encoded_ptr_size
;
9451 case DW_CFA_advance_loc1
:
9452 if ((size_t) (block_end
- start
) < 1)
9457 case DW_CFA_advance_loc2
:
9458 if ((size_t) (block_end
- start
) < 2)
9463 case DW_CFA_advance_loc4
:
9464 if ((size_t) (block_end
- start
) < 4)
9469 case DW_CFA_offset_extended
:
9470 case DW_CFA_val_offset
:
9471 READ_ULEB (reg
, start
, block_end
);
9472 SKIP_ULEB (start
, block_end
);
9474 case DW_CFA_restore_extended
:
9475 READ_ULEB (reg
, start
, block_end
);
9477 case DW_CFA_undefined
:
9478 READ_ULEB (reg
, start
, block_end
);
9480 case DW_CFA_same_value
:
9481 READ_ULEB (reg
, start
, block_end
);
9483 case DW_CFA_register
:
9484 READ_ULEB (reg
, start
, block_end
);
9485 SKIP_ULEB (start
, block_end
);
9487 case DW_CFA_def_cfa
:
9488 SKIP_ULEB (start
, block_end
);
9489 SKIP_ULEB (start
, block_end
);
9491 case DW_CFA_def_cfa_register
:
9492 SKIP_ULEB (start
, block_end
);
9494 case DW_CFA_def_cfa_offset
:
9495 SKIP_ULEB (start
, block_end
);
9497 case DW_CFA_def_cfa_expression
:
9498 READ_ULEB (temp
, start
, block_end
);
9499 if ((size_t) (block_end
- start
) < temp
)
9504 case DW_CFA_expression
:
9505 case DW_CFA_val_expression
:
9506 READ_ULEB (reg
, start
, block_end
);
9507 READ_ULEB (temp
, start
, block_end
);
9508 if ((size_t) (block_end
- start
) < temp
)
9513 case DW_CFA_offset_extended_sf
:
9514 case DW_CFA_val_offset_sf
:
9515 READ_ULEB (reg
, start
, block_end
);
9516 SKIP_SLEB (start
, block_end
);
9518 case DW_CFA_def_cfa_sf
:
9519 SKIP_ULEB (start
, block_end
);
9520 SKIP_SLEB (start
, block_end
);
9522 case DW_CFA_def_cfa_offset_sf
:
9523 SKIP_SLEB (start
, block_end
);
9525 case DW_CFA_MIPS_advance_loc8
:
9526 if ((size_t) (block_end
- start
) < 8)
9531 case DW_CFA_GNU_args_size
:
9532 SKIP_ULEB (start
, block_end
);
9534 case DW_CFA_GNU_negative_offset_extended
:
9535 READ_ULEB (reg
, start
, block_end
);
9536 SKIP_ULEB (start
, block_end
);
9541 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9543 /* Don't leave any reg as DW_CFA_unreferenced so
9544 that frame_display_row prints name of regs in
9545 header, and all referenced regs in each line. */
9546 if (reg
>= cie
->ncols
9547 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9548 fc
->col_type
[reg
] = DW_CFA_undefined
;
9550 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9558 /* Now we know what registers are used, make a second pass over
9559 the chunk, this time actually printing out the info. */
9561 while (start
< block_end
)
9564 /* Note: It is tempting to use an unsigned long for 'reg' but there
9565 are various functions, notably frame_space_needed() that assume that
9566 reg is an unsigned int. */
9570 const char *reg_prefix
= "";
9577 /* Make a note if something other than DW_CFA_nop happens. */
9578 if (op
!= DW_CFA_nop
)
9581 /* Warning: if you add any more cases to this switch, be
9582 sure to add them to the corresponding switch above. */
9585 case DW_CFA_advance_loc
:
9586 opa
*= fc
->code_factor
;
9587 if (do_debug_frames_interp
)
9588 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9591 printf (" DW_CFA_advance_loc: %d to ", opa
);
9592 print_hex_ns (fc
->pc_begin
+ opa
, fc
->ptr_size
);
9595 fc
->pc_begin
+= opa
;
9599 READ_ULEB (ofs
, start
, block_end
);
9600 ofs
*= fc
->data_factor
;
9601 if (opa
>= fc
->ncols
)
9602 reg_prefix
= bad_reg
;
9603 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9604 printf (" DW_CFA_offset: %s%s at cfa%+" PRId64
"\n",
9605 reg_prefix
, regname (opa
, 0), ofs
);
9606 if (*reg_prefix
== '\0')
9608 fc
->col_type
[opa
] = DW_CFA_offset
;
9609 fc
->col_offset
[opa
] = ofs
;
9613 case DW_CFA_restore
:
9614 if (opa
>= fc
->ncols
)
9615 reg_prefix
= bad_reg
;
9616 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9617 printf (" DW_CFA_restore: %s%s\n",
9618 reg_prefix
, regname (opa
, 0));
9619 if (*reg_prefix
!= '\0')
9622 if (opa
>= cie
->ncols
9623 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9625 fc
->col_type
[opa
] = DW_CFA_undefined
;
9626 fc
->col_offset
[opa
] = 0;
9630 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9631 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9635 case DW_CFA_set_loc
:
9636 ofs
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9638 if (do_debug_frames_interp
)
9639 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9642 printf (" DW_CFA_set_loc: ");
9643 print_hex_ns (ofs
, fc
->ptr_size
);
9649 case DW_CFA_advance_loc1
:
9650 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9651 ofs
*= fc
->code_factor
;
9652 if (do_debug_frames_interp
)
9653 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9656 printf (" DW_CFA_advance_loc1: %" PRId64
" to ", ofs
);
9657 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9660 fc
->pc_begin
+= ofs
;
9663 case DW_CFA_advance_loc2
:
9664 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9665 ofs
*= fc
->code_factor
;
9666 if (do_debug_frames_interp
)
9667 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9670 printf (" DW_CFA_advance_loc2: %" PRId64
" to ", ofs
);
9671 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9674 fc
->pc_begin
+= ofs
;
9677 case DW_CFA_advance_loc4
:
9678 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9679 ofs
*= fc
->code_factor
;
9680 if (do_debug_frames_interp
)
9681 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9684 printf (" DW_CFA_advance_loc4: %" PRId64
" to ", ofs
);
9685 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
9688 fc
->pc_begin
+= ofs
;
9691 case DW_CFA_offset_extended
:
9692 READ_ULEB (reg
, start
, block_end
);
9693 READ_ULEB (ofs
, start
, block_end
);
9694 ofs
*= fc
->data_factor
;
9695 if (reg
>= fc
->ncols
)
9696 reg_prefix
= bad_reg
;
9697 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9698 printf (" DW_CFA_offset_extended: %s%s at cfa%+" PRId64
"\n",
9699 reg_prefix
, regname (reg
, 0), ofs
);
9700 if (*reg_prefix
== '\0')
9702 fc
->col_type
[reg
] = DW_CFA_offset
;
9703 fc
->col_offset
[reg
] = ofs
;
9707 case DW_CFA_val_offset
:
9708 READ_ULEB (reg
, start
, block_end
);
9709 READ_ULEB (ofs
, start
, block_end
);
9710 ofs
*= fc
->data_factor
;
9711 if (reg
>= fc
->ncols
)
9712 reg_prefix
= bad_reg
;
9713 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9714 printf (" DW_CFA_val_offset: %s%s is cfa%+" PRId64
"\n",
9715 reg_prefix
, regname (reg
, 0), ofs
);
9716 if (*reg_prefix
== '\0')
9718 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9719 fc
->col_offset
[reg
] = ofs
;
9723 case DW_CFA_restore_extended
:
9724 READ_ULEB (reg
, start
, block_end
);
9725 if (reg
>= fc
->ncols
)
9726 reg_prefix
= bad_reg
;
9727 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9728 printf (" DW_CFA_restore_extended: %s%s\n",
9729 reg_prefix
, regname (reg
, 0));
9730 if (*reg_prefix
!= '\0')
9733 if (reg
>= cie
->ncols
9734 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9736 fc
->col_type
[reg
] = DW_CFA_undefined
;
9737 fc
->col_offset
[reg
] = 0;
9741 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9742 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9746 case DW_CFA_undefined
:
9747 READ_ULEB (reg
, start
, block_end
);
9748 if (reg
>= fc
->ncols
)
9749 reg_prefix
= bad_reg
;
9750 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9751 printf (" DW_CFA_undefined: %s%s\n",
9752 reg_prefix
, regname (reg
, 0));
9753 if (*reg_prefix
== '\0')
9755 fc
->col_type
[reg
] = DW_CFA_undefined
;
9756 fc
->col_offset
[reg
] = 0;
9760 case DW_CFA_same_value
:
9761 READ_ULEB (reg
, start
, block_end
);
9762 if (reg
>= fc
->ncols
)
9763 reg_prefix
= bad_reg
;
9764 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9765 printf (" DW_CFA_same_value: %s%s\n",
9766 reg_prefix
, regname (reg
, 0));
9767 if (*reg_prefix
== '\0')
9769 fc
->col_type
[reg
] = DW_CFA_same_value
;
9770 fc
->col_offset
[reg
] = 0;
9774 case DW_CFA_register
:
9775 READ_ULEB (reg
, start
, block_end
);
9776 READ_ULEB (ofs
, start
, block_end
);
9777 if (reg
>= fc
->ncols
)
9778 reg_prefix
= bad_reg
;
9779 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9781 printf (" DW_CFA_register: %s%s in ",
9782 reg_prefix
, regname (reg
, 0));
9783 puts (regname (ofs
, 0));
9785 if (*reg_prefix
== '\0')
9787 fc
->col_type
[reg
] = DW_CFA_register
;
9788 fc
->col_offset
[reg
] = ofs
;
9792 case DW_CFA_remember_state
:
9793 if (! do_debug_frames_interp
)
9794 printf (" DW_CFA_remember_state\n");
9795 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9796 rs
->cfa_offset
= fc
->cfa_offset
;
9797 rs
->cfa_reg
= fc
->cfa_reg
;
9799 rs
->cfa_exp
= fc
->cfa_exp
;
9800 rs
->ncols
= fc
->ncols
;
9801 rs
->col_type
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_type
));
9802 rs
->col_offset
= xcmalloc (rs
->ncols
, sizeof (*rs
->col_offset
));
9803 memcpy (rs
->col_type
, fc
->col_type
,
9804 rs
->ncols
* sizeof (*fc
->col_type
));
9805 memcpy (rs
->col_offset
, fc
->col_offset
,
9806 rs
->ncols
* sizeof (*fc
->col_offset
));
9807 rs
->next
= remembered_state
;
9808 remembered_state
= rs
;
9811 case DW_CFA_restore_state
:
9812 if (! do_debug_frames_interp
)
9813 printf (" DW_CFA_restore_state\n");
9814 rs
= remembered_state
;
9817 remembered_state
= rs
->next
;
9818 fc
->cfa_offset
= rs
->cfa_offset
;
9819 fc
->cfa_reg
= rs
->cfa_reg
;
9821 fc
->cfa_exp
= rs
->cfa_exp
;
9822 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9824 warn (_("Invalid column number in saved frame state\n"));
9829 memcpy (fc
->col_type
, rs
->col_type
,
9830 rs
->ncols
* sizeof (*rs
->col_type
));
9831 memcpy (fc
->col_offset
, rs
->col_offset
,
9832 rs
->ncols
* sizeof (*rs
->col_offset
));
9834 free (rs
->col_type
);
9835 free (rs
->col_offset
);
9838 else if (do_debug_frames_interp
)
9839 printf ("Mismatched DW_CFA_restore_state\n");
9842 case DW_CFA_def_cfa
:
9843 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9844 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9846 if (! do_debug_frames_interp
)
9847 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9848 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9851 case DW_CFA_def_cfa_register
:
9852 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9854 if (! do_debug_frames_interp
)
9855 printf (" DW_CFA_def_cfa_register: %s\n",
9856 regname (fc
->cfa_reg
, 0));
9859 case DW_CFA_def_cfa_offset
:
9860 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9861 if (! do_debug_frames_interp
)
9862 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9866 if (! do_debug_frames_interp
)
9867 printf (" DW_CFA_nop\n");
9870 case DW_CFA_def_cfa_expression
:
9871 READ_ULEB (ofs
, start
, block_end
);
9872 if (ofs
> (size_t) (block_end
- start
))
9874 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9875 "DW_CFA_def_cfa_expression", ofs
);
9878 if (! do_debug_frames_interp
)
9880 printf (" DW_CFA_def_cfa_expression (");
9881 decode_location_expression (start
, eh_addr_size
, 0, -1,
9889 case DW_CFA_expression
:
9890 READ_ULEB (reg
, start
, block_end
);
9891 READ_ULEB (ofs
, start
, block_end
);
9892 if (reg
>= fc
->ncols
)
9893 reg_prefix
= bad_reg
;
9894 /* PR 17512: file: 069-133014-0.006. */
9895 /* PR 17512: file: 98c02eb4. */
9896 if (ofs
> (size_t) (block_end
- start
))
9898 printf (_(" %s: <corrupt len %" PRIu64
">\n"),
9899 "DW_CFA_expression", ofs
);
9902 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9904 printf (" DW_CFA_expression: %s%s (",
9905 reg_prefix
, regname (reg
, 0));
9906 decode_location_expression (start
, eh_addr_size
, 0, -1,
9910 if (*reg_prefix
== '\0')
9911 fc
->col_type
[reg
] = DW_CFA_expression
;
9915 case DW_CFA_val_expression
:
9916 READ_ULEB (reg
, start
, block_end
);
9917 READ_ULEB (ofs
, start
, block_end
);
9918 if (reg
>= fc
->ncols
)
9919 reg_prefix
= bad_reg
;
9920 if (ofs
> (size_t) (block_end
- start
))
9922 printf (" %s: <corrupt len %" PRIu64
">\n",
9923 "DW_CFA_val_expression", ofs
);
9926 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9928 printf (" DW_CFA_val_expression: %s%s (",
9929 reg_prefix
, regname (reg
, 0));
9930 decode_location_expression (start
, eh_addr_size
, 0, -1,
9934 if (*reg_prefix
== '\0')
9935 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9939 case DW_CFA_offset_extended_sf
:
9940 READ_ULEB (reg
, start
, block_end
);
9941 READ_SLEB (sofs
, start
, block_end
);
9942 /* data_factor multiplicaton done here as unsigned to
9943 avoid integer overflow warnings from asan on fuzzed
9946 ofs
*= fc
->data_factor
;
9947 if (reg
>= fc
->ncols
)
9948 reg_prefix
= bad_reg
;
9949 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9950 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+" PRId64
"\n",
9951 reg_prefix
, regname (reg
, 0), ofs
);
9952 if (*reg_prefix
== '\0')
9954 fc
->col_type
[reg
] = DW_CFA_offset
;
9955 fc
->col_offset
[reg
] = ofs
;
9959 case DW_CFA_val_offset_sf
:
9960 READ_ULEB (reg
, start
, block_end
);
9961 READ_SLEB (sofs
, start
, block_end
);
9963 ofs
*= fc
->data_factor
;
9964 if (reg
>= fc
->ncols
)
9965 reg_prefix
= bad_reg
;
9966 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9967 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+" PRId64
"\n",
9968 reg_prefix
, regname (reg
, 0), ofs
);
9969 if (*reg_prefix
== '\0')
9971 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9972 fc
->col_offset
[reg
] = ofs
;
9976 case DW_CFA_def_cfa_sf
:
9977 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9978 READ_SLEB (sofs
, start
, block_end
);
9980 ofs
*= fc
->data_factor
;
9981 fc
->cfa_offset
= ofs
;
9983 if (! do_debug_frames_interp
)
9984 printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64
"\n",
9985 regname (fc
->cfa_reg
, 0), ofs
);
9988 case DW_CFA_def_cfa_offset_sf
:
9989 READ_SLEB (sofs
, start
, block_end
);
9991 ofs
*= fc
->data_factor
;
9992 fc
->cfa_offset
= ofs
;
9993 if (! do_debug_frames_interp
)
9994 printf (" DW_CFA_def_cfa_offset_sf: %" PRId64
"\n", ofs
);
9997 case DW_CFA_MIPS_advance_loc8
:
9998 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9999 ofs
*= fc
->code_factor
;
10000 if (do_debug_frames_interp
)
10001 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10004 printf (" DW_CFA_MIPS_advance_loc8: %" PRId64
" to ", ofs
);
10005 print_hex_ns (fc
->pc_begin
+ ofs
, fc
->ptr_size
);
10008 fc
->pc_begin
+= ofs
;
10011 case DW_CFA_GNU_window_save
:
10012 if (! do_debug_frames_interp
)
10013 printf (" %s\n", DW_CFA_GNU_window_save_name
[is_aarch64
]);
10016 case DW_CFA_GNU_args_size
:
10017 READ_ULEB (ofs
, start
, block_end
);
10018 if (! do_debug_frames_interp
)
10019 printf (" DW_CFA_GNU_args_size: %" PRIu64
"\n", ofs
);
10022 case DW_CFA_GNU_negative_offset_extended
:
10023 READ_ULEB (reg
, start
, block_end
);
10024 READ_SLEB (sofs
, start
, block_end
);
10026 ofs
= -ofs
* fc
->data_factor
;
10027 if (reg
>= fc
->ncols
)
10028 reg_prefix
= bad_reg
;
10029 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
10030 printf (" DW_CFA_GNU_negative_offset_extended: %s%s "
10031 "at cfa%+" PRId64
"\n",
10032 reg_prefix
, regname (reg
, 0), ofs
);
10033 if (*reg_prefix
== '\0')
10035 fc
->col_type
[reg
] = DW_CFA_offset
;
10036 fc
->col_offset
[reg
] = ofs
;
10041 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
10042 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
10044 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
10049 /* Interpret the CFA - as long as it is not completely full of NOPs. */
10050 if (do_debug_frames_interp
&& ! all_nops
)
10051 frame_display_row (fc
, &need_col_headers
, &max_regs
);
10053 if (fde_fc
.col_type
!= NULL
)
10055 free (fde_fc
.col_type
);
10056 fde_fc
.col_type
= NULL
;
10058 if (fde_fc
.col_offset
!= NULL
)
10060 free (fde_fc
.col_offset
);
10061 fde_fc
.col_offset
= NULL
;
10065 eh_addr_size
= saved_eh_addr_size
;
10070 while (remembered_state
!= NULL
)
10072 rs
= remembered_state
;
10073 remembered_state
= rs
->next
;
10074 free (rs
->col_type
);
10075 free (rs
->col_offset
);
10076 rs
->next
= NULL
; /* Paranoia. */
10080 while (chunks
!= NULL
)
10084 free (rs
->col_type
);
10085 free (rs
->col_offset
);
10086 rs
->next
= NULL
; /* Paranoia. */
10090 while (forward_refs
!= NULL
)
10093 forward_refs
= rs
->next
;
10094 free (rs
->col_type
);
10095 free (rs
->col_offset
);
10096 rs
->next
= NULL
; /* Paranoia. */
10106 display_debug_names (struct dwarf_section
*section
, void *file
)
10108 unsigned char *hdrptr
= section
->start
;
10109 uint64_t unit_length
;
10110 unsigned char *unit_start
;
10111 const unsigned char *const section_end
= section
->start
+ section
->size
;
10112 unsigned char *unit_end
;
10114 introduce (section
, false);
10116 load_debug_section_with_follow (str
, file
);
10118 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10120 unsigned int offset_size
;
10121 uint16_t dwarf_version
, padding
;
10122 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10123 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10124 uint32_t augmentation_string_size
;
10126 bool augmentation_printable
;
10127 const char *augmentation_string
;
10130 unit_start
= hdrptr
;
10132 /* Get and check the length of the block. */
10133 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10135 if (unit_length
== 0xffffffff)
10137 /* This section is 64-bit DWARF. */
10138 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10144 if (unit_length
> (size_t) (section_end
- hdrptr
)
10145 || unit_length
< 2 + 2 + 4 * 7)
10148 warn (_("Debug info is corrupted, %s header at %#tx"
10149 " has length %#" PRIx64
"\n"),
10150 section
->name
, unit_start
- section
->start
, unit_length
);
10153 unit_end
= hdrptr
+ unit_length
;
10155 /* Get and check the version number. */
10156 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10157 printf (_("Version %d\n"), (int) dwarf_version
);
10159 /* Prior versions did not exist, and future versions may not be
10160 backwards compatible. */
10161 if (dwarf_version
!= 5)
10163 warn (_("Only DWARF version 5 .debug_names "
10164 "is currently supported.\n"));
10168 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10170 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10173 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10174 if (comp_unit_count
== 0)
10175 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10177 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10178 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10179 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10180 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10181 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10183 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10184 if (augmentation_string_size
% 4 != 0)
10186 warn (_("Augmentation string length %u must be rounded up "
10187 "to a multiple of 4 in .debug_names.\n"),
10188 augmentation_string_size
);
10189 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10191 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10194 printf (_("Augmentation string:"));
10196 augmentation_printable
= true;
10197 augmentation_string
= (const char *) hdrptr
;
10199 for (i
= 0; i
< augmentation_string_size
; i
++)
10203 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10204 printf (" %02x", uc
);
10206 if (uc
!= 0 && !ISPRINT (uc
))
10207 augmentation_printable
= false;
10210 if (augmentation_printable
)
10214 i
< augmentation_string_size
&& augmentation_string
[i
];
10216 putchar (augmentation_string
[i
]);
10221 printf (_("CU table:\n"));
10222 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10223 || total
> (size_t) (unit_end
- hdrptr
))
10225 for (i
= 0; i
< comp_unit_count
; i
++)
10227 uint64_t cu_offset
;
10229 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10230 printf ("[%3u] %#" PRIx64
"\n", i
, cu_offset
);
10234 printf (_("TU table:\n"));
10235 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10236 || total
> (size_t) (unit_end
- hdrptr
))
10238 for (i
= 0; i
< local_type_unit_count
; i
++)
10240 uint64_t tu_offset
;
10242 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10243 printf ("[%3u] %#" PRIx64
"\n", i
, tu_offset
);
10247 printf (_("Foreign TU table:\n"));
10248 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10249 || total
> (size_t) (unit_end
- hdrptr
))
10251 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10253 uint64_t signature
;
10255 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10256 printf (_("[%3u] "), i
);
10257 print_hex_ns (signature
, 8);
10262 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10263 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10264 + abbrev_table_size
);
10265 if (xtra
> (size_t) (unit_end
- hdrptr
))
10267 warn (_("Entry pool offset (%#" PRIx64
") exceeds unit size %#tx "
10268 "for unit %#tx in the debug_names\n"),
10269 xtra
, unit_end
- unit_start
, unit_start
- section
->start
);
10272 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10273 hdrptr
+= bucket_count
* sizeof (uint32_t);
10274 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10275 hdrptr
+= name_count
* sizeof (uint32_t);
10276 unsigned char *const name_table_string_offsets
= hdrptr
;
10277 hdrptr
+= name_count
* offset_size
;
10278 unsigned char *const name_table_entry_offsets
= hdrptr
;
10279 hdrptr
+= name_count
* offset_size
;
10280 unsigned char *const abbrev_table
= hdrptr
;
10281 hdrptr
+= abbrev_table_size
;
10282 const unsigned char *const abbrev_table_end
= hdrptr
;
10283 unsigned char *const entry_pool
= hdrptr
;
10285 size_t buckets_filled
= 0;
10287 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10289 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10294 printf (ngettext ("Used %zu of %lu bucket.\n",
10295 "Used %zu of %lu buckets.\n",
10296 (unsigned long) bucket_count
),
10297 buckets_filled
, (unsigned long) bucket_count
);
10299 if (bucket_count
!= 0)
10301 uint32_t hash_prev
= 0;
10302 size_t hash_clash_count
= 0;
10303 size_t longest_clash
= 0;
10304 size_t this_length
= 0;
10306 for (hashi
= 0; hashi
< name_count
; hashi
++)
10308 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10312 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10314 ++hash_clash_count
;
10316 longest_clash
= MAX (longest_clash
, this_length
);
10321 hash_prev
= hash_this
;
10323 printf (_("Out of %" PRIu64
" items there are %zu bucket clashes"
10324 " (longest of %zu entries).\n"),
10325 name_count
, hash_clash_count
, longest_clash
);
10327 if (name_count
!= buckets_filled
+ hash_clash_count
)
10328 warn (_("The name_count (%" PRIu64
")"
10329 " is not the same as the used bucket_count"
10330 " (%zu) + the hash clash count (%zu)"),
10331 name_count
, buckets_filled
, hash_clash_count
);
10334 struct abbrev_lookup_entry
10336 uint64_t abbrev_tag
;
10337 unsigned char *abbrev_lookup_ptr
;
10339 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10340 size_t abbrev_lookup_used
= 0;
10341 size_t abbrev_lookup_allocated
= 0;
10343 unsigned char *abbrevptr
= abbrev_table
;
10346 uint64_t abbrev_tag
;
10348 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10349 if (abbrev_tag
== 0)
10351 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10353 abbrev_lookup_allocated
= MAX (0x100,
10354 abbrev_lookup_allocated
* 2);
10355 abbrev_lookup
= xrealloc (abbrev_lookup
,
10356 (abbrev_lookup_allocated
10357 * sizeof (*abbrev_lookup
)));
10359 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10360 struct abbrev_lookup_entry
*entry
;
10361 for (entry
= abbrev_lookup
;
10362 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10364 if (entry
->abbrev_tag
== abbrev_tag
)
10366 warn (_("Duplicate abbreviation tag %" PRIu64
10367 " in unit %#tx in the debug_names section\n"),
10368 abbrev_tag
, unit_start
- section
->start
);
10371 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10372 entry
->abbrev_tag
= abbrev_tag
;
10373 entry
->abbrev_lookup_ptr
= abbrevptr
;
10375 /* Skip DWARF tag. */
10376 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10379 uint64_t xindex
, form
;
10381 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10382 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10383 if (xindex
== 0 && form
== 0)
10388 printf (_("\nSymbol table:\n"));
10390 for (namei
= 0; namei
< name_count
; ++namei
)
10392 uint64_t string_offset
, entry_offset
;
10395 p
= name_table_string_offsets
+ namei
* offset_size
;
10396 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10397 p
= name_table_entry_offsets
+ namei
* offset_size
;
10398 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10400 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10401 fetch_indirect_string (string_offset
));
10403 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10405 /* We need to scan first whether there is a single or multiple
10406 entries. TAGNO is -2 for the first entry, it is -1 for the
10407 initial tag read of the second entry, then it becomes 0 for the
10408 first entry for real printing etc. */
10410 /* Initialize it due to a false compiler warning. */
10411 uint64_t second_abbrev_tag
= -1;
10414 uint64_t abbrev_tag
;
10415 uint64_t dwarf_tag
;
10416 const struct abbrev_lookup_entry
*entry
;
10418 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10421 second_abbrev_tag
= abbrev_tag
;
10423 entryptr
= entry_pool
+ entry_offset
;
10426 if (abbrev_tag
== 0)
10429 printf ("%s<%" PRIu64
">",
10430 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10433 for (entry
= abbrev_lookup
;
10434 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10436 if (entry
->abbrev_tag
== abbrev_tag
)
10438 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10440 warn (_("Undefined abbreviation tag %" PRId64
10441 " in unit %#tx in the debug_names section\n"),
10443 unit_start
- section
->start
);
10446 abbrevptr
= entry
->abbrev_lookup_ptr
;
10447 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10449 printf (" %s", get_TAG_name (dwarf_tag
));
10452 uint64_t xindex
, form
;
10454 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10455 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10456 if (xindex
== 0 && form
== 0)
10460 printf (" %s", get_IDX_name (xindex
));
10461 entryptr
= read_and_display_attr_value (0, form
, 0,
10462 unit_start
, entryptr
, unit_end
,
10464 dwarf_version
, NULL
,
10465 (tagno
< 0), section
,
10471 printf (_(" <no entries>"));
10475 free (abbrev_lookup
);
10482 display_debug_links (struct dwarf_section
* section
,
10483 void * file ATTRIBUTE_UNUSED
)
10485 const unsigned char * filename
;
10486 unsigned int filelen
;
10488 introduce (section
, false);
10490 /* The .gnu_debuglink section is formatted as:
10491 (c-string) Filename.
10492 (padding) If needed to reach a 4 byte boundary.
10493 (uint32_t) CRC32 value.
10495 The .gun_debugaltlink section is formatted as:
10496 (c-string) Filename.
10497 (binary) Build-ID. */
10499 filename
= section
->start
;
10500 filelen
= strnlen ((const char *) filename
, section
->size
);
10501 if (filelen
== section
->size
)
10503 warn (_("The debuglink filename is corrupt/missing\n"));
10507 printf (_(" Separate debug info file: %s\n"), filename
);
10509 if (startswith (section
->name
, ".gnu_debuglink"))
10511 unsigned int crc32
;
10512 unsigned int crc_offset
;
10514 crc_offset
= filelen
+ 1;
10515 crc_offset
= (crc_offset
+ 3) & ~3;
10516 if (crc_offset
+ 4 > section
->size
)
10518 warn (_("CRC offset missing/truncated\n"));
10522 crc32
= byte_get (filename
+ crc_offset
, 4);
10524 printf (_(" CRC value: %#x\n"), crc32
);
10526 if (crc_offset
+ 4 < section
->size
)
10528 warn (_("There are %#" PRIx64
10529 " extraneous bytes at the end of the section\n"),
10530 section
->size
- (crc_offset
+ 4));
10534 else /* startswith (section->name, ".gnu_debugaltlink") */
10536 const unsigned char *build_id
= section
->start
+ filelen
+ 1;
10537 size_t build_id_len
= section
->size
- (filelen
+ 1);
10540 /* FIXME: Should we support smaller build-id notes ? */
10541 if (build_id_len
< 0x14)
10543 warn (_("Build-ID is too short (%#zx bytes)\n"), build_id_len
);
10547 printed
= printf (_(" Build-ID (%#zx bytes):"), build_id_len
);
10548 display_data (printed
, build_id
, build_id_len
);
10557 display_gdb_index (struct dwarf_section
*section
,
10558 void *file ATTRIBUTE_UNUSED
)
10560 unsigned char *start
= section
->start
;
10562 uint32_t cu_list_offset
, tu_list_offset
;
10563 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10564 unsigned int cu_list_elements
, tu_list_elements
;
10565 unsigned int address_table_elements
, symbol_table_slots
;
10566 unsigned char *cu_list
, *tu_list
;
10567 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10570 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10572 introduce (section
, false);
10574 if (section
->size
< 6 * sizeof (uint32_t))
10576 warn (_("Truncated header in the %s section.\n"), section
->name
);
10580 version
= byte_get_little_endian (start
, 4);
10581 printf (_("Version %lu\n"), (unsigned long) version
);
10583 /* Prior versions are obsolete, and future versions may not be
10584 backwards compatible. */
10585 if (version
< 3 || version
> 8)
10587 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10591 warn (_("The address table data in version 3 may be wrong.\n"));
10593 warn (_("Version 4 does not support case insensitive lookups.\n"));
10595 warn (_("Version 5 does not include inlined functions.\n"));
10597 warn (_("Version 6 does not include symbol attributes.\n"));
10598 /* Version 7 indices generated by Gold have bad type unit references,
10599 PR binutils/15021. But we don't know if the index was generated by
10600 Gold or not, so to avoid worrying users with gdb-generated indices
10601 we say nothing for version 7 here. */
10603 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10604 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10605 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10606 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10607 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10609 if (cu_list_offset
> section
->size
10610 || tu_list_offset
> section
->size
10611 || address_table_offset
> section
->size
10612 || symbol_table_offset
> section
->size
10613 || constant_pool_offset
> section
->size
10614 || tu_list_offset
< cu_list_offset
10615 || address_table_offset
< tu_list_offset
10616 || symbol_table_offset
< address_table_offset
10617 || constant_pool_offset
< symbol_table_offset
)
10619 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10623 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10624 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10625 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10626 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10628 cu_list
= start
+ cu_list_offset
;
10629 tu_list
= start
+ tu_list_offset
;
10630 address_table
= start
+ address_table_offset
;
10631 symbol_table
= start
+ symbol_table_offset
;
10632 constant_pool
= start
+ constant_pool_offset
;
10634 printf (_("\nCU table:\n"));
10635 for (i
= 0; i
< cu_list_elements
; i
++)
10637 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10638 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10640 printf ("[%3u] %#" PRIx64
" - %#" PRIx64
"\n",
10641 i
, cu_offset
, cu_offset
+ cu_length
- 1);
10644 printf (_("\nTU table:\n"));
10645 for (i
= 0; i
< tu_list_elements
; i
++)
10647 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10648 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10649 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10651 printf ("[%3u] %#" PRIx64
" %#" PRIx64
" ",
10652 i
, tu_offset
, type_offset
);
10653 print_hex_ns (signature
, 8);
10657 printf (_("\nAddress table:\n"));
10658 for (i
= 0; i
< address_table_elements
; i
++)
10660 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10661 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10662 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
* 20 + 16, 4);
10664 print_hex (low
, 8);
10665 print_hex (high
, 8);
10666 printf ("%" PRIu32
"\n", cu_index
);
10669 printf (_("\nSymbol table:\n"));
10670 for (i
= 0; i
< symbol_table_slots
; ++i
)
10672 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10673 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10674 uint32_t num_cus
, cu
;
10676 if (name_offset
!= 0
10677 || cu_vector_offset
!= 0)
10681 /* PR 17531: file: 5b7b07ad. */
10682 if (name_offset
>= section
->size
- constant_pool_offset
)
10684 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10685 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10689 printf ("[%3u] %.*s:", i
,
10690 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10691 constant_pool
+ name_offset
);
10693 if (section
->size
- constant_pool_offset
< 4
10694 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10696 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10697 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10698 cu_vector_offset
, i
);
10702 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10704 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10705 + cu_vector_offset
+ 4))
10707 printf ("<invalid number of CUs: %d>\n", num_cus
);
10708 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10716 for (j
= 0; j
< num_cus
; ++j
)
10719 gdb_index_symbol_kind kind
;
10721 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10722 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10723 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10724 cu
= GDB_INDEX_CU_VALUE (cu
);
10725 /* Convert to TU number if it's for a type unit. */
10726 if (cu
>= cu_list_elements
)
10727 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10728 (unsigned long) cu
- cu_list_elements
);
10730 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10732 printf (" [%s, %s]",
10733 is_static
? _("static") : _("global"),
10734 get_gdb_index_symbol_kind_name (kind
));
10746 /* Pre-allocate enough space for the CU/TU sets needed. */
10749 prealloc_cu_tu_list (unsigned int nshndx
)
10752 /* Always allocate at least one entry for the end-marker. */
10755 if (shndx_pool
== NULL
)
10757 shndx_pool_size
= nshndx
;
10758 shndx_pool_used
= 0;
10759 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10760 sizeof (unsigned int));
10764 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10765 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10766 sizeof (unsigned int));
10771 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10773 shndx_pool
[shndx_pool_used
++] = shndx
;
10777 end_cu_tu_entry (void)
10779 shndx_pool
[shndx_pool_used
++] = 0;
10782 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10784 static const char *
10785 get_DW_SECT_short_name (unsigned int dw_sect
)
10787 static char buf
[16];
10793 case DW_SECT_TYPES
:
10795 case DW_SECT_ABBREV
:
10801 case DW_SECT_STR_OFFSETS
:
10803 case DW_SECT_MACINFO
:
10805 case DW_SECT_MACRO
:
10811 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10815 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10816 These sections are extensions for Fission.
10817 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10820 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10822 unsigned char *phdr
= section
->start
;
10823 unsigned char *limit
= phdr
+ section
->size
;
10824 unsigned char *phash
;
10825 unsigned char *pindex
;
10826 unsigned char *ppool
;
10827 unsigned int version
;
10828 unsigned int ncols
= 0;
10829 unsigned int nused
;
10830 unsigned int nslots
;
10833 uint64_t signature
;
10836 /* PR 17512: file: 002-168123-0.004. */
10839 warn (_("Section %s is empty\n"), section
->name
);
10842 /* PR 17512: file: 002-376-0.004. */
10843 if (section
->size
< 24)
10845 warn (_("Section %s is too small to contain a CU/TU header\n"),
10851 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10853 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10854 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10855 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10857 pindex
= phash
+ (size_t) nslots
* 8;
10858 ppool
= pindex
+ (size_t) nslots
* 4;
10862 introduce (section
, false);
10864 printf (_(" Version: %u\n"), version
);
10866 printf (_(" Number of columns: %u\n"), ncols
);
10867 printf (_(" Number of used entries: %u\n"), nused
);
10868 printf (_(" Number of slots: %u\n\n"), nslots
);
10871 /* PR 17531: file: 45d69832. */
10872 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10873 || total
> (size_t) (limit
- phash
))
10875 warn (ngettext ("Section %s is too small for %u slot\n",
10876 "Section %s is too small for %u slots\n",
10878 section
->name
, nslots
);
10884 unsigned char *shndx_list
;
10885 unsigned int shndx
;
10889 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10890 for (shndx_list
= ppool
+ 4; shndx_list
<= limit
- 4; shndx_list
+= 4)
10892 shndx
= byte_get (shndx_list
, 4);
10893 add_shndx_to_cu_tu_entry (shndx
);
10895 end_cu_tu_entry ();
10898 for (i
= 0; i
< nslots
; i
++)
10900 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10901 if (signature
!= 0)
10903 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10904 shndx_list
= ppool
+ j
* 4;
10905 /* PR 17531: file: 705e010d. */
10906 if (shndx_list
< ppool
)
10908 warn (_("Section index pool located before start of section\n"));
10912 printf (_(" [%3d] Signature: %#" PRIx64
" Sections: "),
10916 if (shndx_list
>= limit
)
10918 warn (_("Section %s too small for shndx pool\n"),
10922 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10925 printf (" %d", shndx
);
10934 else if (version
== 2)
10937 unsigned int dw_sect
;
10938 unsigned char *ph
= phash
;
10939 unsigned char *pi
= pindex
;
10940 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10941 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10943 struct cu_tu_set
*this_set
= NULL
;
10945 unsigned char *prow
;
10948 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10950 /* PR 17531: file: 0dd159bf.
10951 Check for integer overflow (can occur when size_t is 32-bit)
10952 with overlarge ncols or nused values. */
10954 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10955 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10956 || total
> (size_t) (limit
- ppool
)
10957 /* PR 30227: ncols could be 0. */
10958 || _mul_overflow ((size_t) nused
+ 1, 4, &total
)
10959 || total
> (size_t) (limit
- ppool
))
10961 warn (_("Section %s too small for offset and size tables\n"),
10968 printf (_(" Offset table\n"));
10969 printf (" slot %-16s ",
10970 is_tu_index
? _("signature") : _("dwo_id"));
10977 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10978 this_set
= tu_sets
;
10983 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10984 this_set
= cu_sets
;
10990 for (j
= 0; j
< ncols
; j
++)
10992 unsigned char *p
= ppool
+ j
* 4;
10993 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10994 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10999 for (i
= 0; i
< nslots
; i
++)
11001 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11003 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11006 /* PR 17531: file: a05f6ab3. */
11009 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
11016 size_t num_copy
= sizeof (uint64_t);
11018 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
11021 prow
= poffsets
+ (row
- 1) * ncols
* 4;
11023 printf (" [%3d] %#" PRIx64
, i
, signature
);
11024 for (j
= 0; j
< ncols
; j
++)
11026 unsigned char *p
= prow
+ j
* 4;
11027 SAFE_BYTE_GET (val
, p
, 4, limit
);
11029 printf (" %8d", val
);
11033 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11035 /* PR 17531: file: 10796eb3. */
11036 if (dw_sect
>= DW_SECT_MAX
)
11037 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11039 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11055 printf (_(" Size table\n"));
11056 printf (" slot %-16s ",
11057 is_tu_index
? _("signature") : _("dwo_id"));
11060 for (j
= 0; j
< ncols
; j
++)
11062 unsigned char *p
= ppool
+ j
* 4;
11063 SAFE_BYTE_GET (val
, p
, 4, limit
);
11065 printf (" %8s", get_DW_SECT_short_name (val
));
11071 for (i
= 0; i
< nslots
; i
++)
11073 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11075 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11078 prow
= psizes
+ (row
- 1) * ncols
* 4;
11081 printf (" [%3d] %#" PRIx64
, i
, signature
);
11083 for (j
= 0; j
< ncols
; j
++)
11085 unsigned char *p
= prow
+ j
* 4;
11087 /* PR 28645: Check for overflow. Since we do not know how
11088 many populated rows there will be, we cannot just
11089 perform a single check at the start of this function. */
11090 if (p
> (limit
- 4))
11094 warn (_("Too many rows/columns in DWARF index section %s\n"),
11099 SAFE_BYTE_GET (val
, p
, 4, limit
);
11102 printf (" %8d", val
);
11106 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11107 if (dw_sect
>= DW_SECT_MAX
)
11108 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11110 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11122 else if (do_display
)
11123 printf (_(" Unsupported version (%d)\n"), version
);
11131 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11133 /* Load the CU and TU indexes if present. This will build a list of
11134 section sets that we can use to associate a .debug_info.dwo section
11135 with its associated .debug_abbrev.dwo section in a .dwp file. */
11138 load_cu_tu_indexes (void *file
)
11140 /* If we have already loaded (or tried to load) the CU and TU indexes
11141 then do not bother to repeat the task. */
11142 if (cu_tu_indexes_read
== -1)
11144 cu_tu_indexes_read
= true;
11146 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11147 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11148 cu_tu_indexes_read
= false;
11150 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11151 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11152 cu_tu_indexes_read
= false;
11155 return (bool) cu_tu_indexes_read
;
11158 /* Find the set of sections that includes section SHNDX. */
11161 find_cu_tu_set (void *file
, unsigned int shndx
)
11165 if (! load_cu_tu_indexes (file
))
11168 /* Find SHNDX in the shndx pool. */
11169 for (i
= 0; i
< shndx_pool_used
; i
++)
11170 if (shndx_pool
[i
] == shndx
)
11173 if (i
>= shndx_pool_used
)
11176 /* Now backup to find the first entry in the set. */
11177 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11180 return shndx_pool
+ i
;
11183 /* Display a .debug_cu_index or .debug_tu_index section. */
11186 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11188 return process_cu_tu_index (section
, 1);
11192 display_debug_not_supported (struct dwarf_section
*section
,
11193 void *file ATTRIBUTE_UNUSED
)
11195 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11201 /* Like malloc, but takes two parameters like calloc.
11202 Verifies that the first parameter is not too large.
11203 Note: does *not* initialise the allocated memory to zero. */
11206 cmalloc (uint64_t nmemb
, size_t size
)
11208 /* Check for overflow. */
11209 if (nmemb
>= ~(size_t) 0 / size
)
11212 return xmalloc (nmemb
* size
);
11215 /* Like xmalloc, but takes two parameters like calloc.
11216 Verifies that the first parameter is not too large.
11217 Note: does *not* initialise the allocated memory to zero. */
11220 xcmalloc (uint64_t nmemb
, size_t size
)
11222 /* Check for overflow. */
11223 if (nmemb
>= ~(size_t) 0 / size
)
11226 _("Attempt to allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11231 return xmalloc (nmemb
* size
);
11234 /* Like xrealloc, but takes three parameters.
11235 Verifies that the second parameter is not too large.
11236 Note: does *not* initialise any new memory to zero. */
11239 xcrealloc (void *ptr
, uint64_t nmemb
, size_t size
)
11241 /* Check for overflow. */
11242 if (nmemb
>= ~(size_t) 0 / size
)
11244 error (_("Attempt to re-allocate an array with an excessive number of elements: %#" PRIx64
"\n"),
11249 return xrealloc (ptr
, nmemb
* size
);
11252 /* Like xcalloc, but verifies that the first parameter is not too large. */
11255 xcalloc2 (uint64_t nmemb
, size_t size
)
11257 /* Check for overflow. */
11258 if (nmemb
>= ~(size_t) 0 / size
)
11260 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: %#" PRIx64
"\n"),
11265 return xcalloc (nmemb
, size
);
11268 static unsigned long
11269 calc_gnu_debuglink_crc32 (unsigned long crc
,
11270 const unsigned char *buf
,
11273 static const unsigned long crc32_table
[256] =
11275 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11276 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11277 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11278 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11279 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11280 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11281 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11282 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11283 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11284 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11285 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11286 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11287 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11288 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11289 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11290 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11291 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11292 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11293 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11294 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11295 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11296 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11297 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11298 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11299 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11300 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11301 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11302 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11303 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11304 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11305 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11306 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11307 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11308 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11309 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11310 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11311 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11312 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11313 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11314 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11315 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11316 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11317 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11318 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11319 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11320 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11321 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11322 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11323 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11324 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11325 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11328 const unsigned char *end
;
11330 crc
= ~crc
& 0xffffffff;
11331 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11332 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11333 return ~crc
& 0xffffffff;
11336 typedef bool (*check_func_type
) (const char *, void *);
11337 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11340 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11342 static unsigned char buffer
[8 * 1024];
11345 unsigned long crc
= 0;
11348 sep_data
= open_debug_file (pathname
);
11349 if (sep_data
== NULL
)
11352 /* Yes - we are opening the file twice... */
11353 f
= fopen (pathname
, "rb");
11356 /* Paranoia: This should never happen. */
11357 close_debug_file (sep_data
);
11358 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11362 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11363 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11367 if (crc
!= * (unsigned long *) crc_pointer
)
11369 close_debug_file (sep_data
);
11370 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11378 static const char *
11379 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11382 unsigned int crc_offset
;
11383 unsigned long * crc32
= (unsigned long *) data
;
11385 /* The name is first.
11386 The CRC value is stored after the filename, aligned up to 4 bytes. */
11387 name
= (const char *) section
->start
;
11389 crc_offset
= strnlen (name
, section
->size
) + 1;
11390 if (crc_offset
== 1)
11392 crc_offset
= (crc_offset
+ 3) & ~3;
11393 if (crc_offset
+ 4 > section
->size
)
11396 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11401 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11403 void * sep_data
= open_debug_file (filename
);
11405 if (sep_data
== NULL
)
11408 /* FIXME: We should now extract the build-id in the separate file
11414 typedef struct build_id_data
11417 const unsigned char *data
;
11420 static const char *
11421 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11426 Build_id_data
*build_id_data
;
11428 /* The name is first.
11429 The build-id follows immediately, with no padding, up to the section's end. */
11431 name
= (const char *) section
->start
;
11432 namelen
= strnlen (name
, section
->size
) + 1;
11435 if (namelen
>= section
->size
)
11438 id_len
= section
->size
- namelen
;
11442 build_id_data
= (Build_id_data
*) data
;
11443 build_id_data
->len
= id_len
;
11444 build_id_data
->data
= section
->start
+ namelen
;
11450 add_separate_debug_file (const char * filename
, void * handle
)
11452 separate_info
* i
= xmalloc (sizeof * i
);
11454 i
->filename
= filename
;
11455 i
->handle
= handle
;
11456 i
->next
= first_separate_info
;
11457 first_separate_info
= i
;
11460 #if HAVE_LIBDEBUGINFOD
11461 /* Query debuginfod servers for the target debuglink or debugaltlink
11462 file. If successful, store the path of the file in filename and
11463 return TRUE, otherwise return FALSE. */
11466 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11470 size_t build_id_len
;
11471 unsigned char * build_id
;
11473 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11475 /* Get the build-id of file. */
11476 build_id
= get_build_id (file
);
11479 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11481 /* Get the build-id of the debugaltlink file. */
11482 unsigned int filelen
;
11484 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11485 if (filelen
== section
->size
)
11486 /* Corrupt debugaltlink. */
11489 build_id
= section
->start
+ filelen
+ 1;
11490 build_id_len
= section
->size
- (filelen
+ 1);
11492 if (build_id_len
== 0)
11501 debuginfod_client
* client
;
11503 client
= debuginfod_begin ();
11504 if (client
== NULL
)
11507 /* Query debuginfod servers for the target file. If found its path
11508 will be stored in filename. */
11509 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11510 debuginfod_end (client
);
11512 /* Only free build_id if we allocated space for a hex string
11513 in get_build_id (). */
11514 if (build_id_len
== 0)
11519 /* File successfully retrieved. Close fd since we want to
11520 use open_debug_file () on filename instead. */
11528 #endif /* HAVE_LIBDEBUGINFOD */
11531 load_separate_debug_info (const char * main_filename
,
11532 struct dwarf_section
* xlink
,
11533 parse_func_type parse_func
,
11534 check_func_type check_func
,
11536 void * file ATTRIBUTE_UNUSED
)
11538 const char * separate_filename
;
11539 char * debug_filename
;
11541 size_t canon_dirlen
;
11543 char * canon_filename
;
11544 char * canon_debug_filename
;
11547 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11549 warn (_("Corrupt debuglink section: %s\n"),
11550 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11554 /* Attempt to locate the separate file.
11555 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11557 canon_filename
= lrealpath (main_filename
);
11558 canon_dir
= xstrdup (canon_filename
);
11560 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11561 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11563 canon_dir
[canon_dirlen
] = '\0';
11566 #define DEBUGDIR "/lib/debug"
11568 #ifndef EXTRA_DEBUG_ROOT1
11569 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11571 #ifndef EXTRA_DEBUG_ROOT2
11572 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11575 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11577 + strlen (".debug/")
11578 #ifdef EXTRA_DEBUG_ROOT1
11579 + strlen (EXTRA_DEBUG_ROOT1
)
11581 #ifdef EXTRA_DEBUG_ROOT2
11582 + strlen (EXTRA_DEBUG_ROOT2
)
11584 + strlen (separate_filename
)
11586 if (debug_filename
== NULL
)
11588 warn (_("Out of memory"));
11590 free (canon_filename
);
11594 /* First try in the current directory. */
11595 sprintf (debug_filename
, "%s", separate_filename
);
11596 if (check_func (debug_filename
, func_data
))
11599 /* Then try in a subdirectory called .debug. */
11600 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11601 if (check_func (debug_filename
, func_data
))
11604 /* Then try in the same directory as the original file. */
11605 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11606 if (check_func (debug_filename
, func_data
))
11609 /* And the .debug subdirectory of that directory. */
11610 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11611 if (check_func (debug_filename
, func_data
))
11614 #ifdef EXTRA_DEBUG_ROOT1
11615 /* Try the first extra debug file root. */
11616 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11617 if (check_func (debug_filename
, func_data
))
11620 /* Try the first extra debug file root. */
11621 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11622 if (check_func (debug_filename
, func_data
))
11626 #ifdef EXTRA_DEBUG_ROOT2
11627 /* Try the second extra debug file root. */
11628 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11629 if (check_func (debug_filename
, func_data
))
11633 /* Then try in the global debug_filename directory. */
11634 strcpy (debug_filename
, DEBUGDIR
);
11635 dirlen
= strlen (DEBUGDIR
) - 1;
11636 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11637 strcat (debug_filename
, "/");
11638 strcat (debug_filename
, (const char *) separate_filename
);
11640 if (check_func (debug_filename
, func_data
))
11643 #if HAVE_LIBDEBUGINFOD
11645 char * tmp_filename
;
11648 && debuginfod_fetch_separate_debug_info (xlink
,
11652 /* File successfully downloaded from server, replace
11653 debug_filename with the file's path. */
11654 free (debug_filename
);
11655 debug_filename
= tmp_filename
;
11661 if (do_debug_links
)
11663 /* Failed to find the file. */
11664 warn (_("could not find separate debug file '%s'\n"),
11665 separate_filename
);
11666 warn (_("tried: %s\n"), debug_filename
);
11668 #ifdef EXTRA_DEBUG_ROOT2
11669 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11670 separate_filename
);
11671 warn (_("tried: %s\n"), debug_filename
);
11674 #ifdef EXTRA_DEBUG_ROOT1
11675 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11676 canon_dir
, separate_filename
);
11677 warn (_("tried: %s\n"), debug_filename
);
11679 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11680 separate_filename
);
11681 warn (_("tried: %s\n"), debug_filename
);
11684 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11685 separate_filename
);
11686 warn (_("tried: %s\n"), debug_filename
);
11688 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11689 warn (_("tried: %s\n"), debug_filename
);
11691 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11692 warn (_("tried: %s\n"), debug_filename
);
11694 sprintf (debug_filename
, "%s", separate_filename
);
11695 warn (_("tried: %s\n"), debug_filename
);
11697 #if HAVE_LIBDEBUGINFOD
11698 if (use_debuginfod
)
11700 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11705 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11711 free (debug_filename
);
11712 free (canon_filename
);
11718 canon_debug_filename
= lrealpath (debug_filename
);
11719 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11720 free (canon_filename
);
11721 free (canon_debug_filename
);
11724 free (debug_filename
);
11728 void * debug_handle
;
11730 /* Now open the file.... */
11731 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11733 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11734 free (debug_filename
);
11738 /* FIXME: We do not check to see if there are any other separate debug info
11739 files that would also match. */
11741 if (do_debug_links
)
11742 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11743 add_separate_debug_file (debug_filename
, debug_handle
);
11745 /* Do not free debug_filename - it might be referenced inside
11746 the structure returned by open_debug_file(). */
11747 return debug_handle
;
11750 /* Attempt to load a separate dwarf object file. */
11753 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11755 char * separate_filename
;
11756 void * separate_handle
;
11758 if (IS_ABSOLUTE_PATH (name
))
11759 separate_filename
= strdup (name
);
11761 /* FIXME: Skip adding / if dwo_dir ends in /. */
11762 separate_filename
= concat (dir
, "/", name
, NULL
);
11763 if (separate_filename
== NULL
)
11765 warn (_("Out of memory allocating dwo filename\n"));
11769 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11771 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11772 free (separate_filename
);
11776 /* FIXME: We should check the dwo_id. */
11778 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11780 add_separate_debug_file (separate_filename
, separate_handle
);
11781 /* Note - separate_filename will be freed in free_debug_memory(). */
11782 return separate_handle
;
11786 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11788 char * f
= filename
;
11790 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11793 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11794 strcpy (f
, ".debug");
11796 return open_debug_file (filename
);
11799 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11802 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11804 if (! load_debug_section (note_gnu_build_id
, main_file
))
11805 return; /* No .note.gnu.build-id section. */
11807 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11808 if (section
== NULL
)
11810 warn (_("Unable to load the .note.gnu.build-id section\n"));
11814 if (section
->start
== NULL
|| section
->size
< 0x18)
11816 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11820 /* In theory we should extract the contents of the section into
11821 a note structure and then check the fields. For now though
11822 just use hard coded offsets instead:
11824 Field Bytes Contents
11827 Type 8..11 3 (NT_GNU_BUILD_ID)
11831 /* FIXME: Check the name size, name and type fields. */
11833 unsigned long build_id_size
;
11834 build_id_size
= byte_get (section
->start
+ 4, 4);
11835 if (build_id_size
< 8)
11837 warn (_(".note.gnu.build-id data size is too small\n"));
11841 if (build_id_size
> (section
->size
- 16))
11843 warn (_(".note.gnu.build-id data size is too big\n"));
11848 filename
= xmalloc (strlen (".build-id/")
11849 + build_id_size
* 2 + 2
11850 + strlen (".debug")
11851 /* The next string should be the same as the longest
11852 name found in the prefixes[] array below. */
11853 + strlen ("/usrlib64/debug/usr")
11857 static const char * prefixes
[] =
11862 "/usr/lib/debug/usr/",
11863 "/usr/lib64/debug/",
11864 "/usr/lib64/debug/usr"
11866 long unsigned int i
;
11868 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11870 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11871 section
->start
+ 16, build_id_size
);
11872 if (handle
!= NULL
)
11875 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11876 if (handle
== NULL
)
11878 /* Failed to find a debug file associated with the build-id.
11879 This is not an error however, rather it just means that
11880 the debug info has probably not been loaded on the system,
11881 or that another method is being used to link to the debug
11887 add_separate_debug_file (filename
, handle
);
11890 /* Try to load a debug file pointed to by the .debug_sup section. */
11893 load_debug_sup_file (const char * main_filename
, void * file
)
11895 if (! load_debug_section (debug_sup
, file
))
11896 return; /* No .debug_sup section. */
11898 struct dwarf_section
* section
;
11899 section
= & debug_displays
[debug_sup
].section
;
11900 assert (section
!= NULL
);
11902 if (section
->start
== NULL
|| section
->size
< 5)
11904 warn (_(".debug_sup section is corrupt/empty\n"));
11908 if (section
->start
[2] != 0)
11909 return; /* This is a supplementary file. */
11911 const char * filename
= (const char *) section
->start
+ 3;
11912 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11914 warn (_("filename in .debug_sup section is corrupt\n"));
11918 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11923 new_len
= asprintf (& new_name
, "%.*s/%s",
11924 (int) (strrchr (main_filename
, '/') - main_filename
),
11929 warn (_("unable to construct path for supplementary debug file"));
11934 filename
= new_name
;
11938 /* PR 27796: Make sure that we pass a filename that can be free'd to
11939 add_separate_debug_file(). */
11940 filename
= strdup (filename
);
11941 if (filename
== NULL
)
11943 warn (_("out of memory constructing filename for .debug_sup link\n"));
11948 void * handle
= open_debug_file (filename
);
11949 if (handle
== NULL
)
11951 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11952 free ((void *) filename
);
11956 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11958 /* FIXME: Compare the checksums, if present. */
11959 add_separate_debug_file (filename
, handle
);
11962 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11963 Recursively check the loaded files for more of these sections.
11964 Also follow any links in .debug_sup sections.
11965 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11968 check_for_and_load_links (void * file
, const char * filename
)
11970 void * handle
= NULL
;
11972 if (load_debug_section (gnu_debugaltlink
, file
))
11974 Build_id_data build_id_data
;
11976 handle
= load_separate_debug_info (filename
,
11977 & debug_displays
[gnu_debugaltlink
].section
,
11978 parse_gnu_debugaltlink
,
11979 check_gnu_debugaltlink
,
11984 assert (handle
== first_separate_info
->handle
);
11985 check_for_and_load_links (first_separate_info
->handle
,
11986 first_separate_info
->filename
);
11990 if (load_debug_section (gnu_debuglink
, file
))
11992 unsigned long crc32
;
11994 handle
= load_separate_debug_info (filename
,
11995 & debug_displays
[gnu_debuglink
].section
,
11996 parse_gnu_debuglink
,
11997 check_gnu_debuglink
,
12002 assert (handle
== first_separate_info
->handle
);
12003 check_for_and_load_links (first_separate_info
->handle
,
12004 first_separate_info
->filename
);
12008 load_debug_sup_file (filename
, file
);
12010 load_build_id_debug_file (filename
, file
);
12013 /* Load the separate debug info file(s) attached to FILE, if any exist.
12014 Returns TRUE if any were found, FALSE otherwise.
12015 If TRUE is returned then the linked list starting at first_separate_info
12016 will be populated with open file handles. */
12019 load_separate_debug_files (void * file
, const char * filename
)
12021 /* Skip this operation if we are not interested in debug links. */
12022 if (! do_follow_links
&& ! do_debug_links
)
12025 /* See if there are any dwo links. */
12026 if (load_debug_section (str
, file
)
12027 && load_debug_section (abbrev
, file
)
12028 && load_debug_section (info
, file
))
12030 /* Load the .debug_addr section, if it exists. */
12031 load_debug_section (debug_addr
, file
);
12032 /* Load the .debug_str_offsets section, if it exists. */
12033 load_debug_section (str_index
, file
);
12034 /* Load the .debug_loclists section, if it exists. */
12035 load_debug_section (loclists
, file
);
12036 /* Load the .debug_rnglists section, if it exists. */
12037 load_debug_section (rnglists
, file
);
12041 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
12044 bool introduced
= false;
12046 const char *dir
= NULL
;
12047 const char *id
= NULL
;
12048 const char *name
= NULL
;
12050 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
12052 /* Accumulate NAME, DIR and ID fields. */
12053 switch (dwinfo
->type
)
12057 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12058 name
= dwinfo
->value
;
12062 /* There can be multiple DW_AT_comp_dir entries in a CU,
12063 so do not complain. */
12064 dir
= dwinfo
->value
;
12069 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12070 id
= dwinfo
->value
;
12074 error (_("Unexpected DWO INFO type"));
12078 /* If we have reached the end of our list, or we are changing
12079 CUs, then display the information that we have accumulated
12082 && (dwinfo
->next
== NULL
12083 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12085 if (do_debug_links
)
12089 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12090 debug_displays
[info
].section
.uncompressed_name
);
12094 printf (_(" Name: %s\n"), name
);
12095 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12097 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12098 else if (debug_information
[0].dwarf_version
!= 5)
12099 printf (_(" ID: <not specified>\n"));
12103 if (do_follow_links
)
12104 load_dwo_file (filename
, name
, dir
, id
);
12106 name
= dir
= id
= NULL
;
12112 if (! do_follow_links
)
12113 /* The other debug links will be displayed by display_debug_links()
12114 so we do not need to do any further processing here. */
12117 /* FIXME: We do not check for the presence of both link sections in the same file. */
12118 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12119 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12121 check_for_and_load_links (file
, filename
);
12122 if (first_separate_info
!= NULL
)
12125 do_follow_links
= 0;
12130 free_debug_memory (void)
12134 free_all_abbrevs ();
12138 shndx_pool_size
= 0;
12139 shndx_pool_used
= 0;
12147 memset (level_type_signed
, 0, sizeof level_type_signed
);
12148 cu_tu_indexes_read
= -1;
12150 for (i
= 0; i
< max
; i
++)
12151 free_debug_section ((enum dwarf_section_display_enum
) i
);
12153 if (debug_information
!= NULL
)
12155 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12156 free_debug_information (&debug_information
[i
]);
12157 free (debug_information
);
12158 debug_information
= NULL
;
12159 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12163 separate_info
* next
;
12165 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12167 close_debug_file (d
->handle
);
12168 free ((void *) d
->filename
);
12172 first_separate_info
= NULL
;
12180 const char *option
;
12183 } debug_dump_long_opts
;
12185 static const debug_dump_long_opts debug_option_table
[] =
12187 { 'A', "addr", &do_debug_addr
, 1 },
12188 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12189 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12190 #ifdef HAVE_LIBDEBUGINFOD
12191 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12192 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12194 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12195 { 'f', "frames", &do_debug_frames
, 1 },
12196 { 'g', "gdb_index", &do_gdb_index
, 1 },
12197 { 'i', "info", &do_debug_info
, 1 },
12198 { 'K', "follow-links", &do_follow_links
, 1 },
12199 { 'k', "links", &do_debug_links
, 1 },
12200 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12201 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12202 /* For compatibility with earlier versions of readelf. */
12203 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12204 { 'm', "macro", &do_debug_macinfo
, 1 },
12205 { 'N', "no-follow-links", &do_follow_links
, 0 },
12206 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12207 { 'o', "loc", &do_debug_loc
, 1 },
12208 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12209 { 'R', "Ranges", &do_debug_ranges
, 1 },
12210 { 'r', "aranges", &do_debug_aranges
, 1 },
12211 /* For compatibility with earlier versions of readelf. */
12212 { 'r', "ranges", &do_debug_aranges
, 1 },
12213 { 's', "str", &do_debug_str
, 1 },
12214 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12215 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12216 { 'U', "trace_info", &do_trace_info
, 1 },
12217 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12218 { 0, NULL
, NULL
, 0 }
12221 /* Enable display of specific DWARF sections as determined by the comma
12222 separated strings in NAMES. Returns non-zero if any displaying was
12226 dwarf_select_sections_by_names (const char *names
)
12234 const debug_dump_long_opts
*entry
;
12236 for (entry
= debug_option_table
; entry
->option
; entry
++)
12238 size_t len
= strlen (entry
->option
);
12240 if (strncmp (p
, entry
->option
, len
) == 0
12241 && (p
[len
] == ',' || p
[len
] == '\0'))
12243 if (entry
->val
== 0)
12244 * entry
->variable
= 0;
12246 * entry
->variable
= entry
->val
;
12247 result
|= entry
->val
;
12254 if (entry
->option
== NULL
)
12256 warn (_("Unrecognized debug option '%s'\n"), p
);
12257 p
= strchr (p
, ',');
12266 /* The --debug-dump=frames-interp option also enables the
12267 --debug-dump=frames option. */
12268 if (do_debug_frames_interp
)
12269 do_debug_frames
= 1;
12274 /* Enable display of specific DWARF sections as determined by the characters
12275 in LETTERS. Returns non-zero if any displaying was enabled. */
12278 dwarf_select_sections_by_letters (const char *letters
)
12284 const debug_dump_long_opts
*entry
;
12286 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12288 if (entry
->letter
== * letters
)
12290 if (entry
->val
== 0)
12291 * entry
->variable
= 0;
12293 * entry
->variable
|= entry
->val
;
12294 result
|= entry
->val
;
12299 if (entry
->letter
== 0)
12300 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12305 /* The --debug-dump=frames-interp option also enables the
12306 --debug-dump=frames option. */
12307 if (do_debug_frames_interp
)
12308 do_debug_frames
= 1;
12314 dwarf_select_sections_all (void)
12317 do_debug_abbrevs
= 1;
12318 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12319 do_debug_pubnames
= 1;
12320 do_debug_pubtypes
= 1;
12321 do_debug_aranges
= 1;
12322 do_debug_ranges
= 1;
12323 do_debug_frames
= 1;
12324 do_debug_macinfo
= 1;
12329 do_trace_abbrevs
= 1;
12330 do_trace_aranges
= 1;
12332 do_debug_cu_index
= 1;
12333 do_follow_links
= 1;
12334 do_debug_links
= 1;
12335 do_debug_str_offsets
= 1;
12338 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12339 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12341 /* N.B. The order here must match the order in section_display_enum. */
12343 struct dwarf_section_display debug_displays
[] =
12345 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12346 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12347 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12348 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12349 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12350 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12351 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12352 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12353 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12354 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12355 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12356 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12357 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12358 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12359 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12360 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12361 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12362 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12363 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12364 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12365 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12366 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12367 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12368 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12369 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12370 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12371 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12372 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12373 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12374 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12375 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12376 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12377 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12378 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12379 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12380 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12381 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12382 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12383 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12384 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12385 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12386 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12387 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12388 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12389 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12390 /* Separate debug info files can containt their own .debug_str section,
12391 and this might be in *addition* to a .debug_str section already present
12392 in the main file. Hence we need to have two entries for .debug_str. */
12393 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12394 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12397 /* A static assertion. */
12398 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];